From 838e8c7b35dadbe2544d9b1ea91d6eeb2ded7889 Mon Sep 17 00:00:00 2001 From: Brian Simon Date: Wed, 6 Jul 2011 18:11:02 -0400 Subject: [PATCH] Added InactivateClient and ReconnectClient natives to SDKTools (bug 4931, r=fyren). --- extensions/sdktools/AMBuilder | 1 + extensions/sdktools/Makefile | 3 +- extensions/sdktools/clientnatives.cpp | 97 +++++++++++++++++++++++ extensions/sdktools/clientnatives.h | 37 +++++++++ extensions/sdktools/extension.cpp | 4 +- extensions/sdktools/msvc9/sdktools.vcproj | 8 ++ plugins/include/sdktools.inc | 1 + plugins/include/sdktools_client.inc | 52 ++++++++++++ 8 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 extensions/sdktools/clientnatives.cpp create mode 100644 extensions/sdktools/clientnatives.h create mode 100644 plugins/include/sdktools_client.inc diff --git a/extensions/sdktools/AMBuilder b/extensions/sdktools/AMBuilder index 6affcad6..cf83b474 100644 --- a/extensions/sdktools/AMBuilder +++ b/extensions/sdktools/AMBuilder @@ -38,6 +38,7 @@ for i in SM.sdkInfo: 'vnatives.cpp', 'voice.cpp', 'vsound.cpp', + 'clientnatives.cpp', 'hooks.cpp', 'gamerulesnatives.cpp', 'vstringtable.cpp', diff --git a/extensions/sdktools/Makefile b/extensions/sdktools/Makefile index fa74e69e..8f2cc5d7 100644 --- a/extensions/sdktools/Makefile +++ b/extensions/sdktools/Makefile @@ -22,7 +22,8 @@ USEMETA = true OBJECTS = sdk/smsdk_ext.cpp extension.cpp vdecoder.cpp vcallbuilder.cpp vcaller.cpp \ vnatives.cpp vsound.cpp tenatives.cpp trnatives.cpp tempents.cpp vstringtable.cpp \ vhelpers.cpp vglobals.cpp voice.cpp inputnatives.cpp teamnatives.cpp output.cpp \ - outputnatives.cpp hooks.cpp gamerulesnatives.cpp CDetour/detours.cpp asm/asm.c + outputnatives.cpp hooks.cpp gamerulesnatives.cpp CDetour/detours.cpp asm/asm.c \ + clientnatives.cpp ############################################## ### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### diff --git a/extensions/sdktools/clientnatives.cpp b/extensions/sdktools/clientnatives.cpp new file mode 100644 index 00000000..2547be6d --- /dev/null +++ b/extensions/sdktools/clientnatives.cpp @@ -0,0 +1,97 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod SDKTools Extension + * Copyright (C) 2004-2011 AlliedModders LLC. 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 . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," 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, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + + +#include "extension.h" +#include "clientnatives.h" +#include "iserver.h" +#include "iclient.h" + +static cell_t smn_InactivateClient(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + + + if (!iserver) + { + pContext->ThrowNativeError("IServer is null"); + } + + IClient* pClient = iserver->GetClient(params[1] - 1); + if (pClient) + { + pClient->Inactivate(); + } + else + { + pContext->ThrowNativeError("Could not get IClient for client %d", params[1]); + } + + return 1; +} + +static cell_t smn_ReconnectClient(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + + if (!iserver) + { + pContext->ThrowNativeError("IServer is null"); + } + + IClient* pClient = iserver->GetClient(params[1] - 1); + if (pClient) + { + pClient->Reconnect(); + } + else + { + pContext->ThrowNativeError("Could not get IClient for client %d", params[1]); + } + return 1; +} + +sp_nativeinfo_t g_ClientNatives[] = +{ + { "InactivateClient", smn_InactivateClient }, + { "ReconnectClient", smn_ReconnectClient }, + { NULL, NULL }, +}; \ No newline at end of file diff --git a/extensions/sdktools/clientnatives.h b/extensions/sdktools/clientnatives.h new file mode 100644 index 00000000..402cd063 --- /dev/null +++ b/extensions/sdktools/clientnatives.h @@ -0,0 +1,37 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod SDKTools Extension + * Copyright (C) 2004-2008 AlliedModders LLC. 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 . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," 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, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ +#ifndef _INCLUDE_SDKTOOLS_CLIENTNATIVES_H_ +#define _INCLUDE_SDKTOOLS_CLIENTNATIVES_H_ + +static cell_t smn_InactivateClient(IPluginContext *pContext, const cell_t *params); +static cell_t smn_ReconnectClient(IPluginContext *pContext, const cell_t *params); + +#endif \ No newline at end of file diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index b05b633a..9b3f42e5 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -42,7 +42,7 @@ #include "hooks.h" #include "gamerulesnatives.h" #include - +#include "clientnatives.h" /** * @file extension.cpp * @brief Implements SDK Tools extension code. @@ -86,6 +86,7 @@ extern sp_nativeinfo_t g_VoiceNatives[]; extern sp_nativeinfo_t g_EntInputNatives[]; extern sp_nativeinfo_t g_TeamNatives[]; extern sp_nativeinfo_t g_GameRulesNatives[]; +extern sp_nativeinfo_t g_ClientNatives[]; static void InitSDKToolsAPI(); @@ -110,6 +111,7 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late) sharesys->AddNatives(myself, g_TeamNatives); sharesys->AddNatives(myself, g_EntOutputNatives); sharesys->AddNatives(myself, g_GameRulesNatives); + sharesys->AddNatives(myself, g_ClientNatives); SM_GET_IFACE(GAMEHELPERS, g_pGameHelpers); diff --git a/extensions/sdktools/msvc9/sdktools.vcproj b/extensions/sdktools/msvc9/sdktools.vcproj index e87d8df1..5fe29f59 100644 --- a/extensions/sdktools/msvc9/sdktools.vcproj +++ b/extensions/sdktools/msvc9/sdktools.vcproj @@ -1518,6 +1518,10 @@ RelativePath="..\asm\asm.c" > + + @@ -1604,6 +1608,10 @@ RelativePath="..\CellRecipientFilter.h" > + + diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 2125a99c..ad01d1ea 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -50,6 +50,7 @@ #include #include #include +#include enum SDKCallType { diff --git a/plugins/include/sdktools_client.inc b/plugins/include/sdktools_client.inc new file mode 100644 index 00000000..950b67d5 --- /dev/null +++ b/plugins/include/sdktools_client.inc @@ -0,0 +1,52 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This file is part of the SourceMod/SourcePawn SDK. + * + * 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 . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," 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, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#if defined _sdktools_client_included + #endinput +#endif +#define _sdktools_client_included + +/** + * Sets the client to an inactive state waiting for a new map + * + * @param client The client index + * @noreturn + */ +native InactivateClient(client); + +/** + * Reconnect a client without dropping the netchannel + * + * @param client The client index + * @noreturn + */ +native ReconnectClient(client);