Add support for vcmp, 2.0.9, Fixes #106

This commit is contained in:
mmorrison 2019-02-03 23:40:47 -06:00
parent 89f1353c6f
commit 00f05b5385
5 changed files with 65 additions and 112 deletions

View file

@ -311,6 +311,7 @@ Games List
* Unreal Tournament 3 (ut3) * Unreal Tournament 3 (ut3)
* Urban Terror (urbanterror) * Urban Terror (urbanterror)
* V8 Supercar Challenge (v8supercar) * V8 Supercar Challenge (v8supercar)
* Vice City Multiplayer (vcmp)
* Ventrilo (ventrilo) * Ventrilo (ventrilo)
* Vietcong (vietcong) * Vietcong (vietcong)
* Vietcong 2 (vietcong2) * Vietcong 2 (vietcong2)
@ -349,7 +350,6 @@ Games List
* Sum of All Fears * Sum of All Fears
* Teeworlds * Teeworlds
* Tribes 2 * Tribes 2
* Vice City Multiplayer
* World in Conflict * World in Conflict
> Want support for one of these games? Please open an issue to show your interest! > Want support for one of these games? Please open an issue to show your interest!
@ -429,6 +429,9 @@ as well: `--debug`, `--pretty`, `--socketTimeout 5000`, etc.
Changelog Changelog
--- ---
### 2.0.9
Added support for Vice City: Multiplayer
### 2.0.8 ### 2.0.8
* Improve out-of-order packet handling for gamespy1 protocol * Improve out-of-order packet handling for gamespy1 protocol
* Work-around for buggy duplicate player reporting from bf1942 servers * Work-around for buggy duplicate player reporting from bf1942 servers

View file

@ -21,7 +21,6 @@
# teeworlds|Teeworlds|teeworlds|port=8303 # teeworlds|Teeworlds|teeworlds|port=8303
# tribes|Tribes 1: Starsiege|tribes|port_query=28001 # tribes|Tribes 1: Starsiege|tribes|port_query=28001
# tribes2|Tribes 2|tribes2|port_query=28000 # tribes2|Tribes 2|tribes2|port_query=28000
# vcmp|Vice City Multiplayer|vcmp
# worldinconflict|World in Conflict|worldinconflict # worldinconflict|World in Conflict|worldinconflict
@ -285,6 +284,7 @@ ut3|Unreal Tournament 3|ut3|port=7777,port_query_offset=-1277
urbanterror|Urban Terror|quake3|port_query=27960 urbanterror|Urban Terror|quake3|port_query=27960
v8supercar|V8 Supercar Challenge|gamespy1|port_query=16700 v8supercar|V8 Supercar Challenge|gamespy1|port_query=16700
vcmp|Vice City Multiplayer|vcmp|port=8192
ventrilo|Ventrilo|ventrilo|port=3784 ventrilo|Ventrilo|ventrilo|port=3784
vietcong|Vietcong|gamespy1|port=5425,port_query=15425 vietcong|Vietcong|gamespy1|port=5425,port_query=15425
vietcong2|Vietcong 2|gamespy2|port=5001,port_query=19967 vietcong2|Vietcong 2|gamespy2|port=5001,port_query=19967

View file

@ -4,22 +4,30 @@ class Samp extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'win1252'; this.encoding = 'win1252';
this.magicHeader = 'SAMP';
this.responseMagicHeader = null;
this.isVcmp = false;
} }
async run(state) { async run(state) {
// read info // read info
{ {
const reader = await this.sendPacket('i'); const reader = await this.sendPacket('i');
if (this.isVcmp) {
let version = reader.string(12);
version = version.replace(/\0.*$/g,'');
state.raw.version = version;
}
state.password = !!reader.uint(1); state.password = !!reader.uint(1);
state.raw.numplayers = reader.uint(2); state.raw.numplayers = reader.uint(2);
state.maxplayers = reader.uint(2); state.maxplayers = reader.uint(2);
state.name = this.readString(reader,4); state.name = this.readString(reader,4);
state.raw.gamemode = this.readString(reader,4); state.raw.gamemode = this.readString(reader,4);
this.map = this.readString(reader,4); state.raw.map = this.readString(reader,4);
} }
// read rules // read rules
{ if (!this.isVcmp) {
const reader = await this.sendPacket('r'); const reader = await this.sendPacket('r');
const ruleCount = reader.uint(2); const ruleCount = reader.uint(2);
state.raw.rules = {}; state.raw.rules = {};
@ -28,29 +36,44 @@ class Samp extends Core {
const value = this.readString(reader,1); const value = this.readString(reader,1);
state.raw.rules[key] = value; state.raw.rules[key] = value;
} }
if('mapname' in state.raw.rules)
state.map = state.raw.rules.mapname;
} }
// read players // read players
{ // don't even bother if > 100 players, because the server won't respond
const reader = await this.sendPacket('d', true); let gotPlayerData = false;
if (reader !== null) { if (state.raw.numplayers < 100) {
const playerCount = reader.uint(2); if (this.isVcmp) {
for(let i = 0; i < playerCount; i++) { const reader = await this.sendPacket('c', true);
const player = {}; if (reader !== null) {
player.id = reader.uint(1); gotPlayerData = true;
player.name = this.readString(reader,1); const playerCount = reader.uint(2);
player.score = reader.int(4); for(let i = 0; i < playerCount; i++) {
player.ping = reader.uint(4); const player = {};
state.players.push(player); player.name = this.readString(reader,1);
state.players.push(player);
}
} }
} else { } else {
for(let i = 0; i < state.raw.numplayers; i++) { const reader = await this.sendPacket('d', true);
state.players.push({}); if (reader !== null) {
gotPlayerData = true;
const playerCount = reader.uint(2);
for(let i = 0; i < playerCount; i++) {
const player = {};
player.id = reader.uint(1);
player.name = this.readString(reader,1);
player.score = reader.int(4);
player.ping = reader.uint(4);
state.players.push(player);
}
} }
} }
} }
if (!gotPlayerData) {
for(let i = 0; i < state.raw.numplayers; i++) {
state.players.push({});
}
}
} }
readString(reader,lenBytes) { readString(reader,lenBytes) {
const length = reader.uint(lenBytes); const length = reader.uint(lenBytes);
@ -59,7 +82,7 @@ class Samp extends Core {
} }
async sendPacket(type,allowTimeout) { async sendPacket(type,allowTimeout) {
const outBuffer = Buffer.alloc(11); const outBuffer = Buffer.alloc(11);
outBuffer.writeUInt32BE(0x53414D50,0); outBuffer.write(this.magicHeader,0, 4);
const ipSplit = this.options.address.split('.'); const ipSplit = this.options.address.split('.');
outBuffer.writeUInt8(parseInt(ipSplit[0]),4); outBuffer.writeUInt8(parseInt(ipSplit[0]),4);
outBuffer.writeUInt8(parseInt(ipSplit[1]),5); outBuffer.writeUInt8(parseInt(ipSplit[1]),5);
@ -68,12 +91,17 @@ class Samp extends Core {
outBuffer.writeUInt16LE(this.options.port,8); outBuffer.writeUInt16LE(this.options.port,8);
outBuffer.writeUInt8(type.charCodeAt(0),10); outBuffer.writeUInt8(type.charCodeAt(0),10);
const checkBuffer = Buffer.from(outBuffer);
if (this.responseMagicHeader) {
checkBuffer.write(this.responseMagicHeader, 0, 4);
}
return await this.udpSend( return await this.udpSend(
outBuffer, outBuffer,
(buffer) => { (buffer) => {
const reader = this.reader(buffer); const reader = this.reader(buffer);
for(let i = 0; i < outBuffer.length; i++) { for(let i = 0; i < checkBuffer.length; i++) {
if(outBuffer.readUInt8(i) !== reader.uint(1)) return; if(checkBuffer.readUInt8(i) !== reader.uint(1)) return;
} }
return reader; return reader;
}, },

12
protocols/vcmp.js Normal file
View file

@ -0,0 +1,12 @@
const Samp = require('./samp');
class Vcmp extends Samp {
constructor() {
super();
this.magicHeader = 'VCMP';
this.responseMagicHeader = 'MP04';
this.isVcmp = true;
}
}
module.exports = Vcmp;

View file

@ -1,90 +0,0 @@
/*----------------------------------------------------------------------------------------------------------\
| |
| [ LIVE GAME SERVER LIST ] [ © RICHARD PERRY FROM GREYCUBE.COM ] |
| |
| Released under the terms and conditions of the GNU General Public License Version 3 (http://gnu.org) |
| |
\-----------------------------------------------------------------------------------------------------------*/
function lgsl_query_12(&$server, &$lgsl_need, &$lgsl_fp)
{
//---------------------------------------------------------+
// REFERENCE:
// VICE CITY CURRENTLY ONLY SUPPORTS THE 'i' CHALLENGE
if ($server['b']['type'] == "samp") { $challenge_packet = "SAMP\x21\x21\x21\x21\x00\x00"; }
elseif ($server['b']['type'] == "vcmp") { $challenge_packet = "VCMP\x21\x21\x21\x21\x00\x00"; $lgsl_need['e'] = FALSE; $lgsl_need['p'] = FALSE; }
if ($lgsl_need['s']) { $challenge_packet .= "i"; }
elseif ($lgsl_need['e']) { $challenge_packet .= "r"; }
elseif ($lgsl_need['p']) { $challenge_packet .= "d"; }
fwrite($lgsl_fp, $challenge_packet);
$buffer = fread($lgsl_fp, 4096);
if (!$buffer) { return FALSE; }
//---------------------------------------------------------+
$buffer = substr($buffer, 10); // REMOVE HEADER
$response_type = lgsl_cut_byte($buffer, 1);
//---------------------------------------------------------+
if ($response_type == "i")
{
$lgsl_need['s'] = FALSE;
$server['s']['password'] = ord(lgsl_cut_byte($buffer, 1));
$server['s']['players'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");
$server['s']['playersmax'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");
$server['s']['name'] = lgsl_cut_pascal($buffer, 4);
$server['e']['gamemode'] = lgsl_cut_pascal($buffer, 4);
$server['s']['map'] = lgsl_cut_pascal($buffer, 4);
}
//---------------------------------------------------------+
elseif ($response_type == "r")
{
$lgsl_need['e'] = FALSE;
$item_total = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");
for ($i=0; $i<$item_total; $i++)
{
if (!$buffer) { return FALSE; }
$data_key = strtolower(lgsl_cut_pascal($buffer));
$data_value = lgsl_cut_pascal($buffer);
$server['e'][$data_key] = $data_value;
}
}
//---------------------------------------------------------+
elseif ($response_type == "d")
{
$lgsl_need['p'] = FALSE;
$player_total = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");
for ($i=0; $i<$player_total; $i++)
{
if (!$buffer) { return FALSE; }
$server['p'][$i]['pid'] = ord(lgsl_cut_byte($buffer, 1));
$server['p'][$i]['name'] = lgsl_cut_pascal($buffer);
$server['p'][$i]['score'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "S");
$server['p'][$i]['ping'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "S");
}
}
//---------------------------------------------------------+
return TRUE;
}