Skip to content

Commit 5b8cb6d

Browse files
committed
Add trap_GetPings; remove ping from playerstate
1 parent 782d78f commit 5b8cb6d

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

src/engine/qcommon/q_shared.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,6 @@ union OpaquePlayerState {
19281928
struct {
19291929
// These fields must be identical to ones at the start of playerState_t
19301930
vec3_t origin;
1931-
int ping; // shouldn't even be here?
19321931
int persistant[16];
19331932
int viewheight;
19341933
int clientNum;

src/engine/server/sg_msgdef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum gameImport_t
4545
G_GEN_FINGERPRINT,
4646
G_GET_PLAYER_PUBKEY,
4747
G_GET_TIME_STRING,
48+
G_GET_PINGS,
4849

4950
BOT_ALLOCATE_CLIENT,
5051
BOT_FREE_CLIENT,
@@ -102,6 +103,10 @@ using GetTimeStringMsg = IPC::SyncMessage<
102103
IPC::Message<IPC::Id<VM::QVM, G_GET_TIME_STRING>, int, std::string, qtime_t>,
103104
IPC::Reply<std::string>
104105
>;
106+
using GetPingsMsg = IPC::SyncMessage<
107+
IPC::Message<IPC::Id<VM::QVM, G_GET_PINGS>>,
108+
IPC::Reply<std::vector<int>>
109+
>;
105110

106111
using BotAllocateClientMsg = IPC::SyncMessage<
107112
IPC::Message<IPC::Id<VM::QVM, BOT_ALLOCATE_CLIENT>>,

src/engine/server/sv_main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,6 @@ void SV_CalcPings()
12101210
cl->ping = 999;
12111211
}
12121212
}
1213-
1214-
// let the game module know about the ping
1215-
OpaquePlayerState* ps = SV_GameClientNum( i );
1216-
ps->ping = cl->ping;
12171213
}
12181214
}
12191215

src/engine/server/sv_sgame.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,16 @@ void GameVM::QVMSyscall(int syscallNum, Util::Reader& reader, IPC::Channel& chan
564564
});
565565
break;
566566

567+
case G_GET_PINGS:
568+
IPC::HandleMsg<GetPingsMsg>(channel, std::move(reader), [this](std::vector<int>& pings) {
569+
int count = sv_maxclients->integer;
570+
pings.resize(count);
571+
for (int i = 0; i < count; i++) {
572+
pings[i] = svs.clients[i].ping;
573+
}
574+
});
575+
break;
576+
567577
case BOT_ALLOCATE_CLIENT:
568578
IPC::HandleMsg<BotAllocateClientMsg>(channel, std::move(reader), [this](int& output) {
569579
output = SV_BotAllocateClient();

src/shared/server/sg_api.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ void trap_GetTimeString(char *buffer, int size, const char *format, const qtime_
144144
Q_strncpyz(buffer, text.c_str(), size);
145145
}
146146

147+
// length of returned vector is sv_maxclients
148+
std::vector<int> trap_GetPings()
149+
{
150+
std::vector<int> pings;
151+
VM::SendMsg<GetPingsMsg>(pings);
152+
return pings;
153+
}
154+
155+
147156
int trap_BotAllocateClient()
148157
{
149158
int res;

src/shared/server/sg_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ int trap_RSA_GenerateMessage( const char *public_key, char *clearte
5353
void trap_GenFingerprint( const char *pubkey, int size, char *buffer, int bufsize );
5454
void trap_GetPlayerPubkey( int clientNum, char *pubkey, int size );
5555
void trap_GetTimeString( char *buffer, int size, const char *format, const qtime_t *tm );
56+
std::vector<int> trap_GetPings();
5657

5758
#endif

0 commit comments

Comments
 (0)