From 7104645f5dc421a85c25d1f1f7f8c2243ef94b03 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Fri, 21 Aug 2026 21:03:17 +0200 Subject: [PATCH] chore(deps): update vendored tankroyale botapi to v1.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Syncs libs/tankroyale_botapi with SirStone/robocode_tankroyale_botapi v1.0.1 (extracted from tank-royale nim branch @ 03195a814). The local SIGSEGV fixes (static event queue/SVG/intent buffers) were already ported upstream in issue #24 — content is otherwise identical. New capability (upstream #23): opponent name exposure for ticket #49. - bot.nim: gBotNames id→name table + getBotName(id) / updateBotNames() - umbrella module: dispatch BotListUpdate messages to updateBotNames() Vendored layout and wiring unchanged (--path via config.nims, module name stays tankroyale_botapi). --- libs/tankroyale_botapi/tankroyale_botapi.nim | 2 ++ .../tankroyale_botapi/bot.nim | 27 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libs/tankroyale_botapi/tankroyale_botapi.nim b/libs/tankroyale_botapi/tankroyale_botapi.nim index 81ab133..7ae784d 100644 --- a/libs/tankroyale_botapi/tankroyale_botapi.nim +++ b/libs/tankroyale_botapi/tankroyale_botapi.nim @@ -209,6 +209,8 @@ proc runReceiveLoop*(ws: SyncWebSocket; info: BotInfo; secret: string; serverUrl of "SkippedTurnEvent": let e = node.to(SkippedTurnEvent) gBot.onSkippedTurn(e) + of "BotListUpdate": + updateBotNames(node) else: discard # unknown message type — ignore except Exception as e: diff --git a/libs/tankroyale_botapi/tankroyale_botapi/bot.nim b/libs/tankroyale_botapi/tankroyale_botapi/bot.nim index d9147c5..f41f03a 100644 --- a/libs/tankroyale_botapi/tankroyale_botapi/bot.nim +++ b/libs/tankroyale_botapi/tankroyale_botapi/bot.nim @@ -13,7 +13,7 @@ ## tickChan main → bot (true = new tick ready; false = stop) ## intentChan bot → sender (JSON string to send to server; "" = stop) -import std/[json, locks, math, os, posix, syncio] +import std/[json, locks, math, os, posix, syncio, tables] import ./constants import ./schemas import ./color @@ -68,6 +68,7 @@ var gGameSetup {.guard: gLock.}: GameSetup var gTeammateIds{.guard: gLock.}: seq[int] var gVariant {.guard: gLock.}: string var gServerVersion {.guard: gLock.}: string +var gBotNames {.guard: gLock.}: Table[int, string] # Events handed main -> bot thread. Channel move, NOT a locked shared seq: # the old locked seq[BotEvent] copied GC'd payloads (strings/teamMessages) # across threads on every tick -> refcount churn under ORC + --threads:on -> @@ -166,6 +167,28 @@ proc getTurnRemaining*(): float = gTurnRemaining proc getGunTurnRemaining*(): float = gGunTurnRemaining proc getRadarTurnRemaining*(): float = gRadarTurnRemaining +proc getBotName*(id: int): string = + ## Lookup bot name by id from the last BotListUpdate. Returns "" if unknown. + withLock(gLock): result = gBotNames.getOrDefault(id, "") + +proc updateBotNames*(node: JsonNode) = + ## Update the id → name table from a BotListUpdate message (full replacement). + withLock(gLock): + gBotNames.clear() + if node.isNil: return + let botsNode = node{"bots"} + if botsNode.isNil or botsNode.kind != JArray: return + for b in botsNode: + let name = b{"name"}.getStr("") + if name.len == 0: continue + var id = -1 + if not b{"id"}.isNil: + id = b{"id"}.getInt(-1) + if id == -1 and not b{"botId"}.isNil: + id = b{"botId"}.getInt(-1) + if id == -1: continue + gBotNames[id] = name + proc getMaxSpeed*(): float = gMaxSpeed proc getMaxTurnRate*(): float = gMaxTurnRate proc getMaxGunTurnRate*(): float = gMaxGunTurnRate @@ -862,6 +885,8 @@ proc initGlobals*() = gEventChan.open(8) initLock(gLock) gEventQueue = initEventQueue() + withLock(gLock): + gBotNames = initTable[int, string]() # Debug log is opt-in: it is written every tick from two threads, so leaving # it on by default is a disk hog and an I/O stall source. Enable with # PPOB_DEBUG_LOG=1 to debug; starts fresh (truncated) each run.