Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);//No time out
- $bot = new BasicXatBot();
- $roomID = 152378607;//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.41","10033"); //Connect to XAT...this IP will change as necessary automatically depending on the room you want to join.
- $bot->join($roomID);
- while(true){
- if($bot->read()=='DIED') {
- $bot->connect("174.36.242.40","10033");
- $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 = "364709400";
- private $k = "2331980819";
- //Bot Account Settings
- private $name = "Kot1cs son"; //The display name the bot will use
- private $avatar = 1139; //The Avatar value for the bot, this can be an id number or an image url.
- private $homepage = "Http://YoujustgotIPlogged.com"; //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) {
- $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...
- 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]) {
- case '.say':
- case '.speak':
- case '.talk':
- $this->sendPrivateMessage($command[1],$data['id']);
- break;
- }
- }
- 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 '!info':
- $this->sendPrivateChat('Iam Kot1cs bot.',$data['id']);
- break;
- case '!8ball';
- }
- switch($command[0]) {
- case '!Kotic':
- $this->sendPrivateChat('Kotic is a very Intelligent person, mess with him, you mess with me (un).',$data['id']);
- $this->sendmessage('Kotic is a very Intelligent person, mess with him, you mess with me (un).');
- 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";
- if ($data['message']=='back') {
- $this->sendMessage ('Welcome Back.');
- break;
- }
- if ($data['message']=='ty') {
- $this->sendMessage ('Your welcome.');
- break;
- }
- if ($data['message']=='back') {
- $this->sendMessage ('Welcome back');
- break;
- }
- if ($data['message']=='thank you') {
- $this->sendMessage ('Your welcome.');
- break;
- }
- if ($data['message']=='fuck') {
- $this->sendMessage ('Do not curse.');
- break;
- }
- if ($data['message']=='fuck') {
- $this->sendMessage ('Do not curse');
- break;
- }
- if ($data['message']=='Gtg') {
- $this->sendMessage ('Aw, why so soon?');
- break;
- }
- if ($data['message']=='g2g') {
- $this->sendMessage ('Aw, why so soon?');
- break;
- }
- if ($data['message']=='G2g') {
- $this->sendMessage ('Aw, why so soon?');
- break;
- }
- if ($data['message']=='Gotta go') {
- $this->sendMessage ('Aw, why so soon?');
- break;
- }
- if ($data['message']=='Bye') {
- $this->sendMessage ('Bye, Come back soon!');
- break;
- }
- if ($data['message']=='hi') {
- $this->sendMessage ('Hey there, whats up?');
- break;
- }
- if ($data['message']=='nm') {
- $this->sendMessage ('Cool');
- break;
- }
- if ($data['message']=='Hi') {
- $this->sendMessage ('Hey there, whats up?');
- break;
- }
- if ($data['message']=='What do you care?') {
- $this->sendMessage ('I was just asking..Im sorry.');
- break;
- }
- if ($data['message']=='Sorry') {
- $this->sendMessage ('Thats alright');
- break;
- }
- if ($data['message']=='Hey') {
- $this->sendMessage ('Hey there, whats up?');
- break;
- }
- if ($data['message']=='hey') {
- $this->sendMessage ('Hey there, whats up?');
- break;
- }
- if ($data['message']=='cool bot') {
- $this->sendMessage ('Thanks');
- break;
- }
- if ($data['message']=='Smart bot') {
- $this->sendMessage ('Thanks I have been coded by Kot1c and Sam');
- break;
- }
- if ($data['message']=='Whos is this bot?') {
- $this->sendMessage ('Sams and Kot1cs?');
- break;
- }
- if ($data['message']=='Whats up?') {
- $this->sendMessage ('Nm you?');
- break;
- }
- if ($data['message']=='') {
- $this->sendMessage ('Aw, why so soon?');
- break;
- }
- if ($data['message']=='why') {
- $this->sendMessage ('Because it is not appropiate');
- break;
- }
- if ($data['message']=='y not?') {
- $this->sendMessage ('Because it is not appropiate');
- break;
- }
- if ($data['message']=='fuck you') {
- $this->sendMessage ('Do not curse.');
- break;
- }
- if ($data['message']=='fuck you bot') {
- $this->sendMessage ('Do not curse, or you will have to face the consequences.');
- break;
- }
- if ($data['message']=='gay') {
- $this->sendMessage ('If you dont like this than just leave..');
- break;
- }
- if ($data['message']=='hey kot1c') {
- $this->sendMessage ('Hey there');
- break;
- }
- if ($data['message']=='Kotic') {
- $this->sendMessage ('Hes my dad.');
- break;
- }
- if ($data['message']=='Who are you?') {
- $this->sendMessage ('Im kotics son.');
- break;
- }
- if ($data['message']=='fuck kotic') {
- $this->sendMessage ('Do not curse at him or you will face the consequences.');
- break;
- }
- if ($data['message']=='Sup') {
- $this->sendMessage ('Nm you?.');
- break;
- }
- if ($data['message']=='kot1cs gay') {
- $this->sendMessage ('Do not annoy him please.');
- break;
- }
- if ($data['message']=='Whos bot is that?') {
- $this->sendMessage ('Im kotics son.');
- break;
- }
- if ($data['message']=='lol') {
- $this->sendMessage ('What are you laughing at?');
- break;
- }
- if ($data['message']=='lmfao') {
- $this->sendMessage ('Whats so funny?');
- break;
- }
- if ($data['message']=='your face') {
- $this->sendMessage ('Well I was actually laughing at yours too..');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='Spam') {
- $this->sendMessage ('Iam VIUM staff.');
- break;
- }
- if ($data['message']=='thats gay') {
- $this->sendMessage ('Your face is gay.');
- break;
- }
- if ($data['message']=='cool') {
- $this->sendMessage ('Yeah.');
- break;
- }
- if ($data['message']=='nmu?') {
- $this->sendMessage ('Same bored...');
- break;
- }
- if ($data['message']=='i need help') {
- $this->sendMessage ('If you need help ask Kotic.');
- break;
- }
- if ($data['message']=='SUCK MY BALLS') {
- $this->sendMessage ('If you need help ask Kotic.');
- break;
- }
- if ($data['message']=='help') {
- $this->sendMessage ('If you need help ask Kotic.');
- break;
- }
- if ($data['message']=='guess what') {
- $this->sendMessage ('What?');
- break;
- }
- if ($data['message']==' ') {
- $this->sendMessage ('HA HA');
- break;
- }
- if ($data['message']=='twat') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='shit') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='nigger') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='cunt') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='nigga') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='dick') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='pussy') {
- $this->sendMessage ('Do not curse of you will have to face the consequences.');
- break;
- }
- if ($data['message']=='Who is kotic?') {
- $this->sendMessage ('Kotic is a PHP developer, also VIUM staff.');
- break;
- }
- if ($data['message']=='Yeah right?') {
- $this->sendMessage ('Want to be? Ask Kotic.');
- break;
- }
- if ($data['message']=='Dont be shy say hi') {
- $this->sendMessage ('Hi guys...');
- break;
- }
- if ($data['message']=='!8ball') {
- $this->sendMessage ('Certainly');
- $this->sendMessage ('No');
- break;
- }
- //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 '!say':
- case '!speak':
- case '!talk':
- //Multiple cases lead to the same code being run...
- $this->sendMessage($command[1]);
- break;
- case '!commands':
- $this->sendmessage('Spam commands: !Fact !Info, !Ownerme, !Spam');
- sleep(1);
- break;
- case '!info':
- $this->sendmessage('Iam a bot, Very carefully coded by Kot1c and Sam. ');
- break;
- case '!':
- $this->Sendmessage('Say a command please :s');
- break;
- switch($command[1]) {
- case 'Owner me':
- $this->sendMessage('Dont ask!');
- break; }
- case '!Fact':
- $this->sendMessage('Did you know canadians found out that Einsteins brain was 15% wider than usual');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('The Playstation Creator died in the earthquake in Japan');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('George Washington creates the Order of the Purple Heart ');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('1782 -George Washington creates the Order of the Purple Heart ');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage(' 1789 - US War Department established. ');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('1807 - 1st servicable steamboat the Cleremont goes on 1st voyage');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('In 1983, a Japanese artist, Tadahiko Ogawa, made a copy of the Mona Lisa completely out of ordinary toast.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('A surfer once sued another surfer for "stealing his wave." The case was thrown out because the court was unable to put a price on "pain and suffering" endured by the surfer watching someone else ride "his" wave.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('Between 1902 and 1907, the same tiger killed 434 people in India. ');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('Flying from London to New York by Concord (now retired), due to the time zones crossed, you can arrive 2 hours before you leave.');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('Kissing can aid in reducing tooth decay. This is because the extra saliva helps in keeping the mouth clean.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('In the Durango desert, in Mexico, theres a creepy spot called the "Zone of Silence". You cant pick up clear TV or radio signals. And locals say fireballs sometimes appear in the sky.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('Male goats will pee on each other in order to attract mates.');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('An earthquake on Dec. 16, 1811 caused parts of the Mississippi River to flow backwards.');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('The Angel Falls in Venezuela were named after an American pilot, Jimmy Angel, whose plane got stuck on top of the mountain while searching for gold.');
- sleep(1);
- break; case '!fact':
- $this->sendmessage('Bill Gates donated close to $100 million to fight AIDS in India. As a percent of his total wealth, this would be comparable to him donating ten cents if he only had $60.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('In a study conducted regarding toilet paper usage, Americans are said to use the most toilet paper per trip to the bathroom, which was seven sheets of toilet paper per trip.');
- sleep(1);
- break;
- case '!Fact':
- $this->sendmessage('Ray Kroc bought McDonalds for $2.7 million in 1961 from the McDonald brothers.');
- sleep(1);
- break;
- case '!fact':
- $this->sendmessage('A woman in China partially lost her hearing after her boyfriend reportedly ruptured her eardrum with a passionate kiss. Apparently, the kiss reduced the pressure in the mouth, pulled the eardrum out, and caused the breakdown of the ear.');
- sleep(1);
- break;
- case '!Spam':
- case '!Spam':
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- $this->sendmessage('VIUM Staff.');
- break;
- case '!ownerme':
- $this->sendMessage('I will not owner you, Sorry just following orders.');
- break;
- case '!goto':
- $room = $command[1];
- $this->roomid = $command[1];
- $this->connect("174.36.242.41", "10033" );
- $this->join($room);
- break;
- case '!kick':
- function kick($message, $id) {
- $this->send('<c p="'.$message.'" u="'.$this->parseU($id).'" t="/k" />');
- }
- break;
- }
- }
- break;
- }
- }
- /* ****************************************************** */
- /* *YOU SHOULD NOT NEED TO EDIT ANYTHING AFTER THIS 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 , 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 mod($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 owner($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" />');
- }
- /**
- * 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 '';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement