koraktor / steam-condenser

A multi-language library for querying the Steam Community, Source, GoldSrc servers and Steam master servers
https://koraktor.de/steam-condenser
Other
356 stars 67 forks source link

Minor bugs, php #7

Closed ccondrup closed 15 years ago

ccondrup commented 15 years ago

Props

First off, thanks for your continued effort. Much appreciated! I registered on this site and checked out the git master earlier today. I think that's the equivalent to the svn trunk, right?

Bugs found, proposed changes

Double check please, I am not entirely sure of what I'm doing...

Bug1: Usage examples, PHP. In the usage examples on the homepage for PHP Rcon there's a ) too much after "status".

bug 2: php/lib/UDPSocket.php line 59 stream_set_blocking($this->socket, $doBlock); change to stream_set_blocking($this->socket, $this->isBlocking);

bug 3 php/lib/steam/servers/GameServer.php line 98 $this->rulesHash; change to $this->updateRulesInfo();

bug 4 php/lib/steam/SteamPlayer.php couple of notices: Notice: Undefined property: SteamPlayer::$steamID - should be steamId Notice: Undefined property: SteamPlayer::$extended - never declared

bug 5 Also, every time I try to use the new extended getPlayers($rcon) for GoldSrc, I get and uncaught SteamCondenserException saying "Information to add belongs to a different player". This is correct, it does try to merge two different players. I have no fix for this yet, but I think it works for the first player/loop, then on the next loop it fails. The SteamID array value is also incorrect in my testing, here is a dump: [playerArray:protected] => Array ( [0] => SteamPlayer Object ( [connectTime:private] => 1893.58496094 [id:private] => 0 [loss:private] => [name:private] => PEWPEW* [ping:private] => [score:private] => 7 [state:private] => [steamId:private] => 68 STEAM_0:0:xxx4562 2 21:26 25 0 [extended:private] => 1 [realId] => 1 )

    [1] => SteamPlayer Object
        (
            [connectTime:private] => 1286.49206543
            [id:private] => 0
            [loss:private] => 
            [name:private] => MCFH # tWoPiece# - Wenger :D
            [ping:private] => 
            [score:private] => 2
            [state:private] => 
            [steamId:private] => 
            [extended:private] => 
        )

    [2] => SteamPlayer Object
        (
            [connectTime:private] => 1274.05200195
            [id:private] => 0
            [loss:private] => 
            [name:private] => Usopp#OnePiece#
            [ping:private] => 
            [score:private] => 3
            [state:private] => 
            [steamId:private] => 
            [extended:private] => 
        )

)

Question

koraktor commented 15 years ago

First of all, thanks for all this valuable feedback.

I've fixed most of those bugs locally and will push them to the repository soon. I'll have to take a look at bug 5 though.

Questions:

koraktor commented 15 years ago

Okay... I hunted bug 5 down. GoldSrc status responses are a bit different from Source's ones. I just split the code for both engines in c3c80c6e35510c2aadbacde86e45d507bcd778c7. Please test if this works for you.

ccondrup commented 15 years ago

Thanks for this. Just tried it, both my local php parser and the servers php parser are picking up an error: Fatal error: Class GameServer contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (GameServer::splitPlayerStatus) in /lib/steam/servers/GameServer.php on line 287

I then set abstract class GameServer {}

and got: Fatal error: Cannot call abstract method GameServer::splitPlayerStatus() in lib/steam/servers/GameServer.php on line 227

btw: s/$player/$playerStatus/ in preg_match of GoldSrcServer::splitPlayerstatus

koraktor commented 15 years ago

Ok... this should be fixed since 4605883591ee7e49f498c6d68d77d0d218db3854. Please give it another try.

ccondrup commented 15 years ago

thanks again. Latest report:

Notice: Undefined offset: 2 in /lib/steam/servers/GoldSrcServer.php on line 38
Notice: Undefined offset: 1 in /lib/steam/servers/GameServer.php on line 233
Notice: Undefined index: in /lib/steam/servers/GameServer.php on line 233
Fatal error: Call to a member function addInformation() on a non-object in /lib/steam/servers/GameServer.php on line 233

Info: dump $players after array_slice line 229 GameServer Array ( [0] => # 1 "Player" 2 STEAM_0:1:111111 3 30:42 35 0 80.102.69.8:27005 [1] => 1 users )

So, changing line 228 of GameServer.php
$players = array_slice($players, 7, sizeof($players) - 7);
to
$players = array_slice($players, 7, sizeof($players) - 8);
fixes this for GoldSrc, but I don't know about Source, don't have rcon access to any Source server.
koraktor commented 15 years ago

Once again, fixed. See 499955f25395dad8149322c782ccb772fa5d065d I missed this as I tested with static content copied from a server console.

Thanks for testing.

ccondrup commented 15 years ago

Found 2 new showstoppers:

  1. GameServer: Return subclass name, not superclass change if(get_class() == 'GoldSrcServer') { to if(get_class($this) == 'GoldSrcServer') {
  2. GoldSrc: I found that the regex needs to change a bit:

    8 "Andrea-PT" 37 STEAM_0:0:11111 18 29:41 25 0 81.92.12.109:53129

    11 "Kaffetrakter" 41 STEAM_0:0:2222 10 25:31 42 0 81.82.129.179:29470

Notice the last one has no space after # and this makes the $playerData contain only: Array ( [0] => )

A real bugger this one :)

koraktor commented 15 years ago

Shame on me... didn't test the code - was too sure it'd work. Fixed since 9a58523e2a64ab41011c19dae3608992feda069a.

ccondrup commented 15 years ago

Hehe, guess what. Still some regex problems. Here is what rcon status just returned, maybe it helps for your testing. Currently it stops on row 2 since there are several spaces in front of "MIKE".

Array
(
    [0] => # 1 "OH-WAH-AH-AH-AH!!!!!" 986 STEAM_0:0:2071   2 03:08   45    0 89.10.233.10:26830
    [1] => # 2   "MIKE" 954 STEAM_0:0:1741   7 52:05   48    0 217.211.18.44:27005
    [2] => # 3 "[nordorf gaming] Generalen" 973 STEAM_0:0:2301   5 19:35   25    0 95.14.110.176:27005
    [3] => # 4 "wICKED!ck" 957 STEAM_0:0:1351   7 47:32   29    0 81.117.131.28:55057
    [4] => # 5    "mrk" 975 STEAM_0:0:21121  12 18:03   45    0 81.217.215.155:27005
    [5] => # 6 "Arsenik" 935 STEAM_0:0:97211  11  1:07:38   28    0 85.117.89.40:58131
    [6] => # 7 "Teaze kake e" 987 STEAM_0:1:2472211   1 01:48   43    0 81.119.30.117:52220
    [7] => #10      "g" 982 STEAM_0:0:15341   7 10:42   33    0 81.116.117.7:27005
    [8] => #11 "Jorniboy Dinapus" 967 STEAM_0:1:2421   8 37:45   55    0 81.211.152.30:59764
    [9] => #12 "cLuMsY" 952 STEAM_0:0:1722181   3 56:21   25    0 81.119.104.16:61371
)
koraktor commented 15 years ago

Ok... wierd. Never saw such a status response. I'll fix this soon.

PS: Never mind 7-9, looks like problems with GitHubs Markdown.

koraktor commented 15 years ago

Once again. Fixed in 4663ab69cad18331a7cc696b9381a2a45b96924a. Hopefully the last one.

ccondrup commented 15 years ago

I'll put a space after # to stop Markdown:

15 "(1)Lato" 347 STEAM_0:1:21751669 0 03:45 23 0 85.117.214.34:52185

 Notice: Undefined index: (1)Lato in /lib/steam/servers/GameServer.php on line 238
koraktor commented 15 years ago

Are you sure you have the right version? As you can see here GameServer.php doesn't have code at line 238.

ccondrup commented 15 years ago

Oh, sorry, that's just because I added some debug. The line was actually 235.

I got another one now: Notice: Undefined index: +EmPeTreeeeeeeee# in lib/steam/servers/GameServer.php on line 235 So it breaks on nicks with special characters like +)#( and so on..

koraktor commented 15 years ago

Ok, this seems like a restriction on array indexes in PHP. But I can't reproduce this - tried a local server with bots and a parsing a static string with some special characters. It worked for both.

What version of PHP are you using? php -v Maybe you should try running a simple script like the following to see if this works in general:

<?php
$a = array("#+()" => "some special characters", "[]&%" => "more special characters");
print_r($a);
?>
ccondrup commented 15 years ago

PHP 5.2.9-pl2-gentoo (cli), Zend Engine v2.2.0 The PHP snippet you provided worked fine, output was exactly like expected.

Ran another test, also worked fine, output in bottom of paste: http://pastie.org/483228 As soon as I uncomment line 21 of that paste, I get these errors: Notice: Undefined index: OH-WAH-AH-AH-AH!!!!! in lib/steam/servers/GameServer.php on line 235 Fatal error: Call to a member function addInformation() on a non-object in lib/steam/servers/GameServer.php on line 235

line 235 = line 21 of the paste

koraktor commented 15 years ago

I assume you don't try to access $this->playerArray like shown in your pastie. $this isn't defined there. Most probably you use this in GameServer.php. Maybe you should add some debug output of the array before the additional data is added / parsed.

Or maybe you can send me (either by mail or GitHub message) the whole code you're using and I'll take a look at it.

ccondrup commented 15 years ago

I am using the library exactly like you provide, I only started to modify it to try to debug the errors I see. The code I pasted was only the lines I modified (temporarily) from the updatePlayerInfo($rcon) method of GameServer.php

Here is my entire GameServer.php with the testdata that gave me errors - do you not get the same errors as I did? -> http://pastie.org/483490

The only code I have to trigger this is $server = new GoldSrcServer(new InetAddress($ip), $port); $server->initialize(); $players = $server->getPlayers($rcon);

koraktor commented 15 years ago

Now I understand... This cannot work. You try to update live player data from the server you're querying with the static data in $status. Most probably some of the players have stopped playing since you created this static data. ;)

ccondrup commented 15 years ago

I understand this. I know what I am doing. I am only debugging. I am trying to find why the script breaks on special characters. I use this way because there are not people with strange nicks on my server 24/7, so I am just faking the status response with testdata so I am sure I get some of the nicks with special characters for every test. Keep in mind though that all these lines of testdata were returned by the server at some point, so it is all real.

Again, have you tried to use Steam-condenser (unchanged) with my rcon-status response? Does that work for you? Because it really does not for me. The easiest way to test is to grab the entire GameServer.php from my last comment and see what that gives you.

koraktor commented 15 years ago

Seems like you didn't completely get my point. You can not update the dynamically acquired playerHash with a hard coded status response in your code. playerHash is initiated with $this->handleResponseForRequest(self::REQUEST_PLAYER);.

Please update your code like shown here - note lines 225-227. This will show that the array that will be updated differs from your static $status.

ccondrup commented 15 years ago

Ouch, I never checked that line, I assumed it was only setting a couple of needed bits or something. I never dreamed that it would fetch all the players simply with that one self::REQUEST_PLAYER. Sorry about the confusion.

I just joined the server myself with nick "+EmP(1)# [hey]" and it seems to be working fine. I'll go ahead and close this ticket now, it has probably been fixed some days already. Thanks for your help and guidance, awesome.

koraktor commented 15 years ago

No problem. Your feedback helps a lot. Thanks :)