forked from ppfun/pixelplanet
fix apisocket pxl receiver
This commit is contained in:
parent
8742bf53b5
commit
358b5a3ce0
|
@ -132,6 +132,7 @@ class APISocketServer extends WebSocketEvents {
|
|||
if (client.subOnline && client.readyState === WebSocket.OPEN) {
|
||||
frame.forEach((data) => {
|
||||
try {
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
client._socket.write(data);
|
||||
} catch (error) {
|
||||
logger.error('(!) Catched error on write apisocket:', error);
|
||||
|
@ -142,7 +143,7 @@ class APISocketServer extends WebSocketEvents {
|
|||
}
|
||||
|
||||
broadcastPixelBuffer(canvasId, chunkid, buffer) {
|
||||
if (canvasId !== 0) return;
|
||||
if (canvasId !== 0 && canvasId !== '0') return;
|
||||
const frame = WebSocket.Sender.frame(buffer, {
|
||||
readOnly: true,
|
||||
mask: false,
|
||||
|
@ -154,6 +155,7 @@ class APISocketServer extends WebSocketEvents {
|
|||
if (client.subPxl && client.readyState === WebSocket.OPEN) {
|
||||
frame.forEach((data) => {
|
||||
try {
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
client._socket.write(data);
|
||||
} catch (error) {
|
||||
logger.error('(!) Catched error on write apisocket:', error);
|
||||
|
@ -171,21 +173,21 @@ class APISocketServer extends WebSocketEvents {
|
|||
if (!command) {
|
||||
return;
|
||||
}
|
||||
if (command == 'sub') {
|
||||
if (command === 'sub') {
|
||||
const even = packet[0];
|
||||
if (even == 'chat') {
|
||||
if (even === 'chat') {
|
||||
ws.subChat = true;
|
||||
}
|
||||
if (even == 'pxl') {
|
||||
if (even === 'pxl') {
|
||||
ws.subPxl = true;
|
||||
}
|
||||
if (even == 'online') {
|
||||
if (even === 'online') {
|
||||
ws.subOnline = true;
|
||||
}
|
||||
logger.info(`APISocket client subscribed to ${command}`);
|
||||
return;
|
||||
}
|
||||
if (command == 'setpxl') {
|
||||
if (command === 'setpxl') {
|
||||
const [minecraftid, ip, x, y, clr] = packet;
|
||||
if (clr < 0 || clr > 32) return;
|
||||
// be aware that user null has no cd
|
||||
|
@ -210,7 +212,7 @@ class APISocketServer extends WebSocketEvents {
|
|||
return;
|
||||
}
|
||||
logger.info(`APISocket message ${message}`);
|
||||
if (command == 'login') {
|
||||
if (command === 'login') {
|
||||
const [minecraftid, minecraftname, ip] = packet;
|
||||
const user = await this.mc.report_login(minecraftid, minecraftname);
|
||||
// get userinfo
|
||||
|
@ -226,7 +228,7 @@ class APISocketServer extends WebSocketEvents {
|
|||
]));
|
||||
return;
|
||||
}
|
||||
if (command == 'userlst') {
|
||||
if (command === 'userlst') {
|
||||
const [userlist] = packet;
|
||||
if (!Array.isArray(userlist) || !Array.isArray(userlist[0])) {
|
||||
logger.error('Got invalid minecraft userlist on APISocketServer');
|
||||
|
@ -235,12 +237,12 @@ class APISocketServer extends WebSocketEvents {
|
|||
this.mc.report_userlist(userlist);
|
||||
return;
|
||||
}
|
||||
if (command == 'logout') {
|
||||
if (command === 'logout') {
|
||||
const [minecraftid] = packet;
|
||||
this.mc.report_logout(minecraftid);
|
||||
return;
|
||||
}
|
||||
if (command == 'mcchat') {
|
||||
if (command === 'mcchat') {
|
||||
const [minecraftname, msg] = packet;
|
||||
const user = this.mc.minecraftname2User(minecraftname);
|
||||
const chatname = (user.id)
|
||||
|
@ -250,13 +252,13 @@ class APISocketServer extends WebSocketEvents {
|
|||
this.broadcastChatMessage(chatname, msg, 'xx', 0, true, ws);
|
||||
return;
|
||||
}
|
||||
if (command == 'chat') {
|
||||
if (command === 'chat') {
|
||||
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') {
|
||||
if (command === 'linkacc') {
|
||||
const [minecraftid, minecraftname, name] = packet;
|
||||
const ret = await this.mc.linkacc(minecraftid, minecraftname, name);
|
||||
if (!ret) {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from struct import *
|
||||
import websocket
|
||||
import json
|
||||
|
||||
try:
|
||||
import thread
|
||||
except ImportError:
|
||||
|
@ -9,7 +11,25 @@ except ImportError:
|
|||
import time
|
||||
|
||||
def on_message(ws, message):
|
||||
print("Got message: " + str(message))
|
||||
if type(message) is str:
|
||||
print("Got message: " + str(message))
|
||||
return
|
||||
if unpack_from('B', message, 0)[0] == 193:
|
||||
x = unpack_from('B', message, 1)[0]
|
||||
y = unpack_from('B', message, 2)[0]
|
||||
a = unpack_from('!h', message, 4)[0]
|
||||
if x != 10000 and y != 10000:
|
||||
return
|
||||
color = int(unpack_from('!B', message, 6)[0])
|
||||
if color == 0:
|
||||
color = 19
|
||||
elif color == 1:
|
||||
color = 2
|
||||
color -= 2
|
||||
number = (65520 & a) >> 4
|
||||
x = int(x * 256 + a % 256 - 256 * 256 / 2)
|
||||
y = int(y * 256 + a // 256 + 256 - 256 * 256 / 2)
|
||||
print('Pixel Received: @%s,%s - color %s' % (str(x), str(y), str(color)))
|
||||
|
||||
def on_error(ws, error):
|
||||
print(error)
|
||||
|
@ -19,10 +39,11 @@ def on_close(ws):
|
|||
|
||||
def on_open(ws):
|
||||
def run(*args):
|
||||
ws.send(json.dumps(["sub", "chat"]))
|
||||
ws.send(json.dumps(["chat", "name", "message"]))
|
||||
ws.send(json.dumps(["linkacc", "someid", "mymcname", "hallo"]))
|
||||
#ws.send(json.dumps(["login", "someid", "mymcname", "127.0.0.1"]))
|
||||
ws.send(json.dumps(["sub", "pxl"]))
|
||||
time.sleep(3)
|
||||
print('Send pixel 10.000 10.000 7')
|
||||
ws.send(json.dumps(["setpxl", "07ef7f62-a631-45c9-a150-a52d5f9f1b42", "123.123.123.123", 10000, 10000, 7]))
|
||||
#ws.send(json.dumps(["setpxl", None, None, 10000, 10000, 7]))
|
||||
time.sleep(120)
|
||||
ws.close()
|
||||
thread.start_new_thread(run, ())
|
||||
|
@ -30,7 +51,7 @@ def on_open(ws):
|
|||
|
||||
if __name__ == "__main__":
|
||||
websocket.enableTrace(True)
|
||||
ws = websocket.WebSocketApp("wss://old.pixelplanet.fun/mcws",
|
||||
ws = websocket.WebSocketApp("wss://pixelplanet.fun/mcws",
|
||||
on_message = on_message,
|
||||
on_error = on_error,
|
||||
on_close = on_close,
|
||||
|
|
Loading…
Reference in New Issue
Block a user