From 5d9c74441c27f991dedd03847a4b4e3f28943c99 Mon Sep 17 00:00:00 2001 From: Austinb Date: Wed, 3 Aug 2016 11:10:44 -0500 Subject: [PATCH] Added Battlefield 2 support. Fixes #317 --- src/GameQ/Protocols/Bf2.php | 98 +++++++++++++++++++ tests/Protocols/Bf2.php | 46 +++++++++ tests/Protocols/Providers/Bf2/1_response.txt | Bin 0 -> 3124 bytes tests/Protocols/Providers/Bf2/1_result.json | 1 + tests/Protocols/Providers/Bf2/2_response.txt | Bin 0 -> 1279 bytes tests/Protocols/Providers/Bf2/2_result.json | 1 + tests/Protocols/Providers/Bf2/3_response.txt | Bin 0 -> 1444 bytes tests/Protocols/Providers/Bf2/3_result.json | 1 + 8 files changed, 147 insertions(+) create mode 100644 src/GameQ/Protocols/Bf2.php create mode 100644 tests/Protocols/Bf2.php create mode 100644 tests/Protocols/Providers/Bf2/1_response.txt create mode 100644 tests/Protocols/Providers/Bf2/1_result.json create mode 100644 tests/Protocols/Providers/Bf2/2_response.txt create mode 100644 tests/Protocols/Providers/Bf2/2_result.json create mode 100644 tests/Protocols/Providers/Bf2/3_response.txt create mode 100644 tests/Protocols/Providers/Bf2/3_result.json diff --git a/src/GameQ/Protocols/Bf2.php b/src/GameQ/Protocols/Bf2.php new file mode 100644 index 00000000..0610f9d0 --- /dev/null +++ b/src/GameQ/Protocols/Bf2.php @@ -0,0 +1,98 @@ +. + */ + +namespace GameQ\Protocols; + +/** + * Class Battlefield 2 + * + * @package GameQ\Protocols + * @author Austin Bischoff + */ +class Bf2 extends Gamespy3 +{ + + /** + * String name of this protocol class + * + * @type string + */ + protected $name = 'bf2'; + + /** + * Longer string name of this protocol class + * + * @type string + */ + protected $name_long = "Battlefield 2"; + + /** + * query_port = client_port + 8433 + * 29900 = 16567 + 13333 + * + * @type int + */ + protected $port_diff = 13333; + + /** + * The client join link + * + * @type string + */ + protected $join_link = "bf2://%s:%d"; + + /** + * BF2 has a different query packet to send than "normal" Gamespy 3 + * + * @var array + */ + protected $packets = [ + self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40\xFF\xFF\xFF\x01", + ]; + + /** + * Normalize settings for this protocol + * + * @type array + */ + protected $normalize = [ + // General + 'general' => [ + // target => source + 'dedicated' => 'dedicated', + 'gametype' => 'gametype', + 'hostname' => 'hostname', + 'mapname' => 'mapname', + 'maxplayers' => 'maxplayers', + 'numplayers' => 'numplayers', + 'password' => 'password', + ], + // Individual + 'player' => [ + 'name' => 'player', + 'kills' => 'score', + 'deaths' => 'deaths', + 'ping' => 'ping', + 'score' => 'score', + ], + 'team' => [ + 'name' => 'team', + 'score' => 'score', + ], + ]; +} diff --git a/tests/Protocols/Bf2.php b/tests/Protocols/Bf2.php new file mode 100644 index 00000000..dda12255 --- /dev/null +++ b/tests/Protocols/Bf2.php @@ -0,0 +1,46 @@ +. + */ + +namespace GameQ\Tests\Protocols; + +class Bf2 extends Base +{ + + /** + * Test responses for Battlefield 2 + * + * @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, + 'bf2', + $responses + ); + + $this->assertEquals($result[$server], $testResult); + } +} diff --git a/tests/Protocols/Providers/Bf2/1_response.txt b/tests/Protocols/Providers/Bf2/1_response.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd258651ef58b49644b4e03e9a453ef98f5bbff6 GIT binary patch literal 3124 zcmcImNpB>#6@HVWPdVmDz%bw()FN5C0VAVj7C{u1k*EeSDrk04d){UKNH7#$i-`u=r2W%A_JF!_VW>ERBP1Yb#B**PWM}?v8rp z+=Cq|;xw98H>Ncs-UmB%l^0M^go1lJj3m+|&3v3yr7KgaQCB3wd{ABeJV7$1+-e1b zuxK4MrkfrQkc2l@(`W}>?pLdosUB%Nj{SFshy8ltrd|(b4_?`*Zc*Cy(CGm{xkK0= zI8n8Sa~i9v`IDyi*7W-fd_HT1Nab@0o5AR=YIYklXu#pK9_s+!rDfMsXW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|6V=*p5i!w+sKzIniIjhQ_}H Q|2GDIUiL>N1R*K<1uoGMEC2ui literal 0 HcmV?d00001 diff --git a/tests/Protocols/Providers/Bf2/1_result.json b/tests/Protocols/Providers/Bf2/1_result.json new file mode 100644 index 00000000..b06960f0 --- /dev/null +++ b/tests/Protocols/Providers/Bf2/1_result.json @@ -0,0 +1 @@ +{"31.186.250.205:16567":{"bf2_anticheat":"1","bf2_autobalanced":"1","bf2_autorec":"1","bf2_bots":"0","bf2_communitylogo_url":"http:\/\/www.superinfantryclan.com\/bf2\/109338097-superbf2.jpg","bf2_coopbotcount":"","bf2_coopbotdiff":"","bf2_coopbotratio":"","bf2_d_dl":"http:\/\/pb.superinfantryclan.com\/servers\/bf2-s1dm\/","bf2_d_idx":"http:\/\/pb.superinfantryclan.com\/servers\/bf2-s1dm\/","bf2_dedicated":"1","bf2_fps":"36.000000","bf2_friendlyfire":"0","bf2_globalunlocks":"1","bf2_mapsize":"64","bf2_novehicles":"1","bf2_os":"linux-64","bf2_plasma":"0","bf2_pure":"1","bf2_ranked":"1","bf2_reservedslots":"0","bf2_scorelimit":"0","bf2_spawntime":"15.000000","bf2_sponsorlogo_url":"http:\/\/www.superinfantryclan.com\/bf2\/109338097-superbf2.jpg","bf2_sponsortext":"www.superinfantryclan.com","bf2_startdelay":"15","bf2_team1":"MEC","bf2_team2":"US","bf2_teamratio":"100.000000","bf2_ticketratio":"100","bf2_tkmode":"No Punish","bf2_voip":"1","gamemode":"openplaying","gamename":"battlefield2","gametype":"gpm_cq","gamevariant":"bf2","gamever":"1.5.3153-802.0","gq_address":"31.186.250.205","gq_joinlink":"bf2:\/\/31.186.250.205:16567","gq_name":"Battlefield 2","gq_online":true,"gq_port_client":16567,"gq_port_query":29900,"gq_protocol":"gamespy3","gq_transport":"udp","gq_type":"bf2","hostname":"SUPER@ - S1 Strike at Karkand Infantry Only","hostport":"16567","mapname":"Strike At Karkand","maxplayers":"64","numplayers":"54","password":"0","players":[{"player":"Deniko_pirliko_BiH","score":"90","ping":"26","team":"2","deaths":"5","pid":"1164362","skill":"21","AIBot":"0"},{"player":"Mr.Untraceable","score":"70","ping":"38","team":"1","deaths":"5","pid":"1162172","skill":"23","AIBot":"0"},{"player":"Rememberme?","score":"68","ping":"42","team":"1","deaths":"4","pid":"500088692","skill":"20","AIBot":"0"},{"player":"[LRRP]Snipersonic","score":"65","ping":"30","team":"2","deaths":"13","pid":"1114130","skill":"22","AIBot":"0"},{"player":"snake4u","score":"59","ping":"53","team":"2","deaths":"11","pid":"1070430","skill":"19","AIBot":"0"},{"player":"canptainx","score":"57","ping":"26","team":"1","deaths":"6","pid":"1053398","skill":"14","AIBot":"0"},{"player":"beyonD|willibalD","score":"53","ping":"27","team":"1","deaths":"7","pid":"447339954","skill":"26","AIBot":"0"},{"player":"Tomcrafd","score":"50","ping":"42","team":"2","deaths":"10","pid":"482738578","skill":"11","AIBot":"0"},{"player":"Sniper14","score":"49","ping":"151","team":"2","deaths":"13","pid":"1229457","skill":"12","AIBot":"0"},{"player":"#Inf Hyvaeae_paeivaeae","score":"48","ping":"40","team":"2","deaths":"6","pid":"1164781","skill":"11","AIBot":"0"},{"player":"maximus1111","score":"44","ping":"59","team":"1","deaths":"9","pid":"1143006","skill":"6","AIBot":"0"},{"player":"givemeyourbest1","score":"43","ping":"86","team":"1","deaths":"7","pid":"1305448","skill":"18","AIBot":"0"},{"player":"Pegas_55rus","score":"40","ping":"86","team":"2","deaths":"12","pid":"1270274","skill":"11","AIBot":"0"},{"player":"ullly_Dobpa.~","score":"38","ping":"87","team":"1","deaths":"4","pid":"1007608","skill":"4","AIBot":"0"},{"player":"100% Lexilium_bih","score":"38","ping":"55","team":"2","deaths":"0","pid":"1067266","skill":"0","AIBot":"0"},{"player":"Tonald_Drump_2k16","score":"36","ping":"77","team":"1","deaths":"8","pid":"1233964","skill":"14","AIBot":"0"},{"player":"=SG= FUQhax","score":"34","ping":"122","team":"1","deaths":"12","pid":"1272903","skill":"13","AIBot":"0"},{"player":"Bi0nic(GhostKid)","score":"33","ping":"62","team":"2","deaths":"2","pid":"441168429","skill":"16","AIBot":"0"},{"player":"N3x","score":"33","ping":"14","team":"1","deaths":"8","pid":"1317778","skill":"5","AIBot":"0"},{"player":"BeLaRUS-1988","score":"32","ping":"62","team":"2","deaths":"8","pid":"1048174","skill":"5","AIBot":"0"},{"player":"corn_syrup","score":"31","ping":"111","team":"2","deaths":"3","pid":"1021430","skill":"11","AIBot":"0"},{"player":"aahnz","score":"30","ping":"22","team":"1","deaths":"7","pid":"1317660","skill":"2","AIBot":"0"},{"player":"sam0ht","score":"29","ping":"7","team":"2","deaths":"2","pid":"1131805","skill":"15","AIBot":"0"},{"player":"BlackBull33","score":"27","ping":"27","team":"1","deaths":"4","pid":"1289858","skill":"8","AIBot":"0"},{"player":"hekutooo","score":"27","ping":"52","team":"2","deaths":"8","pid":"1269541","skill":"7","AIBot":"0"},{"player":"Bl4ck^Sun","score":"25","ping":"51","team":"2","deaths":"9","pid":"1261912","skill":"11","AIBot":"0"},{"player":"LICZER COMAN07","score":"25","ping":"468","team":"2","deaths":"14","pid":"1273269","skill":"8","AIBot":"0"},{"player":"KarniksCCCP","score":"24","ping":"53","team":"2","deaths":"8","pid":"1172761","skill":"6","AIBot":"0"},{"player":"BRKOLOL","score":"21","ping":"35","team":"1","deaths":"13","pid":"1178284","skill":"6","AIBot":"0"},{"player":"spoofer27","score":"19","ping":"115","team":"2","deaths":"7","pid":"1259397","skill":"5","AIBot":"0"},{"player":"zmaj111ss","score":"18","ping":"43","team":"2","deaths":"8","pid":"1318624","skill":"9","AIBot":"0"},{"player":"PempekPalembang","score":"18","ping":"214","team":"1","deaths":"15","pid":"1316864","skill":"6","AIBot":"0"},{"player":"Gamers.Anonymous","score":"17","ping":"53","team":"1","deaths":"6","pid":"1318165","skill":"5","AIBot":"0"},{"player":"BL@cK boky1122","score":"16","ping":"54","team":"1","deaths":"8","pid":"1288033","skill":"4","AIBot":"0"},{"player":"KOFF94","score":"14","ping":"55","team":"1","deaths":"5","pid":"1295618","skill":"5","AIBot":"0"},{"player":"slakic slakicar","score":"14","ping":"50","team":"2","deaths":"8","pid":"1312593","skill":"5","AIBot":"0"},{"player":"Arca","score":"8","ping":"57","team":"1","deaths":"10","pid":"1267400","skill":"4","AIBot":"0"},{"player":"Raptor25","score":"7","ping":"178","team":"2","deaths":"2","pid":"1310891","skill":"3","AIBot":"0"},{"player":"#Inf Revive|Mawr","score":"7","ping":"33","team":"1","deaths":"0","pid":"500088450","skill":"1","AIBot":"0"},{"player":"II_Bratishka_II","score":"6","ping":"37","team":"1","deaths":"0","pid":"1252416","skill":"3","AIBot":"0"},{"player":"tenik","score":"6","ping":"22","team":"2","deaths":"3","pid":"1289493","skill":"3","AIBot":"0"},{"player":"chrissel123","score":"6","ping":"39","team":"2","deaths":"2","pid":"1291452","skill":"2","AIBot":"0"},{"player":"kvk8550","score":"6","ping":"49","team":"2","deaths":"2","pid":"1304925","skill":"2","AIBot":"0"},{"player":"SekerEnes","score":"4","ping":"36","team":"1","deaths":"4","pid":"1271080","skill":"2","AIBot":"0"},{"player":"ardvw","score":"4","ping":"33","team":"1","deaths":"7","pid":"1270304","skill":"2","AIBot":"0"},{"player":"Kecske16","score":"4","ping":"28","team":"1","deaths":"8","pid":"1280227","skill":"1","AIBot":"0"},{"player":"antlolq","score":"1","ping":"26","team":"1","deaths":"1","pid":"1144670","skill":"0","AIBot":"0"},{"player":"RomanBN","score":"0","ping":"86","team":"1","deaths":"0","pid":"1263065","skill":"0","AIBot":"0"},{"player":"nikhomes","score":"0","ping":"27","team":"2","deaths":"0","pid":"1176651","skill":"0","AIBot":"0"},{"player":"Tamtam13","score":"0","ping":"42","team":"2","deaths":"0","pid":"1272249","skill":"0","AIBot":"0"},{"player":"Satido","score":"0","ping":"53","team":"1","deaths":"0","pid":"63902872","skill":"0","AIBot":"0"},{"player":"KyOkUsHiN.OBi","score":"0","ping":"139","team":"2","deaths":"0","pid":"1247612","skill":"0","AIBot":"0"},{"player":"SUPER@ GerEliteSteff_2.","score":"0","ping":"24","team":"2","deaths":"0","pid":"479665451","skill":"0","AIBot":"0"},{"player":"michasio","score":"0","ping":"38","team":"1","deaths":"0","pid":"1293319","skill":"0","AIBot":"0"}],"roundtime":"99","teams":[{"team":"MEC","score":"0"},{"team":"US","score":"0"}],"timelimit":"0"}} \ No newline at end of file diff --git a/tests/Protocols/Providers/Bf2/2_response.txt b/tests/Protocols/Providers/Bf2/2_response.txt new file mode 100644 index 0000000000000000000000000000000000000000..35a7ad75e7b5633da173948c8b94d14885499ecf GIT binary patch literal 1279 zcma)5>u%F96h80-JVIWeZjxSTD@~$d>=l=OS@Ggo!I3tBuRSCbK(9SDba(KL7M7xCa$e6@W(bd!K<5hG!U3~iZZE+KQ zncmIjU!qQw&gRQ*I-M@@KA%F4k#+Q%dN27#aLLjd-Ej*E8IWEw=ygVMN@6IfseM0F zDXV8%L=W8g+SwlshuoAapk^?D zKM+%xrt*r(|M%W$VP3kzs%t8#%Fc~$tl)~t<3`vpXBfn9YnJ9Zy04UQMGZPnt!Err zgEVPobcXJ6Oys8*$0V*#<7>2XNESbMcvT^%==8wXPIx|v_WM04sAU=QfjYrIA=>7r z@5|mK^6nMWWHcVfr$r^X`&V?=af`~b!RK`9L{k}EQ)f|2v$Jv#^q1XAo$FO)&%_EM z%Dl29(`C2%S|)?rA$c}=9fDYi)cE7yL9Y+fZR&&xTYVu{HHISDa&M^@8j=@`)AEd5 z((2KWz}?Nu3{Cq1P2tC~&bQXywSR3Y{LrQfZj=*0Ikei#We`E7q|UZsO~RjVjDueP zvKlUkD`}g-@|scRY*CZYSgmLkn0x;aJ!r>hg8Nq6YpusdAU^pg{jcq!+*1oyI T+d3SZyJQi$Ys;Y_4(Z@Gh*X!q literal 0 HcmV?d00001 diff --git a/tests/Protocols/Providers/Bf2/2_result.json b/tests/Protocols/Providers/Bf2/2_result.json new file mode 100644 index 00000000..b420ee38 --- /dev/null +++ b/tests/Protocols/Providers/Bf2/2_result.json @@ -0,0 +1 @@ +{"108.61.88.95:16567":{"bf2_anticheat":"0","bf2_autobalanced":"0","bf2_autorec":"1","bf2_bots":"0","bf2_communitylogo_url":"http:\/\/www.hardcoregaming.org\/","bf2_coopbotcount":"","bf2_coopbotdiff":"","bf2_coopbotratio":"","bf2_d_dl":"http:\/\/108.61.88.96\/demos\/.index.php","bf2_d_idx":"http:\/\/108.61.88.96\/demos\/.index.php","bf2_dedicated":"1","bf2_fps":"34.000000","bf2_friendlyfire":"1","bf2_globalunlocks":"1","bf2_mapsize":"64","bf2_novehicles":"0","bf2_os":"linux-64","bf2_plasma":"0","bf2_pure":"0","bf2_ranked":"0","bf2_reservedslots":"0","bf2_scorelimit":"1000","bf2_spawntime":"300.000000","bf2_sponsorlogo_url":"http:\/\/i.imgur.com\/uLm15H6.jpg","bf2_sponsortext":"=]H[= HARDCORE GAMING| |Website: www.hardcoregaming.org|TS3: ts.hardcoregaming.org:8990|Rules: www.hardcoregaming.org\/serverrules||- Al Basrah Insurgency Alt","bf2_startdelay":"210","bf2_team1":"MEInsurgent","bf2_team2":"US","bf2_teamratio":"100.000000","bf2_ticketratio":"100","bf2_tkmode":"No Punish","bf2_voip":"0","gamemode":"openplaying","gamename":"battlefield2","gametype":"gpm_insurgency","gamevariant":"pr","gamever":"1.5.3153-802.0","gq_address":"108.61.88.95","gq_joinlink":"bf2:\/\/108.61.88.95:16567","gq_name":"Battlefield 2","gq_online":true,"gq_port_client":16567,"gq_port_query":29900,"gq_protocol":"gamespy3","gq_transport":"udp","gq_type":"bf2","hostname":"[PR v1.3.9.0] =]H[= HARDCORE GAMING - 2INS\/2AAS - NA","hostport":"16567","mapname":"Fallujah West","maxplayers":"100","numplayers":"1","password":"0","players":[{"player":"=]H[= Eskil_swe","score":"99","ping":"106","team":"2","deaths":"0","pid":"100000205","skill":"0","AIBot":"0"}],"roundtime":"1","teams":[{"team":"MEInsurgent","score":"0"},{"team":"US","score":"0"}],"timelimit":"14400"}} \ No newline at end of file diff --git a/tests/Protocols/Providers/Bf2/3_response.txt b/tests/Protocols/Providers/Bf2/3_response.txt new file mode 100644 index 0000000000000000000000000000000000000000..615e5d645b3dcc631979ca8e447946895d422371 GIT binary patch literal 1444 zcmbVMU2hsW6!rG8Px}+xr%I8S4+xM{ine5xR#A%<5u#{SRmhC*fIA-BvOPd5Ui!~_ zZ9_!%ap%QzKYV@exyL4d(&D2tQh3$1gpiGPUa=O)x7nO-%WRNcXT^7VadAO!rZ8`A z==^T-^?va$UEEEkPyfun(B9o+FC>sP?u&a@%zFv70LlB&y9GmZ=7f zA{q!sR2yLaXlqBLP~E;ax=iuTYYWwJD_;t}C$%>p^4!?4wqTo&<@hQa4YJ`lE6ZV? zSi?<-7Hpm{EV=wY`?gw`6H-L7Vv?!qrIXqUP+UIO!iL^MbH0hp%{moG4<6^4^&F5! z(!WeiJHvL^Hxf1|imZrV$~9U!WDoY9Jb|oq3)E{G1VbOd;`rUW!>3M4Duwe@*VJ|r z9My{I&e9#MobW(*yImHDF*d7o)-{JdorM`WIs;3mTKNr~g9`=egVf#~9=^VJbo%(P zpm=7B;KRTuQygt6*-G1B?*wktev@EWfP`$;t)!^v0$A$|u!g>x$A|0dtEDun3UT&OMfl)tK({}nWL6DptcCiPk`J1fbtSS^s8 z4Ac*yVyVG(zbJAX5R$e;(FJ*+Z#)r>WM`rxABdoo)yYH~LWK4S1wcXc8`26bm-`;yKqrV4x(^yL;t2y9T_nr}RGgd>f4wj_s&S z)1mxQMSKmM_=#d1#iX?ilI@h#RpX8dt&Jmt(fMh3#a+ve6>QQ4cR?43G}fuKHh5sd zdhV%ER-T-DxTx#oP