core/HalfLife2.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 06 00:45:26 2008 +0000 (2008-07-06)
changeset 2162 59c5dc056c69
parent 2051 568678a2e847
child 2289 44045ead61cd
permissions -rw-r--r--
fixed amb1808 - KickClient() is delayed and does not crash -- KickClientEx() is the old functionality
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
ds@1952
    33
#define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
ds@1952
    34
ds@1952
    35
#include <sh_list.h>
ds@1952
    36
#include <sh_string.h>
ds@1952
    37
#include <sh_tinyhash.h>
ds@1952
    38
#include <sm_trie_tpl.h>
ds@1952
    39
#include "sm_trie.h"
ds@1952
    40
#include "sm_globals.h"
ds@1952
    41
#include "sm_queue.h"
ds@1952
    42
#include <IGameHelpers.h>
ds@1952
    43
#include <KeyValues.h>
ds@2051
    44
#include <server_class.h>
ds@2051
    45
#include <datamap.h>
ds@1952
    46
ds@1952
    47
class CCommand;
ds@1952
    48
ds@1952
    49
using namespace SourceHook;
ds@1952
    50
using namespace SourceMod;
ds@1952
    51
ds@1952
    52
#define HUD_PRINTTALK		3
ds@1952
    53
#define HUD_PRINTCENTER		4
ds@1952
    54
ds@1952
    55
struct DataTableInfo
ds@1952
    56
{
ds@1952
    57
	ServerClass *sc;
ds@1952
    58
	KTrie<sm_sendprop_info_t> lookup;
ds@1952
    59
};
ds@1952
    60
ds@1952
    61
struct DataMapTrie
ds@1952
    62
{
ds@1952
    63
	DataMapTrie() : trie(NULL) {}
ds@1952
    64
	Trie *trie;
ds@1952
    65
};
ds@1952
    66
ds@1952
    67
struct DelayedFakeCliCmd
ds@1952
    68
{
ds@1952
    69
	String cmd;
ds@1952
    70
	int client;
ds@1952
    71
	int userid;
ds@1952
    72
};
ds@1952
    73
ds@1952
    74
struct CachedCommandInfo
ds@1952
    75
{
ds@1952
    76
	const CCommand *args;
ds@1952
    77
#if !defined ORANGEBOX_BUILD
ds@1952
    78
	char cmd[300];
ds@1952
    79
#endif
ds@1952
    80
};
ds@1952
    81
dvander@2162
    82
struct DelayedKickInfo
dvander@2162
    83
{
dvander@2162
    84
	int userid;
dvander@2162
    85
	int client;
dvander@2162
    86
	char buffer[384];
dvander@2162
    87
};
dvander@2162
    88
ds@1952
    89
class CHalfLife2 : 
ds@1952
    90
	public SMGlobalClass,
ds@1952
    91
	public IGameHelpers
ds@1952
    92
{
ds@1952
    93
public:
ds@1952
    94
	CHalfLife2();
ds@1952
    95
	~CHalfLife2();
ds@1952
    96
public:
ds@1952
    97
	void OnSourceModStartup(bool late);
ds@1952
    98
	void OnSourceModAllInitialized();
ds@1952
    99
	/*void OnSourceModAllShutdown();*/
ds@1952
   100
public: //IGameHelpers
ds@1952
   101
	SendProp *FindInSendTable(const char *classname, const char *offset);
ds@1952
   102
	bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
ds@1952
   103
	datamap_t *GetDataMap(CBaseEntity *pEntity);
ds@1952
   104
	ServerClass *FindServerClass(const char *classname);
ds@1952
   105
	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
ds@1952
   106
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
ds@1952
   107
	bool TextMsg(int client, int dest, const char *msg);
ds@1952
   108
	bool HintTextMsg(int client, const char *msg);
ds@1952
   109
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
ds@1952
   110
	bool IsLANServer();
ds@1952
   111
	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
ds@1952
   112
public:
ds@1952
   113
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
ds@1952
   114
	void ProcessFakeCliCmdQueue();
ds@1952
   115
public:
ds@1952
   116
	void PushCommandStack(const CCommand *cmd);
ds@1952
   117
	void PopCommandStack();
ds@1952
   118
	const CCommand *PeekCommandStack();
ds@1952
   119
	const char *CurrentCommandName();
dvander@2162
   120
	void AddDelayedKick(int client, int userid, const char *msg);
dvander@2162
   121
	void ProcessDelayedKicks();
ds@1952
   122
#if !defined METAMOD_PLAPI_VERSION
ds@1952
   123
	bool IsOriginalEngine();
ds@1952
   124
#endif
ds@1952
   125
private:
ds@1952
   126
	DataTableInfo *_FindServerClass(const char *classname);
ds@1952
   127
private:
ds@1952
   128
	Trie *m_pClasses;
ds@1952
   129
	List<DataTableInfo *> m_Tables;
ds@1952
   130
	THash<datamap_t *, DataMapTrie> m_Maps;
ds@1952
   131
	int m_MsgTextMsg;
ds@1952
   132
	int m_HinTextMsg;
ds@1952
   133
	int m_VGUIMenu;
ds@1952
   134
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
ds@1952
   135
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
ds@1952
   136
	CStack<CachedCommandInfo> m_CommandStack;
dvander@2162
   137
	Queue<DelayedKickInfo> m_DelayedKicks;
ds@1952
   138
};
ds@1952
   139
ds@1952
   140
extern CHalfLife2 g_HL2;
ds@1952
   141
ds@1952
   142
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_