Main Page | Class List | File List | Class Members | File Members

CountryFilter.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- */
00002 /* Countryfilter.h
00003  *
00004  * Copyright (C) 2005 Guwashi <guwashi[AT]fooos[DOT]com>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 // This code is based on
00022 // http://www.sourcemod.net/forums/viewtopic.php?t=628
00023 
00024 #ifndef _COUNTRYFILTER_H_
00025 #define _COUNTRYFILTER_H_
00026 
00027 // HL2 includes START
00028 #include "interface.h"
00029 #include "filesystem.h"
00030 #include "engine/iserverplugin.h"
00031 #include "dlls/iplayerinfo.h"
00032 #include "eiface.h"
00033 #include "inetchannelinfo.h"
00034 #include "igameevents.h"
00035 #include "igamesystem.h"
00036 #include "convar.h"
00037 #include "Color.h"
00038 #include "shake.h"
00039 #include "IEffects.h"
00040 #include "bitbuf.h"
00041 #include "vstdlib/random.h"
00042 #include "engine/IEngineTrace.h"
00043 #include "engine/IEngineSound.h"
00044 #include "KeyValues.h"
00045 #include "tier1/utlvector.h"
00046 
00047 // memdbgon must be the last include file in a .cpp file!!!
00048 #include "tier0/memdbgon.h"
00049 // HL2 includes END
00050 
00051 #include "GeoIPWrapper.h"
00052 
00053 #ifdef _WIN32
00054 #define COUNTRYFILTER_PATH_SEPARATOR "\\"
00055 #else
00056 #define COUNTRYFILTER_PATH_SEPARATOR "/"
00057 #endif
00058 
00059 #define COUNTRYFILTER_TMP_BUFFER_LENGTH 1024
00060 
00064 class CountryFilter : public IServerPluginCallbacks, public IGameEventListener
00065 {
00066 public:
00067   CountryFilter();
00068   ~CountryFilter();
00069 
00070 public:
00071   class CPluginConVarAccessor : public IConCommandBaseAccessor
00072   {
00073     CountryFilter* m_cf;
00074   public:
00075     CPluginConVarAccessor(CountryFilter* cf);
00076     virtual bool RegisterConCommandBase(ConCommandBase* pCommand);
00077   };
00078 
00086   virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory);
00087 
00091   virtual void Unload(void);
00092 
00098   virtual const char* GetPluginDescription(void);
00099 
00103   virtual void Pause(void);
00104 
00108   virtual void UnPause(void);
00109         
00115   virtual void LevelInit(char const* pMapName);
00116 
00124   virtual void ServerActivate(edict_t* pEdictList, int edictCount, int clientMax);
00125 
00129   virtual void LevelShutdown(void);
00130 
00136   virtual void GameFrame(bool simulating);
00137 
00149   virtual PLUGIN_RESULT ClientConnect(bool* bAllowConnect, edict_t* pEntity, const char* pszName, const char* pszAddress, char* reject, int maxrejectlen);
00150 
00156   virtual void ClientDisconnect(edict_t* pEntity);
00157         
00164   virtual void ClientActive(edict_t* pEntity);
00165         
00172   virtual void ClientPutInServer(edict_t* pEntity, char const* playername);
00173 
00179   virtual void ClientSettingsChanged(edict_t* pEntity);
00180 
00187   virtual PLUGIN_RESULT ClientCommand(edict_t* pEntity);
00188 
00197   virtual PLUGIN_RESULT NetworkIDValidated(const char* pszUserName, const char* pszNetworkID);
00198 
00204   virtual void SetCommandClient(int index);
00205 
00206 
00207   virtual void FireGameEvent(KeyValues* event);
00208 
00209 public:
00211   int m_ClCommandIndex;
00212 
00213 private:
00215   IPlayerInfoManager* m_PlayerInfoManager;
00216 
00218   ICvar* m_CvarFactory;
00219 
00221   bool m_Loaded;
00222 
00224   CPluginConVarAccessor* m_pConVarAccessor;
00225 
00227   IVEngineServer* m_IVEngine;
00228 
00230   IEffects* m_IEffects;
00231 
00233   IEngineSound* m_IEngineSound;
00234 
00236   IGameEventManager* m_GameEventManager;
00237 
00239   IServerPluginHelpers* m_Helpers;
00240 
00241 
00243   bool m_Paused;
00244 
00246   bool m_Initialized;
00247 
00249   int m_ClientMax;
00250 
00251   GeoIPWrapper* m_giw;
00252 
00253   CUtlVector<int> m_playerCountryIdList;
00254   char m_playerOriginalNameList[64][256]; // TODO
00255 
00256   PLUGIN_RESULT handleStatusCommand(edict_t* pEntity);
00257   PLUGIN_RESULT handleCountryByAddrCommand(edict_t* pEntity); // for DEBUB
00258   PLUGIN_RESULT handleTestGeoIPCommand(edict_t* pEntity); // for DEBUB
00259 
00260   bool handlePlayerSayEvent(KeyValues* event);
00261 
00262   bool isMessageExcludeFrom(const char* countryCode) const;
00263   bool isAllowConnect(const char* countryCode) const;
00264 
00265   const char* idToCountry(int countryId) const;
00266 
00267   int getPlayerCountryId(int playerIndex) const;
00268   bool setPlayerCountryId(int playerIndex, int countryId);
00269   bool initPlayerCountryIdList(int clientMax);
00270 
00271   const char* getPlayerOriginalName(int playerIndex) const;
00272   bool setPlayerOriginalName(int playerIndex, const char* name);
00273   bool initPlayerOriginalNameList(int clientMax);
00274 
00275   bool printCountryStatus(edict_t* pEntity, bool isChat);
00276   bool testGeoIP(edict_t* pEntity); // for DEBUG
00277 
00278   edict_t* getPlayerEdictByIndex(int playerIndex);
00279   edict_t* getPlayerEdictByUserID(int userID);
00280   IPlayerInfo* getPlayerInfoByEdict(edict_t* pPlayerEdict);
00281   IPlayerInfo* getPlayerInfoByIndex(int playerIndex);
00282   IPlayerInfo* getPlayerInfoByUserID(int userID);
00283   int getPlayerCount();
00284 
00285   bool clientSendChatMessage(edict_t* pEntity, const char* msg);
00286   bool clientSendAllChatMessage(const char* msg);
00287 
00288   static bool isValidSteamId(const char* steamId);
00289   static bool isBOTSteamId(const char* steamId);
00290 
00291   static size_t indexOf(const char* s1, const char* s2, size_t begin = 0);
00292   static bool substring(const char* src, size_t begin, size_t end, char* dst);
00293 };
00294 
00295 extern CountryFilter g_CF;
00296 
00297 extern ConVar g_Version;
00298 extern ConVar g_AllowMessage;
00299 extern ConVar g_DenyMessage;
00300 extern ConVar g_MessageExcludeFrom;
00301 extern ConVar g_Order;
00302 extern ConVar g_AllowFrom;
00303 extern ConVar g_DenyFrom;
00304 extern ConVar g_CountryPrintMode;
00305 extern ConVar g_StatusCommandAlias;
00306 extern ConVar g_ForceChangeName;
00307 extern ConVar g_CountryTag;
00308 
00309 #endif //_COUNTRYFILTER_H_

Generated on Tue Jun 28 01:09:07 2005 for CountryFilter by  doxygen 1.4.3-20050623