Guest User

Untitled

a guest
Jul 7th, 2012
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.21 KB | None | 0 0
  1. #include <irc>
  2. // sscanf2 include from the sscanf plugin
  3. #include <sscanf2>
  4.  
  5. // Name that everyone will see
  6. #define BOT_1_NICKNAME "bot1"
  7. // Name that will only be visible in a whois
  8. #define BOT_1_REALNAME "SA_MP Bot"
  9. // Name that will be in front of the hostname (username@hostname)
  10. #define BOT_1_USERNAME "bot"
  11.  
  12. #define BOT_2_NICKNAME "bot2"
  13. #define BOT_2_REALNAME "SA_MP Bot"
  14. #define BOT_2_USERNAME "bot"
  15.  
  16. #define IRC_SERVER "irc.tl"
  17. #define IRC_PORT (6667)
  18. #define IRC_CHANNEL "#Legend"
  19.  
  20. // Maximum number of bots in the filterscript
  21. #define MAX_BOTS (2)
  22.  
  23. #define PLUGIN_VERSION "1.4.2"
  24.  
  25. new gBotID[MAX_BOTS], gGroupID;
  26.  
  27. /*
  28. When the filterscript is loaded, two bots will connect and a group will be
  29. created for them.
  30. */
  31.  
  32. public OnFilterScriptInit()
  33. {
  34. // Connect the first bot
  35. gBotID[0] = IRC_Connect(#irc.tl, 6667, bot1, SA_MP Bot, bot);
  36. // Set the connect delay for the first bot to 20 seconds
  37. IRC_SetIntData(gBotID[0], E_IRC_CONNECT_DELAY, 20);
  38. // Connect the second bot
  39. gBotID[1] = IRC_Connect(#irc.tl, 6667, bot2, SA_MP Bot, bot);
  40. // Set the connect delay for the second bot to 30 seconds
  41. IRC_SetIntData(gBotID[1], E_IRC_CONNECT_DELAY, 30);
  42. // Create a group (the bots will be added to it upon connect)
  43. gGroupID = IRC_CreateGroup();
  44. }
  45.  
  46. /*
  47. When the filterscript is unloaded, the bots will disconnect, and the group
  48. will be destroyed.
  49. */
  50.  
  51. public OnFilterScriptExit()
  52. {
  53. // Disconnect the first bot
  54. IRC_Quit(gBotID[0], "Filterscript exiting");
  55. // Disconnect the second bot
  56. IRC_Quit(gBotID[1], "Filterscript exiting");
  57. // Destroy the group
  58. IRC_DestroyGroup(gGroupID);
  59. }
  60.  
  61. /*
  62. The standard SA-MP callbacks are below. We will echo a few of them to the
  63. IRC channel.
  64. */
  65.  
  66. public OnPlayerConnect(playerid)
  67. {
  68. new joinMsg[128], name[MAX_PLAYER_NAME];
  69. GetPlayerName(playerid, name, sizeof(name));
  70. format(joinMsg, sizeof(joinMsg), "02[%d] 03*** %s has joined the server.", playerid, name);
  71. IRC_GroupSay(gGroupID, IRC_CHANNEL, joinMsg);
  72. return 1;
  73. }
  74.  
  75. public OnPlayerDisconnect(playerid, reason)
  76. {
  77. new leaveMsg[128], name[MAX_PLAYER_NAME], reasonMsg[8];
  78. switch(reason)
  79. {
  80. case 0: reasonMsg = "Timeout";
  81. case 1: reasonMsg = "Leaving";
  82. case 2: reasonMsg = "Kicked";
  83. }
  84. GetPlayerName(playerid, name, sizeof(name));
  85. format(leaveMsg, sizeof(leaveMsg), "02[%d] 03*** %s has left the server. (%s)", playerid, name, reasonMsg);
  86. IRC_GroupSay(gGroupID, IRC_CHANNEL, leaveMsg);
  87. return 1;
  88. }
  89.  
  90. public OnPlayerDeath(playerid, killerid, reason)
  91. {
  92. new msg[128], killerName[MAX_PLAYER_NAME], reasonMsg[32], playerName[MAX_PLAYER_NAME];
  93. GetPlayerName(killerid, killerName, sizeof(killerName));
  94. GetPlayerName(playerid, playerName, sizeof(playerName));
  95. if (killerid != INVALID_PLAYER_ID)
  96. {
  97. switch (reason)
  98. {
  99. case 0: reasonMsg = "Unarmed";
  100. case 1: reasonMsg = "Brass Knuckles";
  101. case 2: reasonMsg = "Golf Club";
  102. case 3: reasonMsg = "Night Stick";
  103. case 4: reasonMsg = "Knife";
  104. case 5: reasonMsg = "Baseball Bat";
  105. case 6: reasonMsg = "Shovel";
  106. case 7: reasonMsg = "Pool Cue";
  107. case 8: reasonMsg = "Katana";
  108. case 9: reasonMsg = "Chainsaw";
  109. case 10: reasonMsg = "Dildo";
  110. case 11: reasonMsg = "Dildo";
  111. case 12: reasonMsg = "Vibrator";
  112. case 13: reasonMsg = "Vibrator";
  113. case 14: reasonMsg = "Flowers";
  114. case 15: reasonMsg = "Cane";
  115. case 22: reasonMsg = "Pistol";
  116. case 23: reasonMsg = "Silenced Pistol";
  117. case 24: reasonMsg = "Desert Eagle";
  118. case 25: reasonMsg = "Shotgun";
  119. case 26: reasonMsg = "Sawn-off Shotgun";
  120. case 27: reasonMsg = "Combat Shotgun";
  121. case 28: reasonMsg = "MAC-10";
  122. case 29: reasonMsg = "MP5";
  123. case 30: reasonMsg = "AK-47";
  124. case 31: reasonMsg = "M4";
  125. case 32: reasonMsg = "TEC-9";
  126. case 33: reasonMsg = "Country Rifle";
  127. case 34: reasonMsg = "Sniper Rifle";
  128. case 37: reasonMsg = "Fire";
  129. case 38: reasonMsg = "Minigun";
  130. case 41: reasonMsg = "Spray Can";
  131. case 42: reasonMsg = "Fire Extinguisher";
  132. case 49: reasonMsg = "Vehicle Collision";
  133. case 50: reasonMsg = "Vehicle Collision";
  134. case 51: reasonMsg = "Explosion";
  135. default: reasonMsg = "Unknown";
  136. }
  137. format(msg, sizeof(msg), "04*** %s killed %s. (%s)", killerName, playerName, reasonMsg);
  138. }
  139. else
  140. {
  141. switch (reason)
  142. {
  143. case 53: format(msg, sizeof(msg), "04*** %s died. (Drowned)", playerName);
  144. case 54: format(msg, sizeof(msg), "04*** %s died. (Collision)", playerName);
  145. default: format(msg, sizeof(msg), "04*** %s died.", playerName);
  146. }
  147. }
  148. IRC_GroupSay(gGroupID, IRC_CHANNEL, msg);
  149. return 1;
  150. }
  151.  
  152. public OnPlayerText(playerid, text[])
  153. {
  154. new name[MAX_PLAYER_NAME], ircMsg[256];
  155. GetPlayerName(playerid, name, sizeof(name));
  156. format(ircMsg, sizeof(ircMsg), "02[%d] 07%s: %s", playerid, name, text);
  157. IRC_GroupSay(gGroupID, IRC_CHANNEL, ircMsg);
  158. return 1;
  159. }
  160.  
  161. /*
  162. The IRC callbacks are below. Many of these are simply derived from parsed
  163. raw messages received from the IRC server. They can be used to inform the
  164. bot of new activity in any of the channels it has joined.
  165. */
  166.  
  167. /*
  168. This callback is executed whenever a bot successfully connects to an IRC
  169. server.
  170. */
  171.  
  172. public IRC_OnConnect(botid, ip[], port)
  173. {
  174. printf("*** IRC_OnConnect: Bot ID %d connected to %s:%d", botid, ip, port);
  175. // Join the channel
  176. IRC_JoinChannel(botid, IRC_CHANNEL);
  177. // Add the bot to the group
  178. IRC_AddToGroup(gGroupID, botid);
  179. return 1;
  180. }
  181.  
  182. /*
  183. This callback is executed whenever a current connection is closed. The
  184. plugin may automatically attempt to reconnect per user settings. IRC_Quit
  185. may be called at any time to stop the reconnection process.
  186. */
  187.  
  188. public IRC_OnDisconnect(botid, ip[], port, reason[])
  189. {
  190. printf("*** IRC_OnDisconnect: Bot ID %d disconnected from %s:%d (%s)", botid, ip, port, reason);
  191. // Remove the bot from the group
  192. IRC_RemoveFromGroup(gGroupID, botid);
  193. return 1;
  194. }
  195.  
  196. /*
  197. This callback is executed whenever a connection attempt begins. IRC_Quit may
  198. be called at any time to stop the reconnection process.
  199. */
  200.  
  201. public IRC_OnConnectAttempt(botid, ip[], port)
  202. {
  203. printf("*** IRC_OnConnectAttempt: Bot ID %d attempting to connect to %s:%d...", botid, ip, port);
  204. return 1;
  205. }
  206.  
  207. /*
  208. This callback is executed whenever a connection attempt fails. IRC_Quit may
  209. be called at any time to stop the reconnection process.
  210. */
  211.  
  212. public IRC_OnConnectAttemptFail(botid, ip[], port, reason[])
  213. {
  214. printf("*** IRC_OnConnectAttemptFail: Bot ID %d failed to connect to %s:%d (%s)", botid, ip, port, reason);
  215. return 1;
  216. }
  217.  
  218. /*
  219. This callback is executed whenever a bot joins a channel.
  220. */
  221.  
  222. public IRC_OnJoinChannel(botid, channel[])
  223. {
  224. printf("*** IRC_OnJoinChannel: Bot ID %d joined channel %s", botid, channel);
  225. return 1;
  226. }
  227.  
  228. /*
  229. This callback is executed whenevever a bot leaves a channel.
  230. */
  231.  
  232. public IRC_OnLeaveChannel(botid, channel[], message[])
  233. {
  234. printf("*** IRC_OnLeaveChannel: Bot ID %d left channel %s (%s)", botid, channel, message);
  235. IRC_JoinChannel(botid, channel);
  236. return 1;
  237. }
  238.  
  239. /*
  240. This callback is executed whenevever a bot is kicked from a channel. If the
  241. bot cannot immediately rejoin the channel (in the event, for example, that
  242. the bot is kicked and then banned), you might want to set up a timer here
  243. for rejoin attempts.
  244. */
  245.  
  246. public IRC_OnKickedFromChannel(botid, channel[], oppeduser[], oppedhost[], message[])
  247. {
  248. printf("*** IRC_OnKickedFromChannel: Bot ID %d kicked by %s (%s) from channel %s (%s)", botid, oppeduser, oppedhost, channel, message);
  249. IRC_JoinChannel(botid, channel);
  250. return 1;
  251. }
  252.  
  253. public IRC_OnUserDisconnect(botid, user[], host[], message[])
  254. {
  255. printf("*** IRC_OnUserDisconnect (Bot ID %d): User %s (%s) disconnected (%s)", botid, user, host, message);
  256. return 1;
  257. }
  258.  
  259. public IRC_OnUserJoinChannel(botid, channel[], user[], host[])
  260. {
  261. printf("*** IRC_OnUserJoinChannel (Bot ID %d): User %s (%s) joined channel %s", botid, user, host, channel);
  262. return 1;
  263. }
  264.  
  265. public IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[])
  266. {
  267. printf("*** IRC_OnUserLeaveChannel (Bot ID %d): User %s (%s) left channel %s (%s)", botid, user, host, channel, message);
  268. return 1;
  269. }
  270.  
  271. public IRC_OnUserKickedFromChannel(botid, channel[], kickeduser[], oppeduser[], oppedhost[], message[])
  272. {
  273. printf("*** IRC_OnUserKickedFromChannel (Bot ID %d): User %s kicked by %s (%s) from channel %s (%s)", botid, kickeduser, oppeduser, oppedhost, channel, message);
  274. }
  275.  
  276. public IRC_OnUserNickChange(botid, oldnick[], newnick[], host[])
  277. {
  278. printf("*** IRC_OnUserNickChange (Bot ID %d): User %s (%s) changed his/her nick to %s", botid, oldnick, host, newnick);
  279. return 1;
  280. }
  281.  
  282. public IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[])
  283. {
  284. printf("*** IRC_OnUserSetChannelMode (Bot ID %d): User %s (%s) on %s set mode: %s", botid, user, host, channel, mode);
  285. return 1;
  286. }
  287.  
  288. public IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[])
  289. {
  290. printf("*** IRC_OnUserSetChannelTopic (Bot ID %d): User %s (%s) on %s set topic: %s", botid, user, host, channel, topic);
  291. return 1;
  292. }
  293.  
  294. public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
  295. {
  296. printf("*** IRC_OnUserSay (Bot ID %d): User %s (%s) sent message to %s: %s", botid, user, host, recipient, message);
  297. // Someone sent the first bot a private message
  298. if (!strcmp(recipient, BOT_1_NICKNAME))
  299. {
  300. IRC_Say(botid, user, "You sent me a PM!");
  301. }
  302. return 1;
  303. }
  304.  
  305. public IRC_OnUserNotice(botid, recipient[], user[], host[], message[])
  306. {
  307. printf("*** IRC_OnUserNotice (Bot ID %d): User %s (%s) sent notice to %s: %s", botid, user, host, recipient, message);
  308. // Someone sent the second bot a notice (probably a network service)
  309. if (!strcmp(recipient, BOT_2_NICKNAME))
  310. {
  311. IRC_Notice(botid, user, "You sent me a notice!");
  312. }
  313. return 1;
  314. }
  315.  
  316. public IRC_OnUserRequestCTCP(botid, user[], host[], message[])
  317. {
  318. printf("*** IRC_OnUserRequestCTCP (Bot ID %d): User %s (%s) sent CTCP request: %s", botid, user, host, message);
  319. // Someone sent a CTCP VERSION request
  320. if (!strcmp(message, "VERSION"))
  321. {
  322. IRC_ReplyCTCP(botid, user, "VERSION SA-MP IRC Plugin v" #PLUGIN_VERSION "");
  323. }
  324. return 1;
  325. }
  326.  
  327. public IRC_OnUserReplyCTCP(botid, user[], host[], message[])
  328. {
  329. printf("*** IRC_OnUserReplyCTCP (Bot ID %d): User %s (%s) sent CTCP reply: %s", botid, user, host, message);
  330. return 1;
  331. }
  332.  
  333. /*
  334. This callback is useful for logging, debugging, or catching error messages
  335. sent by the IRC server.
  336. */
  337.  
  338. public IRC_OnReceiveRaw(botid, message[])
  339. {
  340. new File:file;
  341. if (!fexist("irc_log.txt"))
  342. {
  343. file = fopen("irc_log.txt", io_write);
  344. }
  345. else
  346. {
  347. file = fopen("irc_log.txt", io_append);
  348. }
  349. if (file)
  350. {
  351. fwrite(file, message);
  352. fwrite(file, "\r\n");
  353. fclose(file);
  354. }
  355. return 1;
  356. }
  357.  
  358. /*
  359. Some examples of channel commands are here. You can add more very easily;
  360. their implementation is identical to that of ZeeX's zcmd.
  361. */
  362.  
  363. IRCCMDay(botid, channel[], user[], host[], params[])
  364. {
  365. // Check if the user has at least voice in the channel
  366. if (IRC_IsVoice(botid, channel, user))
  367. {
  368. // Check if the user entered any text
  369. if (!isnull(params))
  370. {
  371. new msg[128];
  372. // Echo the formatted message
  373. format(msg, sizeof(msg), "02*** %s on IRC: %s", user, params);
  374. IRC_GroupSay(gGroupID, channel, msg);
  375. format(msg, sizeof(msg), "*** %s on IRC: %s", user, params);
  376. SendClientMessageToAll(0x0000FFFF, msg);
  377. }
  378. }
  379. return 1;
  380. }
  381.  
  382. IRCCMD:kick(botid, channel[], user[], host[], params[])
  383. {
  384. // Check if the user is at least a halfop in the channel
  385. if (IRC_IsHalfop(botid, channel, user))
  386. {
  387. new playerid, reason[64];
  388. // Check if the user at least entered a player ID
  389. if (sscanf(params, "dS(No reason)[64]", playerid, reason))
  390. {
  391. return 1;
  392. }
  393. // Check if the player is connected
  394. if (IsPlayerConnected(playerid))
  395. {
  396. // Echo the formatted message
  397. new msg[128], name[MAX_PLAYER_NAME];
  398. GetPlayerName(playerid, name, sizeof(name));
  399. format(msg, sizeof(msg), "02*** %s has been kicked by %s on IRC. (%s)", name, user, reason);
  400. IRC_GroupSay(gGroupID, channel, msg);
  401. format(msg, sizeof(msg), "*** %s has been kicked by %s on IRC. (%s)", name, user, reason);
  402. SendClientMessageToAll(0x0000FFFF, msg);
  403. // Kick the player
  404. Kick(playerid);
  405. }
  406. }
  407. return 1;
  408. }
  409.  
  410. IRCCMD:ban(botid, channel[], user[], host[], params[])
  411. {
  412. // Check if the user is at least an op in the channel
  413. if (IRC_IsOp(botid, channel, user))
  414. {
  415. new playerid, reason[64];
  416. // Check if the user at least entered a player ID
  417. if (sscanf(params, "dS(No reason)[64]", playerid, reason))
  418. {
  419. return 1;
  420. }
  421. // Check if the player is connected
  422. if (IsPlayerConnected(playerid))
  423. {
  424. // Echo the formatted message
  425. new msg[128], name[MAX_PLAYER_NAME];
  426. GetPlayerName(playerid, name, sizeof(name));
  427. format(msg, sizeof(msg), "02*** %s has been banned by %s on IRC. (%s)", name, user, reason);
  428. IRC_GroupSay(gGroupID, channel, msg);
  429. format(msg, sizeof(msg), "*** %s has been banned by %s on IRC. (%s)", name, user, reason);
  430. SendClientMessageToAll(0x0000FFFF, msg);
  431. // Ban the player
  432. BanEx(playerid, reason);
  433. }
  434. }
  435. return 1;
  436. }
  437.  
  438. IRCCMD:rcon(botid, channel[], user[], host[], params[])
  439. {
  440. // Check if the user is at least an op in the channel
  441. if (IRC_IsOp(botid, channel, user))
  442. {
  443. // Check if the user entered any text
  444. if (!isnull(params))
  445. {
  446. // Check if the user did not enter any invalid commands
  447. if (strcmp(params, "exit", true) != 0 && strfind(params, "loadfs irc", true) == -1)
  448. {
  449. // Echo the formatted message
  450. new msg[128];
  451. format(msg, sizeof(msg), "RCON command %s has been executed.", params);
  452. IRC_GroupSay(gGroupID, channel, msg);
  453. // Send the command
  454. SendRconCommand(params);
  455. }
  456. }
  457. }
  458. return 1;
  459. }
Advertisement
Add Comment
Please, Sign In to add comment