-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.py
99 lines (86 loc) · 2.83 KB
/
server.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
import os
if not os.path.isfile("./_key.py"):
print("Please put _key.py in root folder!")
print("If you don't know what you should do,")
print("Please read README.md")
input()
exit(1)
import argparse
import socket
import json
import time
import sqlite3
from threading import Thread, Lock
from channel_server import Channel_Server
from game_server import Game_Server
from patch_server import Patch_Server
def main_loop():
"""
Start udp tcp server threads
"""
lock = Lock()
channel_server = Channel_Server(lock)
game_server = Game_Server(lock)
# patch_server = Patch_Server(lock)
channel_server.start()
game_server.start()
# patch_server.start()
is_running = True
print("Single WS1 Emulator Server.")
print(f"YOUR LOCAL IP: {socket.gethostbyname(socket.gethostname())}")
print("--------------------------------------")
print("quit : quit server")
print("reset: reset server")
print("map: change map")
print("mob: spawn mob or npc")
print("item: get item")
print("hp: set hp")
print("mp: set mp")
print("--------------------------------------")
while is_running:
cmd = ""
try:
cmd = input("cmd >")
except KeyboardInterrupt:
print("Shutting down server...")
channel_server.is_listening = False
game_server.is_listening = False
# patch_server.is_listening = False
is_running = False
if cmd == "quit" or cmd == "exit" or cmd == "q":
print("Shutting down server...")
channel_server.is_listening = False
game_server.is_listening = False
# patch_server.is_listening = False
is_running = False
elif cmd == "reset":
print("Resetting server...")
game_server.is_listening = False
while game_server.is_alive:
time.sleep(0.1)
game_server.start()
print("Resetting server... Done!")
else:
game_server.send_custom_opcode(cmd)
channel_server.join()
game_server.join()
if __name__ == "__main__":
"""
Start a game server
"""
# parser = argparse.ArgumentParser(description='Simple game server')
# parser.add_argument('--tcpport',
# dest='tcp_port',
# help='Listening tcp port',
# default="1234")
# parser.add_argument('--udpport',
# dest='udp_port',
# help='Listening udp port',
# default="1234")
# parser.add_argument('--capacity',
# dest='room_capacity',
# help='Max players per room',
# default="3")
# args = parser.parse_args()
main_loop()