This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rapid_lobby_cli.py
64 lines (53 loc) · 1.95 KB
/
rapid_lobby_cli.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
from rapid_lobby import Server, Client, ServerError
import argparse
def run_client(server_host, server_port):
def printRecvMsg(msg):
"""print the received messages"""
print('\r'+msg+'\n>> ', end='')
try:
c = Client(server_host, server_port, printRecvMsg)
print("[+] Connected To: %s:%s" % (server_host, str(server_port)))
except Exception:
print("[-] Connection Error !!")
exit(-1)
try:
username = input("username: ")
print("[+] loggin ...")
c.auth(username)
c.recv_handler.start()
except Exception:
print("[-] Auth Error")
exit(-2)
while 1:
try:
buf = input(">> ")
c.sendMsg(buf)
except KeyboardInterrupt:
print("\n[+] exiting client")
c.stopClient()
except ServerError as e:
print('[-]', e.message, ', exiting client')
exit(0)
def run_server(host, port, max_clients_num):
s = Server(host, port, max_clients_num)
s.startServer()
def main():
arg_parser = argparse.ArgumentParser()
subparsers = arg_parser.add_subparsers(dest='command')
parser_create = subparsers.add_parser("create")
parser_create.add_argument("host", help="host service address")
parser_create.add_argument("port", type=int,
help="host service port")
parser_create.add_argument("-m", "--max_clients_num", type=int, default=8,
help="max clients number")
parser_join = subparsers.add_parser("join")
parser_join.add_argument("host", help="host service address")
parser_join.add_argument("port", type=int,
help="host service port")
args = arg_parser.parse_args()
if args.command == "create":
run_server(args.host, args.port, args.max_clients_num)
elif args.command == "join":
run_client(args.host, args.port)
if __name__ == '__main__':
main()