From 71634b3c6e7df369cc88970af395796cefdbcb59 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 18 Feb 2022 23:53:43 +0100 Subject: [PATCH] Fix Samp add server by domain (#593) * Update Samp.php * Update Server.php * Update Server.php * Fix test responses to reflect changes * Create Issue588.php * Update Issue588.php * Update Issue588.php * Update Samp.php * Update Issue588.php * Move queryTest to TestBase and dry issue tests, Fix stub in isse 588 test, --- src/GameQ/Server.php | 17 +++-- tests/Issues/Issue307.php | 35 +---------- tests/Issues/Issue382.php | 35 +---------- tests/Issues/Issue588.php | 62 +++++++++++++++++++ tests/Protocols/Base.php | 55 ---------------- tests/Protocols/Providers/Arma/1_result.json | 2 +- .../Providers/Teeworlds/1_result.json | 2 +- .../Providers/Terraria/1_result.json | 2 +- tests/Protocols/Providers/Wurm/2_result.json | 2 +- tests/TestBase.php | 55 ++++++++++++++++ 10 files changed, 134 insertions(+), 133 deletions(-) create mode 100644 tests/Issues/Issue588.php diff --git a/src/GameQ/Server.php b/src/GameQ/Server.php index dff8f77c..c7834924 100644 --- a/src/GameQ/Server.php +++ b/src/GameQ/Server.php @@ -203,13 +203,18 @@ protected function checkAndSetIpPort($ip_address) ); } - // Validate the IPv4 value, if FALSE is not a valid IP, maybe a hostname. Try to resolve - if (!filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,]) - && $this->ip === gethostbyname($this->ip) - ) { + // Validate the IPv4 value, if FALSE is not a valid IP, maybe a hostname. + if (! filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])) { + // Try to resolve the hostname to IPv4 + $resolved = gethostbyname($this->ip); + // When gethostbyname() fails it returns the original string - // so if ip and the result from gethostbyname() are equal this failed. - throw new Exception("Unable to resolve the host '{$this->ip}' to an IP address."); + if ($this->ip === $resolved) { + // so if ip and the result from gethostbyname() are equal this failed. + throw new Exception("Unable to resolve the host '{$this->ip}' to an IP address."); + } else { + $this->ip = $resolved; + } } } } diff --git a/tests/Issues/Issue307.php b/tests/Issues/Issue307.php index 3ef2bc64..33d87ba4 100644 --- a/tests/Issues/Issue307.php +++ b/tests/Issues/Issue307.php @@ -40,40 +40,7 @@ public function test1() $filePath = sprintf('%s/Providers/307.txt', __DIR__); - // Create a mock server - $server = // Create a mock server - $this->getMockBuilder('\GameQ\Server') - ->setConstructorArgs([ - [ - \GameQ\Server::SERVER_HOST => '127.0.0.1:27015', - \GameQ\Server::SERVER_TYPE => 'csgo', - ], - ]) - ->enableProxyingToOriginalMethods() - ->getMock(); - - // Invoke beforeSend function - $server->protocol()->beforeSend($server); - - // Set the packet response as if we have really queried it - $server->protocol()->packetResponse(explode(PHP_EOL . '||' . PHP_EOL, file_get_contents($filePath))); - - // Create a mock GameQ - $gq_mock = $this->getMockBuilder('\GameQ\GameQ') - ->enableProxyingToOriginalMethods() - ->getMock(); - $gq_mock->setOption('debug', false); - - // Reflect on GameQ class so we can parse - $gameq = new \ReflectionClass($gq_mock); - - // Get the parse method so we can call it - $method = $gameq->getMethod('doParseResponse'); - - // Set the method to accessible - $method->setAccessible(true); - - $testResult = $method->invoke($gq_mock, $server); + $testResult = $this->queryTest('127.0.0.1:27015', 'csgo', explode(PHP_EOL . '||' . PHP_EOL, file_get_contents($filePath))); $this->assertEquals($testResult['gq_online'], 1); } diff --git a/tests/Issues/Issue382.php b/tests/Issues/Issue382.php index b801543c..749846fe 100644 --- a/tests/Issues/Issue382.php +++ b/tests/Issues/Issue382.php @@ -43,40 +43,7 @@ public function test1() */ $filePath = sprintf('%s/Providers/382.txt', __DIR__); - // Create a mock server - $server = - $this->getMockBuilder('\GameQ\Server') - ->setConstructorArgs([ - [ - \GameQ\Server::SERVER_HOST => '58.162.184.102:2302', - \GameQ\Server::SERVER_TYPE => 'arma3', - ], - ]) - ->enableProxyingToOriginalMethods() - ->getMock(); - - // Invoke beforeSend function - $server->protocol()->beforeSend($server); - - // Set the packet response as if we have really queried it - $server->protocol()->packetResponse(explode(PHP_EOL . '||' . PHP_EOL, file_get_contents($filePath))); - - // Create a mock GameQ - $gq_mock = $this->getMockBuilder('\GameQ\GameQ') - ->enableProxyingToOriginalMethods() - ->getMock(); - $gq_mock->setOption('debug', false); - - // Reflect on GameQ class so we can parse - $gameq = new \ReflectionClass($gq_mock); - - // Get the parse method so we can call it - $method = $gameq->getMethod('doParseResponse'); - - // Set the method to accessible - $method->setAccessible(true); - - $testResult = $method->invoke($gq_mock, $server); + $testResult = $this->queryTest('58.162.184.102:2302', 'arma3', explode(PHP_EOL . '||' . PHP_EOL, file_get_contents($filePath))); $this->assertEquals($testResult['gq_online'], true); } diff --git a/tests/Issues/Issue588.php b/tests/Issues/Issue588.php new file mode 100644 index 00000000..035a54c2 --- /dev/null +++ b/tests/Issues/Issue588.php @@ -0,0 +1,62 @@ +. + */ + +namespace GameQ\Tests\Issues; + +use GameQ\Tests\TestBase; + +/** + * Class Issue588 + * + * Test for issue #588 - https://github.com/Austinb/GameQ/issues/588 + * + * @package GameQ\Tests\Issues + */ +class Issue588 extends TestBase +{ + /** + * Setup to create our stub + */ + public function setUp() + { + $this->stub = $this->getMockBuilder('\GameQ\GameQ') + ->enableProxyingToOriginalMethods() + ->setMethods(['__get', '__set']) + ->getMock(); + } + + /** + * Test for issue where hostnames are not correctly resolved to IP + */ + public function test1() + { + // Test single add server + $this->stub->addServer([ + \GameQ\Server::SERVER_HOST => 'game.samp-mobile.com:7777', + \GameQ\Server::SERVER_TYPE => 'Samp', + ]); + + $this->stub->addFilter('normalize'); + + // We do fail here + $this->stub->process(); + + // Clear the servers + $this->assertTrue(true); + } +} diff --git a/tests/Protocols/Base.php b/tests/Protocols/Base.php index 4b0bb711..65443cd3 100644 --- a/tests/Protocols/Base.php +++ b/tests/Protocols/Base.php @@ -72,59 +72,4 @@ public function loadData() return $providers; } - - /** - * Generic query test function to simulate testing of protocol classes - * - * @param string $host - * @param string $protocol - * @param array $responses - * @param bool $debug - * @param array $server_options - * - * @return mixed - */ - protected function queryTest($host, $protocol, $responses, $debug = false, $server_options = []) - { - - // Create a mock server - $server = $this->getMockBuilder('\GameQ\Server') - ->setConstructorArgs([ - [ - \GameQ\Server::SERVER_HOST => $host, - \GameQ\Server::SERVER_TYPE => $protocol, - \GameQ\Server::SERVER_OPTIONS => $server_options, - ], - ]) - ->enableProxyingToOriginalMethods() - ->getMock(); - - // Invoke beforeSend function - $server->protocol()->beforeSend($server); - - // Set the packet response as if we have really queried it - $server->protocol()->packetResponse($responses); - - // Create a mock GameQ - $gq_mock = $this->getMockBuilder('\GameQ\GameQ') - ->enableProxyingToOriginalMethods() - ->getMock(); - $gq_mock->setOption('debug', $debug); - $gq_mock->removeFilter('normalize'); - - // Reflect on GameQ class so we can parse - $gameq = new \ReflectionClass($gq_mock); - - // Get the parse method so we can call it - $method = $gameq->getMethod('doParseResponse'); - - // Set the method to accessible - $method->setAccessible(true); - - $testResult = $method->invoke($gq_mock, $server); - - unset($server, $gq_mock, $gameq, $method); - - return $testResult; - } } diff --git a/tests/Protocols/Providers/Arma/1_result.json b/tests/Protocols/Providers/Arma/1_result.json index f4b64dfa..780ff646 100644 --- a/tests/Protocols/Providers/Arma/1_result.json +++ b/tests/Protocols/Providers/Arma/1_result.json @@ -1 +1 @@ -{"sygsky.no-ip.org:2302":{"currentVersion":"118","dedicated":"1","difficulty":"1","equalModRequired":"0","gameState":"7","gamemode":"openplaying","gamename":"armedass","gametype":"COOP","gamever":"1.18","gq_address":"sygsky.no-ip.org","gq_joinlink":"","gq_name":"ArmA Armed Assault","gq_online":true,"gq_port_client":2302,"gq_port_query":2302,"gq_protocol":"gamespy2","gq_transport":"udp","gq_type":"arma","hostname":"Red Engineers ACE Arma-1 server","language":"65561","mapname":"sara","maxplayers":"10","mission":"co@10 Domination!ACE East [4.5+] RA","mod":"CA;@ACE;@SIX_Pack3;@ai_spotting","num_players":2,"num_teams":0,"numplayers":"2","numteams":"0","param1":"22","param2":"8","password":"0","platform":"win","players":[{"player":"Rokse [LT]","team":"","score":"56","deaths":"58"},{"player":"EngineerACE","team":"","score":"39","deaths":"43"}],"requiredVersion":"118","sv_battleye":"0","timelimit":"15"}} \ No newline at end of file +{"sygsky.no-ip.org:2302":{"currentVersion":"118","dedicated":"1","difficulty":"1","equalModRequired":"0","gameState":"7","gamemode":"openplaying","gamename":"armedass","gametype":"COOP","gamever":"1.18","gq_address":"80.240.222.67","gq_joinlink":"","gq_name":"ArmA Armed Assault","gq_online":true,"gq_port_client":2302,"gq_port_query":2302,"gq_protocol":"gamespy2","gq_transport":"udp","gq_type":"arma","hostname":"Red Engineers ACE Arma-1 server","language":"65561","mapname":"sara","maxplayers":"10","mission":"co@10 Domination!ACE East [4.5+] RA","mod":"CA;@ACE;@SIX_Pack3;@ai_spotting","num_players":2,"num_teams":0,"numplayers":"2","numteams":"0","param1":"22","param2":"8","password":"0","platform":"win","players":[{"player":"Rokse [LT]","team":"","score":"56","deaths":"58"},{"player":"EngineerACE","team":"","score":"39","deaths":"43"}],"requiredVersion":"118","sv_battleye":"0","timelimit":"15"}} \ No newline at end of file diff --git a/tests/Protocols/Providers/Teeworlds/1_result.json b/tests/Protocols/Providers/Teeworlds/1_result.json index 5860b30d..f7708e72 100644 --- a/tests/Protocols/Providers/Teeworlds/1_result.json +++ b/tests/Protocols/Providers/Teeworlds/1_result.json @@ -1 +1 @@ -{"ddracepro.net:8000":{"dedicated":true,"flags":"0","game_descr":"DDRace","gq_address":"ddracepro.net","gq_joinlink":"steam:\/\/connect\/ddracepro.net:8000\/","gq_name":"Teeworlds Server","gq_online":true,"gq_port_client":8000,"gq_port_query":8000,"gq_protocol":"teeworlds","gq_transport":"udp","gq_type":"teeworlds","hostname":"ddracepro.net - Gores\/HDP\/Verification\/other solo Maps #1","map":"gores","maxplayers":"16","maxplayers_total":"16","num_players":"0","num_players_total":"0","version":"0.6 trunk, 1.15a"}} \ No newline at end of file +{"ddracepro.net:8000":{"dedicated":true,"flags":"0","game_descr":"DDRace","gq_address":"195.154.113.141","gq_joinlink":"steam:\/\/connect\/195.154.113.141:8000\/","gq_name":"Teeworlds Server","gq_online":true,"gq_port_client":8000,"gq_port_query":8000,"gq_protocol":"teeworlds","gq_transport":"udp","gq_type":"teeworlds","hostname":"ddracepro.net - Gores\/HDP\/Verification\/other solo Maps #1","map":"gores","maxplayers":"16","maxplayers_total":"16","num_players":"0","num_players_total":"0","version":"0.6 trunk, 1.15a"}} \ No newline at end of file diff --git a/tests/Protocols/Providers/Terraria/1_result.json b/tests/Protocols/Providers/Terraria/1_result.json index 7aa3b891..12002dcb 100644 --- a/tests/Protocols/Providers/Terraria/1_result.json +++ b/tests/Protocols/Providers/Terraria/1_result.json @@ -1 +1 @@ -{"t.shadowrain.net:7777":{"dedicated":1,"game_port":7777,"gq_address":"t.shadowrain.net","gq_joinlink":"steam:\/\/connect\/t.shadowrain.net:7777\/","gq_name":"Terraria","gq_online":true,"gq_port_client":7777,"gq_port_query":7878,"gq_protocol":"tshock","gq_transport":"tcp","gq_type":"terraria","hostname":"","maxplayers":86,"numplayers":7,"password":0,"players":[{"nickname":"Woozer","username":"Woozer","group":"default","active":1,"state":10,"team":0},{"nickname":"G0D","username":"G0D","group":"default","active":1,"state":10,"team":5},{"nickname":"dood123","username":"dood123","group":"default","active":1,"state":10,"team":0},{"nickname":"Shpee","username":"Shpee","group":"default","active":1,"state":10,"team":0},{"nickname":"Ford_j_Ford","username":"Ford_j_Ford","group":"default","active":1,"state":10,"team":5},{"nickname":"Hi-im-jimmy","username":"Hi-im-jimmy","group":"Member+1","active":1,"state":10,"team":3},{"nickname":"Biofighter","username":"Biofighter","group":"default","active":1,"state":10,"team":0}],"rules":{"AutoSave":0,"DisableBuild":0,"DisableClownBombs":0,"DisableDungeonGuardian":0,"DisableInvisPvP":1,"DisableSnowBalls":0,"DisableTombstones":1,"EnableWhitelist":0,"HardcoreOnly":0,"PvPMode":"normal","SpawnProtection":1,"SpawnProtectionRadius":325,"ServerSideInventory":0},"serverversion":"v1.3.2.1","uptime":"8.15:10:51","world":"ShadowRain ~ VII"}} \ No newline at end of file +{"t.shadowrain.net:7777":{"dedicated":1,"game_port":7777,"gq_address":"83.233.14.21","gq_joinlink":"steam:\/\/connect\/83.233.14.21:7777\/","gq_name":"Terraria","gq_online":true,"gq_port_client":7777,"gq_port_query":7878,"gq_protocol":"tshock","gq_transport":"tcp","gq_type":"terraria","hostname":"","maxplayers":86,"numplayers":7,"password":0,"players":[{"nickname":"Woozer","username":"Woozer","group":"default","active":1,"state":10,"team":0},{"nickname":"G0D","username":"G0D","group":"default","active":1,"state":10,"team":5},{"nickname":"dood123","username":"dood123","group":"default","active":1,"state":10,"team":0},{"nickname":"Shpee","username":"Shpee","group":"default","active":1,"state":10,"team":0},{"nickname":"Ford_j_Ford","username":"Ford_j_Ford","group":"default","active":1,"state":10,"team":5},{"nickname":"Hi-im-jimmy","username":"Hi-im-jimmy","group":"Member+1","active":1,"state":10,"team":3},{"nickname":"Biofighter","username":"Biofighter","group":"default","active":1,"state":10,"team":0}],"rules":{"AutoSave":0,"DisableBuild":0,"DisableClownBombs":0,"DisableDungeonGuardian":0,"DisableInvisPvP":1,"DisableSnowBalls":0,"DisableTombstones":1,"EnableWhitelist":0,"HardcoreOnly":0,"PvPMode":"normal","SpawnProtection":1,"SpawnProtectionRadius":325,"ServerSideInventory":0},"serverversion":"v1.3.2.1","uptime":"8.15:10:51","world":"ShadowRain ~ VII"}} \ No newline at end of file diff --git a/tests/Protocols/Providers/Wurm/2_result.json b/tests/Protocols/Providers/Wurm/2_result.json index 7ba79f29..922416d2 100644 --- a/tests/Protocols/Providers/Wurm/2_result.json +++ b/tests/Protocols/Providers/Wurm/2_result.json @@ -1 +1 @@ -{"game.mythmoor.com:3724":{"dedicated":"d","game_descr":"Wurm Unlimited Server","game_dir":"wurmunlimitedserver","game_id":366220,"gq_address":"game.mythmoor.com","gq_joinlink":"steam:\/\/connect\/game.mythmoor.com:3724\/","gq_name":"Wurm Unlimited","gq_online":true,"gq_port_client":3724,"gq_port_query":27016,"gq_protocol":"source","gq_transport":"udp","gq_type":"wurm","hostname":"Mythmoor Prime (Dedicated, 7.5x skillgain, 3x action)","map":"New","max_players":250,"num_bots":0,"num_players":122,"os":"w","password":0,"players":[{"id":0,"name":"","score":0,"time":20799.123046875},{"id":0,"name":"","score":0,"time":20744.197265625},{"id":0,"name":"","score":0,"time":20721.05078125},{"id":0,"name":"","score":0,"time":20659.38671875},{"id":0,"name":"","score":0,"time":20578.072265625},{"id":0,"name":"","score":0,"time":20492.74609375},{"id":0,"name":"","score":0,"time":20190.234375},{"id":0,"name":"","score":0,"time":20181.646484375},{"id":0,"name":"","score":0,"time":20034.517578125},{"id":0,"name":"","score":0,"time":20001.765625},{"id":0,"name":"","score":0,"time":19782.232421875},{"id":0,"name":"","score":0,"time":19566.296875},{"id":0,"name":"","score":0,"time":19088.544921875},{"id":0,"name":"","score":0,"time":18952.287109375},{"id":0,"name":"","score":0,"time":18706.642578125},{"id":0,"name":"","score":0,"time":18680.23046875},{"id":0,"name":"","score":0,"time":18286.822265625},{"id":0,"name":"","score":0,"time":18267.892578125},{"id":0,"name":"","score":0,"time":17979.6953125},{"id":0,"name":"","score":0,"time":17368.744140625},{"id":0,"name":"","score":0,"time":16708.4375},{"id":0,"name":"","score":0,"time":15712.014648438},{"id":0,"name":"","score":0,"time":15670.778320312},{"id":0,"name":"","score":0,"time":15400.71875},{"id":0,"name":"","score":0,"time":15125.356445312},{"id":0,"name":"","score":0,"time":14568.228515625},{"id":0,"name":"","score":0,"time":13913.421875},{"id":0,"name":"","score":0,"time":13791.388671875},{"id":0,"name":"","score":0,"time":13390.34375},{"id":0,"name":"","score":0,"time":12236.270507812},{"id":0,"name":"","score":0,"time":11849.6171875},{"id":0,"name":"","score":0,"time":11462.163085938},{"id":0,"name":"","score":0,"time":11429.169921875},{"id":0,"name":"","score":0,"time":11239.673828125},{"id":0,"name":"","score":0,"time":11209.271484375},{"id":0,"name":"","score":0,"time":11107.192382812},{"id":0,"name":"","score":0,"time":10966.579101562},{"id":0,"name":"","score":0,"time":10938.63671875},{"id":0,"name":"","score":0,"time":10915.508789062},{"id":0,"name":"","score":0,"time":10871.122070312},{"id":0,"name":"","score":0,"time":10531.397460938},{"id":0,"name":"","score":0,"time":9820.91015625},{"id":0,"name":"","score":0,"time":9389.107421875},{"id":0,"name":"","score":0,"time":9048.56640625},{"id":0,"name":"","score":0,"time":9014.068359375},{"id":0,"name":"","score":0,"time":8403.4228515625},{"id":0,"name":"","score":0,"time":8339.4287109375},{"id":0,"name":"","score":0,"time":8181.4291992188},{"id":0,"name":"","score":0,"time":7692.9008789062},{"id":0,"name":"","score":0,"time":7455.91796875},{"id":0,"name":"","score":0,"time":7425.7548828125},{"id":0,"name":"","score":0,"time":7412.0703125},{"id":0,"name":"","score":0,"time":7392.76171875},{"id":0,"name":"","score":0,"time":7058.3701171875},{"id":0,"name":"","score":0,"time":6769.7758789062},{"id":0,"name":"","score":0,"time":6654.34375},{"id":0,"name":"","score":0,"time":6244.50390625},{"id":0,"name":"","score":0,"time":6206.267578125},{"id":0,"name":"","score":0,"time":5901.3784179688},{"id":0,"name":"","score":0,"time":5678.5166015625},{"id":0,"name":"","score":0,"time":5511.8974609375},{"id":0,"name":"","score":0,"time":5429.3369140625},{"id":0,"name":"","score":0,"time":5422.544921875},{"id":0,"name":"","score":0,"time":5401.3090820312},{"id":0,"name":"","score":0,"time":5283.427734375},{"id":0,"name":"","score":0,"time":5193.384765625},{"id":0,"name":"","score":0,"time":5071.0961914062},{"id":0,"name":"","score":0,"time":4941.7436523438},{"id":0,"name":"","score":0,"time":4909.5014648438},{"id":0,"name":"","score":0,"time":4876.1215820312},{"id":0,"name":"","score":0,"time":4853.4926757812},{"id":0,"name":"","score":0,"time":4833.6088867188},{"id":0,"name":"","score":0,"time":4760.7890625},{"id":0,"name":"","score":0,"time":4757.2646484375},{"id":0,"name":"","score":0,"time":4385.0180664062},{"id":0,"name":"","score":0,"time":4146.7109375},{"id":0,"name":"","score":0,"time":4053.5407714844},{"id":0,"name":"","score":0,"time":4026.5090332031},{"id":0,"name":"","score":0,"time":4026.4758300781},{"id":0,"name":"","score":0,"time":3952.9001464844},{"id":0,"name":"","score":0,"time":3939.0012207031},{"id":0,"name":"","score":0,"time":3788.2934570312},{"id":0,"name":"","score":0,"time":3782.3820800781},{"id":0,"name":"","score":0,"time":3745.0656738281},{"id":0,"name":"","score":0,"time":3682.3937988281},{"id":0,"name":"","score":0,"time":3648.5073242188},{"id":0,"name":"","score":0,"time":3627.0673828125},{"id":0,"name":"","score":0,"time":3495.7277832031},{"id":0,"name":"","score":0,"time":3483.6411132812},{"id":0,"name":"","score":0,"time":3443.087890625},{"id":0,"name":"","score":0,"time":3387.6943359375},{"id":0,"name":"","score":0,"time":3318.3935546875},{"id":0,"name":"","score":0,"time":3255.0385742188},{"id":0,"name":"","score":0,"time":3240.1218261719},{"id":0,"name":"","score":0,"time":3063.64453125},{"id":0,"name":"","score":0,"time":3056.9567871094},{"id":0,"name":"","score":0,"time":2931.5700683594},{"id":0,"name":"","score":0,"time":2897.3801269531},{"id":0,"name":"","score":0,"time":2851.1240234375},{"id":0,"name":"","score":0,"time":2797.3330078125},{"id":0,"name":"","score":0,"time":2771.5625},{"id":0,"name":"","score":0,"time":2604.9006347656},{"id":0,"name":"","score":0,"time":2531.3056640625},{"id":0,"name":"","score":0,"time":2428.7844238281},{"id":0,"name":"","score":0,"time":2260.3811035156},{"id":0,"name":"","score":0,"time":2201.7219238281},{"id":0,"name":"","score":0,"time":1846.6312255859},{"id":0,"name":"","score":0,"time":1816.1361083984},{"id":0,"name":"","score":0,"time":1642.4254150391},{"id":0,"name":"","score":0,"time":1522.1634521484},{"id":0,"name":"","score":0,"time":1280.0374755859},{"id":0,"name":"","score":0,"time":1253.3065185547},{"id":0,"name":"","score":0,"time":927.25189208984},{"id":0,"name":"","score":0,"time":848.31591796875},{"id":0,"name":"","score":0,"time":693.53253173828},{"id":0,"name":"","score":0,"time":585.89672851562},{"id":0,"name":"","score":0,"time":550.38208007812},{"id":0,"name":"","score":0,"time":293.07904052734},{"id":0,"name":"","score":0,"time":250.83889770508},{"id":0,"name":"","score":0,"time":242.82012939453},{"id":0,"name":"","score":0,"time":70.087799072266},{"id":0,"name":"","score":0,"time":11.414155006409}],"port":3724,"protocol":17,"secure":1,"steam_id":90099098665377801,"steamappid":0,"version":"1.0.0.0"}} \ No newline at end of file +{"game.mythmoor.com:3724":{"dedicated":"d","game_descr":"Wurm Unlimited Server","game_dir":"wurmunlimitedserver","game_id":366220,"gq_address":"54.39.28.49","gq_joinlink":"steam:\/\/connect\/54.39.28.49:3724\/","gq_name":"Wurm Unlimited","gq_online":true,"gq_port_client":3724,"gq_port_query":27016,"gq_protocol":"source","gq_transport":"udp","gq_type":"wurm","hostname":"Mythmoor Prime (Dedicated, 7.5x skillgain, 3x action)","map":"New","max_players":250,"num_bots":0,"num_players":122,"os":"w","password":0,"players":[{"id":0,"name":"","score":0,"time":20799.123046875},{"id":0,"name":"","score":0,"time":20744.197265625},{"id":0,"name":"","score":0,"time":20721.05078125},{"id":0,"name":"","score":0,"time":20659.38671875},{"id":0,"name":"","score":0,"time":20578.072265625},{"id":0,"name":"","score":0,"time":20492.74609375},{"id":0,"name":"","score":0,"time":20190.234375},{"id":0,"name":"","score":0,"time":20181.646484375},{"id":0,"name":"","score":0,"time":20034.517578125},{"id":0,"name":"","score":0,"time":20001.765625},{"id":0,"name":"","score":0,"time":19782.232421875},{"id":0,"name":"","score":0,"time":19566.296875},{"id":0,"name":"","score":0,"time":19088.544921875},{"id":0,"name":"","score":0,"time":18952.287109375},{"id":0,"name":"","score":0,"time":18706.642578125},{"id":0,"name":"","score":0,"time":18680.23046875},{"id":0,"name":"","score":0,"time":18286.822265625},{"id":0,"name":"","score":0,"time":18267.892578125},{"id":0,"name":"","score":0,"time":17979.6953125},{"id":0,"name":"","score":0,"time":17368.744140625},{"id":0,"name":"","score":0,"time":16708.4375},{"id":0,"name":"","score":0,"time":15712.014648438},{"id":0,"name":"","score":0,"time":15670.778320312},{"id":0,"name":"","score":0,"time":15400.71875},{"id":0,"name":"","score":0,"time":15125.356445312},{"id":0,"name":"","score":0,"time":14568.228515625},{"id":0,"name":"","score":0,"time":13913.421875},{"id":0,"name":"","score":0,"time":13791.388671875},{"id":0,"name":"","score":0,"time":13390.34375},{"id":0,"name":"","score":0,"time":12236.270507812},{"id":0,"name":"","score":0,"time":11849.6171875},{"id":0,"name":"","score":0,"time":11462.163085938},{"id":0,"name":"","score":0,"time":11429.169921875},{"id":0,"name":"","score":0,"time":11239.673828125},{"id":0,"name":"","score":0,"time":11209.271484375},{"id":0,"name":"","score":0,"time":11107.192382812},{"id":0,"name":"","score":0,"time":10966.579101562},{"id":0,"name":"","score":0,"time":10938.63671875},{"id":0,"name":"","score":0,"time":10915.508789062},{"id":0,"name":"","score":0,"time":10871.122070312},{"id":0,"name":"","score":0,"time":10531.397460938},{"id":0,"name":"","score":0,"time":9820.91015625},{"id":0,"name":"","score":0,"time":9389.107421875},{"id":0,"name":"","score":0,"time":9048.56640625},{"id":0,"name":"","score":0,"time":9014.068359375},{"id":0,"name":"","score":0,"time":8403.4228515625},{"id":0,"name":"","score":0,"time":8339.4287109375},{"id":0,"name":"","score":0,"time":8181.4291992188},{"id":0,"name":"","score":0,"time":7692.9008789062},{"id":0,"name":"","score":0,"time":7455.91796875},{"id":0,"name":"","score":0,"time":7425.7548828125},{"id":0,"name":"","score":0,"time":7412.0703125},{"id":0,"name":"","score":0,"time":7392.76171875},{"id":0,"name":"","score":0,"time":7058.3701171875},{"id":0,"name":"","score":0,"time":6769.7758789062},{"id":0,"name":"","score":0,"time":6654.34375},{"id":0,"name":"","score":0,"time":6244.50390625},{"id":0,"name":"","score":0,"time":6206.267578125},{"id":0,"name":"","score":0,"time":5901.3784179688},{"id":0,"name":"","score":0,"time":5678.5166015625},{"id":0,"name":"","score":0,"time":5511.8974609375},{"id":0,"name":"","score":0,"time":5429.3369140625},{"id":0,"name":"","score":0,"time":5422.544921875},{"id":0,"name":"","score":0,"time":5401.3090820312},{"id":0,"name":"","score":0,"time":5283.427734375},{"id":0,"name":"","score":0,"time":5193.384765625},{"id":0,"name":"","score":0,"time":5071.0961914062},{"id":0,"name":"","score":0,"time":4941.7436523438},{"id":0,"name":"","score":0,"time":4909.5014648438},{"id":0,"name":"","score":0,"time":4876.1215820312},{"id":0,"name":"","score":0,"time":4853.4926757812},{"id":0,"name":"","score":0,"time":4833.6088867188},{"id":0,"name":"","score":0,"time":4760.7890625},{"id":0,"name":"","score":0,"time":4757.2646484375},{"id":0,"name":"","score":0,"time":4385.0180664062},{"id":0,"name":"","score":0,"time":4146.7109375},{"id":0,"name":"","score":0,"time":4053.5407714844},{"id":0,"name":"","score":0,"time":4026.5090332031},{"id":0,"name":"","score":0,"time":4026.4758300781},{"id":0,"name":"","score":0,"time":3952.9001464844},{"id":0,"name":"","score":0,"time":3939.0012207031},{"id":0,"name":"","score":0,"time":3788.2934570312},{"id":0,"name":"","score":0,"time":3782.3820800781},{"id":0,"name":"","score":0,"time":3745.0656738281},{"id":0,"name":"","score":0,"time":3682.3937988281},{"id":0,"name":"","score":0,"time":3648.5073242188},{"id":0,"name":"","score":0,"time":3627.0673828125},{"id":0,"name":"","score":0,"time":3495.7277832031},{"id":0,"name":"","score":0,"time":3483.6411132812},{"id":0,"name":"","score":0,"time":3443.087890625},{"id":0,"name":"","score":0,"time":3387.6943359375},{"id":0,"name":"","score":0,"time":3318.3935546875},{"id":0,"name":"","score":0,"time":3255.0385742188},{"id":0,"name":"","score":0,"time":3240.1218261719},{"id":0,"name":"","score":0,"time":3063.64453125},{"id":0,"name":"","score":0,"time":3056.9567871094},{"id":0,"name":"","score":0,"time":2931.5700683594},{"id":0,"name":"","score":0,"time":2897.3801269531},{"id":0,"name":"","score":0,"time":2851.1240234375},{"id":0,"name":"","score":0,"time":2797.3330078125},{"id":0,"name":"","score":0,"time":2771.5625},{"id":0,"name":"","score":0,"time":2604.9006347656},{"id":0,"name":"","score":0,"time":2531.3056640625},{"id":0,"name":"","score":0,"time":2428.7844238281},{"id":0,"name":"","score":0,"time":2260.3811035156},{"id":0,"name":"","score":0,"time":2201.7219238281},{"id":0,"name":"","score":0,"time":1846.6312255859},{"id":0,"name":"","score":0,"time":1816.1361083984},{"id":0,"name":"","score":0,"time":1642.4254150391},{"id":0,"name":"","score":0,"time":1522.1634521484},{"id":0,"name":"","score":0,"time":1280.0374755859},{"id":0,"name":"","score":0,"time":1253.3065185547},{"id":0,"name":"","score":0,"time":927.25189208984},{"id":0,"name":"","score":0,"time":848.31591796875},{"id":0,"name":"","score":0,"time":693.53253173828},{"id":0,"name":"","score":0,"time":585.89672851562},{"id":0,"name":"","score":0,"time":550.38208007812},{"id":0,"name":"","score":0,"time":293.07904052734},{"id":0,"name":"","score":0,"time":250.83889770508},{"id":0,"name":"","score":0,"time":242.82012939453},{"id":0,"name":"","score":0,"time":70.087799072266},{"id":0,"name":"","score":0,"time":11.414155006409}],"port":3724,"protocol":17,"secure":1,"steam_id":90099098665377801,"steamappid":0,"version":"1.0.0.0"}} \ No newline at end of file diff --git a/tests/TestBase.php b/tests/TestBase.php index ae150ccf..fc0f5fcf 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -38,6 +38,61 @@ class_alias('\PHPUnit_Framework_Assert', '\PHPUnit\Framework\Assert'); parent::__construct($name, $data, $dataName); } + /** + * Generic query test function to simulate testing of protocol classes + * + * @param string $host + * @param string $protocol + * @param array $responses + * @param bool $debug + * @param array $server_options + * + * @return mixed + */ + protected function queryTest($host, $protocol, $responses, $debug = false, $server_options = []) + { + + // Create a mock server + $server = $this->getMockBuilder('\GameQ\Server') + ->setConstructorArgs([ + [ + \GameQ\Server::SERVER_HOST => $host, + \GameQ\Server::SERVER_TYPE => $protocol, + \GameQ\Server::SERVER_OPTIONS => $server_options, + ], + ]) + ->enableProxyingToOriginalMethods() + ->getMock(); + + // Invoke beforeSend function + $server->protocol()->beforeSend($server); + + // Set the packet response as if we have really queried it + $server->protocol()->packetResponse($responses); + + // Create a mock GameQ + $gq_mock = $this->getMockBuilder('\GameQ\GameQ') + ->enableProxyingToOriginalMethods() + ->getMock(); + $gq_mock->setOption('debug', $debug); + $gq_mock->removeFilter('normalize'); + + // Reflect on GameQ class so we can parse + $gameq = new \ReflectionClass($gq_mock); + + // Get the parse method so we can call it + $method = $gameq->getMethod('doParseResponse'); + + // Set the method to accessible + $method->setAccessible(true); + + $testResult = $method->invoke($gq_mock, $server); + + unset($server, $gq_mock, $gameq, $method); + + return $testResult; + } + /** * Fake test so PHPUnit won't complain about no tests in class. */