Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gameserver.cc')
-rw-r--r--src/core/gameserver.cc132
1 files changed, 130 insertions, 2 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 2027098..4172d4f 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -17,6 +17,15 @@
namespace core
{
+Player *console_find_player(std::string const & target)
+{
+ Player *targetplayer = server()->find_player(target);
+ if (!targetplayer) {
+ con_print << "^BPlayer " + target + "^B not found.";
+ }
+ return targetplayer;
+}
+
void func_who(std::string const &args)
{
server()->list_players();
@@ -27,6 +36,70 @@ void func_time(std::string const &args)
server()->showtime();
}
+void func_mute(std::string const &args)
+{
+ Player *targetplayer = 0;
+ if (!(targetplayer = console_find_player(args)))
+ return;
+
+ if (targetplayer->mute()) {
+ con_print << "^BPlayer " + targetplayer->name() + "^B has already been muted.";
+ return;
+ }
+
+ targetplayer->player_mute = true;
+ server()->broadcast("^B" + targetplayer->name() + "^B has been muted.", targetplayer);
+ server()->send(targetplayer, "^BYou have been muted.");
+}
+
+void func_unmute(std::string const &args)
+{
+ Player *targetplayer = 0;
+ if (!(targetplayer = console_find_player(args)))
+ return;
+
+ if (!targetplayer->mute()) {
+ con_print << "^BPlayer " + targetplayer->name() + "^B has not been muted.";
+ return;
+ }
+
+ targetplayer->player_mute = false;
+ server()->broadcast("^B" +targetplayer->name() + "^B has been unmuted.", targetplayer);
+ server()->send(targetplayer, "^BYou have been unmuted.");
+}
+
+void func_kick(std::string const &args)
+{
+ std::stringstream str(args);
+ std::string name;
+
+ if (str >> name) {
+ Player *targetplayer = 0;
+ if (!(targetplayer = console_find_player(name)))
+ return;
+ std::string reason;
+ if (args.size() > name.size()+1)
+ reason.assign(args.substr(name.size()+1));
+ else
+ reason.assign("forcefully removed.");
+
+ server()->kick(targetplayer, reason);
+ }
+}
+
+void func_grant_rcon(std::string const &args)
+{
+ Player *targetplayer = 0;
+ if (!(targetplayer = console_find_player(args)))
+ return;}
+
+void func_revoke_rcon(std::string const &args)
+{
+ Player *targetplayer = 0;
+ if (!(targetplayer = console_find_player(args)))
+ return;
+}
+
GameServer *GameServer::server_instance = 0;
GameServer::GameServer() : GameInterface()
@@ -69,8 +142,30 @@ GameServer::GameServer() : GameInterface()
server_network = 0;
}
- Func::add("time", func_time, Func::Shared);
- Func::add("who", func_who, Func::Shared);
+ Func *func = 0;
+
+ /* -- admin functions -- */
+ func = Func::add("mute", func_mute);
+ func->set_info("[player] mute a player");
+
+ func = Func::add("unmute", func_unmute);
+ func->set_info("[player] unmute a player");
+
+ func = Func::add("kick", func_kick);
+ func->set_info("[player] [reason] kick a player from the server");
+/*
+ func = Func::add("grant_rcon", func_grant_rcon);
+ func->set_info("[player] grant a player rcon rights");
+
+ func = Func::add("revoke_rcon", func_grant_rcon);
+ func->set_info("[player] revoke a player's rcon rights");
+*/
+ /* -- player functions --*/
+ func = Func::add("time", func_time, Func::Shared);
+ func->set_info("get the server uptime and current localtime");
+
+ func = Func::add("who", func_who, Func::Shared);
+ func->set_info("get a list of connected players");
if (!Cvar::sv_dedicated->value()) {
player_connect(localplayer());
@@ -100,6 +195,12 @@ GameServer::~GameServer()
delete server_module;
}
+ Func::remove("mute");
+ Func::remove("unmute");
+
+/* Func::remove("grant_rcon");
+ Func::remove("revoke_rcon");
+*/
Func::remove("time");
Func::remove("who");
@@ -174,6 +275,11 @@ void GameServer::say(Player *player, std::string const &message)
if (!message.size())
return;
+ if (player->mute()) {
+ send(player, "^BYou have been muted.");
+ return;
+ }
+
std::string notification("^B");
notification.append(player->name());
notification.append("^F:^B ");
@@ -192,6 +298,28 @@ void GameServer::say(Player *player, std::string const &message)
}
}
+void GameServer::kick(Player *player, std::string const &reason)
+{
+ // FIXME kicked by
+ if (!server_network) {
+ con_print << "Not running a networked server." << std::endl;
+ return;
+ }
+
+ NetClient *client = server_network->find_client(player);
+ if (client) {
+ broadcast("^B" + player->name() + "^B has been kicked: " + reason, player);
+ send(player, "^WYou have been kicked: " + reason);
+
+ client->send("disconnect\n");
+ client->transmit(server_network->fd());
+
+ client->abort();
+ } else {
+ con_print << "Network client not found." << std::endl;
+ }
+}
+
void GameServer::broadcast(std::string const & message, Player *ignore_player)
{
// send to application