From d198b7b8d9ff713d891f35ab173d1f428f610e7d Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 16 Feb 2008 14:31:02 +0000 Subject: code cleanup --- src/core/gameinterface.cc | 55 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'src/core/gameinterface.cc') diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index a4a402d..d07f804 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -9,22 +9,29 @@ class GameInterface; +#include "core/application.h" #include "core/gameinterface.h" #include "core/player.h" +#include "sys/sys.h" namespace core { +GameInterface *game() +{ + return GameInterface::instance(); +} + GameInterface *GameInterface::gameinterface_instance = 0; -GameInterface::GameInterface(const char *game_name) +GameInterface::GameInterface(const char *gamename) { gameinterface_instance = this; connected = false; - if (game_name) - name.assign(game_name); + if (gamename) + game_name.assign(gamename); else - name.clear(); + game_name.clear(); } GameInterface::~GameInterface() @@ -37,4 +44,44 @@ GameInterface *GameInterface::instance() return gameinterface_instance; } +std::string const &GameInterface::name() +{ + return game_name; +} + +void message_broadcast(std::string const & message, int ignoreplayer) +{ + // send to console + con_print << message << std::endl; + + // broadcast to remote clients + if (application()->netserver) { + std::string netmessage("msg info "); + netmessage.append(message); + netmessage += '\n'; + + application()->netserver->broadcast(netmessage, ignoreplayer); + } +} + +void message_send(Player const &player, const char *protohdr, std::string message) +{ + // send to console + if (&player == &localplayer) { + con_print << message << std::endl; + } + + // send to remote clients + if (application()->netserver) { + NetClient *client = application()->netserver->find_client(player); + if (client) { + std::string netmessage("msg info "); + netmessage.append(message); + netmessage += '\n'; + + application()->netserver->send(client, message); + } + } +} + } // namespace core -- cgit v1.2.3