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