Page 1 of 1

Text Based Mafia Game || Banning/right menu Part 9 Creating a ban option and fixing the right menu Rate Topic: ***** 2 Votes

Poll: Choose the next tutorial (23 member(s) have cast votes)

What do you want the next tutorial to be,

  1. Crimes (5 votes [21.74%])

    Percentage of vote: 21.74%

  2. Steal a car (1 votes [4.35%])

    Percentage of vote: 4.35%

  3. Travel to different citys (1 votes [4.35%])

    Percentage of vote: 4.35%

  4. Gangs/crews (8 votes [34.78%])

    Percentage of vote: 34.78%

  5. Missions / Kill page (8 votes [34.78%])

    Percentage of vote: 34.78%

Vote Guests cannot vote

#1 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 05 October 2010 - 01:26 PM

Please check out my other tutorials PART 1, PART 2, PART 3, PART 4, PART 5, PART 6, PART 7, PART 8.

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.


--------
Mod: the code can be found here:
https://github.com/m...ext_Based_Mafia


Is This A Good Question/Topic? 0
  • +

Replies To: Text Based Mafia Game || Banning/right menu Part 9

#2 Coding Monkeh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-October 10

Posted 06 October 2010 - 04:26 PM

Congratulations on the series of tutorials, I think I might use some just to start me off, looks like a good starting point :) it has all the basics i need to start. I'll vote for you now :)

good luck on the last tutorial :)
Was This Post Helpful? 0
  • +
  • -

#3 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,299
  • Joined: 22-October 08

Posted 06 October 2010 - 09:14 PM

Another great tutorial denis, though i dont need to read them ive only read some of them. These are perfect references for noobs. Back when i was a noob all those many years ago, i could not find any tutorials maybe you should consider putting them together in a pdf or mayve a Ebook
Thanks Aaron1178
Was This Post Helpful? 0
  • +
  • -

#4 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 08 October 2010 - 02:32 PM

View Postaaron1178, on 07 October 2010 - 03:14 AM, said:

Another great tutorial denis, though i dont need to read them ive only read some of them. These are perfect references for noobs. Back when i was a noob all those many years ago, i could not find any tutorials maybe you should consider putting them together in a pdf or mayve a Ebook
Thanks Aaron1178


yes i am considering doing that. i have started a pdf series with more details and explanations and new features like how to implement Ajax for things like chat etc . Will be published next year :)
Was This Post Helpful? 0
  • +
  • -

#5 jin0616  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-June 09

Posted 03 November 2010 - 03:23 AM

anyone know when is part 10 coming out?
Was This Post Helpful? 0
  • +
  • -

#6 RaverBaloo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-March 12

Posted 18 March 2012 - 02:10 PM

So i am kinda stuck finally, i was wondering where do ihave to put the ban code? i have tried putting it all over my Ban.php. But when i go to bann my test it doesnt ban them....
Was This Post Helpful? 0
  • +
  • -

#7 matty1990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-October 12

Posted 27 October 2012 - 05:27 AM

Hey i must say great tutorial keep up the great work .. for the final tutorial can you make all of the ones people are voting for because i dont see it being any good if theres files missing lol
Was This Post Helpful? 0
  • +
  • -

#8 bamsetheking  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 16
  • Joined: 21-November 12

Posted 05 June 2013 - 01:55 AM

hi can someone help med with mig code ?:D/> i have most off the code but not all working :D/>
my emails is <Removed email>

download link : <Removed link>

This post has been edited by macosxnerd101: 05 June 2013 - 06:06 AM
Reason for edit:: Removed info per site policies

Was This Post Helpful? 0
  • +
  • -

#9 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 05 June 2013 - 09:42 AM

View Postbamsetheking, on 05 June 2013 - 09:55 AM, said:

hi can someone help med with mig code ?:D/>/> i have most off the code but not all working :D/>/>
my emails is <Removed email>

download link : <Removed link>

Post your code so far and tell us where you are having problems. Let us know of any errors messages you are having.
Was This Post Helpful? 0
  • +
  • -

#10 bamsetheking  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 16
  • Joined: 21-November 12

Posted 26 June 2013 - 12:49 AM

banning dosent work :)/>
error : Notice: Undefined index: ban_name in C:\wamp\www\Ban.php on line 117
<?php require("Left.php"); ?>
<?php require("Safe.php"); ?>

<?php 
    if (in_array($name, $admin_array)){ 

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'];
?>

<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="<? 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>
<table width="350" border="0" cellpadding="0" cellspacing="2" class="table">
  <tr>
    <td colspan="2" align="left" class="header">Ban Member: <?php 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="<? 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>
<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>

<?php } ?>
<?php require("Right.php"); ?>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1