Skip to content

Commit

Permalink
GameQ Fix & Update
Browse files Browse the repository at this point in the history
Provided by https://steamcommunity.com/id/0null1works/
(ဪTheLupi#5961)
  • Loading branch information
AEon-Jan committed Jan 6, 2022
1 parent 26054f6 commit 4236d48
Show file tree
Hide file tree
Showing 46 changed files with 1,567 additions and 274 deletions.
4 changes: 2 additions & 2 deletions third_party/gameq/GameQ/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public function readStringMulti($delims, &$delimfound = null)
// Get position of delimiters
$pos = [];
foreach ($delims as $delim) {
if ($p = strpos($this->data, $delim, min($this->index, $this->length))) {
$pos[] = $p;
if ($index = strpos($this->data, $delim, min($this->index, $this->length))) {
$pos[] = $index;
}
}

Expand Down
2 changes: 2 additions & 0 deletions third_party/gameq/GameQ/Filters/Secondstohuman.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected function iterate(array &$result)
// Iterate and update the result
$result[$key] = $this->iterate($value);
} elseif (in_array($key, $this->options[self::OPTION_TIMEKEYS])) {
// Make sure the value is a float (throws E_WARNING in PHP 7.1+)
$value = floatval($value);
// We match one of the keys we are wanting to convert so add it and move on
$result[sprintf(self::RESULT_KEY, $key)] = sprintf(
"%02d:%02d:%02d",
Expand Down
15 changes: 15 additions & 0 deletions third_party/gameq/GameQ/Filters/Stripcolors.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Stripcolors extends Base
/**
* Apply this filter
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @param array $result
* @param \GameQ\Server $server
*
Expand Down Expand Up @@ -62,6 +64,9 @@ public function apply(array $result, Server $server)
case 'gamespy2':
array_walk_recursive($result, [$this, 'stripUnreal']);
break;
case 'source':
array_walk_recursive($result, [$this, 'stripSource']);
break;
}

/*$data['filtered'][ $server->id() ] = $result;
Expand Down Expand Up @@ -97,4 +102,14 @@ protected function stripUnreal(&$string)
{
$string = preg_replace('/\x1b.../', '', $string);
}

/**
* Strip color codes from Source based games
*
* @param string $string
*/
protected function stripSource(&$string)
{
$string = strip_tags($string);
}
}
14 changes: 8 additions & 6 deletions third_party/gameq/GameQ/GameQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* 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;

use GameQ\Exception\Protocol as ProtocolException;
Expand Down Expand Up @@ -43,6 +44,7 @@ class GameQ
/*
* Constants
*/
const PROTOCOLS_DIRECTORY = __DIR__ . '/Protocols';

/* Static Section */

Expand Down Expand Up @@ -408,10 +410,10 @@ protected function doChallenges()
'server_id' => $server_id,
'socket' => $socket,
];
} catch (QueryException $e) {
} catch (QueryException $exception) {
// Check to see if we are in debug, if so bubble up the exception
if ($this->debug) {
throw new \Exception($e->getMessage(), $e->getCode(), $e);
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
}
}

Expand Down Expand Up @@ -509,13 +511,13 @@ protected function doQueries()
'server_id' => $server_id,
'socket' => $socket,
];
} catch (QueryException $e) {
} catch (QueryException $exception) {
// Check to see if we are in debug, if so bubble up the exception
if ($this->debug) {
throw new \Exception($e->getMessage(), $e->getCode(), $e);
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
}

break;
continue;
}

// Clean up the sockets, if any left over
Expand Down Expand Up @@ -636,7 +638,7 @@ protected function doApplyFilters(array $results, Server $server)

// Apply the filter to the data
$results = $filter->apply($results, $server);
} catch (\ReflectionException $e) {
} catch (\ReflectionException $exception) {
// Invalid, skip it
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
namespace GameQ\Protocols;

/**
* Class Aoc
* Class Arma
*
* @package GameQ\Protocols
* @author Austin Bischoff <[email protected]>
*
* @author Wilson Jesus <>
*/
class Aoc extends Source
class Arma extends Gamespy2
{
/**
* String name of this protocol class
*
* @type string
*/
protected $name = 'aoc';
protected $name = 'arma';

/**
* Longer string name of this protocol class
*
* @type string
*/
protected $name_long = "Age of Chivalry";
protected $name_long = "ArmA Armed Assault";
}
150 changes: 4 additions & 146 deletions third_party/gameq/GameQ/Protocols/Arma3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of GameQ.
*
Expand All @@ -18,35 +19,15 @@

namespace GameQ\Protocols;

use GameQ\Buffer;
use GameQ\Result;

/**
* Class Armed Assault 3
*
* Rules protocol reference: https://community.bistudio.com/wiki/Arma_3_ServerBrowserProtocol2
* Class Dayzmod
*
* @package GameQ\Protocols
* @author Marcel Bößendörfer <[email protected]>
* @author Austin Bischoff <[email protected]>
* @author Memphis017 <https://github.com/Memphis017>
*/
class Arma3 extends Source
class Arma3 extends Armedassault2oa
{
/**
* Defines the names for the specific game DLCs
*
* @var array
*/
protected $dlcNames = [
'Karts',
'Marksmen',
'Helicopters',
'Apex',
'Jets',
'Laws of War',
'Tac-Ops',
'Tanks',
];

/**
* String name of this protocol class
Expand All @@ -61,127 +42,4 @@ class Arma3 extends Source
* @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());

/*
* Due to a bug in the DLC byte response from the ARMA servers we end here until the DLC byte bug can be fixed
* or can code around the issue.
* See https://github.com/Austinb/GameQ/issues/420
*/
unset($dlcBit);
return $result->fetch();

//$dlcBit = 255;

/*// Loop over the DLC bit so we can pull in the infor for the DLC (if enabled)
for ($x = 0; $x < 8; $x++) {
if (($dlcBit >> $x) & 1) {
$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();*/
}
}
4 changes: 2 additions & 2 deletions third_party/gameq/GameQ/Protocols/Armedassault2oa.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Armedassault2oa extends Source
protected $name_long = "Armed Assault 2: Operation Arrowhead";

/**
* Query port = client_port - 1
* Query port = client_port + 1
*
* @type int
*/
protected $port_diff = -1;
protected $port_diff = 1;
}
15 changes: 12 additions & 3 deletions third_party/gameq/GameQ/Protocols/Ase.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,21 @@ class Ase extends Protocol
*/
public function processResponse()
{

// Create a new buffer
$buffer = new Buffer(implode('', $this->packets_response));

// Burn the header
$buffer->skip(4);
// Check for valid response
if ($buffer->getLength() < 4) {
throw new \GameQ\Exception\Protocol(sprintf('%s The response from the server was empty.', __METHOD__));
}

// Read the header
$header = $buffer->read(4);

// Verify header
if ($header !== 'EYE1') {
throw new \GameQ\Exception\Protocol(sprintf('%s The response header "%s" does not match expected "EYE1"', __METHOD__, $header));
}

// Create a new result
$result = new Result();
Expand Down
Loading

0 comments on commit 4236d48

Please sign in to comment.