Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-14 18:04:25 +0000
committerStijn Buys <ingar@osirion.org>2008-02-14 18:04:25 +0000
commit715d0c3952a3a1d59b64074e472d0a9a3b414351 (patch)
treea5d0ddd0613caaf4f9fe01f9a3bd34e823651ad5 /src/core/application.cc
parent83e8023c5e46635753a609329cf9805a3520001e (diff)
dedicated server accepts incoming connections
Diffstat (limited to 'src/core/application.cc')
-rw-r--r--src/core/application.cc37
1 files changed, 30 insertions, 7 deletions
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();