Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <sockets_hz>
- #define DEBUG
- #pragma tabsize 0
- #define PREFIX "[WAMod]"
- #define WAMOD_FILESIZE 4000
- new g_ListeningSocket // Наш шпион сокет.
- new HTML_FILE[WAMOD_FILESIZE] // Шаблон хранящийся в памяти
- public plugin_init() {
- register_plugin("WAMod", "0.1-indev", "Fedcomp")
- read_html()
- init_my_socket()
- }
- public plugin_end ()
- {
- socket_close(g_ListeningSocket)
- }
- // ======== UTILS ============ //
- // Получаем порт
- get_port(){
- return get_cvar_num("port")
- }
- // ======= </UTILS> ========== //
- // Читаем шаблон в память
- read_html(){
- new path[255]
- get_configsdir(path, charsmax(path))
- format(path, charsmax(path), "%s/wamod/wamod.html", path)
- // Если файла с шаблоном нет.
- if (!file_exists(path))
- set_fail_state("wamod.html is not found!!")
- new i_filehandle = fopen(path,"rb")
- new szBuffer[2048]
- while(!feof(i_filehandle))
- {
- fgets(i_filehandle, szBuffer, charsmax(szBuffer));
- if(!szBuffer[0] || szBuffer[0] == ';') continue;
- trim(szBuffer);
- format(HTML_FILE, WAMOD_FILESIZE, "%s%s", HTML_FILE, szBuffer)
- }
- fclose(i_filehandle)
- server_print("%s, (len: %i)", HTML_FILE, strlen(HTML_FILE))
- }
- // Создаем сокет на прослушку. Отсылаем телефонные переговоры в США
- init_my_socket() {
- new error //you're the error
- g_ListeningSocket = socket_listen("0.0.0.0", get_port(),SOCKET_TCP,error)
- socket_unblock(g_ListeningSocket)
- server_print("%s LISTENNING ANY IP ON PORT %d", PREFIX, get_port())
- // Делаем таймер на прослушку телефонных переговоров. Т.е таймер который раз в заданное время будет проверять на новые соединения
- set_task(0.1,"incoming_connection",0,"",0,"b")
- }
- format_output(output[], output_len){
- new html[output_len]
- }
- public incoming_connection() {
- new connection;
- if((connection = socket_accept(g_ListeningSocket)) > 0)
- {
- new html_reply[WAMOD_FILESIZE]
- #if defined DEBUG
- server_print("New Connection")
- #endif
- format(html_reply, charsmax(html_reply), HTML_FILE)
- socket_send(connection, html_reply, strlen(html_reply))
- socket_close(connection)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement