Advertisement
Fedcomp

Untitled

Nov 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <sockets_hz>
  4.  
  5. #define DEBUG
  6.  
  7. #pragma tabsize 0
  8.  
  9. #define PREFIX "[WAMod]"
  10. #define WAMOD_FILESIZE 4000
  11.  
  12. new g_ListeningSocket // Наш шпион сокет.
  13.  
  14. new HTML_FILE[WAMOD_FILESIZE]   // Шаблон хранящийся в памяти
  15.  
  16. public plugin_init() {
  17.         register_plugin("WAMod", "0.1-indev", "Fedcomp")
  18.        
  19.         read_html()
  20.         init_my_socket()
  21. }
  22.  
  23. public plugin_end ()
  24. {
  25.         socket_close(g_ListeningSocket)
  26. }
  27.  
  28. // ======== UTILS ============ //
  29.  
  30. // Получаем порт
  31. get_port(){
  32.     return get_cvar_num("port")
  33. }
  34.  
  35. // ======= </UTILS> ========== //
  36.  
  37. // Читаем шаблон в память
  38. read_html(){
  39.     new path[255]
  40.     get_configsdir(path, charsmax(path))
  41.     format(path, charsmax(path), "%s/wamod/wamod.html", path)
  42.    
  43.     // Если файла с шаблоном нет.
  44.     if (!file_exists(path))
  45.         set_fail_state("wamod.html is not found!!")
  46.  
  47.    
  48.     new i_filehandle = fopen(path,"rb")
  49.     new szBuffer[2048]
  50.    
  51.     while(!feof(i_filehandle))
  52.     {
  53.         fgets(i_filehandle, szBuffer, charsmax(szBuffer));
  54.         if(!szBuffer[0] || szBuffer[0] == ';') continue;
  55.         trim(szBuffer);
  56.         format(HTML_FILE, WAMOD_FILESIZE, "%s%s", HTML_FILE, szBuffer)
  57.     }
  58.    
  59.     fclose(i_filehandle)
  60.    
  61.     server_print("%s, (len: %i)", HTML_FILE, strlen(HTML_FILE))
  62. }
  63.  
  64. // Создаем сокет на прослушку. Отсылаем телефонные переговоры в США
  65. init_my_socket() {
  66.     new error //you're the error
  67.     g_ListeningSocket = socket_listen("0.0.0.0", get_port(),SOCKET_TCP,error)
  68.     socket_unblock(g_ListeningSocket)
  69.     server_print("%s LISTENNING ANY IP ON PORT %d", PREFIX, get_port())
  70.    
  71.     // Делаем таймер на прослушку телефонных переговоров. Т.е таймер который раз в заданное время будет проверять на новые соединения
  72.     set_task(0.1,"incoming_connection",0,"",0,"b")
  73. }
  74.  
  75. format_output(output[], output_len){
  76.     new html[output_len]
  77. }
  78.  
  79. public incoming_connection() {
  80.     new connection;
  81.  
  82.     if((connection = socket_accept(g_ListeningSocket)) > 0)
  83.     {
  84.         new html_reply[WAMOD_FILESIZE]
  85.        
  86.         #if defined DEBUG
  87.         server_print("New Connection")
  88.         #endif
  89.        
  90.         format(html_reply, charsmax(html_reply), HTML_FILE)
  91.         socket_send(connection, html_reply, strlen(html_reply))
  92.         socket_close(connection)
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement