mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
Add support for mafia 2 online
This commit is contained in:
parent
fc5975bf0c
commit
481a8d86c8
5 changed files with 57 additions and 40 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
43
protocols/mafia2mp.js
Normal file
43
protocols/mafia2mp.js
Normal file
|
@ -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;
|
11
protocols/mafia2online.js
Normal file
11
protocols/mafia2online.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const Mafia2Multiplayer = require('./mafia2mp');
|
||||
|
||||
class Mafia2Online extends Mafia2Multiplayer {
|
||||
constructor() {
|
||||
super();
|
||||
this.header = 'M2Online';
|
||||
this.isMafia2Online = true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Mafia2Online;
|
Loading…
Reference in a new issue