Guest User

Untitled

a guest
Jul 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set("display_errors", 1);
  5.  
  6. $host='irc.quakenet.org';
  7. $port=6667;
  8. $mynickname='Sakarinpelin';
  9.  
  10. echo "Connecting...\r\n";
  11.  
  12. $game_won = false;
  13. $gamestate = 0;
  14.  
  15. function game_reset()
  16. {
  17. global $gamestate;
  18. $gamestate = 0;
  19. sleep(2);
  20. irc_cmsg('Sakarin villapaitapeli!');
  21. sleep(2);
  22. }
  23.  
  24. function game_start()
  25. {
  26. global $gamestate;
  27. $gamestate = 1;
  28. sleep(2);
  29. irc_cmsg('Pue sakarille villapaita');
  30. sleep(2);
  31. }
  32.  
  33. function game_win()
  34. {
  35. global $gamestate;
  36. $gamestate = 2;
  37. $game_won = true;
  38.  
  39. sleep(2);
  40. irc_cmsg(chr(1).'ACTION pukee päällensä sakarin villapaidan'.chr(1));
  41. sleep(4);
  42. irc_cmsg('Hihihi!');
  43. sleep(1);
  44. irc_cmsg('Kutittaa!');
  45. sleep(1);
  46. irc_cmsg('Voitit pelin!');
  47. sleep(2);
  48. }
  49.  
  50. function game_lose()
  51. {
  52. global $gamestate;
  53. $gamestate = 2;
  54. $game_won = false;
  55.  
  56. sleep(2);
  57. irc_cmsg('Hmm...');
  58. sleep(2);
  59. irc_cmsg('Hävisit pelin!');
  60. sleep(2);
  61. }
  62.  
  63. $fp=fsockopen($host,$port,$errno,$errstr,15);
  64. $ch = "#soldat.dota";
  65. if (!$fp) die("Error: $errstr ($errno)\r\n");
  66.  
  67. IRCSocketMsg('NICK '.$mynickname."\r\n");
  68. IRCSocketMsg('USER '.strtolower($mynickname)." * * :rofl\r\n");
  69.  
  70. function IRCSocketMsg($string) {
  71. global $fp;
  72. fputs($fp,$string);
  73. }
  74.  
  75. function IRCMsg($msg) {
  76. global $ch;
  77. IRCSocketMsg("PRIVMSG $ch :\00307".$msg."\r\n");
  78. }
  79.  
  80. function irc_cmsg($msg) {
  81. global $ch;
  82. IRCSocketMsg("PRIVMSG $ch :".$msg."\n");
  83. }
  84.  
  85. function IRCJoin($channel,$password) {
  86. IRCSocketMsg("JOIN $channel $password\r\n");
  87. }
  88.  
  89. function IRCPart($channel) {
  90. IRCSocketMsg("PART $channel\r\n");
  91. }
  92.  
  93. function GetNIH($useraddress,&$nickname,&$ident,&$hostname) {
  94. $nickname=substr($useraddress,0,strpos($useraddress,'!'));
  95. $ident=substr($useraddress,strpos($useraddress,'!')+1,-strpos($useraddress,'@')-1);
  96. $hostname=substr($useraddress,strpos($useraddress,'@')+1);
  97. }
  98.  
  99. while (true) {
  100. sleep(1);
  101.  
  102. while ($data = fgets($fp)) {
  103. $data=trim($data);
  104. echo $data."\r\n";
  105. $arg=explode(' ',$data);
  106. $msg=substr($data,strpos($data,':',1)+1);
  107. switch ($arg[0]) {
  108. case 'PING':
  109. IRCSocketMsg("PONG $arg[1]\r\n");
  110. break;
  111. }
  112.  
  113. switch ($arg[1]) {
  114. case '004':
  115. IRCJoin($ch,"");
  116. sleep(1);
  117. game_reset();
  118. echo "Done!\r\n";
  119. break;
  120.  
  121. case '431': //ERR_NONICKNAMEGIVEN
  122. case '432': //ERR_ERRONEUSNICKNAME
  123. case '433': //ERR_NICKNAMEINUSE
  124. case '436': //ERR_NICKCOLLISION
  125. $mynickname.=rand(1,9);
  126. IRCSocketMsg('NICK '.$mynickname."\r\n");
  127. break;
  128.  
  129. case 'PRIVMSG':
  130. $chan = $arg[2];
  131. $msgarg = explode(' ', $msg);
  132.  
  133. if (strtolower($arg[2]) != $ch)
  134. break;
  135.  
  136. switch (strtolower($msgarg[0]))
  137. {
  138. case 'aloita':
  139. if ($gamestate == 0)
  140. game_start();
  141. break;
  142.  
  143. case 'en':
  144. if ($gamestate == 1)
  145. game_lose();
  146. break;
  147.  
  148. case 'joo':
  149. if ($gamestate == 1)
  150. game_win();
  151. break;
  152.  
  153. case 'uudestaan':
  154. if ($gamestate == 2 && $game_won == false)
  155. game_reset();
  156. break;
  157.  
  158. case 'uudelleen':
  159. if ($gamestate == 2 && $game_lost == true)
  160. game_reset();
  161. break;
  162. }
  163.  
  164. break;
  165.  
  166. }
  167. }
  168. }
  169. fclose($fp);
  170. ?>
Add Comment
Please, Sign In to add comment