-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
73 lines (63 loc) · 2.05 KB
/
Copy pathserver.py
File metadata and controls
73 lines (63 loc) · 2.05 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
"""
Author: RedFantom
Contributors: Daethyra (Naiii) and Sprigellania (Zarainia)
License: GNU GPLv3 as in LICENSE.md
Copyright (C) 2016-2018 RedFantom
"""
from network.minimap.server import MiniMapServer
import argparse
import time
"""
Setup a SharingServer with command-line arguments. Available arguments:
-a: address to bind to
-p: port to accept connections on
-c: maximum amount of clients
-t: amount of time in minutes to run the network for
"""
DESCRIPTION = "GSF Parser Sharing Server"
DEFAULT_PORT = 83
DEFAULT_CLIENTS = 16
DEFAULT_TIME = 0
DEFAULT_ADDRESS = "127.0.0.1"
if __name__ == '__main__':
"""
First, setup the argument parser with all the possible arguments
"""
parser = argparse.ArgumentParser(description=DESCRIPTION)
# Address
parser.add_argument(
"-a", type=str, nargs=1, help="Address to bind the network to, 'all' means all available",
default=DEFAULT_ADDRESS)
# Port
parser.add_argument(
"-p", type=int, nargs=1, help="Port to accept connections on", default=DEFAULT_PORT)
# Clients
parser.add_argument(
"-c", type=str, nargs=1, help="Maximum amount of Clients to allow on the Server simultaneously",
default=DEFAULT_CLIENTS)
# Type
parser.add_argument(
"-t", type=str, nargs=1, help="Server type (minimap)", default="minimap")
args = parser.parse_args()
"""
Acquire options for the ArgParser
"""
address = "" if isinstance(args.a, list) and args.a[0] == "all" else \
(args.a if args.a == DEFAULT_ADDRESS else args.a[0])
port = int(args.p[0] if args.p != DEFAULT_PORT else DEFAULT_PORT)
clients = int(args.c[0] if isinstance(args.c, list) else args.c)
type = args.t[0] if isinstance(args.t, list) else args.t
"""
Start the network
"""
if type == "minimap":
server = MiniMapServer(address, port)
else:
raise ValueError("Invalid server type: {}".format(type))
server.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
server.stop()
exit()