Config packetlog

This commit is contained in:
Naruse
2025-04-18 09:13:44 +08:00
parent dc17150b86
commit 709b4af735
2 changed files with 10 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ from game_server.game.player.player_manager import PlayerManager
from game_server.dummy import dummyprotolist
import traceback
from utils.time import cur_timestamp_ms
from utils.config import Config
class PlayerSession:
def __init__(self, transport, session_id, client_addr, db):
@@ -94,14 +95,16 @@ class PlayerSession:
if not handle_result:
return
except ModuleNotFoundError:
Error(f"Unhandled request {request_name}")
if Config.PacketLog:
Error(f"Unhandled request {request_name}")
return
except Exception:
Error(f"Handler {request_name} returns error.")
traceback.print_exc()
return
Info(f"Received cmd: {request_name}({cmd_id})")
if Config.PacketLog:
Info(f"Received cmd: {request_name}({cmd_id})")
response_name = handle_result.__class__.__name__
cmd_type = getattr(cmd.CmdID, response_name, None)
@@ -136,7 +139,8 @@ class PlayerSession:
self.kcp.flush()
cmd_id = packet.cmd_type
request_name = cmd.get_key_by_value(cmd_id)
Info(f"Sent cmd: {request_name}({cmd_id})")
if Config.PacketLog:
Info(f"Sent cmd: {request_name}({cmd_id})")
def time(self):
return (cur_timestamp_ms()) - self.connect_time_ms

View File

@@ -17,6 +17,7 @@ class ConfigData:
SDKServer: ServerConfig
SRToolsServer: ServerConfig
RegionName: str
PacketLog: bool
def write_default_config():
config = ConfigData(
LogLevel="INFO",
@@ -24,6 +25,7 @@ class ConfigData:
SDKServer=ServerConfig(IP="127.0.0.1", Port=21000),
SRToolsServer=ServerConfig(IP="127.0.0.1", Port=25000),
RegionName="NeonSR",
PacketLog=True,
)
with open("Config.json", "w") as f:
f.write(json.dumps(asdict(config), indent=2))