From 1b85fda837fb2e3f8fc82c879a5805740c5250cb Mon Sep 17 00:00:00 2001 From: mmorrison Date: Sat, 5 May 2018 03:00:54 -0500 Subject: [PATCH] Add battalion 1944 Fixes #84 --- README.md | 1 + games.txt | 1 + protocols/valve.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3dc5a82..a4a2784 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ Games List * ArmA 3 (arma3) [[Separate Query Port](#separate-query-port)] * Armagetron (armagetron) * Baldur's Gate (baldursgate) [[Separate Query Port](#separate-query-port)] +* Battalion 1944 (bat1944) [[Separate Query Port](#separate-query-port)] * Battlefield 1942 (bf1942) [[Separate Query Port](#separate-query-port)] * Battlefield Vietnam (bfv) [[Separate Query Port](#separate-query-port)] * Battlefield 2 (bf2) [[Separate Query Port](#separate-query-port)] diff --git a/games.txt b/games.txt index 00617bc..985ed22 100644 --- a/games.txt +++ b/games.txt @@ -49,6 +49,7 @@ arma3|ArmA 3|valve|port=2302,port_query_offset=1 armagetron|Armagetron|armagetron|port=4534 baldursgate|Baldur's Gate|gamespy1|port=6073,port_query=1470 +bat1944|Battalion 1944|valve|port=7777,port_query_offset=3 bf1942|Battlefield 1942|gamespy1|port=14567,port_query=23000 bfv|Battlefield Vietnam|gamespy2|port=15567,port_query=23000 diff --git a/protocols/valve.js b/protocols/valve.js index a63ef54..6119ef4 100644 --- a/protocols/valve.js +++ b/protocols/valve.js @@ -37,6 +37,7 @@ class Valve extends require('./core') { (c) => { this.queryChallenge(state,c); }, (c) => { this.queryPlayers(state,c); }, (c) => { this.queryRules(state,c); }, + (c) => { this.cleanup(state,c); }, (c) => { this.finish(state); } ]); } @@ -203,10 +204,10 @@ class Valve extends require('./core') { } queryRules(state,c) { + state.raw.rules = {}; this.sendPacket(0x56,true,false,0x45,(b) => { const reader = this.reader(b); const num = reader.uint(2); - state.raw.rules = {}; for(let i = 0; i < num; i++) { const key = reader.string(); const value = reader.string(); @@ -222,6 +223,34 @@ class Valve extends require('./core') { }); } + cleanup(state,c) { + // Battalion 1944 puts its info into rules fields for some reason + if ('bat_name_s' in state.raw.rules) { + state.name = state.raw.rules.bat_name_s; + delete state.raw.rules.bat_name_s; + if ('bat_player_count_s' in state.raw.rules) { + state.raw.numplayers = parseInt(state.raw.rules.bat_player_count_s); + state.players = []; + for(let i = 0; i < state.raw.numplayers; i++) { + state.players.push({}); + } + delete state.raw.rules.bat_player_count_s; + } + if ('bat_max_players_i' in state.raw.rules) { + state.maxplayers = parseInt(state.raw.rules.bat_max_players_i); + delete state.raw.rules.bat_max_players_i; + } + if ('bat_has_password_s' in state.raw.rules) { + state.password = state.raw.rules.bat_has_password_s === 'Y'; + delete state.raw.rules.bat_has_password_s; + } + // apparently map is already right, and this var is often wrong + delete state.raw.rules.bat_map_s; + } + + c(); + } + sendPacket(type,sendChallenge,payload,expect,callback,ontimeout) { const packetStorage = {};