Skip to content

Commit

Permalink
Moved network chain into C++
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDushan committed Jun 24, 2020
1 parent b8083ce commit e3d3605
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 280 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -260,7 +260,6 @@ set( QCOMMONLIST_HEADERS
set( QCOMMONLIST_SOURCES
${MOUNT_DIR}/qcommon/common.cpp
${MOUNT_DIR}/qcommon/msg.cpp
${MOUNT_DIR}/qcommon/net_chan.cpp
${MOUNT_DIR}/qcommon/parse.cpp
)

Expand All @@ -273,6 +272,7 @@ set( FRAMEWORKS_HEADERS
${MOUNT_DIR}/API/MD4_api.h
${MOUNT_DIR}/API/MD5_api.h
${MOUNT_DIR}/API/Network_api.h
${MOUNT_DIR}/API/NetworkChain_api.h
${MOUNT_DIR}/framework/FileSystem.h
${MOUNT_DIR}/framework/CVarSystem.h
${MOUNT_DIR}/framework/CmdSystem.h
Expand All @@ -286,6 +286,7 @@ set( FRAMEWORKS_HEADERS
${MOUNT_DIR}/framework/Unzip.h
${MOUNT_DIR}/framework/SurfaceFlags_Tech3.h
${MOUNT_DIR}/framework/Network.h
${MOUNT_DIR}/framework/NetworkChain.h
)

set( FRAMEWORKS_SOURCES
Expand All @@ -301,6 +302,7 @@ set( FRAMEWORKS_SOURCES
${MOUNT_DIR}/framework/Puff.cpp
${MOUNT_DIR}/framework/Unzip.cpp
${MOUNT_DIR}/framework/Network.cpp
${MOUNT_DIR}/framework/NetworkChain.cpp
)

set( CLIENTLIST_HEADERS
Expand Down
59 changes: 59 additions & 0 deletions src/engine/API/NetworkChain_api.h
@@ -0,0 +1,59 @@
////////////////////////////////////////////////////////////////////////////////////////
// Copyright(C) 2019 - 2020 Dusan Jocic <dusanjocic@msn.com>
//
// This file is part of the OpenWolf GPL Source Code.
// OpenWolf Source Code is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWolf Source Code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OpenWolf Source Code. If not, see <http://www.gnu.org/licenses/>.
//
// In addition, the OpenWolf Source Code is also subject to certain additional terms.
// You should have received a copy of these additional terms immediately following the
// terms and conditions of the GNU General Public License which accompanied the
// OpenWolf Source Code. If not, please request a copy in writing from id Software
// at the address below.
//
// If you have questions concerning this license or the applicable additional terms,
// you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
// Suite 120, Rockville, Maryland 20850 USA.
//
// -------------------------------------------------------------------------------------
// File name: NetworkChain_api.h
// Compilers: Visual Studio 2019, gcc 7.3.0
// Description:
// -------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////

#ifndef __NETWORKCHAIN_API_H__
#define __NETWORKCHAIN_API_H__

//
// idNetworkChainSystem
//
class idNetworkChainSystem
{
public:
virtual void Init( sint port ) = 0;
virtual void Setup( netsrc_t sock, netchan_t* chan, netadr_t adr, sint qport ) = 0;
virtual void TransmitNextFragment( netchan_t* chan ) = 0;
virtual void Transmit( netchan_t* chan, sint length, const uchar8* data ) = 0;
virtual bool Process( netchan_t* chan, msg_t* msg ) = 0;
virtual bool GetLoopPacket( netsrc_t sock, netadr_t* net_from, msg_t* net_message ) = 0;
virtual void FlushPacketQueue( void ) = 0;
virtual void SendPacket( netsrc_t sock, sint length, const void* data, netadr_t to ) = 0;
virtual void OutOfBandPrint( netsrc_t sock, netadr_t adr, pointer format, ... ) = 0;
virtual void OutOfBandData( netsrc_t sock, netadr_t adr, uchar8* format, sint len ) = 0;
virtual sint StringToAdr( pointer s, netadr_t* a, netadrtype_t family ) = 0;
};

extern idNetworkChainSystem* networkChainSystem;

#endif //!__THREADS_API_H__
27 changes: 13 additions & 14 deletions src/engine/client/cl_main.cpp
Expand Up @@ -1085,7 +1085,7 @@ void CL_MapLoading( void )
cls.keyCatchers = 0;
clientScreenSystem->UpdateScreen();
clc.connectTime = -RETRANSMIT_TIMEOUT;
NET_StringToAdr( cls.servername, &clc.serverAddress, NA_UNSPEC );
networkChainSystem->StringToAdr( cls.servername, &clc.serverAddress, NA_UNSPEC );
// we don't need a challenge on the localhost

CL_CheckForResend();
Expand Down Expand Up @@ -1405,8 +1405,7 @@ void CL_RequestMotd( void )
}
Com_DPrintf( "Resolving %s\n", MASTER_SERVER_NAME );

switch( NET_StringToAdr( MASTER_SERVER_NAME, &cls.updateServer,
NA_UNSPEC ) )
switch( networkChainSystem->StringToAdr( MASTER_SERVER_NAME, &cls.updateServer, NA_UNSPEC ) )
{
case 0:
Com_Printf( "Couldn't resolve master address\n" );
Expand All @@ -1430,7 +1429,7 @@ void CL_RequestMotd( void )
Info_SetValueForKey( info, "renderer", cls.glconfig.renderer_string );
Info_SetValueForKey( info, "version", com_version->string );

NET_OutOfBandPrint( NS_CLIENT, cls.updateServer, "getmotd%s", info );
networkChainSystem->OutOfBandPrint( NS_CLIENT, cls.updateServer, "getmotd%s", info );
}

/*
Expand Down Expand Up @@ -1598,7 +1597,7 @@ void CL_Connect_f( void )

Q_strncpyz( cls.servername, server, sizeof( cls.servername ) );

if( !NET_StringToAdr( cls.servername, &clc.serverAddress, family ) )
if( !networkChainSystem->StringToAdr( cls.servername, &clc.serverAddress, family ) )
{
Com_Printf( "Bad server address\n" );
cls.state = CA_DISCONNECTED;
Expand Down Expand Up @@ -1709,14 +1708,14 @@ void CL_Rcon_f( void )

return;
}
NET_StringToAdr( rconAddress->string, &rcon_address, NA_UNSPEC );
networkChainSystem->StringToAdr( rconAddress->string, &rcon_address, NA_UNSPEC );
if( rcon_address.port == 0 )
{
rcon_address.port = BigShort( PORT_SERVER );
}
}

NET_SendPacket( NS_CLIENT, ::strlen( message ) + 1, message, rcon_address );
networkChainSystem->SendPacket( NS_CLIENT, ::strlen( message ) + 1, message, rcon_address );
}

/*
Expand Down Expand Up @@ -2372,7 +2371,7 @@ void CL_CheckForResend( void )
// EVEN BALANCE - T.RAY
strcpy( pkt, "getchallenge" );
pktlen = strlen( pkt );
NET_OutOfBandPrint( NS_CLIENT, clc.serverAddress, "%s", pkt );
networkChainSystem->OutOfBandPrint( NS_CLIENT, clc.serverAddress, "%s", pkt );
break;

case CA_CHALLENGING:
Expand All @@ -2399,7 +2398,7 @@ void CL_CheckForResend( void )
pktlen = i + 10;
memcpy( pkt, &data[0], pktlen );

NET_OutOfBandData( NS_CLIENT, clc.serverAddress, ( uchar8* ) pkt, pktlen );
networkChainSystem->OutOfBandData( NS_CLIENT, clc.serverAddress, ( uchar8* ) pkt, pktlen );
// the most current userinfo has been sent, so watch for any
// newer changes to userinfo variables
cvar_modifiedFlags &= ~CVAR_USERINFO;
Expand Down Expand Up @@ -2694,7 +2693,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t* msg )
}
}

Netchan_Setup( NS_CLIENT, &clc.netchan, from, cvarSystem->VariableValue( "net_qport" ) );
networkChainSystem->Setup( NS_CLIENT, &clc.netchan, from, cvarSystem->VariableValue( "net_qport" ) );
cls.state = CA_CONNECTED;
clc.lastPacketSentTime = -9999; // send first packet immediately
return;
Expand Down Expand Up @@ -2725,7 +2724,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t* msg )
// echo request from server
if( !Q_stricmp( c, "echo" ) )
{
NET_OutOfBandPrint( NS_CLIENT, from, "%s", cmdSystem->Argv( 1 ) );
networkChainSystem->OutOfBandPrint( NS_CLIENT, from, "%s", cmdSystem->Argv( 1 ) );
return;
}

Expand Down Expand Up @@ -3427,7 +3426,7 @@ void CL_CheckAutoUpdate( void )
srand( Com_Milliseconds() );

// Resolve update server
if( !NET_StringToAdr( cls.autoupdateServerNames[0], &cls.autoupdateServer, NA_IP ) )
if( !networkChainSystem->StringToAdr( cls.autoupdateServerNames[0], &cls.autoupdateServer, NA_IP ) )
{
Com_DPrintf( "Failed to resolve any Auto-update servers.\n" );

Expand All @@ -3448,7 +3447,7 @@ void CL_CheckAutoUpdate( void )
cls.autoupdateServer.ip[2], cls.autoupdateServer.ip[3],
BigShort( cls.autoupdateServer.port ) );

NET_OutOfBandPrint( NS_CLIENT, cls.autoupdateServer, "getUpdateInfo \"%s\" \"%s\"\n", Q3_VERSION, ARCH_STRING );
networkChainSystem->OutOfBandPrint( NS_CLIENT, cls.autoupdateServer, "getUpdateInfo \"%s\" \"%s\"\n", Q3_VERSION, ARCH_STRING );

#endif // !PRE_RELEASE_DEMO

Expand Down Expand Up @@ -3494,7 +3493,7 @@ bool CL_NextUpdateServer( void )
servername = cls.autoupdateServerNames[cls.autoupdatServerIndex];

Com_DPrintf( "Resolving AutoUpdate Server... " );
if( !NET_StringToAdr( servername, &cls.autoupdateServer, NA_IP ) )
if( !networkChainSystem->StringToAdr( servername, &cls.autoupdateServer, NA_IP ) )
{
Com_DPrintf( "Couldn't resolve address, trying next one..." );

Expand Down
6 changes: 3 additions & 3 deletions src/engine/client/cl_net_chan.cpp
Expand Up @@ -160,7 +160,7 @@ CL_Netchan_TransmitNextFragment
*/
void CL_Netchan_TransmitNextFragment( netchan_t* chan )
{
Netchan_TransmitNextFragment( chan );
networkChainSystem->TransmitNextFragment( chan );
}

/*
Expand All @@ -176,7 +176,7 @@ void CL_Netchan_Transmit( netchan_t* chan, msg_t* msg )
{
CL_Netchan_Encode( msg );
}
Netchan_Transmit( chan, msg->cursize, msg->data );
networkChainSystem->Transmit( chan, msg->cursize, msg->data );
}

extern sint oldsize;
Expand All @@ -191,7 +191,7 @@ bool CL_Netchan_Process( netchan_t* chan, msg_t* msg )
{
bool ret;

ret = Netchan_Process( chan, msg );
ret = networkChainSystem->Process( chan, msg );

if( !ret )
{
Expand Down
24 changes: 12 additions & 12 deletions src/engine/client/clientBrowser.cpp
Expand Up @@ -501,7 +501,7 @@ sint idClientBrowserSystemLocal::ServerStatus( valueType* serverAddress, valueTy
}

// get the address
if( !NET_StringToAdr( serverAddress, &to, NA_UNSPEC ) )
if( !networkChainSystem->StringToAdr( serverAddress, &to, NA_UNSPEC ) )
{
return false;
}
Expand Down Expand Up @@ -536,7 +536,7 @@ sint idClientBrowserSystemLocal::ServerStatus( valueType* serverAddress, valueTy
serverStatus->time = 0;
serverStatus->startTime = idsystem->Milliseconds();

NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" );
networkChainSystem->OutOfBandPrint( NS_CLIENT, to, "getstatus" );
return false;
}
}
Expand All @@ -550,7 +550,7 @@ sint idClientBrowserSystemLocal::ServerStatus( valueType* serverAddress, valueTy
serverStatus->startTime = idsystem->Milliseconds();
serverStatus->time = 0;

NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" );
networkChainSystem->OutOfBandPrint( NS_CLIENT, to, "getstatus" );
return false;
}

Expand Down Expand Up @@ -730,10 +730,10 @@ void idClientBrowserSystemLocal::LocalServers( void )
to.port = BigShort( ( short )( PORT_SERVER + j ) );

to.type = NA_BROADCAST;
NET_SendPacket( NS_CLIENT, strlen( message ), message, to );
networkChainSystem->SendPacket( NS_CLIENT, strlen( message ), message, to );

to.type = NA_MULTICAST6;
NET_SendPacket( NS_CLIENT, strlen( message ), message, to );
networkChainSystem->SendPacket( NS_CLIENT, strlen( message ), message, to );
}
}
}
Expand Down Expand Up @@ -794,7 +794,7 @@ void idClientBrowserSystemLocal::GlobalServers( void )

// reset the list, waiting for response
// -1 is used to distinguish a "no response"
i = NET_StringToAdr( masteraddress, &to, NA_UNSPEC );
i = networkChainSystem->StringToAdr( masteraddress, &to, NA_UNSPEC );

if( !i )
{
Expand Down Expand Up @@ -836,7 +836,7 @@ void idClientBrowserSystemLocal::GlobalServers( void )
Q_strcat( command, sizeof( command ), cmdSystem->Argv( i ) );
}

NET_OutOfBandPrint( NS_SERVER, to, "%s", command );
networkChainSystem->OutOfBandPrint( NS_SERVER, to, "%s", command );
}

/*
Expand Down Expand Up @@ -1047,7 +1047,7 @@ void idClientBrowserSystemLocal::Ping( void )

::memset( &to, 0, sizeof( netadr_t ) );

if( !NET_StringToAdr( server, &to, family ) )
if( !networkChainSystem->StringToAdr( server, &to, family ) )
{
return;
}
Expand All @@ -1060,7 +1060,7 @@ void idClientBrowserSystemLocal::Ping( void )

SetServerInfoByAddress( pingptr->adr, nullptr, 0 );

NET_OutOfBandPrint( NS_CLIENT, to, "getinfo xxx" );
networkChainSystem->OutOfBandPrint( NS_CLIENT, to, "getinfo xxx" );
}

/*
Expand Down Expand Up @@ -1149,7 +1149,7 @@ bool idClientBrowserSystemLocal::UpdateVisiblePings( sint source )
::memcpy( &cl_pinglist[j].adr, &server[i].adr, sizeof( netadr_t ) );
cl_pinglist[j].start = cls.realtime;
cl_pinglist[j].time = 0;
NET_OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" );
networkChainSystem->OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" );
slots++;
}
}
Expand Down Expand Up @@ -1255,13 +1255,13 @@ void idClientBrowserSystemLocal::ServerStatus( void )

toptr = &to;

if( !NET_StringToAdr( server, toptr, family ) )
if( !networkChainSystem->StringToAdr( server, toptr, family ) )
{
return;
}
}

NET_OutOfBandPrint( NS_CLIENT, *toptr, "getstatus" );
networkChainSystem->OutOfBandPrint( NS_CLIENT, *toptr, "getstatus" );

serverStatus = GetServerStatus( *toptr );
serverStatus->address = *toptr;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/client/clientLAN.cpp
Expand Up @@ -187,7 +187,7 @@ sint idClientLANSystemLocal::AddServer( sint source, pointer name, pointer addre

if( servers && *count < max )
{
NET_StringToAdr( address, &adr, NA_UNSPEC );
networkChainSystem->StringToAdr( address, &adr, NA_UNSPEC );

for( i = 0; i < *count; i++ )
{
Expand Down Expand Up @@ -246,7 +246,7 @@ void idClientLANSystemLocal::RemoveServer( sint source, pointer addr )
{
netadr_t comp;

NET_StringToAdr( addr, &comp, NA_UNSPEC );
networkChainSystem->StringToAdr( addr, &comp, NA_UNSPEC );

for( i = 0; i < *count; i++ )
{
Expand Down

0 comments on commit e3d3605

Please sign in to comment.