change APISocket to allow country code and channelId definition

This commit is contained in:
HF 2020-04-29 22:11:29 +02:00
parent 50e3a95161
commit d952050f42
2 changed files with 10 additions and 7 deletions

7
API.md
View File

@ -17,7 +17,9 @@ All requests are made as JSON encoded array.
All chat messages, except the once you send with `chat` or `mcchat`, will be sent to you in the form:
```["msg", name, message]```
```["msg", name, message, country, channelId]```
channelId is an integer, channel 0 is `en` channel 1 is `int` and maybe more to come.
country is the [two-letter country code](https://www.nationsonline.org/oneworld/country_code_list.htm) in lowercase
### Subscribe to online user counter
```["sub", "online"]```
@ -61,8 +63,9 @@ wait Seconds is the cooldown like in `retpixel` above.
(got an extra command because minecraftname gets resolved to linked pixelplanet user if possible)
### Send Chat Message
```["chat", name, message]```
```["chat", name, message, country, channelId]```
channelId is an integer, channel 0 is `en` channel 1 is `int` and maybe more to come.
(messages with the name "info" will be displayed as red notifications in the chat window)
### Link Minecraft Account to pixelplanet Account
```["linkacc", minecraftid, minecraftname, pixelplanetname]```

View File

@ -90,9 +90,9 @@ class APISocketServer extends WebSocketEvents {
sendapi,
ws = null,
) {
if (!sendapi || channelId !== 0) return;
if (!sendapi) return;
const sendmsg = JSON.stringify(['msg', name, msg]);
const sendmsg = JSON.stringify(['msg', name, msg, country, channelId]);
this.wss.clients.forEach((client) => {
if (client !== ws
&& client.subChat
@ -250,9 +250,9 @@ class APISocketServer extends WebSocketEvents {
return;
}
if (command == 'chat') {
const [name, msg] = packet;
chatProvider.broadcastChatMessage(name, msg, 'xx', 0, false);
this.broadcastChatMessage(name, msg, 'xx', 0, true, ws);
const [name, msg, country, channelId] = packet;
chatProvider.broadcastChatMessage(name, msg, country, channelId, false);
this.broadcastChatMessage(name, msg, country, channelId, true, ws);
return;
}
if (command == 'linkacc') {