nuclide/Source/Server/Client.c

234 lines
5 KiB
C
Raw Normal View History

2019-01-16 16:43:50 +00:00
/***
*
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
*
* See the file LICENSE attached with the sources for usage details.
*
****/
2016-12-01 17:50:48 +00:00
/*
=================
2017-05-01 15:52:01 +00:00
SpectatorThink
2017-05-01 15:52:01 +00:00
Run every frame on every spectator
=================
*/
2017-05-01 15:52:01 +00:00
void SpectatorThink( void ) {
self.SendFlags = 1;
}
2017-05-01 15:52:01 +00:00
/*
=================
2017-05-01 15:52:01 +00:00
ClientKill
2017-05-01 15:52:01 +00:00
Suicide command 'kill' executes this function.
=================
*/
void ClientKill( void ) {
2017-11-11 21:46:04 +00:00
Damage_Apply( self, self, self.health, self.origin, TRUE );
}
/*
=================
2017-05-01 15:52:01 +00:00
ClientConnect
2017-05-01 15:52:01 +00:00
Run whenever a new client joins
=================
*/
2017-05-01 15:52:01 +00:00
void ClientConnect( void ) {}
/*
=================
2017-05-01 15:52:01 +00:00
SpectatorConnect
2017-05-01 15:52:01 +00:00
Called when a spectator joins the game
=================
*/
2017-05-01 15:52:01 +00:00
void SpectatorConnect( void ) {
//Spawn_MakeSpectator();
//Spawn_ObserverCam();
ClientConnect();
PutClientInServer();
}
2016-12-01 17:50:48 +00:00
/*
=================
2017-05-01 15:52:01 +00:00
SpectatorDisconnect
2016-12-01 17:50:48 +00:00
2017-05-01 15:52:01 +00:00
Called when a spectator leaves the game
=================
*/
2017-05-01 15:52:01 +00:00
void SpectatorDisconnect( void ) {
Spray_RemoveAll( self );
2017-05-01 15:52:01 +00:00
}
2016-12-01 17:50:48 +00:00
/*
=================
ClientDisconnect
Run whenever a client quits
=================
*/
2016-12-01 17:50:48 +00:00
void ClientDisconnect( void ) {
// We were part of the session
self.health = 0;
Rules_CountPlayers();
Rules_DeathCheck();
Spray_RemoveAll( self );
2016-12-01 17:50:48 +00:00
}
void DecodeChangeParms(void)
{
g_landmarkpos[0] = parm1;
g_landmarkpos[1] = parm2;
g_landmarkpos[2] = parm3;
self.angles[0] = parm4;
self.angles[1] = parm5;
self.angles[2] = parm6;
}
void SetChangeParms(void)
{
parm1 = g_landmarkpos[0];
parm2 = g_landmarkpos[1];
parm3 = g_landmarkpos[2];
parm4 = self.angles[0];
parm5 = self.angles[1];
parm6 = self.angles[2];
}
/*
=================
PutClientInServer
Puts a client into the world.
=================
*/
2016-12-01 17:50:48 +00:00
void PutClientInServer( void ) {
if ( cvar( "sv_playerslots" ) == 1 ) {
entity spot;
self.SendEntity = Player_SendEntity;
DecodeChangeParms();
if (startspot) {
self.origin = Landmark_GetSpot();
self.fixangle = TRUE;
} else {
spot = find( world, classname, "info_player_start" );
self.origin = spot.origin;
self.angles = spot.angles;
self.fixangle = TRUE;
}
self.classname = "player";
self.health = self.max_health = 100;
forceinfokey( self, "*dead", "0" );
self.takedamage = DAMAGE_YES;
self.solid = SOLID_SLIDEBOX;
self.movetype = MOVETYPE_WALK;
self.flags = FL_CLIENT;
self.vPain = Player_Pain;
self.vDeath = Player_Death;
self.iBleeds = TRUE;
self.fSlotGrenade = 0;
self.viewzoom = 1.0;
setmodel( self, "models/player/vip/vip.mdl" );
setsize( self, VEC_HULL_MIN, VEC_HULL_MAX );
self.view_ofs = VEC_PLAYER_VIEWPOS;
self.velocity = '0 0 0';
self.frame = 1; // Idle frame
self.fBombProgress = 0;
self.team = TEAM_CT;
forceinfokey( self, "*spec", "0" );
return;
}
entity eTarget = world;
Spawn_MakeSpectator();
Spawn_ObserverCam();
2017-03-04 20:08:59 +00:00
self.SendEntity = Player_SendEntity;
2016-12-01 17:50:48 +00:00
// Because we don't want to reset these when we die
Money_AddMoney( self, autocvar_mp_startmoney );
if ( cvar( "mp_timelimit" ) > 0 ) {
if ( autocvar_fcs_voxannounce == TRUE ) {
float fTimeLeft = cvar( "mp_timelimit" ) - ( time / 60 );
Vox_Singlecast( self, sprintf( "we have %s minutes remaining", Vox_TimeToString( fTimeLeft ) ) );
}
}
self.team = 0;
forceinfokey( self, "*team", "0" );
2016-12-01 17:50:48 +00:00
}
/*
=================
SV_RunClientCommand
Funtion that can interrupt client commands before physics are run
=================
*/
2016-12-01 17:50:48 +00:00
void SV_RunClientCommand( void ) {
if (clienttype(self) == CLIENTTYPE_BOT) {
((CBot)self).RunAI();
}
2017-04-19 17:19:02 +00:00
if ( fGameState == GAME_FREEZE && self.health > 0 ) {
2016-12-01 17:50:48 +00:00
input_movevalues = '0 0 0';
//input_buttons = 0;
2016-12-01 17:50:48 +00:00
input_impulse = 0;
}
// The individual zones will just override this behavior
self.fInBombZone = FALSE;
self.fInBuyZone = FALSE;
self.fInHostageZone = FALSE;
self.fInEscapeZone = FALSE;
self.fInVIPZone = FALSE;
QPhysics_Run( self );
Input_Handle();
2016-12-01 17:50:48 +00:00
}
/*
=================
Client_SendEvent
Send a game event
=================
*/
2016-12-01 17:50:48 +00:00
void Client_SendEvent( entity eClient, float fEVType ) {
Weapon_UpdateCurrents();
WriteByte( MSG_MULTICAST, SVC_CGAMEPACKET );
WriteByte( MSG_MULTICAST, fEVType );
WriteByte( MSG_MULTICAST, num_for_edict( eClient ) );
2016-12-01 17:50:48 +00:00
msg_entity = eClient;
multicast( self.origin, MULTICAST_PVS );
2016-12-01 17:50:48 +00:00
}
/*
=================
Client_TriggerCamera
Switches the player camera to a different position for a specific time
=================
*/
void Client_TriggerCamera( entity eTarget, vector vPos, vector vEndPos, float fResetTime ) {
WriteByte( MSG_MULTICAST, SVC_CGAMEPACKET );
WriteByte( MSG_MULTICAST, EV_CAMERATRIGGER );
WriteCoord( MSG_MULTICAST, vPos_x );
WriteCoord( MSG_MULTICAST, vPos_y );
WriteCoord( MSG_MULTICAST, vPos_z );
WriteCoord( MSG_MULTICAST, vEndPos_x );
WriteCoord( MSG_MULTICAST, vEndPos_y );
WriteCoord( MSG_MULTICAST, vEndPos_z );
WriteFloat( MSG_MULTICAST, fResetTime );
msg_entity = eTarget;
2017-04-19 21:06:41 +00:00
multicast( '0 0 0', MULTICAST_ONE );
}