add log_network Server argument
This commit is contained in:
parent
32560eac92
commit
6567f14415
|
@ -311,11 +311,11 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
|||
args['players'].sort()
|
||||
current_team = -1
|
||||
logger.info('Players:')
|
||||
for team, slot, name in args['players']:
|
||||
if team != current_team:
|
||||
logger.info(f' Team #{team + 1}')
|
||||
current_team = team
|
||||
logger.info(' %s (Player %d)' % (name, slot))
|
||||
for network_player in args['players']:
|
||||
if network_player.team != current_team:
|
||||
logger.info(f' Team #{network_player.team + 1}')
|
||||
current_team = network_player.team
|
||||
logger.info(' %s (Player %d)' % (network_player.alias, network_player.slot))
|
||||
if args["datapackage_version"] > network_data_package["version"]:
|
||||
await ctx.send_msgs([{"cmd": "GetDataPackage"}])
|
||||
await ctx.server_auth(args['password'])
|
||||
|
|
|
@ -332,11 +332,14 @@ async def server(websocket, path, ctx: Context):
|
|||
ctx.endpoints.append(client)
|
||||
|
||||
try:
|
||||
logging.info("Incoming")
|
||||
if ctx.log_network:
|
||||
logging.info("Incoming connection")
|
||||
await on_client_connected(ctx, client)
|
||||
if ctx.log_network:
|
||||
logging.info("Sent Room Info")
|
||||
async for data in websocket:
|
||||
logging.info(data)
|
||||
if ctx.log_network:
|
||||
logging.info(f"Incoming message: {data}")
|
||||
for msg in decode(data):
|
||||
await process_client_cmd(ctx, client, msg)
|
||||
except Exception as e:
|
||||
|
@ -351,7 +354,7 @@ async def on_client_connected(ctx: Context, client: Client):
|
|||
await ctx.send_msgs(client, [{
|
||||
'cmd': 'RoomInfo',
|
||||
'password': ctx.password is not None,
|
||||
'players': [NetworkPlayer(client.team, client.slot, ctx.name_aliases.get((client.team, client.slot), client.name)) for client
|
||||
'players': [NetworkPlayer(client.team, client.slot, ctx.name_aliases.get((client.team, client.slot), client.name), client.name) for client
|
||||
in ctx.endpoints if client.auth],
|
||||
# tags are for additional features in the communication.
|
||||
# Name them by feature or fork, as you feel is appropriate.
|
||||
|
@ -1315,6 +1318,7 @@ def parse_args() -> argparse.Namespace:
|
|||
#1 -> recommended for friendly racing, tries to block third party clients
|
||||
#0 -> recommended for tournaments to force a level playing field, only allow an exact version match
|
||||
""")
|
||||
parser.add_argument('--log_network', default=defaults["log_network"], action="store_true")
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
|
@ -1351,7 +1355,7 @@ async def main(args: argparse.Namespace):
|
|||
ctx = Context(args.host, args.port, args.server_password, args.password, args.location_check_points,
|
||||
args.hint_cost, not args.disable_item_cheat, args.forfeit_mode, args.remaining_mode,
|
||||
args.auto_shutdown, args.compatibility)
|
||||
|
||||
ctx.log_network = args.log_network
|
||||
data_filename = args.multidata
|
||||
|
||||
try:
|
||||
|
|
|
@ -99,6 +99,7 @@ class Node:
|
|||
def __init__(self):
|
||||
self.endpoints = []
|
||||
super(Node, self).__init__()
|
||||
self.log_network = 0
|
||||
|
||||
def broadcast_all(self, msgs):
|
||||
msgs = self.dumper(msgs)
|
||||
|
@ -114,6 +115,9 @@ class Node:
|
|||
except websockets.ConnectionClosed:
|
||||
logging.exception(f"Exception during send_msgs, could not send {msg}")
|
||||
await self.disconnect(endpoint)
|
||||
else:
|
||||
if self.log_network:
|
||||
logging.info(f"Outgoing message: {msg}")
|
||||
|
||||
async def send_encoded_msgs(self, endpoint: Endpoint, msg: str):
|
||||
if not endpoint.socket or not endpoint.socket.open or endpoint.socket.closed:
|
||||
|
@ -123,6 +127,9 @@ class Node:
|
|||
except websockets.ConnectionClosed:
|
||||
logging.exception("Exception during send_msgs")
|
||||
await self.disconnect(endpoint)
|
||||
else:
|
||||
if self.log_network:
|
||||
logging.info(f"Outgoing message: {msg}")
|
||||
|
||||
async def disconnect(self, endpoint):
|
||||
if endpoint in self.endpoints:
|
||||
|
|
1
Utils.py
1
Utils.py
|
@ -194,6 +194,7 @@ def get_default_options() -> dict:
|
|||
"remaining_mode": "goal",
|
||||
"auto_shutdown": 0,
|
||||
"compatibility": 2,
|
||||
"log_network": 0
|
||||
},
|
||||
"multi_mystery_options": {
|
||||
"teams": 1,
|
||||
|
|
|
@ -40,6 +40,8 @@ server_options:
|
|||
# 1 -> Recommended for friendly racing, only allow Berserker's Multiworld, to disallow old /getitem for example
|
||||
# 0 -> Recommended for tournaments to force a level playing field, only allow an exact version match
|
||||
compatibility: 2
|
||||
# log all server traffic, mostly for dev use
|
||||
log_network: 0
|
||||
# Options for MultiMystery.py
|
||||
multi_mystery_options:
|
||||
# Teams
|
||||
|
|
Loading…
Reference in New Issue