Advertisement
Sugisaki

asadsasd

Apr 14th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <sockets_async>
  3.  
  4. #define PLUGIN "Pug Need"
  5. #define VERSION "1.0"
  6. #define AUTHOR "Sugisaki"
  7.  
  8. new Trie:g_ips
  9. new Trie:g_com
  10. new Array:a_ips
  11. new key[] = "cbps_network"
  12. new pcvar_ip
  13. new gMsgSayText
  14.  
  15. new last_call
  16.  
  17. public plugin_init()
  18. {
  19. register_plugin(PLUGIN, VERSION, AUTHOR)
  20. register_clcmd("say", "cmd_redirect")
  21. //register_concmd("say .need", "send")
  22. register_concmd("t", "send")
  23.  
  24. gMsgSayText = get_user_msgid("SayText")
  25. pcvar_ip = register_cvar("need_ip", "127.0.0.1:27015")
  26. new ip[32], port[7]
  27.  
  28. get_user_ip(0, ip, 31)
  29. strtok(ip, ip, charsmax(ip), port, charsmax(port), ':', 1)
  30.  
  31. new SOCKET:sock = socket_create(SOCK_TYPE_TCP, str_to_num(port))
  32. socket_bind(sock, ip, str_to_num(port))
  33. g_ips = TrieCreate()
  34. a_ips = ArrayCreate(64)
  35. g_com = TrieCreate()
  36. new file[] = "addons/amxmodx/configs/need.ini"
  37. if(!file_exists(file))
  38. {
  39. set_fail_state("need.ini no existe")
  40. return
  41. }
  42. new fh = fopen(file, "r")
  43. if(!fh)
  44. {
  45. set_fail_state("need.ini archivo ilegible")
  46. return
  47. }
  48. new line[43], com[10], szip[32]
  49. while(!feof(fh))
  50. {
  51. fgets(fh, line, charsmax(line))
  52.  
  53. trim(line)
  54. if(!line[0] || line[0] == ';')
  55. {
  56. continue
  57. }
  58. parse(line, com, charsmax(com), szip, charsmax(szip))
  59. trim(com)
  60. trim(szip)
  61. if(!szip[0] || !com[0])
  62. {
  63. continue
  64. }
  65. TrieSetString(g_ips, szip, com)
  66. TrieSetString(g_com, com, szip)
  67. ArrayPushString(a_ips, szip)
  68.  
  69.  
  70. //server_print(com)
  71. }
  72. fclose(fh)
  73. }
  74. public send(id)
  75. {
  76. if(last_call > get_systime())
  77. {
  78. client_print(id, print_chat, "[NEED] Debes esperar %i segundos antes de volver a usar .need", last_call - get_systime())
  79. return PLUGIN_HANDLED
  80. }
  81. last_call = get_systime() + 10
  82. new start_id = 40
  83. new SOCKET:sock
  84. new ips[32], port, r[7]
  85. new data[128]
  86. new local_ip[32]
  87. get_pcvar_string(pcvar_ip, local_ip, charsmax(local_ip))
  88.  
  89. for(new i = 0 ; i < ArraySize(a_ips) ; i++)
  90. {
  91. sock = socket_create(SOCK_TYPE_TCP, start_id + i)
  92. if(!sock)
  93. {
  94. client_print(id, print_chat, "[CBP] Error en la conexion remota")
  95. break
  96. }
  97. ArrayGetString(a_ips, i, ips, charsmax(ips))
  98. strtok(ips, ips, charsmax(ips), r, charsmax(r), ':', 1)
  99. port = str_to_num(r)
  100. if(socket_connect(sock, ips, port))
  101. {
  102. formatex(data, charsmax(data), "^"%s^" ^"%s^" ^"%i^"", key, local_ip, (get_maxplayers() - 1) - get_playersnum(1))
  103. if(!socket_send(sock, data, charsmax(data)))
  104. {
  105. client_print(id, print_chat, "[CBP] Error al enviar los datos a un servidor remoto")
  106.  
  107. }
  108. socket_close(sock)
  109. }
  110. else
  111. {
  112. client_print(id, print_chat, "[CBP] Error al hacer la conexion remota")
  113.  
  114. }
  115.  
  116. }
  117. //client_print(id, print_chat, "[CBP] Se ha enviado un mensaje a los servidores afiliados")
  118. return PLUGIN_HANDLED
  119. }
  120.  
  121. public fw_sockReadable(SOCKET:socket, customID, type)
  122. {
  123. new data[128]
  124. socket_recv(socket, data, charsmax(data))
  125. server_print(data)
  126. trim(data)
  127. new ip[32], players[4], enc_key[20]
  128. parse(data, enc_key, charsmax(enc_key), ip, charsmax(ip), players, charsmax(players))
  129. trim(enc_key)
  130. trim(players)
  131. trim(ip)
  132. if(data[0])
  133. {
  134. if(equal(enc_key, key))
  135. {
  136. new fmt[128], com[10]
  137. if(TrieKeyExists(g_ips, ip))
  138. {
  139. TrieGetString(g_ips, ip, com, charsmax(com))
  140.  
  141. formatex(fmt, charsmax(fmt), "^1[^4CBP^1] Se necesitan ^3%s ^1jugadores en ^4%s^1, escribe ^3%s ^1para redirigirte", players, com[1], com)
  142. message_begin(MSG_ALL, gMsgSayText)
  143. write_byte(33)
  144. write_string(fmt)
  145. message_end()
  146.  
  147. }
  148. else
  149. {
  150. log_amx("ip: %s no esta en la lista need.ini | %s", ip, data)
  151. }
  152. }
  153. }
  154. socket_close(socket)
  155. }
  156. public cmd_redirect(id)
  157. {
  158. new arg[10], ip[32]
  159. read_argv(1, arg, 9)
  160. strtolower(arg)
  161. if(equal(arg, ".need"))
  162. {
  163. send(id)
  164. return PLUGIN_HANDLED
  165. }
  166. if(TrieKeyExists(g_com, arg))
  167. {
  168. TrieGetString(g_com, arg, ip, charsmax(ip))
  169. format(ip, charsmax(ip), "connect %s", ip)
  170. client_cmd2(id, ip)
  171. return PLUGIN_HANDLED
  172. }
  173. return PLUGIN_CONTINUE
  174. }
  175. stock client_cmd2(id, cmd[])
  176. {
  177. message_begin(MSG_ONE, SVC_DIRECTOR, _, id)
  178. write_byte(strlen(cmd) + 2)
  179. write_byte(10)
  180. write_string(cmd)
  181. message_end()
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement