From 18f5a12d64e39cdc8b969b582ca7ff13f051f9d3 Mon Sep 17 00:00:00 2001 From: Glenn Fiedler Date: Sun, 24 Dec 2023 10:20:55 -0500 Subject: [PATCH] simplify! --- client_server.cpp | 126 ---------------------------------------------- premake5.lua | 8 --- secure_server.cpp | 108 --------------------------------------- 3 files changed, 242 deletions(-) delete mode 100644 client_server.cpp delete mode 100644 secure_server.cpp diff --git a/client_server.cpp b/client_server.cpp deleted file mode 100644 index 2374e063..00000000 --- a/client_server.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - Yojimbo Client/Server Example. - - Copyright © 2016 - 2019, The Network Protocol Company, Inc. - - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "yojimbo.h" -#include -#include -#include -#include -#include -#include -#include "shared.h" - -using namespace yojimbo; - -static volatile int quit = 0; - -void interrupt_handler( int /*dummy*/ ) -{ - quit = 1; -} - -int ClientServerMain() -{ - double time = 100.0; - - ClientServerConfig config; - - uint8_t privateKey[KeyBytes]; - memset( privateKey, 0, KeyBytes ); - - printf( "starting server on port %d\n", ServerPort ); - - Server server( GetDefaultAllocator(), privateKey, Address( "127.0.0.1", ServerPort ), config, adapter, time ); - - server.Start( MaxClients ); - - if ( !server.IsRunning() ) - return 1; - - printf( "started server\n" ); - - uint64_t clientId = 0; - random_bytes( (uint8_t*) &clientId, 8 ); - printf( "client id is %.16" PRIx64 "\n", clientId ); - - Client client( GetDefaultAllocator(), Address("0.0.0.0"), config, adapter, time ); - - Address serverAddress( "127.0.0.1", ServerPort ); - - client.InsecureConnect( privateKey, clientId, serverAddress ); - - const double deltaTime = 0.1; - - signal( SIGINT, interrupt_handler ); - - while ( !quit ) - { - server.SendPackets(); - client.SendPackets(); - - server.ReceivePackets(); - client.ReceivePackets(); - - time += deltaTime; - - client.AdvanceTime( time ); - - if ( client.IsDisconnected() ) - break; - - time += deltaTime; - - server.AdvanceTime( time ); - - yojimbo_sleep( deltaTime ); - } - - client.Disconnect(); - server.Stop(); - - return 0; -} - -int main() -{ - printf( "\n[client/server]\n" ); - - if ( !InitializeYojimbo() ) - { - printf( "error: failed to initialize Yojimbo!\n" ); - return 1; - } - - yojimbo_log_level( YOJIMBO_LOG_LEVEL_INFO ); - - srand( (unsigned int) time( NULL ) ); - - int result = ClientServerMain(); - - ShutdownYojimbo(); - - printf( "\n" ); - - return result; -} diff --git a/premake5.lua b/premake5.lua index 34147048..4d564f26 100644 --- a/premake5.lua +++ b/premake5.lua @@ -64,14 +64,6 @@ project "server" files { "server.cpp", "shared.h" } links { "yojimbo", "sodium", "tlsf", "netcode", "reliable" } -project "secure_server" - files { "secure_server.cpp", "shared.h" } - links { "yojimbo", "sodium", "tlsf", "netcode", "reliable" } - -project "client_server" - files { "client_server.cpp", "shared.h" } - links { "yojimbo", "sodium", "tlsf", "netcode", "reliable" } - project "loopback" files { "loopback.cpp", "shared.h" } links { "yojimbo", "sodium", "tlsf", "netcode", "reliable" } diff --git a/secure_server.cpp b/secure_server.cpp deleted file mode 100644 index a9cd1c7a..00000000 --- a/secure_server.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - Yojimbo Secure Server Example. - - Copyright © 2016 - 2019, The Network Protocol Company, Inc. - - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer - in the documentation and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "yojimbo.h" -#include -#include - -#include "shared.h" - -using namespace yojimbo; - -static volatile int quit = 0; - -void interrupt_handler( int /*dummy*/ ) -{ - quit = 1; -} - -int ServerMain() -{ - printf( "started server on port %d (secure)\n", ServerPort ); - - double time = 100.0; - - ClientServerConfig config; - config.protocolId = ProtocolId; - - uint8_t privateKey[KeyBytes] = { 0x60, 0x6a, 0xbe, 0x6e, 0xc9, 0x19, 0x10, 0xea, - 0x9a, 0x65, 0x62, 0xf6, 0x6f, 0x2b, 0x30, 0xe4, - 0x43, 0x71, 0xd6, 0x2c, 0xd1, 0x99, 0x27, 0x26, - 0x6b, 0x3c, 0x60, 0xf4, 0xb7, 0x15, 0xab, 0xa1 }; - - Server server( GetDefaultAllocator(), privateKey, Address( "127.0.0.1", ServerPort ), config, adapter, time ); - - server.Start( MaxClients ); - - const double deltaTime = 0.1; - - char addressString[256]; - server.GetAddress().ToString( addressString, sizeof( addressString ) ); - printf( "server address is %s\n", addressString ); - - signal( SIGINT, interrupt_handler ); - - while ( !quit ) - { - server.SendPackets(); - - server.ReceivePackets(); - - time += deltaTime; - - server.AdvanceTime( time ); - - if ( !server.IsRunning() ) - break; - - yojimbo_sleep( deltaTime ); - } - - server.Stop(); - - return 0; -} - -int main() -{ - printf( "\n" ); - - if ( !InitializeYojimbo() ) - { - printf( "error: failed to initialize Yojimbo!\n" ); - return 1; - } - - yojimbo_log_level( YOJIMBO_LOG_LEVEL_INFO ); - - srand( (unsigned int) time( NULL ) ); - - int result = ServerMain(); - - ShutdownYojimbo(); - - printf( "\n" ); - - return result; -}