From fdd4b12ab199e1c64e0e117f5ae908dcc8ef183a Mon Sep 17 00:00:00 2001 From: rststeam Date: Sun, 5 Jan 2014 22:44:21 +0100 Subject: [PATCH 1/2] Adding support for Just Cause 2 Multiplayer This file works with latest GamePanelx --- includes/GameQv2/gameq/protocols/jc2.php | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 includes/GameQv2/gameq/protocols/jc2.php diff --git a/includes/GameQv2/gameq/protocols/jc2.php b/includes/GameQv2/gameq/protocols/jc2.php new file mode 100644 index 0000000..58083f3 --- /dev/null +++ b/includes/GameQv2/gameq/protocols/jc2.php @@ -0,0 +1,52 @@ +. + */ + +/** + * Just Cause 2 Multiplayer Protocol Class + * + * @author Austin Bischoff + */ +class GameQ_Protocols_Jc2 extends GameQ_Protocols_Source +{ + protected $name = "jc2"; + protected $name_long = "Just Cause 2 Multiplayer"; + + protected $port = 7777; + + protected function process_details() + { + // Process the server details first + $results = parent::process_details(); + + // Now we need to fix the "map" for their hack + if(isset($results['map']) + && preg_match('/(?P\d{1,})\/(?P\d{1,})/i', trim($results['map']), $m)) + { + // Define the player counts + $results['num_players'] = $m['cur']; + $results['max_players'] = $m['max']; + + unset($m); + } + + // Map never changes it seems... + $results['map'] = 'Panau'; + + return $results; + } +} From d2e1ecf60a8ad9f3df24b256be806b21cb242436 Mon Sep 17 00:00:00 2001 From: rststeam Date: Sun, 5 Jan 2014 22:47:28 +0100 Subject: [PATCH 2/2] Mafia 2 Multiplayer querry. Needs to be redone? --- includes/GameQv2/gameq/protocols/m2mp | 154 ++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 includes/GameQv2/gameq/protocols/m2mp diff --git a/includes/GameQv2/gameq/protocols/m2mp b/includes/GameQv2/gameq/protocols/m2mp new file mode 100644 index 0000000..fb8a7e2 --- /dev/null +++ b/includes/GameQv2/gameq/protocols/m2mp @@ -0,0 +1,154 @@ +. + */ + +/** + * Mafia 2 Multiplayer Protocol Class + * + * Loosely based on SAMP protocol + * + * Query port = server port + 1 + * + * Thanks to rststeam for example protocol information + * + * Testing m2mp protocol + */ +class GameQ_Protocols_M2mp extends GameQ_Protocols +{ + /** + * Array of packets we want to look up. + * Each key should correspond to a defined method in this or a parent class + * + * @var array + */ + protected $packets = array( + self::PACKET_ALL => "M2MP", + ); + + /** + * Methods to be run when processing the response(s) + * + * @var array + */ + protected $process_methods = array( + "process_all", + ); + + /** + * Default port for this server type + * + * @var int + */ + protected $port = 27016; // Default port, used if not set when instanced + + /** + * The protocol being used + * + * @var string + */ + protected $protocol = 'm2mp'; + + /** + * String name of this protocol class + * + * @var string + */ + protected $name = 'm2mp'; + + /** + * Longer string name of this protocol class + * + * @var string + */ + protected $name_long = "Mafia 2 Multiplayer"; + + /* + * Internal methods + */ + + /** + * Pre-process the server details data that was returned. + * + * @param array $packets + */ + protected function preProcess($packets) + { + // Make buffer so we can check this out + $buf = new GameQ_Buffer(implode('', $packets)); + + // Grab the header + $header = $buf->read(4); + + // Now lets verify the header + if($header != "M2MP") + { + throw new GameQ_ProtocolsException('Unable to match M2MP response header. Header: '. $header); + return FALSE; + } + + // Return the data with the header stripped, ready to go. + return $buf->getBuffer(); + } + + /** + * Process the server details + * + * @throws GameQ_ProtocolsException + */ + protected function process_all() + { + // Make sure we have a valid response + if(!$this->hasValidResponse(self::PACKET_ALL)) + { + return array(); + } + + // Set the result to a new result instance + $result = new GameQ_Result(); + + // Always dedicated + $result->add('dedicated', TRUE); + + // Preprocess and make buffer + $buf = new GameQ_Buffer($this->preProcess($this->packets_response[self::PACKET_ALL])); + + // Pull out the server information + // Note the length information is incorrect, we correct using offset options in pascal method + $result->add('servername', $buf->readPascalString(1, TRUE)); + $result->add('num_players', $buf->readPascalString(1, TRUE)); + $result->add('max_players', $buf->readPascalString(1, TRUE)); + $result->add('gamemode', $buf->readPascalString(1, TRUE)); + $result->add('password', (bool) $buf->readInt8()); + + // Read the player info, it's in the same query response for some odd reason. + while($buf->getLength()) + { + // Check to see if we ran out of info + if($buf->getLength() <= 1) + { + break; + } + + // Only player information is available + $result->addPlayer('name', $buf->readPascalString(1, TRUE)); + } + + unset($buf); + + return $result->fetch(); + } +}