Forgot Password / Register
Site Statistics
Total Members: 506
Total Tutorials: 242
Newsest User: Williamhawk1
Todays Unique Hits: 63
0 Users 1 Guests Online

[PHP IRC] Bot authentication

This time around you will learn how to force your users to identify to the bot in order to use commands.

First off, lets open ext/botExt.php

All edits will be done to this file for the first few segments released. This file contains all the commands and basic functions for the bot. botCore and botDbWrapper are pretty much done unless you wish to expand them further for advanced functions.

Anyway, lets begin with the following;

Find:
Code

private $mIRC_Socket;


Add After:
Code

private $identifiedUsers = array();


This piece of code will hold all the users who have identified with the bot.

Find:
Code

case '!botstat':
fputs($this->mIRC_Socket, "PRIVMSG $user :Oh hai! this bot was coded as a tutorial for the RMB-Scripting community at rmb-scripting.com It was posted by MOD-Shadow.\n"); //simple bot descripion.
break;


Add After:
Code

case '!identify':
$getUser = parent::sqlQuery("SELECT * FROM `ch_modes` WHERE `username` = '$user';");
if(parent::sqlCount($getUser) == 0){
fputs($this->mIRC_Socket, "PRIVMSG $user :Sorry, but your username was not found in the database.\n");
}else{
$usrData = parent::sqlFetch($getUser);
$usrPasswd = $this->Encrypt($data['4']);
if($usrData['password'] == $usrPasswd){
fputs($this->mIRC_Socket, "PRIVMSG $user :The password you have provided is invalid.\n");
}else{
if($this->checkIdentified($user)){
fputs($this->mIRC_Socket, "PRIVMSG $user :You are already identified.\n");
}else{
$this->identifiedUsers = $user;
fputs($this->mIRC_Socket, "PRIVMSG $user :You have now been identified to the bot.\n");
}
}
}
break;


This is our function to force users to !identify [passwordhere] with the bot. If the user is found it will continue on with password checking, then finally to check if the user is already identified or not.

Next, we will add two new functions to the file which will manage encrypted passwords and identify checking.

So, before the final } in the file add these.
Code

function checkIdentified($user){
if(in_array($user, $this->identifiedUsers)){
return true;
}else{
return false;
}
}
function Encrypt($passwd){
$string1 = hash("md4","RMB IRC Bot Tutorial ".$passwd." Password hash");
$string2 = hash("md5",$string1);
$string3 = hash("haval256,5", $string2);
return md5("Good bye").sha1($string3).md5("world!");
}


Encrypt will encrypt your password with md4, md5 and another random password hash.

Finally, you can add a test command so people can message the bot and it will return if they are or aren't identified.

Code

case '!test':
if(!$this->checkIdentified($user)){
fputs($this->mIRC_Socket, "PRIVMSG $user :You are not identified.\n");
}else{
//do things here
fputs($this->mIRC_Socket, "PRIVMSG $user :You are identified.\n");
}
break;


Now, if you wish to add more commands and want them to be identified just add an if statement like above and it should go through.

If you have any troubles PM me on the site, or if you have my MSN send a message on there.
ShadowMage
Author:
Views:
1965
Rating:
There are currently no comments for this tutorial.