networking fixes
This commit is contained in:
@@ -37,6 +37,11 @@ public:
|
|||||||
|
|
||||||
CUtlVector<HSteamNetPollGroup> m_hConnections;
|
CUtlVector<HSteamNetPollGroup> m_hConnections;
|
||||||
|
|
||||||
|
CUtlVector<NetPacket_t> m_incomingPackets = {};
|
||||||
|
CUtlVector<SteamNetworkingMessage_t*> m_incomingSteamPackets = {};
|
||||||
|
CUtlVector<SteamNetworkingMessage_t*> m_freeSteamPackets = {};
|
||||||
|
CUtlLock m_lock;
|
||||||
|
|
||||||
STEAM_GAMESERVER_CALLBACK(CSteamNetworkServer, ClientConnected, SteamNetConnectionStatusChangedCallback_t);
|
STEAM_GAMESERVER_CALLBACK(CSteamNetworkServer, ClientConnected, SteamNetConnectionStatusChangedCallback_t);
|
||||||
STEAM_GAMESERVER_CALLBACK(CSteamNetworkServer, SteamNetAuthenticated, SteamNetAuthenticationStatus_t);
|
STEAM_GAMESERVER_CALLBACK(CSteamNetworkServer, SteamNetAuthenticated, SteamNetAuthenticationStatus_t);
|
||||||
};
|
};
|
||||||
@@ -56,6 +61,31 @@ CSteamNetworkServer::~CSteamNetworkServer()
|
|||||||
|
|
||||||
void CSteamNetworkServer::NetThink()
|
void CSteamNetworkServer::NetThink()
|
||||||
{
|
{
|
||||||
|
int nReceived = 1;
|
||||||
|
for ( auto p: m_freeSteamPackets )
|
||||||
|
{
|
||||||
|
p->Release();
|
||||||
|
}
|
||||||
|
m_freeSteamPackets = {};
|
||||||
|
for ( auto &hC: m_hConnections)
|
||||||
|
{
|
||||||
|
nReceived = 1;
|
||||||
|
while (nReceived)
|
||||||
|
{
|
||||||
|
SteamNetworkingMessage_t *pMessages[64];
|
||||||
|
nReceived = m_pInterface->ReceiveMessagesOnConnection(hC, pMessages, 64);
|
||||||
|
for ( int i = 0; i < nReceived; i++ )
|
||||||
|
{
|
||||||
|
m_incomingSteamPackets.AppendTail(pMessages[i]);
|
||||||
|
NetPacket_t packet = {};
|
||||||
|
packet.m_uOwner = pMessages[i]->GetConnection();
|
||||||
|
packet.uSize = pMessages[i]->GetSize();
|
||||||
|
packet.pData = (void*)pMessages[i]->GetData();
|
||||||
|
m_incomingPackets.AppendTail(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSteamNetworkServer::SetCallback( NetCallbackFn fnCallback )
|
void CSteamNetworkServer::SetCallback( NetCallbackFn fnCallback )
|
||||||
@@ -66,16 +96,30 @@ void CSteamNetworkServer::SetCallback( NetCallbackFn fnCallback )
|
|||||||
|
|
||||||
uint32_t CSteamNetworkServer::BHasUpdates()
|
uint32_t CSteamNetworkServer::BHasUpdates()
|
||||||
{
|
{
|
||||||
return 0;
|
return m_incomingPackets.GetSize();
|
||||||
}
|
}
|
||||||
NetPacket_t CSteamNetworkServer::PeekPacket()
|
NetPacket_t CSteamNetworkServer::PeekPacket()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
m_lock.Lock();
|
||||||
|
if (!BHasUpdates())
|
||||||
|
return {};
|
||||||
|
NetPacket_t p = m_incomingPackets[0];
|
||||||
|
m_lock.Unlock();
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetPacket_t CSteamNetworkServer::RecievePacket()
|
NetPacket_t CSteamNetworkServer::RecievePacket()
|
||||||
{
|
{
|
||||||
|
m_lock.Lock();
|
||||||
|
if (!BHasUpdates())
|
||||||
|
return {};
|
||||||
|
NetPacket_t p = m_incomingPackets[0];
|
||||||
|
m_freeSteamPackets.AppendTail(m_incomingSteamPackets[0]);
|
||||||
|
m_incomingSteamPackets.RemoveHead(1);
|
||||||
|
m_incomingPackets.RemoveHead(1);
|
||||||
|
m_lock.Unlock();
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -281,7 +325,12 @@ NetPacket_t CSteamNetworkClient::RecievePacket()
|
|||||||
|
|
||||||
void CSteamNetworkClient::SendPacket( NetPacket_t stPacket )
|
void CSteamNetworkClient::SendPacket( NetPacket_t stPacket )
|
||||||
{
|
{
|
||||||
|
if (stPacket.m_eArrival == PACKET_MAY_ARRIVE)
|
||||||
|
{
|
||||||
|
m_pInterface->SendMessageToConnection(m_hConnection, stPacket.pData, stPacket.uSize, k_nSteamNetworkingSend_Unreliable, 0);
|
||||||
|
}
|
||||||
|
if (stPacket.m_eArrival == PACKET_MUST_ARRIVE)
|
||||||
|
m_pInterface->SendMessageToConnection(m_hConnection, stPacket.pData, stPacket.uSize, k_nSteamNetworkingSend_Reliable, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSteamNetworkClient::BIsActive()
|
bool CSteamNetworkClient::BIsActive()
|
||||||
|
|||||||
14
funnyassets/maps/test.fmap
Normal file
14
funnyassets/maps/test.fmap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"classname": "prop_physics",
|
||||||
|
"model": "game/core/maps/test0.fmesh_c",
|
||||||
|
"physics": "static"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"classname": "prop_physics",
|
||||||
|
"model": "game/core/meshes/cube.fmesh_c",
|
||||||
|
"physics": "dynamic",
|
||||||
|
"origin": [ 0, 15, 0 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "netprotocol.h"
|
#include "netprotocol.h"
|
||||||
|
|
||||||
|
static C_BaseEntity *s_pLocalEntity;
|
||||||
|
|
||||||
CEntitySystem *EntitySystem()
|
CEntitySystem *EntitySystem()
|
||||||
{
|
{
|
||||||
@@ -122,6 +123,7 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex )
|
void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex )
|
||||||
{
|
{
|
||||||
if ( uIndex >= MAX_EDICTS )
|
if ( uIndex >= MAX_EDICTS )
|
||||||
@@ -129,6 +131,8 @@ void CEntitySystem::DestroyEntityByIndex( uint32_t uIndex )
|
|||||||
if (m_pEntities[uIndex])
|
if (m_pEntities[uIndex])
|
||||||
{
|
{
|
||||||
V_printf("Deleting: %i\n", uIndex);
|
V_printf("Deleting: %i\n", uIndex);
|
||||||
|
if (m_pEntities[uIndex] == s_pLocalEntity)
|
||||||
|
s_pLocalEntity = 0;
|
||||||
delete m_pEntities[uIndex];
|
delete m_pEntities[uIndex];
|
||||||
m_pEntities[uIndex] = 0;
|
m_pEntities[uIndex] = 0;
|
||||||
}
|
}
|
||||||
@@ -174,9 +178,6 @@ searchIndex:
|
|||||||
return (char*)pEntity+pCurrentMap->m_pFields[uCurrentIndex].m_uOffset;
|
return (char*)pEntity+pCurrentMap->m_pFields[uCurrentIndex].m_uOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static C_BaseEntity *s_pLocalEntity;
|
|
||||||
|
|
||||||
void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket )
|
void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket )
|
||||||
{
|
{
|
||||||
PlayerPacket_t *pPlayerPacket = (PlayerPacket_t*)pPacket->pData;
|
PlayerPacket_t *pPlayerPacket = (PlayerPacket_t*)pPacket->pData;
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ void C_MOBAPlayer::Think( float fDelta )
|
|||||||
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
|
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
|
||||||
|
|
||||||
|
|
||||||
m_vMovementVector.x = m_bIsForward - m_bIsBack;
|
m_vMovementVector.z = m_bIsForward - m_bIsBack;
|
||||||
|
m_vMovementVector.x = m_bIsLeft - m_bIsRight;
|
||||||
|
|
||||||
if (pEntity == this)
|
if (pEntity == this)
|
||||||
{
|
{
|
||||||
@@ -84,3 +85,44 @@ static void IN_BackUp( int c, char **v ) {
|
|||||||
((C_MOBAPlayer*)pPlayer)->m_bIsBack = false;
|
((C_MOBAPlayer*)pPlayer)->m_bIsBack = false;
|
||||||
}
|
}
|
||||||
static ConCommand endback("-back", IN_BackUp);
|
static ConCommand endback("-back", IN_BackUp);
|
||||||
|
|
||||||
|
static void IN_RightDown( int c, char **v ) {
|
||||||
|
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
|
||||||
|
if (!pPlayer)
|
||||||
|
return;
|
||||||
|
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
|
||||||
|
return;
|
||||||
|
((C_MOBAPlayer*)pPlayer)->m_bIsRight = true;
|
||||||
|
}
|
||||||
|
static ConCommand startright("+right", IN_RightDown);
|
||||||
|
|
||||||
|
static void IN_RightUp( int c, char **v ) {
|
||||||
|
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
|
||||||
|
if (!pPlayer)
|
||||||
|
return;
|
||||||
|
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
|
||||||
|
return;
|
||||||
|
((C_MOBAPlayer*)pPlayer)->m_bIsRight = false;
|
||||||
|
}
|
||||||
|
static ConCommand endright("-right", IN_RightUp);
|
||||||
|
|
||||||
|
|
||||||
|
static void IN_LeftDown( int c, char **v ) {
|
||||||
|
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
|
||||||
|
if (!pPlayer)
|
||||||
|
return;
|
||||||
|
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
|
||||||
|
return;
|
||||||
|
((C_MOBAPlayer*)pPlayer)->m_bIsLeft = true;
|
||||||
|
}
|
||||||
|
static ConCommand startleft("+left", IN_LeftDown);
|
||||||
|
|
||||||
|
static void IN_LeftUp( int c, char **v ) {
|
||||||
|
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
|
||||||
|
if (!pPlayer)
|
||||||
|
return;
|
||||||
|
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
|
||||||
|
return;
|
||||||
|
((C_MOBAPlayer*)pPlayer)->m_bIsLeft = false;
|
||||||
|
}
|
||||||
|
static ConCommand endleft("-left", IN_LeftUp);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEntitySystem::Think()
|
void CEntitySystem::Think( float fDelta )
|
||||||
{
|
{
|
||||||
CBaseEntity *pEntity;
|
CBaseEntity *pEntity;
|
||||||
int i;
|
int i;
|
||||||
@@ -128,7 +128,7 @@ void CEntitySystem::Think()
|
|||||||
if ( !pEntity->m_pfnThink )
|
if ( !pEntity->m_pfnThink )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
(pEntity->*pEntity->m_pfnThink)(0);
|
(pEntity->*pEntity->m_pfnThink)(fDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
|
|
||||||
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
||||||
|
|
||||||
virtual void Think();
|
virtual void Think( float fDelta );
|
||||||
virtual CBaseEntity **GetEntities();
|
virtual CBaseEntity **GetEntities();
|
||||||
|
|
||||||
virtual void NetRecvPacket( NetPacket_t *pPacket );
|
virtual void NetRecvPacket( NetPacket_t *pPacket );
|
||||||
|
|||||||
@@ -162,12 +162,11 @@ void NET_ProcessPacket( INetworkBase *pBase )
|
|||||||
if (g_pCurrentConnection)
|
if (g_pCurrentConnection)
|
||||||
g_pCurrentConnection->SendPacket({&stLocalEntity, sizeof(stLocalEntity), 0, PACKET_MUST_ARRIVE});
|
g_pCurrentConnection->SendPacket({&stLocalEntity, sizeof(stLocalEntity), 0, PACKET_MUST_ARRIVE});
|
||||||
}
|
}
|
||||||
return;
|
break;
|
||||||
case MESSAGE_ENTITY_DATA_SYNC:
|
case MESSAGE_ENTITY_DATA_SYNC:
|
||||||
EntitySystem()->NetRecvPacket(&packet);
|
EntitySystem()->NetRecvPacket(&packet);
|
||||||
pBase->RecievePacket();
|
break;
|
||||||
default:
|
default:
|
||||||
pBase->RecievePacket();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pBase->RecievePacket();
|
pBase->RecievePacket();
|
||||||
@@ -208,7 +207,7 @@ void CFunnyGameBridge::Frame( float fDelta )
|
|||||||
if (g_pCurrentConnection)
|
if (g_pCurrentConnection)
|
||||||
{
|
{
|
||||||
g_pPhysicsWorld->Frame(fTickRate);
|
g_pPhysicsWorld->Frame(fTickRate);
|
||||||
EntitySystem()->Think();
|
EntitySystem()->Think(fTickRate);
|
||||||
EntitySystem()->NetSendThink(g_pCurrentConnection);
|
EntitySystem()->NetSendThink(g_pCurrentConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
void CMOBAPlayer::Spawn()
|
void CMOBAPlayer::Spawn()
|
||||||
{
|
{
|
||||||
CPhysicsProp::Spawn();
|
CBaseEntity::Spawn();
|
||||||
SetModel("game/core/models/cube.fmdl");
|
SetModel("game/core/models/cube.fmdl");
|
||||||
SetScale(1);
|
SetScale(1);
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
@@ -14,8 +14,14 @@ void CMOBAPlayer::Spawn()
|
|||||||
|
|
||||||
void CMOBAPlayer::Think( float fDelta )
|
void CMOBAPlayer::Think( float fDelta )
|
||||||
{
|
{
|
||||||
V_printf("%f %f %f\n", m_vMovementVector.x, m_vMovementVector.y, m_vMovementVector.z);
|
Vector vPosition = GetAbsOrigin();
|
||||||
CPhysicsProp::Think(fDelta);
|
// player might lie to us
|
||||||
|
m_vMovementVector.x = glm_clamp(m_vMovementVector.x, -1, 1);
|
||||||
|
m_vMovementVector.y = glm_clamp(m_vMovementVector.y, -1, 1);
|
||||||
|
|
||||||
|
vPosition.x += m_vMovementVector.x*fDelta*5;
|
||||||
|
vPosition.z += m_vMovementVector.z*fDelta*5;
|
||||||
|
SetAbsOrigin(vPosition);
|
||||||
};
|
};
|
||||||
|
|
||||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include "physicsprop.h"
|
#include "physicsprop.h"
|
||||||
|
|
||||||
class CMOBAPlayer: public CPhysicsProp
|
class CMOBAPlayer: public CBaseModelEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CMOBAPlayer, CPhysicsProp);
|
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
|
||||||
DECLARE_DATADESC();
|
DECLARE_DATADESC();
|
||||||
DECLARE_SERVERCLASS()
|
DECLARE_SERVERCLASS()
|
||||||
|
|
||||||
|
|||||||
0
game/server/worldsystem.cpp
Normal file
0
game/server/worldsystem.cpp
Normal file
0
game/server/worldsystem.h
Normal file
0
game/server/worldsystem.h
Normal file
Reference in New Issue
Block a user