Moved handle natives from core to logic (bug 4406 part 9, r=ds).
1.1 --- a/core/AMBuilder Fri May 14 20:56:40 2010 -0700
1.2 +++ b/core/AMBuilder Fri May 14 21:06:06 2010 -0700
1.3 @@ -56,7 +56,6 @@
1.4 'smn_halflife.cpp',
1.5 'PluginSys.cpp',
1.6 'smn_console.cpp',
1.7 - 'smn_handles.cpp',
1.8 'UserMessages.cpp',
1.9 'Database.cpp',
1.10 'MenuManager.cpp',
2.1 --- a/core/Makefile Fri May 14 20:56:40 2010 -0700
2.2 +++ b/core/Makefile Fri May 14 21:06:06 2010 -0700
2.3 @@ -25,7 +25,7 @@
2.4 OBJECTS += smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
2.5 smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
2.6 smn_filesystem.cpp smn_gameconfigs.cpp smn_halflife.cpp \
2.7 - smn_handles.cpp smn_keyvalues.cpp smn_player.cpp \
2.8 + smn_keyvalues.cpp smn_player.cpp \
2.9 smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp \
2.10 smn_hudtext.cpp smn_nextmap.cpp
2.11 OBJECTS += ExtensionSys.cpp \
3.1 --- a/core/logic/AMBuilder Fri May 14 20:56:40 2010 -0700
3.2 +++ b/core/logic/AMBuilder Fri May 14 21:06:06 2010 -0700
3.3 @@ -40,6 +40,7 @@
3.4 'PhraseCollection.cpp',
3.5 'smn_lang.cpp',
3.6 'smn_string.cpp',
3.7 + 'smn_handles.cpp',
3.8 'sm_crc32.cpp'
3.9 ]
3.10 if AMBuild.target['platform'] == 'windows':
4.1 --- a/core/logic/Makefile Fri May 14 20:56:40 2010 -0700
4.2 +++ b/core/logic/Makefile Fri May 14 21:06:06 2010 -0700
4.3 @@ -36,6 +36,7 @@
4.4 PhraseCollection.cpp \
4.5 smn_lang.cpp \
4.6 smn_string.cpp \
4.7 + smn_handles.cpp \
4.8 smn_players.cpp
4.9
4.10 ##############################################
5.1 --- a/core/logic/intercom.h Fri May 14 20:56:40 2010 -0700
5.2 +++ b/core/logic/intercom.h Fri May 14 21:06:06 2010 -0700
5.3 @@ -42,7 +42,7 @@
5.4 * Add 1 to the RHS of this expression to bump the intercom file
5.5 * This is to prevent mismatching core/logic binaries
5.6 */
5.7 -#define SM_LOGIC_MAGIC (0x0F47C0DE - 12)
5.8 +#define SM_LOGIC_MAGIC (0x0F47C0DE - 13)
5.9
5.10 #if defined SM_LOGIC
5.11 class IVEngineServer
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/core/logic/smn_handles.cpp Fri May 14 21:06:06 2010 -0700
6.3 @@ -0,0 +1,119 @@
6.4 +/**
6.5 + * vim: set ts=4 :
6.6 + * =============================================================================
6.7 + * SourceMod
6.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6.9 + * =============================================================================
6.10 + *
6.11 + * This program is free software; you can redistribute it and/or modify it under
6.12 + * the terms of the GNU General Public License, version 3.0, as published by the
6.13 + * Free Software Foundation.
6.14 + *
6.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
6.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
6.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
6.18 + * details.
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License along with
6.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
6.22 + *
6.23 + * As a special exception, AlliedModders LLC gives you permission to link the
6.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
6.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
6.26 + * by the Valve Corporation. You must obey the GNU General Public License in
6.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
6.28 + * this exception to all derivative works. AlliedModders LLC defines further
6.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
6.30 + * or <http://www.sourcemod.net/license.php>.
6.31 + *
6.32 + * Version: $Id$
6.33 + */
6.34 +
6.35 +#include "common_logic.h"
6.36 +#include <IHandleSys.h>
6.37 +#include <IPluginSys.h>
6.38 +
6.39 +using namespace SourceMod;
6.40 +
6.41 +static cell_t sm_IsValidHandle(IPluginContext *pContext, const cell_t *params)
6.42 +{
6.43 + Handle_t hndl = static_cast<Handle_t>(params[1]);
6.44 +
6.45 + HandleError err = handlesys->ReadHandle(hndl, 0, NULL, NULL);
6.46 +
6.47 + if (err != HandleError_Access
6.48 + && err != HandleError_None)
6.49 + {
6.50 + return 0;
6.51 + }
6.52 +
6.53 + return 1;
6.54 +}
6.55 +
6.56 +static cell_t sm_CloseHandle(IPluginContext *pContext, const cell_t *params)
6.57 +{
6.58 + Handle_t hndl = static_cast<Handle_t>(params[1]);
6.59 + HandleSecurity sec;
6.60 +
6.61 + sec.pIdentity = NULL;
6.62 + sec.pOwner = pContext->GetIdentity();
6.63 +
6.64 + HandleError err = handlesys->FreeHandle(hndl, &sec);
6.65 +
6.66 + if (err == HandleError_None)
6.67 + {
6.68 + return 1;
6.69 + } else if (err == HandleError_Access) {
6.70 + return 0;
6.71 + } else {
6.72 + return pContext->ThrowNativeError("Handle %x is invalid (error %d)", hndl, err);
6.73 + }
6.74 +}
6.75 +
6.76 +static cell_t sm_CloneHandle(IPluginContext *pContext, const cell_t *params)
6.77 +{
6.78 + Handle_t new_hndl;
6.79 + Handle_t hndl = static_cast<Handle_t>(params[1]);
6.80 + HandleError err;
6.81 + IdentityToken_t *pNewOwner;
6.82 +
6.83 + if (params[2] == 0)
6.84 + {
6.85 + pNewOwner = pContext->GetIdentity();
6.86 + } else {
6.87 + Handle_t hPlugin = static_cast<Handle_t>(params[2]);
6.88 + IPlugin *pPlugin = pluginsys->PluginFromHandle(hPlugin, &err);
6.89 + if (!pPlugin)
6.90 + {
6.91 + return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err);
6.92 + }
6.93 + pNewOwner = pPlugin->GetIdentity();
6.94 + }
6.95 +
6.96 + err = handlesys->CloneHandle(hndl, &new_hndl, pNewOwner, NULL);
6.97 +
6.98 + if (err == HandleError_Access)
6.99 + {
6.100 + return 0;
6.101 + } else if (err == HandleError_None) {
6.102 + return new_hndl;
6.103 + } else {
6.104 + return pContext->ThrowNativeError("Handle %x cannot be cloned because it is invalid (error %d)", hndl, err);
6.105 + }
6.106 +}
6.107 +
6.108 +static cell_t sm_GetMyHandle(IPluginContext *pContext, const cell_t *params)
6.109 +{
6.110 + IPlugin *pPlugin = pluginsys->FindPluginByContext(pContext->GetContext());
6.111 +
6.112 + return pPlugin->GetMyHandle();
6.113 +}
6.114 +
6.115 +REGISTER_NATIVES(handles)
6.116 +{
6.117 + {"IsValidHandle", sm_IsValidHandle},
6.118 + {"CloseHandle", sm_CloseHandle},
6.119 + {"CloneHandle", sm_CloneHandle},
6.120 + {"GetMyHandle", sm_GetMyHandle},
6.121 + {NULL, NULL},
6.122 +};
7.1 --- a/core/smn_handles.cpp Fri May 14 20:56:40 2010 -0700
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,117 +0,0 @@
7.4 -/**
7.5 - * vim: set ts=4 :
7.6 - * =============================================================================
7.7 - * SourceMod
7.8 - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
7.9 - * =============================================================================
7.10 - *
7.11 - * This program is free software; you can redistribute it and/or modify it under
7.12 - * the terms of the GNU General Public License, version 3.0, as published by the
7.13 - * Free Software Foundation.
7.14 - *
7.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
7.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
7.18 - * details.
7.19 - *
7.20 - * You should have received a copy of the GNU General Public License along with
7.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
7.22 - *
7.23 - * As a special exception, AlliedModders LLC gives you permission to link the
7.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
7.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
7.26 - * by the Valve Corporation. You must obey the GNU General Public License in
7.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
7.28 - * this exception to all derivative works. AlliedModders LLC defines further
7.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
7.30 - * or <http://www.sourcemod.net/license.php>.
7.31 - *
7.32 - * Version: $Id$
7.33 - */
7.34 -
7.35 -#include "sm_globals.h"
7.36 -#include "HandleSys.h"
7.37 -#include "PluginSys.h"
7.38 -
7.39 -static cell_t sm_IsValidHandle(IPluginContext *pContext, const cell_t *params)
7.40 -{
7.41 - Handle_t hndl = static_cast<Handle_t>(params[1]);
7.42 -
7.43 - HandleError err = g_HandleSys.ReadHandle(hndl, 0, NULL, NULL);
7.44 -
7.45 - if (err != HandleError_Access
7.46 - && err != HandleError_None)
7.47 - {
7.48 - return 0;
7.49 - }
7.50 -
7.51 - return 1;
7.52 -}
7.53 -
7.54 -static cell_t sm_CloseHandle(IPluginContext *pContext, const cell_t *params)
7.55 -{
7.56 - Handle_t hndl = static_cast<Handle_t>(params[1]);
7.57 - HandleSecurity sec;
7.58 -
7.59 - sec.pIdentity = NULL;
7.60 - sec.pOwner = pContext->GetIdentity();
7.61 -
7.62 - HandleError err = g_HandleSys.FreeHandle(hndl, &sec);
7.63 -
7.64 - if (err == HandleError_None)
7.65 - {
7.66 - return 1;
7.67 - } else if (err == HandleError_Access) {
7.68 - return 0;
7.69 - } else {
7.70 - return pContext->ThrowNativeError("Handle %x is invalid (error %d)", hndl, err);
7.71 - }
7.72 -}
7.73 -
7.74 -static cell_t sm_CloneHandle(IPluginContext *pContext, const cell_t *params)
7.75 -{
7.76 - Handle_t new_hndl;
7.77 - Handle_t hndl = static_cast<Handle_t>(params[1]);
7.78 - HandleError err;
7.79 - IdentityToken_t *pNewOwner;
7.80 -
7.81 - if (params[2] == 0)
7.82 - {
7.83 - pNewOwner = pContext->GetIdentity();
7.84 - } else {
7.85 - Handle_t hPlugin = static_cast<Handle_t>(params[2]);
7.86 - IPlugin *pPlugin = g_PluginSys.PluginFromHandle(hPlugin, &err);
7.87 - if (!pPlugin)
7.88 - {
7.89 - return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err);
7.90 - }
7.91 - pNewOwner = pPlugin->GetIdentity();
7.92 - }
7.93 -
7.94 - err = g_HandleSys.CloneHandle(hndl, &new_hndl, pNewOwner, NULL);
7.95 -
7.96 - if (err == HandleError_Access)
7.97 - {
7.98 - return 0;
7.99 - } else if (err == HandleError_None) {
7.100 - return new_hndl;
7.101 - } else {
7.102 - return pContext->ThrowNativeError("Handle %x cannot be cloned because it is invalid (error %d)", hndl, err);
7.103 - }
7.104 -}
7.105 -
7.106 -static cell_t sm_GetMyHandle(IPluginContext *pContext, const cell_t *params)
7.107 -{
7.108 - CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
7.109 -
7.110 - return pPlugin->GetMyHandle();
7.111 -}
7.112 -
7.113 -REGISTER_NATIVES(handles)
7.114 -{
7.115 - {"IsValidHandle", sm_IsValidHandle},
7.116 - {"CloseHandle", sm_CloseHandle},
7.117 - {"CloneHandle", sm_CloneHandle},
7.118 - {"GetMyHandle", sm_GetMyHandle},
7.119 - {NULL, NULL},
7.120 -};
8.1 --- a/public/IPluginSys.h Fri May 14 20:56:40 2010 -0700
8.2 +++ b/public/IPluginSys.h Fri May 14 21:06:06 2010 -0700
8.3 @@ -42,7 +42,7 @@
8.4 #include <sp_vm_api.h>
8.5
8.6 #define SMINTERFACE_PLUGINSYSTEM_NAME "IPluginManager"
8.7 -#define SMINTERFACE_PLUGINSYSTEM_VERSION 4
8.8 +#define SMINTERFACE_PLUGINSYSTEM_VERSION 5
8.9
8.10 /** Context user slot 3 is used Core for holding an IPluginContext pointer. */
8.11 #define SM_CONTEXTVAR_USER 3
8.12 @@ -206,6 +206,13 @@
8.13 * @return Plugin's phrase collection.
8.14 */
8.15 virtual IPhraseCollection *GetPhrases() =0;
8.16 +
8.17 + /**
8.18 + * @brief Returns a plugin's handle.
8.19 + *
8.20 + * @return Plugin's handle.
8.21 + */
8.22 + virtual Handle_t GetMyHandle() =0;
8.23 };
8.24
8.25