Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-07-11 19:33:27 +0000
committerStijn Buys <ingar@osirion.org>2011-07-11 19:33:27 +0000
commit83c9d657773fa4f829b533791697ed07e0d9d962 (patch)
tree0c53d6a6d71c14894ac51124933ae31b66164217 /src/core
parent99bd770a6030805ecd2cb22671e8f29d32fd59db (diff)
Initial support for saving player data in multiplayer games,
have ships remember their docks and spawns.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gameconnection.cc3
-rw-r--r--src/core/gameserver.cc23
-rw-r--r--src/core/gameserver.h10
-rw-r--r--src/core/module.cc8
-rw-r--r--src/core/module.h6
5 files changed, 42 insertions, 8 deletions
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index ddf4610..70d19ef 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -64,7 +64,8 @@ GameConnection::GameConnection(std::string const &connectionstr)
if (!ofs.is_open()) {
con_warn << "Could not write " << filename << std::endl;
} else {
- ofs << "; keys.ini - osirion client identification" << std::endl;
+ ofs << "; keys.ini" << std::endl;
+ ofs << "; Project::OSiRiON client identification" << std::endl;
ofs << "; DO NOT EDIT OR DELETE THIS FILE" << std::endl;
ofs << "; If you do, you will not be able to use existing characters in multiplayer games" << std::endl;
ofs << std::endl;
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index a1102bd..96dd51e 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -152,11 +152,17 @@ GameServer::GameServer() : GameInterface()
server_previoustime = 0;
server_maxplayerid = 1;
+ if (Cvar::sv_dedicated->value() || Cvar::sv_private->value()) {
+ server_mode = MultiPlayer;
+ } else {
+ server_mode = SinglePlayer;
+ }
+
// create the default infotype for entities
Entity::set_infotype(new InfoType("entity"));
Physics::init();
-
+
server_module = Loader::init();
if (!server_module) {
@@ -173,9 +179,12 @@ GameServer::GameServer() : GameInterface()
set_interactive(server_module->interactive());
+
if (interactive()) {
//FIXME interferes with command line because of cmd.exec
load_config();
+ } else {
+ server_mode = SinglePlayer;
}
// set the name of the game
@@ -184,7 +193,7 @@ GameServer::GameServer() : GameInterface()
con_print << " module '^B" << server_module->name() << "^N'\n";
- if (interactive() && (Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
+ if (mode() == MultiPlayer) {
server_network = new NetServer(Cvar::net_host->str(), (unsigned int) Cvar::net_port->value());
if (!server_network->valid()) {
delete server_network;
@@ -194,13 +203,14 @@ GameServer::GameServer() : GameInterface()
return;
}
} else {
- con_print << " network server disabled.\n";
server_network = 0;
}
Func *func = 0;
/* -- admin functions -- */
+ // FIXME these have to become shared functions and check the player's admin level
+
func = Func::add("mute", func_mute);
func->set_info("[player] mute a player");
@@ -527,6 +537,10 @@ void GameServer::player_connect(Player *player)
void GameServer::player_disconnect(Player *player)
{
+ // notify the game module
+ server_module->player_disconnect(player);
+
+ // print a message
std::string message("^B");
message.append(player->name());
message.append("^B disconnects.");
@@ -535,9 +549,6 @@ void GameServer::player_disconnect(Player *player)
// clear all player assets
player->clear_assets();
- // notify the game module
- server_module->player_disconnect(player);
-
// manage player list
std::list<Player *>:: iterator it = game_players.begin();
while ((it != game_players.end()) && ((*it)->id() != player->id())) {
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index 56d0361..4f25a9b 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -23,13 +23,15 @@ namespace core
class GameServer : public GameInterface
{
public:
+ enum Mode {SinglePlayer = 1, MultiPlayer = 2};
+
GameServer();
virtual ~GameServer();
/*----- inspectors ------------------------------------------------ */
/// current module
- inline const Module *module() const {
+ inline Module *module() {
return server_module;
}
@@ -88,6 +90,10 @@ public:
/// request inventory for entity with id
virtual Inventory *request_inventory(Entity *entity);
+
+ inline Mode mode() const {
+ return server_mode;
+ }
/*----- static ---------------------------------------------------- */
@@ -108,6 +114,8 @@ private:
unsigned long server_previoustime;
sys::Timer server_timer;
+
+ Mode server_mode;
};
inline GameServer *server()
diff --git a/src/core/module.cc b/src/core/module.cc
index 6271331..18c318e 100644
--- a/src/core/module.cc
+++ b/src/core/module.cc
@@ -44,4 +44,12 @@ void Module::abort()
module_running = false;
}
+void Module::player_load(Player *player)
+{
+}
+
+void Module::player_save(Player *player)
+{
+}
+
}
diff --git a/src/core/module.h b/src/core/module.h
index ac6b380..51b1824 100644
--- a/src/core/module.h
+++ b/src/core/module.h
@@ -56,6 +56,12 @@ public:
/// is called when a player disconnects
virtual void player_disconnect(Player *player) = 0;
+
+ /// is called when player data needs to be saved
+ virtual void player_save(Player *player);
+
+ /// is called when player data needs to be loaded
+ virtual void player_load(Player *player);
/// set the module label
void set_label(const std::string &label);