steam networking

This commit is contained in:
2026-03-02 17:31:49 +02:00
parent 3db160b49e
commit 0dc8f1b36f
14 changed files with 99 additions and 7 deletions

View File

@@ -93,7 +93,7 @@ CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
};
V_strncpy((char*)stClassSync.m_szEntityName, szName, 256);
if (g_pCurrentConnection)
g_pCurrentConnection->SendPacket({&stClassSync, sizeof(stClassSync)});
g_pCurrentConnection->SendPacket({&stClassSync, sizeof(stClassSync), 0, PACKET_MUST_ARRIVE});
return pEntity;
}
IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
@@ -109,6 +109,7 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
}
return NULL;
}
void CEntitySystem::Think()
{
CBaseEntity *pEntity;

View File

@@ -5,6 +5,7 @@
#include "game.h"
#include "inetworkserver.h"
#include "netprotocol.h"
#include "tier1/utlvector.h"
#ifdef STEAM
#include "steam/isteamgameserver.h"
#include "steam/steam_gameserver.h"
@@ -44,7 +45,6 @@ EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION
uint32_t NET_ServerCallback( NetCallback_t *pCallback )
{
V_printf("hi %u\n", pCallback->m_eType);
if (pCallback->m_eType == NET_SERVER_READY_TO_USE)
{
V_printf("//--- LAUNCHED SERVER AT ---\n");
@@ -59,6 +59,21 @@ uint32_t NET_ServerCallback( NetCallback_t *pCallback )
if (pCallback->m_eType == NET_CONNECTED)
{
V_printf("user %llu has connected, hi!\n", pCallback->m_ullUserID);
CBaseEntity **ppEntitites = EntitySystem()->GetEntities();
for ( int i = 0; i < MAX_EDICTS; i++ )
{
if (ppEntitites[i] == NULL)
continue;
EntityClass_t stClassSync = {
MESSAGE_ENTITY_CLASS_SYNC,
i,
};
V_strncpy((char*)stClassSync.m_szEntityName, ppEntitites[i]->m_szClassName, 256);
if (g_pCurrentConnection)
g_pCurrentConnection->SendPacket({&stClassSync, sizeof(stClassSync), pCallback->m_ullUserConnection, PACKET_MUST_ARRIVE});
}
CBaseEntity *pEntity;
pEntity = EntitySystem()->CreateByClassname("player");
pEntity->Spawn();
@@ -79,7 +94,7 @@ void CFunnyGameBridge::Init()
SteamErrMsg err = { 0 };
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err));
{
V_printf("SteamGameServer_InitEx: %s", err);
V_printf("SteamGameServer_InitEx: %s\n", err);
}
SteamNetworkingUtils()->InitRelayNetworkAccess();
}
@@ -129,7 +144,7 @@ void NET_ProcessPacket( INetworkBase *pBase )
V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName);
pEntity = EntitySystem()->CreateByClassname("player");
pEntity->Spawn();
break;
return;
default:
break;
}
@@ -144,7 +159,6 @@ void CFunnyGameBridge::Frame( float fDelta )
#ifdef STEAM
if (g_pEngineConstants->m_bIsSteam && g_pEngineConstants->m_bIsDedicated)
{
SteamGameServer_RunCallbacks();
if (m_bIsConnectedToSteamRelay == 0 && SteamNetworkingUtils()->GetRelayNetworkStatus(NULL) == k_ESteamNetworkingAvailability_Current)
{
m_bIsConnectedToSteamRelay = 1;
@@ -153,6 +167,7 @@ void CFunnyGameBridge::Frame( float fDelta )
g_pCurrentConnection = g_pPublicConnection;
return;
}
SteamGameServer_RunCallbacks();
}
#endif
if (g_pCurrentConnection)

View File

@@ -6,6 +6,7 @@
void CMOBAPlayer::Spawn()
{
SetThink(Think);
m_fTimer = 0;
};
void CMOBAPlayer::Think( float fDelta )