Files We are going to use
- Right.php
- Left.php
- Safe.php
Files We are going to create
- Ban.php
- Edit_account.php
- Read_mail.php
Ok this tutorial is going to be packed with Staff tools to help you and your staff in the game. Then we are going to look and fix the Right.php
Ban.php
First up is Ban.php. Even though you have your rules not every one is going to follow them, and some people will not like your game. You dont have to put up with these people you can IP ban them from the host or you can ban their account.
Step One - Designing
Remember like we did The Help Desk Reply where we only wanted the staff to see the page, well we are going to do the same for this. Create a page called Ban.php and in the body section add this
<?php if (in_array($name, $admin_array) or in_array($name, $mods_array)){ ?>
All your coding for ban will go here. only Admins and Mods will be able to see this.
<? } ?>
Under Ban.php we are going to add all of our coding in that little section. Add this html in there
<table width="350" border="0" cellpadding="0" cellspacing="2" class="table">
<tr>
<td colspan="2" align="left" class="header">Ban Member: <? echo "$user"; ?></td>
</tr>
<tr>
<td align="center" class="cell">Username </td>
<td align="center" class="cell"><input name="ban_name" type="text" id="ban_name" onfocus="if(this.value=='Name')this.value='';" value="<?php echo htmlspecialchars($_GET['ban']);?>" /></td>
</tr>
<tr>
<td align="center" valign="top" class="cell">Reason</td>
<td align="center" valign="top" class="cell"><textarea name="reason" rows="6" id="reason">Duping.</textarea></td>
</tr>
<tr>
<td colspan="2" align="left" class="cell"><input type="checkbox" name="ban_all" value="1" id="ban_all" />
<label for="ban_all">Ban all on IP.</label></td>
</tr>
<tr>
<td colspan="2" align="right" class="cell"><input name="Ban" type="submit" id="Ban" value="Ban." onfocus="if(this.blur)this.blur()" /></td>
</tr>
</table>
now one of the things that will make you ban someone is multiple account for that same user. Which means a user can create like 5 accounts send money from all of those account to one main account and create havoc amongst players. It will be like you having 5 lives, which is cheating and is called Duping. When a player is duping and you want to ban them, you will want to ban all account that he is duping with. well if all those accounts are created under the same ip, we are going to add code that will let you check the "Ban all on IP" and it will ban all accounts created under that ip.
Sometime player may way want their account dead not banned, so we need to create a little script for that, this will let staff kill players not ban them. Add this code under the top one.
<table width="350" border="0" cellpadding="0" cellspacing="2" class="table">
<tr>
<td colspan="2" align="left" class="header">Kill Player: </td>
</tr>
<tr>
<td align="center" class="cell">Username</td>
<td align="center" class="cell"><input name="target" type="text" id="target" onfocus="if(this.value=='Name')this.value='';" value="<?php echo htmlspecialchars($_GET['kill']);?>" /></td>
</tr>
<tr>
<td colspan="2" align="right" class="cell"><input name="Murder" type="submit" class="button" id="Murder" value="Murder." onfocus="if(this.blur)this.blur()" /></td>
</tr>
</table>
and finally we are after all humans and we do make mistakes, so if you make a mistake and ban a user we need a way to unban them. Add the following below to your page
<table width="350" border="0" cellpadding="0" cellspacing="2" class="table">
<tr>
<td colspan="2" align="left" class="header">Unban / Revive Member: </td>
</tr>
<tr>
<td align="center" class="cell">Username</td>
<td align="center" class="cell"><input name="remove_ban_name" type="text" id="remove_ban_name" onfocus="if(this.value=='Name')this.value='';" value="Name" /></td>
</tr>
<tr>
<td height="27" colspan="2" align="right" class="cell"><input name="Remove_Ban" type="submit" class="button" id="Remove_Ban" value="Remove Ban." onfocus="if(this.blur)this.blur()" /></td>
</tr>
</table>
Step Two - PHP
ok we have got our design now it is time for some coding.
we need to store some information of the banning so we need to create a banned table.
# # Table structure for table `banned` # CREATE TABLE banned ( id int(22) NOT NULL auto_increment, `name` varchar(20) NOT NULL, banner varchar(20) NOT NULL, `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, reason text NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=124 DEFAULT CHARSET=latin1; # --------------------------------------------------------
How ban/kill works.
when a user gets banned or killed what happens is that we change their sitestate under the users table to 1 for banned or 2 for killed. Right now the sitestate is 0 for alive. then on safe we are going to add a validation to check if sitestate is greater 0 stop the page from loading and display a message. There are better ways of doing this but this is simple and does the job.
right add the php.
<?php
if(isset($_POST['Ban'])){
// fetching and storing the information we need from database
$sql = "SELECT name,sitestate,userip FROM users WHERE name='".mysql_real_escape_string($_POST['ban_name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$banned_name = htmlspecialchars($row->name);
$banned_state = htmlspecialchars($row->sitestate);
$banned_ip = htmlspecialchars($row->userip);
// using the ban all on ip function
if($_POST['ban_all'] == "1"){
$result = mysql_query("UPDATE users SET sitestate='1' WHERE userip='" .mysql_real_escape_string($banned_ip). "'")
or die(mysql_error());
echo "all have been banned.";
}else{
if (empty($banned_name)){
echo "This person does not seem to exist.";
}else {
if($banned_state == 1){
echo "This person is already banned.";
}else{
if (in_array($banned_name, $admin_array) or in_array($banned_name, $mods_array)) {
echo "<b style=\"font-size:36px;\">Cant Ban Staff.</b>";
}else{
$result = mysql_query("UPDATE users SET sitestate='1' WHERE name='" .mysql_real_escape_string($banned_name). "'")
or die(mysql_error());
$sql = "INSERT INTO banned SET id = '', name = '" .mysql_real_escape_string($banned_name). "', banner = '" .mysql_real_escape_string($name). "', reason = '".$_POST['reason']. "'";
$res = mysql_query($sql);
echo $banned_name." has been banned.";
}// killing staff
}// if already banned.
}// if user doesn't exist.
}// ban type select.
}// if isset Ban.
// removing someone from ban
if(isset($_POST['Remove_Ban'])){
$sql = "SELECT name,sitestate,userip FROM users WHERE name='".mysql_real_escape_string($_POST['remove_ban_name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$banned_name = htmlspecialchars($row->name);
$banned_state = htmlspecialchars($row->sitestate);
$banned_ip = htmlspecialchars($row->userip);
if (empty($banned_name)){
echo "This person does not seem to exist.";
}else {
if($banned_state == 0){
echo "This person is not dead or banned.";
}else{
$result = mysql_query("UPDATE users SET sitestate='0' WHERE name='" .mysql_real_escape_string($banned_name). "'")
or die(mysql_error());
echo $banned_name." has been Revived / Un banned.";
}// if already banned.
}// if user doesn't exist.
}// if isset Ban.
// killing an account
if(isset($_POST['Murder'])){
$nsql = "SELECT name,sitestate FROM users WHERE name='".mysql_real_escape_string($_POST['target'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$target_name = htmlspecialchars($row->name);
$target_state = htmlspecialchars($row->sitestate);
if(empty($_POST['target'])){
echo "You didn't enter a target.";
}else{
if (in_array($target_name, $admin_array) or in_array($target_name, $mods_array)) {
echo "<b style=\"font-size:36px;\">Cant Kill Staff.</b>";
}else{
if($target_state != 0 ){
echo "Your target is already dead or banned.";
}else{
$result = mysql_query("UPDATE users SET sitestate='2' WHERE name='" .mysql_real_escape_string($_POST['target']). "'")
or die(mysql_error());
echo "You shot extremely large amount of bullets at ".$target_name." He/She died from the shots.";
}
}
}
}// if isset post murder.
$user=$_GET['ban_name'];
?>
the above php code should be simple and easy to understand. There is nothing new from what we have being doing. if you dont understand any part of it or you need me to explain just post it below and i will.
Step Three - Safe.php
On safe.php we need to add some coding that will block the user from the rest of the site content.
The structure is like this.
If the users sitestate is = 1
echo "You have being banned"
exit (This stops anything else from loading, and because safe is top it will stop any page from loading. This is why we need safe on every page.)
the code looks like this, add this to the bottom of Safe.php
if ($sitestate == 1){
echo " Your account was ban from this site. Bye";
exit();
}
if ($sitestate == 2){
echo " Your account was Killed from this site. Sign up again";
exit();
}
Try to be creative in the way you tell users that their account i banned or killed.
Right.php and Left.php
On the Left menu you may want the staff tools to show just for your staff so normal players cannot see it. the principle to the normal staff pages are the same. For now this is what you should have on the Left.php
<? include_once("Safe.php"); ?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Style.css" />
</head>
<body>
<table width="0%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td align="left" valign="top" >
<table width="123" height="301" border="0" align="left" cellpadding="0" cellspacing="2" class="table">
<tr>
<td height="23" class="header">Main Game</td>
</tr>
<tr >
<td height="65" valign="top" class="cell"><a href="Usersonline.php">Users online</a><a href="Help_Desk.php"><br>
Help Desk<br>
</a><a href="Find_Player.php">Find Player</a></td>
</tr>
<tr class="header">
<td height="23">Social</td>
</tr>
<tr >
<td height="105" valign="top" class="cell"><a href="Forum.php">Forum<br>
</a><a href="Send_Message.php">Send Message</a><a href="Forum.php"> </a></td>
</tr>
<?php if (in_array($name, $admin_array) or in_array($name, $mods_array)){
?>
<tr class="header">
<td height="23">Staff Menu</td>
</tr>
<tr class="cell">
<td height="23"><a href="Ban.php">Ban</a><br>
<a href="Help_Desk_Reply.php">Help Desk</a></td>
</tr>
<? } ?>
<tr class="header">
<td height="23"><a href="index.php">LogOut</a></td>
</tr>
</table>
<td width="100%" align="center" valign="top">
</body>
</html>
Right.php
below is a code to improve Right.php. this is just basic tables and also i use the style we created in the last tutorial. All this is just information fetched in to safe.php displayed on the right menu like the user money their health etc etc.
<html>
<head>
</head>
<body>
<td width="150" align="right" valign="top" bgcolor="">
<table width="135" border="0" align="right" cellpadding="0" cellspacing="2" class="table">
<tr>
<td class="header">Players information</td>
</tr>
<tr>
<td height="19" class="header">Money</td>
</tr>
<tr>
<td height="27" class="cell"><?php echo "$".number_format($money)."";?></td>
</tr>
<tr>
<td height="19" class="header">Points</td>
</tr>
<tr>
<td height="24" class="cell"><?php echo number_format($points);?></td>
</tr>
<tr>
<td height="19" class="header">Health</td>
</tr>
<tr>
<td height="19" class="cell"><?php echo $health."%"; ?></td>
</tr>
</table>
</td></td>
</tr>
</table>
</body>
</html>
Ok that's it for now. The next tutorial will be my last and final tutorial on php game making. so i am going to let you guys choose what you want the last one to be. Vote for the page you want me to make a tutorial on next. Voting close on the 14th of October.






MultiQuote






|