irc.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (C) 2014 Incognito
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <a_samp>
  17. // Enumerator
  18. enum
  19. {
  20. E_IRC_CONNECT_ATTEMPTS,
  21. E_IRC_CONNECT_DELAY,
  22. E_IRC_CONNECT_TIMEOUT,
  23. E_IRC_RECEIVE_TIMEOUT,
  24. E_IRC_RESPAWN
  25. }
  26. // Natives
  27. native IRC_Connect(const server[], port, const nickname[], const realname[], const username[], bool:ssl = false, const localip[] = "", const serverpassword[] = "");
  28. native IRC_Quit(botid, const message[] = "");
  29. native IRC_JoinChannel(botid, const channel[], const key[] = "");
  30. native IRC_PartChannel(botid, const channel[], const message[] = "");
  31. native IRC_ChangeNick(botid, const nick[]);
  32. native IRC_SetMode(botid, const target[], const mode[]);
  33. native IRC_Say(botid, const target[], const message[]);
  34. native IRC_Notice(botid, const target[], const message[]);
  35. native IRC_IsUserOnChannel(botid, const channel[], const user[]);
  36. native IRC_InviteUser(botid, const channel[], const user[]);
  37. native IRC_KickUser(botid, const channel[], const user[], const message[] = "");
  38. native IRC_GetUserChannelMode(botid, const channel[], const user[], dest[]);
  39. native IRC_GetChannelUserList(botid, const channel[], dest[], maxlength = sizeof dest);
  40. native IRC_SetChannelTopic(botid, const channel[], const topic[]);
  41. native IRC_RequestCTCP(botid, const user[], const message[]);
  42. native IRC_ReplyCTCP(botid, const user[], const message[]);
  43. native IRC_SendRaw(botid, const message[]);
  44. native IRC_CreateGroup();
  45. native IRC_DestroyGroup(groupid);
  46. native IRC_AddToGroup(groupid, botid);
  47. native IRC_RemoveFromGroup(groupid, botid);
  48. native IRC_GroupSay(groupid, const target[], const message[]);
  49. native IRC_GroupNotice(groupid, const target[], const message[]);
  50. native IRC_SetIntData(botid, data, value);
  51. // Callbacks
  52. forward IRC_OnConnect(botid, ip[], port);
  53. forward IRC_OnDisconnect(botid, ip[], port, reason[]);
  54. forward IRC_OnConnectAttempt(botid, ip[], port);
  55. forward IRC_OnConnectAttemptFail(botid, ip[], port, reason[]);
  56. forward IRC_OnJoinChannel(botid, channel[]);
  57. forward IRC_OnLeaveChannel(botid, channel[], message[]);
  58. forward IRC_OnInvitedToChannel(botid, channel[], invitinguser[], invitinghost[]);
  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_OnReceiveNumeric(botid, numeric, message[]);
  72. forward IRC_OnReceiveRaw(botid, message[]);
  73. // Stock Functions
  74. stock IRC_IsVoice(botid, channel[], user[])
  75. {
  76. new 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 IRC_IsHalfop(botid, channel[], user[])
  88. {
  89. new mode[2];
  90. IRC_GetUserChannelMode(botid, channel, user, mode);
  91. switch (mode[0])
  92. {
  93. case '%', '@', '&', '!', '*', '~', '.':
  94. {
  95. return 1;
  96. }
  97. }
  98. return 0;
  99. }
  100. stock IRC_IsOp(botid, channel[], user[])
  101. {
  102. new mode[2];
  103. IRC_GetUserChannelMode(botid, channel, user, mode);
  104. switch (mode[0])
  105. {
  106. case '@', '&', '!', '*', '~', '.':
  107. {
  108. return 1;
  109. }
  110. }
  111. return 0;
  112. }
  113. stock IRC_IsAdmin(botid, channel[], user[])
  114. {
  115. new mode[2];
  116. IRC_GetUserChannelMode(botid, channel, user, mode);
  117. switch (mode[0])
  118. {
  119. case '&', '!', '*', '~', '.':
  120. {
  121. return 1;
  122. }
  123. }
  124. return 0;
  125. }
  126. stock IRC_IsOwner(botid, channel[], user[])
  127. {
  128. new mode[2];
  129. IRC_GetUserChannelMode(botid, channel, user, mode);
  130. switch (mode[0])
  131. {
  132. case '~', '.':
  133. {
  134. return 1;
  135. }
  136. }
  137. return 0;
  138. }
  139. // Channel Command System
  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. if (pos > (sizeof(function) - 1))
  193. {
  194. break;
  195. }
  196. }
  197. format(function, sizeof(function), "irccmd_%s", function);
  198. while (message[pos] == ' ')
  199. {
  200. pos++;
  201. }
  202. if (!message[pos])
  203. {
  204. CallLocalFunction(function, "dssss", botid, recipient, user, host, "\1");
  205. }
  206. else
  207. {
  208. CallLocalFunction(function, "dssss", botid, recipient, user, host, message[pos]);
  209. }
  210. }
  211. if (IRC_g_OUS)
  212. {
  213. return CallLocalFunction("IRC_OUS", "dssss", botid, recipient, user, host, message);
  214. }
  215. return 1;
  216. }
  217. #if defined _ALS_IRC_OnUserSay
  218. #undef IRC_OnUserSay
  219. #else
  220. #define _ALS_IRC_OnUserSay
  221. #endif
  222. #define IRC_OnUserSay IRC_OUS
  223. forward IRC_OUS(botid, recipient[], user[], host[], message[]);