Skip to content

Commit

Permalink
Changed Armed Assault 3 class to Arma3. Left behind dummy class for b…
Browse files Browse the repository at this point in the history
…ackwards compatibility but everyone should move to 'arma3' as the protocol name. See #299
  • Loading branch information
Austinb committed Dec 12, 2016
1 parent f4dbb14 commit 9d0c4a4
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 161 deletions.
183 changes: 183 additions & 0 deletions src/GameQ/Protocols/Arma3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?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;

/**
* Class Armed Assault 3
*
* Rules protocol reference: https://community.bistudio.com/wiki/Arma_3_ServerBrowserProtocol2
*
* @package GameQ\Protocols
* @author Austin Bischoff <austin@codebeard.com>
* @author Memphis017 <https://github.com/Memphis017>
*/
class Arma3 extends Source
{
/**
* DLC ^2 constants
*/
const DLC_KARTS = 1,
DLC_MARKSMEN = 2,
DLC_HELICOPTERS = 4,
DLC_APEX = 16;

/**
* Defines the names for the specific game DLCs
*
* @var array
*/
protected $dlcNames = [
self::DLC_KARTS => 'Karts',
self::DLC_MARKSMEN => 'Marksmen',
self::DLC_HELICOPTERS => 'Helicopters',
self::DLC_APEX => 'Apex',
];


/**
* String name of this protocol class
*
* @type string
*/
protected $name = 'arma3';

/**
* Longer string name of this protocol class
*
* @type string
*/
protected $name_long = "Arma3";

/**
* Query port = client_port + 1
*
* @type int
*/
protected $port_diff = 1;

/**
* Process the rules since Arma3 changed their response for rules
*
* @param Buffer $buffer
*
* @return array
* @throws \GameQ\Exception\Protocol
*/
protected function processRules(Buffer $buffer)
{
// Total number of packets, burn it
$buffer->readInt16();

// Will hold the data string
$data = '';

// Loop until we run out of strings
while ($buffer->getLength()) {
// Burn the delimiters (i.e. \x01\x04\x00)
$buffer->readString();

// Add the data to the string, we are reassembling it
$data .= $buffer->readString();
}

// Restore escaped sequences
$data = str_replace(["\x01\x01", "\x01\x02", "\x01\x03"], ["\x01", "\x00", "\xFF"], $data);

// Make a new buffer with the reassembled data
$responseBuffer = new Buffer($data);

// Kill the old buffer, should be empty
unset($buffer, $data);

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

// Get results
$result->add('rules_protocol_version', $responseBuffer->readInt8());
$result->add('overflow', $responseBuffer->readInt8());
$dlcBit = $responseBuffer->readInt8(); // Grab DLC bit and use it later
$responseBuffer->skip(); // Reserved, burn it
// Grab difficulty so we can man handle it...
$difficulty = $responseBuffer->readInt8();

// Process difficulty
$result->add('3rd_person', $difficulty >> 7);
$result->add('advanced_flight_mode', ($difficulty >> 6) & 1);
$result->add('difficulty_ai', ($difficulty >> 3) & 3);
$result->add('difficulty_level', $difficulty & 3);

unset($difficulty);

// Crosshair
$result->add('crosshair', $responseBuffer->readInt8());

// Next are the dlc bits so loop over the dlcBit so we can determine which DLC's are running
for ($x = 1; $x <= $dlcBit; $x *= 2) {
// Enabled, add it to the list
if ($x & $dlcBit) {
$result->addSub('dlcs', 'name', $this->dlcNames[$x]);
$result->addSub('dlcs', 'hash', dechex($responseBuffer->readInt32()));
}
}

// No longer needed
unset($dlcBit);

// Grab the mod count
$modCount = $responseBuffer->readInt8();

// Add mod count
$result->add('mod_count', $modCount);

// Loop the mod count and add them
for ($x = 0; $x < $modCount; $x++) {
// Add the mod to the list
$result->addSub('mods', 'hash', dechex($responseBuffer->readInt32()));
$result->addSub('mods', 'steam_id', hexdec($responseBuffer->readPascalString(0, true)));
$result->addSub('mods', 'name', $responseBuffer->readPascalString(0, true));
}

unset($modCount, $x);

// Burn the signatures count, we will just loop until we run out of strings
$responseBuffer->read();

// Make signatures array
$signatures = [];

// Loop until we run out of strings
while ($responseBuffer->getLength()) {
//$result->addSub('signatures', 0, $responseBuffer->readPascalString(0, true));
$signatures[] = $responseBuffer->readPascalString(0, true);
}

// Add as a simple array
$result->add('signatures', $signatures);

// Add signatures count
$result->add('signature_count', count($signatures));

unset($responseBuffer, $signatures);

return $result->fetch();
}
}
163 changes: 6 additions & 157 deletions src/GameQ/Protocols/Armedassault3.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,166 +18,15 @@

namespace GameQ\Protocols;

use GameQ\Buffer;
use GameQ\Result;

/**
* Class Armed Assault 3
* Armed assault 3 dummy Protocol Class
*
* Rules protocol reference: https://community.bistudio.com/wiki/Arma_3_ServerBrowserProtocol2
* Added for backward compatibility, please update to class arma3
*
* @package GameQ\Protocols
* @author Austin Bischoff <austin@codebeard.com>
* @author Memphis017 <https://github.com/Memphis017>
* @deprecated v3.0.10
* @package GameQ\Protocols
* @author Austin Bischoff <austin@codebeard.com>
*/
class Armedassault3 extends Source
class Armedassault3 extends Arma3
{
/**
* DLC ^2 constants
*/
const DLC_KARTS = 1,
DLC_MARKSMEN = 2,
DLC_HELICOPTERS = 4,
DLC_APEX = 16;

/**
* Defines the names for the specific game DLCs
*
* @var array
*/
protected $dlcNames = [
self::DLC_KARTS => 'Karts',
self::DLC_MARKSMEN => 'Marksmen',
self::DLC_HELICOPTERS => 'Helicopters',
self::DLC_APEX => 'Apex',
];


/**
* String name of this protocol class
*
* @type string
*/
protected $name = 'armedassault3';

/**
* Longer string name of this protocol class
*
* @type string
*/
protected $name_long = "Armed Assault 3";

/**
* Query port = client_port + 1
*
* @type int
*/
protected $port_diff = 1;

/**
* Process the rules since Arma3 changed their response for rules
*
* @param Buffer $buffer
*
* @return array
* @throws \GameQ\Exception\Protocol
*/
protected function processRules(Buffer $buffer)
{
// Total number of packets, burn it
$buffer->readInt16();

// Will hold the data string
$data = '';

// Loop until we run out of strings
while ($buffer->getLength()) {
// Burn the delimiters (i.e. \x01\x04\x00)
$buffer->readString();

// Add the data to the string, we are reassembling it
$data .= $buffer->readString();
}

// Restore escaped sequences
$data = str_replace(["\x01\x01", "\x01\x02", "\x01\x03"], ["\x01", "\x00", "\xFF"], $data);

// Make a new buffer with the reassembled data
$responseBuffer = new Buffer($data);

// Kill the old buffer, should be empty
unset($buffer, $data);

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

// Get results
$result->add('rules_protocol_version', $responseBuffer->readInt8());
$result->add('overflow', $responseBuffer->readInt8());
$dlcBit = $responseBuffer->readInt8(); // Grab DLC bit and use it later
$responseBuffer->skip(); // Reserved, burn it
// Grab difficulty so we can man handle it...
$difficulty = $responseBuffer->readInt8();

// Process difficulty
$result->add('3rd_person', $difficulty >> 7);
$result->add('advanced_flight_mode', ($difficulty >> 6) & 1);
$result->add('difficulty_ai', ($difficulty >> 3) & 3);
$result->add('difficulty_level', $difficulty & 3);

unset($difficulty);

// Crosshair
$result->add('crosshair', $responseBuffer->readInt8());

// Next are the dlc bits so loop over the dlcBit so we can determine which DLC's are running
for ($x = 1; $x <= $dlcBit; $x *= 2) {
// Enabled, add it to the list
if ($x & $dlcBit) {
$result->addSub('dlcs', 'name', $this->dlcNames[$x]);
$result->addSub('dlcs', 'hash', dechex($responseBuffer->readInt32()));
}
}

// No longer needed
unset($dlcBit);

// Grab the mod count
$modCount = $responseBuffer->readInt8();

// Add mod count
$result->add('mod_count', $modCount);

// Loop the mod count and add them
for ($x = 0; $x < $modCount; $x++) {
// Add the mod to the list
$result->addSub('mods', 'hash', dechex($responseBuffer->readInt32()));
$result->addSub('mods', 'steam_id', hexdec($responseBuffer->readPascalString(0, true)));
$result->addSub('mods', 'name', $responseBuffer->readPascalString(0, true));
}

unset($modCount, $x);

// Burn the signatures count, we will just loop until we run out of strings
$responseBuffer->read();

// Make signatures array
$signatures = [];

// Loop until we run out of strings
while ($responseBuffer->getLength()) {
//$result->addSub('signatures', 0, $responseBuffer->readPascalString(0, true));
$signatures[] = $responseBuffer->readPascalString(0, true);
}

// Add as a simple array
$result->add('signatures', $signatures);

// Add signatures count
$result->add('signature_count', count($signatures));

unset($responseBuffer, $signatures);

return $result->fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @package GameQ\Tests\Protocols
*/
class Armedassault3 extends Base
class Arma3 extends Base
{
/**
* Test responses for Arma 3
Expand All @@ -41,7 +41,7 @@ public function testResponses($responses, $result)

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

Expand Down
1 change: 1 addition & 0 deletions tests/Protocols/Providers/Arma3/1_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"192.223.29.245:2312":{"3rd_person":1,"advanced_flight_mode":0,"crosshair":1,"dedicated":"d","difficulty_ai":1,"difficulty_level":1,"dlcs":[{"name":"Karts","hash":"a5c8c24c"},{"name":"Marksmen","hash":"58644447"},{"name":"Helicopters","hash":"6b140d2c"},{"name":"Apex","hash":"c794d30d"}],"game_descr":"King of the Hill by Sa-Matra (v9+++, Infantry)","game_dir":"Arma3","game_id":107410,"gq_address":"192.223.29.245","gq_joinlink":"steam:\/\/connect\/192.223.29.245:2312\/","gq_name":"Arma3","gq_online":true,"gq_port_client":2312,"gq_port_query":2313,"gq_protocol":"source","gq_transport":"udp","gq_type":"arma3","hostname":"HostileTakeover.co - King Of The Hill - US #2 - Infantry","keywords":"bt,r166,n0,s7,i1,mf,lf,vt,dt,tkoth,g65545,h6ecdda65,c0-52,f0,pw,e15,j0,k0,","map":"Altis","max_players":120,"mod_count":0,"num_bots":0,"num_players":78,"os":"w","overflow":0,"password":0,"players":[{"id":0,"name":"t-rev","score":4,"time":1678.1127929688},{"id":0,"name":"gutpile","score":0,"time":1678.0617675781},{"id":0,"name":"Gamble","score":-3,"time":1678.0107421875},{"id":0,"name":"Abraxas","score":0,"time":1677.9584960938},{"id":0,"name":"OVERED","score":0,"time":1677.9068603516},{"id":0,"name":"AnimalMother","score":5,"time":1677.8547363281},{"id":0,"name":"JJbadtower","score":0,"time":1677.802734375},{"id":0,"name":"paulo","score":2,"time":1677.3776855469},{"id":0,"name":"AnimalBrother","score":1,"time":1669.1322021484},{"id":0,"name":"Easy","score":2,"time":1664.2368164062},{"id":0,"name":"ForbiddenLegend","score":2,"time":1663.6546630859},{"id":0,"name":"[FBA] Raphael","score":-5,"time":1662.3812255859},{"id":0,"name":"Vex","score":1,"time":1658.921875},{"id":0,"name":"RiK","score":2,"time":1651.7073974609},{"id":0,"name":"Nick","score":3,"time":1639.5153808594},{"id":0,"name":"ComandanteBoss","score":0,"time":1619.7233886719},{"id":0,"name":"Saintzinho","score":3,"time":1604.6950683594},{"id":0,"name":"Mushyyn","score":1,"time":1599.7711181641},{"id":0,"name":"Stalin","score":8,"time":1574.0270996094},{"id":0,"name":"Scarlatti","score":3,"time":1542.2535400391},{"id":0,"name":"oF13RCE","score":0,"time":1519.8354492188},{"id":0,"name":"Boyd Guy Manson","score":11,"time":1519.7712402344},{"id":0,"name":"El","score":2,"time":1477.3687744141},{"id":0,"name":"Ragnald","score":0,"time":1468.6982421875},{"id":0,"name":"Socalfisher","score":-2,"time":1466.2082519531},{"id":0,"name":"BINGHAM","score":-12,"time":1428.2354736328},{"id":0,"name":"Sgt. GhostRider","score":-2,"time":1414.9805908203},{"id":0,"name":"Buck McKenzie [SaltTeam6]","score":1,"time":1401.1704101562},{"id":0,"name":"Snu","score":0,"time":1381.2198486328},{"id":0,"name":"KATIBERO","score":-1,"time":1347.7222900391},{"id":0,"name":"SPEAR | Ratel [SPEAR]","score":0,"time":1336.0582275391},{"id":0,"name":"Edgar","score":0,"time":1291.2678222656},{"id":0,"name":"OLDSPICE [TLL]","score":0,"time":1172.7967529297},{"id":0,"name":"MasterJeffe","score":0,"time":1072.9832763672},{"id":0,"name":"Gen.Slayer","score":2,"time":1059.16796875},{"id":0,"name":"Brennan","score":0,"time":1023.8662719727},{"id":0,"name":"Joey","score":3,"time":997.58587646484},{"id":0,"name":"I | George King","score":9,"time":962.63208007812},{"id":0,"name":"KID","score":-5,"time":931.37731933594},{"id":0,"name":"Ethan","score":-1,"time":901.58911132812},{"id":0,"name":"marti","score":0,"time":821.86749267578},{"id":0,"name":"kingo","score":-6,"time":811.40942382812},{"id":0,"name":"InvisibleKiller","score":-2,"time":803.3681640625},{"id":0,"name":"Dennis","score":0,"time":788.11627197266},{"id":0,"name":"Hollow","score":0,"time":729.32281494141},{"id":0,"name":"[A.H] Twiistaskeey","score":1,"time":704.02703857422},{"id":0,"name":"Margret","score":0,"time":700.07385253906},{"id":0,"name":"Jeezus","score":0,"time":691.99047851562},{"id":0,"name":"ghostly_ninja1","score":-2,"time":684.95770263672},{"id":0,"name":"Major Drunk","score":1,"time":481.56610107422},{"id":0,"name":"vantak ","score":0,"time":473.2067565918},{"id":0,"name":"StEvE","score":0,"time":452.69955444336},{"id":0,"name":"Blastburn94","score":0,"time":443.25198364258},{"id":0,"name":"Bonerfart","score":0,"time":353.39660644531},{"id":0,"name":"TinkTink88","score":0,"time":351.58361816406},{"id":0,"name":"Lccoo","score":0,"time":349.22796630859},{"id":0,"name":"issac","score":1,"time":336.12591552734},{"id":0,"name":"[GFKR]Cameron","score":0,"time":296.54791259766},{"id":0,"name":"John","score":0,"time":290.63470458984},{"id":0,"name":"CPL. Noah","score":0,"time":278.65484619141},{"id":0,"name":"GloJudge [FMT]","score":0,"time":247.36380004883},{"id":0,"name":"borges","score":0,"time":225.27493286133},{"id":0,"name":"Glen","score":-2,"time":207.66102600098},{"id":0,"name":"Valentino Vegas","score":0,"time":201.99870300293},{"id":0,"name":"Super Critical","score":-13,"time":164.65266418457},{"id":0,"name":"Ryan","score":0,"time":148.58499145508},{"id":0,"name":"[666]Pr0Magic","score":0,"time":142.20388793945},{"id":0,"name":"Greys","score":0,"time":139.02325439453},{"id":0,"name":"Lilkbob","score":0,"time":118.11871337891},{"id":0,"name":"JarEp","score":0,"time":106.53130340576},{"id":0,"name":"BarMan","score":0,"time":102.55344390869},{"id":0,"name":"Donut","score":0,"time":98.713569641113},{"id":0,"name":"Lem","score":0,"time":98.636184692383},{"id":0,"name":"Tony Soprano","score":0,"time":83.17081451416},{"id":0,"name":"Michael Stevens","score":0,"time":47.136447906494},{"id":0,"name":"Bal'to","score":0,"time":21.11442565918},{"id":0,"name":"LiquidMetal","score":0,"time":7.8195986747742},{"id":0,"name":"Rando","score":0,"time":5.9321384429932}],"port":2312,"protocol":17,"rules_protocol_version":2,"secure":0,"signature_count":5,"signatures":["a3","DragonFyre25","dragonfyrelitev3","jsrs-apex","jsrs21"],"steam_id":90105598934646785,"steamappid":0,"version":"1.66.139519"}}
Loading

0 comments on commit 9d0c4a4

Please sign in to comment.