From 715d0c3952a3a1d59b64074e472d0a9a3b414351 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 14 Feb 2008 18:04:25 +0000 Subject: dedicated server accepts incoming connections --- src/core/application.cc | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/core/application.cc') diff --git a/src/core/application.cc b/src/core/application.cc index 9fea8ee..2d29fad 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -19,12 +19,16 @@ #include "core/entity.h" #include "core/func.h" #include "core/cvar.h" +#include "core/netserver.h" namespace core { Cvar sv_dedicated; +Cvar net_host; +Cvar net_port; + // --------------- engine functions ------------------------------ void func_print(std::stringstream &args) { @@ -107,6 +111,8 @@ Application *Application::application_instance = 0; Application::Application() { + netserver = 0; + if (application_instance) { std::cerr << "multiple core::Application instances!" << std::endl; sys::quit(2); @@ -137,13 +143,16 @@ void Application::init() // initialize core subsystems filesystem::init(); - // dedicated or not + // dedicated or not, client should have set this to 0 core::sv_dedicated = core::cvar::get("sv_dedicated", "1", core::cvar::ReadOnly); if (sv_dedicated->value()) localplayer.name = "Console"; else - localplayer.name = "Client"; + localplayer.name = "Player"; + // network settings + core::net_host = core::cvar::get("net_host", "0.0.0.0"); + core::net_port = core::cvar::get("net_port", "8042"); // register our functions func::add("print", func_print); @@ -168,9 +177,12 @@ void Application::shutdown() if (game() && game()->connected) disconnect(); - - //if (game()) unload(); - + + if (netserver) { + delete netserver; + netserver = 0; + } + filesystem::shutdown(); } @@ -197,6 +209,10 @@ void Application::connect() con_print << "Connected." << std::endl; } else { con_warn << "Connect failed." << std::endl; + return; + } + if (core::sv_dedicated->value() && !netserver) { + netserver = new NetServer(net_host->text(), (unsigned int)net_port->value()); } } @@ -211,12 +227,13 @@ void Application::disconnect() con_warn << "Not connected." << std::endl; return; } - + game()->shutdown(); game()->connected = false; game()->current_time = 0; + // remove all entities entity::clear(); // TODO remove all game functions @@ -230,12 +247,18 @@ void Application::frame(float seconds) { current_time += seconds; + if (netserver) { + // TODO limit netserver frames in local mode + netserver->frame(seconds); + } + if (game() && game()->connected) { entity::frame(seconds); - + game()->current_time += seconds; game()->frame(seconds); } + // execute commands in the buffer commandbuffer::execute(); -- cgit v1.2.3