Advertisement
Guest User

Untitled

a guest
May 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <map>
  3. #include <mysql++/mysql++.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. #include "interface.h"
  8.  
  9. #include "filesystem.h"
  10.  
  11. #include "engine/iserverplugin.h"
  12.  
  13. #include "dlls/iplayerinfo.h"
  14.  
  15. #include "eiface.h"
  16.  
  17. #include "igameevents.h"
  18.  
  19. #include "convar.h"
  20.  
  21. #include "Color.h"
  22.  
  23. #include "vstdlib/random.h"
  24.  
  25. #include "engine/IEngineTrace.h"
  26.  
  27.  
  28.  
  29. // memdbgon must be the last include file in a .cpp file!!!
  30.  
  31. #include "tier0/memdbgon.h"
  32.  
  33.  
  34.  
  35. // Interfaces from the engine
  36.  
  37. IVEngineServer  *engine = NULL; // helper functions (messaging clients, loading content, making entities, running commands, etc)
  38.  
  39. IFileSystem     *filesystem = NULL; // file I/O
  40.  
  41. IGameEventManager *gameeventmanager = NULL; // game events interface
  42.  
  43. IPlayerInfoManager *playerinfomanager = NULL; // game dll interface to interact with players
  44.  
  45. IBotManager *botmanager = NULL; // game dll interface to interact with bots
  46.  
  47. IServerPluginHelpers *helpers = NULL; // special 3rd party plugin helpers from the engine
  48.  
  49. IUniformRandomStream *randomStr = NULL;
  50.  
  51. IEngineTrace *enginetrace = NULL;
  52.  
  53.  
  54. mysqlpp::Connection conn(false);   
  55. const char* db = "csrank", *server = "localhost", *user = "csrank", *pass = "132009828";
  56.  
  57. CGlobalVars *gpGlobals = NULL;
  58.  
  59.  
  60.  
  61. // function to initialize any cvars/command in this plugin
  62.  
  63. void InitCVars( CreateInterfaceFn cvarFactory );
  64.  
  65.  
  66.  
  67. // useful helper func
  68.  
  69. inline bool FStrEq(const char *sz1, const char *sz2)
  70.  
  71. {
  72.  
  73.     return(Q_stricmp(sz1, sz2) == 0);
  74.  
  75. }
  76.  
  77.  
  78. class User
  79. {
  80. public:
  81.     User( char const *UserName, char const *UserPassword );
  82.     ~User();
  83.     virtual int     RecheckAuth (char const *UserName, char const *UserPassword);
  84.     virtual int GetSessionID (void);
  85.     virtual int     GetDataBaseID (void);
  86.     virtual int     BecomeNobody (void);
  87.     virtual int     CloseSession (int session, char const *Reason); //TODO move to plugin namespace
  88.    
  89.     virtual int player_death (int attacker_sessionid, char const *weapon, bool headshot);
  90.     virtual int player_hurt (int attacker_sessionid, int health, int armor, char const *weapon, int dmg_health, int dmg_armor, int hitgroup);
  91.     virtual int hostage_killed (void);
  92.     virtual int hostage_rescued(void);
  93.     virtual int bomb_defused(int site);
  94.     virtual int bomb_exploded(int site);
  95.     virtual int player_team(int newteam);
  96.  
  97. private:
  98.     int SessionID;
  99.     int DataBaseID;
  100.     virtual int TestUserInfo (char const *UserName, char const *UserPassword); 
  101.     virtual int UpdateUserID (int NewUserID);
  102.     virtual int CreateSession (int ownerid);  //TODO move to plugin namespace
  103. };
  104.  
  105. int User::player_death (int attacker_sessionid, char const *weapon, bool headshot)
  106. {
  107.     mysqlpp::Query query = conn.query();
  108.     query << "INSERT INTO player_death VALUES (0," << SessionID << ", " << attacker_sessionid << ", " << mysqlpp::quote << weapon  <<", " << headshot << ");";
  109.     return query.exec();
  110.  
  111. }
  112.  
  113. int User::player_hurt (int attacker_sessionid, int health, int armor, char const *weapon, int dmg_health, int dmg_armor, int hitgroup)
  114. {
  115.     mysqlpp::Query query = conn.query();
  116.     query << "INSERT INTO player_hurt VALUES (0," << SessionID << ", " << attacker_sessionid << ", " << health << ", " << armor << ", " << mysqlpp::quote << weapon  <<", " << dmg_health << ", " << dmg_armor << ", " << hitgroup << ");";
  117.     return query.exec();   
  118.  
  119. }
  120.  
  121. int User::hostage_killed (void)
  122. {
  123.     mysqlpp::Query query = conn.query();
  124.     query << "INSERT INTO hostage_killed VALUES (0, " << SessionID << ");";
  125.     return query.exec();
  126.  
  127. }
  128.  
  129. int User::hostage_rescued (void)
  130. {
  131.     mysqlpp::Query query = conn.query();
  132.     query << "INSERT INTO hostage_rescued VALUES (0, " << SessionID << ");";
  133.     return query.exec();
  134.  
  135. }
  136.  
  137. int User::bomb_defused(int site)
  138. {
  139.     mysqlpp::Query query = conn.query();
  140.     query << "INSERT INTO bomb_defused VALUES (0, " << SessionID << ", " << site << ");";
  141.     return query.exec();
  142.  
  143. }
  144.  
  145. int User::bomb_exploded(int site)
  146. {
  147.     mysqlpp::Query query = conn.query();
  148.     query << "INSERT INTO bomb_exploded VALUES (0, " << SessionID << ", " << site << ");";
  149.     return query.exec();
  150. }
  151.  
  152. int User::player_team(int newteam)
  153. {
  154.     mysqlpp::Query query = conn.query();
  155.     query << "INSERT INTO player_team VALUES (0, " << SessionID << ", " << newteam << ");";
  156.     return query.exec();
  157.  
  158. }
  159.  
  160. int User::BecomeNobody (void)
  161. {
  162.     return UpdateUserID (1);
  163. }
  164.  
  165. int User::CloseSession (int session, char const *Reason)
  166. {
  167.     mysqlpp::Query query = conn.query();
  168.    
  169.     query << "UPDATE session SET session_end = now() , reason = " << mysqlpp::quote << Reason << "WHERE id = " << session;
  170.     return query.exec();
  171. }
  172.  
  173. int     User::UpdateUserID (int NewUserID)
  174. {
  175.     mysqlpp::Query query = conn.query();
  176.    
  177.     DataBaseID = NewUserID;
  178.  
  179.     query << "UPDATE session SET user_id = " << NewUserID << " WHERE id = " << SessionID;
  180.     return query.exec();
  181. }
  182.  
  183. int User::RecheckAuth (char const *UserName, char const *UserPassword)
  184. {
  185.     int newid = TestUserInfo(UserName, UserPassword);
  186.  
  187.     if (newid == 1)
  188.         return false;
  189.     else
  190.        if (newid == DataBaseID)
  191.         return true;
  192.        else
  193.         UpdateUserID (newid);
  194. }
  195.  
  196. int     User::TestUserInfo (char const *UserName, char const *UserPassword)
  197. {
  198.     mysqlpp::Query query = conn.query();
  199.  
  200.     query << "select id from user where login = " << mysqlpp::quote << UserName << " and pass = " << mysqlpp::quote << UserPassword;
  201.     mysqlpp::UseQueryResult res = query.use();
  202.     if (res) {
  203.         if (mysqlpp::Row row = res.fetch_row())
  204.             return row["id"];  
  205.         else
  206.             return 1;
  207.     } else
  208.         return 1;
  209. }
  210.  
  211. int User::GetDataBaseID (void)
  212. {
  213.     return DataBaseID;
  214. }
  215.  
  216. int User::GetSessionID (void)
  217. {
  218.     return SessionID;
  219. }
  220.  
  221. int     User::CreateSession (int ownerid)
  222. {
  223.     mysqlpp::Query query = conn.query();
  224.     query << "INSERT INTO session VALUES (0," << ownerid << ", now(), '0000-00-00 00:00:00', '0', '0', '0', '0', '');";
  225.     query.execute();
  226.     return query.insert_id();
  227. }
  228.  
  229. User::User (char const *UserName, char const *UserPassword)
  230. {  
  231.     DataBaseID= TestUserInfo(UserName, UserPassword);
  232.     SessionID = CreateSession(DataBaseID);
  233. }
  234.  
  235. User::~User ()
  236. {
  237.     //CloseSession(SessionID, Reason);
  238. }
  239.  
  240.  
  241. //  userid User
  242. std::map<int, User*> users;
  243. //  userid  edict
  244. std::map<int, edict_t*> edicts;
  245.  
  246.  
  247. //---------------------------------------------------------------------------------
  248.  
  249. // Purpose: a sample 3rd party plugin class
  250.  
  251. //---------------------------------------------------------------------------------
  252.  
  253. class CEmptyServerPlugin: public IServerPluginCallbacks, public IGameEventListener
  254.  
  255. {
  256.  
  257. public:
  258.  
  259.     CEmptyServerPlugin();
  260.  
  261.     ~CEmptyServerPlugin();
  262.  
  263.  
  264.  
  265.     // IServerPluginCallbacks methods
  266.  
  267.     virtual bool            Load(   CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory );
  268.  
  269.     virtual void            Unload( void );
  270.  
  271.     virtual void            Pause( void );
  272.  
  273.     virtual void            UnPause( void );
  274.  
  275.     virtual const char  *GetPluginDescription( void );      
  276.  
  277.     virtual void            LevelInit( char const *pMapName );
  278.  
  279.     virtual void            ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
  280.  
  281.     virtual void            GameFrame( bool simulating );
  282.  
  283.     virtual void            LevelShutdown( void );
  284.  
  285.     virtual void            ClientActive( edict_t *pEntity );
  286.  
  287.     virtual void            ClientDisconnect( edict_t *pEntity );
  288.  
  289.     virtual void            ClientPutInServer( edict_t *pEntity, char const *playername );
  290.  
  291.     virtual void            SetCommandClient( int index );
  292.  
  293.     virtual void            ClientSettingsChanged( edict_t *pEdict );
  294.  
  295.     virtual PLUGIN_RESULT   ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
  296.  
  297.     virtual PLUGIN_RESULT   ClientCommand( edict_t *pEntity );
  298.  
  299.     virtual PLUGIN_RESULT   NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );
  300.  
  301.  
  302.  
  303.     // IGameEventListener Interface
  304.  
  305.     virtual void FireGameEvent( KeyValues * event );
  306.  
  307.  
  308.  
  309.     virtual int GetCommandIndex() { return m_iClientCommandIndex; }
  310.  
  311. private:
  312.  
  313.     int m_iClientCommandIndex;
  314.  
  315. };
  316.  
  317.  
  318.  
  319.  
  320.  
  321. //
  322.  
  323. // The plugin is a static singleton that is exported as an interface
  324.  
  325. //
  326.  
  327. CEmptyServerPlugin g_EmtpyServerPlugin;
  328.  
  329. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CEmptyServerPlugin, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_EmtpyServerPlugin );
  330.  
  331.  
  332.  
  333. //---------------------------------------------------------------------------------
  334.  
  335. // Purpose: constructor/destructor
  336.  
  337. //---------------------------------------------------------------------------------
  338.  
  339. CEmptyServerPlugin::CEmptyServerPlugin()
  340.  
  341. {
  342.  
  343.     m_iClientCommandIndex = 0;
  344.  
  345. }
  346.  
  347.  
  348.  
  349. CEmptyServerPlugin::~CEmptyServerPlugin()
  350.  
  351. {
  352.  
  353. }
  354.  
  355.  
  356.  
  357. //---------------------------------------------------------------------------------
  358.  
  359. // Purpose: called when the plugin is loaded, load the interface we need from the engine
  360.  
  361. //---------------------------------------------------------------------------------
  362.  
  363. bool CEmptyServerPlugin::Load(  CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory )
  364.  
  365. {
  366.  
  367.     playerinfomanager = (IPlayerInfoManager *)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER,NULL);
  368.  
  369.     if ( !playerinfomanager )
  370.  
  371.     {
  372.  
  373.         Warning( "Unable to load playerinfomanager, ignoring\n" ); // this isn't fatal, we just won't be able to access specific player data
  374.  
  375.     }
  376.  
  377.  
  378.  
  379.     botmanager = (IBotManager *)gameServerFactory(INTERFACEVERSION_PLAYERBOTMANAGER, NULL);
  380.  
  381.     if ( !botmanager )
  382.  
  383.     {
  384.  
  385.         Warning( "Unable to load botcontroller, ignoring\n" ); // this isn't fatal, we just won't be able to access specific bot functions
  386.  
  387.     }
  388.  
  389.  
  390.  
  391.     // get the interfaces we want to use
  392.  
  393.     if( !(engine = (IVEngineServer*)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL)) ||
  394.  
  395.         !(gameeventmanager = (IGameEventManager *)interfaceFactory(INTERFACEVERSION_GAMEEVENTSMANAGER,NULL)) ||
  396.  
  397.         !(filesystem = (IFileSystem*)interfaceFactory(FILESYSTEM_INTERFACE_VERSION, NULL)) ||
  398.  
  399.         !(helpers = (IServerPluginHelpers*)interfaceFactory(INTERFACEVERSION_ISERVERPLUGINHELPERS, NULL)) ||
  400.  
  401.         !(enginetrace = (IEngineTrace *)interfaceFactory(INTERFACEVERSION_ENGINETRACE_SERVER,NULL)) ||
  402.  
  403.         !(randomStr = (IUniformRandomStream *)interfaceFactory(VENGINE_SERVER_RANDOM_INTERFACE_VERSION, NULL))
  404.  
  405.         )
  406.  
  407.     {
  408.  
  409.         return false; // we require all these interface to function
  410.  
  411.     }
  412.  
  413.  
  414.  
  415.     if ( playerinfomanager )
  416.  
  417.     {
  418.  
  419.         gpGlobals = playerinfomanager->GetGlobalVars();
  420.  
  421.     }
  422.  
  423.  
  424.  
  425.     InitCVars( interfaceFactory ); // register any cvars we have defined
  426.  
  427.     MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
  428.  
  429.  
  430.  
  431.     if (conn.connect(db, server, user, pass)) {
  432.         Msg ("Rank: DB connected\n");
  433.     } else {
  434.         Msg ("Rank: DB connection failed!\n");
  435.     }  
  436.    
  437.     return true;
  438.  
  439. }
  440.  
  441.  
  442.  
  443. //------------------------------------ ---------------------------------------------
  444.  
  445. // Purpose: called when the plugin is unloaded (turned off)
  446.  
  447. //---------------------------------------------------------------------------------
  448.  
  449. void CEmptyServerPlugin::Unload( void )
  450.  
  451. {
  452.  
  453.     gameeventmanager->RemoveListener( this ); // make sure we are unloaded from the event system
  454.  
  455. }
  456.  
  457.  
  458.  
  459. //---------------------------------------------------------------------------------
  460.  
  461. // Purpose: called when the plugin is paused (i.e should stop running but isn't unloaded)
  462.  
  463. //---------------------------------------------------------------------------------
  464.  
  465. void CEmptyServerPlugin::Pause( void )
  466.  
  467. {
  468.  
  469. }
  470.  
  471.  
  472.  
  473. //---------------------------------------------------------------------------------
  474.  
  475. // Purpose: called when the plugin is unpaused (i.e should start executing again)
  476.  
  477. //---------------------------------------------------------------------------------
  478.  
  479. void CEmptyServerPlugin::UnPause( void )
  480.  
  481. {
  482.  
  483. }
  484.  
  485.  
  486.  
  487. //---------------------------------------------------------------------------------
  488.  
  489. // Purpose: the name of this plugin, returned in "plugin_print" command
  490.  
  491. //---------------------------------------------------------------------------------
  492.  
  493. const char *CEmptyServerPlugin::GetPluginDescription( void )
  494.  
  495. {
  496.  
  497.     return "Rank: DB module.";
  498.  
  499. }
  500.  
  501.  
  502.  
  503. //---------------------------------------------------------------------------------
  504.  
  505. // Purpose: called on level start
  506.  
  507. //---------------------------------------------------------------------------------
  508.  
  509. void CEmptyServerPlugin::LevelInit( char const *pMapName )
  510.  
  511. {
  512.  
  513. //  Msg( "Level \"%s\" has been loaded\n", pMapName );
  514.  
  515.     gameeventmanager->AddListener( this, true );
  516.  
  517. }
  518.  
  519.  
  520.  
  521. //---------------------------------------------------------------------------------
  522.  
  523. // Purpose: called on level start, when the server is ready to accept client connections
  524.  
  525. //      edictCount is the number of entities in the level, clientMax is the max client count
  526.  
  527. //---------------------------------------------------------------------------------
  528.  
  529. void CEmptyServerPlugin::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
  530.  
  531. {
  532. //  Msg(" Server Activated \n");
  533.  
  534. }
  535.  
  536.  
  537.  
  538. //---------------------------------------------------------------------------------
  539.  
  540. // Purpose: called once per server frame, do recurring work here (like checking for timeouts)
  541.  
  542. //---------------------------------------------------------------------------------
  543.  
  544. void CEmptyServerPlugin::GameFrame( bool simulating )
  545.  
  546. {
  547. }
  548.  
  549.  
  550.  
  551. //---------------------------------------------------------------------------------
  552.  
  553. // Purpose: called on level end (as the server is shutting down or going to a new map)
  554.  
  555. //---------------------------------------------------------------------------------
  556.  
  557. void CEmptyServerPlugin::LevelShutdown( void ) // !!!!this can get called multiple times per map change
  558.  
  559. {
  560. //  Msg("Level shutdown \n");
  561.    
  562.  
  563.     gameeventmanager->RemoveListener( this );
  564.  
  565. }
  566.  
  567.  
  568.  
  569. //---------------------------------------------------------------------------------
  570.  
  571. // Purpose: called when a client spawns into a server (i.e as they begin to play)
  572.  
  573. //---------------------------------------------------------------------------------
  574.  
  575. void CEmptyServerPlugin::ClientActive( edict_t *pEntity )
  576.  
  577. {
  578.  
  579. }
  580.  
  581.  
  582.  
  583. //---------------------------------------------------------------------------------
  584.  
  585. // Purpose: called when a client leaves a server (or is timed out)
  586.  
  587. //---------------------------------------------------------------------------------
  588.  
  589. void CEmptyServerPlugin::ClientDisconnect( edict_t *pEntity )
  590.  
  591. {
  592.     int userid = engine->GetPlayerUserId(pEntity);
  593.     edicts.erase(userid);
  594. }
  595.  
  596.  
  597.  
  598. //---------------------------------------------------------------------------------
  599.  
  600. // Purpose: called on
  601.  
  602. //---------------------------------------------------------------------------------
  603.  
  604. void CEmptyServerPlugin::ClientPutInServer( edict_t *pEntity, char const *playername )
  605.  
  606. {
  607.  
  608.    
  609. }
  610.  
  611.  
  612.  
  613. //---------------------------------------------------------------------------------
  614.  
  615. // Purpose: called on level start
  616.  
  617. //---------------------------------------------------------------------------------
  618.  
  619. void CEmptyServerPlugin::SetCommandClient( int index )
  620.  
  621. {
  622.  
  623.     m_iClientCommandIndex = index;
  624.  
  625. }
  626.  
  627.  
  628.  
  629. //---------------------------------------------------------------------------------
  630.  
  631. // Purpose: called on level start
  632.  
  633. //---------------------------------------------------------------------------------
  634.  
  635. void CEmptyServerPlugin::ClientSettingsChanged( edict_t *pEdict )
  636.  
  637. {
  638.  
  639.  
  640.  
  641. }
  642.  
  643.  
  644.  
  645. //---------------------------------------------------------------------------------
  646.  
  647. // Purpose: called when a client joins a server
  648.  
  649. //---------------------------------------------------------------------------------
  650.  
  651.  
  652. PLUGIN_RESULT CEmptyServerPlugin::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
  653.  
  654. {
  655.     int userid = engine->GetPlayerUserId(pEntity); 
  656.     edicts[userid] = pEntity;  
  657.    
  658.     if (!users[userid])
  659.     {
  660.         const char *ranklogin = engine->GetClientConVarValue( engine->IndexOfEdict(pEntity), "rankname" );
  661.         const char *rankpassword = engine->GetClientConVarValue( engine->IndexOfEdict(pEntity), "rankpassword" );      
  662.    
  663.         User *MyUser = new User(ranklogin, rankpassword);      
  664.         users[userid] = MyUser;
  665.  
  666.         Msg ("Rank: Joined %i as %i to %i \n", userid, MyUser->GetDataBaseID(), MyUser->GetSessionID());
  667.     }
  668.  
  669.     return PLUGIN_CONTINUE;
  670.  
  671. }
  672.  
  673.  
  674.  
  675. //---------------------------------------------------------------------------------
  676.  
  677. // Purpose: called when a client types in a command (only a subset of commands however, not CON_COMMAND's)
  678.  
  679. //---------------------------------------------------------------------------------
  680.  
  681. PLUGIN_RESULT CEmptyServerPlugin::ClientCommand( edict_t *pEntity )
  682.  
  683. {
  684.  
  685.     const char *pcmd = engine->Cmd_Argv(0);
  686.  
  687.  
  688.  
  689.     if ( !pEntity || pEntity->IsFree() )
  690.  
  691.     {
  692.  
  693.         return PLUGIN_CONTINUE;
  694.  
  695.     }
  696.  
  697.     if ( FStrEq( pcmd, "rank_join" ) )
  698.     {
  699.         char msg[128];
  700.  
  701.         if (engine->Cmd_Argc() == 3)
  702.         {
  703.             const char *ranklogin = engine->Cmd_Argv(1);
  704.             const char *rankpassword = engine->Cmd_Argv(2);
  705.            
  706.             if (users[engine->GetPlayerUserId(pEntity)]->RecheckAuth(ranklogin, rankpassword))
  707.                 Q_snprintf( msg, sizeof(msg), "Успех. Вы авторизованы как %s \n", ranklogin );    
  708.             else
  709.                 Q_snprintf( msg, sizeof(msg), "Пользователь %s не существует, или пароль не верен. \n", ranklogin );
  710.  
  711.         } else
  712.             Q_snprintf( msg, sizeof(msg), "ОШИБКА: Не верный запрос!\nИспользование: rank_join ВАШ_ЛОГИН ВАШ_ПАРОЛЬ \n" );
  713.  
  714.         engine->ClientPrintf( pEntity, msg );
  715.         return PLUGIN_STOP;
  716.  
  717.     } else
  718.     if ( FStrEq( pcmd, "rank_leave" ) )
  719.     {
  720.         if (users[engine->GetPlayerUserId(pEntity)]->BecomeNobody())
  721.             engine->ClientPrintf( pEntity, "ПРЕДУПРЕЖДЕНИЕ: Ваша сессия будет потеряна! \n" );
  722.         return PLUGIN_STOP;
  723.    
  724.     } else 
  725.     if ( FStrEq( pcmd, "rank_recheck") )
  726.     {  
  727.         const char *ranklogin = engine->GetClientConVarValue( engine->IndexOfEdict(pEntity), "rankname" );
  728.         const char *rankpassword = engine->GetClientConVarValue( engine->IndexOfEdict(pEntity), "rankpassword" );
  729.         char msg[128];
  730.  
  731.         if (users[engine->GetPlayerUserId(pEntity)]->RecheckAuth(ranklogin, rankpassword))
  732.             Q_snprintf( msg, sizeof(msg), "Успех. Вы авторизованы как %s \n", ranklogin );    
  733.         else
  734.             Q_snprintf( msg, sizeof(msg), "Пользователь %s не существует, или пароль не верен. \n", ranklogin );
  735.  
  736.         engine->ClientPrintf( pEntity, msg );
  737.        
  738.         return PLUGIN_STOP;
  739.     } else
  740.     if ( FStrEq( pcmd, "rank_whoiam") )
  741.     {  
  742.         mysqlpp::Query query = conn.query();
  743.         query << "select login from user where id = " << users[engine->GetPlayerUserId(pEntity)]->GetDataBaseID();
  744.         char msg[128];
  745.         const char *login;
  746.  
  747.         mysqlpp::UseQueryResult res = query.use();
  748.         if (res)
  749.             if (mysqlpp::Row row = res.fetch_row())
  750.             {
  751.                 const char *login = row["login"];
  752.                 Q_snprintf( msg, sizeof(msg), "Вы авторизованы как %s \n", login );
  753.             }
  754.        
  755.         engine->ClientPrintf( pEntity, msg );
  756.        
  757.         return PLUGIN_STOP;
  758.     } else
  759.  
  760.  
  761.     return PLUGIN_CONTINUE;
  762.  
  763. }
  764.  
  765.  
  766.  
  767. //---------------------------------------------------------------------------------
  768.  
  769. // Purpose: called when a client is authenticated
  770.  
  771. //---------------------------------------------------------------------------------
  772.  
  773. PLUGIN_RESULT CEmptyServerPlugin::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
  774.  
  775. {
  776.  
  777.     return PLUGIN_CONTINUE;
  778.  
  779. }
  780.  
  781.  
  782. //  virtual int player_death (int attacker_sessionid, char const *weapon, bool headshot);
  783. //  virtual int player_hurt (int attacker_sessionid, int health, int armor, char const *weapon, int dmg_health, int dmg_armor, int hitgroup);
  784. //  virtual int hostage_killed (void);
  785. //  virtual int hostage_rescued(void);
  786. //  virtual int bomb_defused(int site);
  787. //  virtual int bomb_exploded(int site);
  788.  
  789.  
  790. //---------------------------------------------------------------------------------
  791.  
  792. // Purpose: called when an event is fired
  793.  
  794. //---------------------------------------------------------------------------------
  795.  
  796. void CEmptyServerPlugin::FireGameEvent( KeyValues * event )
  797.  
  798. {
  799.  
  800.     const char * name = event->GetName();
  801.  
  802.     if (!users[event->GetInt("userid", 0)])
  803.         return;
  804.  
  805.     if ( FStrEq( name, "player_hurt" ) )
  806.     {
  807.         users[event->GetInt("userid", 0)]->player_hurt(users[event->GetInt("attacker")]->GetSessionID(), event->GetInt("health", 0), event->GetInt("armor", 0), event->GetString("weapon", ""), event->GetInt("dmg_health", 0), event->GetInt("dmg_armor", 0), event->GetInt("hitgroup", 0));      
  808.        
  809.     } else
  810.     if ( FStrEq( name, "player_death" ) )
  811.     {
  812.         users[event->GetInt("userid", 0)]->player_death(users[event->GetInt("attacker")]->GetSessionID(), event->GetString("weapon", ""), event->GetInt("headshot", 0));
  813.  
  814.     } else
  815.     if ( FStrEq( name, "hostage_killed" ) )
  816.     {
  817.         users[event->GetInt("userid", 0)]->hostage_killed();
  818.  
  819.     } else  
  820.     if ( FStrEq( name, "hostage_rescued" ) )
  821.     {
  822.         users[event->GetInt("userid", 0)]->hostage_rescued();
  823.  
  824.     } else  
  825.     if ( FStrEq( name, "bomb_defused" ) )
  826.     {
  827.         users[event->GetInt("userid", 0)]->bomb_defused(event->GetInt("site", 0));
  828.  
  829.     } else  
  830.     if ( FStrEq( name, "bomb_exploded" ) )
  831.     {
  832.         users[event->GetInt("userid", 0)]->bomb_exploded(event->GetInt("site", 0));
  833.        
  834.     } else
  835.     if ( FStrEq( name, "player_team" ) )
  836.     {
  837.         users[event->GetInt("userid", 0)]->player_team(event->GetInt("team", 0));
  838.  
  839.     } else
  840.     /*  
  841.     if ( FStrEq( name, " " ) )
  842.     {
  843.         users[event->GetInt("userid", 0)]-> (users[event->GetInt("attacker")]->GetSessionID(),  );
  844.  
  845.     } else  */
  846.     if ( FStrEq( name, "player_disconnect") )
  847.     {
  848.         int userid = event->GetInt("userid", 0);
  849.         const char * reason = event->GetString("reason", "");
  850.  
  851.         if (users[userid])
  852.         {  
  853.             users[userid]->CloseSession(users[userid]->GetSessionID(), reason);        
  854.             delete (users[userid]);
  855.             users.erase(userid);       
  856.         } else Msg ("Rank: Fault at erase %i user!\n", userid);        
  857.     }
  858.    
  859.  
  860.     //else
  861.  
  862. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement