Skip to content

Commit

Permalink
Fix: redis-keys should contain a server-id as expected by the web API
Browse files Browse the repository at this point in the history
The web API wants the server-ids to be an MD5 hash of the ip:port
of the server. This gives stable server-ids between restarts.
  • Loading branch information
TrueBrain committed Jul 10, 2021
1 parent 9e4937f commit 4da1e91
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion game_coordinator/application/coordinator.py
@@ -1,4 +1,6 @@
import asyncio
import hashlib
import ipaddress
import logging

from openttd_protocol.protocol.coordinator import ConnectionType
Expand Down Expand Up @@ -50,7 +52,12 @@ def remove_server(self, server_id):
del self._servers[server_id]

async def receive_PACKET_COORDINATOR_CLIENT_REGISTER(self, source, protocol_version, game_type, server_port):
server_id = f"{str(source.ip)}:{server_port}"
if isinstance(source.ip, ipaddress.IPv6Address):
server_id_str = f"[{source.ip}]:{server_port}"
else:
server_id_str = f"{source.ip}:{server_port}"

server_id = hashlib.md5(server_id_str.encode()).digest().hex()

source.server = Server(self, server_id, game_type, source, server_port)
self._servers[source.server.server_id] = source.server
Expand Down

0 comments on commit 4da1e91

Please sign in to comment.