Files
DoomRTX/neo/engine/framework/async/NetworkSystem.cpp
T
Justin Marshall af56d4bfeb Added bot code.
2026-05-19 18:34:55 -07:00

556 lines
12 KiB
C++

/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code.
Quake 4 compatibility additions guarded with QUAKE4.
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
#include "NetworkSystem.h"
idNetworkSystem networkSystemLocal;
idNetworkSystem * networkSystem = &networkSystemLocal;
#ifdef QUAKE4
/*
==================
idNetworkSystem::Shutdown
==================
*/
void idNetworkSystem::Shutdown( void ) {
sortFunctions.Clear();
activeSortFunctions.Clear();
clientServerInfo.Clear();
repeaterInfo.Clear();
httpEnabled = false;
memset( &scannedServer, 0, sizeof( scannedServer ) );
memset( &scannedClient, 0, sizeof( scannedClient ) );
}
#endif // QUAKE4
/*
==================
idNetworkSystem::ServerSendReliableMessage
==================
*/
#ifdef QUAKE4
void idNetworkSystem::ServerSendReliableMessage( int clientNum, const idBitMsg &msg, bool inhibitRepeater ) {
// Doom 3 has no repeater path; keep the Q4 argument for interface compatibility.
(void)inhibitRepeater;
#else
void idNetworkSystem::ServerSendReliableMessage( int clientNum, const idBitMsg &msg ) {
#endif
if ( idAsyncNetwork::server.IsActive() ) {
idAsyncNetwork::server.SendReliableGameMessage( clientNum, msg );
}
}
#ifdef QUAKE4
/*
==================
idNetworkSystem::RepeaterSendReliableMessage
==================
*/
void idNetworkSystem::RepeaterSendReliableMessage( int clientNum, const idBitMsg &msg, bool inhibitHeader, int including ) {
// Repeater networking is a Quake 4 runtime feature. Doom 3 does not have this path.
(void)clientNum;
(void)msg;
(void)inhibitHeader;
(void)including;
}
/*
==================
idNetworkSystem::RepeaterSendReliableMessageExcluding
==================
*/
void idNetworkSystem::RepeaterSendReliableMessageExcluding( int excluding, const idBitMsg &msg, bool inhibitHeader, int clientNum ) {
// Repeater networking is a Quake 4 runtime feature. Doom 3 does not have this path.
(void)excluding;
(void)msg;
(void)inhibitHeader;
(void)clientNum;
}
#endif // QUAKE4
/*
==================
idNetworkSystem::ServerSendReliableMessageExcluding
==================
*/
#ifdef QUAKE4
void idNetworkSystem::ServerSendReliableMessageExcluding( int clientNum, const idBitMsg &msg, bool inhibitRepeater ) {
// Doom 3 has no repeater path; keep the Q4 argument for interface compatibility.
(void)inhibitRepeater;
#else
void idNetworkSystem::ServerSendReliableMessageExcluding( int clientNum, const idBitMsg &msg ) {
#endif
if ( idAsyncNetwork::server.IsActive() ) {
idAsyncNetwork::server.SendReliableGameMessageExcluding( clientNum, msg );
}
}
/*
==================
idNetworkSystem::ServerGetClientPing
==================
*/
int idNetworkSystem::ServerGetClientPing( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientPing( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientPrediction
==================
*/
int idNetworkSystem::ServerGetClientPrediction( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientPrediction( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientTimeSinceLastPacket
==================
*/
int idNetworkSystem::ServerGetClientTimeSinceLastPacket( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientTimeSinceLastPacket( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientTimeSinceLastInput
==================
*/
int idNetworkSystem::ServerGetClientTimeSinceLastInput( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientTimeSinceLastInput( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientOutgoingRate
==================
*/
int idNetworkSystem::ServerGetClientOutgoingRate( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientOutgoingRate( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientIncomingRate
==================
*/
int idNetworkSystem::ServerGetClientIncomingRate( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientIncomingRate( clientNum );
}
return 0;
}
/*
==================
idNetworkSystem::ServerGetClientIncomingPacketLoss
==================
*/
float idNetworkSystem::ServerGetClientIncomingPacketLoss( int clientNum ) {
if ( idAsyncNetwork::server.IsActive() ) {
return idAsyncNetwork::server.GetClientIncomingPacketLoss( clientNum );
}
return 0.0f;
}
#ifdef QUAKE4
/*
==================
idNetworkSystem::ServerGetClientNum
==================
*/
int idNetworkSystem::ServerGetClientNum( int clientId ) {
// Doom 3 does not maintain Q4 clientId mappings here.
return clientId;
}
/*
==================
idNetworkSystem::ServerGetServerTime
==================
*/
int idNetworkSystem::ServerGetServerTime( void ) {
return Sys_Milliseconds();
}
/*
==================
idNetworkSystem::ServerConnectBot
==================
*/
int idNetworkSystem::ServerConnectBot( void ) {
// Bot connection is game/runtime specific. Return failure unless your Q4 server layer wires this in.
return -1;
}
/*
==================
idNetworkSystem::RepeaterGetClientNum
==================
*/
int idNetworkSystem::RepeaterGetClientNum( int clientId ) {
return clientId;
}
#endif // QUAKE4
/*
==================
idNetworkSystem::ClientSendReliableMessage
==================
*/
void idNetworkSystem::ClientSendReliableMessage( const idBitMsg &msg ) {
if ( idAsyncNetwork::client.IsActive() ) {
idAsyncNetwork::client.SendReliableGameMessage( msg );
} else if ( idAsyncNetwork::server.IsActive() ) {
idAsyncNetwork::server.LocalClientSendReliableMessage( msg );
}
}
/*
==================
idNetworkSystem::ClientGetPrediction
==================
*/
int idNetworkSystem::ClientGetPrediction( void ) {
if ( idAsyncNetwork::client.IsActive() ) {
return idAsyncNetwork::client.GetPrediction();
}
return 0;
}
/*
==================
idNetworkSystem::ClientGetTimeSinceLastPacket
==================
*/
int idNetworkSystem::ClientGetTimeSinceLastPacket( void ) {
if ( idAsyncNetwork::client.IsActive() ) {
return idAsyncNetwork::client.GetTimeSinceLastPacket();
}
return 0;
}
/*
==================
idNetworkSystem::ClientGetOutgoingRate
==================
*/
int idNetworkSystem::ClientGetOutgoingRate( void ) {
if ( idAsyncNetwork::client.IsActive() ) {
return idAsyncNetwork::client.GetOutgoingRate();
}
return 0;
}
/*
==================
idNetworkSystem::ClientGetIncomingRate
==================
*/
int idNetworkSystem::ClientGetIncomingRate( void ) {
if ( idAsyncNetwork::client.IsActive() ) {
return idAsyncNetwork::client.GetIncomingRate();
}
return 0;
}
/*
==================
idNetworkSystem::ClientGetIncomingPacketLoss
==================
*/
float idNetworkSystem::ClientGetIncomingPacketLoss( void ) {
if ( idAsyncNetwork::client.IsActive() ) {
return idAsyncNetwork::client.GetIncomingPacketLoss();
}
return 0.0f;
}
#ifdef QUAKE4
/*
==================
idNetworkSystem::GetServerAddress
==================
*/
const char *idNetworkSystem::GetServerAddress( void ) {
return "";
}
/*
==================
idNetworkSystem::GetClientAddress
==================
*/
const char *idNetworkSystem::GetClientAddress( int clientNum ) {
(void)clientNum;
return "";
}
/*
==================
idNetworkSystem::AddFriend
==================
*/
void idNetworkSystem::AddFriend( int clientNum ) {
(void)clientNum;
}
/*
==================
idNetworkSystem::RemoveFriend
==================
*/
void idNetworkSystem::RemoveFriend( int clientNum ) {
(void)clientNum;
}
/*
==================
idNetworkSystem::SetLoadingText
==================
*/
void idNetworkSystem::SetLoadingText( const char *loadingText ) {
(void)loadingText;
}
/*
==================
idNetworkSystem::AddLoadingIcon
==================
*/
void idNetworkSystem::AddLoadingIcon( const char *icon ) {
(void)icon;
}
/*
==================
idNetworkSystem::GetClientGUID
==================
*/
const char *idNetworkSystem::GetClientGUID( int clientNum ) {
(void)clientNum;
return "";
}
/*
==================
idNetworkSystem::GetTrafficStats
==================
*/
void idNetworkSystem::GetTrafficStats( int &bytesSent, int &packetsSent, int &bytesReceived, int &packetsReceived ) const {
bytesSent = 0;
packetsSent = 0;
bytesReceived = 0;
packetsReceived = 0;
}
/*
==================
idNetworkSystem::GetNumScannedServers
==================
*/
int idNetworkSystem::GetNumScannedServers( void ) {
return 0;
}
/*
==================
idNetworkSystem::GetScannedServerInfo
==================
*/
const scannedServer_t *idNetworkSystem::GetScannedServerInfo( int serverNum ) {
(void)serverNum;
return NULL;
}
/*
==================
idNetworkSystem::GetScannedServerClientInfo
==================
*/
const scannedClient_t *idNetworkSystem::GetScannedServerClientInfo( int serverNum, int clientNum ) {
(void)serverNum;
(void)clientNum;
return NULL;
}
static bool SortInfoMatches( const sortInfo_t &a, const sortInfo_t &b ) {
return a.column == b.column && a.compareFn == b.compareFn && a.filterFn == b.filterFn && idStr::Icmp( a.description ? a.description : "", b.description ? b.description : "" ) == 0;
}
/*
==================
idNetworkSystem::AddSortFunction
==================
*/
void idNetworkSystem::AddSortFunction( const sortInfo_t &sortInfo ) {
for ( int i = 0; i < sortFunctions.Num(); i++ ) {
if ( SortInfoMatches( sortFunctions[i], sortInfo ) ) {
return;
}
}
sortFunctions.Append( sortInfo );
}
/*
==================
idNetworkSystem::RemoveSortFunction
==================
*/
bool idNetworkSystem::RemoveSortFunction( const sortInfo_t &sortInfo ) {
bool removed = false;
for ( int i = sortFunctions.Num() - 1; i >= 0; i-- ) {
if ( SortInfoMatches( sortFunctions[i], sortInfo ) ) {
sortFunctions.RemoveIndex( i );
removed = true;
}
}
for ( int i = activeSortFunctions.Num() - 1; i >= 0; i-- ) {
if ( SortInfoMatches( activeSortFunctions[i], sortInfo ) ) {
activeSortFunctions.RemoveIndex( i );
}
}
return removed;
}
/*
==================
idNetworkSystem::UseSortFunction
==================
*/
void idNetworkSystem::UseSortFunction( const sortInfo_t &sortInfo, bool use ) {
if ( use ) {
AddSortFunction( sortInfo );
for ( int i = 0; i < activeSortFunctions.Num(); i++ ) {
if ( SortInfoMatches( activeSortFunctions[i], sortInfo ) ) {
return;
}
}
activeSortFunctions.Append( sortInfo );
return;
}
for ( int i = activeSortFunctions.Num() - 1; i >= 0; i-- ) {
if ( SortInfoMatches( activeSortFunctions[i], sortInfo ) ) {
activeSortFunctions.RemoveIndex( i );
}
}
}
/*
==================
idNetworkSystem::SortFunctionIsActive
==================
*/
bool idNetworkSystem::SortFunctionIsActive( const sortInfo_t &sortInfo ) {
for ( int i = 0; i < activeSortFunctions.Num(); i++ ) {
if ( SortInfoMatches( activeSortFunctions[i], sortInfo ) ) {
return true;
}
}
return false;
}
/*
==================
idNetworkSystem::HTTPEnable
==================
*/
bool idNetworkSystem::HTTPEnable( bool enable ) {
httpEnabled = enable;
return httpEnabled;
}
/*
==================
idNetworkSystem::ClientSetServerInfo
==================
*/
void idNetworkSystem::ClientSetServerInfo( const idDict &serverSI ) {
clientServerInfo = serverSI;
}
/*
==================
idNetworkSystem::RepeaterSetInfo
==================
*/
void idNetworkSystem::RepeaterSetInfo( const idDict &info ) {
repeaterInfo = info;
}
/*
==================
idNetworkSystem::GetViewerGUID
==================
*/
const char *idNetworkSystem::GetViewerGUID( int clientNum ) {
(void)clientNum;
return "";
}
#endif // QUAKE4
/*
==================
idNetworkSystem::AllocateClientSlotForBot
==================
*/
int idNetworkSystem::AllocateClientSlotForBot(int maxPlayersOnServer) {
return idAsyncNetwork::server.AllocOpenClientSlotForAI(maxPlayersOnServer);
}
/*
==================
idNetworkSystem::ServerSetBotUserCommand
==================
*/
int idNetworkSystem::ServerSetBotUserCommand(int clientNum, int frameNum, const usercmd_t& cmd) {
return idAsyncNetwork::server.ServerSetBotUserCommand(clientNum, frameNum, cmd);
}
/*
==================
idNetworkSystem::ServerSetBotUserName
==================
*/
int idNetworkSystem::ServerSetBotUserName(int clientNum, const char* playerName) {
return 0;
}