Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //================================IRC Functions=================================
- /*
- This function is called on a timer in order to delay connections to the IRC
- server and effectively prevent join floods.
- */
- forward IRC_ConnectDelay(tempircid);
- public IRC_ConnectDelay(tempircid)
- {
- switch (tempircid)
- {
- case 1:
- {
- gBotID[0] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_1_NICKNAME, BOT_1_REALNAME, BOT_1_USERNAME);
- }
- case 2:
- {
- gBotID[1] = IRC_Connect(IRC_SERVER, IRC_PORT, BOT_2_NICKNAME, BOT_2_REALNAME, BOT_2_USERNAME);
- }
- }
- return 1;
- }
- /*
- The IRC callbacks are below. Many of these are simply derived from parsed
- raw messages received from the IRC server. They can be used to inform the
- bot of new activity in any of the channels it has joined.
- */
- public IRC_OnConnect(botid)
- {
- printf("*** IRC_OnConnect: Bot ID %d connected!", botid);
- if(botid==1) IRC_SendRaw(botid, "IDENTIFY Thesims2rools"), IRC_JoinChannel(botid, IRC_CHANNEL), IRC_AddToGroup(gGroupID, botid);
- if(botid==2) IRC_SendRaw(botid, "IDENTIFY Thesims2rools"), IRC_JoinChannel(botid, IRC_ADMINCHANNEL), IRC_AddToGroup(gGroupID2, botid);
- return 1;
- }
- /*
- Note that this callback is executed whenever a current connection is closed
- OR whenever a connection attempt fails. Reconnecting too fast can flood the
- IRC server and possibly result in a ban. It is recommended to set up
- connection reattempts on a timer, as demonstrated here.
- */
- public IRC_OnDisconnect(botid)
- {
- printf("*** IRC_OnDisconnect: Bot ID %d disconnected!", botid);
- if (botid == gBotID[0])
- {
- // Wait 20 seconds for the first bot
- SetTimerEx("IRC_ConnectDelay", 20000, 0, "d", 1);
- }
- else if (botid == gBotID[1])
- {
- // Wait 25 seconds for the second bot
- SetTimerEx("IRC_ConnectDelay", 25000, 0, "d", 2);
- }
- printf("*** IRC_OnDisconnect: Bot ID %d attempting to reconnect...", botid);
- // Remove the bot from the group
- if(botid==1) IRC_RemoveFromGroup(gGroupID, botid);
- if(botid==2) IRC_RemoveFromGroup(gGroupID2, botid);
- return 1;
- }
- public IRC_OnJoinChannel(botid, channel[])
- {
- printf("*** IRC_OnJoinChannel: Bot ID %d joined channel %s!", botid, channel);
- return 1;
- }
- /*
- If the bot cannot immediately rejoin the channel (in the event, for example,
- that the bot is kicked and then banned), you might want to set up a timer
- here as well for rejoin attempts.
- */
- public IRC_OnLeaveChannel(botid, channel[], message[])
- {
- printf("*** IRC_OnLeaveChannel: Bot ID %d left channel %s (%s)!", botid, channel, message);
- IRC_JoinChannel(botid, channel);
- return 1;
- }
- public IRC_OnUserDisconnect(botid, user[], host[], message[])
- {
- printf("*** IRC_OnUserDisconnect (Bot ID %d): User %s (%s) disconnected! (%s)", botid, user, host, message);
- return 1;
- }
- public IRC_OnUserJoinChannel(botid, channel[], user[], host[])
- {
- printf("*** IRC_OnUserJoinChannel (Bot ID %d): User %s (%s) joined channel %s!", botid, user, host, channel);
- return 1;
- }
- public IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[])
- {
- printf("*** IRC_OnUserLeaveChannel (Bot ID %d): User %s (%s) left channel %s (%s)!", botid, user, host, channel, message);
- return 1;
- }
- public IRC_OnUserNickChange(botid, oldnick[], newnick[], host[])
- {
- printf("*** IRC_OnUserNickChange (Bot ID %d): User %s (%s) changed his nick to %s!", botid, oldnick, host, newnick);
- return 1;
- }
- public IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[])
- {
- printf("*** IRC_OnUserSetChannelMode (Bot ID %d): User %s (%s) on %s set mode: %s!", botid, user, host, channel, mode);
- return 1;
- }
- public IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[])
- {
- printf("*** IRC_OnUserSetChannelTopic (Bot ID %d): User %s (%s) on %s set topic: %s!", botid, user, host, channel, topic);
- return 1;
- }
- public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
- {
- printf("*** IRC_OnUserSay (Bot ID %d): User %s (%s) sent message to %s: %s", botid, user, host, recipient, message);
- // Someone sent the first bot a private message
- if (!strcmp(recipient, BOT_1_NICKNAME))
- {
- IRC_Say(botid, user, "You sent me a PM!");
- }
- return 1;
- }
- public IRC_OnUserNotice(botid, recipient[], user[], host[], message[])
- {
- printf("*** IRC_OnUserNotice (Bot ID %d): User %s (%s) sent notice to %s: %s", botid, user, host, recipient, message);
- // Someone sent the second bot a notice (probably a network service)
- if (!strcmp(recipient, BOT_2_NICKNAME))
- {
- IRC_Notice(botid, user, "You sent me a notice!");
- }
- return 1;
- }
- /*
- Do not print these messages in the console output, as they will probably
- crash the SA-MP server if they are too long. This callback is better suited
- for logging, debugging, or catching error messages sent by the IRC server.
- */
- public IRC_OnReceiveRaw(botid, message[])
- {
- new File:file, output[1536];
- strmid(output, message, 0, sizeof(output), sizeof(output));
- if (!fexist("irc_log.txt"))
- {
- file = fopen("irc_log.txt", io_write);
- fwrite(file, output);
- fclose(file);
- }
- else
- {
- file = fopen("irc_log.txt", io_append);
- fwrite(file, output);
- fclose(file);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment