fix: zero out bots pings prior bot disconnection
fix: do not hook pfnCmdStart if game doesn't support fake pings
This commit is contained in:
parent
c298e607ae
commit
a4233dfaf8
4 changed files with 46 additions and 15 deletions
|
|
@ -82,6 +82,9 @@ public:
|
||||||
// send modified pings to all the clients
|
// send modified pings to all the clients
|
||||||
void emitPings (edict_t *to);
|
void emitPings (edict_t *to);
|
||||||
|
|
||||||
|
// reset ping to zero values
|
||||||
|
void resetPings (edict_t *to);
|
||||||
|
|
||||||
// checks if same model omitting the models directory
|
// checks if same model omitting the models directory
|
||||||
bool isModel (const edict_t *ent, StringRef model);
|
bool isModel (const edict_t *ent, StringRef model);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -389,22 +389,24 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int interfaceVersion) {
|
||||||
bots.frame ();
|
bots.frame ();
|
||||||
};
|
};
|
||||||
|
|
||||||
table->pfnCmdStart = [] (const edict_t *player, usercmd_t *cmd, unsigned int random_seed) {
|
if (game.is (GameFlags::HasFakePings)) {
|
||||||
auto ent = const_cast <edict_t *> (player);
|
table->pfnCmdStart = [] (const edict_t *player, usercmd_t *cmd, unsigned int random_seed) {
|
||||||
|
auto ent = const_cast <edict_t *> (player);
|
||||||
|
|
||||||
// if we're handle pings for bots and clients, clear IN_SCORE button so SV_ShouldUpdatePing engine function return false, and SV_EmitPings will not overwrite our results
|
// if we're handle pings for bots and clients, clear IN_SCORE button so SV_ShouldUpdatePing engine function return false, and SV_EmitPings will not overwrite our results
|
||||||
if (game.is (GameFlags::HasFakePings) && cv_show_latency.int_ () == 2) {
|
if (cv_show_latency.int_ () == 2) {
|
||||||
if (!util.isFakeClient (ent) && (ent->v.oldbuttons | ent->v.button | cmd->buttons) & IN_SCORE) {
|
if (!util.isFakeClient (ent) && (ent->v.oldbuttons | ent->v.button | cmd->buttons) & IN_SCORE) {
|
||||||
cmd->buttons &= ~IN_SCORE;
|
cmd->buttons &= ~IN_SCORE;
|
||||||
util.emitPings (ent);
|
util.emitPings (ent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (game.is (GameFlags::Metamod)) {
|
if (game.is (GameFlags::Metamod)) {
|
||||||
RETURN_META (MRES_IGNORED);
|
RETURN_META (MRES_IGNORED);
|
||||||
}
|
}
|
||||||
dllapi.pfnCmdStart (ent, cmd, random_seed);
|
dllapi.pfnCmdStart (ent, cmd, random_seed);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
table->pfnPM_Move = [] (playermove_t *pm, int server) {
|
table->pfnPM_Move = [] (playermove_t *pm, int server) {
|
||||||
// this is the player movement code clients run to predict things when the server can't update
|
// this is the player movement code clients run to predict things when the server can't update
|
||||||
|
|
|
||||||
|
|
@ -1691,6 +1691,9 @@ void Bot::markStale () {
|
||||||
// switch chatter icon off
|
// switch chatter icon off
|
||||||
showChatterIcon (false, true);
|
showChatterIcon (false, true);
|
||||||
|
|
||||||
|
// reset bots ping to default
|
||||||
|
util.resetPings (ent ());
|
||||||
|
|
||||||
// mark bot as leaving
|
// mark bot as leaving
|
||||||
m_isStale = true;
|
m_isStale = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -498,7 +498,7 @@ void BotSupport::syncCalculatePings () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BotSupport::emitPings (edict_t *to) {
|
void BotSupport::emitPings (edict_t *to) {
|
||||||
MessageWriter msg;
|
static MessageWriter msg;
|
||||||
|
|
||||||
auto isThirdpartyBot = [] (edict_t *ent) {
|
auto isThirdpartyBot = [] (edict_t *ent) {
|
||||||
return !bots[ent] && (ent->v.flags & FL_FAKECLIENT);
|
return !bots[ent] && (ent->v.flags & FL_FAKECLIENT);
|
||||||
|
|
@ -509,6 +509,11 @@ void BotSupport::emitPings (edict_t *to) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do not send to dormants
|
||||||
|
if (client.ent->v.flags & FL_DORMANT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// no ping, no fun
|
// no ping, no fun
|
||||||
if (!client.ping) {
|
if (!client.ping) {
|
||||||
client.ping = getPingBitmask (client.ent, rg.get (5, 10), rg.get (15, 40));
|
client.ping = getPingBitmask (client.ent, rg.get (5, 10), rg.get (15, 40));
|
||||||
|
|
@ -518,7 +523,25 @@ void BotSupport::emitPings (edict_t *to) {
|
||||||
.writeLong (client.ping)
|
.writeLong (client.ping)
|
||||||
.end ();
|
.end ();
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
void BotSupport::resetPings (edict_t *to) {
|
||||||
|
static MessageWriter msg;
|
||||||
|
|
||||||
|
// no reset if game isn't support them
|
||||||
|
if (!game.is (GameFlags::HasFakePings)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &client : m_clients) {
|
||||||
|
if (!(client.flags & ClientFlags::Used) || isFakeClient (client.ent)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.start (MSG_ONE_UNRELIABLE, SVC_PINGS, nullptr, client.ent)
|
||||||
|
.writeLong (getPingBitmask (to, 0, 0))
|
||||||
|
.end ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BotSupport::isModel (const edict_t *ent, StringRef model) {
|
bool BotSupport::isModel (const edict_t *ent, StringRef model) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue