cssdm_players.cpp
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 0 67dcd379a2d5
permissions -rw-r--r--
Update linix CS:GO gamedata
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * By David "BAILOPAN" Anderson
     6  * All rights reserved.
     7  * ===============================================================
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or (at
    12  * your option) any later version.
    13  * 
    14  * This program is distributed in the hope that it will be useful, but
    15  * WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    17  * General Public License for more details.
    18  * 
    19  * You should have received a copy of the GNU General Public License
    20  * along with this program; see the file COPYING; if not, write to the
    21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
    22  * MA 02110-1301 USA
    23  * 
    24  * Version: $Id$
    25  */
    26 
    27 #include "cssdm_players.h"
    28 #include "cssdm_headers.h"
    29 #include "cssdm_utils.h"
    30 #include "cssdm_config.h"
    31 #include "cssdm_includesdk.h"
    32 
    33 ClientListener g_ClientListener;
    34 dm_player_t g_players[65];
    35 
    36 void DM_ResetPlayer(int client);
    37 void DM_ActivatePlayer(int client);
    38 
    39 void ClientListener::OnClientConnected(int client)
    40 {
    41 	memset(&g_players[client], 0, sizeof(dm_player_t));
    42 }
    43 
    44 void ClientListener::OnClientDisconnecting(int client)
    45 {
    46 	dm_player_t *player = DM_GetPlayer(client);
    47 
    48 	DM_ResetPlayer(client);
    49 }
    50 
    51 void ClientListener::OnClientPutInServer(int client)
    52 {
    53 	DM_ActivatePlayer(client);
    54 }
    55 
    56 void DM_ResetPlayer(int client)
    57 {
    58 	dm_player_t *player = DM_GetPlayer(client);
    59 	if (!player)
    60 	{
    61 		return;
    62 	}
    63 
    64 	if (player->respawn_timer)
    65 	{
    66 		timersys->KillTimer(player->respawn_timer);
    67 	}
    68 
    69 	memset(player, 0, sizeof(dm_player_t));
    70 }
    71 
    72 void DM_ActivatePlayer(int client)
    73 {
    74 	dm_player_t *player = DM_GetPlayer(client);
    75 	if (!player)
    76 	{
    77 		return;
    78 	}
    79 
    80 	CBaseEntity *pEntity = DM_GetBaseEntity(client);
    81 	if (!pEntity)
    82 	{
    83 		return;
    84 	}
    85 
    86 	player->pEdict = gamehelpers->EdictOfIndex(client);
    87 	player->pEntity = pEntity;
    88 	player->pInfo = playerinfomngr->GetPlayerInfo(player->pEdict);
    89 	player->pBot = botmanager->GetBotController(player->pEdict);
    90 	player->userid = engine->GetPlayerUserId(player->pEdict);
    91 }
    92 
    93 dm_player_t *DM_GetPlayer(int client)
    94 {
    95 	if (client < 1 || client > gpGlobals->maxClients)
    96 	{
    97 		return NULL;
    98 	}
    99 
   100 	return &g_players[client];
   101 }