extensions/sdktools/clientnatives.cpp
author Nicholas Hastings <skamonkey@gmail.com>
Fri Jul 08 07:53:31 2011 -0400 (2011-07-08)
changeset 3348 fcae86e8cb8f
parent 3339 ab8bc0494926
child 4361 54866d2316bf
permissions -rw-r--r--
Backed out changeset: 9007dacc012d
bluebriansimon@3339
     1
/**
bluebriansimon@3339
     2
 * vim: set ts=4 :
bluebriansimon@3339
     3
 * =============================================================================
bluebriansimon@3339
     4
 * SourceMod SDKTools Extension
bluebriansimon@3339
     5
 * Copyright (C) 2004-2011 AlliedModders LLC.  All rights reserved.
bluebriansimon@3339
     6
 * =============================================================================
bluebriansimon@3339
     7
 *
bluebriansimon@3339
     8
 * This program is free software; you can redistribute it and/or modify it under
bluebriansimon@3339
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
bluebriansimon@3339
    10
 * Free Software Foundation.
bluebriansimon@3339
    11
 * 
bluebriansimon@3339
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
bluebriansimon@3339
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
bluebriansimon@3339
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
bluebriansimon@3339
    15
 * details.
bluebriansimon@3339
    16
 *
bluebriansimon@3339
    17
 * You should have received a copy of the GNU General Public License along with
bluebriansimon@3339
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
bluebriansimon@3339
    19
 *
bluebriansimon@3339
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
bluebriansimon@3339
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
bluebriansimon@3339
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
bluebriansimon@3339
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
bluebriansimon@3339
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
bluebriansimon@3339
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
bluebriansimon@3339
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
bluebriansimon@3339
    27
 * or <http://www.sourcemod.net/license.php>.
bluebriansimon@3339
    28
 *
bluebriansimon@3339
    29
 * Version: $Id$
bluebriansimon@3339
    30
 */
bluebriansimon@3339
    31
bluebriansimon@3339
    32
bluebriansimon@3339
    33
#include "extension.h"
bluebriansimon@3339
    34
#include "clientnatives.h"
bluebriansimon@3339
    35
#include "iserver.h"
bluebriansimon@3339
    36
#include "iclient.h"
bluebriansimon@3339
    37
bluebriansimon@3339
    38
static cell_t smn_InactivateClient(IPluginContext *pContext, const cell_t *params)
bluebriansimon@3339
    39
{
bluebriansimon@3339
    40
	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
bluebriansimon@3339
    41
	
bluebriansimon@3339
    42
	if (player == NULL)
bluebriansimon@3339
    43
	{
bluebriansimon@3339
    44
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
bluebriansimon@3339
    45
	}
bluebriansimon@3339
    46
bluebriansimon@3339
    47
bluebriansimon@3339
    48
	if (!iserver)
bluebriansimon@3339
    49
	{
bluebriansimon@3339
    50
		pContext->ThrowNativeError("IServer is null");
bluebriansimon@3339
    51
	}
bluebriansimon@3339
    52
bluebriansimon@3339
    53
	IClient* pClient = iserver->GetClient(params[1] - 1);
bluebriansimon@3339
    54
	if (pClient)
bluebriansimon@3339
    55
	{
bluebriansimon@3339
    56
		pClient->Inactivate();
bluebriansimon@3339
    57
	}
bluebriansimon@3339
    58
	else
bluebriansimon@3339
    59
	{
bluebriansimon@3339
    60
		pContext->ThrowNativeError("Could not get IClient for client %d", params[1]);
bluebriansimon@3339
    61
	}
bluebriansimon@3339
    62
bluebriansimon@3339
    63
	return 1;
bluebriansimon@3339
    64
}
bluebriansimon@3339
    65
bluebriansimon@3339
    66
static cell_t smn_ReconnectClient(IPluginContext *pContext, const cell_t *params)
bluebriansimon@3339
    67
{
bluebriansimon@3339
    68
	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
bluebriansimon@3339
    69
	
bluebriansimon@3339
    70
	if (player == NULL)
bluebriansimon@3339
    71
	{
bluebriansimon@3339
    72
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
bluebriansimon@3339
    73
	}
bluebriansimon@3339
    74
bluebriansimon@3339
    75
	if (!iserver)
bluebriansimon@3339
    76
	{
bluebriansimon@3339
    77
		pContext->ThrowNativeError("IServer is null");
bluebriansimon@3339
    78
	}
bluebriansimon@3339
    79
bluebriansimon@3339
    80
	IClient* pClient = iserver->GetClient(params[1] - 1);
bluebriansimon@3339
    81
	if (pClient)
bluebriansimon@3339
    82
	{
bluebriansimon@3339
    83
		pClient->Reconnect();
bluebriansimon@3339
    84
	}
bluebriansimon@3339
    85
	else
bluebriansimon@3339
    86
	{
bluebriansimon@3339
    87
		pContext->ThrowNativeError("Could not get IClient for client %d", params[1]);
bluebriansimon@3339
    88
	}
bluebriansimon@3339
    89
	return 1;
bluebriansimon@3339
    90
}
bluebriansimon@3339
    91
bluebriansimon@3339
    92
sp_nativeinfo_t g_ClientNatives[] = 
bluebriansimon@3339
    93
{
bluebriansimon@3339
    94
	{ "InactivateClient",	smn_InactivateClient	},
bluebriansimon@3339
    95
	{ "ReconnectClient",	smn_ReconnectClient		},
bluebriansimon@3339
    96
	{ NULL,					NULL					},
bluebriansimon@3339
    97
};