diff --git a/README.md b/README.md index 2d56976..359a458 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ Games List * Left 4 Dead (left4dead) * Left 4 Dead 2 (left4dead2) * Mafia 2 Multiplayer (m2mp) +* Mafia 2 Online (m2o) * Medieval Engineers (medievalengineers) * Medal of Honor: Allied Assault (mohaa) * Medal of Honor: Pacific Assault (mohpa) diff --git a/games.txt b/games.txt index e0b2c93..15db75e 100644 --- a/games.txt +++ b/games.txt @@ -134,7 +134,8 @@ kspdmp|DMP - KSP Multiplayer|kspdmp|port=6702,port_query_offset=1 kzmod|KzMod|valve|port=27015 left4dead|Left 4 Dead|valve|port=27015 left4dead2|Left 4 Dead 2|valve|port=27015 -m2mp|Mafia 2 Multiplayer|m2mp|port=27016,port_query_offset=1 +m2mp|Mafia 2 Multiplayer|mafia2mp|port=27016,port_query_offset=1 +m2o|Mafia 2 Online|mafia2online|port=27015,port_query_offset=1 medievalengineers|Medieval Engineers|valve|port=27015 mohaa|Medal of Honor: Allied Assault|gamespy1|port=12203,port_query_offset=97 diff --git a/protocols/m2mp.js b/protocols/m2mp.js deleted file mode 100644 index 809f505..0000000 --- a/protocols/m2mp.js +++ /dev/null @@ -1,39 +0,0 @@ -const Core = require('./core'); - -class M2mp extends Core { - constructor() { - super(); - this.encoding = 'latin1'; - } - - async run(state) { - const body = await this.udpSend('M2MP',(buffer) => { - const reader = this.reader(buffer); - const header = reader.string(4); - if (header !== 'M2MP') return; - return reader.rest(); - }); - - const reader = this.reader(body); - state.name = this.readString(reader); - state.raw.numplayers = this.readString(reader); - state.maxplayers = this.readString(reader); - state.raw.gamemode = this.readString(reader); - state.password = !!reader.uint(1); - state.gamePort = this.options.port - 1; - - while(!reader.done()) { - const name = this.readString(reader); - if(!name) break; - state.players.push({ - name:name - }); - } - } - - readString(reader) { - return reader.pascalString(1,-1); - } -} - -module.exports = M2mp; diff --git a/protocols/mafia2mp.js b/protocols/mafia2mp.js new file mode 100644 index 0000000..21992d6 --- /dev/null +++ b/protocols/mafia2mp.js @@ -0,0 +1,43 @@ +const Core = require('./core'); + +class Mafia2Multiplayer extends Core { + constructor() { + super(); + this.encoding = 'latin1'; + this.header = 'M2MP'; + this.isMafia2Online = false; + } + + async run(state) { + const body = await this.udpSend(this.header,(buffer) => { + const reader = this.reader(buffer); + const header = reader.string(this.header.length); + if (header !== this.header) return; + return reader.rest(); + }); + + const reader = this.reader(body); + state.name = this.readString(reader); + state.raw.numplayers = this.readString(reader); + state.maxplayers = parseInt(this.readString(reader)); + state.raw.gamemode = this.readString(reader); + state.password = !!reader.uint(1); + state.gamePort = this.options.port - 1; + + while(!reader.done()) { + const player = {}; + player.name = this.readString(reader); + if(!player.name) break; + if (this.isMafia2Online) { + player.ping = parseInt(this.readString(reader)); + } + state.players.push(player); + } + } + + readString(reader) { + return reader.pascalString(1,-1); + } +} + +module.exports = Mafia2Multiplayer; diff --git a/protocols/mafia2online.js b/protocols/mafia2online.js new file mode 100644 index 0000000..0523554 --- /dev/null +++ b/protocols/mafia2online.js @@ -0,0 +1,11 @@ +const Mafia2Multiplayer = require('./mafia2mp'); + +class Mafia2Online extends Mafia2Multiplayer { + constructor() { + super(); + this.header = 'M2Online'; + this.isMafia2Online = true; + } +} + +module.exports = Mafia2Online;