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] GM Status (Very clean and easy to use ).

Genesis?Is it a new drug?
Joined
Apr 8, 2010
Messages
512
Reaction score
96
Hello, I did a GM's Status script... yeah, I know that there's a lot of it here, but this one is easier to use, it's very effective, have clean codes, and doesn't have bugs.

I got nothing to do some time a go, then I created it xD

The instructions are in the script.


This is the script:

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Server GM's status</title>

<style type="text/css">

body{
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
color: #404040;	
}

</style>

</head>
<body>

<?php
	
	require_once "config.php";
	
	$array_gms = array(
	
	'ID, Nickname, Rank',
	'ID2, Nickname2, Rank2'
	//...
	);
	
	//NOTE: You can add an infinite number of GMs =)
	
	//NOTE2: To add another GM, insert a COMMA (,) in the end of the previous array, and then create another array following the examples above.
	
	for($i = 0; $i < count($array_gms); $i++){ //OK, ok. I forgot that I could have used foreach, but the result is the same D=
		
		$ExpInfos = explode(',', $array_gms[$i]);
		
		$ArrDados = mysql_query("SELECT `zoneid` FROM `point` WHERE `uid`='".$ExpInfos[0]."' AND `zoneid` > 0");
		
		if(mysql_num_rows($ArrDados) <= 0) $status = '<font color="red">Offline</font>';
		
		else $status = '<font color="#006600">Online</font>'; 
		
		echo '['.trim($ExpInfos[2]).'] '.trim($ExpInfos[1]).' '.$status; if($i != count($array_gms)) echo '<br />';
		
	}
	
?>

</body>
</html>

And this is the database configuration file:

PHP:
<?php
	
	$DBHost 		= 		"localhost"; //DNS or IP
	$DBUser 		= 		"root"; 	 //Database's User
	$DBPassword 	= 		""; 		 //Database's Password
	$DBName 		= 		"pw"; 		 //Database's Name
	
	$Conn 	= 	mysql_connect($DBHost, $DBUser, $DBPassword) or die(mysql_error());
	$Dbs	=	mysql_select_db($DBName, $Conn) or die(mysql_error());

?>

Don't forget to change the database's access information in config.php

Enjoy xD
 
Last edited:
Angelemu founder
Joined
Mar 2, 2011
Messages
525
Reaction score
247
reading the code, i guess you just put it on some page and you can see there which gm is online at the moment.
No need for a tutorial on such simple script.
 
Experienced Elementalist
Joined
Nov 17, 2009
Messages
233
Reaction score
26
the source kinda explain it all, thats nicely put together i like it, great work.
 
Genesis?Is it a new drug?
Joined
Apr 8, 2010
Messages
512
Reaction score
96
no tutorial how to use?
:?: :?:

Just read the codes, there are comments that explain how to use :):

Also, there was a small error in the script... I forgot that I wrote the database connection in the config.php file... so it would try to connect twice, but it's fixed now =)
 
Junior Spellweaver
Joined
Dec 11, 2010
Messages
101
Reaction score
110
I rewrote your code so that it only uses one query and retrieves the GMs name as well as having robust query handling. Well, I don't know if I can call checking the query for validity, robust...but I digress.

PHP:
<?php
define('DB_HOST',		'localhost');	// Database Location
define('DB_USERNAME',	'root');		// Database Username
define('DB_PASSWORD',	'');	// Database Password
define('DB_NAME',		'');	// Database Name

$mysql_connection = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die('MySQL connection failed!');
$mysql_db = @mysql_select_db(DB_NAME, $mysql_connection) or die('MySQL failed to select database!');

$query; // null
$query_str;
$output_info = array();
$output = '';

$array_gms = array(
	32	=> 'Rank',
	96	=> 'Rank2',
	144	=> 'Rank3',
);

if ( count($array_gms) )
{
	// Starting Query
	$query_str = "SELECT point.uid, point.zoneid, roles.role_name FROM point INNER JOIN roles ON point.uid = roles.role_id WHERE ";
	
	// Retrieve GM IDs
	$gmIDs = array_keys($array_gms);
	
	// Build Query
	for($i = 0; $i < count($gmIDs); $i++)
	{
		$query_str .= "point.uid = '" . $gmIDs[$i] . "'";
		
		if ( $i + 1 < count($gmIDs) )
		{
			$query_str .= ' OR ';
		}
	}
	
	$query = @mysql_query($query_str);
	
	// echo '<pre>' . $query_str . '</pre>'; // You can view the generated query with this
	
	if ( $query )
	{
		if ( mysql_num_rows($query) )
		{
			while ( $current_row = mysql_fetch_array($query) )
			{
				$output_info[]  = $current_row;
			}
		}
	}
	else
	{
		echo 'MySQL query failed!';
	}
}
else
{
	// No GMs to speak of...
	echo "No GMs to speak of...<br />";
}

// Output Area
if ( count($output_info) )
{
	// echo '<pre>' . print_r($output_info, 1) . '</pre>'; // You can view the data obtained from the database with this
	
	$html_online = '<font color="#006600">Online</font>';
	$html_offline = '<font color="red">Offline</font>';
	
	foreach ( $output_info as $gm => $data )
	{
		$output .= '[' . $array_gms[$data['uid']] . ']' . htmlentities($data['role_name']) . ' ';
		if ( $data['zoneid'] )
		{
			$output .= $html_online;
		}
		else
		{
			$output .= $html_offline;
		}
		$output .= '<br />';
	}
	
	echo $output;
}
?>
 
Last edited:
Genesis?Is it a new drug?
Joined
Apr 8, 2010
Messages
512
Reaction score
96
I really don't think it's necessary to do queries to check GMs nicknames since you, as an admin, will know their nicknames xD

But anyway... nice code, thanks. =)

...lol, hrace009 is becoming a password example :rofl:
 
Last edited:
Angelemu founder
Joined
Mar 2, 2011
Messages
525
Reaction score
247
with that query you get all online gms without even knowing any name or id of them, just by help of the auth table:
Code:
$query_str = "SELECT point.uid, point.zoneid, roles.role_name FROM point INNER JOIN roles ON point.uid = roles.role_id WHERE point.zoneid<>'null'  and point.uid in (SELECT DISTINCT auth.userid FROM auth )";
 
Last edited:
Genesis?Is it a new drug?
Joined
Apr 8, 2010
Messages
512
Reaction score
96
with that query you get all online gms without even knowing any name or id of them, just by help of the auth table:
Code:
$query_str = "SELECT point.uid, point.zoneid, roles.role_name FROM point INNER JOIN roles ON point.uid = roles.role_id WHERE point.zoneid<>'null'  and point.uid in (SELECT DISTINCT auth.userid FROM auth )";

Yeah... but he still used my gms array D=
 
Junior Spellweaver
Joined
Dec 11, 2010
Messages
101
Reaction score
110
I really don't think it's necessary to do queries to check GMs nicknames since you, as an admin, will know their nicknames xD

But anyway... nice code, thanks. =)

...lol, hrace009 is becoming a password example :rofl:

hrace009 is the password on my local test server. It was originally based on his release and is now extremely modified and half his, half 343's release...I meant to take that info out of the code, but who cares. I made better new code below.


with that query you get all online gms without even knowing any name or id of them, just by help of the auth table:
Code:
$query_str = "SELECT point.uid, point.zoneid, roles.role_name FROM point INNER JOIN roles ON point.uid = roles.role_id WHERE point.zoneid<>'null'  and point.uid in (SELECT DISTINCT auth.userid FROM auth )";

Hmm? I see what this does, but I'm not sure what the auth table data is. Does it only contain the user IDs of the GMs? If so, alright, but what's rid for, if you know?

Also, this query isn't quite right, I fixed it in the below code. You only grabbed the user if they were online, which is going to skip those who are offline.

----------
This is heavily modified even from my earlier one and better documented.

PHP:
<?php
define('DB_HOST',		'localhost');	// Database Location
define('DB_USERNAME',	'root');		// Database Username
define('DB_PASSWORD',	'mypws');	// Database Password
define('DB_NAME',		'pws');	// Database Name

define('GM_ONLINE', '<font color="#006600">Online</font>'); // GM online message
define('GM_OFFLINE', '<font color="red">Offline</font>'); // GM offline message

$mysql_connection = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die('MySQL connection failed!');
$mysql_db = @mysql_select_db(DB_NAME, $mysql_connection) or die('MySQL failed to select database!');

$query; // null
$query_str;
$output_info = array();
$output = '';

// Optional Ranks for GMs
$gm_ranks = array(
	// 'GM Name' => 'Rank'
	'MyCharacter'	=> 'Rank',
	'Rank2 GM'	=> 'Rank2',
	'SomeGuy'	=> 'Rank3',
);

// 'GM Name' => true | This will filter their name out
// 'GM Name' => false| This will NOT filter their name out
// Leaving it empty will also NOT filter out GMs names
$gm_filter = array( // Any GMs you don't want to show...
	'GM Name' => true,
);

// Query
$query_str = "SELECT point.zoneid, roles.role_name FROM point INNER JOIN roles ON point.uid = roles.role_id WHERE point.uid IN (SELECT DISTINCT auth.userid FROM auth)";

// Execute Query
$query = @mysql_query($query_str);

// echo '<pre>' . $query_str . '</pre>'; // You can view the generated query with this

// If query is successful
if ( $query )
{
	// if query is not empty, fetch all information
	if ( mysql_num_rows($query) )
	{
		while ( $current_row = mysql_fetch_array($query) )
		{
			$output_info[]  = $current_row;
		}
	}
}
else
{
	echo 'MySQL query failed!';
}

// Output Area
if ( count($output_info) )
{
	// echo '<pre>' . print_r($output_info, 1) . '</pre>'; // You can view the data obtained from the database with this

	// Iterate through output query data
	foreach ( $output_info as $gm => $data )
	{
		// If GM isn't filtered out
		if ( !$gm_filter[$data['role_name']] )
		{
			// Apply title if user has title
			if ( $gm_ranks[$data['role_name']] )
			{
				$output .= '[' . $gm_ranks[$data['role_name']] . ']';
			}
			
			// Output GM name
			$output .=  htmlentities($data['role_name']) . ' ';
			
			// Output status
			if ( $data['zoneid'] )
			{
				$output .= GM_ONLINE;
			}
			else
			{
				$output .= GM_OFFLINE;
			}
			
			// Output line break
			$output .= '<br />';
		}
	}
	
	// Print out generated output
	echo $output;
}
?>

------------
Renan, I'm going to be adding this (my code) to my php PerfectWorldAPI class. Thank you for getting it started though.
 
Last edited:
Angelemu founder
Joined
Mar 2, 2011
Messages
525
Reaction score
247
it was supposed to show only online gms ^^,
if you want to show all gms, just remove the point.zoneid check.
Of course all this does not work when the gm's char is not the first one one the acc. It will not show the gm when he/she deleted the first char and uses the 2nd. You have to use roles.account_id instead of roles.roleid to get around that.

Code:
SELECT roles.role_name, point.zoneid FROM point INNER JOIN roles ON point.uid = roles.account_id where point.uid IN (SELECT DISTINCT auth.userid FROM auth)  group by roles.account_id order by point.zoneid,roles.role_id asc
this will select the first available character on every gm account and order them by zoneid and roleid

Yes the auth table controls gm powers. rid is the gm power that he/she has.
Example:
Code:
<operation description="Force to be offline" name="Force_Offline" type="100"/>  
        <operation description="Forbid talking" name="Forbid_Talk" type="101"/>   
        <operation description="Forbid trades among players, and between player and NPC" name="Forbid_Trade" type="102"/> 
        <operation description="Forbid selling" name="Forbid_Sell" type="103"/>   
        <operation description="System broadcast" name="Broadcast" type="104"/>

check gmopgen.xml for the full list.

Be aware that if you remove all but one right, the gm may not be even able to talk or attack.
If at least one flag is set, the player with that accountid will show up as gm ingame, and you have to add some additional flags so he/she is able to do the same things as a player, because the default is to deny everything you don't allow as soon as he/she is gm.
 
Last edited:
Back
Top