[Release] Check with PHP if a player is ingame

Results 1 to 13 of 13
  1. #1
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    [Release] Check with PHP if a player is ingame

    Hello

    There are 2 ways to check if a player is logged in.

    1. KOSP Status Server (under R11 KOSP): checks if the requested player is ingame using the player_list command
    2. Auth log: checks the last login/logout log of the account. If the last one is a login, disable access.

    METHOD 1: KOSP

    You can use the StatusServer in KOSP R9 and before to check if a player is logged in or not.

    This following script requires basic PHP knowledge and I will NOT reply any question about PHP that is not related to this script.

    PHP Code:
    <?php
    $msconnect 
    mssql_connect("IP","user","pass"); //db connection
    $kaldb 'kal_db'//db name

    mssql_select_db($kaldb);

    function 
    Send_KOSP_command($cmd
     {
     
     
    // this info should match with the ones in config.properties
     // make sure you set StatusServer = true
     
      
    $port "20009"
      
    $host "localhost";  
      
    $user "admin";
      
    $pass "password";

      
    $fp = @fsockopen($host$port); 

      if(
    $fp
      {    
       
    // Send login 
       
    fwrite($fp,"login $user $pass\r"); 
       
    // Set mode 
       
    fwrite($fp,"mode web\r"); 
       
    // Send command 
       
    fwrite($fp"$cmd\r"); 
       while(!
    feof($fp)) 
        
    $result .= fread ($fp1024); 
       
    fclose($fp); 
       return 
    $result
       } 
      return 
    NULL;
     }
     
     function 
    pid2name($string)
     {
     
    $sql mssql_fetch_array(mssql_query("SELECT [Name] FROM Player WHERE PID = '".$string."'"));
     
    $name $sql['Name'];
     return 
    $name;
     }


    //check if player is online
    $PlayerList Send_KOSP_command("player_list"); 
    $part explode(", "$PlayerList);
    $online 0;
    $i 0;
    while(
    $i count($part))
    {
    if(
    $part[$i] == pid2name($_SESSION['pid'])) //you can change the variable pid2name($_SESSION['pid']) to a direct name instead of using the function. This would look like this:
    //if($part[$i] == "NameHere")
    {
    $online 1;
    }
    $i++;
    }


    if(
    $online == 1)
    {
    echo 
    "You must be logged out of the game when using this function!";
    }
    else
    {
    //your site content
    }
    ?>
    I use it to prevent players from using several PHP scripts on the Client Site while being logged in such as skill upgrades, item transactions as they are not live (if you delete an item in the database it will still be ingame until you relog and that could lead to abuse)

    METHOD 2: Auth log

    Easy, I made it when discovering the Auth Log :)

    Here's how to do it with the kal_auth Log table:

    Function:
    PHP Code:
    function online($uid)
    {
    global 
    $kalauth;
    mssql_select_db($kalauth);
    $sql mssql_fetch_array(mssql_query("SELECT TOP 1 * FROM Log WHERE Player1 = '".$uid."' ORDER BY date desc"));
    $number $sql['Type'];
    return 
    $number;
     } 
    Check:
    PHP Code:
    $uid 548;
    if(
    online($uid) == "0")
    {
    // Logged in
    // fail message
    }
    else
    {
    // Logged out
    // run query

    Have fun with it

    Greets
    Bjorn
    Last edited by General; 22-10-08 at 04:20 PM.


  2. #2
    Account Upgraded | Title Enabled! Spirit is offline
    MemberRank
    Oct 2007 Join Date
    Universe.Location
    291Posts

    Re: [Release] Check with PHP if a player is ingame

    thanks for da Release ... usefull one :)

  3. #3
    Proficient Member DDrAgO is offline
    MemberRank
    May 2008 Join Date
    EgyptLocation
    173Posts

    Re: [Release] Check with PHP if a player is ingame

    Nice :D

  4. #4
    Account Upgraded | Title Enabled! andrew951 is offline
    MemberRank
    Dec 2006 Join Date
    207Posts

    Re: [Release] Check with PHP if a player is ingame

    lol. it would be smart to put your config at the top of your script. not the middle.
    decent script.

  5. #5
    QuaintKal developer ObuolYs is offline
    MemberRank
    May 2007 Join Date
    LithuaniaLocation
    322Posts

    Re: [Release] Check with PHP if a player is ingame

    Nice one :good:
    Is it working on F R10 003 055 146 0948 KOSP version ?
    (I tested on that version but nothing happens. I'm getting clean php page.)

  6. #6
    Hm. foxx is offline
    MemberRank
    Sep 2006 Join Date
    Czech RepublicLocation
    5,257Posts

    Re: [Release] Check with PHP if a player is ingame

    Quote Originally Posted by andrew951 View Post
    lol. it would be smart to put your config at the top of your script. not the middle.
    decent script.
    It's not a config for sql connect but for connecting to the status server, it wouldn't be smart at all imo.

  7. #7
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: [Release] Check with PHP if a player is ingame

    Quote Originally Posted by andrew951 View Post
    lol. it would be smart to put your config at the top of your script. not the middle.
    decent script.
    The statusserver logins are inside the function and if you would put them on top of the page you would have to use global variables which are vulnurable.

  8. #8
    Valued Member Onkelmat is offline
    MemberRank
    Jun 2007 Join Date
    145Posts

    Re: [Release] Check with PHP if a player is ingame

    there is also another way to check ;)
    there is a table in db which shows logged in or logged out :)

  9. #9
    Account Upgraded | Title Enabled! StickyIcky is offline
    MemberRank
    Feb 2008 Join Date
    daheimLocation
    465Posts

    Re: [Release] Check with PHP if a player is ingame

    aja :D thats why u need to push old threads ?xD

  10. #10
    Hm. foxx is offline
    MemberRank
    Sep 2006 Join Date
    Czech RepublicLocation
    5,257Posts

    Re: [Release] Check with PHP if a player is ingame

    Quote Originally Posted by Onkelmat View Post
    there is also another way to check ;)
    there is a table in db which shows logged in or logged out :)
    Which is not real time so it's like very useless.

  11. #11
    A.K.A /v\aX /--/ PHP Guru ToXiC L33T is offline
    MemberRank
    Aug 2007 Join Date
    Prestwich, UnitLocation
    1,112Posts

    Re: [Release] Check with PHP if a player is ingame

    nice release BjornVH.. Nice idea

  12. #12
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: [Release] Check with PHP if a player is ingame

    Quote Originally Posted by Onkelmat View Post
    there is also another way to check ;)
    there is a table in db which shows logged in or logged out :)
    Yeah, making a script for it now :p

  13. #13
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: [Release] Check with PHP if a player is ingame

    Added the Auth log check



Advertisement