Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/gameserver.cc38
-rw-r--r--src/core/gameserver.h3
2 files changed, 41 insertions, 0 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index dadff8f..211bb96 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -4,6 +4,8 @@
the terms of the GNU General Public License version 2
*/
+#include <iomanip>
+
#include "sys/sys.h"
#include "core/cvar.h"
#include "core/func.h"
@@ -18,6 +20,11 @@ void func_say(Player *player, std::string const &args)
server()->say(player, args);
}
+void func_who(Player *player, std::string const &args)
+{
+ server()->list_players(player);
+}
+
GameServer *GameServer::server_instance = 0;
GameServer::GameServer() : GameInterface()
@@ -58,6 +65,7 @@ GameServer::GameServer() : GameInterface()
}
Func::add("say", (GameFuncPtr) func_say);
+ Func::add("who", (GameFuncPtr) func_who);
if (!Cvar::sv_dedicated->value()) {
player_connect(localplayer());
@@ -88,6 +96,8 @@ GameServer::~GameServer()
}
Func::remove("say");
+ Func::remove("who");
+
server_instance = 0;
}
@@ -96,6 +106,34 @@ void GameServer::abort()
server_running = false;
}
+void GameServer::list_players(Player *player)
+{
+ using namespace std;
+
+ stringstream msgstr;
+ int count = 0;
+
+ if (!Cvar::sv_dedicated->value()) {
+ msgstr << setw(3) << localplayer()->id() << setw(16) << localplayer()->name();
+ send(player, msgstr.str());
+ count++;
+ }
+
+ if (server_network) {
+ std::list<NetClient *>:: iterator it;
+ for (it = server_network->clients.begin(); it != server_network->clients.end(); it++) {
+ msgstr.str("");
+ msgstr << setw(3) << (*it)->player()->id() << setw(16) << (*it)->player()->name();
+ send(player, msgstr.str());
+ count++;
+ }
+ }
+
+ msgstr.str("");
+ msgstr << count << " connected players";
+ send(player, msgstr.str());
+}
+
void GameServer::say(Player *player, std::string const &message)
{
if (!message.size())
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index 2e492c8..6003629 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -42,6 +42,9 @@ public:
/// run a game server time frame
void frame(float seconds);
+
+ /// a player requests a list of who is connected
+ void list_players(Player *player);
/// a player sends a chat message on the public channel
void say(Player *player, std::string const &args);