Redesigned how server commands work. The "plugins" command will be back soon.
1 #include "sm_globals.h"
5 static cell_t sm_IsValidHandle(IPluginContext *pContext, const cell_t *params)
7 Handle_t hndl = static_cast<Handle_t>(params[1]);
9 HandleError err = g_HandleSys.ReadHandle(hndl, 0, NULL, NULL);
11 if (err != HandleError_Access
12 && err != HandleError_None)
20 static cell_t sm_CloseHandle(IPluginContext *pContext, const cell_t *params)
22 Handle_t hndl = static_cast<Handle_t>(params[1]);
26 sec.pOwner = pContext->GetIdentity();
28 HandleError err = g_HandleSys.FreeHandle(hndl, &sec);
30 if (err == HandleError_None)
33 } else if (err == HandleError_Access) {
36 return pContext->ThrowNativeError("Handle %x is invalid (error %d)", hndl, err);
40 static cell_t sm_CloneHandle(IPluginContext *pContext, const cell_t *params)
43 Handle_t hndl = static_cast<Handle_t>(params[1]);
45 IdentityToken_t *pNewOwner;
49 pNewOwner = pContext->GetIdentity();
51 Handle_t hPlugin = static_cast<Handle_t>(params[2]);
52 IPlugin *pPlugin = g_PluginSys.PluginFromHandle(hPlugin, &err);
55 return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err);
57 pNewOwner = pPlugin->GetIdentity();
60 err = g_HandleSys.CloneHandle(hndl, &new_hndl, pNewOwner, NULL);
62 if (err == HandleError_Access)
65 } else if (err == HandleError_None) {
68 return pContext->ThrowNativeError("Handle %x cannot be cloned because it is invalid (error %d)", hndl, err);
72 REGISTER_NATIVES(handles)
74 {"IsValidHandle", sm_IsValidHandle},
75 {"CloseHandle", sm_CloseHandle},
76 {"CloneHandle", sm_CloneHandle},