Advertisement
AvasiloaeiFlorentin

test

Jan 25th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <sockets>
  4. #include <sqlx>
  5. #include <special_geoip>
  6.  
  7. #define PLUGIN "Evidenta"
  8. #define VERSION "1.1"
  9. #define AUTHOR "Author"
  10.  
  11. #define szHost "localhost"
  12. #define szUser "root"
  13. #define szPass "florentin12345"
  14. #define szDb "evidenta"
  15.  
  16. #define LOG_NUMEFISIER "RedirectStats.log" //nume fisier inscriere loguri
  17. #define CFG_NUMEFISIER "PSHLDS_Proprietar.cfg" //nume fisier incarcare setari cvar-uri
  18.  
  19. #define TAG_PLUGIN "[RWS]" //Redirect Web Stats - RWS
  20.  
  21. new gCvarRedirectIp, gCvarRedirectPort, gCvarRedirectPassword, gCvarRedirectHost;
  22. new gCvarRedirectPath, gCvarRedirectUsername, gCvarRedirectUpdate;
  23.  
  24. new gRedirectHost[ 50 ], gRedirectName[ 50 ], gRedirectPath[ 50 ];
  25.  
  26. new gError;
  27.  
  28. new Handle:g_SqlTuple
  29.  
  30. public plugin_init( )
  31. {
  32. register_plugin(PLUGIN, VERSION, AUTHOR)
  33.  
  34. g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDb, 10)
  35.  
  36. gCvarRedirectIp = register_cvar( "redirect_server", "global.csredstars.com" ); //ip-ul serverului pe care vei redirectiona jucatorii sau dns-ul lui
  37. gCvarRedirectPort = register_cvar( "redirect_serverport", "27015" ); //fara : doar portul serverului tercut in cvar-ul de deasupra
  38. gCvarRedirectPassword = register_cvar( "redirect_serverpw", "" ); //daca serverul are parola pune parola lui intre ghilimele
  39. gCvarRedirectHost = register_cvar( "redirect_host", "http://boost-master.net/" ); //adresa fara director
  40. gCvarRedirectPath = register_cvar( "redirect_path", "/test" ); //directorul in care se afla instalat scriptul si care vin dupa adresa de mai sus
  41. gCvarRedirectUsername = register_cvar( "redirect_username", "Florentin" ); //numele celui ce tine redirectul
  42.  
  43. gCvarRedirectUpdate = register_cvar( "redirect_uptime", "150" );
  44.  
  45. set_task( float( get_pcvar_num( gCvarRedirectUpdate ) ), "RedirectServer", _, _, _, "b" );
  46. }
  47.  
  48. public plugin_cfg( )
  49. {
  50. new szConfigsDir[ 32 ];
  51. get_configsdir( szConfigsDir, charsmax( szConfigsDir ) );
  52. new szFile[ 192 ];
  53. formatex( szFile, charsmax( szFile ), "%s/%s", szConfigsDir, CFG_NUMEFISIER );
  54.  
  55. if( file_exists( szFile ) )
  56. {
  57. server_cmd( "exec %s", szFile );
  58.  
  59. server_print( "%s Fisierul ^"%s^" a fost incarcat cu succes!", TAG_PLUGIN, szFile );
  60. /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
  61. //log_to_file( LOG_NUMEFISIER, "%s Fisierul <%s> a fost incarcat cu succes!", TAG_PLUGIN, szFile );
  62. }
  63. else
  64. {
  65. server_print( "%s Eroare! Fisierul ^"%s^" nu a fost gasit!", TAG_PLUGIN, szFile );
  66. /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
  67. //log_to_file( LOG_NUMEFISIER, "%s Eroare! Fisierul ^"%s^" nu a fost gasit!", TAG_PLUGIN, szFile );
  68. }
  69. }
  70.  
  71. public RedirectServer( )
  72. {
  73. new RedirectPort[ 10 ];
  74.  
  75. get_cvar_string( "port", RedirectPort, charsmax( RedirectPort ) );
  76. get_pcvar_string( gCvarRedirectHost, gRedirectHost, charsmax( gRedirectHost ) );
  77. get_pcvar_string( gCvarRedirectPath, gRedirectPath, charsmax( gRedirectPath ) );
  78. get_pcvar_string( gCvarRedirectUsername, gRedirectName, charsmax( gRedirectName ) );
  79.  
  80. new RedirectSocket = socket_open( gRedirectHost, 80, SOCKET_TCP, gError);
  81.  
  82. new szData[ 512 ];
  83. formatex( szData, charsmax( szData ), "GET %s/alive.php?p=%s&f=%s HTTP/1.1^r^nHost:%s^r^nConnection: close^r^n^r^n", gRedirectPath, RedirectPort, gRedirectName, gRedirectHost );
  84.  
  85. socket_send( RedirectSocket, szData, charsmax( szData ) );
  86.  
  87. /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
  88. //log_to_file( LOG_NUMEFISIER, "%s HeartBeat sent !", TAG_PLUGIN);
  89. }
  90.  
  91. public ServerPlayers( )
  92. {
  93. get_pcvar_string( gCvarRedirectHost, gRedirectHost, charsmax( gRedirectHost ) );
  94. get_pcvar_string( gCvarRedirectPath, gRedirectPath, charsmax( gRedirectPath ) );
  95. get_pcvar_string( gCvarRedirectUsername, gRedirectName, charsmax( gRedirectName ) );
  96.  
  97. new PlayerSocket = socket_open( gRedirectHost, 80, SOCKET_TCP, gError);
  98.  
  99. new PlayerCount[ 512 ];
  100. formatex( PlayerCount, charsmax( PlayerCount ), "GET %s/new.php?f=%s HTTP/1.1^r^nHost:%s^r^nConnection: close^r^n^r^n", gRedirectPath, gRedirectName, gRedirectHost );
  101.  
  102. socket_send( PlayerSocket, PlayerCount, charsmax( PlayerCount ) );
  103. }
  104.  
  105. public client_connect( id )
  106. {
  107. new szServerPassword[ 30 ], szServerIp[ 32 ];
  108.  
  109. get_pcvar_string( gCvarRedirectPassword, szServerPassword, charsmax( szServerPassword ) );
  110. get_pcvar_string( gCvarRedirectIp, szServerIp, charsmax( szServerIp ) );
  111.  
  112. if( is_user_connecting( id ) && !is_user_bot( id ) )
  113. {
  114. ServerPlayers( );
  115. }
  116.  
  117. if( get_playersnum( ) >= 0 )
  118. {
  119. if( ! equal( szServerPassword, "" ) )
  120. {
  121. client_cmd( id, "password %s", szServerPassword );
  122. }
  123. client_cmd( id, "wait;wait;wait;wait;wait;^"Connect^" %s:%d", szServerIp, get_pcvar_num( gCvarRedirectPort ) );
  124. }
  125.  
  126. if(is_user_bot(id)){
  127. server_cmd("kick #%d", id)
  128. return PLUGIN_HANDLED
  129. }
  130. inregistrare(id)
  131.  
  132. static sql[256]
  133. // --------------- Preluare IP -----------------
  134. //new szIp[32];
  135. //get_user_ip (id, szIp, charsmax(szIp), 1);
  136. //new Country[32];
  137. //geoip_country(szIp, Country, charsmax(Country));
  138. //new country[33];
  139. //new ip[32];
  140. //get_user_ip( id, ip, charsmax( ip ));
  141. //geoip_country( ip, country, charsmax( country ) );
  142.  
  143.  
  144. static Name[64], ip[64], Country[64], City[64], AreaCode[64];
  145. get_user_ip(id, ip, 63, 1);
  146. get_user_name(id, Name, 63);
  147. GeoipInfo(ip, GI_Country, Country, charsmax(Country));
  148. GeoipInfo(ip, GI_City, City, 63);
  149. GeoipInfo(ip, GI_CountryCode, AreaCode, charsmax(AreaCode));
  150. // -------------- Preluare Data -----------------
  151. static preluare_an[5],time_an;
  152. static preluare_luna[3],time_luna;
  153. static preluare_zi[3],time_zi;
  154. static preluare_ora[3],time_ora;
  155. static preluare_minute[3],time_minute;
  156. static preluare_secunde[3],time_secunde;
  157. get_time("%Y", preluare_an, 4);
  158. get_time("%m", preluare_luna, 2);
  159. get_time("%d", preluare_zi, 2);
  160. get_time("%H", preluare_ora, 2);
  161. get_time("%M", preluare_minute, 2);
  162. get_time("%S", preluare_secunde, 2);
  163. time_an = str_to_num(preluare_an);
  164. time_luna = str_to_num(preluare_luna);
  165. time_zi = str_to_num(preluare_zi);
  166. time_ora = str_to_num(preluare_ora);
  167. time_minute = str_to_num(preluare_minute);
  168. time_secunde = str_to_num(preluare_secunde);
  169.  
  170. formatex(sql, charsmax(sql), "INSERT INTO `logs` (`timeyear`, `timemonth`, `timeday`, `timehour`, `timeminute`, `timesecound`, `ip`, `type`, `name`, `country`, `areacode`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%s', 'cs', '%s', '%s', '%s'); ",time_an, time_luna, time_zi, time_ora, time_minute, time_secunde, ip, Name, Country, AreaCode);
  171. SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", sql)
  172.  
  173. return PLUGIN_CONTINUE
  174.  
  175. }
  176.  
  177. public IgnoreHandle(FailState, Handle:Query, szError[], Errcode)
  178. {
  179. QueryStatus(FailState, szError, Errcode)
  180. new DataNum
  181. while(SQL_MoreResults(Query))
  182. {
  183. DataNum = SQL_ReadResult(Query,0)
  184. server_print("zomg, some data: %s",DataNum)
  185. SQL_NextRow(Query)
  186. }
  187. SQL_FreeHandle(Query);
  188.  
  189. return PLUGIN_HANDLED;
  190. }
  191.  
  192. public client_putinserver(id){
  193. if(is_user_bot(id)){
  194. server_cmd("kick #%d", id)
  195. return PLUGIN_HANDLED
  196. }
  197.  
  198. set_task(3.0, "inregistrare", id)
  199.  
  200. return PLUGIN_CONTINUE
  201. }
  202.  
  203. public inregistrare(id){
  204.  
  205. return PLUGIN_CONTINUE
  206. }
  207.  
  208. public QueryStatus(FailState, szError[], Errcode){
  209.  
  210. static szDate[32], error[512]
  211.  
  212. get_time("%d.%m.%y - %H:%M:%S", szDate, 31)
  213.  
  214. if(FailState == TQUERY_CONNECT_FAILED){
  215. formatex(error, charsmax(error), "[MYSQL CONNECT ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
  216. write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
  217.  
  218. server_print("A aparut o eroare ! Info in logs !")
  219. }
  220. else if(FailState == TQUERY_QUERY_FAILED){
  221. formatex(error, charsmax(error), "[MYSQL QUERY ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
  222. write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
  223.  
  224. server_print("A aparut o eroare ! Info in logs !")
  225. }
  226. else if(Errcode){
  227. formatex(error, charsmax(error), "[MYSQL ERROR CODE] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
  228. write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
  229.  
  230. server_print("A aparut o eroare ! Info in logs !")
  231. }
  232.  
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement