Guest User

Untitled

a guest
Jul 17th, 2018
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.55 KB | None | 0 0
  1. <?php
  2.     /*
  3.     * BOT TS
  4.     */
  5.     $chan = '#MixMeMore';
  6.     $chanRegex = '\#MixMeMore';
  7.     $passChan = 'MixBotSt4ff';
  8.     $serv = 'irc.quakenet.org';
  9.     $port = '6667';
  10.    
  11. /*****************************************************************/
  12. /************************* CONNEXION & JOIN **********************/
  13. /*****************************************************************/
  14.     set_time_limit(0);
  15.     $socket = fsockopen(''.$serv.'',''.$port.'');
  16.     if(!$socket) {
  17.         echo 'Impossible de se connecter au serveur '.$serv.' sur le port '.$port.'.';
  18.         exit;
  19.     }
  20.    
  21.     // USER & NICK
  22.     fputs($socket,"USER MixBot MixBot MixBot MixBot\r\n");
  23.     fputs($socket,"NICK MixBot\r\n");
  24.    
  25.     // Le PING PONG
  26.     $continuer = 1;
  27.     $i=0;
  28.     while($continuer) {
  29.         echo $i;
  30.         $donnees = fgets($socket, 1024);
  31.         $retour = explode(':',$donnees); // On sépare les différentes données.
  32.         if(rtrim($retour[0]) == 'PING') {
  33.             fputs($socket,'PONG :'.$retour[1]);
  34.             $continuer = 0;
  35.         }
  36.         if($donnees) // Si le serveur a envoyé des données, on les affiche.
  37.             echo ' <= incrementeur'.$donnees.'<br /><br />';
  38.         $i++;
  39.     }
  40.  
  41.     // Join canal
  42.     for($i=0;$i<20;$i++) {
  43.         $donnees = fgets($socket,1024);
  44.     }  
  45.     echo 'apres'.$i.' : '.$donnees.'<br /><br />';
  46.     fputs($socket,"JOIN $chan $passChan\r\n");
  47.    
  48.    
  49. /*****************************************************************/
  50. /************************* FIN CONNEXION *************************/
  51. /*****************************************************************/
  52.  
  53.     // Boucle principale du programme :
  54.     $cptPlayers = 0;
  55.     $tabPlayers = array();
  56.     $pseudoList = '';
  57.     $whois = '';
  58.     while(1) {
  59.         $donnees = fgets($socket, 1024);
  60.         if($donnees) { // Si le serveur nous a envoyé quelque chose.
  61.             echo $donnees.'<br />';
  62.             $commande = explode(' ',$donnees);
  63.             $message = explode(':',$donnees);
  64.             // Si PING
  65.             if($commande[0] == 'PING')
  66.                 fputs($socket,"PONG ".$commande[1]."\r\n");
  67.             // Si KICK
  68.             if($commande[1] == 'KICK') {
  69.                 if($commande[3] == 'MixBot') // Si c'est le bot qui est expulsé, on rejoint le canal
  70.                     fputs($socket,"JOIN $chan\r\n");
  71.             }
  72.            
  73.             // Si PRIVMSG
  74.             if($commande[1] == 'PRIVMSG') {
  75.                 // Si COMMANDE
  76.                 if(isset($message[2][0]) && $message[2][0] == '!') {
  77.                     // GETTER PSEUDO & AUTH
  78.                     $auth = explode(':',$commande[0]);
  79.                     $pseudo = $auth[1];
  80.                     $auth = explode('!',$auth[1]); // AUTH du joueur
  81.                     $auth = $auth[1];
  82.                     $pseudo = explode('!',$pseudo);
  83.                     $pseudo = $pseudo[0];// PSEUDO du joueur
  84.                    
  85.                     // ADD
  86.                     if(trim($message[2]) == '!add') {
  87.                         /*if(isset($cptTemps)) {
  88.                             fputs($socket,"PRIVMSG #dev :A mix has just started. You have to wait 10min \r\n");
  89.                         }*/
  90.                         if(!isset($tabPlayers[$auth])) { // Si pas deja add
  91.                             $cptPlayers++;
  92.                             $pseudoList .= $pseudo.' ';
  93.                             if($cptPlayers < 5) {
  94.                                 $tabPlayers[$auth] = $pseudo; // [auth] => pseudo
  95.                                 fputs($socket,"PRIVMSG $chan :Signed up players: [$cptPlayers/5] : type !who to see who is signed up.\r\n"); // On envoie la question courante.
  96.                                 fputs($socket,"MODE $chan +v $pseudo\r\n");
  97.                                 echo  "<pre>********** Tab Players ADD *************";
  98.                                 print_r($tabPlayers);
  99.                                 echo "<br /></pre>";
  100.                             }
  101.                             if($cptPlayers == 5) {
  102.                                 $tabPlayers[''.$auth.''] = $pseudo;
  103.                                 fputs($socket,"PRIVMSG $chan :Signed up players : [5/5]. Players : .Have fun.\r\n"); // On envoie la question courante.
  104.                                 fputs($socket,"PRIVMSG $chan :!pcw 5 ts\r\n");
  105.                                 $cptPlayers = 0;
  106.                             }
  107.                            
  108.                             // SEND IP
  109.                             // fputs($socket,"PRIVMSG $pseudo : <blablabla> + IP \r\n");
  110.                         }
  111.                     }
  112.                    
  113.                     // REMOVE
  114.                     if(trim($message[2]) == '!remove') {
  115.                         if(isset($tabPlayers[$auth])) {
  116.                             $cptPlayers--;
  117.                             fputs($socket,"MODE $chan -v $pseudo\r\n");
  118.                             unset($tabPlayers[$auth]);
  119.                             if($cptPlayers == 0)
  120.                                 fputs($socket,"PRIVMSG $chan :Nobody is signed up\r\n");
  121.                             else
  122.                                 fputs($socket,"PRIVMSG $chan :Signed up players : [$cptPlayers/5] : type !who to see who is signed up.\r\n");
  123.                         }
  124.                     }
  125.                    
  126.                     // WHO
  127.                     if(trim($message[2]) == '!who') {
  128.                         if($cptPlayers == 0) {
  129.                             fputs($socket,"PRIVMSG $chan :Nobody is signed up\r\n");
  130.                         }
  131.                         else {
  132.                             fputs($socket,"PRIVMSG $chan :Signed up players [$cptPlayers/5] : $pseudoList\r\n");
  133.                         }
  134.                     }
  135.                    
  136.                     // RING
  137.                     if(trim($message[2]) == '!ring') {
  138.                         if(isset($tabPlayers[$auth])) {
  139.                             $nbRingers = 5 - $cptPlayers;
  140.                             fputs($socket,"PRIVMSG $chan :!ringer $nbRingers /join $chan and type !add\r\n");                  
  141.                         }
  142.                     }
  143.                    
  144.                     // RESET
  145.                     if(trim($message[2]) == '!reset') {
  146.                         fputs($socket,"WHOIS $pseudo\r\n");
  147.                         while(!preg_match('#End of /WHOIS list.#', $whois)) {
  148.                             $whois .= trim(fgets($socket, 1024));
  149.                         }
  150.                         if(preg_match('#@'.$chanRegex.'#',$whois)) {
  151.                             $cptPlayers = 0;
  152.                             $tabPlayers = array();
  153.                             $pseudoList = '';
  154.                             fputs($socket,"PRIVMSG $chan :Mix successfully reseted.\r\n");
  155.                         }
  156.                     }
  157.                    
  158.                     // HELP
  159.                     if(trim($message[2]) == '!help') {
  160.                         fputs($socket,"PRIVMSG $chan :Public commands : !add, !remove, !who, !ring, !gameover, !noob. You can also see rules at : <address>.\r\n");
  161.                     }
  162.                    
  163.                     // QUIT
  164.                     if(trim($message[2]) == '!quit') {
  165.                         if($auth == '~Narkoweed@ANantes-551-1-234-66.w90-49.abo.wanadoo.fr') { // Narkoweed
  166.                             fputs($socket,"QUIT\r\n");
  167.                             exit();
  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.         usleep(100); // On fait « dormir » le programme afin d'économiser l'utilisation du processeur.
  174.     }
  175. ?>
Add Comment
Please, Sign In to add comment