From 12ddbba66e6f2585e59d05d1782c0e8ce9fe6146 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 17 Dec 2021 23:55:44 +0800 Subject: 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. --- example/messaging.jsonc | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 example/messaging.jsonc (limited to 'example') 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 -- cgit v1.2.3