Advertisement
iiWizrius

damn 0.6

May 17th, 2016
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 47.52 KB | None | 0 0
  1. <?php
  2. /**
  3. * dAmn Class
  4. *
  5. *@todo add a global records variable to record joins/parts and other stats. Maybe record the times too?
  6. *@author SubjectX52873M <SubjectX52873M@gmail.com>
  7. *@author electicnet
  8. *@copyright SubjectX52873M 2006
  9. *@origin Tarbot 0.2e
  10. *@version 0.5
  11. *@modlevel medium
  12. *@package Dante
  13. *@license http://www.opensource.org/licenses/gpl-license.php GNU General Public License
  14. */
  15. /**
  16. * dAmn related functions
  17. * contains alot of functions and variables related to dAmn function.
  18. *@author SubjectX52873M <SubjectX52873M@gmail.com>
  19. *@author electicnet
  20. *@copyright SubjectX52873M 2006
  21. *@origin Tarbot 0.2e
  22. *@modlevel medium
  23. *@version 0.6
  24. */
  25.     class dAmn {
  26.         /**
  27.         * Stores whether or not the bot is connected.
  28.         *@var bool $connected
  29.         */
  30.         var $connected;
  31.         /**
  32.         * Stores whether or not the bot is logged in.
  33.         *@var bool $loggedIn
  34.         */
  35.         var $loggedIn;
  36.        
  37.         /**
  38.         * Tracks if there was a socket error
  39.         *
  40.         * Used to prevent the bot from going into an infinite loop, this has been a problem.
  41.         *@origin Dante 0.4
  42.         *@var bool $SocketAbort
  43.         */
  44.         var $SocketAbort;
  45.        
  46.         /**
  47.         * Use the stored token for login.
  48.         *
  49.         *This is to track the use of a token and whether a new one is required
  50.         *@var bool $UseToken
  51.         */
  52.         var $UseToken;
  53.        
  54.         /**
  55.         *Last access time for the socket
  56.         *@var integer $lastAccess
  57.         */
  58.         var $lastAccess;
  59.        
  60.         /**
  61.         * Bot Startup
  62.         *
  63.         * Runs dAmn::getAuthToken() and sets $config['bot']['token']
  64.         *@author electricnet
  65.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  66.         *@origin Tarbot 0.2e
  67.         *@version 0.6
  68.         */
  69.         function init(){
  70.             global $config, $seperator, $debug;
  71.             $this->connected = false;
  72.             $this->loggedIn = false;
  73.             $this->SocketAbort=false;
  74.             //Grab login info.
  75.             if(!$debug){
  76.                 internalHeader("STARTING DANTE!", "=");
  77.             } else {
  78.                 internalHeader("STARTING DANTE -- DEBUG MODE!", "=");
  79.             }
  80.             internalMessage("Running ".BotType." version ".BotVersion." ".BotState);
  81.             internalMessage("Written by: SubjectX52873M.");
  82.             internalMessage("With code \"stolen\" from: Tarbot 0.2e, xBot 0.9, and Noodlebot 3.0");
  83.             internalHeader("AUTHTOKEN");
  84.             //New to version 0.3, now get the AuthToken
  85.             if ($this->UseToken) {
  86.                 internalMessage("Trying Stored token first.");
  87.             } else {
  88.                 $config['bot']['token'] = $this->getAuthToken();
  89.                 save_config('bot');
  90.             }
  91.         }
  92.        
  93.         /**
  94.         * If the bot fails to load properly you need to reconnect the socket.
  95.         *
  96.         *This is only called if the stored Token fails to work.
  97.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  98.         *@origin Dante 0.3
  99.         *@version 0.5
  100.         */
  101.         function reconSocket() {
  102.             global $config, $socket;
  103.             socket_close($socket);
  104.             $socket =null;
  105.             $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  106.             if(!@socket_connect($socket, gethostbyname(BotServer), BotPort)) {intMsg('Can\'t connect socket!!!!');return;}
  107.             if ($this->UseToken==false) { //IF NOT!! messed this up in 0.3
  108.             //Okay, function called to reconnect from a failure with a stored token.
  109.                 internalMessage("Failed to login using stored token. Grabbing a new one and trying again.");
  110.                 $config['bot']['token'] = $this->getAuthToken();
  111.                 save_config('bot');
  112.                 global  $packetping;
  113.                  $packetping=microtime(true);
  114.                 //Connect
  115.                 $this->startup();
  116.                 //Join rooms.
  117.                 $this->autoJoin();
  118.                 $this->pingpong();
  119.                 $loop = 0;
  120.                 $onceconnected = false;
  121.             }
  122.         }
  123.        
  124.         /**
  125.         *Reconnect on disconnect
  126.         *
  127.         *Makes the code in the main file cleaner to use this here.
  128.         *@origin Dante 0.3
  129.         *@version 0.5
  130.         */
  131.         function reconnect() {
  132.             global $socket, $loops;
  133.             $this->SocketAbort=false;
  134.             internalMessage("Closing socket.");
  135.             @socket_shutdown($socket);
  136.             @socket_close($socket); //Supress Errors.
  137.            
  138.             internalMessage("Waiting 15 secs for reconnect");
  139.             sleep(15);
  140.             echo "\n";
  141.             internalMessage("Connecting...");
  142.             $socket = null; // Remove previous references
  143.             $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  144.            
  145.             //Connect the socket
  146.             if(@socket_connect($socket, gethostbyname(BotServer), BotPort)) {
  147.                 internalmessage("Connecting...");
  148.                 $this->startup();
  149.                 $this->autoJoin();
  150.                 $loops = 0;
  151.                 global  $packetping;
  152.                  $packetping=microtime(true);
  153.             } else {
  154.                  sleep(15); //Prevent inifinite loops
  155.                  $loops++;
  156.                 if ($loops==100) { internalmessage("Can't connect after 100 tries, dying."); die();}
  157.                  internalmessage("Can't connect socket!!!!, waiting 15 seconds. Try: $loops");
  158.                  sleep(15); //Prevent inifinite loops
  159.                
  160.             }
  161.         }
  162.         /**
  163.         * Bot Startup
  164.         *
  165.         * Runs dAmn:connect() and dAmn::login()
  166.         *
  167.         * electricnet: Includes everything needed to startup in ONE function
  168.         *@author electricnet
  169.         *@origin Tarbot 0.2e
  170.         *@modlevel no modified
  171.         *@see dAmn:login()
  172.         *@see dAmn:connect()
  173.         *@version 0.1
  174.         */
  175.         function startup(){
  176.             global $seperator;
  177.             internalHeader("CONNECT");
  178.             $this->connect();
  179.             $this->login();
  180.         }
  181.         /**
  182.         * Connect to server and send the useragent
  183.         *
  184.         *User Agent is currently just "agent=Dante"
  185.         *
  186.         *Raw dAmnClient 0.2\nagent=Dante\n\0
  187.         *@author electricnet
  188.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  189.         *@origin Tarbot 0.2e
  190.         *@modlevel light
  191.         *@todo Store Useragent elsewhere?
  192.         *@version 0.1
  193.         */
  194.         function connect(){
  195.             global $running;
  196.             $this->send("dAmnClient 0.2\nagent=Dante\n".chr(0), true);
  197.             $this->connected = true;
  198.             $running = true;
  199.         }
  200.        
  201.         /*
  202.         16:54:29 <ManjyomeThunder> i got a wii
  203.         16:55:02 <SubjectX52873M> Great, I have a penis too :)
  204.         16:55:09 <bentomlin> :rofl:
  205.         16:55:15 <ManjyomeThunder> wtf
  206.         16:55:29 <SubjectX52873M> Are you going to go play with your wii now?
  207.         */
  208.         //Wii is pronouced "Wee" :)
  209.         //All three in the above are guys too so it was funny.
  210.        
  211.         /**
  212.         * Login to server and send the username and token
  213.         *@author electricnet
  214.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  215.         *@origin Tarbot 0.2e
  216.         *@modlevel light
  217.         *@version 0.1
  218.         */
  219.         function login(){
  220.             global $config;
  221.             if($this->connected){
  222.                 $this->send(
  223.                     "login " . $config['bot']['username'] .
  224.                     "\npk=" . $config['bot']['token'] .
  225.                     "\n" . chr(0), true);
  226.                 $this->loggedIn = true;
  227.             }
  228.         }
  229.         /**
  230.         * Send stuff to the server.
  231.         *
  232.         * It's sent raw, you need to add chr(0) to the end of any data you send using this function.
  233.         *@author electricnet
  234.         *@origin Tarbot 0.2e
  235.         *@modlevel not modified
  236.         *@version 0.4
  237.         */
  238.         function send($data, $boic = false){
  239.             global $socket, $debug;
  240.            
  241.             $this->checkQueues();
  242.             if($debug){
  243.                 echo "** OUTGOING -> " . time() . " **\n";
  244.                 var_dump($data); //electricnet: DEBUG
  245.             }
  246.             if (!$this->SocketAbort) {
  247.                 if ($debug) {
  248.                     socket_send($socket, $data, strlen($data), 0x0);
  249.                 } else {
  250.                     @socket_send($socket, $data, strlen($data), 0x0);
  251.                 }
  252.                 if (socket_last_error($socket)){
  253.                    
  254.                     /*intmsg("Error");
  255.                     $this->SocketAbort=True;
  256.                     $this->connected=false;*/
  257.                     socket_clear_error($socket);
  258.                 }
  259.                
  260.             }
  261.             $this->checkQueues($boic);
  262.         }
  263.        
  264.         /**
  265.         *Autojoin Rooms.
  266.         *@origin Dante 0.4
  267.         *@version 0.4
  268.         */
  269.         function autoJoin() {
  270.             global $config;
  271.             foreach($config['bot']['rooms'] as $room){
  272.                 $this->joinRoom($room);
  273.             }
  274.         }
  275.         /**
  276.         * Gets data from the socket and returns it
  277.         *@author electricnet
  278.         *@return string
  279.         *@origin Tarbot 0.2e
  280.         *@modlevel not modified
  281.         *@version 0.4
  282.         */     
  283.         function listen(){
  284.             global $socket;
  285.             $response = "";
  286.             if ($debug) {
  287.                 //Don't supress errors.
  288.                 if(0 === socket_recv($socket, $response, 8192, 0)){ $this->connected = false; }
  289.             } elseif (!$this->SocketAbort) {
  290.                 //Supress errors from the socket.
  291.                 if(0 === @socket_recv($socket, $response, 8192, 0)){ $this->connected = false; }
  292.             }
  293.             return $response;
  294.            
  295.         }
  296.  
  297.         /**
  298.         * PONG!
  299.         *
  300.         * Sends data out to check if the bot is still connected
  301.         *
  302.         * Modified in Version 0.4 to allow the main loop to use with out halting the bot.
  303.         *
  304.         * Used to repond to a ping from the dAmnserver
  305.         *@author electricnet
  306.         *@origin Tarbot 0.2e
  307.         *@modlevel light
  308.         *@version 0.6
  309.         */
  310.         function pingpong(){
  311.             $this->send("pong\n" . chr(0));
  312.         }
  313.        
  314.         /**
  315.         *Sends an invalid msg main packet to the server to check for a connection
  316.         *
  317.         *This should not be called too often. :)
  318.         *
  319.         *Defaults to not block on incoming.
  320.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  321.         *@origin Dante 0.4
  322.         *@version 0.4
  323.         */
  324.         function pingpong2(){
  325.             $this->send("send chat:!err_plz!\n\nmsg main\n\nBAD FOO" . chr(0));
  326.         }
  327.         /**
  328.         * Send a message to a the chatroom
  329.         *
  330.         * Now accpets /np for nonparsed messages
  331.         *@author electricnet
  332.         *@origin Tarbot 0.2e
  333.         *@modlevel light
  334.         *@version 0.5
  335.         */
  336.         function say($message, $chatroom){
  337.             $chatroom = generateChatName($chatroom);
  338.             if(substr($message, 0, 4) == "/me "){
  339.                 $this->me(substr($message, 4), $chatroom);
  340.             } elseif(substr($message, 0, 4) == "/np "){
  341.                 $this->npmsg(substr($message, 4), $chatroom);
  342.             } else {
  343.                 $this->send("send " . $chatroom . "\n\nmsg main\n\n" . $message . chr(0), true);
  344.             }
  345.         }
  346.        
  347.         /**
  348.         * Send a nonparsed message to a chatroom
  349.         *
  350.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  351.         *@origin Dante 0.3
  352.         *@version 0.3
  353.         */
  354.         function npmsg($message, $chatroom){
  355.             $chatroom = generateChatName($chatroom);
  356.             $this->send("send " . $chatroom . "\n\nnpmsg main\n\n" . $message . chr(0), true);
  357.         }
  358.         /**
  359.         * Send an action to a the chatroom
  360.         *@author electricnet
  361.         *@origin Tarbot 0.2e
  362.         *@modlevel not modified
  363.         *@version 0.1
  364.         */
  365.         function me($message, $chatroom){
  366.             $chatroom = generateChatName($chatroom);
  367.             $this->send("send " . $chatroom . "\n\naction main\n\n" . $message . chr(0), true);
  368.         }
  369.         /**
  370.         * Join a chatroom
  371.         *@author electricnet
  372.         *@return bool True for success in joining, False for failure.
  373.         *@origin Tarbot 0.2e
  374.         *@modlevel not modified
  375.         *@version 0.1
  376.         */
  377.         function joinRoom($chatroom){
  378.             if(!empty($chatroom)){
  379.                 $chatroom = generateChatName($chatroom);
  380.                 $this->send("join " . $chatroom . "\n" . chr(0), true);
  381.                 return true;
  382.             } else {
  383.                 return false;
  384.             }
  385.         }
  386.         /**
  387.         * Leave a chatroom
  388.         *@author electricnet
  389.         *@return bool True for success in leave, False for failure.
  390.         *@origin Tarbot 0.2e
  391.         *@modlevel not modified
  392.         *@version 0.1
  393.         */
  394.         function partRoom($chatroom){
  395.             if(!empty($chatroom)){
  396.                 $chatroom = generateChatName($chatroom);
  397.                 $this->send("part " . $chatroom . "\n" . chr(0), true);
  398.                 return true;
  399.             } else {
  400.                 return false;
  401.             }
  402.         }
  403.         /**
  404.         * Get a property
  405.         *
  406.         * This does not return a value. It sends a request for data to the server and dAmn:process catches it later.
  407.         *@author electricnet
  408.         *@origin Tarbot 0.2e
  409.         *@modlevel not modified
  410.         *@version 0.1
  411.         */
  412.         function get($property, $chatroom){
  413.             $chatroom = generateChatName($chatroom);
  414.             if ($chatroom ==false) { return; }
  415.             $this->send("get " . $chatroom . "\np=" . $property . "\n" . chr(0));
  416.         }
  417.        
  418.         /**
  419.         * /whois a user
  420.         *
  421.         * This does not return a value. It sends a request for data to the server and dAmn:process catches it later.
  422.         *@author electricnet
  423.         *@origin Tarbot 0.2e
  424.         *@modlevel light
  425.         *@version 0.4
  426.         */
  427.         function getUserInfo($username){
  428.             if (!empty($username)) {
  429.             $this->send("get login:" . $username . "\np=info\n" . chr(0));
  430.             }
  431.         }
  432.        
  433.         /**
  434.         * Kick a user from a chatroom
  435.         *@author electricnet
  436.         *@origin Tarbot 0.2e
  437.         *@modlevel light
  438.         *@version 0.4
  439.         */
  440.         function kick($username, $chatroom, $reason = ""){
  441.             $chatroom = generateChatName($chatroom);
  442.             if ($chatroom ==false) { return; }
  443.             $this->send("kick " . $chatroom . "\nu=" . $username . "\n\n" . $reason . chr(0));
  444.         }
  445.        
  446.         /**
  447.         * Promote a user.
  448.         *@author electricnet
  449.         *@origin Tarbot 0.2e
  450.         *@modlevel light
  451.         *@version 0.4
  452.         */
  453.         function promote($username, $privclass, $chatroom){
  454.             $chatroom = generateChatName($chatroom);
  455.             if ($chatroom ==false) { return; }
  456.             $this->send("send " . $chatroom . "\n\npromote " . $username . "\n\n" . $privclass . chr(0));
  457.         }
  458.         /**
  459.         * Demote a user.
  460.         *@author electricnet
  461.         *@origin Tarbot 0.2e
  462.         *@modlevel light
  463.         *@version 0.4
  464.         */
  465.         function demote($username, $privclass, $chatroom){
  466.             $chatroom = generateChatName($chatroom);
  467.             if ($chatroom ==false) { return; }
  468.             $this->send("send " . $chatroom . "\n\ndemote " . $username . "\n\n" . $privclass . chr(0));
  469.         }
  470.         /**
  471.         * Ban a user.
  472.         *
  473.         * Equiv to !demote (user) banned
  474.         *@author electricnet
  475.         *@origin Tarbot 0.2e
  476.         *@modlevel light
  477.         *@version 0.4
  478.         */
  479.         function ban($username, $chatroom){
  480.             $chatroom = generateChatName($chatroom);
  481.             if ($chatroom ==false) { return; }
  482.             $this->send("send " . $chatroom . "\n\nban " . $username . "\n\n" . chr(0));
  483.         }
  484.         /**
  485.         * Unban a user.
  486.         *
  487.         *This promotes/demotes a user to the default guest level
  488.         *@author electricnet
  489.         *@origin Tarbot 0.2e
  490.         *@modlevel light
  491.         *@version 0.4
  492.         */
  493.         function unban($username, $chatroom){
  494.             $chatroom = generateChatName($chatroom);
  495.             if ($chatroom ==false) { return; }
  496.             $this->send("send " . $chatroom . "\n\nunban " . $username . "\n\n" . chr(0));
  497.         }
  498.        
  499.         /**
  500.         * Set a property
  501.         *
  502.         * Only Topic/Title works right now.
  503.         *@author electricnet
  504.         *@return bool True for success in leave, False for failure.
  505.         *@origin Tarbot 0.2e
  506.         *@modlevel light
  507.         *@version 0.4
  508.         */
  509.         function set($property, $value, $chatroom){
  510.             $chatroom = generateChatName($chatroom);
  511.             if ($chatroom ==false) { return; }
  512.             if($property == "title" || $property == "topic"){
  513.                 $this->send("set " . $chatroom . "\np=" . $property . "\n\n" . $value . chr(0));
  514.                 return true;
  515.             } else {
  516.                 return false;
  517.             }
  518.         }
  519.         /**
  520.         * Admin
  521.         *
  522.         *See the dAmn FAQ for /admin uage
  523.         *@author electricnet
  524.         *@origin Tarbot 0.2e
  525.         *@modlevel light
  526.         *@version 0.4
  527.         */
  528.         function admin($command, $chatroom){
  529.             $chatroom = generateChatName($chatroom);
  530.             if ($chatroom ==false) { return; }
  531.             $this->send("send " . $chatroom . "\n\nadmin\n\n" . $command . chr(0));
  532.         }
  533.        
  534.         /**
  535.         *Check Socket for Data
  536.         *
  537.         *Checks for data from the socket and sends the info where it needs to go.
  538.         *@author electricnet
  539.         *@origin Tarbot 0.2e
  540.         *@modlevel light
  541.         *@version 0.5
  542.         */
  543.         function checkQueues($boic = false){
  544.             global $socket, $debug, $data;
  545.             if(socket_select($r = array($socket), $w = NULL, $e = NULL, 0) > 0){
  546.                 if (in_array($socket, $r)) {
  547.                     $data .= $this->listen();
  548.                     if ($this->SocketAbort==True) {
  549.                         $this->connected=false;
  550.                         return;
  551.                     } else {
  552.                         $datas = explode(chr(0), $data);
  553.                         $data = $datas[count($datas) - 1];
  554.                         unset($datas[count($datas) - 1]);
  555.                         if($debug){
  556.                             echo "** INCOMING <- " . time() . "**\n";
  557.                             var_dump($datas);
  558.                         }
  559.                         foreach($datas as $recievedData){
  560.                             if($debug){ echo "(" . strlen($recievedData) . ")\n"; }
  561.                             $this->process($recievedData);
  562.                         }
  563.                         $this->lastAccess = microtime(true);
  564.                     }
  565.                 } else {
  566.                     if (microtime(true)-$this->lastAccess < 100) {
  567.                         $this->connected=false;
  568.                         $lastAccess->lastAccess = microtime(true);
  569.                         echo "\nSOCKET TIMEOUT\n";
  570.                     }
  571.                 }//*/
  572.             }
  573.         }
  574.        
  575.         /**
  576.         *Checks bot.ini for proper settings
  577.         *
  578.         *Builds a copy if one is not found.
  579.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  580.         *@origin Dante 0.4b
  581.         *@version 0.5
  582.         */
  583.         function checkINI() {
  584.             global $config;
  585.             include f("config.php");
  586.             $die=false;
  587.             if (empty($login['username'])) {
  588.                 intmsg('FATAL: No username in Config.php');
  589.                 $die=true;
  590.             }
  591.             if (empty($login['owner'])) {
  592.                 intmsg('FATAL: No owner in Config.php');
  593.                 $die=true;
  594.             }
  595.             if (empty($login['password'])) {
  596.                 intmsg('FATAL: No password in Config.php');
  597.                 $die=true;
  598.             }
  599.             if (empty($login['trigger'])) {
  600.                 intmsg('FATAL: No trigger in Config.php');
  601.                 $die=true;
  602.             }
  603.             if ($die) {die();}
  604.            
  605.             if ($config['bot']['EraseConfigNextRun']!=='no') {
  606.                 //Build the config.
  607.                 intmsg('Config does not exist, building.');
  608.  
  609.                 $config['bot']=array(
  610.                     'username'=>$login['username'],
  611.                     'trigger'=>$login['trigger'],
  612.                     'owner'=>$login['owner'],
  613.                     'token' => '',
  614.                     'about' => ':mechabug:Dante {version} owned by: {owner} and running on: {os} <br />'.
  615.                         'Link: <a href="http://botdom.24bps.com/wiki/Dante">Project Page</a> | See {trig}credits for credits.',
  616.                     'AutoRejoinWhenKicked' => true,
  617.                     'timestamp' => 'H:i:s',
  618.                     'timestamp_log' => 'M jS, Y / H:i:s',
  619.                     'BadCommandMsg' => '',
  620.                     'RestrictedCommandMsg' => '',
  621.                     'thumbMode'=>false,
  622.                     'logChats'=>true,
  623.                     'rooms' => array('#Botdom','#LabX52'),
  624.                     'EraseConfigNextRun'=>'no',
  625.                 );
  626.                 $config['ignore']=array();
  627.                 $config['users']=array();
  628.                 $config['access']=array(
  629.                     'priv'=>array(),
  630.                     'default'=>array(
  631.                         'guests'=>0,
  632.                         'commands'=>0,
  633.                         'errors'=>0,
  634.                         'trigcheck'=>0,
  635.                     ),
  636.                 ); //Clear out access
  637.                 save_config(false,true); //Save all ini files and force it to save.
  638.                 intmsg('Config has been created.');
  639.                 intmsg('Your bot can be found in #Botdom when it finishes loading.');
  640.                 sleep(5);
  641.             } else {
  642.                 //Check config.
  643.                 $error=false;
  644.                 if ($config['bot']['username']!==$login['username']) {
  645.                     intmsg('Notice: Username in config.php does not match name in bot.ini Fixing');
  646.                     $config['bot']['username']=$login['username'];
  647.                     //If there is a new user you need a new token
  648.                     $config['bot']['token']='';
  649.                     $error=true;
  650.                 }
  651.                 if ($config['bot']['owner']!==$login['owner']) {
  652.                     $config['bot']['owner']=$login['owner'];
  653.                     intmsg('Notice: Owner in config.php does not match name in bot.ini Leaving Alone');
  654.                     $error=false;
  655.                 }
  656.                 if ($config['bot']['trigger']!==$login['trigger']) {
  657.                     intmsg('Notice: Trigger in config.php does not match name in bot.ini Leaving Alone');
  658.                     $error=false;
  659.                 }
  660.                 if (!isset($config['access']['default']['guests'])) {
  661.                     $config['access']['default']['guests']=0;
  662.                     intmsg('Notice: Missing guest priv default... Setting to 0');
  663.                     $error=true;
  664.                 }
  665.                 if (!isset($config['access']['default']['errors'])){
  666.                     $config['access']['default']['errors']=0;
  667.                     intmsg('Notice: Missing error priv default... Setting to 0');
  668.                     $error=true;
  669.                 }
  670.                 if (!isset($config['access']['default']['commands'])){
  671.                     $config['access']['default']['commands']=0;
  672.                     intmsg('Notice: Missing commands priv default... Setting to 0');
  673.                     $error=true;
  674.                 }
  675.                 if ($error) {
  676.                     save_config('bot');
  677.                     save_config('access');
  678.                 }
  679.             }
  680.         }
  681.        
  682.         /**
  683.         *Get Token
  684.         *
  685.         *This function logs the bot into it's account and steals the cookie from the server. The cookie contains an Md5 hash, called an AuthToken. The dAmn server (chat.deviantart.com:3900) uses the AuthTokens for login not passwords. So the bot needs to grab the Authtoken before logging into the chat server.
  686.         *
  687.         *This function now sets up the bot's config file for the first time.
  688.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  689.         *@author electricnet
  690.         *@origin Tarbot 0.2e
  691.         *@modlevel Light
  692.         *@version 0.4
  693.         */
  694.         function getAuthToken(){
  695.             internalMessage("Getting authtoken...");
  696.             global $event,$config;
  697.             include f("config.php"); //This loads the $login
  698.  
  699.             $query = "username=" . $login['username'] . "&password=" . $login['password'] . "&reusetoken=1" . chr(0);
  700.             $data = "POST /users/login HTTP/1.1\n" .
  701.                     "Host: www.deviantart.com\n" .
  702.                     "User-Agent: " . BotUserAgent . "\n" .
  703.                     "Accept: text/html\n" .
  704.                     "Cookie: skipintro=1\n" .
  705.                     "Content-Type: application/x-www-form-urlencoded\n" .
  706.                     "Content-Length: " . strlen($query) . "\n\n" . $query;
  707.                
  708.             $a = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp"));
  709.             @socket_connect($a, "www.deviantart.com", 80);
  710.             @socket_send($a, $data, strlen($data), 0x0);
  711.             $response = @socket_read($a, 8192);
  712.             if (socket_last_error($a)){
  713.                     internalMessage("WARNING Can't open socket for login. Check your internet connection.");
  714.                     die();
  715.                     return;
  716.                 }
  717.             @socket_clear_error($a);
  718.             @socket_close($a);
  719.        
  720.             if(!empty($response)){
  721.                 $response = urldecode($response);
  722.                 if(stristr($response, "Set-Cookie: ") && stristr($response, "authtoken")){
  723.                     $bits = explode("userinfo=", $response);
  724.                     $cookie = substr($bits[1], 0, strpos($bits[1],"; expir"));
  725.                     $cookie = unserialize($cookie);
  726.                     if(!empty($cookie['authtoken'])){
  727.                         internalMessage("Got it!");
  728.                         unset($login); //Remove $login to prevent modules from grabbing the password.
  729.                         internalMessage("Authtoken: " . $cookie['authtoken']);
  730.                         //Need a authtoken event
  731.                         $event="authtoken";
  732.                         include f("system/callables/event.php");
  733.                         return $cookie['authtoken'];
  734.                     } else {
  735.                         internalMessage("Oops, couldn't get the authtoken. You may need to find it yourself.");
  736.                         $event="authtoken-fail";
  737.                         include f("system/callables/event.php");
  738.                         return false;
  739.                     }
  740.                 } else {
  741.                     internalMessage("Oops, couldn't get the authtoken. You may need to find it yourself.");
  742.                     $event="authtoken-fail";
  743.                     include f("system/callables/event.php");
  744.                     return false;
  745.                 }
  746.             } else {
  747.                 unset($login);
  748.                 internalMessage("Oops, couldn't get the authtoken. You may need to find it yourself.");
  749.                 $event="authtoken-fail";
  750.                 include f("system/callables/event.php");
  751.                 return false;
  752.             }
  753.         }
  754.        
  755.     /*
  756.     *Timeout
  757.     *@author SubjectX52873M <SubjectX52873M@gmail.com>
  758.     *@origin Dante 0.2
  759.     *@version 0.5
  760.     */
  761.     function timeout(){
  762.         global $packetping;
  763.         if (!isset($packetping)) {$packetping=microtime(true);}
  764.         $ping=microtime(true)-$packetping;
  765.         if ($ping > 100) {
  766.             intmsg("Timeout detected\n");
  767.             $this->connected=false;
  768.         }
  769.     }
  770.     /**
  771.     *Parse Tablumps
  772.     *
  773.     *Html tags and emoticons are incased in tab characters. This function makes messages more human readable and easier to program for.
  774.     *
  775.     *Swapped out the tarbot version of this for the noodlbot version. This one prints out prettier.
  776.     *@author doofsmack?
  777.     *@origin Noodlebot 3.0
  778.     *@modlevel not modified
  779.     *@version 0.1
  780.     */
  781.     function parseTablumps($text)
  782.     {
  783.         $search[]="/&emote\t([^\t])\t([0-9]+)\t([0-9]+)\t(.+)\t(.+)\t/U";
  784.         $replace[]=":\\1:";
  785.         $search[]="/&emote\t(.+)\t([0-9]+)\t([0-9]+)\t(.+)\t(.+)\t/U";
  786.         $replace[]="\\1";
  787.         $search[]="/&br\t/";
  788.         $replace[]="\n\t";
  789.         $search[]="/&(b|i|s|u|sub|sup|code|ul|ol|li|p|bcode)\t/";
  790.         $replace[]="<\\1>";
  791.         $search[]="/&\\/(b|i|s|u|sub|sup|code|ul|ol|li|p|bcode)\t/";
  792.         $replace[]="</\\1>";
  793.         $search[]="/&acro\t(.*)\t(.*)&\\/acro\t/U";
  794.         $replace[]="<acronym title=\"\\1\">\\2</acronym>";
  795.         $search[]="/&abbr\t(.*)\t(.*)&\\/abbr\t/U";
  796.         $replace[]="<abbr title=\"\\1\">\\2</abbr>";
  797.         $search[]="/&link\t([^\t]*)\t([^\t]*)\t&\t/U"; //noodleman: this one must be first.. otherwise the next one gets greedy and grabs the tab and name as part of the url.
  798.         $replace[]="\\1 (\\2)";
  799.         $search[]="/&link\t([^\t]*)\t&\t/U";
  800.         $replace[]="\\1";
  801.         $search[]="/&a\t(.*)\t(.*)\t(.*)&\\/a\t/U";
  802.         $replace[]="<a href=\"\\1\" title=\"\\2\">\\3</a>";
  803.         $search[]="/&(iframe|embed)\t(.*)\t([0-9]*)\t([0-9]*)\t&\\/(iframe|embed)\t/U";
  804.         $replace[]="<\\1 src=\"\\2\" width=\"\\3\" height=\"\\4\" />";
  805.         $search[]="/&img\t(.*)\t([0-9]*)\t([0-9]*)\t/U";
  806.         $replace[]="<img src=\"\\1\" width=\"\\2\" height=\"\\3\" />";
  807.         $search[]="/&thumb\t([0-9]*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t/U";
  808.         $replace[]=":thumb\\1:";
  809.         $search[]="/&dev\t([^\t])\t([^\t]+)\t/U";
  810.         $replace[]=":dev\\2:";
  811.         $search[]="/&avatar\t([^\t]+)\t[01]\t/U";
  812.         $replace[]=":icon\\1:";
  813.         $search[]="/ width=\"\"/";
  814.         $replace[]="";
  815.         $search[]="/ height=\"\"/";
  816.         $replace[]="";
  817.         $oldtext='';
  818.         while($text!=$oldtext)
  819.         {
  820.             $oldtext=$text;
  821.             $text=preg_replace($search, $replace, $text);
  822.         }
  823.         return($text);
  824.     }
  825.    
  826.     function getdays_month($month){
  827.         if(!is_numeric($month)) $month=getnum_month($month);
  828.         if(date("L")) $feb=29;
  829.         else $feb=28;
  830.         $days=array(
  831.           '1'=>31,
  832.           '2'=>$feb,
  833.           '3'=>31,
  834.           '4'=>30,
  835.           '5'=>31,
  836.           '6'=>30,
  837.           '7'=>31,
  838.           '8'=>31,
  839.           '9'=>30,
  840.           '10'=>31,
  841.           '11'=>30,
  842.           '12'=>31
  843.         );
  844.         return $days[$month];
  845.     }
  846.    
  847.     /**
  848.     *parseWhoisTS
  849.     *@author Noodleman?
  850.     *@origin Noodlebot 3.0
  851.     *@modlevel not modified
  852.     *@version 0.5
  853.     */
  854.     function parseWhoisTS($d, $words=true){
  855.         $o=array();
  856.         $o['year']=floor($d/31536000);
  857.         $d-=$o['year']*31536000;
  858.         $o['month']=0;
  859.         for($m=0; $m<12; $m++)
  860.         {
  861.             $days=$this->getdays_month($m+1)*86400;
  862.             if($d>=$days && $d>0)
  863.             {
  864.                 $d-=$days;
  865.                 $o['month']++;
  866.             } else break;
  867.         }
  868.         $o['week']=floor($d/604800);
  869.         $d-=$o['week']*604800;
  870.         $o['day']=floor($d/86400);
  871.         $d-=$o['day']*86400;
  872.         $o['hour']=floor($d/3600);
  873.         $d-=$o['hour']*3600;
  874.         $o['minute']=floor($d/60);
  875.         $d-=$o['minute']*60;
  876.         $o['second']=$d;
  877.    
  878.         $s="";
  879.         foreach($o as $t => $v)
  880.             if($v)
  881.             {
  882.                 $s.=$v;
  883.                 if($words)
  884.                 {
  885.                     $s.=' '.$t;
  886.                     if($v!==1 && $v!=='1') $s.='s';
  887.                 }
  888.                 $s.=' ';
  889.             }
  890.         if($s=="") $s="<1 second";
  891.         return $s;
  892.     }
  893.     /*X52 Well this is the best place to put it.
  894.     Room info is stored like this
  895.     $rooms = array(
  896.         $chatroom=> array(
  897.             joined (boolean),
  898.             topic,title => array (
  899.                 value,
  900.                 by,
  901.                 time (Figure this out)
  902.                 )
  903.                
  904.             //NOTICE the members array does not store all users because the members packet is larger than 8kb the socket cuts it off before it finishes. See php.net docs for socket recv, read user comments and find a way to make this work.//
  905.            
  906.             members => member array (
  907.                 status = joined:parted:kicked:notset //notset is data from the prop-members event
  908.                 name = Nick //Crytopolonium
  909.                 pc = Privclass //Not reliable //Bots
  910.                 ico = 0:1 //1
  911.                 sym // ~
  912.                 symname (Need to make) // nonsubbed account
  913.                 realname ???? // w/ Chip
  914.                 typename ???? // dAmn addict
  915.             ), // Need to add stuff.
  916.             privclasses => pv,
  917.             )
  918.     */
  919.         /**
  920.         * Process Symbol
  921.         *
  922.         * This accepts the symbol that sit in front of a deviant's name and returns the type as a string.
  923.         *
  924.         * Example: dAmn::symproc('~') returns "Member" and dAmn::symproc('*') returns "Subscriber"
  925.         *
  926.         * Example: dAmn::symproc('~SubjectX52873M') returns 'Unknown Type (~SubjectX52873M)'
  927.         * @author SubjectX52873M <SubjectX52873M@gmail.com>
  928.         * @return string
  929.         * @version 0.6
  930.         */
  931.         function symproc($symbol='='){
  932.             if(empty($symbol)){ $symbol='=';}
  933.             $symbols=array(
  934.               '~' => 'Member',
  935.               '*' => 'Subscriber',
  936.               '=' => 'Official Beta Tester',
  937.               '`' => 'Former Staff or Senior Member',
  938.               '°' => 'Alumni Staff',
  939.               '#' => 'Art Group Member',
  940.               '@' => 'Shoutbox/dAmn Staff',
  941.               ':' => 'Premium Content Staff',
  942.               '©' => 'Policy Enforcement Staff',
  943.               '%' => 'deviantART Prints Staff',
  944.               '+' => 'General Staff',
  945.               '¢' => 'Creative Staff',
  946.               '^' => 'Gallery Director',
  947.               '$' => 'Core Administrator',
  948.               '!' => 'Banned User'
  949.             );
  950.             if(array_key_exists($symbol,$symbols)) {
  951.                 return $symbols[$symbol];
  952.             } else {
  953.                 return 'Unknown Type ('.$symbol.')';
  954.             }
  955.         }
  956.            
  957.         /**
  958.         *Parse Order
  959.         *
  960.         *Parses the order of a privclass update or creation.
  961.         *
  962.         *This pulls out the order=## from a privclass event
  963.         *
  964.         *Used in dAmn::process()
  965.         *@return mixed On success a string is returned, on failure false is returned.
  966.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  967.         *@version 0.1
  968.         */
  969.         function parseOrder($data) {
  970.             $da=explode("\n",$data);
  971.             $db=explode("=",$da);
  972.             if ($db[0]="order") {
  973.                 return $db[1];
  974.             } else {
  975.                 return false;
  976.             }
  977.         }
  978.        
  979.         /**
  980.         *Room parser
  981.         *
  982.         *Alias for downSortPChat
  983.         *@version 0.4
  984.         *@return string
  985.         */
  986.         function parseRoom($room) {
  987.             return downSortPChat($room);
  988.         }
  989.            
  990.         /**
  991.         *propRoom
  992.         *@version 0.5
  993.         *@return String
  994.         */
  995.         function propRoom($p) {
  996.             if(isset($p['property chat'])){
  997.                 return $this->parseRoom($p['property chat']);
  998.             } elseif (isset($p['property pchat'])) {
  999.                 return $this->parseRoom($p['property pchat']);
  1000.             }else {
  1001.                 return "(Unknown)";
  1002.             }
  1003.         }
  1004.         /**
  1005.         *Parse Datas
  1006.         *@return array
  1007.         *@version 0.2
  1008.         */
  1009.         function parseUserDatas($og) {
  1010.             $return=array();
  1011.             $o = explode("\n",$og);
  1012.             foreach($o as $i) {
  1013.                 $stuffs = explode("=",$i);
  1014.                 $return[$stuffs[0]]=$stuffs[1];
  1015.             }
  1016.             return $return;
  1017.         }
  1018.         /**
  1019.         *Process
  1020.         *
  1021.         *This breaks up the packets from the socket at routs the commands and calls modules to handle them.
  1022.         *@author electricnet
  1023.         *@author SubjectX52873M <SubjectX52873M@gmail.com>
  1024.         *@origin Tarbot 0.2e
  1025.         *@modlevel Medium
  1026.         *@version 0.5
  1027.         */
  1028.         /* sorry for those reading the source. I haven't cleaned up the comments on this function yet */
  1029.         function process($data){
  1030.             global $rooms, $config, $debug, $whoisroom, $latestwhois, $packetping;
  1031.            
  1032.             $rawdata=$data; //Raw data should be available to modules with this.
  1033.            
  1034.             //This is for the time based disconnection
  1035.             $packetping=microtime(true);
  1036.            
  1037.             $data = $this->parseTablumps($data);
  1038.             $datas = explode("\n", $data);
  1039.             $mainDatas = explode(" ", $datas[0]);
  1040.             $name = str_replace("\n", "", $mainDatas[0]);
  1041.             $param = $mainDatas[1];
  1042.             if($debug){
  1043.                 echo ts() . " ** PROCESS " . time() . " **\n";
  1044.                 var_dump($name);
  1045.                 var_dump($data);
  1046.             }
  1047.             switch($name){
  1048.                 case "dAmnServer":
  1049.                     internalMessage("Hello there, we got connected! :D");
  1050.                     internalMessage("You are running on dAmnServer " . $param);
  1051.                     $event = "handshake";
  1052.                     /**
  1053.                     * Check for a module to handle event
  1054.                     */
  1055.                     include f("system/callables/event.php");
  1056.                     break;
  1057.                 case "login":
  1058.                     $params = params($data);
  1059.                     if($debug){ var_dump($params); }
  1060.                     if($params['e'] == "ok"){
  1061.                         internalMessage("You are successfully logged in as " . $config['bot']['username'] . ".");
  1062.                         $this->UseToken=true;
  1063.                         if (isset($login)) {unset($login);}
  1064.                         $event = "login-success";
  1065.                         include f("system/callables/event.php");
  1066.                     } elseif($params['e'] == "authentication failed"){
  1067.                         if ($this->UseToken) {
  1068.                             $this->UseToken=false;
  1069.                             $this->reconSocket();
  1070.                             $this->connected=true;
  1071.                         } else {
  1072.                             internalMessage("Couldn't log in as " . $config['bot']['username'] . ", authentication failed. Please check that your username and/or password is right.");
  1073.                         }
  1074.                     } else {
  1075.                         internalMessage("An unexpected error happened logging in as " . $botdom['username'] . ". Error recieved: \"" . $params['e'] . "\"");
  1076.                     }
  1077.                     $event = "login";
  1078.                     include f("system/callables/event.php");
  1079.                     break;
  1080.                 case "ping":
  1081.                     //electricnet: Let's respond to the ping!
  1082.                     $this->pingpong();
  1083.                     $event = "ping";
  1084.                     include f("system/callables/event.php");
  1085.                     break;
  1086.                 case "join":
  1087.                     $chatroom=$this->parseRoom($param);
  1088.                     $params = params($data);
  1089.                     if($debug){ var_dump($params); }
  1090.                     if($params['e'] == "ok"){
  1091.                         $output = "Joined " . $chatroom . "!";
  1092.                         //internalMessage($output);
  1093.                         registerChat("** " . $output, $param, false);
  1094.                         //X52 open. Joined a room. Need to store
  1095.                         $rooms[degenerateChatName($chatroom)]['joined']=true;
  1096.                         //X52 close.
  1097.                         $c = $chatroom = $param;
  1098.                         //New Event, join-success
  1099.                         $event = "join-success";
  1100.                         include f("system/callables/event.php");
  1101.                         break;
  1102.                     } else {
  1103.                         internalMessage("Couldn't join " . $chatroom . ", got error: \"" . ucfirst($params['e']) . "\".");
  1104.                         //New Event, join-fail
  1105.                         $event = "join-fail";
  1106.                         include f("system/callables/event.php");
  1107.                     break;
  1108.                     }
  1109.                     $event = "join";
  1110.                     include f("system/callables/event.php");
  1111.                     break;
  1112.                 case "kicked":
  1113.                     $params = params($data);
  1114.                     $chatroom=$this->parseRoom($param);
  1115.                     $by = $params['by'];
  1116.                     $message = $params[0];
  1117.                     $output = "Kicked from " . $chatroom ." by ".$by.", reason: ".$message;
  1118.                     registerChat("** " . $output, $param, false);
  1119.                     $event = "kicked";
  1120.                     include f("system/callables/event.php");
  1121.                     break;
  1122.                 case "get": //electricnet: A whois was requested, but an error gets returned.
  1123.                     $params = params($data);
  1124.                     if($debug){ var_dump($params); }
  1125.                     if($params['e'] == "bad namespace"){
  1126.                         $message = "This user isn't currently on dAmn.";
  1127.                     } else {
  1128.                         $message = "An unexpected error happened to your whois query: \"" . $params['e'] . "\"";
  1129.                     }
  1130.                     if(!empty($whoisroom)){
  1131.                         $this->say($message, $whoisroom);
  1132.                     } else {
  1133.                         internalMessage("Didn't know where to echo userinfo!");
  1134.                     }
  1135.                     $event = "get";
  1136.                     include f("system/callables/event.php");
  1137.                     break;
  1138.                 case "part":
  1139.                     //Pchat:chat
  1140.                     $chatroom=$this->parseRoom($param);
  1141.                     $params = params($data);
  1142.                     if($debug){ var_dump($params); }
  1143.                     if($params['e'] == "ok"){
  1144.                         $output = "Parted " . $chatroom . ".";
  1145.                         //internalMessage($output);
  1146.                         registerChat("** " . $output, $param, false);
  1147.                         $c = $chatroom = $param;
  1148.                         //X52 open. Parted a room. Need to store
  1149.                         $rooms[degenerateChatName($chatroom)]['joined']=false; //X52 Notice this does not affect other room data
  1150.                         $event = "part-success";
  1151.                         include f("system/callables/event.php");
  1152.                         break;
  1153.                         //X52 close.
  1154.                     } else {
  1155.                         internalMessage("Couldn't part " . $chatroom . ", got error: \"" . ucfirst($params['e']) . "\".");
  1156.                         //How does a part fail unless you aren't in the room to begin with?
  1157.                         // Add new events
  1158.                         $event = "part-fail";
  1159.                         include f("system/callables/event.php");
  1160.                     }
  1161.                     $event = "part";
  1162.                     include f("system/callables/event.php");
  1163.                     break;
  1164.                 case "recv":
  1165.                     $params = array();
  1166.                     $paramblocks = explode("\n\n", $data);
  1167.                     foreach($paramblocks as $paramblock){
  1168.                         switch(count($params)){
  1169.                             case 0:
  1170.                                 $params[] = params($paramblock);
  1171.                                 break;
  1172.                             case 1:
  1173.                                 $params[] = params($paramblock, false);
  1174.                                 break;
  1175.                             case 2:
  1176.                                 $params[] = array($paramblock);
  1177.                                 break;
  1178.                         }
  1179.                     }
  1180.                     $action = explode(" ", $params[1][0]);
  1181.                     $c = $chatroom = $param;
  1182.                     switch($action[0]){
  1183.                         case "msg":
  1184.                             $message = trim($params[2][0]);
  1185.                             $output = "<" . $params[1]['from'] . "> " . $message;
  1186.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1187.                             if(!empty($output)){ registerChat($output, $param); }
  1188.                             processMessage($message, $params[1]['from'], $param, $action[0]);
  1189.                             $from = $params[1]['from'];
  1190.                             $event = "recv-msg";
  1191.                             include f("system/callables/event.php");
  1192.                             break;
  1193.                         case "action":
  1194.                             $message = trim($params[2][0]);
  1195.                             $output = "* " . $params[1]['from'] . " " . $message;
  1196.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1197.                             if(!empty($output)){ registerChat($output, $param); }
  1198.                             processMessage($message, $params[1]['from'], $param, $action[0]);
  1199.                             $from = $params[1]['from'];
  1200.                             $event = "recv-action";
  1201.                             include f("system/callables/event.php");
  1202.                             break;
  1203.                         case "join":
  1204.                             $output = "** " . $action[1] . " has joined";
  1205.                             $event = "recv-join";
  1206.                             $from = $action[1];
  1207.                             if ($debug) {
  1208.                                 intmsg('JOINED... DUMPING PARAMS');
  1209.                                 var_dump($params);
  1210.                             }
  1211.                            
  1212.                             //X52 open Set user as joined
  1213.                             $stuffs=$this->parseUserDatas($params[2][0]);
  1214.                             $rooms[degenerateChatName($c)]['members'][$from]= array(
  1215.                                 "name"=>$from,
  1216.                                 "status"=>"joined",
  1217.                                 "usericon"=>$stuffs['usericon'],
  1218.                                 "symbol"=>$stuffs['symbol'],
  1219.                                 "symbolname" => $this->symproc($stuffs['symbol']),
  1220.                                 "realname"=>$stuffs['realname'],
  1221.                                 "typename"=>$stuffs['typename'],
  1222.                                 "pc"=>$stuffs['pc'],
  1223.                                
  1224.                             );
  1225.                             //X52 close
  1226.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1227.                             if(!empty($output)){ registerChat($output, $param); }
  1228.                             include f("system/callables/event.php");
  1229.                             break;
  1230.                         case "part":
  1231.                             $output = "** " . $action[1] . " has left" . ((!empty($params[1]['r'])) ? " [" . $params[1]['r'] . "]" : "");
  1232.                             $event = "recv-part";
  1233.                             $from = $action[1];
  1234.                             //X52 open Set user as parted
  1235.                             $rooms[degenerateChatName($chatroom)]['members'][$from]["status"]="parted";
  1236.                             //X52 close
  1237.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1238.                             if(!empty($output)){ registerChat($output, $param); }
  1239.                             include f("system/callables/event.php");
  1240.                             break;
  1241.                         case "kicked":
  1242.                             $output = "** " . $action[1] . " was kicked by " . $params[1]['by'] . " * " . $params[2][0];
  1243.                             $event = "recv-kicked";
  1244.                             $from = $action[1];
  1245.                             $by = $params[1]['by'];
  1246.                             $message = $params[2][0];
  1247.                             //X52 open Set user as kicked
  1248.                             $rooms[degenerateChatName($chatroom)]['members'][$from]["status"]="kicked";
  1249.                             //X52 close
  1250.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1251.                             if(!empty($output)){ registerChat($output, $param); }
  1252.                             include f("system/callables/event.php");
  1253.                             break;
  1254.                         case "privchg":
  1255.                             //Need to set $rooms[degenerateChatName($chatroom)][$user]["privclass"]=$params[1]['pc'];
  1256.                             $output = "** " . $action[1] . " has been made a member of '" . $params[1]['pc'] . "' by " . $params[1]['by'] . " *";
  1257.                             $event = "recv-privchg";
  1258.                             $from = $action[1];
  1259.                             $by = $params[1]['by'];
  1260.                             //X52 open Set user's privclass
  1261.                             //X52 Add $members global later.
  1262.                             $rooms[degenerateChatName($chatroom)][$from]["privclass"]=$params[1]['pc'];
  1263.                             //X52 close
  1264.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1265.                             if(!empty($output)){ registerChat($output, $param); }
  1266.                             include f("system/callables/event.php");
  1267.                             break;
  1268.                         case "admin":
  1269.                             switch($action[1]){
  1270.                                 case "create":
  1271.                                     if($params[1]['p'] == "privclass"){
  1272.                         /*X52 Need to set ... and need to parse out the changes
  1273.                             $rooms[degenerateChatName($chatroom)]["privclasses"][##]=level and
  1274.                             $rooms[degenerateChatName($chatroom)]["privclasses"][level]=##
  1275.                         */
  1276.                                         $output = "** Privilege class '" . $params[1]['name'] . "' has been created by " . $params[1]['by'] . " with: " . $params[1]['privs'];
  1277.                                        
  1278.                                         if ($this->parseOrder($params[1]['privs'])==false) {
  1279.                                             $output = $output.' error registering pc with bot';
  1280.                                         } else {
  1281.                                             $num=$this->parseOrder($params[1]['privs']);
  1282.                                             $rooms[degenerateChatName($chatroom)]["privclasses"][$num]=$params[1]['name'];
  1283.                                             $rooms[degenerateChatName($chatroom)]["privclasses"][$params[1]['name']]=$num;
  1284.                                         }
  1285.                                        
  1286.                                         //X52 need to parse out the priv level
  1287.                                     }
  1288.                                     break;
  1289.                                 case "update":
  1290.                                 /*X52 Need to set
  1291.                                     $rooms[degenerateChatName($chatroom)]["privclasses"][##]=level and
  1292.                                     $rooms[degenerateChatName($chatroom)]["privclasses"][level]=##
  1293.                                     Need to parse the privs to do this. :|
  1294.                                 */
  1295.                                     if($params[1]['p'] == "privclass"){
  1296.                                         $output = "** Privilege class '" . $params[1]['name'] . "' has been updated by " . $params[1]['by'] . " with: " . $params[1]['privs'];
  1297.                                     }
  1298.                                     if ($this->parseOrder($params[1]['privs'])==false) {
  1299.                                             $output = $output.' error registering pc with bot';
  1300.                                         } else {
  1301.                                             $target_level=$rooms[degenerateChatName($chatroom)]["privclasses"][$params[1]['name']];
  1302.                                             unset($rooms[degenerateChatName($chatroom)]["privclasses"][$target_level]);
  1303.                                             $num=$this->parseOrder($params[1]['privs']);
  1304.                                             $rooms[degenerateChatName($chatroom)]["privclasses"][$num]=$params[1]['name'];
  1305.                                             $rooms[degenerateChatName($chatroom)]["privclasses"][$params[1]['name']]=$num;
  1306.                                         }
  1307.                                     break;
  1308.                                 case "rename":
  1309.                                     if($params[1]['p'] == "privclass"){
  1310.                                         $output = "** Privilege class '" . $params[1]['prev'] . "' has been renamed to '" . $params[1]['name'] . "' by " . $params[1]['by'] . " *";
  1311.                                         //X52 open Set new privclass
  1312.                                         $prev_room=$params[1]['prev'];
  1313.                                         $target_name=$params[1]['name'];
  1314.                                         $target_priv=$rooms[degenerateChatName($chatroom)]["privclasses"][$prev_room];
  1315.                                         unset($rooms[degenerateChatName($chatroom)]["privclasses"][$prev_room]);
  1316.                                         $rooms[degenerateChatName($chatroom)]["privclasses"][$target_priv]=$target_name;
  1317.                                         $rooms[degenerateChatName($chatroom)]["privclasses"][$target_name]=$target_priv;
  1318.                                         //X52 close
  1319.                                     }
  1320.                                     break;
  1321.                                 case "move":
  1322.                                     //X52 Maybe do this? Much Later
  1323.                                     if($params[1]['p'] == "users"){
  1324.                                         $output = "** All members of '" . $params[1]['prev'] . "' has been moved to '" . $params[1]['name'] . "' by " . $params[1]['by'] . " -- " . $params[1]['n'] . " members were affected.";
  1325.                                     }
  1326.                                     break;
  1327.                                 case "remove":
  1328.                                     /*
  1329.                                     Me: "I don't know if I can pull 5 pages out of that"
  1330.                                     Amanda: "I'm going 5 out of my ass. I need that extra credit."
  1331.                                     */
  1332.                                     if($params[1]['p'] == "privclass"){
  1333.                                         $output = "** Privilege class '" . $params[1]['name'] . "' has been removed by " . $params[1]['by'] . " -- " . $params[1]['n'] . " members were affected.";
  1334.                                         //X52 open delete privclass and create the new one.
  1335.                                         //X52 will need code to mod $members (Create new global to store stuff.)
  1336.                                         $target_class=$params[1]['name'];
  1337.                                         $target_num=$rooms[degenerateChatName($chatroom)]["privclasses"][$target_class];
  1338.                                         unset($rooms[degenerateChatName($chatroom)]["privclasses"][$target_class]);
  1339.                                         unset($rooms[degenerateChatName($chatroom)]["privclasses"][$target_num]);
  1340.                                         //X52 close
  1341.                                     }
  1342.                                     break;
  1343.                             }
  1344.                             $output = "[" . $this->parseRoom($param) . "] " . $output;
  1345.                             if(!empty($output)){ registerChat($output, $param); }
  1346.                             $event = "recv-admin";
  1347.                             include f("system/callables/event.php");
  1348.                             break;
  1349.                     }
  1350.                     break;
  1351.                 case "property":
  1352.                     if($debug){ echo "****** -> PROPERTY\n"; }
  1353.                     $params = array();
  1354.                     $paramblocks = explode("\n\n", $data);
  1355.                     foreach($paramblocks as $paramblock){
  1356.                         if(empty($params)){
  1357.                             $params[] = params($paramblock);
  1358.                             $proptype = $params[0]['p'];
  1359.                         } else {
  1360.                             switch($proptype){
  1361.                                 case "topic":
  1362.                                 case "title":
  1363.                                     $params[] = $paramblock;
  1364.                                     break;
  1365.                                 default:
  1366.                                     $params[] = params($paramblock, false);
  1367.                                     break;
  1368.                             }
  1369.                         }
  1370.                     }
  1371.                     if($debug){
  1372.                         echo "PROPTYPE = " . $proptype . "\n";
  1373.                         echo "PARAMS = ";
  1374.                         var_dump($params);
  1375.                         echo "\n";
  1376.                     }
  1377.                     if ($params[0]['property chat']) {$c = $chatroom =$params[0]['property chat'];}
  1378.                     else{$c = $chatroom =$params[0]['property pchat'];}
  1379.                     switch($proptype){
  1380.                         case "privclasses":
  1381.                             $privclasses = $params[1];
  1382.                             //X52 open Setup privclasses.
  1383.                              foreach($privclasses as $i => $o) {
  1384.                                 //$i = int($i);
  1385.                                 $rooms[degenerateChatName($chatroom)]['privclasses'][$i] = $o;
  1386.                                 $rooms[degenerateChatName($chatroom)]['privclasses'][$o] = $i;
  1387.                             }
  1388.                             //X52 close
  1389.                             //electricnet: A var_dump($privclasses); gives something like
  1390.                             /*  array(9) {
  1391.                                 [99]=>
  1392.                                 string(8) "Founders"
  1393.                                 [75]=>
  1394.                                 string(9) "Operators"
  1395.                                 [25]=>
  1396.                                 string(6) "Guests"
  1397.                                 [1]=>
  1398.                                 string(6) "Banned"
  1399.                               } */
  1400.                             //electricnet: NOTE_TO_DEV: Maybe post privclasses to the web here? At least do something with it.
  1401.                             //X52, better idea. Put all classes in the bot. Store a copy locally to save bandwidth.
  1402.                             internalMessage("Got privclasses for ".$this->propRoom($params[0]));
  1403.                             $event = "property-privclasses";
  1404.                             include f("system/callables/event.php");
  1405.                             break;
  1406.                         case "members":
  1407.                             // need to manually parse this one.
  1408.                             /*X52
  1409.                             property chat:${channel}\np=members\n\nmember ${nick}\npc=${privclass}\nusericon=${usericon}\nsymbol=${symbol}\nrealname=${realname}\ntypename=${typename}\n\n\0
  1410.                            
  1411.                             */
  1412.                             if(isset($rooms[degenerateChatName($chatroom)]["members"])){
  1413.                                 unset($rooms[degenerateChatName($chatroom)]["members"]);
  1414.                             }
  1415.                             //Interesting note. This is code from Dante 0.0 :) Pre-Tarbot core
  1416.                             //Start with data
  1417.                             //X52 Okay this blows up the list :)
  1418.                             //Talk to eletricnet and use $params instead >.<
  1419.                             //This code actually works... if the bot can grab the members packet
  1420.                             $temp=explode("\n\n",$data,2); //New in 0.4, better splitting.
  1421.                             $temp=explode("\n\n",$temp[1]);
  1422.                             $datar=array();
  1423.                             foreach($temp as $i => $xx) {
  1424.                                 if(!empty($xx)){
  1425.                                     $x=explode("\n",$xx,2);
  1426.                                     $member=$x[0];
  1427.                                     $infos=$x[1];
  1428.                                     $marray=$this->parseUserDatas($infos);
  1429.                                     $member=str_replace("member ","",$member);
  1430.                                     $datar[$member]=$marray;
  1431.                                     $datar[$member]['name']=$member;
  1432.                                     $datar[$member]['status']='notset';
  1433.                                     $datar[$member]['symbolname'] = $this->symproc($datar[$member]['symbol']);
  1434.                                 }
  1435.                             }
  1436.                             $rooms[degenerateChatName($chatroom)]["members"]=$datar;
  1437.                             internalMessage("Got members for ".$this->propRoom($params[0]));
  1438.                             $event = "property-members";
  1439.                             include f("system/callables/event.php");
  1440.                             break;
  1441.                         case "title":
  1442.                             $message = $params[1];
  1443.                             $by = $params[0]['by'];
  1444.                             $ts = $params[0]['ts'];
  1445.                             //X52 open Set rooms info
  1446.                             $rooms[dChatName($chatroom)]["title"]= array(
  1447.                                 "value" => $message,
  1448.                                 "by" => $by,
  1449.                                 "time" => $ts);
  1450.                             //X52 close
  1451.                             internalMessage("Got title for ".$this->propRoom($params[0]));
  1452.                             $event = "property-title";
  1453.                             include f("system/callables/event.php");
  1454.                             break;
  1455.                         case "topic":
  1456.                             //X52 $rooms[degenerateChatName($chatroom)]["topic"]
  1457.                             $message = $params[1];
  1458.                             $by = $params[0]['by'];
  1459.                             $ts = $params[0]['ts'];
  1460.                             //X52 open Set rooms info
  1461.                             $rooms[dChatName($chatroom)]["topic"]= array(
  1462.                                 "value" => $message,
  1463.                                 "by" => $by,
  1464.                                 "time" => $ts);
  1465.                             //X52 close
  1466.                             internalMessage("Got topic for ".$this->propRoom($params[0]));
  1467.                             $event = "property-topic";
  1468.                             include f("system/callables/event.php");
  1469.                             break;
  1470.                         case "info":
  1471.                             $message  = ":icon" . $params[0]['property login'] . ": <strong>:dev" . $params[0]['property login'] . ":</strong>";
  1472.                             $message .= "<ul><li>" . $params[1]['realname'] . "</li><li>" . $params[1]['typename'] . "</li>";
  1473.                             $message .= ($params[1]['gpc'] != "guest") ? "<li>dAmn " . $params[1]['gpc'] . "</li></ul>" : "</ul>";
  1474.                             $connNumber = 1;
  1475.                             foreach($params as $number => $thisParam){
  1476.                                 if($params > 1){
  1477.                                     if($params[$number][0] == "conn"){
  1478.                                         $message .= "<br /><em>Connection " . $connNumber . "</em>";
  1479.                                         $message .= "<br />&#9679; <strong>Online:</strong> " . date("D M j Y [H:m:s]", time() - $params[$number]['online']);
  1480.                                         $message .= "<br />&#9679; <strong>Idle:</strong> " . $this->parseWhoisTS($params[$number]['idle']);
  1481.                                         $message .= "<br />&#9679; <strong>Chatrooms:</strong>";
  1482.                                         $connNumber++;
  1483.                                     } elseif(!empty($params[$number]['ns chat'])){
  1484.                                         $message .= "&nbsp; #" . $params[$number]['ns chat'];
  1485.                                     }
  1486.                                 }
  1487.                             }
  1488.                            
  1489.                             $username = $params[0]['property login'];
  1490.                            
  1491.                             if(!empty($whoisroom)){
  1492.                                 $this->say($message, $whoisroom);
  1493.                                 $whoisroom = "";
  1494.                             }
  1495.                             $latestwhois[$username] = $params;
  1496.                             $latestwhois[$username]['t'] = time();
  1497.                             break;
  1498.                     }
  1499.                     break;
  1500.             }
  1501.         }
  1502.     }
  1503. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement