-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
81 lines (73 loc) · 2.06 KB
/
server.py
File metadata and controls
81 lines (73 loc) · 2.06 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
A vanilla reimplementation made using BeeMineAPI.
This should NOT be used in Production.
It is not complete.
"""
from beemineapi import BeeProtocol, BeeFactory, BeeAPI, reactor
import sys
true, false = True, False
c = '§'
beeapi = BeeAPI()
allowed_protocols = [759, 760, 761]
def exit(exit_code: int=0):
try:
sys.exit(exit_code)
except:
quit()
def packet_chat_message(self, buff):
p_text = buff.unpack_string()
fmt = f"<{self.display_name}> {p_text}"
print(f'[CHAT] {fmt}')
beeapi.sendMessage(fmt)
buff.discard()
def getHelpMsg():
return f"{c}cThis is a placeholder."
def packet_chat_command(self, buff):
command = buff.unpack_string()
commands = command.split()
cmd = commands[0]
args = commands
args.remove(cmd)
returned = 0
if cmd == "help":
beeapi.sendMessage(getHelpMsg(), self)
returned = 1
elif cmd == "eval":
beeapi.sendMessage(f'{c}7Executing...', self)
executes = ''
for arg in args:
executes += f' {arg}'
try:
got = eval(executes)
except Exception as e:
exname = str(type(e)).replace(' ', '').replace('<', '>').replace('>', '').replace('class', '').replace('\'', '')
beeapi.sendMessage(f'{c}c{exname}: {e}', self)
returned = 1
else:
beeapi.sendMessage(f'{c}cInvalid Command! Use /help for help.', self)
returned = 1
if returned == 1:
print(f"{self.displayname} executed command: {command}")
buff.discard()
def getBadVersionKick(version: int):
return f"Minecraft Protocol {version} is not allowed."
def player_joined(self):
super().player_joined()
if not self.protocol_version in allowed_protocols:
self.close(getBadVersionKick(self.protocol_version))
class VanillaFactory(BeeFactory):
protocol = BeeProtocol
motd = f'A Minecraft Server\n{c}eBeeMineAPI Vanilla Reimplementation'
icon_path = "./server.png"
protocol.player_joined = player_joined
protocol.packet_chat_message = packet_chat_message
protocol.packet_chat_command = packet_chat_command
try:
factory = VanillaFactory()
host, port="", 25565
addr=(host, port)
beeapi = BeeAPI(factory)
factory.listen(*addr)
reactor.run()
except Exception as e:
exit()