NeO_Ravers

Lulverhaal

Jul 15th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.10 KB | None | 0 0
  1. //================================IRC Functions=================================
  2. /*
  3.     This function is called on a timer in order to delay connections to the IRC
  4.     server and effectively prevent join floods.
  5. */
  6. forward IRC_ConnectDelay(tempircid);
  7. public IRC_ConnectDelay(tempircid)
  8. {
  9.     switch (tempircid)
  10.     {
  11.         case 1:
  12.         {
  13.             gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
  14.         }
  15.         case 2:
  16.         {
  17.             gBotID[1] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_2_NICKNAME, BOT_2_REALNAME, BOT_2_USERNAME);
  18.         }
  19.     }
  20.     return 1;
  21. }
  22. /*
  23.     The IRC callbacks are below. Many of these are simply derived from parsed
  24.     raw messages received from the IRC server. They can be used to inform the
  25.     bot of new activity in any of the channels it has joined.
  26. */
  27. public IRC_OnConnect(botid)
  28. {
  29.     printf("*** IRC_OnConnect: Bot ID %d connected!", botid);
  30.     if(botid==1) IRC_SendRaw(botid, "IDENTIFY  Thesims2rools"), IRC_JoinChannel(botid, IRC_CHANNEL), IRC_AddToGroup(gGroupID, botid);
  31.     if(botid==2) IRC_SendRaw(botid, "IDENTIFY  Thesims2rools"), IRC_JoinChannel(botid, IRC_ADMINCHANNEL), IRC_AddToGroup(gGroupID2, botid);
  32.     return 1;
  33. }
  34.  
  35. /*
  36.     Note that this callback is executed whenever a current connection is closed
  37.     OR whenever a connection attempt fails. Reconnecting too fast can flood the
  38.     IRC server and possibly result in a ban. It is recommended to set up
  39.     connection reattempts on a timer, as demonstrated here.
  40. */
  41. public IRC_OnDisconnect(botid)
  42. {
  43.     printf("*** IRC_OnDisconnect: Bot ID %d disconnected!", botid);
  44.     if (botid == gBotID[0])
  45.     {
  46.         // Wait 20 seconds for the first bot
  47.         SetTimerEx("IRC_ConnectDelay", 20000, 0, "d", 1);
  48.     }
  49.     else if (botid == gBotID[1])
  50.     {
  51.         // Wait 25 seconds for the second bot
  52.         SetTimerEx("IRC_ConnectDelay", 25000, 0, "d", 2);
  53.     }
  54.     printf("*** IRC_OnDisconnect: Bot ID %d attempting to reconnect...", botid);
  55.     // Remove the bot from the group
  56.     if(botid==1) IRC_RemoveFromGroup(gGroupID, botid);
  57.     if(botid==2) IRC_RemoveFromGroup(gGroupID2, botid);
  58.     return 1;
  59. }
  60.  
  61. public IRC_OnJoinChannel(botid, channel[])
  62. {
  63.     printf("*** IRC_OnJoinChannel: Bot ID %d joined channel %s!", botid, channel);
  64.     return 1;
  65. }
  66.  
  67. /*
  68.     If the bot cannot immediately rejoin the channel (in the event, for example,
  69.     that the bot is kicked and then banned), you might want to set up a timer
  70.     here as well for rejoin attempts.
  71. */
  72.  
  73. public IRC_OnLeaveChannel(botid, channel[], message[])
  74. {
  75.     printf("*** IRC_OnLeaveChannel: Bot ID %d left channel %s (%s)!", botid, channel, message);
  76.     IRC_JoinChannel(botid, channel);
  77.     return 1;
  78. }
  79.  
  80. public IRC_OnUserDisconnect(botid, user[], host[], message[])
  81. {
  82.     printf("*** IRC_OnUserDisconnect (Bot ID %d): User %s (%s) disconnected! (%s)", botid, user, host, message);
  83.     return 1;
  84. }
  85.  
  86. public IRC_OnUserJoinChannel(botid, channel[], user[], host[])
  87. {
  88.     printf("*** IRC_OnUserJoinChannel (Bot ID %d): User %s (%s) joined channel %s!", botid, user, host, channel);
  89.     return 1;
  90. }
  91.  
  92. public IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[])
  93. {
  94.     printf("*** IRC_OnUserLeaveChannel (Bot ID %d): User %s (%s) left channel %s (%s)!", botid, user, host, channel, message);
  95.     return 1;
  96. }
  97.  
  98. public IRC_OnUserNickChange(botid, oldnick[], newnick[], host[])
  99. {
  100.     printf("*** IRC_OnUserNickChange (Bot ID %d): User %s (%s) changed his nick to %s!", botid, oldnick, host, newnick);
  101.     return 1;
  102. }
  103.  
  104. public IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[])
  105. {
  106.     printf("*** IRC_OnUserSetChannelMode (Bot ID %d): User %s (%s) on %s set mode: %s!", botid, user, host, channel, mode);
  107.     return 1;
  108. }
  109.  
  110. public IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[])
  111. {
  112.     printf("*** IRC_OnUserSetChannelTopic (Bot ID %d): User %s (%s) on %s set topic: %s!", botid, user, host, channel, topic);
  113.     return 1;
  114. }
  115.  
  116. public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
  117. {
  118.     printf("*** IRC_OnUserSay (Bot ID %d): User %s (%s) sent message to %s: %s", botid, user, host, recipient, message);
  119.     // Someone sent the first bot a private message
  120.     if (!strcmp(recipient, BOT_1_NICKNAME))
  121.     {
  122.         IRC_Say(botid, user, "You sent me a PM!");
  123.     }
  124.     return 1;
  125. }
  126.  
  127. public IRC_OnUserNotice(botid, recipient[], user[], host[], message[])
  128. {
  129.     printf("*** IRC_OnUserNotice (Bot ID %d): User %s (%s) sent notice to %s: %s", botid, user, host, recipient, message);
  130.     // Someone sent the second bot a notice (probably a network service)
  131.     if (!strcmp(recipient, BOT_2_NICKNAME))
  132.     {
  133.         IRC_Notice(botid, user, "You sent me a notice!");
  134.     }
  135.     return 1;
  136. }
  137.  
  138. /*
  139.     Do not print these messages in the console output, as they will probably
  140.     crash the SA-MP server if they are too long. This callback is better suited
  141.     for logging, debugging, or catching error messages sent by the IRC server.
  142. */
  143. public IRC_OnReceiveRaw(botid, message[])
  144. {
  145.     new File:file, output[1536];
  146.     strmid(output, message, 0, sizeof(output), sizeof(output));
  147.     if (!fexist("irc_log.txt"))
  148.     {
  149.         file = fopen("irc_log.txt", io_write);
  150.         fwrite(file, output);
  151.         fclose(file);
  152.     }
  153.     else
  154.     {
  155.         file = fopen("irc_log.txt", io_append);
  156.         fwrite(file, output);
  157.         fclose(file);
  158.     }
  159.     return 1;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment