setting $values and repeating them

ok I added some changes, backup what you have just so you can always go back, but give this section of the code a try:
[php]

<?php /** * @author 3nvisi0n * @copyright 2011 * * This is just a basic version of my Xat Bot you can build upon to add the feature you want. * */ set_time_limit(0);//No time out $bot = new BasicXatBot(); $botowner = array('320467393', '320467394'); $roomID = 150355757;//Don't know how to get this ID? goto xat.com/ROOM_YOU_WANT_BOT_IN and View Source(Firefox: Ctrl+U, Internet Explorer: View>Source) Look for "flashvars="id=#########&..." the ID is the number you want $bot->connect("174.36.242.26","10024"); //Connect to XAT...this IP will change as necessary automatically depending on the room you want to join. $bot->join($roomID); class BasicXatBot { private $soc; //Socket for bot private $debug = false;//Used to toggle debugging output. private $packet;//Stores information about the last recieved packet of each kind private $userInfo;//Stores User information //If you don't know where to get these you should probably not be trying to make your own bot. //Go download WPE Pro and check out the packets XAT sends and learn about how XAT works. //The UserID and K Value are the source or the 'old falsh' error(if you get it) make sure you get these values from a REGISTERED account private $userID = "351599155"; //The Bot's UserID private $k = "3607438505";//The Bot's K value //Bot Account Settings private $name = "DuBot"; //The display name the bot will use private $avatar = "http://www.instablogsimages.com/images/2009/01/08/joe-bot-inflatable-robot_NBz64_6648.jpg"; //The Avatar value for the bot, this can be an id number or an image url. private $homepage = ""; //The bot's homepage link. private $roomID;//This gets set in code, don't touch it here. just used ->join(ID) /** * This is where everything the bot does needs to happen, this is the only default function you should need to edit * @param $event The event that just occured(and thus needs to be handled) * @param $data Any data relating to this event. */ function handleEvent($event,$data) { global $automem, $botowner; $info = $this->getUserArray($data['id']); switch($event) { case 'userJoined': { /* $data['id'] Has the ID of the user who just joined $data['old'] Sometimes XAT sends packets that are not current(for example when you join a room, old ==true for all users who are already in the room when you join, but still this event is handled as thought they just joined */ //Do whever you want with users joining here... $this->sendPrivateMessage("Welcome to the chat! Please follow the rules and enjoy your stay. :)",$data['id']); if("$info[rank]"=="guest" && "$automem"=="on") $this->member($data['id']); if($info['name']=='') $this->kick("NULL",$data['id']); echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) has just joined.\n"; break; } case 'userLeft': /* $data['id']The ID of the user that just left. */ echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) has just left.\n"; break; case 'privateMessage': /* $data['id']The ID of the user that just left. $data['message'] The message sent to you as a PM */ echo "[PM] ".((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n"; //Example of a private message command $command = explode(' ',$data['message'],2); //First parse the first word out see if it is a command... //[0] has first word [1] has everything else if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right. switch($command[0]) { } } break; case 'privateChat': /* $data['id']The ID of the user that just left. $data['message'] The message sent to you as a PC */ echo "[PC] ".((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n"; //Example of a private chat command $command = explode(' ',$data['message'],2); //First parse the first word out see if it is a command... //[0] has first word [1] has everything else if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right. switch($command[0]) { case '!unbanme': if(($data['id'])==$botowner) $this->unban($data['id']); break; } } break; case 'message': /* $data['id']The ID of the user $data['old']See $data['old'] under userJoined $data['message'] The message sent to main chat */ echo ((trim($info['registeredName'])!='')?$info['registeredName']:$info['name'])."($info[rank]) -> $data[message]\n"; //How to do main chat commands: if($data['old']) return; //Old message $command = explode(' ',trim($data['message']),2); //First parse the first word out see if it is a command... //[0] has first word [1] has everything else if($command[0]{0}=='!'){//I am use ! as the character to signify a command, so check if the first character is right. switch($command[0]) { case '!commands': $this->sendPrivateMessage("!guestme | !memberme | !kickme | !banme [seconds] | !info",$data['id']); break; case '!say': if(($data['id'])==$botowner) $this->sendMessage($command[1]); else $this->sendMessage("Don't tell me what to say (D)",$data['id']); break; case '!automember': if(in_array($data['id'], $botowner]) && $command[1]=="on") { $automem = "on"; $this->sendMessage("Auto Membering is ".$automem."."); } elseif(in_array($data['id'], $botowner]) && $command[1]=="off") { $automem = "off"; $this->sendMessage("Auto Membering is ".$automem."."); } continue; case '!ams': $this->sendMessage("Auto membering is currently ".$automem); break; case '!guest': if(($data['id'])==$botowner) $this->guest($command[1]); break; case '!member': if(($data['id'])==$botowner) $this->member($command[1]); break; case '!mod': if(($data['id'])==$botowner) $this->mod($command[1]); break; case '!kick': if(($data['id'])==$botowner) $this->kick("Dubz told me to... (WARY)",$command[1]); break; case '!ban': if(($data['id'])==$botowner) $this->ban("Dubz told me to... (WARY)",$command[1],600); break; case '!unban': if(($data['id'])==$botowner) $this->unban($command[1]); break; case '!guestme': $this->guest($data['id']); break; case '!memberme': $this->member($data['id']); break; case '!modme': if(($data['id'])==$botowner) $this->mod($data['id']); else $this->sendMessage("Yeah, right. (SMIRK)",$data['id']); break; case '!moderatorme': if(($data['id'])==$botowner) $this->mod($data['id']); else $this->sendMessage("Yeah, right. (SMIRK)",$data['id']); break; case '!ownerme': if(($data['id'])==$botowner) $this->owner($data['id']); else $this->sendMessage("You gotta be kidding me! (XD)",$data['id']); break; case '!mainownerme': $this->sendMessage("What on Earth are you smoking? (O_O)",$data['id']); break; case '!kickme': $this->kick("You asked for it...",$data['id']); break; case '!banme': $this->ban("You asked for it...",$data['id'],$command[1]); break; case '!protect': if(($data['id'])==$botowner) $this->sendMessage("/p"); break; case '!define': if(($data['id'])==$botowner) $this->sendMessage("http://www.urbandictionary.com/define.php?term=".$command[1],$data['id']); break; case '!info': $this->sendMessage("Dubz is my master.",$data['id']); break; case '!killbot': if(($data['id'])==$botowner) $this->die(); else $this->sendMessage("Yeah? YOU AND WHAT ARMY! (SMIRK)",$data['id']); break; } } break; } } /* ****************************************************** */ /* *YOU SHOULD NOT NEED TO EDIT ANYTHING AFTER TH IS LINE* */ /* ****************************************************** */ [/php]

thanks this works great now. i got both problems fixed (botowner and switch)

the only bug in the script was a ] after $botowner in the if statements but i just deleted them and it works.
ill add them to the rest of the owner commands. i dont want you to do it all for me so i can learn too :stuck_out_tongue:

thanks for your help and im sure ill be ack here for more questions in the future ;D

actually i have one last problem. sometimes whenever i try to run it on a chat i get an old flash error that i dont know how to fix. It runs in the command prompt and i have no idea how to fix it. It just says an old chat is being used (its not an old chat) and to upgrade flash to fix it but it is updated. not sure if you would know how to fix that. its xat chats by the way if you havent figured that out already :stuck_out_tongue:

xat.com

try clearing your browser cache, then close the browser and give it a shot again sometimes it can be a cache issue since flash files get cached like images and mp3’s etc. if everything is up to date then that would most likely be the culprit. I doubt it would be due to old version of flash if it is telling you it is an old chat, but you never know. Yes I noticed it was xat 8) I love that chat. I am glad you got it all straight now!

ive tried the cache before and it never seemed to work. ive had very slim luck wiht turning my proxy on and off and restarting by broswer but if a chats on promotion it almost never works :frowning:

also, im trying to add another function to member registered users only and im getting an error.

heres what i did

[php] if("$info[rank]"==“guest” && “$automem”==“on”)
$this->member($data[‘id’]);
if("$info[rank]"==“guest” && “$info[‘registeredName’]”!=’’ && “$automem”==“registered”)
$this->member($data[‘id’]);[/php]
the error is on that 3rd line but the other works. i added the registered command already after the on and off ones so it should be fine. some people just only want registered users to be members and i didn’t want to have to have 2 main scripts to be messing around with when i could have one main one.

I dont believe these should be in quotes
“$info[‘registeredName’]”
“$info[rank]”
could be wrong but I think take them out of quotes, also did you add a new section which would register the variable $automem as “regististered” cause when we last left off it was only “on” or"off"?

i tried it without quotes but it didnt work. the error didnt show but the command didnt go. and yes i did add another elseif for registered

do what you have to, to have it echo out
$info[rank]
$info[‘registeredName’]
$automem
I am betting they are empty or not what they need to be to fill the if statement!

yeah i did it before but deleted the script because i was going to put it all on one. i dindt bother to look at that part and remember it or copy it down though. i just made a small command to say that to figure out which one i needed so ill jsut do that again

well i removed the quotes before and it didnt work but now it is ???

i think i might of been editing another one i had at the time so i wasnt editing the one i was testing and when i realized it i never tried that but idk

works:
[php]if("$info[rank]"==“guest” && $info[‘registeredName’]!=’’ && “$automem”==“registered”)[/php]

thanks for all your help so far. im sure ill be back with more questions :stuck_out_tongue:

im still getting this flash error. i cleared my browsing data, tried the proxy, restarted my browser and nothing. the error points to this part of the script
[php]function read($parse=true) {
$res = rtrim(socket_read($this->soc, 4096));
if($this->debug)echo “<<-\t$res\n”;
if(!$res) {
return “DIED”; //Used to gracefully handle a closed socket
}
if($res{strlen($res)-1}!=’>’) { $res.=$this->read(false);} //Recursive call for messages split over several packets.
if($parse)$this->parse($res);
return $res;
}[/php]
heres a snapshot of the error: http://prntscr.com/2c3n7 (i just made a batch file to run the bots easily instead of going through cmd every time i can just open it and type in the name to run)

if you could help me with this it would be greatly appreciated since it does this very often

its pointing to the second line of that btw

are you sure that you have secure sockets enabled?

not sure what you mean. heres the second half of the script if it helps you tell. the first half issues the connection and all that but this has all the functions and stuff in it

[php] /* ****************************************************** /
/
YOU SHOULD NOT NEED TO EDIT ANYTHING AFTER TH
IS LINE
/
/
****************************************************** /
/
*
* Connects to a given ip on the given port
* @param $ip The IP to connect to.
* @param $port The port on the IP to connect to.
*/
function connect($ip, $port) {
if($this->soc!=null) socket_close($this->soc);
$this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
if(!socket_connect($this->soc,$ip,$port)) die(“Could not connect.”);
}

/**
 * Writes the given message to the object socket($this->soc)
 * @param $message The packet to send.
 */
function send($message) {
    if($this->debug)echo "->>\t$message\n";
    socket_write($this->soc, $message."\0", strlen($message)+1); 
}


/**
 * Reads a message from the socket, will read until entire message has been recieved or connection closes.
 * @param $parse Used for recursive calls to tell the function not to parse a partial packet
 */
function read($parse=true) {
    $res = rtrim(socket_read($this->soc, 4096));
    if($this->debug)echo "<<-\t$res\n";
    if(!$res) {
        return "DIED"; //Used to gracefully handle a closed socket
    }
    if($res{strlen($res)-1}!='>') { $res.=$this->read(false);} //Recursive call for messages split over several packets.
    if($parse)$this->parse($res);
    return $res;
}

/**
 * Parses the recieved packets into their message and types.
 * @param $packet The packet recieved.
 */
function parse($packet) {
    if(substr_count($packet,'>')>1) $packet = explode('/>',$packet);//If necessary split the packet into individual messages
    foreach((Array)$packet as $p) {
        $p = trim($p);
        if(strlen($p)<5) return;//garbage data
        $type = trim(strtolower(substr($p,1,strpos($p.' ',' '))));//packet type
        $p = trim(str_replace("<$type",'',str_replace('/>','',$p)));//remove details so it is just the info to be parsed
        parse_str(str_replace('"','',str_replace('" ','&',str_replace('="','=',str_replace('&','__38',$p)))),$this->packet[$type]);
        foreach($this->packet[$type] as $k=>$v) {
            $this->packet[$type][$k] = str_replace('__38','&',$v); //htmlspecial chars are protected instead of being parsed 
        }
        $this->handle($type,$p);
    }
}

/**
 * This is the inital handler for the packets, parses them and sends them off to their respective function to be handled further.
 * @param $type The character code indicating the type of data within the message.
 * @param $message The data the message contains.
 */
function handle($type,$msg) { 
    switch($type) {
        case 'gp':
            if(isset($this->packet['gp']['x']))
                $this->send('<x i="'.$this->packet['gp']['x'].'" u="'.$this->userID.'" t="j" />'); //Handle groups
        break;
        case 'q'://XAT notice to change ip/port
            $this->connect($this->packet['q']['d'], $this->packet['q']['p']);
            $this->join($this->roomID);
        break;  
        case 'o': 
            $this->packet['o']['u'] = $this->parseU(@$this->packet['u']['u']);
            $this->userInfo[$this->packet['o']['u']]['name'] = @$this->packet['o']['n'];
            $this->userInfo[$this->packet['o']['u']]['registeredName'] = ((isset($this->packet['o']['N']))?$this->packet['o']['N']:'');
            $this->userInfo[$this->packet['o']['u']]['avatar'] = @$this->packet['o']['a'];
            $this->userInfo[$this->packet['o']['u']]['homepage'] = @$this->packet['o']['h'];
            $this->userInfo[$this->packet['o']['u']]['rank'] = $this->f2rank(@$this->packet['o']['f']);
        break;
        case 'u':
            //Joined
            //Default Bot stuff regarding userInformation
            $this->packet['u']['u'] = $this->parseU(@$this->packet['u']['u']);
            $this->userInfo[$this->packet['u']['u']]['name'] = @$this->packet['u']['n'];
            $this->userInfo[$this->packet['u']['u']]['registeredName'] = ((isset($this->packet['u']['N']))?$this->packet['u']['N']:'');
            $this->userInfo[$this->packet['u']['u']]['avatar'] = @$this->packet['u']['a'];
            $this->userInfo[$this->packet['u']['u']]['homepage'] = @$this->packet['u']['h'];
            $this->userInfo[$this->packet['u']['u']]['rank'] = $this->f2rank(@$this->packet['u']['f']);
            
            $event = 'userJoined';
            $data['id'] = $this->packet['u']['u'];
            $data['old'] = ($type=='o'||(isset($this->packet['u']['s']))?true:false);
            $this->handleEvent($event,$data);
            
        break;
        case 'l':
            //User Left or was kicked, banned
            unset($this->userInfo[$this->packet['l']['u']]);
            $event = 'userLeft';
            $data['id'] = $this->packet['l']['u'];
            $this->handleEvent($event,$data);
            
        break;
        case 'p':
            //Private message/chat recieved
            $event = ((isset($this->packet['p']['d']))?'privateChat':'privateMessage');
            $data['id'] =  $this->parseU(@$this->packet['p']['u']);
            $data['message'] = $this->packet['p']['t'];
            $this->handleEvent($event,$data);
        break;
        case 'm':
            //message to main chat.
            $event = 'message';
            $data['id'] = $this->parseU(@$this->packet['m']['u']);
            $data['message'] = $this->packet['m']['t'];
            $data['old'] = ((isset($this->packet['m']['s']))?true:false);
            $this->handleEvent($event,$data);
        break;
    }
}

/**
 * Joins a room.
 * @param $roomID the numeric roomID to join.
 */
function join($roomID) {
    //Announce we are here:
    $this->send('<y m="1" />');//Anounces our arrival to the server and gets some information to send back
    $this->read(); //Auto parsed into $this->packet['y']
    $this->send('<j2 q="1" y="'.$this->packet['y']['i'].'" k="'.$this->k.'" k3="0" z="12" p="0" c="'.$roomID.'" f="0" u="'.$this->userID.'" d0="0" n="'.$this->name.'" a="'.$this->avatar.'" h="'.$this->homepage.'" v="0" />');
    $this->roomID = $roomID;
}

/**
 * Parses the u value from a packet to get just the id
 * @param $id the id to be parsed.
 */
function parseU($id) {
    if(substr_count($id,'_')>=1) $id = substr($id,0,strpos($id,'_'));
    return $id;
}

/**
 * Converts an f value to a string containing the corresponding rank...this if you don't understand bitwise operations is a little 'magical' deal with it.
 * @param $f The f value to be parsed.
 */
function f2rank($f) {
    $f = $this->parseU($f);
    
    if($f==-1) return 'guest';
    //Okay, 98% of you reading this on NewHax won't know what any of this means; if you do you are more adnvanced than I expected
    //Not that this is advnaced stuff, but basiclly it is a bit-wise comparision(notice & instead of && it is checking if certain binary bits are set to 1
    //The F value is essientially a bunch of flags where for example 00010000 == banned(the 0s can be 0 or 1, just as long as that one 1 is a one you are banned.
    if((16 & $f)) return 'banned';
    if((1 & $f)&&(2 & $f)) return 'member';
    if((4 & $f)) return 'owner';
    if((32 & $f)&&(1 & $f)&&!(2 & $f)) return 'main';
    if(!(1 & $f)&&!(2 & $f)) return 'guest';
    if((16 & $f)) return 'banned';
    if((2 & $f)&&!(1 & $f)) return 'mod';
}

/**
 * Returns an assoc array of information regarding the user with the given id
 * @param $id The user id you want information on.
 */
function getUserArray($id) {
    $id = $this->parseU($id);
    if(isset($this->userInfo[$id])) {
         return $this->userInfo[$id];
    } else return false;
}

/**
 * Sends the given message to the main chat
 * @param $message
 */
function sendMessage($message) {
    if(empty($message))return;
    $this->send('<m t="'.$message.'" u="'.$this->userID.'" />');    
}

/**
 * Sends a PC to the given ID
 * @param $message The message to send.
 * @param $id The id to send the message to
 */
function sendPrivateChat($message, $id) {
    if(empty($message))return;
    $this->send('<p u="'.$id.'" t="'.$message.'" s="2" d="'.$this->userID.'" />');    
}

/**
 * Sends a PM to the given ID
 * @param $message The message to send.
 * @param $id The id to send the message to
 */
function sendPrivateMessage($message,$id) {
    $id = $this->parseU($id);
    if(empty($message))return;
    $this->send('<p u="'.$id.'" t="'.$message.'" />');    
}

/** 
 * Makes the given $id an owner, assuming the bot is main
 * @param $id The id to promote
 */
function owner($id) {
    $this->send('<c u="'.$this->parseU($id).'" t="/M" />');
}

/** 
 * Makes the given $id a mod, assuming the bot is owner
 * @param $id The id to promote
 */
function mod($id) {
    $this->send('<c u="'.$this->parseU($id).'" t="/m" />');
}

/** 
 * Makes the given $id a member, assuming the bot is mod
 * @param $id The id to member
 */
function member($id) {
        $this->send('<c u="'.$this->parseU($id).'" t="/e" />');
}

/** 
 * Makes the given $id a guest, assuming the bot is mod
 * @param $id The id to guest
 */
function guest($id) {
        $this->send('<c u="'.$this->parseU($id).'" t="/r" />');
}

/** 
 * Ki!cks the given ID assuming the bot is a mod and $id is a member or less
 * @param $id The id to kick
 */
function kick($message, $id) {
    $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/k" />');   
}

/** 
 * Bans the ID for a given time(0 is forever)
 * @param $id The id to ban
 */
function ban($message, $id, $time) {
    if(empty($time)) $time = 3600;
    $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/g'.$time.'" />');
}

/** 
 * Unbans the given ID
 * @param $id The id to unban
 */
function unban($id) {
    $this->send('<c u="'.$this->parseU($id).'" t="/u" />');    
}

/**
 * Performs a basic HTTP GET to the given URL
 * @param $url The url to retrieve, please include http:// and www if necessary
 * @param $includeHeader Tells teh function wether or not to include the server header respond before the main content
 */
function get($url, $includeHeader=false) {
    $urlp = parse_url($url); 
    $fp = fsockopen($urlp['host'],80); 
    $path = explode('/',$url,4);
    $path = ((count($path)>=4)?$path[3]:"");
    $req = "GET /$path HTTP/1.1\r\n";
    $req .= "Host: $urlp[host]\r\n";
    $req .= "Connection: Close\r\n\r\n";
    fputs($fp, $req);
    $res = ""; 
    while(!feof($fp)) $res .= fgets($fp, 4096);
    fclose($fp);
    if($includeHeader) return $res;
    $res = explode("\r\n\r\n",$res,2);
    return $res[1];
}
/**
 * A utility function to get all text beween $start and $end
 * @param $content The content from which we are grabbing data
 * @param $start where to start grabbing from
 * @param $end the end of the content to grab
 */
function getBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}
function pause($seconds){
	    sleep($seconds);
}

}

?>[/php]

i talked to 3nvisi0n (the guy who made this script) and he said secure sockets arent needed and just to get the ID and K value from a registered user and login with protection and locking of. i tried but still no luck.

Sponsor our Newsletter | Privacy Policy | Terms of Service