fixed server status uptime for coldeve
This commit is contained in:
parent
ca12f4807b
commit
72de9b0f7f
3 changed files with 56 additions and 39 deletions
|
|
@ -43,6 +43,7 @@ services:
|
||||||
POSTGRES_DB: dereth
|
POSTGRES_DB: dereth
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
||||||
|
DB_RETENTION_DAYS: 30
|
||||||
volumes:
|
volumes:
|
||||||
- timescale-data:/var/lib/postgresql/data
|
- timescale-data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
84
main.py
84
main.py
|
|
@ -171,53 +171,67 @@ AC_LOGIN_PACKET = bytes([
|
||||||
])
|
])
|
||||||
|
|
||||||
async def check_server_health(address: str, port: int, timeout: float = 3.0) -> tuple[bool, float, int]:
|
async def check_server_health(address: str, port: int, timeout: float = 3.0) -> tuple[bool, float, int]:
|
||||||
"""Check AC server health via UDP packet.
|
"""Check AC server health via UDP packet with retry logic.
|
||||||
|
|
||||||
|
Retries 6 times with 5-second delays before declaring server down.
|
||||||
Returns: (is_up, latency_ms, player_count)
|
Returns: (is_up, latency_ms, player_count)
|
||||||
"""
|
"""
|
||||||
logger.debug(f"🔍 Starting health check for {address}:{port}")
|
max_retries = 6
|
||||||
start_time = time.time()
|
retry_delay = 5.0
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
sock.setblocking(False)
|
|
||||||
|
|
||||||
try:
|
for attempt in range(max_retries):
|
||||||
# Send login packet (same as ThwargLauncher)
|
logger.debug(f"🔍 Health check attempt {attempt + 1}/{max_retries} for {address}:{port}")
|
||||||
await asyncio.get_event_loop().sock_sendto(sock, AC_LOGIN_PACKET, (address, port))
|
start_time = time.time()
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.setblocking(False)
|
||||||
|
|
||||||
# Wait for response with timeout
|
|
||||||
try:
|
try:
|
||||||
data, addr = await asyncio.wait_for(
|
# Send login packet (same as ThwargLauncher)
|
||||||
asyncio.get_event_loop().sock_recvfrom(sock, 1024),
|
await asyncio.get_event_loop().sock_sendto(sock, AC_LOGIN_PACKET, (address, port))
|
||||||
timeout=timeout
|
|
||||||
)
|
|
||||||
|
|
||||||
latency_ms = (time.time() - start_time) * 1000
|
# Wait for response with timeout
|
||||||
logger.debug(f"📥 Received response from {addr}: {len(data)} bytes, latency: {latency_ms:.1f}ms")
|
try:
|
||||||
|
data, addr = await asyncio.wait_for(
|
||||||
|
asyncio.get_event_loop().sock_recvfrom(sock, 1024),
|
||||||
|
timeout=timeout
|
||||||
|
)
|
||||||
|
|
||||||
# Check if valid response (support both TimeSynch 0x800000 and ConnectRequest 0x40000)
|
latency_ms = (time.time() - start_time) * 1000
|
||||||
if len(data) >= 24:
|
logger.debug(f"📥 Received response from {addr}: {len(data)} bytes, latency: {latency_ms:.1f}ms")
|
||||||
flags = struct.unpack('<I', data[4:8])[0]
|
|
||||||
|
|
||||||
# Accept both TimeSynch (0x800000) and ConnectRequest (0x40000) as valid responses
|
# Check if valid response (support both TimeSynch 0x800000 and ConnectRequest 0x40000)
|
||||||
if (flags & 0x800000) or (flags & 0x40000):
|
if len(data) >= 24:
|
||||||
# UDP health check is for server status and latency only
|
flags = struct.unpack('<I', data[4:8])[0]
|
||||||
# Player count comes from TreeStats.net API (like ThwargLauncher)
|
|
||||||
logger.debug(f"✅ Valid server response: latency: {latency_ms:.1f}ms")
|
|
||||||
return True, latency_ms, None
|
|
||||||
|
|
||||||
# Any response indicates server is up, even if not the expected format
|
# Accept both TimeSynch (0x800000) and ConnectRequest (0x40000) as valid responses
|
||||||
logger.info(f"✅ Server response (non-standard format): latency: {latency_ms:.1f}ms")
|
if (flags & 0x800000) or (flags & 0x40000):
|
||||||
return True, latency_ms, None
|
# UDP health check is for server status and latency only
|
||||||
|
# Player count comes from TreeStats.net API (like ThwargLauncher)
|
||||||
|
logger.debug(f"✅ Valid server response: latency: {latency_ms:.1f}ms")
|
||||||
|
return True, latency_ms, None
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
# Any response indicates server is up, even if not the expected format
|
||||||
logger.debug(f"⏰ TIMEOUT: No response from {address}:{port} after {timeout}s - server down")
|
logger.info(f"✅ Server response (non-standard format): latency: {latency_ms:.1f}ms")
|
||||||
return False, None, None
|
return True, latency_ms, None
|
||||||
|
|
||||||
except Exception as e:
|
except asyncio.TimeoutError:
|
||||||
logger.error(f"Server health check error: {e}")
|
logger.debug(f"⏰ TIMEOUT: No response from {address}:{port} after {timeout}s")
|
||||||
return False, None, None
|
if attempt < max_retries - 1:
|
||||||
finally:
|
logger.debug(f"Retrying in {retry_delay} seconds...")
|
||||||
sock.close()
|
await asyncio.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Server health check error on attempt {attempt + 1}: {e}")
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
finally:
|
||||||
|
sock.close()
|
||||||
|
|
||||||
|
# Only declare down after all retries fail
|
||||||
|
logger.warning(f"❌ Server {address}:{port} is DOWN after {max_retries} attempts over {max_retries * retry_delay} seconds")
|
||||||
|
return False, None, None
|
||||||
|
|
||||||
async def get_player_count_from_treestats(server_name: str) -> int:
|
async def get_player_count_from_treestats(server_name: str) -> int:
|
||||||
"""Get player count from TreeStats.net API (same as ThwargLauncher)."""
|
"""Get player count from TreeStats.net API (same as ThwargLauncher)."""
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ body {
|
||||||
font-family: "Segoe UI", sans-serif;
|
font-family: "Segoe UI", sans-serif;
|
||||||
background: var(--bg-main);
|
background: var(--bg-main);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sort-buttons {
|
.sort-buttons {
|
||||||
|
|
@ -1450,3 +1451,4 @@ body.noselect, body.noselect * {
|
||||||
.regular-spell {
|
.regular-spell {
|
||||||
color: #88ccff;
|
color: #88ccff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue