From ca0c1d3e6f8b5fa4eb2e0a86fcf47b12fb600786 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 27 Sep 2008 17:16:15 +0000 Subject: mission targets, texture unloading, private messages --- src/core/netconnection.cc | 91 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 28 deletions(-) (limited to 'src/core/netconnection.cc') diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index ed1a91b..9268447 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -328,6 +328,7 @@ void NetConnection::send_raw(std::string const &msg) * cup * cmd * say + * priv */ // send a "connect" message to the server @@ -380,6 +381,15 @@ void NetConnection::send_say(std::string const &text) this->send_raw(msg); } +// send a "priv" private message to the server +void NetConnection::send_private_message(std::string const &text) +{ + std::string msg("priv "); + msg.append(text); + msg += '\n'; + this->send_raw(msg); +} + // parse incoming client messages /** * The following incoming messages are parsed; @@ -388,13 +398,14 @@ void NetConnection::send_say(std::string const &text) * disconnect * msg info * msg public + * msg private * msg rcon * msg snd - * die - * ent + * die + * ent * frame - * sup - * pif + * sup + * pif * zone */ void NetConnection::parse_incoming_message(const std::string & message) @@ -409,19 +420,22 @@ void NetConnection::parse_incoming_message(const std::string & message) if (msgstream >> level) { if (level =="info") { if (message.size() > 9) { - application()->notify_message(message.substr(9)); + application()->notify_message(Message::Info, message.substr(9)); } } else if (level =="rcon") { if (message.size() > 9) { - con_print << message.substr(9) << std::endl; + application()->notify_message(Message::RCon, message.substr(9)); } } else if (level == "public") { // FIXME - separate sender nickname if (message.size() > 11) { - application()->notify_message(message.substr(11)); - application()->notify_sound("com/chat"); + application()->notify_message(Message::Public, message.substr(11)); } - + } else if (level == "private") { + // FIXME - separate sender nickname + if (message.size() > 12) { + application()->notify_message(Message::Private, message.substr(12)); + } } else if (level == "snd") { if (message.size() > 8) { application()->notify_sound(message.substr(8).c_str()); @@ -527,29 +541,50 @@ void NetConnection::parse_incoming_message(const std::string & message) } else if (command == "pif") { //con_debug << "Received update player info" << std::endl; - - Zone *oldzone = connection()->localplayer()->zone(); - connection()->localplayer()->receive_server_update(msgstream); - - //con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl; - if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) { - - // notify the applciation to clear none-core zone assets (textures etc) - application()->notify_zoneclear(oldzone); - - // delete all entities in the old zone - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { - Entity *entity = (*it).second; + int player_id; + if (!(msgstream >> player_id)) { + con_warn << "Received illegal update player info for player!" << std::endl; + return; + } - if ((entity->zone() == oldzone)) { - delete entity; - Entity::registry().erase(it++); - } else { - ++it; + if (!player_id) { + Zone *oldzone = connection()->localplayer()->zone(); + connection()->localplayer()->receive_server_update(msgstream); + + //con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl; + + if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) { + + // notify the applciation to clear none-core zone assets (textures etc) + application()->notify_zoneclear(oldzone); + + // delete all entities in the old zone + for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { + Entity *entity = (*it).second; + + if ((entity->zone() == oldzone)) { + delete entity; + Entity::registry().erase(it++); + } else { + ++it; + } + } + oldzone->content().clear(); + } + } else { + // FIXME find player + Player *player = 0; + for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) { + if( (*it)->id() == player_id) { + player = (*it); } } - oldzone->content().clear(); + if (!player) { + player = new Player(); + game()->players().push_back(player); + } + player->receive_server_update(msgstream); } } else if (command == "sup") { -- cgit v1.2.3