irc.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. SA-MP IRC Plugin v1.3.6
  3. Copyright © 2010 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. #pragma library irc
  20. // Natives
  21. native IRC_Connect(const server[], port, const nickname[], const realname[], const username[], bool:ssl = false, localip[] = "");
  22. native IRC_Quit(botid, const message[] = "");
  23. native IRC_JoinChannel(botid, const channel[], const key[] = "");
  24. native IRC_PartChannel(botid, const channel[], const message[] = "");
  25. native IRC_ChangeNick(botid, const nick[]);
  26. native IRC_SetMode(botid, const target[], const mode[]);
  27. native IRC_Say(botid, const target[], const message[]);
  28. native IRC_Notice(botid, const target[], const message[]);
  29. native IRC_IsUserOnChannel(botid, const channel[], const user[]);
  30. native IRC_InviteUser(botid, const channel[], const user[]);
  31. native IRC_KickUser(botid, const channel[], const user[], const message[] = "");
  32. native IRC_GetUserChannelMode(botid, const channel[], const user[], dest[]);
  33. native IRC_GetChannelUserList(botid, const channel[], dest[], maxlength = sizeof dest);
  34. native IRC_SetChannelTopic(botid, const channel[], const topic[]);
  35. native IRC_SendRaw(botid, const message[]);
  36. native IRC_CreateGroup();
  37. native IRC_DestroyGroup(groupid);
  38. native IRC_AddToGroup(groupid, botid);
  39. native IRC_RemoveFromGroup(groupid, botid);
  40. native IRC_GroupSay(groupid, const target[], const message[]);
  41. native IRC_GroupNotice(groupid, const target[], const message[]);
  42. // Callbacks
  43. forward IRC_OnConnect(botid);
  44. forward IRC_OnDisconnect(botid);
  45. forward IRC_OnJoinChannel(botid, channel[]);
  46. forward IRC_OnLeaveChannel(botid, channel[], message[]);
  47. forward IRC_OnUserDisconnect(botid, user[], host[], message[]);
  48. forward IRC_OnUserJoinChannel(botid, channel[], user[], host[]);
  49. forward IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[]);
  50. forward IRC_OnUserNickChange(botid, oldnick[], newnick[], host[]);
  51. forward IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[]);
  52. forward IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[]);
  53. forward IRC_OnUserSay(botid, recipient[], user[], host[], message[]);
  54. forward IRC_OnUserNotice(botid, recipient[], user[], host[], message[]);
  55. forward IRC_OnReceiveRaw(botid, message[]);
  56. // Stock Functions
  57. stock
  58. IRC_IsVoice(botid, channel[], user[])
  59. {
  60. new
  61. mode[2];
  62. IRC_GetUserChannelMode(botid, channel, user, mode);
  63. switch (mode[0])
  64. {
  65. case '+', '%', '@', '&', '!', '*', '~', '.':
  66. {
  67. return 1;
  68. }
  69. }
  70. return 0;
  71. }
  72. stock
  73. IRC_IsHalfop(botid, channel[], user[])
  74. {
  75. new
  76. mode[2];
  77. IRC_GetUserChannelMode(botid, channel, user, mode);
  78. switch (mode[0])
  79. {
  80. case '%', '@', '&', '!', '*', '~', '.':
  81. {
  82. return 1;
  83. }
  84. }
  85. return 0;
  86. }
  87. stock
  88. IRC_IsOp(botid, channel[], user[])
  89. {
  90. new
  91. mode[2];
  92. IRC_GetUserChannelMode(botid, channel, user, mode);
  93. switch (mode[0])
  94. {
  95. case '@', '&', '!', '*', '~', '.':
  96. {
  97. return 1;
  98. }
  99. }
  100. return 0;
  101. }
  102. stock
  103. IRC_IsAdmin(botid, channel[], user[])
  104. {
  105. new
  106. mode[2];
  107. IRC_GetUserChannelMode(botid, channel, user, mode);
  108. switch (mode[0])
  109. {
  110. case '&', '!', '*', '~', '.':
  111. {
  112. return 1;
  113. }
  114. }
  115. return 0;
  116. }
  117. stock
  118. IRC_IsOwner(botid, channel[], user[])
  119. {
  120. new
  121. mode[2];
  122. IRC_GetUserChannelMode(botid, channel, user, mode);
  123. switch (mode[0])
  124. {
  125. case '~', '.':
  126. {
  127. return 1;
  128. }
  129. }
  130. return 0;
  131. }
  132. // Command system for users in IRC channels
  133. // Slightly modified zcmd (original by ZeeX)
  134. #define CHANNEL_PREFIX '#'
  135. #define COMMAND_PREFIX '!'
  136. #define IRCCMD:%1(%2) \
  137. forward irccmd_%1(%2); \
  138. public irccmd_%1(%2)
  139. #define irccmd(%1,%2,%3,%4,%5,%6) \
  140. IRCCMD:%1(%2, %3, %4, %5, %6)
  141. #if !defined isnull
  142. #define isnull(%1) \
  143. ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  144. #endif
  145. static
  146. bool:IRC_g_OUS = false;
  147. public
  148. OnFilterScriptInit()
  149. {
  150. IRC_g_OUS = funcidx("IRC_OUS") != -1;
  151. if (funcidx("IRC_OnFilterScriptInit") != -1)
  152. {
  153. return CallLocalFunction("IRC_OnFilterScriptInit", "");
  154. }
  155. return 1;
  156. }
  157. #if defined _ALS_OnFilterScriptInit
  158. #undef OnFilterScriptInit
  159. #else
  160. #define _ALS_OnFilterScriptInit
  161. #endif
  162. #define OnFilterScriptInit IRC_OnFilterScriptInit
  163. forward
  164. IRC_OnFilterScriptInit();
  165. public
  166. OnGameModeInit()
  167. {
  168. IRC_g_OUS = funcidx("IRC_OUS") != -1;
  169. if (funcidx("IRC_OnGameModeInit") != -1)
  170. {
  171. return CallLocalFunction("IRC_OnGameModeInit", "");
  172. }
  173. return 1;
  174. }
  175. #if defined _ALS_OnGameModeInit
  176. #undef OnGameModeInit
  177. #else
  178. #define _ALS_OnGameModeInit
  179. #endif
  180. #define OnGameModeInit IRC_OnGameModeInit
  181. forward
  182. IRC_OnGameModeInit();
  183. public
  184. IRC_OnUserSay(botid, recipient[], user[], host[], message[])
  185. {
  186. if (recipient[0] == CHANNEL_PREFIX && message[0] == COMMAND_PREFIX)
  187. {
  188. new
  189. function[32],
  190. pos = 0;
  191. while (message[++pos] > ' ')
  192. {
  193. function[pos - 1] = tolower(message[pos]);
  194. }
  195. format(function, sizeof(function), "irccmd_%s", function);
  196. while (message[pos] == ' ')
  197. {
  198. pos++;
  199. }
  200. if (!message[pos])
  201. {
  202. CallLocalFunction(function, "dssss", botid, recipient, user, host, "\1");
  203. }
  204. else
  205. {
  206. CallLocalFunction(function, "dssss", botid, recipient, user, host, message[pos]);
  207. }
  208. }
  209. if (IRC_g_OUS)
  210. {
  211. return CallLocalFunction("IRC_OUS", "dssss", botid, recipient, user, host, message);
  212. }
  213. return 1;
  214. }
  215. #if defined _ALS_IRC_OnUserSay
  216. #undef IRC_OnUserSay
  217. #else
  218. #define _ALS_IRC_OnUserSay
  219. #endif
  220. #define IRC_OnUserSay IRC_OUS
  221. forward
  222. IRC_OUS(botid, recipient[], user[], host[], message[]);