artemis/titles/idz/handlers/load_server_info.py

100 lines
3.4 KiB
Python
Raw Normal View History

2023-04-23 08:38:28 +00:00
import struct
2023-11-09 04:54:35 +00:00
from core.utils import Utils
2023-04-23 08:38:28 +00:00
from .base import IDZHandlerBase
from core.config import CoreConfig
from ..config import IDZConfig
from ..const import IDZConstants
2023-04-23 08:38:28 +00:00
class IDZHandlerLoadServerInfo(IDZHandlerBase):
cmd_codes = [0x0006] * IDZConstants.NUM_VERS
rsp_codes = [0x0007] * IDZConstants.NUM_VERS
name = "load_server_info1"
def __init__(self, core_cfg: CoreConfig, game_cfg: IDZConfig, version: int) -> None:
super().__init__(core_cfg, game_cfg, version)
self.size = 0x04B0
2023-04-23 08:38:28 +00:00
def handle(self, data: bytes) -> bytearray:
ret = super().handle(data)
offset = 0
if self.version >= IDZConstants.VER_IDZ_210:
2023-04-23 08:38:28 +00:00
offset = 2
2023-11-09 04:54:35 +00:00
t_port = Utils.get_title_port(self.core_config)
2024-01-09 08:07:04 +00:00
news_str = f"http://{self.core_config.server.hostname}:{t_port}/idz/news/news80**.txt"
err_str = f"http://{self.core_config.server.hostname}:{t_port}/idz/error"
2023-04-23 08:38:28 +00:00
2024-01-09 08:07:04 +00:00
len_hostname = len(self.core_config.server.hostname)
2023-04-23 08:38:28 +00:00
len_news = len(news_str)
len_error = len(err_str)
struct.pack_into("<I", ret, 0x2 + offset, 1) # Status
struct.pack_into(
f"{len_hostname}s",
ret,
0x4 + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x84 + offset, self.game_cfg.ports.userdb)
struct.pack_into("<I", ret, 0x86 + offset, self.game_cfg.ports.userdb + 1)
struct.pack_into(
f"{len_hostname}s",
ret,
0x88 + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x108 + offset, self.game_cfg.ports.match - 1)
struct.pack_into("<I", ret, 0x10A + offset, self.game_cfg.ports.match - 3)
struct.pack_into("<I", ret, 0x10C + offset, self.game_cfg.ports.match - 2)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x10E + offset, self.game_cfg.ports.match + 2)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x110 + offset, self.game_cfg.ports.match + 3)
struct.pack_into("<I", ret, 0x112 + offset, self.game_cfg.ports.match + 1)
struct.pack_into(
f"{len_hostname}s",
ret,
0x114 + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x194 + offset, self.game_cfg.ports.echo + 2)
struct.pack_into(
f"{len_hostname}s",
ret,
0x0199 + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x0219 + offset, self.game_cfg.ports.echo + 3)
struct.pack_into(
f"{len_hostname}s",
ret,
0x021C + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
struct.pack_into(
f"{len_hostname}s",
ret,
0x029C + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
struct.pack_into(
f"{len_hostname}s",
ret,
0x031C + offset,
2024-01-09 08:07:04 +00:00
self.core_config.server.hostname.encode(),
)
2023-04-23 08:38:28 +00:00
struct.pack_into("<I", ret, 0x39C + offset, self.game_cfg.ports.echo)
struct.pack_into("<I", ret, 0x39E + offset, self.game_cfg.ports.echo + 1)
2023-04-23 08:38:28 +00:00
struct.pack_into(f"{len_news}s", ret, 0x03A0 + offset, news_str.encode())
2023-04-23 08:38:28 +00:00
struct.pack_into(f"{len_error}s", ret, 0x0424 + offset, err_str.encode())
return ret