about summary refs log tree commit diff
path: root/src/game/server/game_server.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-26 07:15:52 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-26 07:15:52 +0000
commitc1da3b23b64e31eef6970a8eb021fc79bdd65e08 (patch)
tree21db1c457c9ae76c615f031cc3a0052a7432f827 /src/game/server/game_server.cpp
parent02de6728983454da110e5d2c9758c3baee6e68de (diff)
downloadzcatch-c1da3b23b64e31eef6970a8eb021fc79bdd65e08.tar.gz
zcatch-c1da3b23b64e31eef6970a8eb021fc79bdd65e08.zip
fixed so that the latnecy doesn't update so fast
Diffstat (limited to 'src/game/server/game_server.cpp')
-rw-r--r--src/game/server/game_server.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index 31052aa5..3dfa0773 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -1006,6 +1006,27 @@ int player::handle_weapons()
 
 void player::tick()
 {
+	// do latency stuff
+	{
+		client_info info;
+		if(server_getclientinfo(client_id, &info))
+		{
+			latency_accum += info.latency;
+			latency_accum_max = max(latency_accum_max, info.latency);
+			latency_accum_min = min(latency_accum_min, info.latency);
+		}
+			
+		if(server_tick()%server_tickspeed() == 0)
+		{
+			latency_avg = latency_accum/server_tickspeed();
+			latency_max = latency_accum_max;
+			latency_min = latency_accum_min;
+			latency_accum = 0;
+			latency_accum_min = 1000;
+			latency_accum_max = 0;
+		}
+	}
+
 	// TODO: rework the input to be more robust
 	// TODO: remove this tick count, it feels weird
 	if(dead)
@@ -1287,11 +1308,8 @@ void player::snap(int snaping_client)
 	player->vy = (int)vel.y;
 	player->emote = EMOTE_NORMAL;
 
-	player->latency = 0;
-	client_info info;
-	if(server_getclientinfo(client_id, &info))
-		player->latency = info.latency;
-	
+	player->latency = latency_avg;
+	player->latency_flux = latency_max-latency_min;
 
 	player->ammocount = weapons[active_weapon].ammo;
 	player->health = 0;
@@ -1637,8 +1655,8 @@ void mods_client_enter(int client_id)
 void mods_client_drop(int client_id)
 {
 	dbg_msg("mods", "client drop %d", client_id);
-	players[client_id].client_id = -1;
 	world.remove_entity(&players[client_id]);
+	players[client_id].client_id = -1;
 }
 
 void mods_message(int msg, int client_id)