Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release] Check with PHP if a player is ingame

Joined
Sep 10, 2006
Messages
1,243
Reaction score
179
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:
<?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 ($fp, 1024); 
   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:
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:
$uid = 548;
if(online($uid) == "0")
{
// Logged in
// fail message
}
else
{
// Logged out
// run query
}

Have fun with it

Greets
Bjorn
 
Last edited:
Junior Spellweaver
Joined
Oct 19, 2007
Messages
198
Reaction score
2
thanks for da Release ... usefull one :)
 
Junior Spellweaver
Joined
Dec 2, 2006
Messages
198
Reaction score
0
lol. it would be smart to put your config at the top of your script. not the middle.
decent script.
 
Experienced Elementalist
Joined
May 21, 2007
Messages
228
Reaction score
48
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.)
 
Junior Spellweaver
Joined
Jun 11, 2007
Messages
118
Reaction score
0
there is also another way to check ;)
there is a table in db which shows logged in or logged out :)
 
Back
Top