-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathsp_main.cpp
executable file
·740 lines (618 loc) · 25.4 KB
/
sp_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
// --------------------------------------------------------
// Includes
// --------------------------------------------------------
#include "sp_python.h"
#include "sp_main.h"
#include "interface.h"
#include "filesystem.h"
#include "eiface.h"
#include "igameevents.h"
#include "convar.h"
#include "Color.h"
#include "vstdlib/random.h"
#include "engine/IEngineTrace.h"
#include "tier2/tier2.h"
#include "game/server/iplayerinfo.h"
#include "shake.h" // Linux compile fails without this.
#include "game/shared/IEffects.h"
#include "utilities/wrap_macros.h"
#include "engine/IEngineSound.h"
#include "engine/IEngineTrace.h"
#include "public/toolframework/itoolentity.h"
#include "dyncall.h"
#include "networkstringtabledefs.h"
#include "edict.h"
#include "convar.h"
#include "utilities/call_python.h"
#include "vphysics_interface.h"
#include "datacache/imdlcache.h"
#include "ivoiceserver.h"
#include "tier0/threadtools.h"
#include "manager.h"
#include "modules/listeners/listeners_manager.h"
#include "utilities/conversions.h"
#include "modules/entities/entities_entity.h"
#include "modules/core/core.h"
#ifdef _WIN32
#include "Windows.h"
#endif
#include "sp_hooks.h"
//-----------------------------------------------------------------------------
// Disable warnings.
//-----------------------------------------------------------------------------
#if defined(_WIN32)
# pragma warning( disable : 4005 )
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Interfaces from the engine
//-----------------------------------------------------------------------------
IVEngineServer* engine = NULL; // helper functions (messaging clients, loading content, making entities, running commands, etc)
IGameEventManager2* gameeventmanager = NULL; // game events interface
IPlayerInfoManager* playerinfomanager = NULL; // game dll interface to interact with players
IBotManager* botmanager = NULL; // game dll interface to interact with bots
IServerPluginHelpers* helpers = NULL; // special 3rd party plugin helpers from the engine
IUniformRandomStream* randomStr = NULL;
IEngineTrace* enginetrace = NULL;
IEngineSound* enginesound = NULL;
CGlobalVars* gpGlobals = NULL;
IFileSystem* filesystem = NULL;
IServerGameDLL* servergamedll = NULL;
IServerGameClients* servergameclients = NULL;
IServerTools* servertools = NULL;
IPhysics* physics = NULL;
IPhysicsCollision* physcollision = NULL;
IPhysicsSurfaceProps* physprops = NULL;
IMDLCache* modelcache = NULL;
IVoiceServer* voiceserver = NULL;
INetworkStringTableContainer* networkstringtable = NULL;
//-----------------------------------------------------------------------------
// External globals
//-----------------------------------------------------------------------------
extern ICvar* g_pCVar;
//-----------------------------------------------------------------------------
// Extern functions
//-----------------------------------------------------------------------------
extern void InitCommands();
extern void ClearAllCommands();
extern PLUGIN_RESULT DispatchClientCommand(edict_t *pEntity, const CCommand &command);
extern CConVarChangedListenerManager* GetOnConVarChangedListenerManager();
//-----------------------------------------------------------------------------
// The plugin is a static singleton that is exported as an interface
//-----------------------------------------------------------------------------
CSourcePython g_SourcePythonPlugin;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CSourcePython, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_SourcePythonPlugin );
//-----------------------------------------------------------------------------
// Interface helper class.
//-----------------------------------------------------------------------------
struct InterfaceHelper_t
{
const char* szInterface;
void** pGlobal;
};
//-----------------------------------------------------------------------------
// We need all of these interfaces in order to function.
//-----------------------------------------------------------------------------
InterfaceHelper_t gEngineInterfaces[] = {
{INTERFACEVERSION_VENGINESERVER, (void **)&engine},
{INTERFACEVERSION_GAMEEVENTSMANAGER2, (void **)&gameeventmanager},
{INTERFACEVERSION_ISERVERPLUGINHELPERS, (void **)&helpers},
{INTERFACEVERSION_ENGINETRACE_SERVER, (void **)&enginetrace},
{IENGINESOUND_SERVER_INTERFACE_VERSION, (void **)&enginesound},
{VENGINE_SERVER_RANDOM_INTERFACE_VERSION, (void **)&randomStr},
{FILESYSTEM_INTERFACE_VERSION, (void **)&filesystem},
{INTERFACENAME_NETWORKSTRINGTABLESERVER, (void **)&networkstringtable},
{VPHYSICS_INTERFACE_VERSION, (void **)&physics},
{VPHYSICS_COLLISION_INTERFACE_VERSION, (void **)&physcollision},
{VPHYSICS_SURFACEPROPS_INTERFACE_VERSION, (void **)&physprops},
{MDLCACHE_INTERFACE_VERSION, (void **)&modelcache},
{INTERFACEVERSION_VOICESERVER, (void **)&voiceserver},
{NULL, NULL}
};
InterfaceHelper_t gGameInterfaces[] = {
{INTERFACEVERSION_PLAYERINFOMANAGER, (void **)&playerinfomanager},
{INTERFACEVERSION_PLAYERBOTMANAGER, (void **)&botmanager},
{INTERFACEVERSION_SERVERGAMEDLL, (void **)&servergamedll},
{INTERFACEVERSION_SERVERGAMECLIENTS, (void **)&servergameclients},
{VSERVERTOOLS_INTERFACE_VERSION, (void **)&servertools},
{NULL, NULL}
};
//-----------------------------------------------------------------------------
// Get all engine interfaces.
//-----------------------------------------------------------------------------
bool GetInterfaces( InterfaceHelper_t* pInterfaceList, CreateInterfaceFn factory )
{
InterfaceHelper_t* pInterface = pInterfaceList;
while( pInterface->szInterface )
{
void** pGlobal = pInterface->pGlobal;
// Get the interface from the given factory.
*pGlobal = factory(pInterface->szInterface, NULL);
// If it's not valid, bail out.
if( *pGlobal ) {
DevMsg(1, MSG_PREFIX "Interface %s at %x\n", pInterface->szInterface, *pGlobal);
} else {
Warning(MSG_PREFIX "Could not retrieve interface %s\n", pInterface->szInterface);
return false;
}
pInterface++;
}
return true;
}
//-----------------------------------------------------------------------------
// Server output hook.
//-----------------------------------------------------------------------------
#if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
SpewRetval_t SP_SpewOutput( SpewType_t spewType, const tchar *pMsg )
{
bool block = false;
// Only filter outputs from the main thread. See issues #400 and #404.
if (ThreadInMainThread()) {
extern CListenerManager* GetOnServerOutputListenerManager();
for(int i = 0; i < GetOnServerOutputListenerManager()->m_vecCallables.Count(); i++)
{
BEGIN_BOOST_PY()
object return_value = GetOnServerOutputListenerManager()->m_vecCallables[i](
(MessageSeverity) spewType,
pMsg);
if (!return_value.is_none() && extract<OutputReturn>(return_value) == OUTPUT_BLOCK)
block = true;
END_BOOST_PY_NORET()
}
}
if (!block && g_SourcePythonPlugin.m_pOldSpewOutputFunc)
return g_SourcePythonPlugin.m_pOldSpewOutputFunc(spewType, pMsg);
return SPEW_CONTINUE;
}
#else
class SPLoggingListener: public ILoggingListener
{
public:
virtual void Log( const LoggingContext_t *pContext, const tchar *pMessage )
{
bool block = false;
// Only filter outputs from the main thread. See issues #400 and #404.
if (ThreadInMainThread()) {
extern CListenerManager* GetOnServerOutputListenerManager();
for(int i = 0; i < GetOnServerOutputListenerManager()->m_vecCallables.Count(); i++)
{
BEGIN_BOOST_PY()
object return_value = GetOnServerOutputListenerManager()->m_vecCallables[i](
(MessageSeverity) pContext->m_Severity,
pMessage);
if (!return_value.is_none() && extract<OutputReturn>(return_value) == OUTPUT_BLOCK)
block = true;
END_BOOST_PY_NORET()
}
}
if (!block)
{
// Restore the old logging state before SP has been loaded
LoggingSystem_PopLoggingState(false);
// Resend the log message. Our listener won't get called anymore
LoggingSystem_LogDirect(
pContext->m_ChannelID,
pContext->m_Severity,
pContext->m_Color,
pMessage);
// Create a new logging state with only our listener being active
#if defined(ENGINE_LEFT4DEAD2)
LoggingSystem_PushLoggingState(false);
#else
LoggingSystem_PushLoggingState(false, true);
#endif
LoggingSystem_RegisterLoggingListener(this);
}
}
} g_LoggingListener;
#endif
//-----------------------------------------------------------------------------
// Purpose: constructor/destructor
//-----------------------------------------------------------------------------
CSourcePython::CSourcePython()
{
m_iClientCommandIndex = 0;
m_pOldMDLCacheNotifier = NULL;
#if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
m_pOldSpewOutputFunc = NULL;
#endif
}
CSourcePython::~CSourcePython()
{
}
//-----------------------------------------------------------------------------
// Purpose: called when the plugin is loaded, load the interface we need from the engine
//-----------------------------------------------------------------------------
bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory )
{
#if defined(ENGINE_CSGO) || defined(ENGINE_BLADE)
DevMsg(1, MSG_PREFIX "Connecting interfaces...\n");
ConnectInterfaces(&interfaceFactory, 1);
#else
DevMsg(1, MSG_PREFIX "Connecting tier1 libraries...\n");
ConnectTier1Libraries( &interfaceFactory, 1 );
DevMsg(1, MSG_PREFIX "Connecting tier2 libraries...\n");
ConnectTier2Libraries( &interfaceFactory, 2 );
#endif
// Get all engine interfaces.
DevMsg(1, MSG_PREFIX "Retrieving engine interfaces...\n");
if( !GetInterfaces(gEngineInterfaces, interfaceFactory) ) {
return false;
}
// Get all game interfaces.
DevMsg(1, MSG_PREFIX "Retrieving game interfaces...\n");
if( !GetInterfaces(gGameInterfaces, gameServerFactory) ) {
return false;
}
DevMsg(1, MSG_PREFIX "Retrieving global variables...\n");
gpGlobals = playerinfomanager->GetGlobalVars();
if (!gpGlobals) {
Msg(MSG_PREFIX "Could retrieve global variables.\n");
return false;
}
DevMsg(1, MSG_PREFIX "Initializing mathlib...\n");
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
DevMsg(1, MSG_PREFIX "Initializing server and say commands...\n");
InitCommands();
// Initialize python
DevMsg(1, MSG_PREFIX "Initializing python...\n");
if( !g_PythonManager.Initialize() ) {
Msg(MSG_PREFIX "Could not initialize python.\n");
return false;
}
#if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
DevMsg(1, MSG_PREFIX "Retrieving old output function...\n");
m_pOldSpewOutputFunc = GetSpewOutputFunc();
DevMsg(1, MSG_PREFIX "Setting new output function...\n");
SpewOutputFunc(SP_SpewOutput);
#else
DevMsg(1, MSG_PREFIX "Registering logging listener...\n");
#if defined(ENGINE_LEFT4DEAD2)
LoggingSystem_PushLoggingState(false);
#else
LoggingSystem_PushLoggingState(false, true);
#endif
LoggingSystem_RegisterLoggingListener(&g_LoggingListener);
#endif
// TODO: Don't hardcode the 64 bytes offset
#ifdef ENGINE_LEFT4DEAD2
#define CACHE_NOTIFY_OFFSET 68
#else
#define CACHE_NOTIFY_OFFSET 64
#endif
DevMsg(1, MSG_PREFIX "Retrieving the current cache notifier...\n");
m_pOldMDLCacheNotifier = *(IMDLCacheNotify **)(((unsigned long) modelcache) + CACHE_NOTIFY_OFFSET);
DevMsg(1, MSG_PREFIX "Setting the new cache notifier...\n");
modelcache->SetCacheNotify(this);
g_EntityHooks.push_back(new PlayerHook(
"run_command",
(HookHandlerFn*) (void*) &PrePlayerRunCommand,
HOOKTYPE_PRE));
InitHooks();
Msg(MSG_PREFIX "Loaded successfully.\n");
return true;
}
//-----------------------------------------------------------------------------
// Purpose: called when the plugin is unloaded (turned off)
//-----------------------------------------------------------------------------
void CSourcePython::Unload( void )
{
Msg(MSG_PREFIX "Unloading...\n");
#if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
if (m_pOldSpewOutputFunc)
{
DevMsg(1, MSG_PREFIX "Restoring old output function...\n");
SpewOutputFunc(m_pOldSpewOutputFunc);
}
#else
DevMsg(1, MSG_PREFIX "Restoring old logging state...\n");
LoggingSystem_PopLoggingState(false);
#endif
DevMsg(1, MSG_PREFIX "Resetting cache notifier...\n");
modelcache->SetCacheNotify(m_pOldMDLCacheNotifier);
DevMsg(1, MSG_PREFIX "Shutting down python...\n");
g_PythonManager.Shutdown();
DevMsg(1, MSG_PREFIX "Clearing convar changed listener...\n");
GetOnConVarChangedListenerManager()->clear();
DevMsg(1, MSG_PREFIX "Unhooking all functions...\n");
GetHookManager()->UnhookAllFunctions();
DevMsg(1, MSG_PREFIX "Clearing all commands...\n");
ClearAllCommands();
// New in CSGO...
#if defined(ENGINE_CSGO) || defined(ENGINE_BLADE)
DevMsg(1, MSG_PREFIX "Disconnecting interfaces...\n");
DisconnectInterfaces();
#else
DevMsg(1, MSG_PREFIX "Disconnecting tier2 libraries...\n");
DisconnectTier2Libraries( );
DevMsg(1, MSG_PREFIX "Disconnecting tier1 libraries...\n");
DisconnectTier1Libraries( );
#endif
Msg(MSG_PREFIX "Unloaded successfully.\n");
#ifdef _WIN32
// This "fixes" a crash after SP has been unloaded.
Sleep(1000);
#endif
}
//-----------------------------------------------------------------------------
// Purpose: called when the plugin is paused (i.e should stop running but isn't unloaded)
//-----------------------------------------------------------------------------
void CSourcePython::Pause( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: called when the plugin is unpaused (i.e should start executing again)
//-----------------------------------------------------------------------------
void CSourcePython::UnPause( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: the name of this plugin, returned in "plugin_print" command
//-----------------------------------------------------------------------------
const char *CSourcePython::GetPluginDescription( void )
{
return "Source.Python, (C) 2012-2021, Source.Python Team.";
}
//-----------------------------------------------------------------------------
// Purpose: called on level start
//-----------------------------------------------------------------------------
void CSourcePython::LevelInit( char const *pMapName )
{
CALL_LISTENERS(OnLevelInit, pMapName);
}
//-----------------------------------------------------------------------------
// Purpose: called on level start, when the server is ready to accept client connections
// edictCount is the number of entities in the level, clientMax is the max client count
//-----------------------------------------------------------------------------
void CSourcePython::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
{
list edicts;
for(int i=0; i < edictCount; i++)
edicts.append(pEdictList[i]);
CALL_LISTENERS(OnServerActivate, edicts, edictCount, clientMax);
}
//-----------------------------------------------------------------------------
// Purpose: called once per server frame, do recurring work here (like checking for timeouts)
//-----------------------------------------------------------------------------
void CSourcePython::GameFrame( bool simulating )
{
CALL_LISTENERS(OnTick);
}
//-----------------------------------------------------------------------------
// Purpose: called on level end (as the server is shutting down or going to a new map)
//-----------------------------------------------------------------------------
void CSourcePython::LevelShutdown( void ) // !!!!this can get called multiple times per map change
{
CALL_LISTENERS(OnLevelShutdown);
}
//-----------------------------------------------------------------------------
// Purpose: called when a client spawns into a server (i.e as they begin to play)
//-----------------------------------------------------------------------------
void CSourcePython::ClientActive( edict_t *pEntity )
{
unsigned int iEntityIndex;
if (!IndexFromEdict(pEntity, iEntityIndex))
return;
CALL_LISTENERS(OnClientActive, iEntityIndex);
}
//-----------------------------------------------------------------------------
// Purpose: called when a client leaves a server (or is timed out)
//-----------------------------------------------------------------------------
void CSourcePython::ClientDisconnect( edict_t *pEntity )
{
unsigned int iEntityIndex;
if (!IndexFromEdict(pEntity, iEntityIndex))
return;
CALL_LISTENERS(OnClientDisconnect, iEntityIndex);
}
//-----------------------------------------------------------------------------
// Purpose: called on
//-----------------------------------------------------------------------------
void CSourcePython::ClientPutInServer( edict_t *pEntity, char const *playername )
{
CALL_LISTENERS(OnClientPutInServer, ptr(pEntity), playername);
}
//-----------------------------------------------------------------------------
// Purpose: called on level start
//-----------------------------------------------------------------------------
void CSourcePython::SetCommandClient( int index )
{
m_iClientCommandIndex = index;
}
//-----------------------------------------------------------------------------
// Purpose: called on level start
//-----------------------------------------------------------------------------
void CSourcePython::ClientSettingsChanged( edict_t *pEdict )
{
unsigned int iEntityIndex;
if (!IndexFromEdict(pEdict, iEntityIndex))
return;
CALL_LISTENERS(OnClientSettingsChanged, iEntityIndex);
}
//-----------------------------------------------------------------------------
// Purpose: called when a client joins a server
//-----------------------------------------------------------------------------
PLUGIN_RESULT CSourcePython::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
{
CPointer allowConnect = CPointer((unsigned long) bAllowConnect);
CPointer rejectMessage = CPointer((unsigned long) reject);
CALL_LISTENERS(OnClientConnect, allowConnect, ptr(pEntity), pszName, pszAddress, rejectMessage, maxrejectlen);
return PLUGIN_OVERRIDE;
}
//-----------------------------------------------------------------------------
// Purpose: called when a client is authenticated
//-----------------------------------------------------------------------------
PLUGIN_RESULT CSourcePython::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
{
CALL_LISTENERS(OnNetworkidValidated, pszUserName, pszNetworkID);
return PLUGIN_CONTINUE;
}
//-----------------------------------------------------------------------------
// Purpose: called when a cvar value query is finished
//-----------------------------------------------------------------------------
void CSourcePython::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity,
EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
{
PythonLog(4, "Cvar query (cookie: %d, status: %d) - name: %s, value: %s", iCookie, eStatus, pCvarName, pCvarValue );
unsigned int iEntityIndex;
if (!IndexFromEdict(pPlayerEntity, iEntityIndex))
return;
CALL_LISTENERS(OnQueryCvarValueFinished, (int) iCookie, iEntityIndex, eStatus, pCvarName, pCvarValue);
}
//-----------------------------------------------------------------------------
// Orangebox.
//-----------------------------------------------------------------------------
PLUGIN_RESULT CSourcePython::ClientCommand( edict_t *pEntity, const CCommand &args )
{
return DispatchClientCommand(pEntity, args);
}
//-----------------------------------------------------------------------------
// Alien Swarm.
//-----------------------------------------------------------------------------
#if defined(ENGINE_CSGO) || defined(ENGINE_BLADE)
void CSourcePython::ClientFullyConnect( edict_t *pEntity )
{
unsigned int iEntityIndex;
if (!IndexFromEdict(pEntity, iEntityIndex))
return;
CALL_LISTENERS(OnClientFullyConnect, iEntityIndex);
}
#endif
#if defined(ENGINE_CSGO) || defined(ENGINE_BMS) || defined(ENGINE_BLADE)
void CSourcePython::OnEdictAllocated( edict_t *edict )
{
unsigned int iEntityIndex;
if (!IndexFromEdict(edict, iEntityIndex))
return;
CALL_LISTENERS(OnEdictAllocated, iEntityIndex);
}
void CSourcePython::OnEdictFreed( const edict_t *edict )
{
CALL_LISTENERS(OnEdictFreed, ptr(edict));
}
#endif
#ifdef ENGINE_BMS
void CSourcePython::OnEntityPreSpawned( CBaseEntity *pEntity )
{
CALL_LISTENERS(OnEntityPreSpawned, ptr((CBaseEntityWrapper*) pEntity));
GET_LISTENER_MANAGER(OnNetworkedEntityPreSpawned, on_networked_entity_pre_spawned_manager);
if (!on_networked_entity_pre_spawned_manager->GetCount())
return;
unsigned int uiIndex;
if (!IndexFromBaseEntity(pEntity, uiIndex))
return;
static object Entity = import("entities").attr("entity").attr("Entity");
CALL_LISTENERS_WITH_MNGR(on_networked_entity_pre_spawned_manager, Entity(uiIndex));
}
#endif
void CSourcePython::OnEntityCreated( CBaseEntity *pEntity )
{
edict_t *pEdict;
if (EdictFromBaseEntity(pEntity, pEdict)) {
IServerUnknown* pServerUnknown = pEdict->GetUnknown();
if (pServerUnknown)
pEdict->m_pNetworkable = pServerUnknown->GetNetworkable();
}
InitHooks(pEntity);
CALL_LISTENERS(OnEntityCreated, ptr((CBaseEntityWrapper*) pEntity));
GET_LISTENER_MANAGER(OnNetworkedEntityCreated, on_networked_entity_created_manager);
if (!on_networked_entity_created_manager->GetCount())
return;
unsigned int uiIndex;
if (!IndexFromBaseEntity(pEntity, uiIndex))
return;
static object Entity = import("entities").attr("entity").attr("Entity");
CALL_LISTENERS_WITH_MNGR(on_networked_entity_created_manager, Entity(uiIndex));
}
void CSourcePython::OnEntitySpawned( CBaseEntity *pEntity )
{
CALL_LISTENERS(OnEntitySpawned, ptr((CBaseEntityWrapper*) pEntity));
GET_LISTENER_MANAGER(OnNetworkedEntitySpawned, on_networked_entity_spawned_manager);
if (!on_networked_entity_spawned_manager->GetCount())
return;
unsigned int uiIndex;
if (!IndexFromBaseEntity(pEntity, uiIndex))
return;
static object Entity = import("entities").attr("entity").attr("Entity");
CALL_LISTENERS_WITH_MNGR(on_networked_entity_spawned_manager, Entity(uiIndex));
}
void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity )
{
CALL_LISTENERS(OnEntityDeleted, ptr((CBaseEntityWrapper*) pEntity));
unsigned int uiIndex;
if (!IndexFromBaseEntity(pEntity, uiIndex))
return;
GET_LISTENER_MANAGER(OnNetworkedEntityDeleted, on_networked_entity_deleted_manager);
if (on_networked_entity_deleted_manager->GetCount())
{
static object Entity = import("entities").attr("entity").attr("Entity");
CALL_LISTENERS_WITH_MNGR(on_networked_entity_deleted_manager, Entity(uiIndex));
}
// Invalidate the internal entity cache once all callbacks have been called.
static object _on_networked_entity_deleted = import("entities").attr("_base").attr("_on_networked_entity_deleted");
_on_networked_entity_deleted(uiIndex);
}
void CSourcePython::OnDataLoaded( MDLCacheDataType_t type, MDLHandle_t handle )
{
if (m_pOldMDLCacheNotifier)
m_pOldMDLCacheNotifier->OnDataLoaded(type, handle);
CALL_LISTENERS(OnDataLoaded, type, handle);
}
void CSourcePython::OnDataUnloaded( MDLCacheDataType_t type, MDLHandle_t handle )
{
if (m_pOldMDLCacheNotifier)
m_pOldMDLCacheNotifier->OnDataUnloaded(type, handle);
CALL_LISTENERS(OnDataUnloaded, type, handle);
}
#if defined(ENGINE_CSGO) || defined(ENGINE_BLADE)
void CSourcePython::OnCombinerPreCache(MDLCacheDataType_t type, MDLHandle_t handle )
{
if (m_pOldMDLCacheNotifier)
m_pOldMDLCacheNotifier->OnCombinerPreCache(type, handle);
CALL_LISTENERS(OnCombinerPreCache, type, handle);
}
bool CSourcePython::ShouldSupressLoadWarning(MDLHandle_t handle)
{
bool result = false;
if (m_pOldMDLCacheNotifier)
result = m_pOldMDLCacheNotifier->ShouldSupressLoadWarning(handle);
return result;
}
bool CSourcePython::BNetworkCryptKeyCheckRequired( uint32 unFromIP, uint16 usFromPort,
uint32 unAccountIdProvidedByClient, bool bClientWantsToUseCryptKey )
{
return false;
}
bool CSourcePython::BNetworkCryptKeyValidate( uint32 unFromIP, uint16 usFromPort, uint32 unAccountIdProvidedByClient,
int nEncryptionKeyIndexFromClient, int numEncryptedBytesFromClient, byte *pbEncryptedBufferFromClient,
byte *pbPlainTextKeyForNetchan )
{
return false;
}
#endif