Jump to content

what does this stand for in a function?


Go to solution Solved by dodgeitorelse3,

Recommended Posts

It would help if you displayed the function in which it is used. As you may have noticed, there is an incrementation of 1 for occurring; however, without seeing the actual function we cannot definitively describe what/why/how that incrementation is being used.

it is for a game server tracker . I am trying to learn what some parts of it are as I wopuld like to make a server query for our communications server. I am not afraid to learn and am somewaht capable within php but not to this extent. I have searched and searched and thanks to you guys I have been given keywords to search for and as usual, you guys know what you are looking at and talking about. below is the function I am trying to learn from. Any pointers to tutorials or whatever are greatly appreciated.

 

function lgsl_query_09(&$server, &$lgsl_need, &$lgsl_fp)
  {
//---------------------------------------------------------+

    // SERIOUS SAM 2 RETURNS ALL PLAYER NAMES AS "Unknown Player" SO SKIP OR CONVERT ANY PLAYER REQUESTS
    if ($server['b']['type'] == "serioussam2") { $lgsl_need['p'] = FALSE; if (!$lgsl_need['s'] && !$lgsl_need['e']) { $lgsl_need['s'] = TRUE; } }

//---------------------------------------------------------+

    if ($lgsl_need['s'] || $lgsl_need['e'])
    {
      $lgsl_need['s'] = FALSE; $lgsl_need['e'] = FALSE;

      fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\xFF\x00\x00\x00");

      $buffer = fread($lgsl_fp, 4096);

      $buffer = substr($buffer, 5, -2); // REMOVE HEADER AND FOOTER

      if (!$buffer) { return FALSE; }

      $item = explode("\x00", $buffer);

      foreach ($item as $item_key => $data_key)
      {
        if ($item_key % 2) { continue; } // SKIP EVEN KEYS

        $data_key = strtolower($data_key);
        $server['e'][$data_key] = $item[$item_key+1];
      }

      if (isset($server['e']['hostname']))   { $server['s']['name']       = $server['e']['hostname']; }
      if (isset($server['e']['mapname']))    { $server['s']['map']        = $server['e']['mapname']; }
      if (isset($server['e']['numplayers'])) { $server['s']['players']    = $server['e']['numplayers']; }
      if (isset($server['e']['maxplayers'])) { $server['s']['playersmax'] = $server['e']['maxplayers']; }
      if (isset($server['e']['password']))   { $server['s']['password']   = $server['e']['password']; }

      if (!empty($server['e']['gamename']))   { $server['s']['game'] = $server['e']['gamename']; }   // AARMY
      if (!empty($server['e']['gsgamename'])) { $server['s']['game'] = $server['e']['gsgamename']; } // FEAR
      if (!empty($server['e']['game_id']))    { $server['s']['game'] = $server['e']['game_id']; }    // BFVIETNAM

      if ($server['b']['type'] == "arma" || $server['b']['type'] == "arma2")
      {
        $server['s']['map'] = $server['e']['mission'];
      }
      elseif ($server['b']['type'] == "vietcong2")
      {
        $server['e']['extinfo_autobalance'] = ord($server['e']['extinfo'][18]) == 2 ? "off" : "on";
        // [ 13 = Vietnam and RPG Mode 19 1b 99 9b ] [ 22 23 = Mounted MG Limit ]
        // [ 27 = Idle Limit ] [ 18 = Auto Balance ] [ 55 = Chat and Blind Spectator 5a 5c da dc ]
      }
    }

//---------------------------------------------------------+

    elseif ($lgsl_need['p'])
    {
      $lgsl_need['p'] = FALSE;

      fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\x00\xFF\x00\x00");

      $buffer = fread($lgsl_fp, 4096);

      $buffer = substr($buffer, 7, -1); // REMOVE HEADER / PLAYER TOTAL / FOOTER

      if (!$buffer) { return FALSE; }

      if (strpos($buffer, "\x00\x00") === FALSE) { return TRUE; } // NO PLAYERS

      $buffer     = explode("\x00\x00",$buffer, 2);            // SPLIT FIELDS FROM ITEMS
      $buffer[0]  = str_replace("_",      "",     $buffer[0]); // REMOVE UNDERSCORES FROM FIELDS
      $buffer[0]  = str_replace("player", "name", $buffer[0]); // LGSL STANDARD
      $field_list = explode("\x00",$buffer[0]);                // SPLIT UP FIELDS
      $item       = explode("\x00",$buffer[1]);                // SPLIT UP ITEMS

      $item_position = 0;
      $item_total    = count($item);
      $player_key    = 0;

      do
      {
        foreach ($field_list as $field)
        {
          $server['p'][$player_key][$field] = $item[$item_position];

          $item_position ++;
        }

        $player_key ++;
      }
      while ($item_position < $item_total);
    }

//---------------------------------------------------------+

    return TRUE;
  }

//------------------------------------------------------------------------------------------------------------+
//------------------------------------------------------------------------------------------------------------+

The actual binary strings are specific to Serious Sam 2, and a description of them should be available in their official fora. That's not something we can help you with, as it requires specialized knowledge about the specific game engine.

As for the rest of the code it's pretty standard socket communication, with the code sending a request to the server (fwrite ()), reading the response (fread ()), and then parsing the results to something humans can read (everything after if (!$buffer) {return false; }). The PHP manual will explain what each function does, and by stepping through the code with a debugger you can see the effects for yourself. ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.