Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * BOT TS
- */
- $chan = '#MixMeMore';
- $chanRegex = '\#MixMeMore';
- $passChan = 'MixBotSt4ff';
- $serv = 'irc.quakenet.org';
- $port = '6667';
- /*****************************************************************/
- /************************* CONNEXION & JOIN **********************/
- /*****************************************************************/
- set_time_limit(0);
- $socket = fsockopen(''.$serv.'',''.$port.'');
- if(!$socket) {
- echo 'Impossible de se connecter au serveur '.$serv.' sur le port '.$port.'.';
- exit;
- }
- // USER & NICK
- fputs($socket,"USER MixBot MixBot MixBot MixBot\r\n");
- fputs($socket,"NICK MixBot\r\n");
- // Le PING PONG
- $continuer = 1;
- $i=0;
- while($continuer) {
- echo $i;
- $donnees = fgets($socket, 1024);
- $retour = explode(':',$donnees); // On sépare les différentes données.
- if(rtrim($retour[0]) == 'PING') {
- fputs($socket,'PONG :'.$retour[1]);
- $continuer = 0;
- }
- if($donnees) // Si le serveur a envoyé des données, on les affiche.
- echo ' <= incrementeur'.$donnees.'<br /><br />';
- $i++;
- }
- // Join canal
- for($i=0;$i<20;$i++) {
- $donnees = fgets($socket,1024);
- }
- echo 'apres'.$i.' : '.$donnees.'<br /><br />';
- fputs($socket,"JOIN $chan $passChan\r\n");
- /*****************************************************************/
- /************************* FIN CONNEXION *************************/
- /*****************************************************************/
- // Boucle principale du programme :
- $cptPlayers = 0;
- $tabPlayers = array();
- $pseudoList = '';
- $whois = '';
- while(1) {
- $donnees = fgets($socket, 1024);
- if($donnees) { // Si le serveur nous a envoyé quelque chose.
- echo $donnees.'<br />';
- $commande = explode(' ',$donnees);
- $message = explode(':',$donnees);
- // Si PING
- if($commande[0] == 'PING')
- fputs($socket,"PONG ".$commande[1]."\r\n");
- // Si KICK
- if($commande[1] == 'KICK') {
- if($commande[3] == 'MixBot') // Si c'est le bot qui est expulsé, on rejoint le canal
- fputs($socket,"JOIN $chan\r\n");
- }
- // Si PRIVMSG
- if($commande[1] == 'PRIVMSG') {
- // Si COMMANDE
- if(isset($message[2][0]) && $message[2][0] == '!') {
- // GETTER PSEUDO & AUTH
- $auth = explode(':',$commande[0]);
- $pseudo = $auth[1];
- $auth = explode('!',$auth[1]); // AUTH du joueur
- $auth = $auth[1];
- $pseudo = explode('!',$pseudo);
- $pseudo = $pseudo[0];// PSEUDO du joueur
- // ADD
- if(trim($message[2]) == '!add') {
- /*if(isset($cptTemps)) {
- fputs($socket,"PRIVMSG #dev :A mix has just started. You have to wait 10min \r\n");
- }*/
- if(!isset($tabPlayers[$auth])) { // Si pas deja add
- $cptPlayers++;
- $pseudoList .= $pseudo.' ';
- if($cptPlayers < 5) {
- $tabPlayers[$auth] = $pseudo; // [auth] => pseudo
- fputs($socket,"PRIVMSG $chan :Signed up players: [$cptPlayers/5] : type !who to see who is signed up.\r\n"); // On envoie la question courante.
- fputs($socket,"MODE $chan +v $pseudo\r\n");
- echo "<pre>********** Tab Players ADD *************";
- print_r($tabPlayers);
- echo "<br /></pre>";
- }
- if($cptPlayers == 5) {
- $tabPlayers[''.$auth.''] = $pseudo;
- fputs($socket,"PRIVMSG $chan :Signed up players : [5/5]. Players : .Have fun.\r\n"); // On envoie la question courante.
- fputs($socket,"PRIVMSG $chan :!pcw 5 ts\r\n");
- $cptPlayers = 0;
- }
- // SEND IP
- // fputs($socket,"PRIVMSG $pseudo : <blablabla> + IP \r\n");
- }
- }
- // REMOVE
- if(trim($message[2]) == '!remove') {
- if(isset($tabPlayers[$auth])) {
- $cptPlayers--;
- fputs($socket,"MODE $chan -v $pseudo\r\n");
- unset($tabPlayers[$auth]);
- if($cptPlayers == 0)
- fputs($socket,"PRIVMSG $chan :Nobody is signed up\r\n");
- else
- fputs($socket,"PRIVMSG $chan :Signed up players : [$cptPlayers/5] : type !who to see who is signed up.\r\n");
- }
- }
- // WHO
- if(trim($message[2]) == '!who') {
- if($cptPlayers == 0) {
- fputs($socket,"PRIVMSG $chan :Nobody is signed up\r\n");
- }
- else {
- fputs($socket,"PRIVMSG $chan :Signed up players [$cptPlayers/5] : $pseudoList\r\n");
- }
- }
- // RING
- if(trim($message[2]) == '!ring') {
- if(isset($tabPlayers[$auth])) {
- $nbRingers = 5 - $cptPlayers;
- fputs($socket,"PRIVMSG $chan :!ringer $nbRingers /join $chan and type !add\r\n");
- }
- }
- // RESET
- if(trim($message[2]) == '!reset') {
- fputs($socket,"WHOIS $pseudo\r\n");
- while(!preg_match('#End of /WHOIS list.#', $whois)) {
- $whois .= trim(fgets($socket, 1024));
- }
- if(preg_match('#@'.$chanRegex.'#',$whois)) {
- $cptPlayers = 0;
- $tabPlayers = array();
- $pseudoList = '';
- fputs($socket,"PRIVMSG $chan :Mix successfully reseted.\r\n");
- }
- }
- // HELP
- if(trim($message[2]) == '!help') {
- fputs($socket,"PRIVMSG $chan :Public commands : !add, !remove, !who, !ring, !gameover, !noob. You can also see rules at : <address>.\r\n");
- }
- // QUIT
- if(trim($message[2]) == '!quit') {
- if($auth == '~Narkoweed@ANantes-551-1-234-66.w90-49.abo.wanadoo.fr') { // Narkoweed
- fputs($socket,"QUIT\r\n");
- exit();
- }
- }
- }
- }
- }
- usleep(100); // On fait « dormir » le programme afin d'économiser l'utilisation du processeur.
- }
- ?>
Add Comment
Please, Sign In to add comment