Networking #22

Merged
pieeebot merged 3 commits from ubergamer-pie/cafeberry:networking into networking 2026-08-04 22:19:30 +00:00
2 changed files with 27 additions and 9 deletions
@@ -57,6 +57,9 @@ std::vector<BYTE> NetworkSocketLayer::s_disconnectedSmallIds;
CRITICAL_SECTION NetworkSocketLayer::s_freeSmallIdLock;
std::vector<BYTE> NetworkSocketLayer::s_freeSmallIds;
// only goes true on a successful Initialize(), and a failed one gets retried
static bool s_locksCreated = false;
bool g_MultiplayerHost = false;
bool g_MultiplayerJoin = true;
int g_MultiplayerPort = NETWORK_LAN_DEFAULT_PORT;
@@ -65,6 +68,19 @@ char g_MultiplayerIP[256] = "127.0.0.1";
bool NetworkSocketLayer::Initialize()
{
if (s_initialized) return true;
// Create the locks before touching the platform network stack.
if (!s_locksCreated)
{
InitializeCriticalSection(&s_sendLock);
InitializeCriticalSection(&s_connectionsLock);
InitializeCriticalSection(&s_advertiseLock);
InitializeCriticalSection(&s_discoveryLock);
InitializeCriticalSection(&s_disconnectLock);
InitializeCriticalSection(&s_freeSmallIdLock);
s_locksCreated = true;
}
#if defined _WINDOWS64 || defined _XBOX
WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
@@ -95,19 +111,13 @@ bool NetworkSocketLayer::Initialize()
param.flags = 0;
int result = sceNetInit(&param);
if (result < 0) {
app.DebugPrintf("sceNetInit failed: %d\n", result);
// libnet is brought up before us by the platform layer, which reports EBUSY here.
if (result < 0 && result != SCE_NET_ERROR_EBUSY) {
app.DebugPrintf("sceNetInit failed: 0x%08x\n", result);
return false;
}
#endif
InitializeCriticalSection(&s_sendLock);
InitializeCriticalSection(&s_connectionsLock);
InitializeCriticalSection(&s_advertiseLock);
InitializeCriticalSection(&s_discoveryLock);
InitializeCriticalSection(&s_disconnectLock);
InitializeCriticalSection(&s_freeSmallIdLock);
s_initialized = true;
StartDiscovery();
@@ -190,6 +200,7 @@ void NetworkSocketLayer::Shutdown()
s_disconnectedSmallIds.clear();
DeleteCriticalSection(&s_freeSmallIdLock);
s_freeSmallIds.clear();
s_locksCreated = false;
WSACleanup();
s_initialized = false;
}
@@ -674,6 +674,13 @@ int main()
// debug switch to trial version
//ProfileManager.SetDebugFullOverride(false);
#ifdef DISABLE_PSN
// Set full mode. on DISABLE_PSN we cannot check if its trial or not.
ProfileManager.SetFullVersion(true);
ProfileManager.SetDebugFullOverride(true);
StorageManager.SetSaveDisabled(false);
#endif
//ProfileManager.AddDLC(2);
StorageManager.SetDLCPackageRoot("DLCDrive");
#if 0