Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions Core/GameEngine/Source/Common/System/AsciiString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ inline char* skipNonSeps(char* p, const char* seps)
//-----------------------------------------------------------------------------
inline char* skipWhitespace(char* p)
{
while (*p && isspace(*p))
while (*p && isspace((unsigned char)*p))
++p;
return p;
}

//-----------------------------------------------------------------------------
inline char* skipNonWhitespace(char* p)
{
while (*p && !isspace(*p))
while (*p && !isspace((unsigned char)*p))
++p;
return p;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ void AsciiString::trimEnd()
// Clip trailing white space from the string.
const int len = strlen(peek());
int index = len;
while (index > 0 && isspace(getCharAt(index - 1)))
while (index > 0 && isspace((unsigned char)getCharAt(index - 1)))
{
--index;
}
Expand Down Expand Up @@ -378,7 +378,7 @@ void AsciiString::toLower()
char* c = buf;
while (c && *c)
{
*c = tolower(*c);
*c = (char)tolower((unsigned char)*c);
c++;
}
set(buf);
Expand Down
41 changes: 34 additions & 7 deletions Core/GameEngine/Source/GameNetwork/GameSpy/MainMenuUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "../OnlineServices_Init.h"
#include "Common/GameEngine.h"
#include "Common/GlobalData.h"
#include "../PluginInterfaces.h"


///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -649,15 +650,15 @@ static GHTTPBool overallStatsCallback( GHTTPRequest request, GHTTPResult result,
message.nextToken(&totalLine, "\n");
message.nextToken(&winsLine, "\n");
message.nextToken(&lossesLine, "\n");
while (totalLine.isNotEmpty() && !isdigit(totalLine.getCharAt(0)))
while (totalLine.isNotEmpty() && !isdigit((unsigned char)totalLine.getCharAt(0)))
{
totalLine = totalLine.str()+1;
}
while (winsLine.isNotEmpty() && !isdigit(winsLine.getCharAt(0)))
while (winsLine.isNotEmpty() && !isdigit((unsigned char)winsLine.getCharAt(0)))
{
winsLine = winsLine.str()+1;
}
while (lossesLine.isNotEmpty() && !isdigit(lossesLine.getCharAt(0)))
while (lossesLine.isNotEmpty() && !isdigit((unsigned char)lossesLine.getCharAt(0)))
{
lossesLine = lossesLine.str()+1;
}
Expand Down Expand Up @@ -865,19 +866,45 @@ void StartPatchCheck()
// GENERALS ONLINE
NGMP_OnlineServicesManager::CreateInstance();

onlineCancelWindow = MessageBoxCancel(TheGameText->fetch("GUI:CheckingForPatches"),
TheGameText->fetch("GUI:CheckingForPatches"), CancelPatchCheckCallbackAndReopenDropdown);

// online services must be initialized
// TODO_NGMP: Uninit this when leaving MP, waste of resources and cycles
NGMP_OnlineServicesManager::GetInstance()->Init();

// if we have an AC plugin loaded but the AC external process isnt running, show an error message
if (AnticheatPlugInterface::IsPluginLoaded())
{
if (!AnticheatPlugInterface::IsExternalProcessRunning())
{
MessageBoxOk(TheGameText->fetchOrSubstitute("GUI:ACErrorHeader", L"AntiCheat Error"),
TheGameText->fetchOrSubstitute("GUI:ACExternalProcessNotRunning", L"The AntiCheat external process is not running"),
CancelPatchCheckCallbackAndReopenDropdown);

return;
}
}
else if (AnticheatPlugInterface::DidPluginFailToLoad()) // Did we have something to load but it failed?
{
std::string strPlugin = NGMP_OnlineServicesManager::Settings.GetAnticheatPlugin();
std::string pluginPath = std::format("plugins/{}/{}.dll", strPlugin.c_str(), strPlugin.c_str());

UnicodeString strErrorMssage;
strErrorMssage.format(L"Failed to load the AntiCheat plugin from path: %hs. Please make sure the plugin is installed correctly.", pluginPath.c_str());

MessageBoxOk(TheGameText->fetchOrSubstitute("GUI:ACErrorHeader", L"AntiCheat Error"),
strErrorMssage,
CancelPatchCheckCallbackAndReopenDropdown);

return;
}

onlineCancelWindow = MessageBoxCancel(TheGameText->fetch("GUI:CheckingForPatches"),
TheGameText->fetch("GUI:CheckingForPatches"), CancelPatchCheckCallbackAndReopenDropdown);

NGMP_OnlineServicesManager::GetInstance()->StartVersionCheck([](bool bSuccess, bool bNeedsUpdate)
{
#if defined(USE_TEST_ENV) || defined(USE_DEBUG_ON_LIVE_SERVER)
bNeedsUpdate = false;
#endif

cantConnectBeforeOnline = !bSuccess;
mustDownloadPatch = bNeedsUpdate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void GameResultsThreadClass::Thread_Function()
// resolve the hostname
const char *hostnameBuffer = req.hostname.c_str();
UnsignedInt IP = 0xFFFFFFFF;
if (isdigit(hostnameBuffer[0]))
if (isdigit((unsigned char)hostnameBuffer[0]))
{
IP = inet_addr(hostnameBuffer);
in_addr hostNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void PingThreadClass::Thread_Function()
// resolve the hostname
const char *hostnameBuffer = req.hostname.c_str();
UnsignedInt IP = 0xFFFFFFFF;
if (isdigit(hostnameBuffer[0]))
if (isdigit((unsigned char)hostnameBuffer[0]))
{
IP = inet_addr(hostnameBuffer);
in_addr hostNode;
Expand Down
2 changes: 1 addition & 1 deletion Core/GameEngine/Source/GameNetwork/NAT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ void NAT::sendMangledPortNumberToTarget(UnsignedShort mangledPort, GameSlot *tar
void NAT::processGlobalMessage(Int slotNum, const char *options) {
const char *ptr = options;
// skip preceding whitespace.
while (isspace(*ptr)) {
while (isspace((unsigned char)*ptr)) {
++ptr;
}
DEBUG_LOG(("NAT::processGlobalMessage - got message from slot %d, message is \"%s\"", slotNum, ptr));
Expand Down
4 changes: 2 additions & 2 deletions Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void dumpBufferToLog(const void *vBuf, Int len, const char *fname, Int line)
for (dumpindex2 = 0; dumpindex2 < numBytesThisLine; ++dumpindex2)
{
char c = buf[offset + dumpindex2];
DEBUG_LOG_RAW(("%c", (isprint(c)?c:'.')));
DEBUG_LOG_RAW(("%c", (isprint((unsigned char)c)?c:'.')));
}
DEBUG_LOG_RAW(("\n"));
}
Expand All @@ -105,7 +105,7 @@ UnsignedInt ResolveIP(AsciiString host)
}

// String such as "127.0.0.1"
if (isdigit(host.getCharAt(0)))
if (isdigit((unsigned char)host.getCharAt(0)))
{
return ( ntohl(inet_addr(host.str())) );
}
Expand Down
52 changes: 41 additions & 11 deletions Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ void MilesAudioManager::reset()
void MilesAudioManager::update()
{
AudioManager::update();

// Check audio device is initialized before updating
if (m_digitalHandle == nullptr)
{
return; // Audio device not ready, skip update
}

setDeviceListenerPosition();
processRequestList();
processPlayingList();
Expand Down Expand Up @@ -1193,15 +1200,21 @@ void MilesAudioManager::freeAllMilesHandles()
std::list<HSAMPLE>::iterator it;
for ( it = m_availableSamples.begin(); it != m_availableSamples.end(); /* empty */ ) {
HSAMPLE sample = *it;
AIL_release_sample_handle(sample);
if (sample != nullptr)
{
AIL_release_sample_handle(sample);
}
it = m_availableSamples.erase(it);
}
m_num2DSamples = 0;

std::list<H3DSAMPLE>::iterator it3D;
for ( it3D = m_available3DSamples.begin(); it3D != m_available3DSamples.end(); /* empty */ ) {
H3DSAMPLE sample3D = *it3D;
AIL_release_3D_sample_handle(sample3D);
if (sample3D != nullptr)
{
AIL_release_3D_sample_handle(sample3D);
}
it3D = m_available3DSamples.erase(it3D);
}
m_num3DSamples = 0;
Expand Down Expand Up @@ -1440,9 +1453,13 @@ AsciiString MilesAudioManager::getMusicTrackName() const
void MilesAudioManager::openDevice()
{
if (!TheGlobalData->m_audioOn) {
m_digitalHandle = nullptr;
return;
}

// Always clear handle at start - only set if initialization succeeds
m_digitalHandle = nullptr;

AIL_set_redist_directory("MSS\\");
AIL_startup();
Int retval = 0;
Expand All @@ -1453,22 +1470,31 @@ void MilesAudioManager::openDevice()

retval = AIL_quick_startup(audioSettings->m_useDigital, audioSettings->m_useMidi, audioSettings->m_outputRate, audioSettings->m_outputBits, audioSettings->m_outputChannels);

// Quick handles tells us where to store the various devices. For now, we're only interested in the digital handle.
if (!retval) {
// Initialization failed - ensure m_digitalHandle stays nullptr and audio is disabled
m_digitalHandle = nullptr;
setOn(false, AudioAffect_All);
return; // EXIT EARLY - don't continue with invalid device
}

// Only get handles if initialization succeeded
AIL_quick_handles(&m_digitalHandle, nullptr, nullptr);

if (retval) {
buildProviderList();
} else {
// if we couldn't initialize any devices, turn sound off (fail silently)
setOn( false, AudioAffect_All );
// If we still don't have a valid handle, disable audio
if (m_digitalHandle == nullptr) {
setOn(false, AudioAffect_All);
return;
}

// Device initialized successfully - proceed with setup
buildProviderList();
selectProvider(TheAudio->getProviderIndex(m_pref3DProvider));

// Now that we're all done, update the cached variables so that everything is in sync.
TheAudio->refreshCachedVariables();

if (!isValidProvider()) {
m_digitalHandle = nullptr; // Mark as invalid if provider check fails
return;
}

Expand All @@ -1478,9 +1504,13 @@ void MilesAudioManager::openDevice()
//-------------------------------------------------------------------------------------------------
void MilesAudioManager::closeDevice()
{
freeAllMilesHandles();
unselectProvider();
AIL_shutdown();
if (m_digitalHandle != nullptr)
{
freeAllMilesHandles();
unselectProvider();
AIL_shutdown();
m_digitalHandle = nullptr;
}
}

//-------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AsciiString encodeURL(AsciiString source)
const char *ptr = source.str();
while (*ptr)
{
if (isalnum(*ptr) || allowedChars.find(*ptr))
if (isalnum((unsigned char)*ptr) || allowedChars.find(*ptr))
{
target.concat(*ptr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void readUntilSemicolon( File *fp, char *buffer, int maxBufLen )
fp->read(buffer + i, 1);

// make all whitespace characters spaces
if( isspace( buffer[ i ] ) )
if( isspace( (unsigned char)buffer[ i ] ) )
{

if( start == FALSE )
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ set(GAMEENGINE_SRC
Include/GameNetwork/GeneralsOnline/HTTP/HTTPManager.h
Include/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.h
Include/GameNetwork/GeneralsOnline/NextGenTransport.h
Include/GameNetwork/GeneralsOnline/PluginInterfaces.h
Include/GameNetwork/GeneralsOnline/Vendor/ValveNetworkingSockets/steam/isteamnetworkingmessages.h
Include/GameNetwork/GeneralsOnline/Vendor/ValveNetworkingSockets/steam/isteamnetworkingsockets.h
Include/GameNetwork/GeneralsOnline/Vendor/ValveNetworkingSockets/steam/isteamnetworkingutils.h
Expand Down Expand Up @@ -1196,6 +1197,7 @@ set(GAMEENGINE_SRC
Source/GameNetwork/GeneralsOnline/OnlineServices_MatchmakingInterface.cpp
Source/GameNetwork/GeneralsOnline/NextGenTransport.cpp
Source/GameNetwork/GeneralsOnline/NetworkBitstream.cpp
Source/GameNetwork/GeneralsOnline/PluginInterfaces.cpp
)

if(RTS_GAMEMEMORY_ENABLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class GenOnlineSettings
return m_Render_FramerateLimit_FPSVal;
}

std::string GetAnticheatPlugin() const { return m_Plugins_Anticheat; }

bool Social_Notifications_FriendComesOnline_Menus() { return m_Social_Notification_FriendComesOnline_Menus; }
bool Social_Notifications_FriendComesOnline_Gameplay() { return m_Social_Notification_FriendComesOnline_Gameplay; }
bool Social_Notifications_FriendGoesOffline_Menus() { return m_Social_Notification_FriendGoesOffline_Menus; }
Expand Down Expand Up @@ -136,6 +138,8 @@ class GenOnlineSettings
bool m_Social_Notification_PlayerSendsRequest_Menus = true;
bool m_Social_Notification_PlayerSendsRequest_Gameplay = true;

std::string m_Plugins_Anticheat = std::string();

EHTTPVersion m_Network_HTTPVersion = EHTTPVersion::HTTP_VERSION_AUTO;
bool m_Network_UseAlternativeEndpoint = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
#include "GameNetwork/GeneralsOnline/OnlineServices_StatsInterface.h"
#include "GameNetwork/GeneralsOnline/OnlineServices_MatchmakingInterface.h"
#include "GameNetwork/GeneralsOnline/OnlineServices_SocialInterface.h"

#include "GameNetwork/GeneralsOnline/PluginInterfaces.h"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "NGMP_include.h"
#include <ws2ipdef.h>
#include "ValveNetworkingSockets/steam/steamnetworkingsockets.h"
#include <mutex>
#include "ValveNetworkingSockets/steam/steamnetworkingcustomsignaling.h"

class NetRoom_ChatMessagePacket;

Expand Down Expand Up @@ -43,6 +44,8 @@ class PlayerConnection

int SendGamePacket(void* pBuffer, uint32_t totalDataSize);

void SendACPacket(const void* pData, uint32_t dataLen);

void UpdateLatencyHistogram();

bool IsIPV4();
Expand Down Expand Up @@ -91,6 +94,8 @@ class PlayerConnection
int ComputeConnectionScore();

HSteamNetConnection m_hSteamConnection = k_HSteamNetConnection_Invalid;

void LiteUpdateForAC();
};

struct LobbyMemberEntry;
Expand Down Expand Up @@ -166,12 +171,10 @@ class NetworkMesh
}


std::queue<QueuedGamePacket> m_queueQueuedGamePackets;

bool HasGamePacket();
QueuedGamePacket RecvGamePacket();
int SendGamePacket(void* pBuffer, uint32_t totalDataSize, int64_t userID);

void SendACPacket(uint32_t userID, const void* pData, uint32_t dataLen);

void StartConnectionSignalling(int64_t remoteUserID, uint16_t preferredPort);
void DisconnectUser(int64_t remoteUserID);
void Disconnect();
Expand All @@ -198,6 +201,7 @@ class NetworkMesh

private:
std::map<int64_t, PlayerConnection> m_mapConnections;
mutable std::recursive_mutex m_mapConnectionsMutex; // Synchronizes access to m_mapConnections

ISignalingClient* m_pSignaling = nullptr;

Expand Down
Loading
Loading