summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-12-17 23:55:44 +0800
committerKeuin <[email protected]>2021-12-17 23:55:44 +0800
commit12ddbba66e6f2585e59d05d1782c0e8ce9fe6146 (patch)
tree0d98ee95c01c8509160658080523e351357d4a9b /example
parent7fc64f506ea7ebc68fcb0a9e98351deed7c1d212 (diff)
Use the latest Velocity API.
Implement API server for online players and server status. Implement core message routing abstraction and concrete BungeeCross, Velocity, Telegram endpoint impl. Load config from config file "crosslink/config.json". Test core components. Proxy API related stuff are not tested. Add README in English and Chinese. TODO: Add config hot reloading. More configurable system. PSMB endpoint impl.
Diffstat (limited to 'example')
-rw-r--r--example/messaging.jsonc89
1 files changed, 89 insertions, 0 deletions
diff --git a/example/messaging.jsonc b/example/messaging.jsonc
new file mode 100644
index 0000000..649d7ee
--- /dev/null
+++ b/example/messaging.jsonc
@@ -0,0 +1,89 @@
+{
+ "remotes": [
+ {
+ "type": "telegram",
+ "id": "Telegram", // this endpoint is identified with "remote:Telegram"
+ "enabled": true, // default: true, if set to false, this remote will be ignored
+ "token": "================TOKEN================",
+ "chat_id": 12345678 // repeat to and from this chat
+ },
+ {
+ "type": "psmb", // psmb is a special case, since it is not an endpoint
+ "id": "mypsmb", // this stub endpoint is identified with "remote:mypsmb"
+ "enabled": true, // but it creates zero or one or more than one sub "virtual" endpoints
+ "host": "1.onesmp.org",
+ "port": 3456,
+ "subscribe_to": "chat_.+", // psmb subscription pattern
+ // for example: if you have topic chat_1 and chat_2
+ // then they are identified with "remote:mypsmb:chat_1" and "remote:mypsmb:chat_2"
+ // dispatching messages from "remote:mypsmb" to virtual endpoints
+ // such as "remote:mypsmb:chat_1", is done by psmb stub endpoint
+ "topics": [ // all topics this endpoint can actually "see"
+ "chat_qq", // regexp in "subscribe_to" and action route "to"
+ "chat_wechat" // will only match endpoints declared in this list
+ ]
+ },
+ {
+ "type": "json-rpc",
+ "id": "rpc",
+ "enabled": true,
+ "listen": ["127.0.0.1", 8008],
+ "methods": {
+ "get": "getMessage",
+ "put": "sendMessage"
+ }
+ }
+ ],
+ "routing": [
+ // all rules are processed sequentially
+ // a message may match multiple rules and thus may be duplicate in your case
+ // if the message is dropped in an action in one rule,
+ // (the action type is just "drop" and it does not have any argument)
+ // all subsequent rules will NOT see this message
+ {
+ // inbound chat messages (remote -> all servers)
+ "object": "chat_message", // match chat messages
+ "from": "remote:.*", // regexp matching source,
+ // only messages with matched source will be
+ // processed by this rule, otherwise this rule is skipped
+ "actions": [{
+ "type": "format",
+ "color": "green"
+ }, { // actions run sequentially
+ "type": "route", // route this message to matched destinations
+ "to": "server:.*" // regexp matching destination
+ }]
+ },
+ {
+ // outbound messages (starting with '#', server -> all remotes)
+ "object": "chat_message",
+ "from": "server:.*",
+ "actions": [{
+ "type": "filter", // filter the message using given regexp
+ // if the message does not match given pattern,
+ // it won't be passed into subsequent actions
+ "pattern": "#.+" // match all messages starts with char '#'
+ }, {
+ "type": "replace", // replace the message, removing heading '#'
+ "from": "^#(.*)", // capture all chars after the heading '#'
+ "to": "$1" // and make them as the output
+ }, {
+ "type": "route", // send the message to all remotes
+ "to": "remote:.*"
+ }]
+ },
+ {
+ // cross-server messages (server -> all other servers)
+ "object": "chat_message",
+ "from": "server:.*",
+ "actions": [{
+ "type": "route",
+ "to": "server:.*",
+ "backflow": false // do not repeat to sender, true by default
+ // since the destination pattern will match the source,
+ // we have to set backflow to false to prevent
+ // players from seeing duplicate messages
+ }]
+ }
+ ]
+} \ No newline at end of file