Archive eaglermotd (plugin, 1.5.2, 1.8.8, clean)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"slug": "eaglermotd",
|
||||
"name": "EaglerMOTD",
|
||||
"category": "plugin",
|
||||
"mc_version": "1.5.2, 1.8.8",
|
||||
"author": "lax1dude",
|
||||
"license": "MIT",
|
||||
"upstream_ref": "main",
|
||||
"sha256": "6df435d5fe4db9d66dd4b325c291ad9a5cf3fc2b7d6ec08c493a848a67fbac21",
|
||||
"size": 156306,
|
||||
"storage": {
|
||||
"git_path": null,
|
||||
"fs_url": null
|
||||
},
|
||||
"play": null,
|
||||
"sources": [
|
||||
{
|
||||
"url": "https://github.com/lax1dude/eaglercraft-motd",
|
||||
"retrieved_at": "2026-11-28T03:12:00Z",
|
||||
"type": "upstream",
|
||||
"notes": "Official upstream repository"
|
||||
}
|
||||
],
|
||||
"vetting": {
|
||||
"verdict": "clean",
|
||||
"tools": [
|
||||
"vet-static.mjs",
|
||||
"virustotal-hash"
|
||||
],
|
||||
"date": "2026-11-28",
|
||||
"notes": "Static scan: 0 flagged patterns across 18 files; VirusTotal hash lookup: 0 detections.",
|
||||
"reviewer": "vet-static (automated)"
|
||||
},
|
||||
"large_files_omitted_from_git": []
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# EaglerMOTD
|
||||
|
||||
Animated MOTD and server ping handler plugin for BungeeCord proxies serving Eaglercraft clients.
|
||||
|
||||
- **Archive page:** https://archive.eaglercraft.tech/entries/eaglermotd.html
|
||||
- **MC Version:** 1.5.2, 1.8.8
|
||||
- **Author:** lax1dude
|
||||
- **License:** MIT
|
||||
- **SHA-256:** `6df435d5fe4db9d66dd4b325c291ad9a5cf3fc2b7d6ec08c493a848a67fbac21`
|
||||
- **Vetting:** clean (2026-11-28)
|
||||
@@ -0,0 +1,3 @@
|
||||
/.settings/
|
||||
/bin/
|
||||
.classpath
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EaglerMOTD</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 LAX1DUDE
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,254 @@
|
||||
### THIS IS A BUNGEE PLUGIN! Install in 'bungee_command/plugins' not 'bukkit_command/plugins'
|
||||
|
||||
# EaglerMOTD
|
||||
|
||||
### This plugin can add animated MOTDs to your Eaglercraft server
|
||||
|
||||

|
||||
|
||||
**It can also add custom "Accept:" query handlers for 3rd party sites to gather more information about your server**
|
||||
|
||||
## How to Install
|
||||
|
||||
**Download [EaglerMOTD.jar](https://raw.githubusercontent.com/LAX1DUDE/eaglercraft-motd/main/EaglerMOTD.jar) and place it in your EaglercraftBungee '/plugins' directory. Then, restart EaglercraftBungee**
|
||||
|
||||
You will find a new 'EaglerMOTD' folder in the plugins folder you put the jar in, once you finish restarting your server. This contains the plugin's configuration files, you can edit any of them and then type `motd-reload` in the EaglercraftBungee console to reload all the variables.
|
||||
|
||||
## Configuration Guide
|
||||
|
||||
### Messages.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"close_socket_after": 1200,
|
||||
"max_sockets_per_ip": 10,
|
||||
"max_total_sockets": 256,
|
||||
"allow_banned_ips": false,
|
||||
"messages": {
|
||||
"all": [
|
||||
{
|
||||
"name": "default",
|
||||
"frames": [
|
||||
"frames.frame1",
|
||||
"frames.frame2",
|
||||
"frames.frame3",
|
||||
"frames.frame4"
|
||||
],
|
||||
"interval": 8,
|
||||
"random": false,
|
||||
"shuffle": false,
|
||||
"timeout": 500,
|
||||
"weight": 1.0,
|
||||
"next": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `close_socket_after` Defines the maximum number of ticks (1/20ths of a second) that an animated MOTD should be displayed to a player (default 1200 ticks, which is 60 seconds)
|
||||
|
||||
- `max_sockets_per_ip` Defines the maximum number of MOTD connections that a single IP address can open (does not apply to local IPs like 127.0.0.1 and 192.168.0.0 have no limit)
|
||||
|
||||
- `max_total_sockets` Defines the maximum number of MOTD connections that can be open on the server at any given time
|
||||
|
||||
- `allow_banned_ips` Defines if animated MOTDs should play for banned IPs
|
||||
|
||||
- `messages` Defines the list of possible messages to display on every listener
|
||||
|
||||
- `all` Defines the list of possible messages to display on all listeners
|
||||
|
||||
- To define a list for a specific listener, type the hostname of the listener. The default host defined in a fresh default `config.yml` in EaglercraftBungee is `0.0.0.0:25565` so to define a list of messages for that specific listener you would use `"0.0.0.0:25565"` instead of `"all"` to add the messages. Messages defined as `"all"` will be added to the list of messages for all listeners.
|
||||
|
||||
- The list contains a set of JSON objects each containing these fields:
|
||||
- `name` *(Optional)* Defines the name of the message, used for specifying a `next` property in a different message to jump to this message once it has timed out
|
||||
- `frames` Defines a list of strings specifying the list of frames in the animation of this message. They are defined in `file.frame` format where `file` is the file the frame is located in (which would be `file.json`) and `frame` is the name of the frame in that file to use
|
||||
- `interval` *(Optional)* defines the delay between frames. Setting to `0` (default) disables the animation and only shows the first frame
|
||||
- `random` *(Optional)* defines if the animation should begin on a random frame (`true`) or the first frame (`false`, default)
|
||||
- `shuffle` *(Optional)* defines if the animation should switch between frames sequentially (`false`, default) or randomly (`true`)
|
||||
- `timeout` *(Optional)* defines how many ticks the animation should play before stopping or switching to `"next"` (default 500)
|
||||
- `weight` *(Optional)* defines the random probability of choosing this message over any other messages in `"all"` and the list of messages for the specific listener the message is playing on. Default is 1.0
|
||||
- `next` *(Optional)* defines the `"name"` of the message to play once this message times out (`timeout`). Set to `"any"` to pick any message, or set to `null` to stop the animation once `timeout` is reached. Default is null
|
||||
|
||||
### Frames.json:
|
||||
|
||||
**You can name this file anything you want, and you can create more than one. In 'messages.json' just define the frame as, for example, 'file.name' and it will look in a file called 'file.json' for a frame named 'name'. The example 'frames.frame1' in 'messages.json' will load 'frame1' from this default file called 'frames.json'**
|
||||
|
||||
```json
|
||||
{
|
||||
"frame1": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 0,
|
||||
"icon_spriteY": 0,
|
||||
"online": "default",
|
||||
"max": "default",
|
||||
"players": "default",
|
||||
"text0": "&7An Eaglercraft server",
|
||||
"text1": "&0!!!!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame2": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 1,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 0.0, 0.0, 0.15 ],
|
||||
"online": 10,
|
||||
"players": [ "fake player 1", "fake player 2" ],
|
||||
"text0": "&6&nAn&r &7Eaglercraft server",
|
||||
"text1": "&0!!&8!&0!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame3": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 2,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 0.0, 0.0, 0.15 ],
|
||||
"icon_tint": [ 0.8, 0.8, 1.0 ],
|
||||
"online": 20,
|
||||
"players": [],
|
||||
"text0": "&7An &6&nEaglercraft&r &7server",
|
||||
"text1": "&0!&8!!&0!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame4": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 3,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 1.0, 0.0, 0.15 ],
|
||||
"icon_tint": [ 0.8, 0.8, 1.0, 0.8 ],
|
||||
"online": 30,
|
||||
"players": "default",
|
||||
"text0": "&7An Eaglercraft &6&nserver&r",
|
||||
"text1": "&8!!!&0!&8Running EaglerMOTD plugin"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Every frame will retrieve the values from the previous frame in the message for the default value for every variable**
|
||||
|
||||
- `text0` *(Optional)* Changes the first line of text in the server's current MOTD
|
||||
|
||||
- `text1` *(Optional)* Changes the second line of text in the server's current MOTD
|
||||
|
||||
- `online` *(Optional)* Changes the number of online players, use `"default"` to reset it
|
||||
|
||||
- `max` *(Optional)* Changes the max number of players in the MOTD, use `"default"` to reset it
|
||||
|
||||
- `players` *(Optional)* Changes the list of players shown when the mouse is hovering over the online/max count in the multiplayer screen. use `"default"` to reset it and show the real list of players instead of spoofing it
|
||||
|
||||
- `icon` *(Optional)* A JPEG/PNG/BMP/GIF to display as the server icon. The icon must be at least 64x64 pixels. **Transparency is supported.** The top left 64x64 pixels of the image are displayed if the image is larger than 64x64 pixels. **Animated GIF files are not supported, they load but only display the first frame.** Setting the icon resets the values of `icon_spriteX`, `icon_spriteY`, `icon_color`, `icon_tint`, `icon_flipX`, `icon_flipY`, and `icon_rotate` **to their default values.** Setting to `"none"` will reset everything and set the icon to be black and 100% transparent. **The icon's file name is relative to the folder EaglercraftBungee is currently running in**, not the folder where the JSON file is stored.
|
||||
|
||||
- `icon_spriteX` *(Optional)* defines the X coordinate to read a 64x64 pixel portion of the current `"icon"` file, if the file is larger than 64x64. The value is multiplied by 64 to get the exact pixel coordinate in the image to read from. `"icon_spriteX": 2` will read a 64x64 pixel portion of a larger image beginning at 128 pixels X and 0 pixels Y of the current `"icon"` file. Default is 0
|
||||
- `icon_spriteY` *(Optional)* defines the Y coordinate to read a 64x64 pixel portion of the current `"icon"` file, if the file is larger than 64x64. The value is multiplied by 64 to get the exact pixel coordinate in the image to read from. `"icon_spriteY": 2` will read a 64x64 pixel portion of a larger image beginning at 0 pixels X and 128 pixels Y of the current `"icon"` file. Default is 0. Setting, for example, `"icon_spriteX": 1` and `"icon_spriteY": 2` will read a 64x64 pixel portion of the current `"icon"` file beginning at 64 pixels X and 128 pixels Y.
|
||||
|
||||
- `icon_pixelX` *(Optional)* defines the exact X pixel coordinate to read a 64x64 pixel portion of the current `"icon"` file, if the file is larger than 64x64. Unlike `icon_spriteX`, setting this value will not multiply the input value by 64, it will read from the exact coordinate in the image. **Overrides icon_spriteX**
|
||||
- `icon_pixelY` *(Optional)* defines the exact Y pixel coordinate to read a 64x64 pixel portion of the current `"icon"` file, if the file is larger than 64x64. Unlike `icon_spriteY`, setting this value will not multiply the input value by 64, it will read from the exact coordinate in the image. **Overrides icon_spriteY**
|
||||
|
||||
- `icon_color` *(Optional)* mixes an RGBA color with the current `"icon"`, or displays the color directly if `"icon"` is `"none"`. `[1.0, 1.0, 1.0]` displays white, `[0.0, 0.0, 0.0]` displays black, `[0.0, 1.0, 0.0]` displays green, `[0.0, 1.0, 0.0, 0.5]` displays green with 50% transparency, blending it with the color of the current `"icon"` file's pixels if it is set.
|
||||
|
||||
- `icon_tint` *(Optional)* multiplies an RGBA color by all the pixels in the current `"icon"` and/or `"icon_color"`. `[0.0, 0.0, 1.0]` would make the icon's pixels blue-colored, `[1.0, 0.0, 0.0]` would make the icon's pixels red-colored, `[0.0, 1.0, 0.0, 0.5]` would make the icon's pixels green-colored and 50% transparent. `[2.0, 2.0, 2.0]` would double the brightness of the icon.
|
||||
|
||||
- `icon_flipX` *(Optional)* flips the pixels of the icon displayed horizontally
|
||||
|
||||
- `icon_flipY` *(Optional)* flips the pixels of the icon displayed vertically
|
||||
|
||||
- `icon_rotate` *(Optional)* rotates the icon 90°, 180°, or 270° clockwise (`0` = 0°, `1` = 90°, `2` = 180°, `3` = 270°)
|
||||
|
||||
### Queries.json:
|
||||
|
||||
**This has nothing to do with MOTD, skip this part if you're just trying to add an animated MOTD**
|
||||
|
||||
**This file allows you to configure custom** `Accept:` **handlers to EaglercraftBungee to provide more custom statistics to 3rd party server lists and crawlers**
|
||||
|
||||
```json
|
||||
{
|
||||
"queries": {
|
||||
"ExampleQuery1": {
|
||||
"type": "ExampleQuery1_result",
|
||||
"string": "This is a string"
|
||||
},
|
||||
"ExampleQuery2": {
|
||||
"type": "ExampleQuery2_result",
|
||||
"txt": "query2.txt"
|
||||
},
|
||||
"ExampleQuery3": {
|
||||
"type": "ExampleQuery3_result",
|
||||
"string": "This query returns binary",
|
||||
"file": "binary.dat"
|
||||
},
|
||||
"ExampleQuery4": {
|
||||
"type": "ExampleQuery4_result",
|
||||
"json": "query4.json"
|
||||
},
|
||||
"ExampleQuery5": {
|
||||
"type": "ExampleQuery5_result",
|
||||
"json": {
|
||||
"key1": "value1",
|
||||
"key2": "value2"
|
||||
}
|
||||
},
|
||||
"ExampleQuery6": {
|
||||
"type": "ExampleQuery6_result",
|
||||
"json": {
|
||||
"desc": "This query returns JSON and a file",
|
||||
"filename": "test_file.dat",
|
||||
"size": 69
|
||||
},
|
||||
"file": "test_file.dat"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`"queries"` contains a JSON object, each variable in this JSON object is the name of a query and the value is a JSON object containing the type of response and the content of the `"data"` value in the response
|
||||
|
||||
**Here is an example of a server's response to a generic query:**
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "<type here>",
|
||||
"data": "<data here>",
|
||||
"vers": "0.1.0",
|
||||
"name": "EaglercraftBungee Server",
|
||||
"time": 1648946954405,
|
||||
"brand": "Eagtek",
|
||||
"cracked": true
|
||||
}
|
||||
```
|
||||
|
||||
`"type"` **is just a generic string you can set to hint to the client what kind of response you are sending, and** `"data"` **stores the actually data of the response, and can be either a string or JSON object**
|
||||
|
||||
**Binary WebSocket packets can also be sent to a client, their format can be completely arbitrary and arrive containing the same raw unformatted data that was sent. They accompany a regular JSON response, the** `"type"` **and/or** `"data"` **value of the JSON response can be used to hint to the client when a raw binary packet is present**
|
||||
|
||||
The `"vers"`, `"name"`, `"time"`, `"brand"`, and `"cracked"` values are added internally by the server and cannot be changed
|
||||
|
||||
### Queries.json Format:
|
||||
|
||||
The file contains a JSON object with a `"queries"` value which contains a map of keys matching `Accept:` types to JSON objects
|
||||
|
||||
The JSON objects contain the `"type"` of response to send and what the `"data"` for that response should be. Also, a path to a binary file can be specified.
|
||||
|
||||
**All files specified in queries.json are RELOADED AUTOMATICALLY when changes are detected.** This allows you to dynamically update the response for certain queries without `motd-reload` because you can just edit the file the query is configured to read and it will update the version cached in memory automatically.
|
||||
|
||||
To add or edit an entry in queries.json, you need to define:
|
||||
- `type`, which determines the string in the `"type"` field of the response sent to the client
|
||||
|
||||
Then, you must define **one** of:
|
||||
- `json` *(object)* A JSON object to send as `"data"` in the response
|
||||
- `json` *(string)* A path to a file (relative to your EaglercraftBungee folder) to parse as a JSON object and send as JSON as `"data"` in the response
|
||||
- `txt` A path to a text file (relative to your EaglercraftBungee folder) to send as a string as `"data"` in the response
|
||||
- `string` A string to send as `"data"` in the response
|
||||
|
||||
Optionally, you can define:
|
||||
- `file` A path to an additional binary file (relative to your EaglercraftBungee folder) to send as a binary WebSocket packet after sending the first JSON response containing the `"data"` from the required `json`, `txt`, or `string` value. This file is also reloaded automatically
|
||||
|
||||
**Use** `motd-reload` **to reload queries.json**
|
||||
|
||||
## Compiling and Contributing
|
||||
|
||||
First, download the latest [EaglercraftBungee jar](https://github.com/LAX1DUDE/eaglercraft/blob/main/stable-download/java/bungee_command/bungee-dist.jar) in stable-download on [LAX1DUDE/eaglercraft](https://github.com/LAX1DUDE/eaglercraft/)
|
||||
|
||||
**Make a new java project in Eclipse/IDEA/etc and add 'src' folder in this repository as the source code folder**
|
||||
|
||||
**Then, add your EaglercraftBungee jar ([bungee-dist.jar](https://github.com/LAX1DUDE/eaglercraft/blob/main/stable-download/java/bungee_command/bungee-dist.jar)) to the java project's Build Path and refresh**
|
||||
|
||||
Export the contents of 'src' folder of the project to a JAR file to compile the plugin
|
||||
|
||||
**For a PR:** Tabs, not spaces, and format the code like the Eclipse auto format tool on factory settings.
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"frame1": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 0,
|
||||
"icon_spriteY": 0,
|
||||
"online": "default",
|
||||
"max": "default",
|
||||
"players": "default",
|
||||
"text0": "&7An Eaglercraft server",
|
||||
"text1": "&0!!!!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame2": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 1,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 0.0, 0.0, 0.15 ],
|
||||
"online": 10,
|
||||
"players": [ "fake player 1", "fake player 2" ],
|
||||
"text0": "&6&nAn&r &7Eaglercraft server",
|
||||
"text1": "&0!!&8!&0!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame3": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 2,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 0.0, 0.0, 0.15 ],
|
||||
"icon_tint": [ 0.8, 0.8, 1.0 ],
|
||||
"online": 20,
|
||||
"players": [],
|
||||
"text0": "&7An &6&nEaglercraft&r &7server",
|
||||
"text1": "&0!&8!!&0!&8Running EaglerMOTD plugin"
|
||||
},
|
||||
"frame4": {
|
||||
"icon": "server-animation.png",
|
||||
"icon_spriteX": 3,
|
||||
"icon_spriteY": 0,
|
||||
"icon_color": [ 1.0, 1.0, 0.0, 0.15 ],
|
||||
"icon_tint": [ 0.8, 0.8, 1.0, 0.8 ],
|
||||
"online": 30,
|
||||
"players": "default",
|
||||
"text0": "&7An Eaglercraft &6&nserver&r",
|
||||
"text1": "&8!!!&0!&8Running EaglerMOTD plugin"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"close_socket_after": 1200,
|
||||
"max_sockets_per_ip": 10,
|
||||
"max_total_sockets": 256,
|
||||
"allow_banned_ips": false,
|
||||
"messages": {
|
||||
"all": [
|
||||
{
|
||||
"name": "default",
|
||||
"frames": [
|
||||
"frames.frame1",
|
||||
"frames.frame2",
|
||||
"frames.frame3",
|
||||
"frames.frame4"
|
||||
],
|
||||
"interval": 8,
|
||||
"random": false,
|
||||
"shuffle": false,
|
||||
"timeout": 500,
|
||||
"weight": 1.0,
|
||||
"next": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"queries": {
|
||||
"ExampleQuery1": {
|
||||
"type": "ExampleQuery1_result",
|
||||
"string": "This is a string"
|
||||
},
|
||||
"ExampleQuery2": {
|
||||
"type": "ExampleQuery2_result",
|
||||
"txt": "query2.txt"
|
||||
},
|
||||
"ExampleQuery3": {
|
||||
"type": "ExampleQuery3_result",
|
||||
"string": "This query returns binary",
|
||||
"file": "binary.dat"
|
||||
},
|
||||
"ExampleQuery4": {
|
||||
"type": "ExampleQuery4_result",
|
||||
"json": "query4.json"
|
||||
},
|
||||
"ExampleQuery5": {
|
||||
"type": "ExampleQuery5_result",
|
||||
"json": {
|
||||
"key1": "value1",
|
||||
"key2": "value2"
|
||||
}
|
||||
},
|
||||
"ExampleQuery6": {
|
||||
"type": "ExampleQuery6_result",
|
||||
"json": {
|
||||
"desc": "This query returns JSON and a file",
|
||||
"filename": "test_file.dat",
|
||||
"size": 69
|
||||
},
|
||||
"file": "test_file.dat"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class BitmapFile {
|
||||
|
||||
public final String name;
|
||||
public final int[][] frame;
|
||||
public final int w, h;
|
||||
|
||||
public BitmapFile(String name, int[][] frame, int w, int h) {
|
||||
this.name = name;
|
||||
this.frame = frame;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public static final Map<String, BitmapFile> bitmapCache = new HashMap();
|
||||
|
||||
public static BitmapFile getCachedIcon(String name) {
|
||||
BitmapFile ret = bitmapCache.get(name);
|
||||
if(ret == null) {
|
||||
File f = new File(name);
|
||||
if(f.exists()) {
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(f);
|
||||
int w = img.getWidth();
|
||||
int h = img.getHeight();
|
||||
if(w < 64 || h < 64) {
|
||||
System.err.println("[EaglerMOTD] Icon '" + name + "' must be at least be 64x64 pixels large (it is " + w + "x" + h + ")");
|
||||
}else {
|
||||
int[][] load = new int[w][h];
|
||||
for(int y = 0; y < h; ++y) {
|
||||
for(int x = 0; x < w; ++x) {
|
||||
load[x][y] = img.getRGB(x, y);
|
||||
}
|
||||
}
|
||||
ret = new BitmapFile(name, load, w, h);
|
||||
bitmapCache.put(name, ret);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("[EaglerMOTD] Could not load icon file: '" + name + "'");
|
||||
System.err.println("[EaglerMOTD] Place the file in the same directory as 'messages.json'");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int[] getSprite(int x, int y) {
|
||||
if(x < 0 || y < 0) {
|
||||
return null;
|
||||
}
|
||||
int offsetX = x;
|
||||
int offsetY = y;
|
||||
if(offsetX + 64 > w || offsetY + 64 > h) {
|
||||
return null;
|
||||
}
|
||||
int[] ret = new int[64 * 64];
|
||||
for(int i = 0; i < ret.length; ++i) {
|
||||
int xx = i % 64;
|
||||
int yy = i / 64;
|
||||
ret[i] = frame[offsetX + xx][offsetY + yy];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int[] makeColor(int[] in, float r, float g, float b, float a) {
|
||||
if(r < 0.0f) r = 0.0f;
|
||||
if(r > 1.0f) r = 1.0f;
|
||||
if(g < 0.0f) g = 0.0f;
|
||||
if(g > 1.0f) g = 1.0f;
|
||||
if(b < 0.0f) b = 0.0f;
|
||||
if(b > 1.0f) b = 1.0f;
|
||||
if(a < 0.0f) a = 0.0f;
|
||||
if(a > 1.0f) a = 1.0f;
|
||||
int c = ((int)(a*255.0f) << 24) | ((int)(r*255.0f) << 16) | ((int)(g*255.0f) << 8) | (int)(b*255.0f);
|
||||
for(int i = 0; i < in.length; ++i) {
|
||||
in[i] = c;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
public static int[] applyColor(int[] in, float r, float g, float b, float a) {
|
||||
for(int i = 0; i < in.length; ++i) {
|
||||
float rr = ((in[i] >> 16) & 0xFF) / 255.0f;
|
||||
float gg = ((in[i] >> 8) & 0xFF) / 255.0f;
|
||||
float bb = (in[i] & 0xFF) / 255.0f;
|
||||
float aa = ((in[i] >> 24) & 0xFF) / 255.0f;
|
||||
rr = r * a + rr * (1.0f - a);
|
||||
gg = g * a + gg * (1.0f - a);
|
||||
bb = b * a + bb * (1.0f - a);
|
||||
aa = a + aa * (1.0f - a);
|
||||
if(rr < 0.0f) rr = 0.0f;
|
||||
if(rr > 1.0f) rr = 1.0f;
|
||||
if(gg < 0.0f) gg = 0.0f;
|
||||
if(gg > 1.0f) gg = 1.0f;
|
||||
if(bb < 0.0f) bb = 0.0f;
|
||||
if(bb > 1.0f) bb = 1.0f;
|
||||
if(aa < 0.0f) aa = 0.0f;
|
||||
if(aa > 1.0f) aa = 1.0f;
|
||||
in[i] = ((int)(aa*255.0f) << 24) | ((int)(rr*255.0f) << 16) | ((int)(gg*255.0f) << 8) | (int)(bb*255.0f);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
public static int[] applyTint(int[] in, float r, float g, float b, float a) {
|
||||
for(int i = 0; i < in.length; ++i) {
|
||||
float rr = ((in[i] >> 16) & 0xFF) / 255.0f * r;
|
||||
float gg = ((in[i] >> 8) & 0xFF) / 255.0f * g;
|
||||
float bb = (in[i] & 0xFF) / 255.0f * b;
|
||||
float aa = ((in[i] >> 24) & 0xFF) / 255.0f * a;
|
||||
if(rr < 0.0f) rr = 0.0f;
|
||||
if(rr > 1.0f) rr = 1.0f;
|
||||
if(gg < 0.0f) gg = 0.0f;
|
||||
if(gg > 1.0f) gg = 1.0f;
|
||||
if(bb < 0.0f) bb = 0.0f;
|
||||
if(bb > 1.0f) bb = 1.0f;
|
||||
if(aa < 0.0f) aa = 0.0f;
|
||||
if(aa > 1.0f) aa = 1.0f;
|
||||
in[i] = ((int)(aa*255.0f) << 24) | ((int)(rr*255.0f) << 16) | ((int)(gg*255.0f) << 8) | (int)(bb*255.0f);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
private static final int[] flipTmpBuffer = new int[64];
|
||||
|
||||
public static int[] flipX(int[] newIcon) {
|
||||
for(int y = 0; y < 64; ++y) {
|
||||
int o = y * 64;
|
||||
System.arraycopy(newIcon, o, flipTmpBuffer, 0, 64);
|
||||
for(int i = 0; i < 64; ++i) {
|
||||
newIcon[o + i] = flipTmpBuffer[63 - i];
|
||||
}
|
||||
}
|
||||
return newIcon;
|
||||
}
|
||||
|
||||
public static int[] flipY(int[] newIcon) {
|
||||
for(int x = 0; x < 64; ++x) {
|
||||
for(int i = 0; i < 64; ++i) {
|
||||
flipTmpBuffer[i] = newIcon[i * 64 + x];
|
||||
}
|
||||
for(int i = 0; i < 64; ++i) {
|
||||
newIcon[i * 64 + x] = flipTmpBuffer[63 - i];
|
||||
}
|
||||
}
|
||||
return newIcon;
|
||||
}
|
||||
|
||||
private static int[] transpose(int[] in) {
|
||||
int[] ret = new int[64*64];
|
||||
for(int y = 0; y < 64; ++y) {
|
||||
for(int x = 0; x < 64; ++x) {
|
||||
ret[x * 64 + y] = in[y * 64 + x];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int[] rotate(int[] newIcon, int rotate) {
|
||||
rotate = rotate % 4;
|
||||
if(rotate == 1) {
|
||||
newIcon = flipX(transpose(newIcon));
|
||||
}else if(rotate == 2) {
|
||||
newIcon = flipY(flipX(newIcon));
|
||||
}else if(rotate == 3) {
|
||||
newIcon = flipY(transpose(newIcon));
|
||||
}
|
||||
return newIcon;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class CommandMOTDReload extends Command {
|
||||
|
||||
public final EaglerMOTD plugin;
|
||||
|
||||
public CommandMOTDReload(EaglerMOTD plugin) {
|
||||
super("motd-reload", "eaglermotd.command.reload");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender paramCommandSender, String[] paramArrayOfString) {
|
||||
try {
|
||||
plugin.loadConfiguration(paramCommandSender);
|
||||
} catch (Exception e) {
|
||||
paramCommandSender.sendMessage(ChatColor.RED + "[EaglerMOTD] Failed to reload! " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.event.WebsocketMOTDEvent;
|
||||
import net.md_5.bungee.api.event.WebsocketQueryEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.command.ConsoleCommandSender;
|
||||
import net.md_5.bungee.eaglercraft.BanList;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class EaglerMOTD extends Plugin implements Listener {
|
||||
|
||||
public static final Map<String,List<MessagePoolEntry>> messages = new HashMap();
|
||||
public static final Map<String,MessagePool> messagePools = new HashMap();
|
||||
public static final Map<String,JSONObject> framesCache = new HashMap();
|
||||
public static final Map<String,QueryType> queryTypes = new HashMap();
|
||||
public static EaglerMOTD instance = null;
|
||||
public static int close_socket_after = 1200;
|
||||
public static int max_sockets_per_ip = 10;
|
||||
public static int max_total_sockets = 256;
|
||||
public static boolean allow_banned_ips = false;
|
||||
|
||||
public final Timer tickTimer = new Timer("MOTD Tick Timer");
|
||||
public final List<MOTDConnection> motdConnections = new LinkedList();
|
||||
|
||||
public EaglerMOTD() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void loadConfiguration(CommandSender cs) throws Exception {
|
||||
messages.clear();
|
||||
messagePools.clear();
|
||||
framesCache.clear();
|
||||
queryTypes.clear();
|
||||
|
||||
BitmapFile.bitmapCache.clear();
|
||||
QueryCache.flush();
|
||||
|
||||
synchronized(motdConnections) {
|
||||
if(motdConnections.size() > 0) {
|
||||
for(MOTDConnection con : motdConnections) {
|
||||
con.close();
|
||||
}
|
||||
motdConnections.clear();
|
||||
}
|
||||
}
|
||||
|
||||
getDataFolder().mkdirs();
|
||||
|
||||
byte[] damn = new byte[4096];
|
||||
int i;
|
||||
|
||||
File msgs = new File(getDataFolder(), "messages.json");
|
||||
|
||||
if(!msgs.exists()) {
|
||||
OutputStream msgsNew = new FileOutputStream(msgs);
|
||||
InputStream msgsDefault = EaglerMOTD.class.getResourceAsStream("/default_messages.json");
|
||||
while((i = msgsDefault.read(damn)) != -1) {
|
||||
msgsNew.write(damn, 0, i);
|
||||
}
|
||||
msgsNew.close();
|
||||
msgsDefault.close();
|
||||
File f2 = new File(getDataFolder(), "frames.json");
|
||||
if(!f2.exists()) {
|
||||
msgsNew = new FileOutputStream(f2);
|
||||
msgsDefault = EaglerMOTD.class.getResourceAsStream("/default_frames.json");
|
||||
while((i = msgsDefault.read(damn)) != -1) {
|
||||
msgsNew.write(damn, 0, i);
|
||||
}
|
||||
msgsNew.close();
|
||||
msgsDefault.close();
|
||||
}
|
||||
f2 = new File(getDataFolder(), "queries.json");
|
||||
if(!f2.exists()) {
|
||||
msgsNew = new FileOutputStream(f2);
|
||||
msgsDefault = EaglerMOTD.class.getResourceAsStream("/default_queries.json");
|
||||
while((i = msgsDefault.read(damn)) != -1) {
|
||||
msgsNew.write(damn, 0, i);
|
||||
}
|
||||
msgsNew.close();
|
||||
msgsDefault.close();
|
||||
}
|
||||
f2 = new File("server-animation.png");
|
||||
if(!f2.exists()) {
|
||||
msgsNew = new FileOutputStream(f2);
|
||||
msgsDefault = EaglerMOTD.class.getResourceAsStream("/server-icons-test.png");
|
||||
while((i = msgsDefault.read(damn)) != -1) {
|
||||
msgsNew.write(damn, 0, i);
|
||||
}
|
||||
msgsNew.close();
|
||||
msgsDefault.close();
|
||||
}
|
||||
}
|
||||
if(!msgs.exists()) {
|
||||
throw new NullPointerException("messages.json is missing and could not be created");
|
||||
}
|
||||
|
||||
InputStream is = new FileInputStream(msgs);
|
||||
ByteArrayOutputStream bao = new ByteArrayOutputStream(is.available());
|
||||
while((i = is.read(damn)) != -1) {
|
||||
bao.write(damn, 0, i);
|
||||
}
|
||||
is.close();
|
||||
|
||||
JSONObject msgsObj = new JSONObject(new String(bao.toByteArray(), StandardCharsets.UTF_8));
|
||||
framesCache.put("messages", msgsObj);
|
||||
close_socket_after = msgsObj.optInt("close_socket_after", 1200);
|
||||
max_sockets_per_ip = msgsObj.optInt("max_sockets_per_ip", 10);
|
||||
max_total_sockets = msgsObj.optInt("max_total_sockets", 256);
|
||||
allow_banned_ips = msgsObj.optBoolean("allow_banned_ips", false);
|
||||
msgsObj = msgsObj.getJSONObject("messages");
|
||||
|
||||
for(String ss : msgsObj.keySet()) {
|
||||
try {
|
||||
List<MessagePoolEntry> poolEntries = new LinkedList();
|
||||
JSONArray arr = msgsObj.getJSONArray(ss);
|
||||
for(int j = 0, l = arr.length(); j < l; ++j) {
|
||||
JSONObject entry = arr.getJSONObject(j);
|
||||
List<JSONObject> frames = new LinkedList();
|
||||
JSONArray framesJSON = entry.getJSONArray("frames");
|
||||
for(int k = 0, l2 = framesJSON.length(); k < l2; ++k) {
|
||||
JSONObject frame = resolveFrame(framesJSON.getString(k), cs);
|
||||
if(frame != null) {
|
||||
frames.add(frame);
|
||||
}
|
||||
}
|
||||
if(frames.size() > 0) {
|
||||
poolEntries.add(new MessagePoolEntry(entry.optInt("interval", 0), entry.optInt("timeout", 500),
|
||||
entry.optBoolean("random", false), entry.optBoolean("shuffle", false), entry.optFloat("weight", 1.0f),
|
||||
entry.optString("next", null), frames, entry.optString("name", null)));
|
||||
}else {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Message '" + ss + "' has no frames!");
|
||||
}
|
||||
}
|
||||
if(poolEntries.size() > 0) {
|
||||
List<MessagePoolEntry> existingList = messages.get(ss);
|
||||
if(existingList == null) {
|
||||
existingList = poolEntries;
|
||||
messages.put(ss, existingList);
|
||||
}else {
|
||||
existingList.addAll(poolEntries);
|
||||
}
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Could not parse messages for '" + ss + "' " + t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Collection<ListenerInfo> listeners = getProxy().getConfigurationAdapter().getListeners();
|
||||
|
||||
String flag = null;
|
||||
for(String s : messages.keySet()) {
|
||||
if(!s.equals("all")) {
|
||||
boolean flag2 = false;
|
||||
for(ListenerInfo l : listeners) {
|
||||
if(s.equals(makeListenerString(l.getHost()))) {
|
||||
flag2 = true;
|
||||
}
|
||||
}
|
||||
if(!flag2) {
|
||||
flag = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(flag != null) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Listener '" + flag + "' does not exist!");
|
||||
String hostsString = "";
|
||||
for(ListenerInfo l : listeners) {
|
||||
if(hostsString.length() > 0) {
|
||||
hostsString += " ";
|
||||
}
|
||||
hostsString += makeListenerString(l.getHost());
|
||||
}
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Listeners configured: " + ChatColor.YELLOW + hostsString);
|
||||
}
|
||||
|
||||
for(ListenerInfo l : listeners) {
|
||||
String name = makeListenerString(l.getHost());
|
||||
MessagePool m = new MessagePool(name);
|
||||
List<MessagePoolEntry> e = messages.get("all");
|
||||
if(e != null) {
|
||||
m.messagePool.addAll(e);
|
||||
}
|
||||
e = messages.get(name);
|
||||
if(e != null) {
|
||||
m.messagePool.addAll(e);
|
||||
}
|
||||
if(m.messagePool.size() > 0) {
|
||||
cs.sendMessage(ChatColor.GREEN + "[EaglerMOTD] Loaded " + m.messagePool.size() + " messages for " + name);
|
||||
messagePools.put(name, m);
|
||||
}
|
||||
}
|
||||
|
||||
msgs = new File(getDataFolder(), "queries.json");
|
||||
if(msgs.exists()) {
|
||||
try {
|
||||
is = new FileInputStream(msgs);
|
||||
bao = new ByteArrayOutputStream(is.available());
|
||||
while((i = is.read(damn)) != -1) {
|
||||
bao.write(damn, 0, i);
|
||||
}
|
||||
is.close();
|
||||
JSONObject queriesObject = new JSONObject(new String(bao.toByteArray(), StandardCharsets.UTF_8));
|
||||
JSONObject queriesQueriesObject = queriesObject.getJSONObject("queries");
|
||||
for(String s : queriesQueriesObject.keySet()) {
|
||||
queryTypes.put(s.toLowerCase(), new QueryType(s, queriesQueriesObject.getJSONObject(s)));
|
||||
}
|
||||
if(queryTypes.size() > 0) {
|
||||
cs.sendMessage(ChatColor.GREEN + "[EaglerMOTD] Loaded " + queryTypes.size() + " query types");
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Queries were not loaded: " + t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String makeListenerString(InetSocketAddress addr) {
|
||||
InetAddress addrHost = addr.getAddress();
|
||||
if(addrHost instanceof Inet6Address) {
|
||||
return "[" + addrHost.getHostAddress() + "]:" + addr.getPort();
|
||||
}else {
|
||||
return addrHost.getHostAddress() + ":" + addr.getPort();
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject resolveFrame(String s, CommandSender cs) {
|
||||
int i = s.indexOf('.');
|
||||
if(i == -1) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Frame '" + s + "' cannot be found! (it does not specify a filename)");
|
||||
return null;
|
||||
}
|
||||
String f = s.substring(0, i);
|
||||
JSONObject fc = framesCache.get(f);
|
||||
if(fc == null) {
|
||||
File ff = new File(getDataFolder(), f + ".json");
|
||||
if(!ff.exists()) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] File '" + f + ".json' cannot be found!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] damn = new byte[4096];
|
||||
InputStream is = new FileInputStream(ff);
|
||||
ByteArrayOutputStream bao = new ByteArrayOutputStream(is.available());
|
||||
int j;
|
||||
while((j = is.read(damn)) != -1) {
|
||||
bao.write(damn, 0, j);
|
||||
}
|
||||
is.close();
|
||||
fc = new JSONObject(new String(bao.toByteArray(), StandardCharsets.UTF_8));
|
||||
framesCache.put(f, fc);
|
||||
}catch(Throwable t) {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] File '" + f + ".json' could not be loaded: " + t.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
f = s.substring(i + 1).trim();
|
||||
if(fc.has(f)) {
|
||||
return fc.getJSONObject(f);
|
||||
}else {
|
||||
cs.sendMessage(ChatColor.RED + "[EaglerMOTD] Frame '" + s + "' cannot be found!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void showRunCmd(CommandSender cs) {
|
||||
cs.sendMessage(ChatColor.YELLOW + "[EaglerMOTD] Use /motd-reload to reload your MOTD config files");
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
try {
|
||||
getProxy().getPluginManager().registerCommand(this, new CommandMOTDReload(this));
|
||||
loadConfiguration(ConsoleCommandSender.getInstance());
|
||||
} catch (Exception e) {
|
||||
System.err.println("[EaglerMOTD] Could not load!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
tickTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized(motdConnections) {
|
||||
Iterator<MOTDConnection> itr = motdConnections.iterator();
|
||||
while(itr.hasNext()) {
|
||||
MOTDConnection c = itr.next();
|
||||
try {
|
||||
if(!c.tick()) {
|
||||
itr.remove();
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Error ticking MOTD '" + (c.currentMessage == null ? "null" : c.currentMessage.name) + "' on listener " + c.listenerName);
|
||||
t.printStackTrace();
|
||||
c.close();
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, 0, 50l);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
tickTimer.cancel();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMOTD(WebsocketMOTDEvent evt) {
|
||||
if(!evt.getAccept().equalsIgnoreCase("motd") && !evt.getAccept().equalsIgnoreCase("motd.noicon")) {
|
||||
return;
|
||||
}
|
||||
MOTDConnection con = new MOTDConnection(evt.getListener(), evt.getMOTD());
|
||||
if(con.execute()) {
|
||||
if(max_total_sockets > 0) {
|
||||
synchronized(motdConnections) {
|
||||
while(motdConnections.size() >= max_total_sockets) {
|
||||
MOTDConnection c = motdConnections.remove(motdConnections.size() - 1);
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
InetAddress addr = con.motd.getRemoteAddress();
|
||||
boolean flag = false;
|
||||
for(BanList.IPBan b : BanList.blockedBans) {
|
||||
if(b.checkBan(addr)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag) {
|
||||
synchronized(motdConnections) {
|
||||
motdConnections.add(0, con);
|
||||
}
|
||||
}else {
|
||||
if(allow_banned_ips || !BanList.checkIpBanned(addr).isBanned()) {
|
||||
synchronized(motdConnections) {
|
||||
if(max_sockets_per_ip > 0) {
|
||||
int i = 0;
|
||||
int c = 0;
|
||||
while(i < motdConnections.size()) {
|
||||
if(motdConnections.get(i).motd.getRemoteAddress().equals(addr)) {
|
||||
++c;
|
||||
if(c >= max_sockets_per_ip) {
|
||||
motdConnections.remove(i).close();
|
||||
--i;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
motdConnections.add(0, con);
|
||||
}
|
||||
}else {
|
||||
con.motd.keepAlive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuery(WebsocketQueryEvent evt) {
|
||||
if(evt.getQuery().isClosed() || evt.getAccept().equalsIgnoreCase("MOTD")) {
|
||||
return;
|
||||
}
|
||||
QueryType t = queryTypes.get(evt.getAccept().toLowerCase());
|
||||
if(t != null) {
|
||||
t.doQuery(evt.getQuery());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.MOTD;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class MOTDConnection {
|
||||
|
||||
public final ListenerInfo listener;
|
||||
public final String listenerName;
|
||||
public final MOTD motd;
|
||||
|
||||
public MessagePoolEntry currentMessage = null;
|
||||
public int messageTimeTimer = 0;
|
||||
public int messageIntervalTimer = 0;
|
||||
public int currentFrame = 0;
|
||||
public int ageTimer = 0;
|
||||
|
||||
public BitmapFile bitmap = null;
|
||||
public int spriteX = 0;
|
||||
public int spriteY = 0;
|
||||
public boolean flipX = false;
|
||||
public boolean flipY = false;
|
||||
public int rotate = 0;
|
||||
public float[] color = new float[] { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
public float[] tint = new float[] { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
private Random rand = null;
|
||||
|
||||
public MOTDConnection(ListenerInfo l, MOTD m) {
|
||||
this.motd = m;
|
||||
this.listener = l;
|
||||
this.listenerName = EaglerMOTD.makeListenerString(l.getHost());
|
||||
}
|
||||
|
||||
public boolean execute() {
|
||||
MessagePool p = EaglerMOTD.messagePools.get(listenerName);
|
||||
if(p == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
messageTimeTimer = 0;
|
||||
messageIntervalTimer = 0;
|
||||
currentMessage = p.pickDefault();
|
||||
if(currentMessage.random || currentMessage.shuffle) {
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
currentFrame = currentMessage.random ? rand.nextInt(currentMessage.frames.size()) : 0;
|
||||
|
||||
applyFrame(currentMessage.frames.get(currentFrame));
|
||||
if(currentMessage.interval > 0 || currentMessage.next != null) {
|
||||
this.motd.keepAlive(true);
|
||||
return true;
|
||||
}else {
|
||||
this.motd.keepAlive(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tick() {
|
||||
ageTimer++;
|
||||
if(this.motd.isClosed()) {
|
||||
return false;
|
||||
}
|
||||
if(ageTimer > EaglerMOTD.close_socket_after) {
|
||||
this.motd.close();
|
||||
return false;
|
||||
}
|
||||
messageTimeTimer++;
|
||||
if(messageTimeTimer >= currentMessage.timeout) {
|
||||
if(currentMessage.next != null) {
|
||||
if(currentMessage.next.equalsIgnoreCase("any") || currentMessage.next.equalsIgnoreCase("random")) {
|
||||
MessagePool p = EaglerMOTD.messagePools.get(listenerName);
|
||||
if(p == null) {
|
||||
this.motd.close();
|
||||
return false;
|
||||
}
|
||||
if(p.messagePool.size() > 1) {
|
||||
MessagePoolEntry m;
|
||||
do {
|
||||
m = p.pickNew();
|
||||
}while(m == currentMessage);
|
||||
currentMessage = m;
|
||||
}
|
||||
}else {
|
||||
if(!changeMessageTo(listenerName, currentMessage.next)) {
|
||||
boolean flag = false;
|
||||
for(String s : EaglerMOTD.messages.keySet()) {
|
||||
if(!s.equalsIgnoreCase(listenerName) && changeMessageTo(s, currentMessage.next)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag) {
|
||||
this.motd.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(currentMessage == null) {
|
||||
this.motd.close();
|
||||
return false;
|
||||
}
|
||||
messageTimeTimer = 0;
|
||||
messageIntervalTimer = 0;
|
||||
if(rand == null && (currentMessage.random || currentMessage.shuffle)) {
|
||||
rand = new Random();
|
||||
}
|
||||
currentFrame = currentMessage.random ? rand.nextInt(currentMessage.frames.size()) : 0;
|
||||
applyFrame(currentMessage.frames.get(currentFrame));
|
||||
motd.sendToUser();
|
||||
if(currentMessage.next == null && currentMessage.interval <= 0) {
|
||||
motd.close();
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
this.motd.close();
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
messageIntervalTimer++;
|
||||
if(currentMessage.interval > 0 && messageIntervalTimer >= currentMessage.interval) {
|
||||
messageIntervalTimer = 0;
|
||||
if(currentMessage.frames.size() > 1) {
|
||||
if(currentMessage.shuffle) {
|
||||
int i;
|
||||
do {
|
||||
i = rand.nextInt(currentMessage.frames.size());
|
||||
}while(i == currentFrame);
|
||||
currentFrame = i;
|
||||
}else {
|
||||
++currentFrame;
|
||||
if(currentFrame >= currentMessage.frames.size()) {
|
||||
currentFrame = 0;
|
||||
}
|
||||
}
|
||||
applyFrame(currentMessage.frames.get(currentFrame));
|
||||
motd.sendToUser();
|
||||
}
|
||||
}
|
||||
if(currentMessage.next == null && currentMessage.interval <= 0) {
|
||||
motd.close();
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changeMessageTo(String group, String s) {
|
||||
if(group == null || s == null) {
|
||||
return false;
|
||||
}
|
||||
List<MessagePoolEntry> lst = EaglerMOTD.messages.get(group);
|
||||
if(lst == null) {
|
||||
return false;
|
||||
}
|
||||
for(MessagePoolEntry m : lst) {
|
||||
if(m.name.equalsIgnoreCase(s)) {
|
||||
currentMessage = m;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void applyFrame(JSONObject frame) {
|
||||
boolean shouldPush = false;
|
||||
Object v = frame.opt("online");
|
||||
if(v != null) {
|
||||
if(v instanceof Number) {
|
||||
motd.setOnlinePlayers(((Number)v).intValue());
|
||||
}else {
|
||||
motd.setOnlinePlayers(BungeeCord.getInstance().getPlayers().size());
|
||||
}
|
||||
shouldPush = true;
|
||||
}
|
||||
v = frame.opt("max");
|
||||
if(v != null) {
|
||||
if(v instanceof Number) {
|
||||
motd.setMaxPlayers(((Number)v).intValue());
|
||||
}else {
|
||||
motd.setMaxPlayers(listener.getMaxPlayers());
|
||||
}
|
||||
shouldPush = true;
|
||||
}
|
||||
v = frame.opt("players");
|
||||
if(v != null) {
|
||||
if(v instanceof JSONArray) {
|
||||
List<String> players = new ArrayList();
|
||||
JSONArray vv = (JSONArray) v;
|
||||
for(int i = 0, l = vv.length(); i < l; ++i) {
|
||||
players.add(ChatColor.translateAlternateColorCodes('&', vv.getString(i)));
|
||||
}
|
||||
motd.setPlayerList(players);
|
||||
}else {
|
||||
List<String> players = new ArrayList();
|
||||
Collection<ProxiedPlayer> ppl = BungeeCord.getInstance().getPlayers();
|
||||
for(ProxiedPlayer pp : ppl) {
|
||||
players.add(pp.getDisplayName());
|
||||
if(players.size() >= 9) {
|
||||
players.add("" + ChatColor.GRAY + ChatColor.ITALIC + "(" + (ppl.size() - players.size()) + " more)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
motd.setPlayerList(players);
|
||||
}
|
||||
shouldPush = true;
|
||||
}
|
||||
String line = frame.optString("text0", frame.optString("text", null));
|
||||
if(line != null) {
|
||||
int ix = line.indexOf('\n');
|
||||
if(ix != -1) {
|
||||
motd.setLine1(ChatColor.translateAlternateColorCodes('&', line.substring(0, ix)));
|
||||
motd.setLine2(ChatColor.translateAlternateColorCodes('&', line.substring(ix + 1)));
|
||||
}else {
|
||||
motd.setLine1(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
line = frame.optString("text1", null);
|
||||
if(line != null) {
|
||||
motd.setLine2(ChatColor.translateAlternateColorCodes('&', line));
|
||||
}
|
||||
shouldPush = true;
|
||||
}
|
||||
if(!this.motd.getAccept().equalsIgnoreCase("motd.noicon")) {
|
||||
boolean shouldRenderIcon = false;
|
||||
Object icon = frame.opt("icon");
|
||||
if(icon != null) {
|
||||
String asString = (icon instanceof String) ? (String)icon : null;
|
||||
shouldRenderIcon = true;
|
||||
if(icon == JSONObject.NULL || asString == null || asString.equalsIgnoreCase("none") || asString.equalsIgnoreCase("default")
|
||||
|| asString.equalsIgnoreCase("null") || asString.equalsIgnoreCase("color")) {
|
||||
bitmap = null;
|
||||
}else {
|
||||
bitmap = BitmapFile.getCachedIcon(asString);
|
||||
}
|
||||
spriteX = spriteY = rotate = 0;
|
||||
flipX = flipY = false;
|
||||
color = new float[] { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
tint = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
}
|
||||
int sprtX = frame.optInt("icon_spriteX", -1) * 64;
|
||||
if(sprtX >= 0 && sprtX != spriteX) {
|
||||
shouldRenderIcon = true;
|
||||
spriteX = sprtX;
|
||||
}
|
||||
int sprtY = frame.optInt("icon_spriteY", -1) * 64;
|
||||
if(sprtY >= 0 && sprtY != spriteY) {
|
||||
shouldRenderIcon = true;
|
||||
spriteY = sprtY;
|
||||
}
|
||||
sprtX = frame.optInt("icon_pixelX", -1);
|
||||
if(sprtX >= 0 && sprtX != spriteX) {
|
||||
shouldRenderIcon = true;
|
||||
spriteX = sprtX;
|
||||
}
|
||||
sprtY = frame.optInt("icon_pixelY", -1);
|
||||
if(sprtY >= 0 && sprtY != spriteY) {
|
||||
shouldRenderIcon = true;
|
||||
spriteY = sprtY;
|
||||
}
|
||||
Object flip = frame.opt("icon_flipX");
|
||||
if(flip != null) {
|
||||
shouldRenderIcon = true;
|
||||
if(flip instanceof Boolean) {
|
||||
flipX = ((Boolean)flip).booleanValue();
|
||||
}else {
|
||||
flipX = false;
|
||||
}
|
||||
}
|
||||
flip = frame.opt("icon_flipY");
|
||||
if(flip != null) {
|
||||
shouldRenderIcon = true;
|
||||
if(flip instanceof Boolean) {
|
||||
flipY = ((Boolean)flip).booleanValue();
|
||||
}else {
|
||||
flipY = false;
|
||||
}
|
||||
}
|
||||
int rot = frame.optInt("icon_rotate", -1);
|
||||
if(rot >= 0) {
|
||||
shouldRenderIcon = true;
|
||||
rotate = rot % 4;
|
||||
}
|
||||
JSONArray colorF = frame.optJSONArray("icon_color");
|
||||
if(colorF != null && colorF.length() > 0) {
|
||||
shouldRenderIcon = true;
|
||||
color[0] = colorF.getFloat(0);
|
||||
color[1] = colorF.length() > 1 ? colorF.getFloat(1) : color[1];
|
||||
color[2] = colorF.length() > 2 ? colorF.getFloat(2) : color[2];
|
||||
color[3] = colorF.length() > 3 ? colorF.getFloat(3) : 1.0f;
|
||||
}
|
||||
colorF = frame.optJSONArray("icon_tint");
|
||||
if(colorF != null && colorF.length() > 0) {
|
||||
shouldRenderIcon = true;
|
||||
tint[0] = colorF.getFloat(0);
|
||||
tint[1] = colorF.length() > 1 ? colorF.getFloat(1) : tint[1];
|
||||
tint[2] = colorF.length() > 2 ? colorF.getFloat(2) : tint[2];
|
||||
tint[3] = colorF.length() > 3 ? colorF.getFloat(3) : 1.0f;
|
||||
}
|
||||
if(shouldRenderIcon) {
|
||||
int[] newIcon = null;
|
||||
if(bitmap != null) {
|
||||
newIcon = bitmap.getSprite(spriteX, spriteY);
|
||||
}
|
||||
if(newIcon == null) {
|
||||
newIcon = new int[64*64];
|
||||
}
|
||||
newIcon = BitmapFile.applyTint(newIcon, tint[0], tint[1], tint[2], tint[3]);
|
||||
if(color[3] > 0.0f) {
|
||||
newIcon = BitmapFile.applyColor(newIcon, color[0], color[1], color[2], color[3]);
|
||||
}
|
||||
if(bitmap != null) {
|
||||
if(flipX) {
|
||||
newIcon = BitmapFile.flipX(newIcon);
|
||||
}
|
||||
if(flipY) {
|
||||
newIcon = BitmapFile.flipY(newIcon);
|
||||
}
|
||||
if(rotate != 0) {
|
||||
newIcon = BitmapFile.rotate(newIcon, rotate);
|
||||
}
|
||||
}
|
||||
motd.setBitmap(newIcon);
|
||||
shouldPush = true;
|
||||
}
|
||||
}
|
||||
if(shouldPush) {
|
||||
motd.sendToUser();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
motd.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class MessagePool {
|
||||
|
||||
public final String poolName;
|
||||
public final List<MessagePoolEntry> messagePool = new LinkedList();
|
||||
public final Random random = new Random();
|
||||
|
||||
public MessagePool(String s) {
|
||||
this.poolName = s;
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(messagePool);
|
||||
}
|
||||
|
||||
public MessagePoolEntry pickNew() {
|
||||
if(messagePool.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
float f = 0.0f;
|
||||
for(MessagePoolEntry m : messagePool) {
|
||||
f += m.weight;
|
||||
}
|
||||
f *= random.nextFloat();
|
||||
float f2 = 0.0f;
|
||||
for(MessagePoolEntry m : messagePool) {
|
||||
f2 += m.weight;
|
||||
if(f2 >= f) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return messagePool.get(0);
|
||||
}
|
||||
|
||||
public MessagePoolEntry pickDefault() {
|
||||
for(MessagePoolEntry m : messagePool) {
|
||||
if("default".equalsIgnoreCase(m.name)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return pickNew();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class MessagePoolEntry implements Comparable<MessagePoolEntry> {
|
||||
|
||||
public final String name;
|
||||
public final int interval;
|
||||
public final int timeout;
|
||||
public final boolean random;
|
||||
public final boolean shuffle;
|
||||
public final float weight;
|
||||
public final String next;
|
||||
public final List<JSONObject> frames;
|
||||
|
||||
public MessagePoolEntry(int interval, int timeout, boolean random, boolean shuffle, float weight, String next, List<JSONObject> frames, String name) {
|
||||
this.interval = interval;
|
||||
this.timeout = timeout;
|
||||
this.random = random;
|
||||
this.shuffle = shuffle;
|
||||
this.weight = weight;
|
||||
this.next = next;
|
||||
this.frames = frames;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MessagePoolEntry o) {
|
||||
return Float.compare(weight, o.weight);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class QueryCache {
|
||||
|
||||
private static class CachedFile {
|
||||
protected final String name;
|
||||
protected final File file;
|
||||
protected long lastReload;
|
||||
protected long lastRescan;
|
||||
protected CachedFile(String name, File file) {
|
||||
this.name = name;
|
||||
this.file = file;
|
||||
this.lastReload = this.lastRescan = 0l;
|
||||
}
|
||||
protected boolean needsReload() {
|
||||
long l = System.currentTimeMillis();
|
||||
if(l - lastRescan > 5000l) {
|
||||
lastRescan = l;
|
||||
return file.exists() && lastReload < file.lastModified();
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedFileBinary extends CachedFile {
|
||||
protected byte[] bytes = null;
|
||||
protected CachedFileBinary(String name, File file) {
|
||||
super(name, file);
|
||||
}
|
||||
protected byte[] getOrReload() {
|
||||
if(needsReload()) {
|
||||
if(file.exists()) {
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
ByteArrayOutputStream read = new ByteArrayOutputStream(fis.available());
|
||||
byte[] d = new byte[8192];
|
||||
int i;
|
||||
while((i = fis.read(d)) != -1) {
|
||||
read.write(d, 0, i);
|
||||
}
|
||||
lastRescan = lastReload = System.currentTimeMillis();
|
||||
bytes = read.toByteArray();
|
||||
}catch(Throwable t) {
|
||||
bytes = null;
|
||||
System.err.println("[EaglerMOTD] Failed to load binary: " + name);
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedFileString extends CachedFile {
|
||||
protected String chars = null;
|
||||
protected CachedFileString(String name, File file) {
|
||||
super(name, file);
|
||||
|
||||
}
|
||||
protected String getOrReload() {
|
||||
if(needsReload()) {
|
||||
if(file.exists()) {
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
ByteArrayOutputStream read = new ByteArrayOutputStream(fis.available());
|
||||
byte[] d = new byte[8192];
|
||||
int i;
|
||||
while((i = fis.read(d)) != -1) {
|
||||
read.write(d, 0, i);
|
||||
}
|
||||
lastRescan = lastReload = System.currentTimeMillis();
|
||||
chars = new String(read.toByteArray(), StandardCharsets.UTF_8);
|
||||
}catch(Throwable t) {
|
||||
chars = null;
|
||||
System.err.println("[EaglerMOTD] Failed to load text: " + name);
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return chars;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedFileJSON extends CachedFile {
|
||||
protected JSONObject json = null;
|
||||
protected CachedFileJSON(String name, File file) {
|
||||
super(name, file);
|
||||
|
||||
}
|
||||
protected JSONObject getOrReload() {
|
||||
if(needsReload()) {
|
||||
if(file.exists()) {
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
ByteArrayOutputStream read = new ByteArrayOutputStream(fis.available());
|
||||
byte[] d = new byte[8192];
|
||||
int i;
|
||||
while((i = fis.read(d)) != -1) {
|
||||
read.write(d, 0, i);
|
||||
}
|
||||
lastRescan = lastReload = System.currentTimeMillis();
|
||||
json = new JSONObject(new String(read.toByteArray(), StandardCharsets.UTF_8));
|
||||
}catch(Throwable t) {
|
||||
json = null;
|
||||
System.err.println("[EaglerMOTD] Failed to load json: " + name);
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
private static final HashMap<String, CachedFileBinary> cachedBinary = new HashMap();
|
||||
private static final HashMap<String, CachedFileString> cachedString = new HashMap();
|
||||
private static final HashMap<String, CachedFileJSON> cachedJSON = new HashMap();
|
||||
|
||||
public static void flush() {
|
||||
cachedBinary.clear();
|
||||
cachedString.clear();
|
||||
cachedJSON.clear();
|
||||
}
|
||||
|
||||
public static byte[] getBinaryFile(String s) {
|
||||
CachedFileBinary fb = cachedBinary.get(s);
|
||||
if(fb == null) {
|
||||
fb = new CachedFileBinary(s, new File(s));
|
||||
cachedBinary.put(s, fb);
|
||||
}
|
||||
return fb.getOrReload();
|
||||
}
|
||||
|
||||
public static String getStringFile(String s) {
|
||||
CachedFileString fb = cachedString.get(s);
|
||||
if(fb == null) {
|
||||
fb = new CachedFileString(s, new File(s));
|
||||
cachedString.put(s, fb);
|
||||
}
|
||||
return fb.getOrReload();
|
||||
}
|
||||
|
||||
public static JSONObject getJSONFile(String s) {
|
||||
CachedFileJSON fb = cachedJSON.get(s);
|
||||
if(fb == null) {
|
||||
fb = new CachedFileJSON(s, new File(s));
|
||||
cachedJSON.put(s, fb);
|
||||
}
|
||||
return fb.getOrReload();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package net.lax1dude.eaglercraft.eaglermotd;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import net.md_5.bungee.api.QueryConnection;
|
||||
|
||||
public class QueryType {
|
||||
|
||||
public final String name;
|
||||
public final String type;
|
||||
|
||||
public final String dataString;
|
||||
public final String dataJSONFile;
|
||||
public final JSONObject dataJSONObject;
|
||||
public final String dataTextFile;
|
||||
public final String dataBinaryFile;
|
||||
|
||||
public QueryType(String name, JSONObject tag) {
|
||||
this.name = name;
|
||||
this.dataJSONObject = tag.optJSONObject("json", null);
|
||||
if(this.dataJSONObject == null) {
|
||||
this.dataJSONFile = tag.optString("json", null);
|
||||
if(this.dataJSONFile == null) {
|
||||
this.dataTextFile = tag.optString("txt", null);
|
||||
if(this.dataTextFile == null) {
|
||||
this.dataString = tag.optString("string", null);
|
||||
}else {
|
||||
this.dataString = null;
|
||||
}
|
||||
}else {
|
||||
this.dataTextFile = null;
|
||||
this.dataString = null;
|
||||
}
|
||||
}else {
|
||||
this.dataJSONFile = null;
|
||||
this.dataTextFile = null;
|
||||
this.dataString = null;
|
||||
}
|
||||
this.dataBinaryFile = tag.optString("file", null);
|
||||
String t = tag.optString("type", null);
|
||||
if(t == null) {
|
||||
if(this.dataJSONObject != null || this.dataJSONFile != null) {
|
||||
t = "json";
|
||||
}else if(this.dataString != null || this.dataTextFile != null) {
|
||||
t = "text";
|
||||
}else {
|
||||
t = "binary";
|
||||
}
|
||||
}
|
||||
this.type = t;
|
||||
}
|
||||
|
||||
public void doQuery(QueryConnection query) {
|
||||
byte[] bin = null;
|
||||
if(dataBinaryFile != null) {
|
||||
bin = QueryCache.getBinaryFile(dataBinaryFile);
|
||||
if(bin == null) {
|
||||
query.setReturnType("error");
|
||||
query.writeResponse("Error: could not load binary file '" + dataBinaryFile + "' for query '" + type + "'");
|
||||
return;
|
||||
}
|
||||
}
|
||||
boolean flag = false;
|
||||
if(dataJSONObject != null) {
|
||||
query.setReturnType(type);
|
||||
query.writeResponse(dataJSONObject);
|
||||
flag = true;
|
||||
}else if(dataJSONFile != null) {
|
||||
JSONObject obj = QueryCache.getJSONFile(dataJSONFile);
|
||||
if(obj == null) {
|
||||
query.setReturnType("error");
|
||||
query.writeResponse("Error: could not load or parse JSON file '" + dataJSONFile + "' for query '" + type + "'");
|
||||
return;
|
||||
}else {
|
||||
query.setReturnType(type);
|
||||
query.writeResponse(obj);
|
||||
flag = true;
|
||||
}
|
||||
}else if(dataTextFile != null) {
|
||||
String txt = QueryCache.getStringFile(dataTextFile);
|
||||
if(txt == null) {
|
||||
query.setReturnType("error");
|
||||
query.writeResponse("Error: could not load text file '" + dataJSONFile + "' for query '" + type + "'");
|
||||
return;
|
||||
}else {
|
||||
query.setReturnType(type);
|
||||
query.writeResponse(txt);
|
||||
flag = true;
|
||||
}
|
||||
}else if(dataString != null) {
|
||||
query.setReturnType(type);
|
||||
query.writeResponse(dataString);
|
||||
flag = true;
|
||||
}
|
||||
if(!flag) {
|
||||
query.setReturnType(type);
|
||||
if(bin != null) {
|
||||
query.writeResponse((new JSONObject()).put("binary", true).put("file", dataBinaryFile).put("size", bin.length));
|
||||
}else {
|
||||
query.writeResponse("<No Content>");
|
||||
}
|
||||
}
|
||||
if(bin != null) {
|
||||
query.writeResponseBinary(bin);
|
||||
}
|
||||
query.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
name: EaglerMOTD
|
||||
main: net.lax1dude.eaglercraft.eaglermotd.EaglerMOTD
|
||||
version: 1.0.4
|
||||
author: LAX1DUDE
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Reference in New Issue
Block a user