Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 74 additions & 79 deletions src/server/client/client_session_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,12 @@ Implements the legacy ClientConnect logic behind the service seam so future
callers can transition away from the procedural entry point.
=============
*/
bool ClientSessionServiceImpl::ClientConnect(local_game_import_t&, GameLocals&, LevelLocals&,
bool ClientSessionServiceImpl::ClientConnect(local_game_import_t& gi, GameLocals& game, LevelLocals& level,
gentity_t* ent, char* userInfo, const char* socialID, bool isBot) {
local_game_import_t& gi = gi_;
GameLocals& game = game_;
LevelLocals& level = level_;


if (!ent)
return false;

const char* safeSocialID = (socialID && *socialID) ? socialID : "";
auto& configStore = configStore_;

Expand All @@ -482,23 +479,23 @@ gentity_t* ent, char* userInfo, const char* socialID, bool isBot) {
ent->client->sess.admin = false;
ent->client->sess.banned = false;
ent->client->sess.is_888 = false;

//ent->client = game.clients + (ent - g_entities - 1);

if (!isBot) {
if (CheckBanned(gi, level, ent, userInfo, safeSocialID))
return false;
return false;

ClientCheckPermissions(game, ent, safeSocialID);
}

ent->client->sess.team = deathmatch->integer ? Team::None : Team::Free;

// they can connect
ent->client = game.clients + (ent - g_entities - 1);

// set up userInfo early
ClientUserinfoChanged(gi_, game_, level_, ent, userInfo);
ClientUserinfoChanged(gi, game, level, ent, userInfo);

// if there is already a body waiting for us (a loadgame), just
// take it, otherwise spawn one from scratch
Expand Down Expand Up @@ -539,7 +536,7 @@ gentity_t* ent, char* userInfo, const char* socialID, bool isBot) {
}

// set up userInfo early
ClientUserinfoChanged(gi_, game_, level_, ent, userInfo);
ClientUserinfoChanged(gi, game, level, ent, userInfo);

Q_strlcpy(ent->client->sess.socialID, safeSocialID, sizeof(ent->client->sess.socialID));

Expand Down Expand Up @@ -819,97 +816,95 @@ while reporting status via DisconnectResult.
=============
*/
DisconnectResult ClientSessionServiceImpl::ClientDisconnect(local_game_import_t& gi, GameLocals& game, LevelLocals& level, gentity_t* ent) {
(void)gi;
(void)game;
(void)level;

if (!ent || !ent->client) {
return DisconnectResult::InvalidEntity;
}
if (!ent || !ent->client) {
return DisconnectResult::InvalidEntity;
}

gclient_t* cl = ent->client;
const int64_t now = GetCurrentRealTimeMillis();
cl->sess.playEndRealTime = now;
worr::server::client::P_AccumulateMatchPlayTime(cl, now);
gclient_t* cl = game.clients + (ent - g_entities - 1);
ent->client = cl;
const int64_t now = GetCurrentRealTimeMillis();
cl->sess.playEndRealTime = now;
worr::server::client::P_AccumulateMatchPlayTime(cl, now);

OnDisconnect(ent);
OnDisconnect(ent);

if (cl->trackerPainTime) {
RemoveAttackingPainDaemons(ent);
}
if (cl->trackerPainTime) {
RemoveAttackingPainDaemons(ent);
}

if (cl->ownedSphere) {
if (cl->ownedSphere->inUse) {
FreeEntity(cl->ownedSphere);
}
cl->ownedSphere = nullptr;
if (cl->ownedSphere) {
if (cl->ownedSphere->inUse) {
FreeEntity(cl->ownedSphere);
}
cl->ownedSphere = nullptr;
}

PlayerTrail_Destroy(ent);
PlayerTrail_Destroy(ent);

ProBall::HandleCarrierDisconnect(ent);
Harvester_HandlePlayerDisconnect(ent);
ProBall::HandleCarrierDisconnect(ent);
Harvester_HandlePlayerDisconnect(ent);

HeadHunters::DropHeads(ent, nullptr);
HeadHunters::ResetPlayerState(cl);
HeadHunters::DropHeads(ent, nullptr);
HeadHunters::ResetPlayerState(cl);

if (!(ent->svFlags & SVF_NOCLIENT)) {
TossClientItems(ent);
if (!(ent->svFlags & SVF_NOCLIENT)) {
TossClientItems(ent);

gi_.WriteByte(svc_muzzleflash);
gi_.WriteEntity(ent);
gi_.WriteByte(MZ_LOGOUT);
gi_.multicast(ent->s.origin, MULTICAST_PVS, false);
}
gi.WriteByte(svc_muzzleflash);
gi.WriteEntity(ent);
gi.WriteByte(MZ_LOGOUT);
gi.multicast(ent->s.origin, MULTICAST_PVS, false);
}

if (cl->pers.connected && cl->sess.initialised && !cl->sess.is_a_bot) {
if (cl->sess.netName[0]) {
gi_.LocBroadcast_Print(PRINT_HIGH, "{} disconnected.", cl->sess.netName);
}
if (cl->pers.connected && cl->sess.initialised && !cl->sess.is_a_bot) {
if (cl->sess.netName[0]) {
gi.LocBroadcast_Print(PRINT_HIGH, "{} disconnected.", cl->sess.netName);
}
}

FreeClientFollowers(ent);

const int clientIndex = ent->s.number - 1;
MapSelector_ClearVote(level_, clientIndex);
MapSelector_SyncVotes(level_);
MapSelector_ClearVote(level, clientIndex);
MapSelector_SyncVotes(level);

G_RevertVote(cl);

P_SaveGhostSlot(ent);

gi_.unlinkEntity(ent);
ent->s.modelIndex = 0;
ent->solid = SOLID_NOT;
ent->inUse = false;
ent->sv.init = false;
ent->className = "disconnected";
cl->pers.connected = false;
cl->sess.inGame = false;
cl->sess.matchWins = 0;
cl->sess.matchLosses = 0;
cl->pers.limitedLivesPersist = false;
cl->pers.limitedLivesStash = 0;
const bool wasSpawned = cl->pers.spawned;
cl->pers.spawned = false;
ent->timeStamp = level_.time + 1_sec;

if (wasSpawned) {
const auto statsContext = BuildMatchStatsContext(level_);
statsService_.SaveStatsForDisconnect(statsContext, ent);
}
gi.unlinkEntity(ent);
ent->s.modelIndex = 0;
ent->solid = SOLID_NOT;
ent->inUse = false;
ent->sv.init = false;
ent->className = "disconnected";
cl->pers.connected = false;
cl->sess.inGame = false;
cl->sess.matchWins = 0;
cl->sess.matchLosses = 0;
cl->pers.limitedLivesPersist = false;
cl->pers.limitedLivesStash = 0;
const bool wasSpawned = cl->pers.spawned;
cl->pers.spawned = false;
ent->timeStamp = level.time + 1_sec;

if (wasSpawned) {
const auto statsContext = BuildMatchStatsContext(level);
statsService_.SaveStatsForDisconnect(statsContext, ent);
}

if (deathmatch->integer) {
CalculateRanks();
if (deathmatch->integer) {
CalculateRanks();

for (auto ec : active_clients()) {
if (ec->client->showScores) {
ec->client->menu.updateTime = level_.time;
}
for (auto ec : active_clients()) {
if (ec->client->showScores) {
ec->client->menu.updateTime = level.time;
}
}
}

return DisconnectResult::Success;}
return DisconnectResult::Success;
}


/*
Expand Down