hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2025.10.11. 19:13



Jelenlévő felhasználók

Jelenleg 332 felhasználó van jelen :: 2 regisztrált, 0 rejtett és 330 vendég

A legtöbb felhasználó (2883 fő) 2025.07.30. 16:00-kor tartózkodott itt.

Regisztrált felhasználók: Baidu [Spider], Bing [Bot]az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása Hozzászólás a témához  [3 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: Plugin lezárva, wtf?
HozzászólásElküldve:2012.07.25. 14:00 
Offline
Őstag
Avatar

Csatlakozott:2012.02.14. 15:09
Hozzászólások:1423
Megköszönték neki: 2 alkalommal
Ez mi ? cvarokat se tudom szerkeszteni és ki-be kapcsolásnál aztírja lezárva.Működni se nagyon akar.


Csatolmányok:
wtf.PNG
wtf.PNG [20.77KiB |Megtekintve 259 alkalommal ]

_________________
Kép
Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: Plugin lezárva, wtf?
HozzászólásElküldve:2012.07.25. 19:07 
Offline
Developer
Avatar

Csatlakozott:2011.06.01. 21:11
Hozzászólások:7966
Megköszönt másnak: 295 alkalommal
Megköszönték neki: 537 alkalommal
forráskód?

_________________
http://www.easyrankup.eu


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: Plugin lezárva, wtf?
HozzászólásElküldve:2012.07.25. 19:57 
Offline
Őstag
Avatar

Csatlakozott:2012.02.14. 15:09
Hozzászólások:1423
Megköszönték neki: 2 alkalommal
Kód:
  1. /*

  2.         Plugin: Remember the Score

  3.         Current Version: 1.0.791

  4.        

  5.         Author: Nextra

  6.         E-Mail: nextra.24@gmail.com

  7.        


  8.        

  9.                         AMX Mod X script.

  10.                

  11.                 This program is free software; you can redistribute it and/or modify it

  12.                 under the terms of the GNU General Public License as published by the

  13.                 Free Software Foundation; either version 2 of the License, or (at

  14.                 your option) any later version.

  15.  

  16.                 This program is distributed in the hope that it will be useful, but

  17.                 WITHOUT ANY WARRANTY; without even the implied warranty of

  18.                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

  19.                 General Public License for more details.

  20.  

  21.                 You should have received a copy of the GNU General Public License

  22.                 along with this program; if not, write to the Free Software Foundation,

  23.                 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

  24.  

  25.                 In addition, as a special exception, the author gives permission to

  26.                 link the code of this program with the Half-Life Game Engine ("HL

  27.                 Engine") and Modified Game Libraries ("MODs") developed by Valve,

  28.                 L.L.C ("Valve"). You must obey the GNU General Public License in all

  29.                 respects for all of the code used other than the HL Engine and MODs

  30.                 from Valve. If you modify this file, you may extend this exception

  31.                 to your version of the file, but you are not obligated to do so. If

  32.                 you do not wish to do so, delete this exception statement from your

  33.                 version.

  34.        

  35.         .: Description

  36.        

  37.                 This plugin will keep track of players' scores through a mysql (or optionally sqlite) database.

  38.                 Everytime the user joins the server his score will be set to what is saved in the database (i.e.

  39.                 the score he has left the server with last time).

  40.                 It was done as per request.

  41.                

  42.         .: Features

  43.        

  44.                 - Automatic saving on disconnect + configurable prevention saving to minimize loss of data after a crash

  45.                 - Automatic pruning and per-map storing

  46.                 - Uses threaded-querying

  47.                 - Configuration of when and what to save

  48.                 - API to allow for easy implementation into other plugins

  49.                

  50.         .: Cvars

  51.        

  52.                 rts_host        - DB Host

  53.                 rts_user        - DB User

  54.                 rts_pass        - DB Password

  55.                 rts_db          - DB

  56.                 rts_table       - DB Table

  57.                 rts_type        - DB Type (mysql or sqlite)

  58.                 rts_auth        - Track users by:

  59.                                                 0 = steamid

  60.                                                 1 = ip

  61.                                                 2 = name

  62.                 rts_max         - Maximum of Score/Deaths to save (score saved in db will not go beyond this value)

  63.                 rts_min         - Score minimum to save (deaths minimum if rts_track = 2)

  64.                 rts_prune       - When to prune data (in days, 0 = disable)

  65.                 rts_permap      - Only save for one map. Table gets emptied completely on a new map. (Overrides rts_prune, rts_max and rts_min)

  66.                 rts_track       - What to track:

  67.                                                 1 = track score

  68.                                                 2 = track deaths

  69.                                                 3 = track both

  70.                                                 0 = plugin disabled

  71.                 rts_save        - The plugin saves on disconnect, additionally (prevents loss of data on crash) save on:

  72.                                                 0 = never

  73.                                                 1 = roundend

  74.                                                 2 = every respawn (for deathmatch servers)

  75.                                                 3 = every score update (may cause lots of traffic)

  76.        

  77.         .: Required Modules

  78.        

  79.                 - CStrike

  80.                 - FakeMeta

  81.                 - Ham Sandwich

  82.                 - MySQL / SQLite

  83.                

  84.         .: Notes

  85.        

  86.                 #1 - I know that there is a plugin that essentially does the same but as I said this was a request,

  87.                 done due to the other one not working for the requester. I just wanted to share this in the hope it

  88.                 will be useful for others. For clearance why there are no credits: This was entirely done from scratch -

  89.                 no code was taken from any (esp. not rememberthefrags) plugins in the creation process.

  90.                

  91.                 #2 - I made the plugin rts_complement to showcase the API functions of RTS. It is made to be used

  92.                 as a reference and therefore only includes limited features, do not expect anything special from it.

  93.                

  94.                 #3 - This plugin did not go through much testing, unlike I usually prefer to do it with my stuff.

  95.                 This is because I currently do not need it myself. It is, however, working without errors for a few

  96.                 days on the     requesters server (MySQL). SQLite has been only tested locally but everything should work

  97.                 fine. Please report any bugs you may encounter.

  98.        

  99.         .: Changelog

  100.        

  101.                 * 1.0.785

  102.                 - Initial release.

  103.                

  104.                 * 1.0.786

  105.                 - Optimization by caching is_user_connected and is_user_bot.

  106.                

  107.                 * 1.0.790

  108.                 - Implemented cvar to define how players are tracked (steamid, ip, name).

  109.                

  110.                 * 1.0.791

  111.                 - Fixed not escaping strings for nickname saving.

  112.                

  113.                 * 1.0.800

  114.                 - Fixed Auth problems.

  115.                 - Added integrity checks and sync setting for SQLite, fixing problems that occured for some.

  116.                

  117.                 * 1.0.810

  118.                 - Fixed typo.

  119.                 - Changed errorlogging in startup routine to now use set_fail_and_fwd.

  120. */

  121.  

  122. #pragma semicolon 1

  123. #pragma ctrlchar '\'

  124.  

  125. #pragma loadlib sqlite

  126. #pragma loadlib mysql

  127.  

  128. #include <amxmodx>

  129. #include <amxmisc>

  130. #include <cstrike>

  131. #include <fakemeta>

  132. #include <hamsandwich>

  133. #include <sqlx>

  134.  

  135. //----------------------------------------------------------------------------------------

  136. // Do not change anything below this line if you don't know exactly what you are doing!

  137. //----------------------------------------------------------------------------------------

  138. new const PLUGIN[]      = "Remember the Score";

  139. new const VERSION[] = "1.0.810";

  140. new const AUTHOR[]      = "Nextra";

  141.  

  142. #define IsValidPlayer(%1) ( 1 <= %1 <= g_iMaxPlayers )

  143.  

  144. new g_szQuery[512];

  145.  

  146. new Handle:g_SqlTuple, Handle:g_SqlConn;

  147.  

  148. new g_Table[64], g_Auth, g_msgid_ScoreInfo, g_iMaxPlayers, g_iAuthFwd, g_iActiveFwd, g_iDeActiveFwd, g_iFwdReturn;

  149.  

  150. new p_Host, p_User, p_Pass, p_Db, p_Table, p_Type, p_Auth, p_Max, p_Min, p_Prune, p_Permap, p_Track, p_Save;

  151.  

  152. enum STORAGE

  153. {

  154.         SCORE,

  155.         DEATHS,

  156.         USERID,

  157.         CONNECT,

  158.         BOT,

  159.         SETUP

  160. };

  161.  

  162. new g_Storage[33][STORAGE];

  163.  

  164. enum

  165. {

  166.         TRACK_SCORE,

  167.         TRACK_DEATHS

  168. };

  169.  

  170. enum DBTYPES

  171. {

  172.         MYSQL,

  173.         SQLITE

  174. };

  175.  

  176. new DBTYPES:g_DBType;

  177.  

  178. new szTimeStamp[DBTYPES][] =

  179. {

  180.         "UNIX_TIMESTAMP( )",

  181.         "strftime( '%s', 'now', 'localtime' )"

  182. };

  183.  

  184. enum

  185. {

  186.         SETUP_PLAYER,

  187.         SAVE_PLAYER,

  188.         INSERT_PLAYER

  189. };

  190.  

  191. const TASK_SETUP = 1230;

  192.  

  193. public plugin_natives( )

  194. {

  195.         register_library( "rememberthescore" );

  196.        

  197.         register_native( "rts_save_score"       , "_native_save_player"         );

  198.         register_native( "rts_update_score"     , "_native_update_player"       );

  199.         register_native( "rts_is_authorized", "_native_is_authorized"   );

  200. }

  201.  

  202.  

  203. public plugin_init( )

  204. {

  205.         register_plugin( PLUGIN, VERSION, AUTHOR );

  206.         register_cvar( "rts_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY );

  207.        

  208.         g_msgid_ScoreInfo = get_user_msgid( "ScoreInfo" );

  209.        

  210.         p_Host          = register_cvar( "rts_host"             , ""            , FCVAR_PROTECTED       ),

  211.         p_User          = register_cvar( "rts_user"             , ""            , FCVAR_PROTECTED       ),

  212.         p_Pass          = register_cvar( "rts_pass"             , ""            , FCVAR_PROTECTED       ),

  213.         p_Db            = register_cvar( "rts_db"               , ""            , FCVAR_PROTECTED       ),

  214.         p_Table         = register_cvar( "rts_table"    , ""            , FCVAR_PROTECTED       ),

  215.         p_Type          = register_cvar( "rts_type"             , "mysql"       , FCVAR_PROTECTED       ),

  216.         p_Auth          = register_cvar( "rts_auth"             , "0"           ),

  217.         p_Max           = register_cvar( "rts_max"              , "1000"        ),

  218.         p_Min           = register_cvar( "rts_min"              , "0"           ),

  219.         p_Prune         = register_cvar( "rts_prune"    , "0"           ),

  220.         p_Permap        = register_cvar( "rts_permap"   , "0"           ),

  221.         p_Track         = register_cvar( "rts_track"    , "3"           ),

  222.         p_Save          = register_cvar( "rts_save"             , "0"           );

  223.        

  224.         RegisterHam( Ham_Spawn, "player", "on_Spawn", 1 );  

  225.        

  226.         register_logevent( "on_RoundEnd", 2, "1=Round_End" );

  227.         register_message( g_msgid_ScoreInfo, "msg_ScoreInfo" );

  228.        

  229.         g_iAuthFwd              = CreateMultiForward( "rts_user_authorized"     , ET_IGNORE, FP_CELL );

  230.         g_iDeActiveFwd  = CreateMultiForward( "rts_plugin_inactive"     , ET_IGNORE, FP_CELL );

  231.         g_iActiveFwd    = CreateMultiForward( "rts_plugin_active"       , ET_IGNORE );

  232.        

  233.         if( !g_iAuthFwd )

  234.                 log_amx( "[RTS] Authorized forward could not be created. Other plugins may malfunction." );

  235.         if( !g_iDeActiveFwd )

  236.                 log_amx( "[RTS] Deactivation forward could not be created. Other plugins may malfunction." );

  237.         if( !g_iActiveFwd )

  238.                 log_amx( "[RTS] Activation forward could not be created. Other plugins may malfunction." );

  239.        

  240.         g_iMaxPlayers = get_maxplayers( );

  241. }

  242.  

  243. public plugin_cfg( )

  244. {

  245.         new szFile[128];

  246.         get_configsdir( szFile, charsmax(szFile) );

  247.         add( szFile, charsmax(szFile), "/sql.cfg" );

  248.        

  249.         server_cmd( "exec %s", szFile );

  250.         server_exec( );

  251.        

  252.         new szAffinity[8], szNewAffinity[8];

  253.        

  254.         get_pcvar_string( p_Type, szNewAffinity, charsmax(szNewAffinity) );

  255.         SQL_GetAffinity( szAffinity, charsmax(szAffinity) );

  256.        

  257.         if( !equali( szAffinity, szNewAffinity ) )

  258.         {

  259.                 if( !SQL_SetAffinity( szNewAffinity ) )

  260.                         log_amx( "Failed to set database type from %s to %s.", szAffinity, szNewAffinity );

  261.                 else

  262.                         szAffinity = szNewAffinity;

  263.         }

  264.        

  265.         if( equali( szAffinity, "mysql" ) )

  266.                 g_DBType = MYSQL;

  267.         else if( equali( szAffinity, "sqlite" ) )

  268.                 g_DBType = SQLITE;

  269.         else

  270.                 set_fail_and_fwd( "[RTS] Unsupported database type" );

  271.        

  272.        

  273.         new szHost[32], szUser[32], szPass[32], szDb[32];

  274.        

  275.         get_pcvar_string( p_Host, szHost, charsmax(szHost)      );

  276.         get_pcvar_string( p_User, szUser, charsmax(szUser)      );

  277.         get_pcvar_string( p_Pass, szPass, charsmax(szPass)      );

  278.         get_pcvar_string( p_Db  , szDb  , charsmax(szDb)        );

  279.        

  280.         get_pcvar_string( p_Table, g_Table, charsmax(g_Table) );

  281.        

  282.         g_Auth = get_pcvar_num( p_Auth );

  283.        

  284.         g_SqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDb );

  285.        

  286.         if( g_SqlTuple == Empty_Handle )

  287.         {

  288.                 set_fail_and_fwd( "[RTS] Database handle could not be created." );

  289.                 return;

  290.         }

  291.        

  292.         new iError;

  293.        

  294.         g_SqlConn = SQL_Connect( g_SqlTuple, iError, g_szQuery, charsmax(g_szQuery) );

  295.        

  296.         if( g_SqlConn == Empty_Handle )

  297.         {

  298.                 set_fail_and_fwd( "[RTS] Database connection could not be established." );

  299.                 return;

  300.         }

  301.        

  302.         if( g_DBType == MYSQL )

  303.         {

  304.                 formatex( g_szQuery, charsmax(g_szQuery),

  305.                         "CREATE TABLE IF NOT EXISTS `%s` ( \

  306.                                 `id` INT NOT NULL AUTO_INCREMENT, \

  307.                                 `player_id` VARCHAR( 32 ) DEFAULT NULL, \

  308.                                 `score` INT( 11 ) NOT NULL DEFAULT '0', \

  309.                                 `deaths` INT( 11 ) NOT NULL DEFAULT '0', \

  310.                                 `time` INT( 11 ) NOT NULL DEFAULT '0', \

  311.                                 PRIMARY KEY ( `id` ), \

  312.                                 UNIQUE ( `player_id` ) \

  313.                         )",

  314.                 g_Table );

  315.         }

  316.         else

  317.         {

  318.                 formatex( g_szQuery, charsmax(g_szQuery),

  319.                         "CREATE TABLE IF NOT EXISTS `%s` ( \

  320.                                 `id` INTEGER PRIMARY KEY AUTOINCREMENT, \

  321.                                 `player_id` TEXT UNIQUE DEFAULT NULL, \

  322.                                 `score` INTEGER NOT NULL DEFAULT '0', \

  323.                                 `deaths` INTEGER NOT NULL DEFAULT '0', \

  324.                                 `time` INTEGER NOT NULL DEFAULT '0' \

  325.                         )",

  326.                 g_Table );

  327.         }

  328.        

  329.         SimpleQueryAndErr( g_SqlConn, g_szQuery );

  330.        

  331.         if( g_DBType == SQLITE )

  332.         {

  333.                 new Handle:SqlIntegrityQuery = SQL_PrepareQuery( g_SqlConn, "PRAGMA integrity_check" );

  334.                

  335.                 if( !SQL_Execute( SqlIntegrityQuery ) )

  336.                 {

  337.                         set_fail_and_fwd( "[RTS] Integrity check could not be performed. Ceasing any further operation." );

  338.                         return;

  339.                 }

  340.                

  341.                 new szIntegrity[64];

  342.                 if( SQL_NumResults( SqlIntegrityQuery ) )

  343.                 {

  344.                         SQL_ReadResult( SqlIntegrityQuery, 0, szIntegrity, charsmax(szIntegrity) );

  345.                 }

  346.  

  347.                 SQL_FreeHandle( SqlIntegrityQuery );

  348.  

  349.                 if( !equali( szIntegrity, "OK" ) )

  350.                 {

  351.                         log_amx( "[RTS] Integrity Check returned: %s", szIntegrity );

  352.                         set_fail_and_fwd( "[RTS] Integrity check failed. Ceasing any further operation." );

  353.                         return;

  354.                 }

  355.                

  356.                 if( !SimpleQueryAndErr( g_SqlConn, "PRAGMA synchronous = 1" ) )

  357.                 {

  358.                         set_fail_and_fwd( "[RTS] SQLite synchronous setting failed. Ceasing any further operation." );

  359.                         return;

  360.                 }

  361.         }

  362.        

  363.         if( get_pcvar_num( p_Permap ) )

  364.                 clean_db( );

  365.         else if( get_pcvar_num( p_Prune ) > 0 )

  366.                 prune_db( );

  367.         else

  368.                 SQL_FreeHandle( g_SqlConn );

  369. }

  370.  

  371.  

  372. public plugin_pause( )

  373. {

  374.         for( new id = 1; id <= g_iMaxPlayers; id++ )

  375.                 g_Storage[id][USERID] = 0;

  376.                

  377.         if( !ExecuteForward( g_iDeActiveFwd, g_iFwdReturn, 0 ) )

  378.                 log_amx( "[RTS] Error executing inactive forward." );

  379. }

  380.  

  381.  

  382. public plugin_unpause( )

  383. {

  384.         for( new id = 1; id <= g_iMaxPlayers; id++ )

  385.         {

  386.                 if( g_Storage[id][CONNECT] )

  387.                         setup_player( id );

  388.         }

  389.        

  390.         if( !ExecuteForward( g_iActiveFwd, g_iFwdReturn ) )

  391.                 log_amx( "[RTS] Error executing activation forward." );

  392. }

  393.  

  394.  

  395. clean_db( )

  396. {

  397.         if( g_DBType == MYSQL )

  398.         {

  399.                 formatex( g_szQuery, charsmax(g_szQuery),

  400.                         "TRUNCATE TABLE `%s`;",

  401.                 g_Table );

  402.         }

  403.         else

  404.         {

  405.                 formatex( g_szQuery, charsmax(g_szQuery),

  406.                         "DELETE FROM `%s`;",

  407.                 g_Table );

  408.         }

  409.        

  410.         SimpleQueryAndErr( g_SqlConn, g_szQuery );

  411.        

  412.         SQL_FreeHandle( g_SqlConn );

  413. }

  414.  

  415.  

  416. prune_db( )

  417. {

  418.         formatex( g_szQuery, charsmax(g_szQuery),

  419.                 "DELETE \

  420.                 FROM `%s` \

  421.                 WHERE %s - `time` > %d;",

  422.         g_Table, szTimeStamp[g_DBType], ( get_pcvar_num( p_Prune ) * 86400 ) );

  423.        

  424.         SimpleQueryAndErr( g_SqlConn, g_szQuery );

  425.        

  426.         SQL_FreeHandle( g_SqlConn );

  427. }

  428.  

  429.  

  430. public client_connect( id )

  431. {

  432.         g_Storage[id][SCORE]    = 0,

  433.         g_Storage[id][DEATHS]   = 0,

  434.         g_Storage[id][SETUP]    = 0,

  435.         g_Storage[id][USERID]   = 0;

  436. }

  437.  

  438.  

  439. public client_putinserver( id )

  440. {

  441.         g_Storage[id][CONNECT]  = 1,

  442.         g_Storage[id][BOT]              = is_user_bot( id );

  443. }

  444.  

  445.  

  446. public client_disconnect( id )

  447. {

  448.         save_player( id, 1 );

  449.         g_Storage[id][CONNECT] = 0;

  450. }

  451.  

  452.  

  453. public on_RoundEnd( )

  454. {

  455.         if( get_pcvar_num( p_Track ) && get_pcvar_num( p_Save ) == 1 )

  456.                 save_all( 0 );

  457. }

  458.  

  459.  

  460. public msg_ScoreInfo( )

  461. {

  462.         new id = get_msg_arg_int( 1 );

  463.        

  464.         if( !g_Storage[id][CONNECT] )

  465.                 return PLUGIN_CONTINUE;

  466.        

  467.         new iScore      = get_msg_arg_int( 2 ),

  468.                 iDeaths = get_msg_arg_int( 3 );

  469.        

  470.         if( !iScore && !iDeaths )

  471.         {

  472.                 if( !g_Storage[id][USERID] )

  473.                         setup_player( id );

  474.                 else

  475.                         set_score( id );

  476.         }

  477.         else

  478.         {

  479.                 g_Storage[id][SCORE]    = iScore,

  480.                 g_Storage[id][DEATHS]   = iDeaths;

  481.                

  482.                 if( get_pcvar_num( p_Save ) == 3 )

  483.                         save_player( id, 0 );

  484.         }

  485.        

  486.         return PLUGIN_CONTINUE;

  487. }

  488.  

  489.  

  490. public on_Spawn( const id )

  491. {

  492.         if( get_pcvar_num( p_Save ) == 2 )

  493.                 save_player( id, 0 );

  494. }

  495.  

  496.  

  497. public setup_player( id )

  498. {

  499.         if( id >= TASK_SETUP )

  500.                 id -= TASK_SETUP;

  501.        

  502.         if( g_Storage[id][SETUP] )

  503.                 return;

  504.         else if( g_Storage[id][BOT] )

  505.                 return;

  506.                

  507.         g_Storage[id][SETUP] = 1;

  508.        

  509.         new szAuth[32];

  510.         get_auth( id, szAuth, charsmax(szAuth) );

  511.                

  512.        

  513.         new data[2];

  514.         data[0] = SETUP_PLAYER,

  515.         data[1] = id;

  516.        

  517.         formatex( g_szQuery, charsmax(g_szQuery),

  518.                 "SELECT `score`, `deaths`, `id` \

  519.                 FROM `%s` \

  520.                 WHERE `player_id` = '%s';",

  521.         g_Table, szAuth );

  522.        

  523.         SQL_ThreadQuery( g_SqlTuple, "Handle_SQL", g_szQuery, data, sizeof data );

  524. }

  525.  

  526.  

  527. get_score( Handle:Query, const id )

  528. {

  529.         if( !g_Storage[id][CONNECT] )

  530.                 return;

  531.        

  532.         if( SQL_MoreResults( Query ) )

  533.         {

  534.                 new iTrack = get_pcvar_num( p_Track );

  535.                

  536.                 if( iTrack & (1<<TRACK_SCORE) )

  537.                         g_Storage[id][SCORE] = SQL_ReadResult( Query, 0 );

  538.                

  539.                 if( iTrack & (1<<TRACK_DEATHS) )

  540.                         g_Storage[id][DEATHS] = SQL_ReadResult( Query, 1 );

  541.                

  542.                 g_Storage[id][USERID] = SQL_ReadResult( Query, 2 );

  543.                

  544.                 set_score( id );

  545.                

  546.                 if( !ExecuteForward( g_iAuthFwd, g_iFwdReturn, id ) )

  547.                         log_amx( "[RTS] Error executing auth forward." );

  548.                        

  549.                 g_Storage[id][SETUP] = 0;

  550.         }

  551.         else

  552.         {

  553.                 new szAuth[32];

  554.                 get_auth( id, szAuth, charsmax(szAuth) );

  555.                

  556.                 new data[2];

  557.                 data[0] = INSERT_PLAYER,

  558.                 data[1] = id;

  559.                

  560.                 formatex( g_szQuery, charsmax(g_szQuery),

  561.                         "INSERT INTO `%s` \

  562.                         ( `player_id`, `time` ) \

  563.                         VALUES ( '%s', %s );",

  564.                 g_Table, szAuth, szTimeStamp[g_DBType] );

  565.                

  566.                 SQL_ThreadQuery( g_SqlTuple, "Handle_SQL", g_szQuery, data, sizeof data );

  567.         }

  568. }

  569.  

  570.  

  571. get_userid( Handle:Query, const id )

  572. {

  573.         if( !g_Storage[id][CONNECT] )

  574.                 return;

  575.        

  576.         g_Storage[id][SETUP] = 0;

  577.        

  578.         new uid = SQL_GetInsertId( Query );

  579.        

  580.         if( !uid )

  581.                 set_task( 1.0, "setup_player", TASK_SETUP + id );

  582.         else

  583.         {

  584.                 g_Storage[id][USERID] = uid;

  585.                

  586.                 if( !ExecuteForward( g_iAuthFwd, g_iFwdReturn, id ) )

  587.                         log_amx( "[RTS] Error executing auth forward." );

  588.         }

  589. }

  590.  

  591.  

  592. save_all( const iTimestamp )

  593. {

  594.         for( new id = 1; id <= g_iMaxPlayers; id++ )

  595.         {

  596.                 if( g_Storage[id][CONNECT] )

  597.                         save_player( id, iTimestamp );

  598.         }

  599. }

  600.  

  601.  

  602. save_player( const id, const iTimestamp )

  603. {

  604.         if( g_Storage[id][CONNECT] )

  605.         {

  606.                 if( g_Storage[id][BOT] || !g_Storage[id][USERID] )

  607.                         return;

  608.         }

  609.        

  610.         new iTrack = get_pcvar_num( p_Track );

  611.        

  612.         if( !iTrack )

  613.         {

  614.                 g_Storage[id][USERID] = 0;

  615.                 return;

  616.         }

  617.        

  618.         new iScore = g_Storage[id][SCORE], iDeaths = g_Storage[id][DEATHS];

  619.        

  620.         if( !get_pcvar_num( p_Permap ) )

  621.         {

  622.                 new iMax = get_pcvar_num( p_Max ), iMin = get_pcvar_num( p_Min );

  623.                

  624.                 if( iTrack == (1<<TRACK_DEATHS) && iDeaths < iMin )

  625.                         iDeaths = 0;

  626.                 else if( iScore < iMin )

  627.                         iScore = iDeaths = 0;

  628.                 else

  629.                 {

  630.                         iScore  = min( iScore, iMax ),

  631.                         iDeaths = min( iDeaths, iMax );

  632.                 }

  633.         }

  634.        

  635.         static const szTime[DBTYPES][] =

  636.         {

  637.                 ", `time` = UNIX_TIMESTAMP( )",

  638.                 ", `time` = strftime( '%s', 'now', 'localtime' )"

  639.         };

  640.        

  641.         new data[2];

  642.         data[0] = SAVE_PLAYER,

  643.         data[1] = id;

  644.        

  645.         formatex( g_szQuery, charsmax(g_szQuery),

  646.                 "UPDATE `%s` \

  647.                 SET `score` = '%i', `deaths` = '%i'%s \

  648.                 WHERE `id` = '%i';",

  649.         g_Table, ( iTrack & (1<<TRACK_SCORE) ? iScore : 0 ), ( iTrack & (1<<TRACK_DEATHS) ? iDeaths : 0 ),

  650.                 iTimestamp ? szTime[g_DBType] : "", g_Storage[id][USERID] );

  651.  

  652.         SQL_ThreadQuery( g_SqlTuple, "Handle_SQL", g_szQuery, data, sizeof data );

  653. }

  654.  

  655.  

  656. public _native_save_player( iPlugin, iParams )

  657. {

  658.         if( iParams != 1 )

  659.         {

  660.                 log_error( AMX_ERR_PARAMS, "[RTS] Allowed parameter count is 1." );

  661.                 return 0;

  662.         }

  663.  

  664.         new id = get_param( 1 );

  665.  

  666.         if( !IsValidPlayer( id ) )

  667.                 return 0;

  668.         else if( !g_Storage[id][CONNECT] || g_Storage[id][BOT] )

  669.                 return 0;

  670.                

  671.         save_player( id, 0 );

  672.        

  673.         return 1;

  674. }

  675.  

  676.  

  677. public _native_update_player( iPlugin, iParams )

  678. {

  679.         if( iParams != 1 )

  680.         {

  681.                 log_error( AMX_ERR_PARAMS, "[RTS] Allowed parameter count is 1." );

  682.                 return 0;

  683.         }

  684.  

  685.         new id = get_param( 1 );

  686.  

  687.         if( !IsValidPlayer( id ) )

  688.                 return 0;

  689.         else if( !g_Storage[id][CONNECT] || g_Storage[id][BOT] )

  690.                 return 0;

  691.        

  692.         new iScore = get_user_frags( id ), iDeaths = cs_get_user_deaths( id );

  693.        

  694.         if( iScore != g_Storage[id][SCORE] )

  695.                 g_Storage[id][SCORE] = iScore;

  696.        

  697.         if( iDeaths != g_Storage[id][DEATHS] )

  698.                 g_Storage[id][DEATHS] = iDeaths;

  699.                

  700.         return 1;

  701. }

  702.  

  703.  

  704. public _native_is_authorized( iPlugin, iParams )

  705. {

  706.         if( iParams != 1 )

  707.         {

  708.                 log_error( AMX_ERR_PARAMS, "[RTS] Allowed parameter count is 1." );

  709.                 return 0;

  710.         }

  711.        

  712.         new id = get_param( 1 );

  713.        

  714.         if( !IsValidPlayer( id ) )

  715.                 return 0;

  716.         else if( !g_Storage[id][CONNECT] || g_Storage[id][BOT] )

  717.                 return 0;

  718.        

  719.         return ( g_Storage[id][USERID] ? 1 : 0 );

  720. }

  721.  

  722.  

  723. set_score( const id )

  724. {

  725.         set_pev( id, pev_frags, float( g_Storage[id][SCORE] ) );

  726.         cs_set_user_deaths( id, g_Storage[id][DEATHS] );

  727.        

  728.         message_begin( MSG_ALL, g_msgid_ScoreInfo );

  729.         write_byte( id );

  730.         write_short( g_Storage[id][SCORE] );

  731.         write_short( g_Storage[id][DEATHS] );

  732.         write_short( 0 );

  733.         write_short( get_user_team( id ) );

  734.         message_end( );

  735. }

  736.  

  737.  

  738. public plugin_end( )

  739. {

  740.         DestroyForward( g_iDeActiveFwd  );

  741.         DestroyForward( g_iActiveFwd    );

  742.         DestroyForward( g_iAuthFwd              );

  743.         SQL_FreeHandle( g_SqlTuple              );

  744. }

  745.  

  746.  

  747. public Handle_SQL( iFailState, Handle:Query, szError[], iErrorcode, Data[], iSize, Float:fQueueTime )

  748. {

  749.         if( iFailState )

  750.         {

  751.                 SQL_GetQueryString( Query, g_szQuery, charsmax(g_szQuery) );

  752.                

  753.                 log_amx( "[RTS] Error: (%d) %s", iErrorcode, szError );

  754.                 log_amx( "[RTS] Query: %s", g_szQuery );

  755.                

  756.                 pause( "a" );

  757.                 return;

  758.         }

  759.        

  760.         // log_amx( "[RTS] fQueueTime: %f. Func: %i.", QueueTime, Data[0] );

  761.        

  762.         switch( Data[0] )

  763.         {

  764.                 case SETUP_PLAYER       : get_score     ( Query, Data[1] );

  765.                 case INSERT_PLAYER      : get_userid( Query, Data[1] );

  766.         }

  767. }

  768.  

  769.  

  770. get_auth( const id, szAuth[], iLen )

  771. {

  772.         switch( g_Auth )

  773.         {

  774.                 case 0: get_user_authid( id, szAuth, iLen );

  775.                 case 1: get_user_ip( id, szAuth, iLen, 1 );

  776.                 case 2:

  777.                 {      

  778.                         get_user_name( id, szAuth, iLen );

  779.        

  780.                         if( g_DBType == MYSQL )

  781.                                 replace_all( szAuth, iLen, "'"  , "\\'" );

  782.                         else

  783.                                 replace_all( szAuth, iLen, "'"  , "''"  );

  784.                 }

  785.         }

  786. }

  787.  

  788.  

  789. SimpleQueryAndErr( Handle:SqlCon, const szQuery[] )

  790. {

  791.         new szError[256];

  792.         if( !SQL_SimpleQuery( SqlCon, szQuery, szError, charsmax(szError) ) )

  793.         {

  794.                 log_amx( "[RTS] Error: %s", szError );

  795.                 log_amx( "[RTS] Query: %s", szQuery );

  796.        

  797.                 return 0;

  798.         }

  799.        

  800.         return 1;

  801. }

  802.  

  803.  

  804. set_fail_and_fwd( const szError[] )

  805. {

  806.         if( !ExecuteForward( g_iDeActiveFwd, g_iFwdReturn, 1 ) )

  807.                 log_amx( "[RTS] Error executing deactivation forward." );

  808.  

  809.         set_fail_state( szError );

  810. }

  811.  

_________________
Kép


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése: Rendezés 
Új téma nyitása Hozzászólás a témához  [3 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 12 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole