Skip to content

Commit

Permalink
CLIENT/SERVER: Various network fixes to be more dedicated-server frie…
Browse files Browse the repository at this point in the history
…ndly
  • Loading branch information
MotoLegacy committed Dec 8, 2024
1 parent c0bd852 commit 25832d6
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 115 deletions.
47 changes: 31 additions & 16 deletions source/client/hud.qc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void(float amount, float playernum) RegisterPointChange =

// set our x and y positions
point_elements[index].x_position = 0;
point_elements[index].y_position = (g_height - 90) - (25*(playernum - 1));
point_elements[index].y_position = (g_height - 90) - (25 * (playernum - 1));

// start with an opacity of 1
point_elements[index].opacity = 1;
Expand Down Expand Up @@ -315,10 +315,10 @@ void(float width, float height) HUD_Points =

for (int i = 3; i >= 0; i = i - 1)
{
float player_number = getplayerkeyfloat(i, "viewentity");
float player_number = getplayerkeyfloat(i, "client_index");
entity client = findfloat(world, playernum, player_number);

if (client == world || client.movetype == MOVETYPE_BOUNCE)
if ((client == world || !client.classname) && !client.is_spectator)
continue;

switch(i) {
Expand All @@ -331,15 +331,15 @@ void(float width, float height) HUD_Points =
pointwidth = getTextWidth(ftos(client.points), 12);
x = (99 - pointwidth)/2 + GetUltraWideOffset();

if ((i + 1) == getstatf(STAT_PLAYERNUM)) {
if (player_number == getstatf(STAT_PLAYERNUM)) {
drawpic([3 + GetUltraWideOffset(), g_height - 97 - (i * 25)], "gfx/hud/moneyback.tga", [96, 24], [1,1,1], 1);
Draw_String([x, g_height - 92 - (i * 25)], ftos(client.points), [12, 12], TEXTCOLOR, 1, 0);
} else {
drawpic([-7 + GetUltraWideOffset(), g_height - 97 - (i * 25)], "gfx/hud/moneyback_condensed.tga", [96, 24], [1,1,1], 1);
Draw_String([x - 9, g_height - 92 - (i * 25)], ftos(client.points), [12, 12], TEXTCOLOR, 1, 0);
}

PointUpdate(x + 70, width, height, i + 1);
PointUpdate(x + 70, width, height, player_number);
}
}

Expand Down Expand Up @@ -1524,11 +1524,11 @@ void() HUD_Scores =

for (int i = 0; i < 4; i = i + 1)
{
float player_number = getplayerkeyfloat(i, "viewentity");
float player_number = getplayerkeyfloat(i, "client_index");
entity client = findfloat(world, playernum, player_number);

if (client == world || client.movetype == MOVETYPE_BOUNCE)
break;
if ((client == world || !client.classname) && !client.is_spectator)
continue;

switch(i) {
case 1: TEXTCOLOR = TEXT_LIGHTBLUE; break;
Expand Down Expand Up @@ -1795,18 +1795,27 @@ void(float width, float height) HUD_Waypoint =
HUD_DrawWaypointModeString(5, 175, "impulse 24", "Save current Waypoints");
}

void(float width, float height) HUD_Spectator =
{
drawfill([0, 4], [250, 60], [0, 0, 0], 0.75, 0);
Draw_String([5, 8], "SPECTATING", [18, 18], [1, 1, 1], 1, 0);
Draw_String([5, 30], "You will spawn next Round", [12, 12], [1, 1, 0], 1, 0);
Draw_String([5, 45], "(Fly around or go grab a snack!)", [10, 10], [1, 1, 1], 1, 0);
drawfill([5, 60], [240, 3], [0.3, 0.3, 0.3], 1, 0);
}

void(float width, float height) HUD_PlayerNames =
{
for (float i = 3; i >= 0; i = i - 1) {
if ((i+1) == getstatf(STAT_PLAYERNUM))
float player_number = getplayerkeyfloat(i, "client_index");

if (player_number == getstatf(STAT_PLAYERNUM))
continue;

float player_number = getplayerkeyfloat(i, "viewentity");

string text = getplayerkeyvalue(i, "name");
entity client = findfloat(world, playernum, player_number);

if (client == world || client.movetype == MOVETYPE_BOUNCE)
if (client == world || !client.classname || client.is_spectator)
continue;

// Append "[CHAT] " to the player name if the user is in message mode
Expand Down Expand Up @@ -1856,13 +1865,13 @@ void(float width, float height) HUD_ReviveIcons =
if (revive_icons[player_index].state == 1)
revive_icons[player_index].timer += frametime;

float player_number = getplayerkeyfloat(i, "viewentity");
float player_number = getplayerkeyfloat(i, "client_index");

//string text = getplayerkeyvalue(i, "name");
entity client = findfloat(world, playernum, player_number);

// Client does not exist/is spectating.
if (client == world || client.movetype == MOVETYPE_BOUNCE)
// Client does not exist.
if (client == world || !client.classname || client.is_spectator)
continue;

entity plr = findfloat(world, playernum, player_number);
Expand Down Expand Up @@ -1933,8 +1942,14 @@ void(float width, float height) HUD_Draw =
{
if (cvar("cl_cinematic"))
return;

if (getstatf(STAT_SPECTATING)) {
HUD_Rounds(width, height);
HUD_Spectator(width, height);
return;
}

if (!getstatf(STAT_SPECTATING) && (getstatf(STAT_HEALTH) > 1) && !score_show)
if ((getstatf(STAT_HEALTH) > 1) && !score_show)
{
Draw_Crosshair();

Expand Down
18 changes: 13 additions & 5 deletions source/client/main.qc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void() ToggleMenu =
{
if (serverkey("constate") != "disconnected")
{
if (player_count == 0)
if (player_count == 1)
localcmd("cmd pause\n");

if(current_menu == MENU_NONE)
Expand Down Expand Up @@ -428,15 +428,16 @@ noref void(float isnew) CSQC_Ent_Update =
self.points = readfloat(); // FIXME: this should be made a short, but I know we use price of 1 for some test maps, so I can't do /10 *10 shenanigans.
self.kills = readshort();
self.is_in_menu = readbyte();
self.is_spectator = readbyte();

RegisterPointChange(self.points - old_points, self.playernum);
setmodelindex(self, self.modelindex);

if (self.movetype == MOVETYPE_BOUNCE)
if (self.is_spectator)
self.solid = SOLID_NOT;
else
self.solid = SOLID_SLIDEBOX;
setmodelindex(self, self.modelindex);

RegisterPointChange(self.points - old_points, self.playernum);

if (map_compatibility_mode != MAP_COMPAT_BETA) {
if (self.stance == 2)
Expand All @@ -446,6 +447,13 @@ noref void(float isnew) CSQC_Ent_Update =
} else {
setsize(self, PLAYER_MINS_QUAKE, PLAYER_MAXS_QUAKE);
}

if (self.modelindex == getmodelindex("models/sprites/null.spr") && !self.playernum) {
self.solid = SOLID_NOT;
self.classname = "";
} else {
self.classname = "player";
}
}
// Power-Up
else if (ent_type == 2) {
Expand Down
2 changes: 1 addition & 1 deletion source/server/ai/ai_core.qc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ entity(entity blarg) find_new_enemy =

while(targets != world) {
// Don't target downed players.
if (targets.downed == true || targets.isspec == true) {
if (targets.downed == true || targets.is_spectator == true) {
targets = find(targets, classname, "player");
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion source/server/ai/dog_core.qc
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ float() spawn_a_dogA =
FAIL = false;
pcount = 0;
szombie = getFreeZombieEnt();
if(szombie == world || dogCount >= (2 * (player_count + 1)))
if(szombie == world || dogCount >= (2 * (player_count)))
{
return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions source/server/clientfuncs.qc
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void(entity target, string player_name) nzp_setplayername =
};

void(string chaptertitle, string location, string date, string person, entity who) WorldText = {
if (player_count == 0) {
if (player_count == 1) {
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EVENT_WORLDDATA);
WriteString(MSG_MULTICAST, chaptertitle);
Expand Down Expand Up @@ -472,8 +472,8 @@ void (float achievement_id, optional entity who) GiveAchievement =
#endif // FTE

// this is an achievement specific to an individual
if ((who && who != world) || player_count == 0) {
if (player_count == 0) who = find(world, classname, "player");
if ((who && who != world) || player_count == 1) {
if (player_count == 1) who = find(world, classname, "player");

#ifndef FTE

Expand Down Expand Up @@ -549,6 +549,7 @@ float Player_SendEntity( entity ePVEnt, float flChanged ) {
WriteFloat( MSG_ENTITY, self.points ); // Player Score
WriteShort( MSG_ENTITY, self.kills ); // Player Kills
WriteByte( MSG_ENTITY, self.is_in_menu ); // Player is in a Menu State
WriteByte( MSG_ENTITY, self.is_spectator ); // Player is spectating
return TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion source/server/damage.qc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void() EndGameSetup =
self.weapon2model = "";
self.animend = SUB_Null;
self.perks = 0;
self.isspec = true;
self.is_spectator = true;
self.movetype = MOVETYPE_TOSS;

if (!game_over) {
Expand Down
2 changes: 0 additions & 2 deletions source/server/defs/custom.qc
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ float global_trace_damage_multiplier;

.vector oldvelocity;
.float lastsound_time;
.float isspec;
string mappath;
.float ads_toggle;
float player_count;
entity pl1;
.string fog; // used for hacking in changing fog from world.fog for legacy maps

entity local_client;
Expand Down
10 changes: 5 additions & 5 deletions source/server/entities/perk_a_cola.qc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void() touch_perk =

float perk_purchase_limit;

if (player_count >= 1)
if (player_count > 1)
perk_purchase_limit = self.perk_purchase_limit_coop;
else
perk_purchase_limit = self.perk_purchase_limit_solo;
Expand All @@ -265,7 +265,7 @@ void() touch_perk =
float price;

// Check if we're playing in Co-Op, adjust price if so.
if (player_count >= 1)
if (player_count > 1)
price = self.cost2;
// Nope, use normal/solo cost.
else
Expand Down Expand Up @@ -374,7 +374,7 @@ void() Perk_Jingle =
{
float perk_purchase_limit;

if (player_count >= 1)
if (player_count > 1)
perk_purchase_limit = self.perk_purchase_limit_coop;
else
perk_purchase_limit = self.perk_purchase_limit_solo;
Expand Down Expand Up @@ -413,8 +413,8 @@ void() setup_perk =
// Check for Power
if (power != world && !isPowerOn) {
// Power Switch is present -- but does this machine have an override?
if ((self.perk_requires_power_coop < 0 && player_count >= 1) ||
(self.perk_requires_power_solo < 0 && !player_count))
if ((self.perk_requires_power_coop < 0 && player_count > 1) ||
(self.perk_requires_power_solo < 0 && player_count == 1))
self.requirespower = false;
else
self.requirespower = true;
Expand Down
10 changes: 5 additions & 5 deletions source/server/entities/powerups.qc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void() PU_CarpenterFinalize =

// Reset all windows
while(windows) {
windows.isspec = 0;
windows.is_spectator = 0;
windows.box1owner = world;
windows.usedent = world;
windows.owner = world;
Expand All @@ -424,7 +424,7 @@ entity() PU_CarpenterFindWindow =

while(windows != world) {
// Window needs repaired and is repairable
if (windows.health < 6 && windows.health != -10 && !windows.isspec
if (windows.health < 6 && windows.health != -10 && !windows.is_spectator
&& !windows.ads_release)
return windows;

Expand All @@ -442,7 +442,7 @@ entity() PU_CarpenterFindWindow =
void() PU_CarpenterRepair =
{
// Find a new Barricade to Repair
if (self.goaldummy == world || self.goaldummy.isspec == 0) {
if (self.goaldummy == world || self.goaldummy.is_spectator == 0) {

if (self.goaldummy != world)
self.goaldummy.owner = world;
Expand All @@ -458,7 +458,7 @@ void() PU_CarpenterRepair =
}

// Mark the window as being Repaired
self.goaldummy.isspec = 1;
self.goaldummy.is_spectator = 1;
self.goaldummy.ads_release = 1;
self.goaldummy.owner = self;
}
Expand All @@ -484,7 +484,7 @@ void() PU_CarpenterRepair =
} else {
if (self.ltime < time) {
self.goaldummy.frame = 88;
self.goaldummy.isspec = 0;
self.goaldummy.is_spectator = 0;
self.goaldummy.health = 6;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/server/entities/window.qc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void() window_carpenter_8 =[ 8, window_carpenter_9 ] {self.frame = 72;};
void() window_carpenter_9 =[ 7, window_carpenter_10 ] {self.frame = 79; Sound_PlaySound(self, self.oldmodel, SOUND_TYPE_ENV_OBJECT, SOUND_PRIORITY_PLAYALWAYS); };
void() window_carpenter_10 =[ 8, window_carpenter_11 ] {self.frame = 80;};
void() window_carpenter_11 =[ 7, window_carpenter_12 ] {self.frame = 87; Sound_PlaySound(self, self.oldmodel, SOUND_TYPE_ENV_OBJECT, SOUND_PRIORITY_PLAYALWAYS); };
void() window_carpenter_12 =[ 8, SUB_Null ] {self.frame = 88;self.isspec = 0;};
void() window_carpenter_12 =[ 8, SUB_Null ] {self.frame = 88;self.is_spectator = 0;};


void() Window_Damage =
Expand Down
2 changes: 1 addition & 1 deletion source/server/main.qc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void() worldspawn =
clientstat(STAT_WEAPONZOOM, EV_FLOAT, zoom);
clientstat(STAT_INSTA, EV_FLOAT, insta_icon);
clientstat(STAT_X2, EV_FLOAT, x2_icon);
clientstat(STAT_SPECTATING, EV_FLOAT, isspec);
clientstat(STAT_SPECTATING, EV_FLOAT, is_spectator);
clientstat(STAT_PLAYERNUM, EV_FLOAT, playernum); // literally useless but will be kept in case
clientstat(STAT_PLAYERSTANCE, EV_FLOAT, stance);
clientstat(STAT_FACINGENEMY, EV_FLOAT, facingenemy);
Expand Down
8 changes: 4 additions & 4 deletions source/server/player/last_stand.qc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void(entity client) LastStand_AssignWeapon =
self.weapons[0].weapon_reserve = 0;
}
} else {
if (!player_count) {
if (player_count == 1) {
Weapon_AssignWeapon(0, W_BIATCH, 6, 12);
} else {
Weapon_AssignWeapon(0, W_COLT, 8, 16);
Expand Down Expand Up @@ -461,7 +461,7 @@ void(entity client) LastStand_Begin =

// End the game if no one else is alive.
float players_still_alive = PollPlayersAlive();
if ((player_count && !players_still_alive) || (!player_count && !(self.perks & P_REVIVE))) {
if ((player_count > 1&& !players_still_alive) || (player_count == 1 && !(self.perks & P_REVIVE))) {
EndGameSetup();
return;
}
Expand All @@ -476,7 +476,7 @@ void(entity client) LastStand_Begin =
self.health = 19;

// Initiate Self-Revive on Solo
if ((self.perks & P_REVIVE) && !player_count) {
if ((self.perks & P_REVIVE) && player_count == 1) {
LastStand_InitiateSoloRevive(self);
}
// Spawn the Revive Trigger
Expand All @@ -494,7 +494,7 @@ void(entity client) LastStand_Begin =
LastStand_AssignWeapon(self);

// Spawn Revive Sprite in Co-Op
if (player_count) {
if (player_count > 1) {
EnableReviveIcon(self.playernum);
}

Expand Down
Loading

0 comments on commit 25832d6

Please sign in to comment.