From 834c9c0c4efef1cb3860718e374cc7cc23b61985 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 24 May 2008 12:04:59 +0000 Subject: Help --- src/core/application.cc | 25 +++++++++++++---------- src/core/commandbuffer.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++- src/core/commandbuffer.h | 3 +++ src/core/cvar.cc | 1 + src/core/cvar.h | 1 + src/core/gameserver.cc | 30 +++++++++++++-------------- src/core/gameserver.h | 2 ++ src/core/netserver.cc | 2 +- 8 files changed, 88 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/core/application.cc b/src/core/application.cc index ac836df..09b3f61 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -16,6 +16,7 @@ #include "math/mathlib.h" #include "filesystem/filesystem.h" #include "core/application.h" +#include "core/core.h" #include "core/cvar.h" #include "core/entity.h" #include "core/func.h" @@ -26,14 +27,15 @@ namespace core { // --------------- engine functions ------------------------------ -void func_print(std::string const &args) -{ - con_print << args << "\n"; -} - void func_help(std::string const &args) { - con_print << "This is the help function\n"; + std::istringstream argstream(args); + std::string topic; + if (!(argstream >> topic)) + topic.assign("help"); + + topic.append(".txt"); + CommandBuffer::print_file("help/" + topic); } void func_quit(std::string const &args) @@ -140,6 +142,10 @@ void Application::init(int count, char **arguments) Cvar::sv_framerate = Cvar::get("sv_framerate", "25"); Cvar::sv_framerate->set_info("[int] server framerate in frames/sec"); + // server settings + Cvar::sv_name = Cvar::get("sv_name", "osirion server", Cvar::Archive); + Cvar::sv_name->set_info("[string] server name"); + // network settings Cvar::net_host = Cvar::get("net_host", "0.0.0.0", Cvar::Archive); Cvar::net_host->set_info("[ip] IP address the network server binds to"); @@ -150,10 +156,10 @@ void Application::init(int count, char **arguments) Cvar::net_maxclients = Cvar::get("net_maxclients", "16", Cvar::Archive); Cvar::net_maxclients->set_info("[int] maximum number of network clients"); - Cvar::net_timeout = Cvar::get("net_timeout", "20", Cvar::Archive); + Cvar::net_timeout = Cvar::get("net_timeout", "20"); Cvar::net_timeout->set_info("[int] network timeout in seconds"); - Cvar::net_framerate = Cvar::get("net_framerate", "25", Cvar::Archive); + Cvar::net_framerate = Cvar::get("net_framerate", "25"); Cvar::net_framerate->set_info("[int] network framerate in frames/sec"); #ifdef _WIN32 @@ -175,9 +181,6 @@ void Application::init(int count, char **arguments) // register our engine functions Func *func = 0; - func = Func::add("print", func_print); - func->set_info("[str] print a message on the console"); - func = Func::add("help", func_help); func->set_info("dummy help function"); diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index d1c9451..40517e1 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -20,6 +20,21 @@ namespace core { +void func_print(std::string const &args) +{ + con_print << args << "\n"; +} + +void func_print_file(std::string const &args) +{ + std::istringstream argstream(args); + std::string filename; + if (!(argstream >> filename)) + return; + + CommandBuffer::print_file(filename); +} + void func_list_func(std::string const &args) { Func::list(); @@ -75,7 +90,6 @@ std::stringstream CommandBuffer::cmdbuf(std::stringstream::in | std::stringstrea void CommandBuffer::init() { //con_debug << "Initializing command buffer...\n"; - Func *func = 0; func = Func::add("list_ent", (FuncPtr)func_list_ent); func->set_info("list entities"); @@ -89,6 +103,12 @@ void CommandBuffer::init() func = Func::add("set", (FuncPtr)func_set); func->set_info("[variable] [str] set variable value"); + func = Func::add("print", func_print); + func->set_info("[str] print a message on the console"); + + func = Func::add("print_file", func_print_file); + func->set_info("[filename] print messages from file"); + func = Func::add("exec", (FuncPtr)func_exec); func->set_info("[filename] execute commands from file"); } @@ -101,6 +121,9 @@ void CommandBuffer::shutdown() Func::remove("list_var"); Func::remove("list_func"); Func::remove("list_ent"); + Func::remove("print"); + Func::remove("print_file"); + Func::remove("exec"); } void CommandBuffer::exec(std::string const &cmdline) @@ -263,5 +286,32 @@ void CommandBuffer::exec_file(std::string const & filename) ifs.close(); } +void CommandBuffer::print_file(std::string const & filename) +{ + filesystem::File *f = filesystem::open(filename.c_str()); + if (!f) { + con_warn << "Could not open " << filename << std::endl; + return; + } + + std::string fn = f->path(); + fn.append(f->name()); + filesystem::close(f); + + std::ifstream ifs; + ifs.open(fn.c_str()); + if (!ifs.is_open()) { + con_warn << "Could not stream " << fn << "!\n"; + return; + } + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + con_print << line << "\n"; + } + + ifs.close(); +} + } diff --git a/src/core/commandbuffer.h b/src/core/commandbuffer.h index 7b26211..9cd919b 100644 --- a/src/core/commandbuffer.h +++ b/src/core/commandbuffer.h @@ -31,6 +31,9 @@ public: /// execute commands from a file static void exec_file(std::string const & filename); + /// print messages from a file + static void print_file(std::string const & filename); + /// global buffer to hold the command stream static std::stringstream cmd; diff --git a/src/core/cvar.cc b/src/core/cvar.cc index f8ea746..83ec5c4 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -21,6 +21,7 @@ Cvar *Cvar::con_ansi = 0; Cvar *Cvar::sv_dedicated = 0; Cvar *Cvar::sv_private = 0; Cvar *Cvar::sv_framerate = 0; +Cvar *Cvar::sv_name = 0; Cvar *Cvar::net_host = 0; Cvar *Cvar::net_port = 0; diff --git a/src/core/cvar.h b/src/core/cvar.h index 69fcae1..fceb79b 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -112,6 +112,7 @@ public: static Cvar *sv_dedicated; // dedicated server static Cvar *sv_private; // client with private server static Cvar *sv_framerate; // server framerate + static Cvar *sv_name; // server name static Cvar *con_ansi; // console ANSI colors diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 7e03c61..c18b1fa 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -104,6 +104,8 @@ GameServer::~GameServer() Func::remove("who"); server_instance = 0; + + players.clear(); } void GameServer::abort() @@ -114,26 +116,16 @@ void GameServer::abort() void GameServer::list_players(Player *player) { using namespace std; - stringstream msgstr; int count = 0; - if (!Cvar::sv_dedicated->value()) { - msgstr << setw(3) << localplayer()->id() << aux::spaces(localplayer()->name(), 24); + for (std::list:: iterator it = players.begin(); it != players.end(); it++) { + msgstr.str(""); + msgstr << setw(3) << (*it)->id() << aux::spaces((*it)->name(), 24); send(player, msgstr.str()); count++; } - if (server_network) { - std::list:: iterator it; - for (it = server_network->clients.begin(); it != server_network->clients.end(); it++) { - msgstr.str(""); - msgstr << setw(3) << (*it)->player()->id() << aux::spaces((*it)->player()->name(), 24); - send(player, msgstr.str()); - count++; - } - } - msgstr.str(""); msgstr << count << " connected " << aux::plural("player", count); send(player, msgstr.str()); @@ -270,7 +262,8 @@ void GameServer::player_connect(Player *player) // notify the game module server_module->player_connect(player); - // TODO manage player list + // manage player list + players.push_back(player); } void GameServer::player_disconnect(Player *player) @@ -283,7 +276,14 @@ void GameServer::player_disconnect(Player *player) // notify the game module server_module->player_disconnect(player); - // TODO manage player list + // manage player list + std::list:: iterator it = players.begin(); + while (((*it)->id() != player->id()) && (it != players.end())) { + it++; + } + if (it != players.end()) { + players.erase(it); + } } void GameServer::frame(float seconds) diff --git a/src/core/gameserver.h b/src/core/gameserver.h index c35ef74..d7d6eb8 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -64,6 +64,8 @@ public: /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); + std::list players; + /*----- static ---------------------------------------------------- */ /// return the current game server diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 5334c6f..b604f47 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -278,7 +278,7 @@ void NetServer::client_initialize(NetClient *client) { // send welcome message std::ostringstream netmsg; netmsg.str(""); - netmsg << "msg info Receiving data from remote server...\n"; + netmsg << "msg info ^B" << Cvar::sv_name->str() << "\n"; client->send(netmsg.str()); client->transmit(fd()); -- cgit v1.2.3