From 493e4317e19725e2de2d51753e5c1906bf9c64ba Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Dec 2014 23:27:31 +0000 Subject: Implemented messageboxes and the ability for the game module to send them to remote clients, send a messagebox if the player's ship is destroyed, this fixes having to press the respawn button twice. added messageboxes on network connection failures. --- src/core/netserver.cc | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) (limited to 'src/core/netserver.cc') diff --git a/src/core/netserver.cc b/src/core/netserver.cc index cbb2dc7..1b49aee 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -487,20 +487,23 @@ void NetServer::frame(unsigned long timestamp) * The following messages can be send to a client * * frame - * ent + * ent * die * inf * inv * ping - * sup + * rep + * sup * * msg * supported message channels are "info" "public" "rcon" and "snd" * "snd" is a special channel to transmit sound events + * box + * send a messagebox * zone */ -// send a message on a specified channel to a single client +// send a text message on a specified channel to a single client void NetServer::send_message(NetClient *client, const Message::Channel channel, const std::string & message) { if (!message.size()) @@ -538,15 +541,44 @@ void NetServer::send_message(NetClient *client, const Message::Channel channel, break; } + std::string str_message(message); + aux::strip_quotes(str_message); + std::string msg("msg "); msg.append(msg_channel); msg += ' '; - msg.append(message); + msg.append(str_message); msg += '\n'; client->send_raw(msg); } +// send a messagebox to a single client +void NetServer::send_messagebox(NetClient *client, const std::string & text, const std::string &label1, const std::string command1, const std::string &label2, const std::string command2) +{ + std::string str_text(text); + aux::strip_quotes(str_text); + + std::string str_label1(label1); + aux::strip_quotes(str_label1); + std::string str_command1(command1); + aux::strip_quotes(str_command1); + + std::string str_label2(label2); + aux::strip_quotes(str_label2); + std::string str_command2(command2); + aux::strip_quotes(str_command2); + + std::ostringstream msg(""); + msg << "box "; + msg << "\"" << str_text << '\"' << ' '; + msg << "\"" << str_label1 << '\"' << ' '; + msg << "\"" << str_command1 << '\"' << ' '; + msg << "\"" << str_label2 << '\"' << ' '; + msg << "\"" << str_command2 << '\"' << '\n'; + + client->send_raw(msg.str()); +} // disconnect a client void NetServer::send_disconnect(NetClient *client) @@ -745,7 +777,6 @@ void NetServer::send_inventory_update(NetClient *client, Entity *entity, const u * info * req * inv - * */ void NetServer::parse_incoming_message(NetClient *client, const std::string & message) { @@ -779,6 +810,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me con_print << client->host() << ":" << client->port() << " " << netmsgstream.str() << std::endl; send_message(client, Message::Info, netmsgstream.str()); + send_messagebox(client, netmsgstream.str(), "", "", "", ""); send_disconnect(client); } else { -- cgit v1.2.3