Advertisement
Guest User

.

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