sourcemm/CSmmAPI.cpp
author David Anderson <dvander@alliedmods.net>
Thu May 26 08:06:23 2005 +0000 (2005-05-26)
changeset 67 1753f7a9b2f2
parent 65 27c4d32394a6
child 76 39266faeec97
permissions -rw-r--r--
Working ConCommandBase replacement code
     1 /* ======== SourceMM ========
     2 * Copyright (C) 2004-2005 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): David "BAILOPAN" Anderson
     8 * ============================
     9 */
    10 
    11 #include "CSmmAPI.h"
    12 #include "sourcemm.h"
    13 #include "concommands.h"
    14 
    15 /**
    16  * @brief Implementation of main API interface
    17  * @file CSmmAPI.cpp
    18  */
    19 
    20 using namespace SourceMM;
    21 
    22 CSmmAPI g_SmmAPI;
    23 
    24 ISmmPluginManager *CSmmAPI::PluginManager()
    25 {
    26 	return static_cast<ISmmPluginManager *>(&g_PluginMngr);
    27 }
    28 
    29 SourceHook::ISourceHook *CSmmAPI::SourceHook()
    30 {
    31 	return static_cast<SourceHook::ISourceHook *>(&g_SourceHook);
    32 }
    33 
    34 void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
    35 {
    36 	va_list ap;
    37 	static char buffer[2048];
    38 
    39 	buffer[0] = '\0';
    40 
    41 	va_start(ap, msg);
    42 	vsnprintf(buffer, sizeof(buffer)-1, msg, ap);
    43 	va_end(ap);
    44 
    45 	LogMessage("[%s] %s", pl->GetLogTag(), buffer);
    46 }
    47 
    48 CreateInterfaceFn CSmmAPI::engineFactory(bool syn)
    49 {
    50 	if (syn)
    51 		return EngineFactory;
    52 	return g_Engine.engineFactory;
    53 }
    54 
    55 CreateInterfaceFn CSmmAPI::physicsFactory(bool syn)
    56 {
    57 	if (syn)
    58 		return PhysicsFactory;
    59 	return g_Engine.physicsFactory;
    60 }
    61 
    62 CreateInterfaceFn CSmmAPI::fileSystemFactory(bool syn)
    63 {
    64 	if (syn)
    65 		return FileSystemFactory;
    66 	return g_Engine.fileSystemFactory;
    67 }
    68 
    69 CreateInterfaceFn CSmmAPI::serverFactory(bool syn)
    70 {
    71 	if (syn)
    72 		return CreateInterface;
    73 	return g_GameDll.factory;
    74 }
    75 
    76 CGlobalVars *CSmmAPI::pGlobals()
    77 {
    78 	return g_Engine.pGlobals;
    79 }
    80 
    81 void CSmmAPI::SetLastMetaReturn(META_RES res)
    82 {
    83 	m_Res = res;
    84 }
    85 
    86 META_RES CSmmAPI::GetLastMetaReturn()
    87 {
    88 	return m_Res;
    89 }
    90 
    91 IConCommandBaseAccessor *CSmmAPI::GetCvarBaseAccessor()
    92 {
    93 	return static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor);
    94 }
    95 
    96 bool CSmmAPI::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
    97 {
    98 	if (pCommand->IsCommand())
    99 	{
   100 		g_PluginMngr.AddPluginCmd(plugin, pCommand);
   101 	} else {
   102 		g_PluginMngr.AddPluginCvar(plugin, pCommand);
   103 	}
   104 
   105 	return g_SMConVarAccessor.Register(pCommand);
   106 }
   107 
   108 void CSmmAPI::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
   109 {
   110 	if (pCommand->IsCommand())
   111 	{
   112 		g_PluginMngr.RemovePluginCmd(plugin, pCommand);
   113 	} else {
   114 		g_PluginMngr.RemovePluginCvar(plugin, pCommand);
   115 	}
   116 
   117 	g_SMConVarAccessor.Unregister(pCommand);
   118 }
   119