Moved network chain into C++

Moved network chain into C++

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 83e9541..c6e23e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
 )
 
@@ -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
@@ -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
@@ -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
diff --git a/src/engine/API/NetworkChain_api.h b/src/engine/API/NetworkChain_api.h
new file mode 100644
index 0000000..402b14b
--- /dev/null
+++ b/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__
diff --git a/src/engine/client/cl_main.cpp b/src/engine/client/cl_main.cpp
index b245ffc..a4b4749 100644
--- a/src/engine/client/cl_main.cpp
+++ b/src/engine/client/cl_main.cpp
@@ -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();
@@ -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" );
@@ -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 );
 }
 
 /*
@@ -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;
@@ -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 );
 }
 
 /*
@@ -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:
@@ -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;
@@ -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;

[... diff too long, it was truncated ...]

GitHub
sha: e3d3605e