Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Protocol: Call of Duty: Modern Warfare 2 #626

Merged
merged 8 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/GameQ/Protocols/Codmw2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* This file is part of GameQ.
*
* GameQ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GameQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GameQ\Protocols;

use GameQ\Buffer;
use GameQ\Result;

/**
* Call of Duty: Modern Warfare 2 Protocol Class
*
* @package GameQ\Protocols
* @author Wilson Jesus <>
*/
class Codmw2 extends Quake3
{
/**
* String name of this protocol class
*
* @type string
*/
protected $name = 'codmw2';

/**
* Longer string name of this protocol class
*
* @type string
*/
protected $name_long = "Call of Duty: Modern Warfare 2";

protected function processPlayers(Buffer $buffer)
{
// Temporarily cache players in order to remove last
$players = [];

// Loop until we are out of data
while ($buffer->getLength()) {
// Make a new buffer with this block
$playerInfo = new Buffer($buffer->readString("\x0A"));

// Read player info
$player = [
'frags' => $playerInfo->readString("\x20"),
'ping' => $playerInfo->readString("\x20"),
];

// Skip first "
$playerInfo->skip(1);

// Add player name, encoded
$player['name'] = utf8_encode(trim(($playerInfo->readString('"'))));

// Add player
$players[] = $player;
}

// Remove last, empty player
array_pop($players);

// Set the result to a new result instance
$result = new Result();

// Add players
$result->add('players', $players);

// Add Playercount
$result->add('clients', count($players));

// Clear
unset($buffer, $players);

return $result->fetch();
}
}
50 changes: 50 additions & 0 deletions tests/Protocols/Codmw2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* This file is part of GameQ.
*
* GameQ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GameQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GameQ\Tests\Protocols;

/**
* Test Class for Call of Duty: Modern Warfare 2
*
* @package GameQ\Tests\Protocols
*/
class Codmw2 extends Base
{
/**
* Test responses for Codmw2
*
* @dataProvider loadData
*
* @param $responses
* @param $result
*/
public function testResponses($responses, $result)
{

// Pull the first key off the array this is the server ip:port
$server = key($result);

$testResult = $this->queryTest(
$server,
'codmw2',
$responses
);

$this->assertEquals($result[$server], $testResult);
}
}
37 changes: 19 additions & 18 deletions tests/Protocols/Providers/Codmw2/1_response.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
����statusResponse
\challenge\\checksum\D776832D\g_gametype\war\g_hardcore\0\gamename\IW4\isPrivate\0\mapname\mp_terminal\matchtype\2\protocol\149\scr_game_allowkillcam\1\scr_team_fftype\0\shortversion\0.6.0\sv_allowAnonymous\0\sv_allowClientConsole\1\sv_floodProtect\1\sv_hostname\^:[NBS] ^3Terminal 24/7 ^:[US]\sv_maxPing\0\sv_maxRate\25000\sv_maxclients\18\sv_minPing\0\sv_privateClients\0\sv_privateClientsForClients\0\sv_pure\0\sv_securityLevel\23
6200 27 "Andrew"
1540 91 "A.C.G."
1040 42 "Heisenberg"
1420 41 "FluffyBits"
0 103 "DEXTERGX"
1640 49 "av2k4"
300 139 "OSHI 62"
2340 21 "^1No^9Mo^4Names"
400 101 "mar19"
3080 40 "Spies"
860 22 "Im a Nut"
360 143 "batya"
400 518 "Skinny"
1120 27 "Jager_R6S"
0 999 "^2Bwana"
1640 199 "YUKKY"
3500 93 "SonOfWafflez"
\challenge\\checksum\FA3F6549\g_gametype\war\g_hardcore\0\gamename\IW4\isPrivate\0\mapname\mp_terminal\matchtype\2\protocol\150\scr_game_allowkillcam\1\scr_team_fftype\0\shortversion\0.7.1\sv_allowAnonymous\0\sv_allowClientConsole\1\sv_floodProtect\1\sv_hostname\^:[NBS] ^3Terminal 24/7 ^:[US]\sv_maxPing\0\sv_maxRate\25000\sv_maxclients\18\sv_minPing\0\sv_privateClients\0\sv_privateClientsForClients\0\sv_pure\0\sv_securityLevel\23
1440 37 "amongus"
2100 80 "Nimmy404"
2260 155 "TallWhhhiteBoy"
220 71 "Breezyy4K"
1600 84 "MikeHawk-IsBig"
3640 17 "Speciulsv2"
1400 106 "kevin"
1420 42 "ThatElectricPot"
1660 80 "Spectertrader"
0 50 "nextah"
0 79 "^2UR Revs"
100 53 "Alex"
920 66 "TTV.Getherdunn7"
0 98 "^5cx760"
700 107 "Arctic"
2220 40 "BloodyBlade"
2480 51 "^:Ur Mum Gae"
1560 34 "Seeker"

2 changes: 1 addition & 1 deletion tests/Protocols/Providers/Codmw2/1_result.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"66.150.121.184:28965":{"challenge":"","checksum":"D776832D","clients":18,"g_gametype":"war","g_hardcore":"0","gamename":"IW4","gq_address":"66.150.121.184","gq_joinlink":"","gq_name":"Call of Duty: Modern Warfare 2","gq_online":true,"gq_port_client":28965,"gq_port_query":28965,"gq_protocol":"quake3","gq_transport":"udp","gq_type":"codmw2","isPrivate":"0","mapname":"mp_terminal","matchtype":"2","players":[{"frags":"6200","ping":"27","name":"Andrew"},{"frags":"1540","ping":"91","name":"A.C.G."},{"frags":"1040","ping":"42","name":"Heisenberg"},{"frags":"1420","ping":"41","name":"FluffyBits"},{"frags":"0","ping":"103","name":"DEXTERGX"},{"frags":"1640","ping":"49","name":"av2k4"},{"frags":"300","ping":"139","name":"OSHI 62"},{"frags":"2340","ping":"21","name":"^1No^9Mo^4Names"},{"frags":"400","ping":"101","name":"mar19"},{"frags":"3080","ping":"40","name":"Spies"},{"frags":"860","ping":"22","name":"Im a Nut"},{"frags":"360","ping":"143","name":"batya"},{"frags":"400","ping":"518","name":"Skinny"},{"frags":"1120","ping":"27","name":"Jager_R6S"},{"frags":"0","ping":"999","name":"^2Bwana"},{"frags":"1640","ping":"199","name":"YUKKY"},{"frags":"3500","ping":"93","name":"SonOfWafflez"},{"frags":"","ping":"","name":""}],"protocol":"149","scr_game_allowkillcam":"1","scr_team_fftype":"0","shortversion":"0.6.0","sv_allowAnonymous":"0","sv_allowClientConsole":"1","sv_floodProtect":"1","sv_hostname":"^:[NBS] ^3Terminal 24\/7 ^:[US]","sv_maxPing":"0","sv_maxRate":"25000","sv_maxclients":"18","sv_minPing":"0","sv_privateClients":"0","sv_privateClientsForClients":"0","sv_pure":"0","sv_securityLevel":"23"}}
{"66.150.121.184:28965":{"challenge":"","checksum":"FA3F6549","clients":18,"g_gametype":"war","g_hardcore":"0","gamename":"IW4","gq_address":"66.150.121.184","gq_joinlink":"","gq_name":"Call of Duty: Modern Warfare 2","gq_online":true,"gq_port_client":28965,"gq_port_query":28965,"gq_protocol":"quake3","gq_transport":"udp","gq_type":"codmw2","isPrivate":"0","mapname":"mp_terminal","matchtype":"2","players":[{"frags":"1440","ping":"37","name":"amongus"},{"frags":"2100","ping":"80","name":"Nimmy404"},{"frags":"2260","ping":"155","name":"TallWhhhiteBoy"},{"frags":"220","ping":"71","name":"Breezyy4K"},{"frags":"1600","ping":"84","name":"MikeHawk-IsBig"},{"frags":"3640","ping":"17","name":"Speciulsv2"},{"frags":"1400","ping":"106","name":"kevin"},{"frags":"1420","ping":"42","name":"ThatElectricPot"},{"frags":"1660","ping":"80","name":"Spectertrader"},{"frags":"0","ping":"50","name":"nextah"},{"frags":"0","ping":"79","name":"^2UR Revs"},{"frags":"100","ping":"53","name":"Alex"},{"frags":"920","ping":"66","name":"TTV.Getherdunn7"},{"frags":"0","ping":"98","name":"^5cx760"},{"frags":"700","ping":"107","name":"Arctic"},{"frags":"2220","ping":"40","name":"BloodyBlade"},{"frags":"2480","ping":"51","name":"^:Ur Mum Gae"},{"frags":"1560","ping":"34","name":"Seeker"}],"protocol":"150","scr_game_allowkillcam":"1","scr_team_fftype":"0","shortversion":"0.7.1","sv_allowAnonymous":"0","sv_allowClientConsole":"1","sv_floodProtect":"1","sv_hostname":"^:[NBS] ^3Terminal 24\/7 ^:[US]","sv_maxPing":"0","sv_maxRate":"25000","sv_maxclients":"18","sv_minPing":"0","sv_privateClients":"0","sv_privateClientsForClients":"0","sv_pure":"0","sv_securityLevel":"23"}}
4 changes: 3 additions & 1 deletion tests/Protocols/Providers/Codmw2/2_response.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
����statusResponse
\challenge\\checksum\6A2D4422\fs_game\mods/c32mapvote\g_gametype\dm\g_hardcore\0\gamename\IW4\isPrivate\0\mapname\mp_rust\matchtype\2\protocol\149\scr_game_allowkillcam\1\scr_team_fftype\0\shortversion\0.6.0\sv_allowAnonymous\0\sv_allowClientConsole\1\sv_floodProtect\1\sv_hostname\^:<chris32.de> ^7Vanilla | ^1Mixed^7 | Vote\sv_maxPing\0\sv_maxRate\25000\sv_maxclients\18\sv_minPing\0\sv_privateClients\0\sv_privateClientsForClients\0\sv_pure\0\sv_securityLevel\21
\challenge\\checksum\C2CB9517\fs_game\mods/c32mapvote\g_gametype\dm\g_hardcore\0\gamename\IW4\isPrivate\0\mapname\mp_rust\matchtype\2\protocol\150\scr_game_allowkillcam\1\scr_team_fftype\0\shortversion\0.7.2\sv_allowAnonymous\0\sv_allowClientConsole\1\sv_floodProtect\1\sv_hostname\^:<chris32.de> ^7Vanilla | ^1FFA^7 | MapVote\sv_maxPing\0\sv_maxRate\25000\sv_maxclients\12\sv_minPing\0\sv_privateClients\0\sv_privateClientsForClients\0\sv_pure\0\sv_securityLevel\21
50 39 "aliciaismybabe"
50 37 "imjamesBabygirl"

2 changes: 1 addition & 1 deletion tests/Protocols/Providers/Codmw2/2_result.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"213.202.223.46:28960":{"challenge":"","checksum":"6A2D4422","clients":1,"fs_game":"mods\/c32mapvote","g_gametype":"dm","g_hardcore":"0","gamename":"IW4","gq_address":"213.202.223.46","gq_joinlink":"","gq_name":"Call of Duty: Modern Warfare 2","gq_online":true,"gq_port_client":28960,"gq_port_query":28960,"gq_protocol":"quake3","gq_transport":"udp","gq_type":"codmw2","isPrivate":"0","mapname":"mp_rust","matchtype":"2","players":[{"frags":"","ping":"","name":""}],"protocol":"149","scr_game_allowkillcam":"1","scr_team_fftype":"0","shortversion":"0.6.0","sv_allowAnonymous":"0","sv_allowClientConsole":"1","sv_floodProtect":"1","sv_hostname":"^:<chris32.de> ^7Vanilla | ^1Mixed^7 | Vote","sv_maxPing":"0","sv_maxRate":"25000","sv_maxclients":"18","sv_minPing":"0","sv_privateClients":"0","sv_privateClientsForClients":"0","sv_pure":"0","sv_securityLevel":"21"}}
{"213.202.223.46:28960":{"challenge":"","checksum":"C2CB9517","clients":2,"fs_game":"mods\/c32mapvote","g_gametype":"dm","g_hardcore":"0","gamename":"IW4","gq_address":"213.202.223.46","gq_joinlink":"","gq_name":"Call of Duty: Modern Warfare 2","gq_online":true,"gq_port_client":28960,"gq_port_query":28960,"gq_protocol":"quake3","gq_transport":"udp","gq_type":"codmw2","isPrivate":"0","mapname":"mp_rust","matchtype":"2","players":[{"frags":"50","ping":"39","name":"aliciaismybabe"},{"frags":"50","ping":"37","name":"imjamesBabygirl"}],"protocol":"150","scr_game_allowkillcam":"1","scr_team_fftype":"0","shortversion":"0.7.2","sv_allowAnonymous":"0","sv_allowClientConsole":"1","sv_floodProtect":"1","sv_hostname":"^:<chris32.de> ^7Vanilla | ^1FFA^7 | MapVote","sv_maxPing":"0","sv_maxRate":"25000","sv_maxclients":"12","sv_minPing":"0","sv_privateClients":"0","sv_privateClientsForClients":"0","sv_pure":"0","sv_securityLevel":"21"}}
9 changes: 9 additions & 0 deletions tests/Protocols/Providers/Codmw2/3_response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
����statusResponse
\challenge\\checksum\2AEED8CB\g_gametype\war\g_hardcore\1\gamename\IW4\isPrivate\0\mapname\mp_complex\matchtype\2\protocol\149\scr_game_allowkillcam\1\scr_team_fftype\0\shortversion\0.6.6\sv_allowAnonymous\0\sv_allowClientConsole\1\sv_floodProtect\1\sv_hostname\^7RUSWARS ^2HARD^1#2^7^//cardicon_harrier\sv_maxPing\0\sv_maxRate\25000\sv_maxclients\18\sv_minPing\0\sv_privateClients\0\sv_privateClientsForClients\0\sv_pure\0\sv_securityLevel\23
800 181 "Khan"
3700 12 "^:freysan"
120 78 "Kakarotto"
100 25 "^4Barsik"
1300 17 "CAHEK"
820 32 "WOLFHARD"

1 change: 1 addition & 0 deletions tests/Protocols/Providers/Codmw2/3_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"185.231.245.71:28961":{"challenge":"","checksum":"2AEED8CB","clients":6,"g_gametype":"war","g_hardcore":"1","gamename":"IW4","gq_address":"185.231.245.71","gq_joinlink":"","gq_name":"Call of Duty: Modern Warfare 2","gq_online":true,"gq_port_client":28961,"gq_port_query":28961,"gq_protocol":"quake3","gq_transport":"udp","gq_type":"codmw2","isPrivate":"0","mapname":"mp_complex","matchtype":"2","players":[{"frags":"800","ping":"181","name":"Khan"},{"frags":"3700","ping":"12","name":"^:freysan"},{"frags":"120","ping":"78","name":"Kakarotto"},{"frags":"100","ping":"25","name":"^4Barsik"},{"frags":"1300","ping":"17","name":"CAHEK"},{"frags":"820","ping":"32","name":"WOLFHARD"}],"protocol":"149","scr_game_allowkillcam":"1","scr_team_fftype":"0","shortversion":"0.6.6","sv_allowAnonymous":"0","sv_allowClientConsole":"1","sv_floodProtect":"1","sv_hostname":"^7RUSWARS ^2HARD^1#2^7^\u0001\/\/\u0010cardicon_harrier","sv_maxPing":"0","sv_maxRate":"25000","sv_maxclients":"18","sv_minPing":"0","sv_privateClients":"0","sv_privateClientsForClients":"0","sv_pure":"0","sv_securityLevel":"23"}}