diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gameserver.cc | 38 | ||||
-rw-r--r-- | src/core/gameserver.h | 6 | ||||
-rw-r--r-- | src/core/netconnection.cc | 7 |
3 files changed, 48 insertions, 3 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 54d667b..85c00ab 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -151,7 +151,7 @@ void GameServer::say(Player *player, std::string const &message) // send to application application()->notify_message(notification); - application()->notify_sound("ui/chat.wav"); + application()->notify_sound("com/chat"); // broadcast to remote clients if (server_network) { @@ -165,7 +165,8 @@ void GameServer::say(Player *player, std::string const &message) void GameServer::broadcast(std::string const & message, Player *ignore_player) { // send to application - application()->notify_message(message); + if (ignore_player != game()->localplayer()) + application()->notify_message(message); // broadcast to remote clients if (server_network) { @@ -176,6 +177,21 @@ void GameServer::broadcast(std::string const & message, Player *ignore_player) } } +void GameServer::broadcast_sound(std::string const & sound, Player *ignore_player) +{ + // send to application + if (ignore_player != game()->localplayer()) + application()->notify_sound(sound.c_str()); + + // broadcast to remote clients + if (server_network) { + std::string netmessage("msg snd "); + netmessage.append(sound); + netmessage += '\n'; + server_network->broadcast(netmessage, ignore_player); + } +} + void GameServer::send(Player *player, std::string message) { // send to application @@ -195,6 +211,24 @@ void GameServer::send(Player *player, std::string message) } } +void GameServer::send_sound(Player *player, std::string sound) +{ + if (player->id() == localplayer()->id()) { + application()->notify_sound(sound.c_str()); + } + + // send to remote clients + if (server_network) { + NetClient *client = server_network->find_client(player); + if (client) { + std::string netmessage("msg snd "); + netmessage.append(sound); + netmessage += '\n'; + server_network->send(client, netmessage); + } + } +} + void GameServer::exec(Player *player, std::string const & cmdline) { std::string command; diff --git a/src/core/gameserver.h b/src/core/gameserver.h index bcd9cc3..c35ef74 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -52,9 +52,15 @@ public: /// broadcast a message to all players void broadcast(std::string const & message, Player *ignore_player = 0); + /// broadcast a sound to all players + void broadcast_sound(std::string const & sound, Player *ignore_player = 0); + /// send a message to a single player void send(Player *player, std::string message); + /// send a sound to a single player + void send_sound(Player *player, std::string sound); + /// a player sends a command to the game server void exec(Player *player, std::string const &cmdline); diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 8da8b1b..aa3db1a 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -265,6 +265,7 @@ void NetConnection::transmit() * disconnect * msg info <text> * msg public <name> <text> + * msg snd <soundname> * die * ent * frame @@ -289,9 +290,13 @@ void NetConnection::parse_incoming_message(const std::string & message) // FIXME - separate sender nickname if (message.size() > 11) { application()->notify_message(message.substr(11)); - application()->notify_sound("ui/chat.wav"); + application()->notify_sound("com/chat.wav"); } + } else if (level == "snd") { + if (message.size() > 8) { + application()->notify_sound(message.substr(8).c_str()); + } } } } else if (command == "connect") { |