Prevent Players From Chatting on TMN

This is the place where you can find everything related to the dedicated server, control scripts and community tools.

Moderators: Pit Crew, TM-Patrol

njbigblue
cyclist
cyclist
Posts: 36
Joined: 19 Jun 2007 04:09
Owned TM-games: TMN, TMU
Contact:

Prevent Players From Chatting on TMN

Post by njbigblue » 15 Jul 2007 07:09

As requested, I'm posting code which will prevent players from chatting on TMN.

Read the comments in the code because the version I'm posting
works in conjunction with my cursing script.

You'll have to modify the players table and the chat.admin.php
file so you can enable/disable chat for a player

I usually disable chat for a player and then re-enable after 10 minutes.
Most of the time they behave after that. If they don't, I kick
and/or ban them depending on what they typed.

If you use my curse script in conjunction with this, it will still kick them even
if you have chat disabled for the user.

Comments welcome

BIGBLUE

Code: Select all

<?php 
/* 
// TMN No Chat by BIGBLUE
// http://www.myspace.com/njbigblue
//
// This script will prevent users in TMN from chatting 
//
// It requires a new field 'AllowChat' to be added 
// to the players database. 
//
// +------------+------------+-------------------+------+---------+
// | Field      | Type       | Collation         | Null | Default | 
// +------------+------------+-------------------+------+---------+
// | AllowChat  | varchar(1) | latin1_general_ci | No   | 1       |
// +------------+------------+-------------------+------+---------+
//
// In order for the script to work you need to add 
//
//     $chatstack = array(); 
//
// to the section of rasp_settings.php that says 
// ----------------------------------------- 
// Do not modify anything below this line... 
// ----------------------------------------- 
//
// Chatting can be enabled and disabled using my
// modified chat.admin.php file
//
// NOTE: There must be at least 18 lines in the chat buffer
//       for this script to completly hide the chat line.
//
*/
 
Aseco::registerEvent("onChat", "checkChat"); 
function getChat($login) { 
     $query1 = "SELECT AllowChat FROM players WHERE Login='" . $login . "'"; 
     $result1 = mysql_query($query1); 
     if (mysql_num_rows($result1) > 0) {	 
          $row1 = mysql_fetch_row($result1); 
          return $row1[0]; 
     	}
     	else
     	{ 
          return "1"; 
     	} 
	} 
	
function checkChat($aseco, $command) { 
global $chatstack;
global $cursestack; // Remove this line if you are not using my Cursing Script
$loginid = $command[0]; 
$login = $command[1]; 
$player = $aseco->server->players->getPlayer($login); 
$nickname = $player->nickname; 
$message = $command[2]; 
$good = false;
$canChat = getChat($login);

if ($loginid != 0) { 
	$msg = $message;
	$arrsize = count($chatstack);
	if ($arrsize > 18) { //This is the max size of the chat window
		$dump = array_shift($chatstack); // remove the oldest chat
		}
	If ($message{0} != "/") { //Filter server commands from the buffer
	array_push($chatstack, "\$ff4[".$nickname."\$m\$ff4] ".$msg); //add chat line to end of the array
	}

//=====
// Players who cannot chat
//=====

If ($canChat != "1"){
	
	//Only allow certain server commands to be used
	$servcommand = array( "/help" 
        ,"/rules" 
        ,"/recs" 
        ,"/stats" 
        ,"/pb" 
        ,"/rank" 
        ,"/top5"
        ,"/y" 
        ,"/karma" 
        ); 

foreach ($servcommand as $word){ 
	$comnd = strlen($word);
	// Only read the first part of the string
	// prevents users from typing "whatever they want /help" and being able to chat 
	    if (stristr(substr($message,0,$comnd),$word)) { //only reads the first part of string
		    $good = true;
	  	 }
 	  	} 
		if ($good != true) {
			
			// Remove the next line if you are not using my Cursing Script
			$dump = array_pop($cursestack); //remove chat line from the curse array
			
			If ($message{0} != "/") {
			$dump1 = array_pop($chatstack); //remove chat line from the chat array
			}
			foreach ($chatstack as &$val) { // Send the last 18 chat lines to all users
			$aseco->addCall('ChatSendServerMessage', array($val));
			}
			$msg = "\$ff4>> Chat is disabled for ".$nickname."\$m\$ff4.\$f00 /help \$ff4commands only"; //Display message to all users stating this use is not allowed to chat
			$aseco->addCall('ChatSendServerMessage', array($msg));			
    	   } 
      }
   } 
}
?>
chat.admin.php mod

Code: Select all

Aseco::addChatCommand('nochat', 'disables chat for player', true);
Aseco::addChatCommand('allowchat', 're-enables chat for a player', true);

Code: Select all

//=====
	/**
	 * NO CHAT
	 */
	elseif ($command['params'][0] == "nochat" && $command['params'][1] != "") {
		// get player information ...
		$player = $aseco->server->players->getPlayer($command['params'][1]);

		if ( !isset($player) )
			{
			$message = "{#server}>> " . $command['params'][1] . " is not a valid player login. Use /players to find the correct login.";
			$aseco->addCall('ChatSendServerMessageToLogin', array($aseco->formatColors($message), $admin->login));
			}
		else
			{

	$query2 = 'SELECT Id, AllowChat FROM players WHERE Login=' . quotedString($player->login);
	$res2 = mysql_query($query2);
	if (mysql_num_rows($res2) > 0) {
		$row2 = mysql_fetch_row($res2);
		$pid2 = $row2[0];
	} else {
	 	return;
	}
	$query3 = "UPDATE players SET AllowChat = '0' WHERE players.Id =".$pid2;
	mysql_query($query3);

			// display console message ...
			$aseco->console("admin [{1}] disabled chat for {2}!", $command['author']->id, stripColors($player->nickname));

			// replace parameters ...
			$message = formatText("{#server}>> Admin [" . $admin->nickname . "{#server}] disabled chat for ");

			// replace colors ...
			$message = $aseco->formatColors($message);
			$message = $message . $player->nickname;

			// send chat message ...
			$aseco->addCall(ChatSendServerMessage, array($message));
			}
		}
//=====
	/**
	 * Allow CHAT
	 */
	elseif ($command['params'][0] == "allowchat" && $command['params'][1] != "") {
		// get player information ...
		$player = $aseco->server->players->getPlayer($command['params'][1]);

		if ( !isset($player) )
			{
			$message = "{#server}>> " . $command['params'][1] . " is not a valid player login. Use /players to find the correct login.";
			$aseco->addCall('ChatSendServerMessageToLogin', array($aseco->formatColors($message), $admin->login));
			}
		else
			{

	$query2 = 'SELECT Id, AllowChat FROM players WHERE Login=' . quotedString($player->login);
	$res2 = mysql_query($query2);
	if (mysql_num_rows($res2) > 0) {
		$row2 = mysql_fetch_row($res2);
		$pid2 = $row2[0];
	} else {
	 	return;
	}
	$query3 = "UPDATE players SET AllowChat = '1' WHERE players.Id =".$pid2;
	mysql_query($query3);

			// display console message ...
			$aseco->console("admin [{1}] allowed chat for {2}!", $command['author']->id, stripColors($player->nickname));

			// replace parameters ...
			$message = formatText("{#server}>> Admin [" . $admin->nickname . "{#server}] allowed chat for ");

			// replace colors ...
			$message = $aseco->formatColors($message);
			$message = $message . $player->nickname;

			// send chat message ...
			$aseco->addCall(ChatSendServerMessage, array($message));
			}
		}
//=====
Lastly the Cursing script

Code: Select all

<?php 
/*
// Curse Blocker by BIGBLUE
// http://www.myspace.com/njbigblue
//
// This script will detect a curse on the chat line,
// hide the curse from all users, send the player a
// warning message and then kick the player. 
// 
// In order for the script to work you need to add 
//
//     $cursestack = array(); 
//
// to the section of rasp_settings.php that says 
// ----------------------------------------- 
// Do not modify anything below this line... 
// ----------------------------------------- 
// 
// NOTE: There must be at least 18 lines in the chat buffer 
//       for this script to completly hide the curse. 
// 
*/
Aseco::registerEvent("onChat", "check4curse"); 

function check4curse($aseco, $command) { 
global $cursestack;
global $chatstack; // Remove this line if you are not using my No Chat script
$loginid = $command[0]; 
$login = $command[1]; 
$player = $aseco->server->players->getPlayer($login); 
$nickname = $player->nickname; 
$message = $command[2]; 

//id=0 is a server message - filter these
if ($loginid != 0) { 
	$msg = $message;
	$arrsize = count($cursestack);
	if ($arrsize > 18) { //This is the max size of the chat window
		$dump = array_shift($cursestack); // remove the oldest chat
		}
	If ($message{0} != "/") { //Filter server commands from the buffer
	array_push($cursestack, "\$ff4[".$nickname."\$m\$ff4] ".$msg); //add chat line to end of the array
	}

//====	
// List all bad words in an array
//====
$badwords = array( "****" 
            ,"****" 
            ,"dickhead" 
            ,"nigger" 
            ,"*******" 
            ); 

foreach ($badwords as $word){ 
      if (stristr($message, $word)){ // check to see if a bad word is in the chat line
 			$dump = array_pop($cursestack); //remove the curse word from the array
 			
 			// Remove the next line if you are not using my No Chat script
			$dump1 = array_pop($chatstack); //remove chat line from the chat array
			
			foreach ($cursestack as &$val) { // Send the last 18 chat lines to all users
			$aseco->addCall('ChatSendServerMessage', array($val));
			}
			// Send message to all users informing them a player cursed and was kicked
			$msg = "\$ff4[$08fBIGBLUEs Server\$m\$ff4]\$fff ".$nickname."\$m\$f00 cursed. \$ff4The line has been censored and the player has been kicked";
			$aseco->addCall('ChatSendServerMessage', array($msg));
			
						$cursewarning =	"\$s\$F00This is an administrative warning.\n\n".
						"\$z\$sCursing is not allowed on this server\n".
						"and you are being \$f00 kicked \$z\$sbecause of it.\n".
						"\$z\$sIf you can control yourself, come back.\n".
						"Repeated abuse will trigger an automatic \$F00BAN\n\n".
						"\$00fBIGBLUE";
			// send popup to user telling them they are being kicked for cursing					
			$aseco->addCall('SendDisplayServerMessageToLogin', array($player->login, $cursewarning, 'OK', '', 0));			
			$aseco->addCall("Kick", array($login));	//kick the user		
       } 
   }              
  } 
}
?>
Visit my server in the USA
BIGBLUEs MINITRAX

m&o
happy cruiser
happy cruiser
Posts: 188
Joined: 19 Apr 2007 17:53
Owned TM-games: TMN, TMU, TMF

Post by m&o » 15 Jul 2007 15:06

nice one now I can stop warining people I don't want to kick:P
wil try it out later

edit
I got a eror:
[PHP Warning] mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 38 in file C:\Documents and Settings\Mat\Mijn documenten\usbTMNserver\Tmn\aseco\plugins\nochat.php

he says it like 50 times(not using cursing script)
Image

njbigblue
cyclist
cyclist
Posts: 36
Joined: 19 Jun 2007 04:09
Owned TM-games: TMN, TMU
Contact:

Post by njbigblue » 17 Jul 2007 05:07

m&o wrote: I got a eror:
[PHP Warning] mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 38 in file C:\Documents and Settings\Mat\Mijn documenten\usbTMNserver\Tmn\aseco\plugins\nochat.php
Did you add the "AllowChat" field to the Players Database?
Visit my server in the USA
BIGBLUEs MINITRAX

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Post by nocturne » 17 Jul 2007 05:54

So, how does it mute the player? To me, it looks like it puts in a bunch of blank lines to clear out the chat window.

njbigblue
cyclist
cyclist
Posts: 36
Joined: 19 Jun 2007 04:09
Owned TM-games: TMN, TMU
Contact:

Post by njbigblue » 18 Jul 2007 01:08

nocturne wrote:So, how does it mute the player? To me, it looks like it puts in a bunch of blank lines to clear out the chat window.
It doesn't put blank lines in the chat window. It puts the last 18 chats in the window. If you want to see it in action, go to my server and ask one my admins to disable your chat (of course tell them to re-enable it after a minute)

BIGBLUE
Visit my server in the USA
BIGBLUEs MINITRAX

m&o
happy cruiser
happy cruiser
Posts: 188
Joined: 19 Apr 2007 17:53
Owned TM-games: TMN, TMU, TMF

Post by m&o » 19 Jul 2007 08:47

added it and it works fine now

thnx
Image

m&o
happy cruiser
happy cruiser
Posts: 188
Joined: 19 Apr 2007 17:53
Owned TM-games: TMN, TMU, TMF

Post by m&o » 20 Jul 2007 17:40

is it posible it also says aseco stuf again like recs becase now I miss that
Image

njbigblue
cyclist
cyclist
Posts: 36
Joined: 19 Jun 2007 04:09
Owned TM-games: TMN, TMU
Contact:

Post by njbigblue » 21 Jul 2007 00:09

m&o wrote:is it posible it also says aseco stuf again like recs becase now I miss that
Yea, I know... I gotta figure out a way to do that because I filter all messages from the server. The problem is that messages that go to one player (pb, rank, welcome msg, etc...) and the ones that go to all players (recs, karma, etc...) are both classified as server messages.

I'm thinking I can add a character to the global server messages and allow that into the array or add a character to the private messages and prevent that from going into the array. Either way, pretty much every PHP file will need to be modified... unless someone else can give me an easier solution.

If I wind up making the changes, I'll let you know...

BIGBLUE
Visit my server in the USA
BIGBLUEs MINITRAX

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: Prevent Players From Chatting on TMN

Post by nocturne » 24 Jul 2007 05:28

What about putting in an allowance for the serverid, and any message beginning with '>', which would include everything but the Karma and top5 recs (easy enough to put a '>' in those anyways).

In my case, the only message commands that are enabled is my /adminmsg plugin for messaging connected admins, which I'd want to include to give the players a chance to apologize, besides the admin's messaging commands. What would I change/remove just to keep all server messages? Or could I put in a line to add the serverid's messages to the chatstack? I don't know much about php, so any help would be greatly appreciated...

njbigblue
cyclist
cyclist
Posts: 36
Joined: 19 Jun 2007 04:09
Owned TM-games: TMN, TMU
Contact:

Re: Prevent Players From Chatting on TMN

Post by njbigblue » 28 Jul 2007 17:42

OK, I have a soloution... :)

Instead of modifying all of the server messages and adding a > or >> and then modifying the nochat and cursing script (there is just too much to modify) I've modified the functions that send server messages.

All you need to do is at the beginning of the function add

Code: Select all

global $chatstack;
global $cursestack;
then right before the line that contains "ChatSendServerMessage" add this code

Code: Select all

//=====
//Add message to chat array and curse array
//=====
	$arraymsg = $message; // change $message to whatever variable is being sent to the users
	// Chat Array
	$arrsize = count($chatstack);
	if ($arrsize > 18) { //This is the max size of the chat window
		$dump = array_shift($chatstack); // remove the oldest chat
		}
	array_push($chatstack, $arraymsg); //add chat line to end of the array
	// Curse Array
	$arrsize2 = count($cursestack);
	if ($arrsize2 > 18) { //This is the max size of the chat window
		$dump = array_shift($cursestack); // remove the oldest chat
		}
	array_push($cursestack, $arraymsg); //add chat line to end of the array
//=====
I modified the following PHP files

aseco.php
plugin.localdatabase.php
plugin.rasp_jukebox.php
plugin.rasp_karma.php

NOTE: Remove the references to the Curse Array if you are not using my Cursing script

Enjoy!!!
BIGBLUE
Visit my server in the USA
BIGBLUEs MINITRAX

m&o
happy cruiser
happy cruiser
Posts: 188
Joined: 19 Apr 2007 17:53
Owned TM-games: TMN, TMU, TMF

Re: Prevent Players From Chatting on TMN

Post by m&o » 04 Aug 2007 10:52

njbigblue wrote:OK, I have a soloution... :)

Instead of modifying all of the server messages and adding a > or >> and then modifying the nochat and cursing script (there is just too much to modify) I've modified the functions that send server messages.

All you need to do is at the beginning of the function add

Code: Select all

global $chatstack;
global $cursestack;
then right before the line that contains "ChatSendServerMessage" add this code

Code: Select all

//=====
//Add message to chat array and curse array
//=====
	$arraymsg = $message; // change $message to whatever variable is being sent to the users
	// Chat Array
	$arrsize = count($chatstack);
	if ($arrsize > 18) { //This is the max size of the chat window
		$dump = array_shift($chatstack); // remove the oldest chat
		}
	array_push($chatstack, $arraymsg); //add chat line to end of the array
	// Curse Array
	$arrsize2 = count($cursestack);
	if ($arrsize2 > 18) { //This is the max size of the chat window
		$dump = array_shift($cursestack); // remove the oldest chat
		}
	array_push($cursestack, $arraymsg); //add chat line to end of the array
//=====
I modified the following PHP files

aseco.php
plugin.localdatabase.php
plugin.rasp_jukebox.php
plugin.rasp_karma.php

NOTE: Remove the references to the Curse Array if you are not using my Cursing script

Enjoy!!!
BIGBLUE
how do I need to do it becase I not get it do I need to put that code in the aseco.php
plugin.localdatabase.php
plugin.rasp_jukebox.php
plugin.rasp_karma.php?
Image

User avatar
soehest
happy cruiser
happy cruiser
Posts: 161
Joined: 07 Jun 2007 13:52
Owned TM-games: TMU
Contact:

Re: Prevent Players From Chatting on TMN

Post by soehest » 09 Aug 2007 16:14

It is a nice idea for a script, but was thinking of an easier and more fair solution. Is it posible to make a script that would disable chat entirely, like /nochat, and it would send a message that admin has disabled chat, and /allowchat...?

regards

User avatar
BReMFoX
smooth traffic navigator
smooth traffic navigator
Posts: 275
Joined: 05 Sep 2006 08:53
Owned TM-games: TMUF
Location: The Netherlands

Re: Prevent Players From Chatting on TMN

Post by BReMFoX » 12 Aug 2007 16:33

Some time ago i asked for a plugin that replaces text when someone curses.
They said, i wasn't really possible.
But....
I think it can be done?!

Idea:

- When someone curses in the chat the line will be removed automatically with this 'Prevent Players From Chatting script'.
- The nickname will be shown in the chat, but not from him/her self (because it's erased by the plugin above), but through the server.
- The server sends the message to the chat with the nick who cursed, with a different sweet text you can edit yourself.

Is this possible?

User avatar
Terron
speedy pilot
speedy pilot
Posts: 445
Joined: 02 Jun 2007 15:00
Owned TM-games: all full+some betas
Location: Earth

Re: Prevent Players From Chatting on TMN

Post by Terron » 26 Aug 2010 19:40

how to use it in TMF?

Xymph
Pit Crew
Pit Crew
Posts: 5650
Joined: 19 Aug 2007 12:58
Owned TM-games: TMN, TMU, TMF, TM²
Contact:

Re: Prevent Players From Chatting on TMN

Post by Xymph » 26 Aug 2010 20:47

Terron wrote:how to use it in TMF?
By forgetting this ancient plugin and using the built-in Ignore method. E.g. in XAseco via /admin ignore.
Developer of XASECO for TMF/TMN ESWC & XASECO2 for TM²: see XAseco.org
Find your way around the Mania community from the TMN ESWC hub, TMF hub, TM² hub, and SM hub

Post Reply