diff --git a/game/experiment/scripts/lua/includes/extensions/entity_networked_variables.lua b/game/experiment/scripts/lua/includes/extensions/entity_networked_variables.lua index 87d72cc838..ee3c8cce80 100644 --- a/game/experiment/scripts/lua/includes/extensions/entity_networked_variables.lua +++ b/game/experiment/scripts/lua/includes/extensions/entity_networked_variables.lua @@ -15,6 +15,11 @@ if (GAMEUI) then return end +if (SERVER) then + Networks.AddNetworkString("EntityNetworkedVariable") + Networks.AddNetworkString("EntityNetworkedVariableSet") +end + local ENTITY_META = _R.Entity local Hooks = require("hooks") @@ -196,7 +201,7 @@ else if (not IsValid(entity)) then -- TODO: Should this happen? We should only be sending to players that are in the PVS of the entity -- Erroring for debug, but perhaps we should just ignore it - error("Received networked variable for invalid entity") + debugPrint("Received networked variable for invalid entity") return end diff --git a/game/experiment/scripts/lua/includes/extensions/networked_variables.lua b/game/experiment/scripts/lua/includes/extensions/networked_variables.lua index d44b91620a..ce2b39ae85 100644 --- a/game/experiment/scripts/lua/includes/extensions/networked_variables.lua +++ b/game/experiment/scripts/lua/includes/extensions/networked_variables.lua @@ -8,6 +8,11 @@ if (GAMEUI) then return end +if (SERVER) then + Networks.AddNetworkString("GlobalNetworkedVariable") + Networks.AddNetworkString("GlobalNetworkedVariableSet") +end + local Hooks = require("hooks") local debugPrint = function(...) diff --git a/game/experiment/scripts/lua/includes/extensions/networks.lua b/game/experiment/scripts/lua/includes/extensions/networks.lua index 6cb0b3377e..35e10aefd0 100644 --- a/game/experiment/scripts/lua/includes/extensions/networks.lua +++ b/game/experiment/scripts/lua/includes/extensions/networks.lua @@ -137,7 +137,9 @@ local networkStrings = NetworkStringTables.FindTable("LuaNetworkStrings") function Networks.AddNetworkString(name) if (SERVER) then - networkStrings:AddString(true, name) + local networkId = networkStrings:AddString(true, name) + + printDebug("Added network string: " .. name .. " with id " .. networkId) end end diff --git a/game/experiment/scripts/lua/utilities/test/networks.lua b/game/experiment/scripts/lua/utilities/test/networks.lua index 7c7a5db368..66fc8044f4 100644 --- a/game/experiment/scripts/lua/utilities/test/networks.lua +++ b/game/experiment/scripts/lua/utilities/test/networks.lua @@ -3,8 +3,10 @@ local countReceived = 0 -- After registering the network strings we must wait a bit -local DELAY_BEFORE_START = 1 -local DELAY_BEFORE_DONE = 2 +local DELAY_BEFORE_START = 0.2 +local DELAY_BEFORE_DONE = 1 + +print("Running net module tests...") if (SERVER) then Networks.AddNetworkString("TestMessage") @@ -13,7 +15,6 @@ if (SERVER) then Networks.AddNetworkString("CTestMessage2") Networks.Receive("TestMessage", function(length, client) - print("TestMessage", length, client) local message = Networks.ReadString() local num = Networks.ReadFloat() @@ -30,7 +31,6 @@ if (SERVER) then end) Networks.Receive("TestMessage2", function(length, client) - print("TestMessage2", length, client) Networks.Start("CTestMessage2") Networks.WriteString("Hello again, client!") Networks.Send(client) @@ -47,7 +47,6 @@ end if (CLIENT) then Networks.Receive("CTestMessage", function(length) - print("CTestMessage", length) local num = Networks.ReadFloat() local message = Networks.ReadString() local position = Networks.ReadVector() @@ -60,7 +59,6 @@ if (CLIENT) then end) Networks.Receive("CTestMessage2", function(length) - print("CTestMessage2", length) local message = Networks.ReadString() assert(message == "Hello again, client!", "Received incorrect message from server!") diff --git a/src/common/networksystem/isockets.h b/src/common/networksystem/isockets.h index 21eedd09ae..1d92fb39d8 100644 --- a/src/common/networksystem/isockets.h +++ b/src/common/networksystem/isockets.h @@ -18,9 +18,8 @@ class CNetPacket; #define NETWORK_MESSAGE_HEADER_BITS ( NETWORK_MESSAGE_GROUP_BITS + NETWORK_MESSAGE_INDEX_BITS ) // The size of messages is sent first, so we know when a 'packet' is complete -#define NETWORK_MESSAGE_LENGTH_DATATYPE short // Max 64KB -#define NET_MAX_PAYLOAD 4000 -#define NET_MAX_MESSAGE 4096 +#define NETWORK_MESSAGE_LENGTH_DATATYPE uint16 // Max 64KB +#define NETWORK_MAX_MESSAGE_LENGTH ( 1 << ( sizeof( NETWORK_MESSAGE_LENGTH_DATATYPE ) * 8 ) ) enum { diff --git a/src/game/shared/experiment/util/lnetworks.cpp b/src/game/shared/experiment/util/lnetworks.cpp index 0202dc8cce..967d06a07f 100644 --- a/src/game/shared/experiment/util/lnetworks.cpp +++ b/src/game/shared/experiment/util/lnetworks.cpp @@ -22,7 +22,7 @@ LUA_BINDING_BEGIN( Networks, InternalSendToClients, "library", "Send a message t message->SetBuffer( ( const char * )messageWriter.GetBasePointer(), messageWriter.GetNumBytesWritten() ); // If no clients are probided, broadcast the message - if ( lua_isnil( L, 3 ) ) + if ( lua_isnoneornil( L, 3 ) ) { g_pNetworkManager->BroadcastServerToClientMessage( message ); } diff --git a/src/networksystem/netpacket.cpp b/src/networksystem/netpacket.cpp index c06f667e3e..61e4a2e492 100644 --- a/src/networksystem/netpacket.cpp +++ b/src/networksystem/netpacket.cpp @@ -4,7 +4,7 @@ #include "netpacket.h" #include "networksystem.h" -static CUtlMemoryPool s_PacketBufferAlloc( NET_MAX_MESSAGE, 8, CUtlMemoryPool::GROW_SLOW ); +static CUtlMemoryPool s_PacketBufferAlloc( NETWORK_MAX_MESSAGE_LENGTH, 8, CUtlMemoryPool::GROW_SLOW ); DEFINE_FIXEDSIZE_ALLOCATOR( CNetPacket, 32, CUtlMemoryPool::GROW_SLOW ); CNetPacket::CNetPacket() diff --git a/src/networksystem/tcp_sockets.cpp b/src/networksystem/tcp_sockets.cpp index 03bb799b93..09c503252d 100644 --- a/src/networksystem/tcp_sockets.cpp +++ b/src/networksystem/tcp_sockets.cpp @@ -70,7 +70,9 @@ int CTcpClientSocket::ReceiveMessageLength() return -1; } - return LittleLong( *( NETWORK_MESSAGE_LENGTH_DATATYPE * )buffer ); + NETWORK_MESSAGE_LENGTH_DATATYPE length; + memcpy( &length, buffer, sizeof( length ) ); + return LittleLong( length ); } bool CTcpClientSocket::Receive( CUtlBuffer &data ) @@ -122,7 +124,8 @@ bool CTcpClientSocket::Send( const char *data, size_t dataLength ) { // Send the length of the message first char lengthBuffer[sizeof( NETWORK_MESSAGE_LENGTH_DATATYPE )]; - *( NETWORK_MESSAGE_LENGTH_DATATYPE * )lengthBuffer = LittleLong( ( int )dataLength ); + NETWORK_MESSAGE_LENGTH_DATATYPE length = LittleLong( ( int )dataLength ); + memcpy( lengthBuffer, &length, sizeof( length ) ); int bytesSent = send( m_Socket, lengthBuffer, sizeof( lengthBuffer ), 0 ); diff --git a/src/public/lnetwork.cpp b/src/public/lnetwork.cpp index a9b70e3172..2caac30452 100644 --- a/src/public/lnetwork.cpp +++ b/src/public/lnetwork.cpp @@ -762,8 +762,8 @@ LUA_REGISTRATION_INIT( MessageWriters ) LUA_BINDING_BEGIN( MessageWriters, Create, "library", "Creates a new MessageWriter for writing network messages" ) { - void *buffer = malloc( NET_MAX_MESSAGE ); - bf_write *writer = new bf_write( buffer, NET_MAX_MESSAGE ); + void *buffer = malloc( NETWORK_MAX_MESSAGE_LENGTH ); + bf_write *writer = new bf_write( buffer, NETWORK_MAX_MESSAGE_LENGTH ); lua_pushbf_write( L, writer ); return 1; }