irc.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. SA-MP IRC Plugin v1.4.1
  3. Copyright © 2011 Incognito
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #if defined _irc_included
  16. #endinput
  17. #endif
  18. #define _irc_included
  19. #include <a_samp>
  20. // Enumerator
  21. enum
  22. {
  23. E_IRC_CONNECT_ATTEMPTS,
  24. E_IRC_CONNECT_DELAY,
  25. E_IRC_CONNECT_TIMEOUT
  26. }
  27. // Natives
  28. native IRC_Connect(const server[], port, const nickname[], const realname[], const username[], bool:ssl = false, localip[] = "");
  29. native IRC_Quit(botid, const message[] = "");
  30. native IRC_JoinChannel(botid, const channel[], const key[] = "");
  31. native IRC_PartChannel(botid, const channel[], const message[] = "");
  32. native IRC_ChangeNick(botid, const nick[]);
  33. native IRC_SetMode(botid, const target[], const mode[]);
  34. native IRC_Say(botid, const target[], const message[]);
  35. native IRC_Notice(botid, const target[], const message[]);
  36. native IRC_IsUserOnChannel(botid, const channel[], const user[]);
  37. native IRC_InviteUser(botid, const channel[], const user[]);
  38. native IRC_KickUser(botid, const channel[], const user[], const message[] = "");
  39. native IRC_GetUserChannelMode(botid, const channel[], const user[], dest[]);
  40. native IRC_GetChannelUserList(botid, const channel[], dest[], maxlength = sizeof dest);
  41. native IRC_SetChannelTopic(botid, const channel[], const topic[]);
  42. native IRC_RequestCTCP(botid, const user[], const message[]);
  43. native IRC_ReplyCTCP(botid, const user[], const message[]);
  44. native IRC_SendRaw(botid, const message[]);
  45. native IRC_CreateGroup();
  46. native IRC_DestroyGroup(groupid);
  47. native IRC_AddToGroup(groupid, botid);
  48. native IRC_RemoveFromGroup(groupid, botid);
  49. native IRC_GroupSay(groupid, const target[], const message[]);
  50. native IRC_GroupNotice(groupid, const target[], const message[]);
  51. native IRC_SetIntData(botid, data, value);
  52. // Callbacks
  53. forward IRC_OnConnect(botid, ip[], port);
  54. forward IRC_OnDisconnect(botid, ip[], port, reason[]);
  55. forward IRC_OnConnectAttempt(botid, ip[], port);
  56. forward IRC_OnConnectAttemptFail(botid, ip[], port, reason[]);
  57. forward IRC_OnJoinChannel(botid, channel[]);
  58. forward IRC_OnLeaveChannel(botid, channel[], message[]);
  59. forward IRC_OnKickedFromChannel(botid, channel[], oppeduser[], oppedhost[], message[]);
  60. forward IRC_OnUserDisconnect(botid, user[], host[], message[]);
  61. forward IRC_OnUserJoinChannel(botid, channel[], user[], host[]);
  62. forward IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[]);
  63. forward IRC_OnUserKickedFromChannel(botid, channel[], kickeduser[], oppeduser[], oppedhost[], message[]);
  64. forward IRC_OnUserNickChange(botid, oldnick[], newnick[], host[]);
  65. forward IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[]);
  66. forward IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[]);
  67. forward IRC_OnUserSay(botid, recipient[], user[], host[], message[]);
  68. forward IRC_OnUserNotice(botid, recipient[], user[], host[], message[]);
  69. forward IRC_OnUserRequestCTCP(botid, user[], host[], message[]);
  70. forward IRC_OnUserReplyCTCP(botid, user[], host[], message[]);
  71. forward IRC_OnReceiveRaw(botid, message[]);
  72. // Stock Functions
  73. stock IRC_IsVoice(botid, channel[], user[])
  74. {
  75. new mode[2];
  76. IRC_GetUserChannelMode(botid, channel, user, mode);
  77. switch (mode[0])
  78. {
  79. case '+', '%', '@', '&', '!', '*', '~', '.':
  80. {
  81. return 1;
  82. }
  83. }
  84. return 0;
  85. }
  86. stock IRC_IsHalfop(botid, channel[], user[])
  87. {
  88. new mode[2];
  89. IRC_GetUserChannelMode(botid, channel, user, mode);
  90. switch (mode[0])
  91. {
  92. case '%', '@', '&', '!', '*', '~', '.':
  93. {
  94. return 1;
  95. }
  96. }
  97. return 0;
  98. }
  99. stock IRC_IsOp(botid, channel[], user[])
  100. {
  101. new mode[2];
  102. IRC_GetUserChannelMode(botid, channel, user, mode);
  103. switch (mode[0])
  104. {
  105. case '@', '&', '!', '*', '~', '.':
  106. {
  107. return 1;
  108. }
  109. }
  110. return 0;
  111. }
  112. stock IRC_IsAdmin(botid, channel[], user[])
  113. {
  114. new mode[2];
  115. IRC_GetUserChannelMode(botid, channel, user, mode);
  116. switch (mode[0])
  117. {
  118. case '&', '!', '*', '~', '.':
  119. {
  120. return 1;
  121. }
  122. }
  123. return 0;
  124. }
  125. stock IRC_IsOwner(botid, channel[], user[])
  126. {
  127. new mode[2];
  128. IRC_GetUserChannelMode(botid, channel, user, mode);
  129. switch (mode[0])
  130. {
  131. case '~', '.':
  132. {
  133. return 1;
  134. }
  135. }
  136. return 0;
  137. }
  138. // Command system for users in IRC channels
  139. // Slightly modified zcmd by Zeex
  140. #define CHANNEL_PREFIX '#'
  141. #define COMMAND_PREFIX '!'
  142. #define IRCCMD:%1(%2) \
  143. forward irccmd_%1(%2); \
  144. public irccmd_%1(%2)
  145. #define irccmd(%1,%2,%3,%4,%5,%6) \
  146. IRCCMD:%1(%2, %3, %4, %5, %6)
  147. #if !defined isnull
  148. #define isnull(%1) \
  149. ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  150. #endif
  151. static bool:IRC_g_OUS = false;
  152. public OnFilterScriptInit()
  153. {
  154. IRC_g_OUS = funcidx("IRC_OUS") != -1;
  155. if (funcidx("IRC_OnFilterScriptInit") != -1)
  156. {
  157. return CallLocalFunction("IRC_OnFilterScriptInit", "");
  158. }
  159. return 1;
  160. }
  161. #if defined _ALS_OnFilterScriptInit
  162. #undef OnFilterScriptInit
  163. #else
  164. #define _ALS_OnFilterScriptInit
  165. #endif
  166. #define OnFilterScriptInit IRC_OnFilterScriptInit
  167. forward IRC_OnFilterScriptInit();
  168. public OnGameModeInit()
  169. {
  170. IRC_g_OUS = funcidx("IRC_OUS") != -1;
  171. if (funcidx("IRC_OnGameModeInit") != -1)
  172. {
  173. return CallLocalFunction("IRC_OnGameModeInit", "");
  174. }
  175. return 1;
  176. }
  177. #if defined _ALS_OnGameModeInit
  178. #undef OnGameModeInit
  179. #else
  180. #define _ALS_OnGameModeInit
  181. #endif
  182. #define OnGameModeInit IRC_OnGameModeInit
  183. forward IRC_OnGameModeInit();
  184. public IRC_OnUserSay(botid, recipient[], user[], host[], message[])
  185. {
  186. if (recipient[0] == CHANNEL_PREFIX && message[0] == COMMAND_PREFIX)
  187. {
  188. new function[32], pos = 0;
  189. while (message[++pos] > ' ')
  190. {
  191. function[pos - 1] = tolower(message[pos]);
  192. }
  193. format(function, sizeof(function), "irccmd_%s", function);
  194. while (message[pos] == ' ')
  195. {
  196. pos++;
  197. }
  198. if (!message[pos])
  199. {
  200. CallLocalFunction(function, "dssss", botid, recipient, user, host, "\1");
  201. }
  202. else
  203. {
  204. CallLocalFunction(function, "dssss", botid, recipient, user, host, message[pos]);
  205. }
  206. }
  207. if (IRC_g_OUS)
  208. {
  209. return CallLocalFunction("IRC_OUS", "dssss", botid, recipient, user, host, message);
  210. }
  211. return 1;
  212. }
  213. #if defined _ALS_IRC_OnUserSay
  214. #undef IRC_OnUserSay
  215. #else
  216. #define _ALS_IRC_OnUserSay
  217. #endif
  218. #define IRC_OnUserSay IRC_OUS
  219. forward IRC_OUS(botid, recipient[], user[], host[], message[]);