sm0k3
2011-05-25 00:20:46
heres a php function from a script it works perfectly (almost)
basicly it does server side checking for a string then carries out an action
case '/join': is looking for the text /join
all of the cases work and get picked up by the script (they were there already.)
exept for /wipe (i added this .. i think its possibly the SQL statement thats the problem)
$db->query($sql); is for sending sql query to predefined sql server
i know this works as it is used in many places in the script
[PHP]
function insertParsedMessage($text) {
// If a queryUserName is set, sent all messages as private messages to this userName:
if($this->getQueryUserName() !== null && strpos($text, '/') !== 0) {
$text = '/msg '.$this->getQueryUserName().' '.$text;
}
// Parse IRC-style commands:
if(strpos($text, '/') === 0) {
$textParts = explode(' ', $text);
switch($textParts[0]) {
// Channel switch:
case '/join':
$this->insertParsedMessageJoin($textParts);
break;
//clearChat
case '/wipe':
$sql = 'TRUNCATE TABLE
`ajax_chat_messages`;
ALTER TABLE
`ajax_chat_messages`
AUTO_INCREMENT = 1';
$result = $db->query($sql);
break;
// Logout:
case '/quit':
$this->logout();
break;
// Private message:
case '/msg':
case '/describe':
$this->insertParsedMessagePrivMsg($textParts);
break;
// Invitation:
case '/invite':
$this->insertParsedMessageInvite($textParts);
break;
// Uninvitation:
case '/uninvite':
$this->insertParsedMessageUninvite($textParts);
break;
// Private messaging:
case '/query':
$this->insertParsedMessageQuery($textParts);
break;
// Kicking offending users from the chat:
case '/kick':
$this->insertParsedMessageKick($textParts);
break;
// Listing banned users:
case '/bans':
$this->insertParsedMessageBans($textParts);
break;
// Unban user (remove from ban list):
case '/unban':
$this->insertParsedMessageUnban($textParts);
break;
// Describing actions:
case '/me':
case '/action':
$this->insertParsedMessageAction($textParts);
break;
// Listing online Users:
case '/who':
$this->insertParsedMessageWho($textParts);
break;
// Listing available channels:
case '/list':
$this->insertParsedMessageList($textParts);
break;
// Retrieving the channel of a User:
case '/whereis':
$this->insertParsedMessageWhereis($textParts);
break;
// Listing information about a User:
case '/whois':
$this->insertParsedMessageWhois($textParts);
break;
// Rolling dice:
case '/roll':
$this->insertParsedMessageRoll($textParts);
break;
// Switching userName:
case '/nick':
$this->insertParsedMessageNick($textParts);
break;
// Custom or unknown command:
default:
if(!$this->parseCustomCommands($text, $textParts)) {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error UnknownCommand '.$textParts[0]
);
}
}
} else {
// No command found, just insert the plain message:
$this->insertCustomMessage(
$this->getUserID(),
$this->getUserName(),
$this->getUserRole(),
$this->getChannel(),
$text
);
}
}
[/PHP]
basicly it does server side checking for a string then carries out an action
case '/join': is looking for the text /join
all of the cases work and get picked up by the script (they were there already.)
exept for /wipe (i added this .. i think its possibly the SQL statement thats the problem)
$db->query($sql); is for sending sql query to predefined sql server
i know this works as it is used in many places in the script
[PHP]
function insertParsedMessage($text) {
// If a queryUserName is set, sent all messages as private messages to this userName:
if($this->getQueryUserName() !== null && strpos($text, '/') !== 0) {
$text = '/msg '.$this->getQueryUserName().' '.$text;
}
// Parse IRC-style commands:
if(strpos($text, '/') === 0) {
$textParts = explode(' ', $text);
switch($textParts[0]) {
// Channel switch:
case '/join':
$this->insertParsedMessageJoin($textParts);
break;
//clearChat
case '/wipe':
$sql = 'TRUNCATE TABLE
`ajax_chat_messages`;
ALTER TABLE
`ajax_chat_messages`
AUTO_INCREMENT = 1';
$result = $db->query($sql);
break;
// Logout:
case '/quit':
$this->logout();
break;
// Private message:
case '/msg':
case '/describe':
$this->insertParsedMessagePrivMsg($textParts);
break;
// Invitation:
case '/invite':
$this->insertParsedMessageInvite($textParts);
break;
// Uninvitation:
case '/uninvite':
$this->insertParsedMessageUninvite($textParts);
break;
// Private messaging:
case '/query':
$this->insertParsedMessageQuery($textParts);
break;
// Kicking offending users from the chat:
case '/kick':
$this->insertParsedMessageKick($textParts);
break;
// Listing banned users:
case '/bans':
$this->insertParsedMessageBans($textParts);
break;
// Unban user (remove from ban list):
case '/unban':
$this->insertParsedMessageUnban($textParts);
break;
// Describing actions:
case '/me':
case '/action':
$this->insertParsedMessageAction($textParts);
break;
// Listing online Users:
case '/who':
$this->insertParsedMessageWho($textParts);
break;
// Listing available channels:
case '/list':
$this->insertParsedMessageList($textParts);
break;
// Retrieving the channel of a User:
case '/whereis':
$this->insertParsedMessageWhereis($textParts);
break;
// Listing information about a User:
case '/whois':
$this->insertParsedMessageWhois($textParts);
break;
// Rolling dice:
case '/roll':
$this->insertParsedMessageRoll($textParts);
break;
// Switching userName:
case '/nick':
$this->insertParsedMessageNick($textParts);
break;
// Custom or unknown command:
default:
if(!$this->parseCustomCommands($text, $textParts)) {
$this->insertChatBotMessage(
$this->getPrivateMessageID(),
'/error UnknownCommand '.$textParts[0]
);
}
}
} else {
// No command found, just insert the plain message:
$this->insertCustomMessage(
$this->getUserID(),
$this->getUserName(),
$this->getUserRole(),
$this->getChannel(),
$text
);
}
}
[/PHP]