Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <sockets_async>
- #define PLUGIN "Pug Need"
- #define VERSION "1.0"
- #define AUTHOR "Sugisaki"
- new Trie:g_ips
- new Trie:g_com
- new Array:a_ips
- new key[] = "cbps_network"
- new pcvar_ip
- new gMsgSayText
- new last_call
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- register_clcmd("say", "cmd_redirect")
- //register_concmd("say .need", "send")
- register_concmd("t", "send")
- gMsgSayText = get_user_msgid("SayText")
- pcvar_ip = register_cvar("need_ip", "127.0.0.1:27015")
- new ip[32], port[7]
- get_user_ip(0, ip, 31)
- strtok(ip, ip, charsmax(ip), port, charsmax(port), ':', 1)
- new SOCKET:sock = socket_create(SOCK_TYPE_TCP, str_to_num(port))
- socket_bind(sock, ip, str_to_num(port))
- g_ips = TrieCreate()
- a_ips = ArrayCreate(64)
- g_com = TrieCreate()
- new file[] = "addons/amxmodx/configs/need.ini"
- if(!file_exists(file))
- {
- set_fail_state("need.ini no existe")
- return
- }
- new fh = fopen(file, "r")
- if(!fh)
- {
- set_fail_state("need.ini archivo ilegible")
- return
- }
- new line[43], com[10], szip[32]
- while(!feof(fh))
- {
- fgets(fh, line, charsmax(line))
- trim(line)
- if(!line[0] || line[0] == ';')
- {
- continue
- }
- parse(line, com, charsmax(com), szip, charsmax(szip))
- trim(com)
- trim(szip)
- if(!szip[0] || !com[0])
- {
- continue
- }
- TrieSetString(g_ips, szip, com)
- TrieSetString(g_com, com, szip)
- ArrayPushString(a_ips, szip)
- //server_print(com)
- }
- fclose(fh)
- }
- public send(id)
- {
- if(last_call > get_systime())
- {
- client_print(id, print_chat, "[NEED] Debes esperar %i segundos antes de volver a usar .need", last_call - get_systime())
- return PLUGIN_HANDLED
- }
- last_call = get_systime() + 10
- new start_id = 40
- new SOCKET:sock
- new ips[32], port, r[7]
- new data[128]
- new local_ip[32]
- get_pcvar_string(pcvar_ip, local_ip, charsmax(local_ip))
- for(new i = 0 ; i < ArraySize(a_ips) ; i++)
- {
- sock = socket_create(SOCK_TYPE_TCP, start_id + i)
- if(!sock)
- {
- client_print(id, print_chat, "[CBP] Error en la conexion remota")
- break
- }
- ArrayGetString(a_ips, i, ips, charsmax(ips))
- strtok(ips, ips, charsmax(ips), r, charsmax(r), ':', 1)
- port = str_to_num(r)
- if(socket_connect(sock, ips, port))
- {
- formatex(data, charsmax(data), "^"%s^" ^"%s^" ^"%i^"", key, local_ip, (get_maxplayers() - 1) - get_playersnum(1))
- if(!socket_send(sock, data, charsmax(data)))
- {
- client_print(id, print_chat, "[CBP] Error al enviar los datos a un servidor remoto")
- }
- socket_close(sock)
- }
- else
- {
- client_print(id, print_chat, "[CBP] Error al hacer la conexion remota")
- }
- }
- //client_print(id, print_chat, "[CBP] Se ha enviado un mensaje a los servidores afiliados")
- return PLUGIN_HANDLED
- }
- public fw_sockReadable(SOCKET:socket, customID, type)
- {
- new data[128]
- socket_recv(socket, data, charsmax(data))
- server_print(data)
- trim(data)
- new ip[32], players[4], enc_key[20]
- parse(data, enc_key, charsmax(enc_key), ip, charsmax(ip), players, charsmax(players))
- trim(enc_key)
- trim(players)
- trim(ip)
- if(data[0])
- {
- if(equal(enc_key, key))
- {
- new fmt[128], com[10]
- if(TrieKeyExists(g_ips, ip))
- {
- TrieGetString(g_ips, ip, com, charsmax(com))
- 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)
- message_begin(MSG_ALL, gMsgSayText)
- write_byte(33)
- write_string(fmt)
- message_end()
- }
- else
- {
- log_amx("ip: %s no esta en la lista need.ini | %s", ip, data)
- }
- }
- }
- socket_close(socket)
- }
- public cmd_redirect(id)
- {
- new arg[10], ip[32]
- read_argv(1, arg, 9)
- strtolower(arg)
- if(equal(arg, ".need"))
- {
- send(id)
- return PLUGIN_HANDLED
- }
- if(TrieKeyExists(g_com, arg))
- {
- TrieGetString(g_com, arg, ip, charsmax(ip))
- format(ip, charsmax(ip), "connect %s", ip)
- client_cmd2(id, ip)
- return PLUGIN_HANDLED
- }
- return PLUGIN_CONTINUE
- }
- stock client_cmd2(id, cmd[])
- {
- message_begin(MSG_ONE, SVC_DIRECTOR, _, id)
- write_byte(strlen(cmd) + 2)
- write_byte(10)
- write_string(cmd)
- message_end()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement