-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequester.py
More file actions
45 lines (35 loc) · 1.08 KB
/
Copy pathrequester.py
File metadata and controls
45 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import uuid
import json
from thin_ws_server import WebSocketServer
def createRequestBody(command, *args):
REQUEST_BODY = {
"body": {
"origin": {
"type": "player"
},
"commandLine": command + " " + " ".join(args),
"version": 1
},
"header": {
"requestId": str(uuid.uuid4()),
"messagePurpose": "commandRequest",
"version": 1,
"messageType": "commandRequest"
}
}
return json.dumps(REQUEST_BODY)
class CommandRequester(WebSocketServer):
def __init__(self):
super().__init__(8000)
def request(self, command, *args):
request_body = createRequestBody(command, *args)
self.send(request_body)
response = self.recv().decode()
return json.loads(response)
if __name__ == "__main__":
cr = CommandRequester()
print("Waiting for connection...")
cr.accept()
while True:
response = cr.request("summon", "tnt", "~~~")
print(response)