Klaus Halfmann has proposed merging lp:~widelands-dev/widelands/bug-1395278-network into lp:widelands.
Requested reviews: Widelands Developers (widelands-dev) For more details, see: https://code.launchpad.net/~widelands-dev/widelands/bug-1395278-network/+merge/285990 Make member variables like <member>_ mostly in network. -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1395278-network into lp:widelands.
=== modified file 'src/network/internet_gaming.cc' --- src/network/internet_gaming.cc 2016-02-06 11:11:24 +0000 +++ src/network/internet_gaming.cc 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2006, 2008-2009, 2012-2013 by the Widelands Development Team + * Copyright (C) 2004-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -35,56 +35,56 @@ /// Private constructor by purpose: NEVER call directly. Always call InternetGaming::ref(), this will ensure /// that only one instance is running at time. InternetGaming::InternetGaming() : - m_sock (nullptr), - m_sockset (nullptr), - m_state (OFFLINE), - m_reg (false), - m_port (INTERNET_GAMING_PORT), - m_clientrights (INTERNET_CLIENT_UNREGISTERED), - m_gameip (""), - clientupdateonmetaserver (true), - gameupdateonmetaserver (true), - clientupdate (false), - gameupdate (false), - time_offset (0), - waittimeout (std::numeric_limits<int32_t>::max()), - lastping (time(nullptr)) + sock_ (nullptr), + sockset_ (nullptr), + state_ (OFFLINE), + reg_ (false), + port_ (INTERNET_GAMING_PORT), + clientrights_ (INTERNET_CLIENT_UNREGISTERED), + gameip_ (""), + clientupdateonmetaserver_(true), + gameupdateonmetaserver_ (true), + clientupdate_ (false), + gameupdate_ (false), + time_offset_ (0), + waittimeout_ (std::numeric_limits<int32_t>::max()), + lastping_ (time(nullptr)) { // Fill the list of possible messages from the server InternetGamingMessages::fill_map(); // Set connection tracking variables to 0 - lastbrokensocket[0] = 0; - lastbrokensocket[1] = 0; + lastbrokensocket_[0] = 0; + lastbrokensocket_[1] = 0; } /// resets all stored variables without the chat messages for a clean new login (not relogin) void InternetGaming::reset() { - m_sock = nullptr; - m_sockset = nullptr; - m_state = OFFLINE; - m_pwd = ""; - m_reg = false; - m_meta = INTERNET_GAMING_METASERVER; - m_port = INTERNET_GAMING_PORT; - m_clientname = ""; - m_clientrights = INTERNET_CLIENT_UNREGISTERED; - m_gamename = ""; - m_gameip = ""; - clientupdateonmetaserver = true; - gameupdateonmetaserver = true; - clientupdate = false; - gameupdate = false; - time_offset = 0; - waitcmd = ""; - waittimeout = std::numeric_limits<int32_t>::max(); - lastbrokensocket[0] = 0; - lastbrokensocket[1] = 0; - lastping = time(nullptr); + sock_ = nullptr; + sockset_ = nullptr; + state_ = OFFLINE; + pwd_ = ""; + reg_ = false; + meta_ = INTERNET_GAMING_METASERVER; + port_ = INTERNET_GAMING_PORT; + clientname_ = ""; + clientrights_ = INTERNET_CLIENT_UNREGISTERED; + gamename_ = ""; + gameip_ = ""; + clientupdateonmetaserver_= true; + gameupdateonmetaserver_ = true; + clientupdate_ = false; + gameupdate_ = false; + time_offset_ = 0; + waitcmd_ = ""; + waittimeout_ = std::numeric_limits<int32_t>::max(); + lastbrokensocket_[0] = 0; + lastbrokensocket_[1] = 0; + lastping_ = time(nullptr); - clientlist.clear(); - gamelist.clear(); + clientlist_.clear(); + gamelist_.clear(); } @@ -104,18 +104,18 @@ // First of all try to connect to the metaserver log("InternetGaming: Connecting to the metaserver.\n"); IPaddress peer; - if (hostent * const he = gethostbyname(m_meta.c_str())) { + if (hostent * const he = gethostbyname(meta_.c_str())) { peer.host = (reinterpret_cast<in_addr *>(he->h_addr_list[0]))->s_addr; DIAG_OFF("-Wold-style-cast") - peer.port = htons(m_port); + peer.port = htons(port_); DIAG_ON("-Wold-style-cast") } else throw WLWarning (_("Connection problem"), "%s", _("Widelands could not connect to the metaserver.")); - SDLNet_ResolveHost (&peer, m_meta.c_str(), m_port); - m_sock = SDLNet_TCP_Open(&peer); - if (m_sock == nullptr) + SDLNet_ResolveHost (&peer, meta_.c_str(), port_); + sock_ = SDLNet_TCP_Open(&peer); + if (sock_ == nullptr) throw WLWarning (_("Could not establish connection to host"), _ @@ -123,11 +123,11 @@ "Either there was no metaserver running at the supposed port or\n" "your network setup is broken.")); - m_sockset = SDLNet_AllocSocketSet(1); - SDLNet_TCP_AddSocket (m_sockset, m_sock); + sockset_ = SDLNet_AllocSocketSet(1); + SDLNet_TCP_AddSocket (sockset_, sock_); // Of course not 100% true, but we just care about an answer at all, so we reset this tracker - lastping = time(nullptr); + lastping_ = time(nullptr); } @@ -136,12 +136,12 @@ bool InternetGaming::login (const std::string & nick, const std::string & pwd, bool reg, const std::string & meta, uint32_t port) { - assert(m_state == OFFLINE); + assert(state_ == OFFLINE); - m_pwd = pwd; - m_reg = reg; - m_meta = meta; - m_port = port; + pwd_ = pwd; + reg_ = reg; + meta_ = meta; + port_ = port; initialize_connection(); @@ -155,17 +155,17 @@ s.string(bool2str(reg)); if (reg) s.string(pwd); - s.send(m_sock); + s.send(sock_); // Now let's see, whether the metaserver is answering uint32_t const secs = time(nullptr); - m_state = CONNECTING; + state_ = CONNECTING; while (INTERNET_GAMING_TIMEOUT > time(nullptr) - secs) { handle_metaserver_communication(); // Check if we are a step further... if yes handle_packet has taken care about all the // paperwork, so we put our feet up and just return. ;) - if (m_state != CONNECTING) { - if (m_state == LOBBY) { + if (state_ != CONNECTING) { + if (state_ == LOBBY) { format_and_add_chat("", "", true, _("For hosting a game, please take a look at the notes at:")); format_and_add_chat("", "", true, "http://wl.widelands.org/wiki/InternetGaming"); return true; @@ -194,22 +194,22 @@ SendPacket s; s.string(IGPCMD_RELOGIN); s.string(boost::lexical_cast<std::string>(INTERNET_GAMING_PROTOCOL_VERSION)); - s.string(m_clientname); + s.string(clientname_); s.string(build_id()); - s.string(bool2str(m_reg)); - if (m_reg) - s.string(m_pwd); - s.send(m_sock); + s.string(bool2str(reg_)); + if (reg_) + s.string(pwd_); + s.send(sock_); // Now let's see, whether the metaserver is answering uint32_t const secs = time(nullptr); - m_state = CONNECTING; + state_ = CONNECTING; while (INTERNET_GAMING_TIMEOUT > time(nullptr) - secs) { handle_metaserver_communication(); // Check if we are a step further... if yes handle_packet has taken care about all the // paperwork, so we put our feet up and just return. ;) - if (m_state != CONNECTING) { - if (m_state == LOBBY) { + if (state_ != CONNECTING) { + if (state_ == LOBBY) { break; } else if (error()) return false; @@ -222,13 +222,13 @@ } // Client is reconnected, so let's try resend the timeouted command. - if (waitcmd == IGPCMD_GAME_CONNECT) - join_game(m_gamename); - else if (waitcmd == IGPCMD_GAME_OPEN) { - m_state = IN_GAME; + if (waitcmd_ == IGPCMD_GAME_CONNECT) + join_game(gamename_); + else if (waitcmd_ == IGPCMD_GAME_OPEN) { + state_ = IN_GAME; open_game(); - } else if (waitcmd == IGPCMD_GAME_START) { - m_state = IN_GAME; + } else if (waitcmd_ == IGPCMD_GAME_START) { + state_ = IN_GAME; set_game_playing(); } @@ -245,7 +245,7 @@ SendPacket s; s.string(IGPCMD_DISCONNECT); s.string(msgcode); - s.send(m_sock); + s.send(sock_); const std::string & msg = InternetGamingMessages::get_message(msgcode); log("InternetGaming: logout(%s)\n", msg.c_str()); @@ -255,46 +255,53 @@ } +/** + * Handle situation when reading from socket failed. + */ +void InternetGaming::handle_failed_read() { + set_error(); + const std::string & msg = InternetGamingMessages::get_message("CONNECTION_LOST"); + log("InternetGaming: Error: %s\n", msg.c_str()); + format_and_add_chat("", "", true, msg); + + // Check how much time passed since the socket broke the last time + // Maybe something is completely wrong at the moment? + // At least it seems to be, if the socket broke three times in the last 10 seconds... + time_t now = time(nullptr); + if ((now - lastbrokensocket_[1] < 10) && (now - lastbrokensocket_[0] < 10)) { + reset(); + set_error(); + return; + } + lastbrokensocket_[1] = lastbrokensocket_[0]; + lastbrokensocket_[0] = now; + + // Try to relogin + if (!relogin()) { + // Do not try to relogin again automatically. + reset(); + set_error(); + } +} + /// handles all communication between the metaserver and the client void InternetGaming::handle_metaserver_communication() { if (error()) return; try { - while (m_sock != nullptr && SDLNet_CheckSockets(m_sockset, 0) > 0) { + while (sock_ != nullptr && SDLNet_CheckSockets(sockset_, 0) > 0) { // Perform only one read operation, then process all packets // from this read. This ensures that we process DISCONNECT // packets that are followed immediately by connection close. - if (!m_deserializer.read(m_sock)) { - set_error(); - const std::string & msg = InternetGamingMessages::get_message("CONNECTION_LOST"); - log("InternetGaming: Error: %s\n", msg.c_str()); - format_and_add_chat("", "", true, msg); - - // Check how much time passed since the socket broke the last time - // Maybe something is completely wrong at the moment? - // At least it seems to be, if the socket broke three times in the last 10 seconds... - time_t now = time(nullptr); - if ((now - lastbrokensocket[1] < 10) && (now - lastbrokensocket[0] < 10)) { - reset(); - set_error(); - return; - } - lastbrokensocket[1] = lastbrokensocket[0]; - lastbrokensocket[0] = now; - - // Try to relogin - if (!relogin()) { - // Do not try to relogin again automatically. - reset(); - set_error(); - } + if (!deserializer_.read(sock_)) { + handle_failed_read(); return; } // Process all the packets from the last read - while (m_sock && m_deserializer.avail()) { - RecvPacket packet(m_deserializer); + while (sock_ && deserializer_.avail()) { + RecvPacket packet(deserializer_); handle_packet(packet); } } @@ -305,31 +312,31 @@ set_error(); } - if (m_state == LOBBY) { + if (state_ == LOBBY) { // client is in the lobby and therefore we want realtime information updates - if (clientupdateonmetaserver) { + if (clientupdateonmetaserver_) { SendPacket s; s.string(IGPCMD_CLIENTS); - s.send(m_sock); + s.send(sock_); - clientupdateonmetaserver = false; + clientupdateonmetaserver_ = false; } - if (gameupdateonmetaserver) { + if (gameupdateonmetaserver_) { SendPacket s; s.string(IGPCMD_GAMES); - s.send(m_sock); + s.send(sock_); - gameupdateonmetaserver = false; + gameupdateonmetaserver_ = false; } } - if (!waitcmd.empty()) { + if (!waitcmd_.empty()) { // Check if timeout is reached time_t now = time(nullptr); - if (now > waittimeout) { + if (now > waittimeout_) { set_error(); - waittimeout = std::numeric_limits<int32_t>::max(); + waittimeout_ = std::numeric_limits<int32_t>::max(); log("InternetGaming: reached a timeout for an awaited answer of the metaserver!\n"); if (!relogin()) { // Do not try to relogin again automatically. @@ -341,7 +348,7 @@ // Check connection to the metaserver // Was a ping received in the last 4 minutes? - if (time(nullptr) - lastping > 240) { + if (time(nullptr) - lastping_ > 240) { // Try to relogin set_error(); if (!relogin()) { @@ -376,19 +383,19 @@ } // Are we already online? - if (m_state == CONNECTING) { + if (state_ == CONNECTING) { if (cmd == IGPCMD_LOGIN) { // Clients request to login was granted - m_clientname = packet.string(); - m_clientrights = packet.string(); - m_state = LOBBY; - log("InternetGaming: Client %s logged in.\n", m_clientname.c_str()); + clientname_ = packet.string(); + clientrights_ = packet.string(); + state_ = LOBBY; + log("InternetGaming: Client %s logged in.\n", clientname_.c_str()); return; } else if (cmd == IGPCMD_RELOGIN) { // Clients request to relogin was granted - m_state = LOBBY; - log("InternetGaming: Client %s relogged in.\n", m_clientname.c_str()); + state_ = LOBBY; + log("InternetGaming: Client %s relogged in.\n", clientname_.c_str()); format_and_add_chat("", "", true, _("Successfully reconnected to the metaserver!")); return; @@ -429,17 +436,17 @@ else if (cmd == IGPCMD_TIME) { // Client received the server time - time_offset = boost::lexical_cast<int>(packet.string()) - time(nullptr); + time_offset_ = boost::lexical_cast<int>(packet.string()) - time(nullptr); log (ngettext ("InternetGaming: Server time offset is %u second.", - "InternetGaming: Server time offset is %u seconds.", time_offset), - time_offset); + "InternetGaming: Server time offset is %u seconds.", time_offset_), + time_offset_); std::string temp = (boost::format (ngettext("Server time offset is %u second.", - "Server time offset is %u seconds.", time_offset)) - % time_offset) + "Server time offset is %u seconds.", time_offset_)) + % time_offset_) .str(); format_and_add_chat("", "", true, temp); } @@ -448,9 +455,9 @@ // Client received a PING and should immediately PONG as requested SendPacket s; s.string(IGPCMD_PONG); - s.send(m_sock); + s.send(sock_); - lastping = time(nullptr); + lastping_ = time(nullptr); } else if (cmd == IGPCMD_CHAT) { @@ -465,27 +472,27 @@ bool personal = type == "private"; bool system = type == "system"; - format_and_add_chat(sender, personal ? m_clientname : "", system, message); + format_and_add_chat(sender, personal ? clientname_ : "", system, message); } else if (cmd == IGPCMD_GAMES_UPDATE) { // Client received a note, that the list of games was changed log("InternetGaming: Game update on metaserver.\n"); - gameupdateonmetaserver = true; + gameupdateonmetaserver_ = true; } else if (cmd == IGPCMD_GAMES) { // Client received the new list of games uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff; - std::vector<InternetGame> old = gamelist; - gamelist.clear(); + std::vector<InternetGame> old = gamelist_; + gamelist_.clear(); log("InternetGaming: Received a game list update with %u items.\n", number); for (uint8_t i = 0; i < number; ++i) { InternetGame * ing = new InternetGame(); ing->name = packet.string(); ing->build_id = packet.string(); ing->connectable = str2bool(packet.string()); - gamelist.push_back(*ing); + gamelist_.push_back(*ing); bool found = false; for (std::vector<InternetGame>::size_type j = 0; j < old.size(); ++j) @@ -507,20 +514,20 @@ format_and_add_chat ("", "", true, (boost::format(_("The game %s has been closed")) % old[i].name).str()); - gameupdate = true; + gameupdate_ = true; } else if (cmd == IGPCMD_CLIENTS_UPDATE) { // Client received a note, that the list of clients was changed log("InternetGaming: Client update on metaserver.\n"); - clientupdateonmetaserver = true; + clientupdateonmetaserver_ = true; } else if (cmd == IGPCMD_CLIENTS) { // Client received the new list of clients uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff; - std::vector<InternetClient> old = clientlist; - clientlist.clear(); + std::vector<InternetClient> old = clientlist_; + clientlist_.clear(); log("InternetGaming: Received a client list update with %u items.\n", number); for (uint8_t i = 0; i < number; ++i) { InternetClient * inc = new InternetClient(); @@ -529,7 +536,7 @@ inc->game = packet.string(); inc->type = packet.string(); inc->points = packet.string(); - clientlist.push_back(*inc); + clientlist_.push_back(*inc); bool found = old.empty(); // do not show all clients, if this instance is the actual change for (std::vector<InternetClient>::size_type j = 0; j < old.size(); ++j) @@ -551,28 +558,28 @@ format_and_add_chat ("", "", true, (boost::format(_("%s left the lobby")) % old[i].name).str()); - clientupdate = true; + clientupdate_ = true; } else if (cmd == IGPCMD_GAME_OPEN) { // Client received the acknowledgment, that the game was opened - assert (waitcmd == IGPCMD_GAME_OPEN); - waitcmd = ""; + assert (waitcmd_ == IGPCMD_GAME_OPEN); + waitcmd_ = ""; } else if (cmd == IGPCMD_GAME_CONNECT) { // Client received the ip for the game it wants to join - assert (waitcmd == IGPCMD_GAME_CONNECT); - waitcmd = ""; + assert (waitcmd_ == IGPCMD_GAME_CONNECT); + waitcmd_ = ""; // save the received ip, so the client cann connect to the game - m_gameip = packet.string(); - log("InternetGaming: Received ip of the game to join: %s.\n", m_gameip.c_str()); + gameip_ = packet.string(); + log("InternetGaming: Received ip of the game to join: %s.\n", gameip_.c_str()); } else if (cmd == IGPCMD_GAME_START) { // Client received the acknowledgment, that the game was started - assert (waitcmd == IGPCMD_GAME_START); - waitcmd = ""; + assert (waitcmd_ == IGPCMD_GAME_START); + waitcmd_ = ""; } else if (cmd == IGPCMD_ERROR) { @@ -597,7 +604,7 @@ // Something went wrong with the newly opened game message = InternetGamingMessages::get_message(reason); // we got our answer, so no need to wait anymore - waitcmd = ""; + waitcmd_ = ""; } message = (boost::format(_("ERROR: %s")) % message).str(); @@ -623,7 +630,7 @@ /// \returns the ip of the game the client is on or wants to join (or the client is hosting) /// or 0, if no ip available. const std::string & InternetGaming::ip() { - return m_gameip; + return gameip_; } @@ -636,35 +643,35 @@ SendPacket s; s.string(IGPCMD_GAME_CONNECT); s.string(gamename); - s.send(m_sock); - m_gamename = gamename; - log("InternetGaming: Client tries to join a game with the name %s\n", m_gamename.c_str()); - m_state = IN_GAME; + s.send(sock_); + gamename_ = gamename; + log("InternetGaming: Client tries to join a game with the name %s\n", gamename_.c_str()); + state_ = IN_GAME; // From now on we wait for a reply from the metaserver - waitcmd = IGPCMD_GAME_CONNECT; - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; + waitcmd_ = IGPCMD_GAME_CONNECT; + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; } -/// called by a client to open a new game with name m_gamename +/// called by a client to open a new game with name gamename_ void InternetGaming::open_game() { if (!logged_in()) return; SendPacket s; s.string(IGPCMD_GAME_OPEN); - s.string(m_gamename); + s.string(gamename_); s.string("1024"); // Used to be maxclients, no longer used. - s.send(m_sock); - log("InternetGaming: Client opened a game with the name %s.\n", m_gamename.c_str()); - m_state = IN_GAME; + s.send(sock_); + log("InternetGaming: Client opened a game with the name %s.\n", gamename_.c_str()); + state_ = IN_GAME; // From now on we wait for a reply from the metaserver - waitcmd = IGPCMD_GAME_OPEN; - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; + waitcmd_ = IGPCMD_GAME_OPEN; + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; } @@ -676,12 +683,12 @@ SendPacket s; s.string(IGPCMD_GAME_START); - s.send(m_sock); - log("InternetGaming: Client announced the start of the game %s.\n", m_gamename.c_str()); + s.send(sock_); + log("InternetGaming: Client announced the start of the game %s.\n", gamename_.c_str()); // From now on we wait for a reply from the metaserver - waitcmd = IGPCMD_GAME_START; - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; + waitcmd_ = IGPCMD_GAME_START; + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; } @@ -694,21 +701,21 @@ SendPacket s; s.string(IGPCMD_GAME_DISCONNECT); - s.send(m_sock); - - m_gameip = ""; - m_state = LOBBY; - - log("InternetGaming: Client announced the disconnect from the game %s.\n", m_gamename.c_str()); + s.send(sock_); + + gameip_ = ""; + state_ = LOBBY; + + log("InternetGaming: Client announced the disconnect from the game %s.\n", gamename_.c_str()); } /// \returns whether the local gamelist was updated -/// \note this function resets gameupdate. So if you call it, please really handle the output. +/// \note this function resets gameupdate_. So if you call it, please really handle the output. bool InternetGaming::update_for_games() { - bool temp = gameupdate; - gameupdate = false; + bool temp = gameupdate_; + gameupdate_ = false; return temp; } @@ -716,16 +723,17 @@ /// \returns the tables in the room, if no error occured const std::vector<InternetGame> & InternetGaming::games() { - return error() ? * (new std::vector<InternetGame>()) : gamelist; + // TODO(Hasi50): in case of error() this is a memory leak? should return some unmodifiable singleton. + return error() ? * (new std::vector<InternetGame>()) : gamelist_; } -/// \returns whether the local clientlist was updated -/// \note this function resets clientupdate. So if you call it, please really handle the output. +/// \returns whether the local clientlist_ was updated +/// \note this function resets clientupdate_. So if you call it, please really handle the output. bool InternetGaming::update_for_clients() { - bool temp = clientupdate; - clientupdate = false; + bool temp = clientupdate_; + clientupdate_ = false; return temp; } @@ -733,7 +741,8 @@ /// \returns the players in the room, if no error occured const std::vector<InternetClient> & InternetGaming::clients() { - return error() ? * (new std::vector<InternetClient>()) : clientlist; + // TODO(Hasi50): in case of error() this is a memory leak? should return some unmodifiable singleton. + return error() ? * (new std::vector<InternetClient>()) : clientlist_; } @@ -760,9 +769,9 @@ s.string(msg.substr(space + 1)); // message s.string(msg.substr(1, space - 1)); // recipient - format_and_add_chat(m_clientname, msg.substr(1, space - 1), false, msg.substr(space + 1)); + format_and_add_chat(clientname_, msg.substr(1, space - 1), false, msg.substr(space + 1)); - } else if (m_clientrights == INTERNET_CLIENT_SUPERUSER && msg.size() && *msg.begin() == '/') { + } else if (clientrights_ == INTERNET_CLIENT_SUPERUSER && msg.size() && *msg.begin() == '/') { // This is either a /me command, a super user command, or well... just a chat message beginning // with a "/" - let's see... @@ -799,14 +808,14 @@ } // send the request to change the motd m.string(arg); - m.send(m_sock); + m.send(sock_); return; } else if (cmd == "announcement") { // send the request to change the motd SendPacket m; m.string(IGPCMD_ANNOUNCEMENT); m.string(arg); - m.send(m_sock); + m.send(sock_); return; } else // let everything else pass @@ -818,7 +827,7 @@ s.string(""); } - s.send(m_sock); + s.send(sock_); } /** @@ -858,9 +867,9 @@ c.recipient = to; receive(c); - if (system && (m_state == IN_GAME)) { + if (system && (state_ == IN_GAME)) { // Save system chat messages seperately as well, so the nethost can import and show them in game; c.msg = "METASERVER: " + msg; - ingame_system_chat.push_back(c); + ingame_systechat_.push_back(c); } } === modified file 'src/network/internet_gaming.h' --- src/network/internet_gaming.h 2015-01-21 20:57:11 +0000 +++ src/network/internet_gaming.h 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2006, 2008-2009, 2012-2013 by the Widelands Development Team + * Copyright (C) 2004-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -70,9 +70,9 @@ void logout(const std::string & msgcode = "CONNECTION_CLOSED"); /// \returns whether the client is logged in - bool logged_in() {return (m_state == LOBBY) || (m_state == CONNECTING) || (m_state == IN_GAME);} - bool error() {return (m_state == COMMUNICATION_ERROR);} - void set_error() {m_state = COMMUNICATION_ERROR; gameupdate = true; clientupdate = true;} + bool logged_in() {return (state_ == LOBBY) || (state_ == CONNECTING) || (state_ == IN_GAME);} + bool error() {return (state_ == COMMUNICATION_ERROR);} + void set_error() {state_ = COMMUNICATION_ERROR; gameupdate_ = true; clientupdate_ = true;} void handle_metaserver_communication(); @@ -91,16 +91,16 @@ const std::vector<InternetClient> & clients(); /// sets the name of the local server as shown in the games list - void set_local_servername(const std::string & name) {m_gamename = name;} + void set_local_servername(const std::string & name) {gamename_ = name;} /// \returns the name of the local server - std::string & get_local_servername() {return m_gamename;} + std::string & get_local_servername() {return gamename_;} /// \returns the name of the local client - std::string & get_local_clientname() {return m_clientname;} + std::string & get_local_clientname() {return clientname_;} /// \returns the rights of the local client - std::string & get_local_clientrights() {return m_clientrights;} + std::string & get_local_clientrights() {return clientrights_;} /// ChatProvider: sends a message via the metaserver. @@ -108,26 +108,27 @@ /// ChatProvider: adds the message to the message list and calls parent. void receive(const ChatMessage & msg) { - messages.push_back(msg); + messages_.push_back(msg); Notifications::publish(msg); } /// ChatProvider: returns the list of chatmessages. - const std::vector<ChatMessage> & get_messages() const override {return messages;} + const std::vector<ChatMessage> & get_messages() const override {return messages_;} /// Silence the internet lobby chat if we are in game as we do not see the messages anyways - bool sound_off() override {return m_state == IN_GAME;} + bool sound_off() override {return state_ == IN_GAME;} - /// writes the ingame_system_chat messages to \arg msg and resets it afterwards + /// writes the ingame_systechat_ messages to \arg msg and resets it afterwards void get_ingame_system_messages(std::vector<ChatMessage> & msg) { - msg = ingame_system_chat; - ingame_system_chat.clear(); + msg = ingame_systechat_; + ingame_systechat_.clear(); } private: InternetGaming(); void handle_packet(RecvPacket & packet); + void handle_failed_read(); // conversion functions bool str2bool(std::string); @@ -137,13 +138,13 @@ /// The socket that connects us to the host - TCPsocket m_sock; + TCPsocket sock_; /// Socket set used for selection - SDLNet_SocketSet m_sockset; + SDLNet_SocketSet sockset_; /// Deserializer acts as a buffer for packets (reassembly/splitting up) - Deserializer m_deserializer; + Deserializer deserializer_; /// Current state of this class enum { @@ -152,42 +153,42 @@ LOBBY, IN_GAME, COMMUNICATION_ERROR - } m_state; + } state_; /// data saved for possible relogin - std::string m_pwd; - bool m_reg; - std::string m_meta; - uint32_t m_port; + std::string pwd_; + bool reg_; + std::string meta_; + uint32_t port_; /// local clients name and rights - std::string m_clientname; - std::string m_clientrights; + std::string clientname_; + std::string clientrights_; /// informations of the clients game - std::string m_gamename; - std::string m_gameip; + std::string gamename_; + std::string gameip_; /// Metaserver informations - bool clientupdateonmetaserver; - bool gameupdateonmetaserver; - bool clientupdate; - bool gameupdate; - std::vector<InternetClient> clientlist; - std::vector<InternetGame> gamelist; - int32_t time_offset; + bool clientupdateonmetaserver_; + bool gameupdateonmetaserver_; + bool clientupdate_; + bool gameupdate_; + std::vector<InternetClient> clientlist_; + std::vector<InternetGame> gamelist_; + int32_t time_offset_; /// ChatProvider: chat messages - std::vector<ChatMessage> messages; - std::vector<ChatMessage> ingame_system_chat; + std::vector<ChatMessage> messages_; + std::vector<ChatMessage> ingame_systechat_; /// An important response of the metaserver, the client is waiting for. - std::string waitcmd; - int32_t waittimeout; + std::string waitcmd_; + int32_t waittimeout_; /// Connection tracking specific variables - time_t lastbrokensocket[2]; - time_t lastping; + time_t lastbrokensocket_[2]; /// last times when socket last broke in s. + time_t lastping_; }; === modified file 'src/network/netclient.cc' --- src/network/netclient.cc 2016-02-11 06:56:47 +0000 +++ src/network/netclient.cc 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2013, 2015 by the Widelands Development Team + * Copyright (C) 2008-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -100,7 +100,7 @@ NetClient::NetClient (IPaddress * const svaddr, const std::string & playername, bool internet) -: d(new NetClientImpl), m_internet(internet) +: d(new NetClientImpl), internet_(internet) { d->sock = SDLNet_TCP_Open(svaddr); if (d->sock == nullptr) @@ -122,7 +122,7 @@ d->game = nullptr; d->realspeed = 0; d->desiredspeed = 1000; - file = nullptr; + file_ = nullptr; // Get the default win condition script d->settings.win_condition_script = d->settings.win_condition_scripts.front(); @@ -159,7 +159,7 @@ d->modal = nullptr; if (code == FullscreenMenuBase::MenuTarget::kBack) { // if this is an internet game, tell the metaserver that client is back in the lobby. - if (m_internet) + if (internet_) InternetGaming::ref().set_game_done(); return; } @@ -212,7 +212,7 @@ (boost::format("netclient_%d") % static_cast<int>(d->settings.usernum)).str()); // if this is an internet game, tell the metaserver that the game is done. - if (m_internet) + if (internet_) InternetGaming::ref().set_game_done(); d->modal = nullptr; d->game = nullptr; @@ -615,8 +615,8 @@ d->settings.mapname.c_str(), d->settings.mapfilename.c_str()); // New map was set, so we clean up the buffer of a previously requested file - if (file) - delete file; + if (file_) + delete file_; break; } @@ -655,13 +655,13 @@ s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); s.send(d->sock); - if (file) - delete file; + if (file_) + delete file_; - file = new NetTransferFile(); - file->bytes = bytes; - file->filename = path; - file->md5sum = md5; + file_ = new NetTransferFile(); + file_->bytes = bytes; + file_->filename = path; + file_->md5sum = md5; size_t position = path.rfind(g_fs->file_separator(), path.size() - 2); if (position != std::string::npos) { path.resize(position); @@ -674,7 +674,7 @@ // Only go on, if we are waiting for a file part at the moment. It can happen, that an "unrequested" // part is send by the server if the map was changed just a moment ago and there was an outstanding // request from the client. - if (!file) + if (!file_) return; // silently ignore uint32_t part = packet.unsigned_32(); @@ -684,7 +684,7 @@ SendPacket s; s.unsigned_8(NETCMD_FILE_PART); s.unsigned_32(part); - s.string(file->md5sum); + s.string(file_->md5sum); s.send(d->sock); FilePart fp; @@ -695,37 +695,37 @@ if (packet.data(buf, size) != size) log("Readproblem. Will try to go on anyways\n"); memcpy(fp.part, &buf[0], size); - file->parts.push_back(fp); + file_->parts.push_back(fp); // Write file to disk as soon as all parts arrived - uint32_t left = (file->bytes - NETFILEPARTSIZE * part); + uint32_t left = (file_->bytes - NETFILEPARTSIZE * part); if (left <= NETFILEPARTSIZE) { FileWrite fw; - left = file->bytes; + left = file_->bytes; uint32_t i = 0; // Put all data together while (left > 0) { uint32_t writeout = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; - fw.data(file->parts[i].part, writeout, FileWrite::Pos::null()); + fw.data(file_->parts[i].part, writeout, FileWrite::Pos::null()); left -= writeout; ++i; } // Now really write the file - fw.write(*g_fs, file->filename.c_str()); + fw.write(*g_fs, file_->filename.c_str()); // Check for consistence FileRead fr; - fr.open(*g_fs, file->filename); - - std::unique_ptr<char[]> complete(new char[file->bytes]); - - fr.data_complete(complete.get(), file->bytes); + fr.open(*g_fs, file_->filename); + + std::unique_ptr<char[]> complete(new char[file_->bytes]); + + fr.data_complete(complete.get(), file_->bytes); SimpleMD5Checksum md5sum; - md5sum.data(complete.get(), file->bytes); + md5sum.data(complete.get(), file_->bytes); md5sum.finish_checksum(); std::string localmd5 = md5sum.get_checksum().str(); - if (localmd5 != file->md5sum) { + if (localmd5 != file_->md5sum) { // Something went wrong! We have to rerequest the file. s.reset(); s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); @@ -735,7 +735,7 @@ s.unsigned_8(NETCMD_CHAT); s.string(_("/me 's file failed md5 checksumming.")); s.send(d->sock); - g_fs->fs_unlink(file->filename); + g_fs->fs_unlink(file_->filename); } // Check file for validity bool invalid = false; @@ -743,22 +743,22 @@ // Saved game check - does Widelands recognize the file as saved game? Widelands::Game game; try { - Widelands::GameLoader gl(file->filename, game); + Widelands::GameLoader gl(file_->filename, game); } catch (...) { invalid = true; } } else { // Map check - does Widelands recognize the file as map? Widelands::Map map; - std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(file->filename); + std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(file_->filename); if (!ml) invalid = true; } if (invalid) { - g_fs->fs_unlink(file->filename); + g_fs->fs_unlink(file_->filename); // Restore original file, if there was one before - if (g_fs->file_exists(backup_file_name(file->filename))) - g_fs->fs_rename(backup_file_name(file->filename), file->filename); + if (g_fs->file_exists(backup_file_name(file_->filename))) + g_fs->fs_rename(backup_file_name(file_->filename), file_->filename); s.reset(); s.unsigned_8(NETCMD_CHAT); s.string @@ -918,7 +918,7 @@ void NetClient::handle_network () { // if this is an internet game, handle the metaserver network - if (m_internet) + if (internet_) InternetGaming::ref().handle_metaserver_communication(); try { while (d->sock != nullptr && SDLNet_CheckSockets(d->sockset, 0) > 0) { === modified file 'src/network/netclient.h' --- src/network/netclient.h 2016-02-06 11:11:24 +0000 +++ src/network/netclient.h 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2012 by the Widelands Development Team + * Copyright (C) 2008-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -103,8 +103,6 @@ /// for unique backupname std::string backup_file_name(std::string & path) {return path + "~backup";} - NetTransferFile * file; - void syncreport() override; void handle_packet(RecvPacket &); @@ -115,8 +113,9 @@ void disconnect (const std::string & reason, const std::string & arg = "", bool sendreason = true, bool showmsg = true); - NetClientImpl * d; - bool m_internet; + NetTransferFile * file_; + NetClientImpl * d; + bool internet_; }; #endif // end of include guard: WL_NETWORK_NETCLIENT_H === modified file 'src/network/nethost.cc' --- src/network/nethost.cc 2016-02-07 07:41:45 +0000 +++ src/network/nethost.cc 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2013, 2015 by the Widelands Development Team + * Copyright (C) 2008-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -583,8 +583,8 @@ NetHost::NetHost (const std::string & playername, bool internet) : d(new NetHostImpl(this)), - m_internet(internet), - m_forced_pause(false) + internet_(internet), + forced_pause_(false) { log("[Host]: starting up.\n"); @@ -618,7 +618,7 @@ hostuser.position = UserSettings::none(); hostuser.ready = true; d->settings.users.push_back(hostuser); - file = nullptr; // Initialize as 0 pointer - unfortunately needed in struct. + file_ = nullptr; // Initialize as 0 pointer - unfortunately needed in struct. } NetHost::~NetHost () @@ -638,7 +638,7 @@ delete d->promoter; delete d; - delete file; + delete file_; } const std::string & NetHost::get_local_playername() const @@ -690,13 +690,13 @@ const FullscreenMenuBase::MenuTarget code = lm.run<FullscreenMenuBase::MenuTarget>(); if (code == FullscreenMenuBase::MenuTarget::kBack) { // if this is an internet game, tell the metaserver that client is back in the lobby. - if (m_internet) + if (internet_) InternetGaming::ref().set_game_done(); return; } // if this is an internet game, tell the metaserver that the game started - if (m_internet) + if (internet_) InternetGaming::ref().set_game_playing(); for (uint32_t i = 0; i < d->clients.size(); ++i) { @@ -778,7 +778,7 @@ delete tips; // if this is an internet game, tell the metaserver that the game is done. - if (m_internet) + if (internet_) InternetGaming::ref().set_game_done(); clear_computer_players(); } catch (...) { @@ -1163,30 +1163,30 @@ // Read in the file FileRead fr; fr.open(*g_fs, mapfilename); - if (file) - delete file; - file = new NetTransferFile(); - file->filename = mapfilename; - uint32_t leftparts = file->bytes = fr.get_size(); + if (file_) + delete file_; + file_ = new NetTransferFile(); + file_->filename = mapfilename; + uint32_t leftparts = file_->bytes = fr.get_size(); while (leftparts > 0) { uint32_t readout = (leftparts > NETFILEPARTSIZE) ? NETFILEPARTSIZE : leftparts; FilePart fp; memcpy(fp.part, fr.data(readout), readout); - file->parts.push_back(fp); + file_->parts.push_back(fp); leftparts -= readout; } - std::vector<char> complete(file->bytes); + std::vector<char> complete(file_->bytes); fr.set_file_pos(0); - fr.data_complete(&complete[0], file->bytes); + fr.data_complete(&complete[0], file_->bytes); SimpleMD5Checksum md5sum; - md5sum.data(&complete[0], file->bytes); + md5sum.data(&complete[0], file_->bytes); md5sum.finish_checksum(); - file->md5sum = md5sum.get_checksum().str(); + file_->md5sum = md5sum.get_checksum().str(); } else { // reset previously offered map / saved game - if (file) { - delete file; - file = nullptr; + if (file_) { + delete file_; + file_ = nullptr; } } @@ -1615,8 +1615,8 @@ //Scan-build reports that access to bytes here results in a dereference of null pointer. //This is a false positive. //See https://bugs.launchpad.net/widelands/+bug/1198919 - s.unsigned_32(file->bytes); - s.string(file->md5sum); + s.unsigned_32(file_->bytes); + s.string(file_->md5sum); return true; } @@ -1722,9 +1722,9 @@ s.send(client.sock); // If possible, offer the map / savegame as transfer - if (file) { + if (file_) { s.reset(); - if (write_map_transfer_info(s, file->filename)) + if (write_map_transfer_info(s, file_->filename)) s.send(client.sock); } @@ -1926,7 +1926,7 @@ uint32_t const oldnetworkspeed = d->networkspeed; // First check if a pause was forced by the host - if (m_forced_pause) + if (forced_pause_) d->networkspeed = 0; else { @@ -2075,7 +2075,7 @@ } // if this is an internet game, handle the metaserver information - if (m_internet) { + if (internet_) { InternetGaming::ref().handle_metaserver_communication(); // Maybe an important message was send on the metaserver, // that we should show in game as well. @@ -2114,9 +2114,9 @@ } } - // If a pause was forced or if the players all pause, send a ping regularly - // to keep the sockets up and running - if ((m_forced_pause || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { + // If a pause was forced or if the players all pause, send a ping regularly + // to keep the sockets up and running + if ((forced_pause_ || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { d->lastpauseping = time(nullptr); SendPacket s; @@ -2322,10 +2322,10 @@ } case NETCMD_NEW_FILE_AVAILABLE: { - if (!file) // Do we have a file for sending + if (!file_) // Do we have a file for sending throw DisconnectException("REQUEST_OF_N_E_FILE"); send_system_message_code - ("STARTED_SENDING_FILE", file->filename, d->settings.users.at(client.usernum).name); + ("STARTED_SENDING_FILE", file_->filename, d->settings.users.at(client.usernum).name); send_file_part(client.sock, 0); // Remember client as "currently receiving file" d->settings.users[client.usernum].ready = false; @@ -2338,19 +2338,19 @@ } case NETCMD_FILE_PART: { - if (!file) // Do we have a file for sending + if (!file_) // Do we have a file for sending throw DisconnectException("REQUEST_OF_N_E_FILE"); uint32_t part = r.unsigned_32(); std::string x = r.string(); - if (x != file->md5sum) { - log("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file->md5sum.c_str()); + if (x != file_->md5sum) { + log("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file_->md5sum.c_str()); return; // Surely the file was changed, so we cancel here. } - if (part >= file->parts.size()) + if (part >= file_->parts.size()) throw DisconnectException("REQUEST_OF_N_E_FILEPART"); - if (part == file->parts.size() - 1) { + if (part == file_->parts.size() - 1) { send_system_message_code - ("COMPLETED_FILE_TRANSFER", file->filename, d->settings.users.at(client.usernum).name); + ("COMPLETED_FILE_TRANSFER", file_->filename, d->settings.users.at(client.usernum).name); d->settings.users[client.usernum].ready = true; SendPacket s; s.unsigned_8(NETCMD_SETTING_USER); @@ -2363,8 +2363,8 @@ if (part % 100 == 0) send_system_message_code ("SENDING_FILE_PART", - (boost::format("%i/%i") % part % (file->parts.size() + 1)).str(), - file->filename, d->settings.users.at(client.usernum).name); + (boost::format("%i/%i") % part % (file_->parts.size() + 1)).str(), + file_->filename, d->settings.users.at(client.usernum).name); send_file_part(client.sock, part); break; } @@ -2375,9 +2375,9 @@ } void NetHost::send_file_part(TCPsocket csock, uint32_t part) { - assert(part < file->parts.size()); + assert(part < file_->parts.size()); - uint32_t left = file->bytes - NETFILEPARTSIZE * part; + uint32_t left = file_->bytes - NETFILEPARTSIZE * part; uint32_t size = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; // Send the part @@ -2385,7 +2385,7 @@ s.unsigned_8(NETCMD_FILE_PART); s.unsigned_32(part); s.unsigned_32(size); - s.data(file->parts[part].part, size); + s.data(file_->parts[part].part, size); s.send(csock); } === modified file 'src/network/nethost.h' --- src/network/nethost.h 2016-02-06 12:49:40 +0000 +++ src/network/nethost.h 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2012 by the Widelands Development Team + * Copyright (C) 2008-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -94,19 +94,18 @@ void report_result(uint8_t player, Widelands::PlayerEndResult result, const std::string & info) override; void force_pause() { - m_forced_pause = true; + forced_pause_ = true; update_network_speed(); } void end_forced_pause() { - m_forced_pause = false; + forced_pause_ = false; update_network_speed(); } - bool forced_pause() {return m_forced_pause;} + bool forced_pause() {return forced_pause_;} private: - NetTransferFile * file; void send_system_message_code (const std::string &, @@ -153,9 +152,10 @@ const std::string & arg = ""); void reaper(); - NetHostImpl * d; - bool m_internet; - bool m_forced_pause; + NetTransferFile * file_; + NetHostImpl * d; + bool internet_; + bool forced_pause_; }; === modified file 'src/network/network.cc' --- src/network/network.cc 2015-11-21 10:16:52 +0000 +++ src/network/network.cc 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2009, 2015 by the Widelands Development Team + * Copyright (C) 2004-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,12 +25,12 @@ CmdNetCheckSync::CmdNetCheckSync(uint32_t const dt, SyncCallback * const cb) : -Command (dt), m_callback(cb) +Command (dt), callback_(cb) {} void CmdNetCheckSync::execute (Widelands::Game &) { - m_callback->syncreport(); + callback_->syncreport(); } @@ -41,22 +41,22 @@ void NetworkTime::reset(int32_t const ntime) { - m_networktime = m_time = ntime; - m_lastframe = SDL_GetTicks(); - m_latency = 0; + networktime_ = time_ = ntime; + lastframe_ = SDL_GetTicks(); + latency_ = 0; } void NetworkTime::fastforward() { - m_time = m_networktime; - m_lastframe = SDL_GetTicks(); + time_ = networktime_; + lastframe_ = SDL_GetTicks(); } void NetworkTime::think(uint32_t const speed) { uint32_t const curtime = SDL_GetTicks(); - int32_t delta = curtime - m_lastframe; - m_lastframe = curtime; + int32_t delta = curtime - lastframe_; + lastframe_ = curtime; // in case weird things are happening with the system time // (e.g. debugger, extremely slow simulation, ...) @@ -67,55 +67,55 @@ delta = (delta * speed) / 1000; - int32_t const behind = m_networktime - m_time; + int32_t const behind = networktime_ - time_; // Play catch up uint32_t speedup = 0; - if (m_latency > static_cast<uint32_t>(10 * delta)) + if (latency_ > static_cast<uint32_t>(10 * delta)) // just try to kill as much of the latency as possible if we are that // far behind - speedup = m_latency / 3; - else if (m_latency > static_cast<uint32_t>(delta)) + speedup = latency_ / 3; + else if (latency_ > static_cast<uint32_t>(delta)) speedup = delta / 8; // speed up by 12.5% if (static_cast<int32_t>(delta + speedup) > behind) speedup = behind - delta; delta += speedup; - m_latency -= speedup; + latency_ -= speedup; if (delta > behind) delta = behind; - m_time += delta; + time_ += delta; } int32_t NetworkTime::time() const { - return m_time; + return time_; } int32_t NetworkTime::networktime() const { - return m_networktime; + return networktime_; } void NetworkTime::receive(int32_t const ntime) { - if (ntime < m_networktime) + if (ntime < networktime_) throw wexception("NetworkTime: Time appears to be running backwards."); - uint32_t const behind = m_networktime - m_time; + uint32_t const behind = networktime_ - time_; - m_latency = behind < m_latency ? behind : ((m_latency * 7) + behind) / 8; + latency_ = behind < latency_ ? behind : ((latency_ * 7) + behind) / 8; #if 0 log ("NetworkTime: New networktime %i (local time %i), behind %i, latency " "%u\n", - ntime, m_time, m_networktime - m_time, m_latency); + ntime, time_, networktime_ - time_, latency_); #endif - m_networktime = ntime; + networktime_ = ntime; } @@ -158,32 +158,32 @@ RecvPacket::RecvPacket (Deserializer & des) { - uint16_t const size = des.queue[0] << 8 | des.queue[1]; + uint16_t const size = des.queue_[0] << 8 | des.queue_[1]; // The following should be caught by Deserializer::read and ::avail - assert(des.queue.size() >= static_cast<size_t>(size)); + assert(des.queue_.size() >= static_cast<size_t>(size)); assert(size >= 2); - buffer.insert(buffer.end(), des.queue.begin() + 2, des.queue.begin() + size); - m_index = 0; + buffer.insert(buffer.end(), des.queue_.begin() + 2, des.queue_.begin() + size); + index_ = 0; - des.queue.erase(des.queue.begin(), des.queue.begin() + size); + des.queue_.erase(des.queue_.begin(), des.queue_.begin() + size); } size_t RecvPacket::data(void * const packet_data, size_t const bufsize) { - if (m_index + bufsize > buffer.size()) + if (index_ + bufsize > buffer.size()) throw wexception("Packet too short"); for (size_t read = 0; read < bufsize; ++read) - static_cast<uint8_t *>(packet_data)[read] = buffer[m_index++]; + static_cast<uint8_t *>(packet_data)[read] = buffer[index_++]; return bufsize; } bool RecvPacket::end_of_file() const { - return m_index < buffer.size(); + return index_ < buffer.size(); } bool Deserializer::read(TCPsocket sock) @@ -193,9 +193,9 @@ if (bytes <= 0) return false; - queue.insert(queue.end(), &buffer[0], &buffer[bytes]); + queue_.insert(queue_.end(), &buffer[0], &buffer[bytes]); - return queue.size() < 2 || 2 <= (queue[0] << 8 | queue[1]); + return queue_.size() < 2 || 2 <= (queue_[0] << 8 | queue_[1]); } /** @@ -203,14 +203,14 @@ */ bool Deserializer::avail() const { - if (queue.size() < 2) + if (queue_.size() < 2) return false; - const uint16_t size = queue[0] << 8 | queue[1]; + const uint16_t size = queue_[0] << 8 | queue_[1]; if (size < 2) return false; - return queue.size() >= static_cast<size_t>(size); + return queue_.size() >= static_cast<size_t>(size); } @@ -223,10 +223,10 @@ vsnprintf(buffer, sizeof(buffer), fmt, va); va_end(va); } - m_what = buffer; + what_ = buffer; } char const * DisconnectException::what() const noexcept { - return m_what.c_str(); + return what_.c_str(); } === modified file 'src/network/network.h' --- src/network/network.h 2016-01-18 19:35:25 +0000 +++ src/network/network.h 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2008, 2012, 2015 by the Widelands Development Team + * Copyright (C) 2004-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -53,7 +53,7 @@ Widelands::QueueCommandTypes id() const override {return Widelands::QueueCommandTypes::kNetCheckSync;} private: - SyncCallback * m_callback; + SyncCallback * callback_; }; @@ -79,13 +79,13 @@ void receive(int32_t ntime); private: - int32_t m_networktime; - int32_t m_time; + int32_t networktime_; + int32_t time_; - uint32_t m_lastframe; + uint32_t lastframe_; /// This is an attempt to measure how far behind the network time we are. - uint32_t m_latency; + uint32_t latency_; }; @@ -118,7 +118,7 @@ private: std::vector<uint8_t> buffer; - size_t m_index; + size_t index_; }; struct FilePart { @@ -150,7 +150,7 @@ private: friend struct RecvPacket; - std::vector<uint8_t> queue; + std::vector<uint8_t> queue_; }; @@ -169,7 +169,7 @@ const char * what() const noexcept override; private: - std::string m_what; + std::string what_; }; /** @@ -177,7 +177,7 @@ * should be terminated because an unexpected message got received that is disallowed by the protocol. */ struct ProtocolException : public std::exception { - explicit ProtocolException(uint8_t code) {m_what = code;} + explicit ProtocolException(uint8_t code) {what_ = code;} /// do NOT use!!! This exception shall only return the command number of the received message /// via \ref ProtocolException:number() @@ -186,10 +186,10 @@ } /// \returns the command number of the received message - virtual int number() const {return m_what;} + virtual int number() const {return what_;} private: // no uint8_t, as lexical_cast does not support that format - int m_what; + int what_; }; #endif // end of include guard: WL_NETWORK_NETWORK_H === modified file 'src/profile/profile.cc' --- src/profile/profile.cc 2015-11-28 22:29:26 +0000 +++ src/profile/profile.cc 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2006-2013 by the Widelands Development Team + * Copyright (C) 2002-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -77,17 +77,17 @@ Profile g_options(Profile::err_log); Section::Value::Value(const string & nname, const char * const nval) : - m_used(false), - m_name(nname) + used_(false), + name_(nname) { set_string(nval); } Section::Value::Value(const Section::Value & o) : - m_used(o.m_used), - m_name(o.m_name) + used_(o.used_), + name_(o.name_) { - set_string(o.m_value.get()); + set_string(o.value_.get()); } Section::Value::Value(Section::Value && o) @@ -113,18 +113,18 @@ bool Section::Value::is_used() const { - return m_used; + return used_; } void Section::Value::mark_used() { - m_used = true; + used_ = true; } int32_t Section::Value::get_int() const { char * endp; - long int const i = strtol(m_value.get(), &endp, 0); + long int const i = strtol(value_.get(), &endp, 0); if (*endp) throw wexception("%s: '%s' is not an integer", get_name(), get_string()); int32_t const result = i; @@ -138,7 +138,7 @@ uint32_t Section::Value::get_natural() const { char * endp; - long long int i = strtoll(m_value.get(), &endp, 0); + long long int i = strtoll(value_.get(), &endp, 0); if (*endp || i < 0) throw wexception("%s: '%s' is not natural", get_name(), get_string()); return i; @@ -148,7 +148,7 @@ uint32_t Section::Value::get_positive() const { char * endp; - long long int i = strtoll(m_value.get(), &endp, 0); + long long int i = strtoll(value_.get(), &endp, 0); if (*endp || i < 1) throw wexception("%s: '%s' is not positive", get_name(), get_string()); return i; @@ -158,10 +158,10 @@ bool Section::Value::get_bool() const { for (int32_t i = 0; i < TRUE_WORDS; ++i) - if (boost::iequals(m_value.get(), trueWords[i])) + if (boost::iequals(value_.get(), trueWords[i])) return true; for (int32_t i = 0; i < FALSE_WORDS; ++i) - if (boost::iequals(m_value.get(), falseWords[i])) + if (boost::iequals(value_.get(), falseWords[i])) return false; throw wexception("%s: '%s' is not a boolean value", get_name(), get_string()); @@ -170,7 +170,7 @@ Point Section::Value::get_point() const { - char * endp = m_value.get(); + char * endp = value_.get(); long int const x = strtol(endp, &endp, 0); long int const y = strtol(endp, &endp, 0); if (*endp) @@ -184,17 +184,17 @@ using std::copy; const auto len = strlen(value) + 1; - m_value.reset(new char[len]); - copy(value, value + len, m_value.get()); + value_.reset(new char[len]); + copy(value, value + len, value_.get()); } void swap(Section::Value & first, Section::Value & second) { using std::swap; - swap(first.m_name, second.m_name); - swap(first.m_value, second.m_value); - swap(first.m_used, second.m_used); + swap(first.name_, second.name_); + swap(first.value_, second.value_); + swap(first.used_, second.used_); } @@ -207,21 +207,21 @@ */ char const * Section::get_name() const { - return m_section_name.c_str(); + return section_name_.c_str(); } void Section::set_name(const std::string& name) { - m_section_name = name; + section_name_ = name; } Section::Section(Profile * const prof, const std::string & name) : -m_profile(prof), m_used(false), m_section_name(name) {} +profile_(prof), used_(false), section_name_(name) {} /** Section::is_used() * */ bool Section::is_used() const { - return m_used; + return used_; } /** Section::mark_used() @@ -229,7 +229,7 @@ */ void Section::mark_used() { - m_used = true; + used_ = true; } /** Section::check_used() @@ -238,9 +238,9 @@ */ void Section::check_used() const { - for (const Value& temp_value : m_values) { + for (const Value& temp_value : values_) { if (!temp_value.is_used()) { - m_profile->error + profile_->error ("Section [%s], key '%s' not used (did you spell the name " "correctly?)", get_name(), temp_value.get_name()); @@ -251,7 +251,7 @@ bool Section::has_val(char const * const name) const { - for (const Value& temp_value : m_values) { + for (const Value& temp_value : values_) { if (boost::iequals(temp_value.get_name(), name)) { return true; } @@ -268,7 +268,7 @@ */ Section::Value * Section::get_val(char const * const name) { - for (Value& value : m_values) { + for (Value& value : values_) { if (boost::iequals(value.get_name(), name)) { value.mark_used(); return &value; @@ -286,7 +286,7 @@ */ Section::Value * Section::get_next_val(char const * const name) { - for (Value& value : m_values) { + for (Value& value : values_) { if (!value.is_used()) { if (!name || boost::iequals(value.get_name(), name)) { value.mark_used(); @@ -300,7 +300,7 @@ Section::Value & Section::create_val (char const * const name, char const * const value) { - for (Value& temp_value : m_values) { + for (Value& temp_value : values_) { if (boost::iequals(temp_value.get_name(), name)) { temp_value.set_string(value); return temp_value; @@ -312,8 +312,8 @@ Section::Value & Section::create_val_duplicate (char const * const name, char const * const value) { - m_values.emplace_back(name, value); - return m_values.back(); + values_.emplace_back(name, value); + return values_.back(); } /** @@ -400,7 +400,7 @@ try { return v->get_int(); } catch (const std::exception & e) { - m_profile->error("%s", e.what()); + profile_->error("%s", e.what()); } return def; @@ -413,7 +413,7 @@ try { return v->get_natural(); } catch (const std::exception & e) { - m_profile->error("%s", e.what()); + profile_->error("%s", e.what()); return def; } else @@ -428,7 +428,7 @@ try { return v->get_positive(); } catch (const std::exception & e) { - m_profile->error("%s", e.what()); + profile_->error("%s", e.what()); return def; } } @@ -455,7 +455,7 @@ try { return v->get_bool(); } catch (const std::exception & e) { - m_profile->error("%s", e.what()); + profile_->error("%s", e.what()); } return def; @@ -540,7 +540,7 @@ */ Profile::Profile(int32_t error_level) { - m_error_level = error_level; + error_level_ = error_level; } /** @@ -553,7 +553,7 @@ (char const * const filename, char const * const global_section, int32_t const error_level) - : m_filename(filename), m_error_level(error_level) + : filename_(filename), error_level_(error_level) { read(filename, global_section); } @@ -563,7 +563,7 @@ char const * const global_section, const std::string & textdomain, int32_t const error_level) - : m_filename(filename), m_error_level(error_level) + : filename_(filename), error_level_(error_level) { i18n::Textdomain td(textdomain); read(filename, global_section); @@ -576,7 +576,7 @@ */ void Profile::error(char const * const fmt, ...) const { - if (m_error_level == err_ignore) + if (error_level_ == err_ignore) return; char buffer[256]; @@ -586,10 +586,10 @@ vsnprintf(buffer, sizeof(buffer), fmt, va); va_end(va); - if (m_error_level == err_log) - log("[%s] %s\n", m_filename.c_str(), buffer); + if (error_level_ == err_log) + log("[%s] %s\n", filename_.c_str(), buffer); else - throw wexception("[%s] %s", m_filename.c_str(), buffer); + throw wexception("[%s] %s", filename_.c_str(), buffer); } /** Profile::check_used() @@ -598,7 +598,7 @@ */ void Profile::check_used() const { - for (const Section& temp_section : m_sections) { + for (const Section& temp_section : sections_) { if (!temp_section.is_used()) { error ("Section [%s] not used (did you spell the name correctly?)", @@ -619,7 +619,7 @@ */ Section * Profile::get_section(const std::string & name) { - for (Section& temp_section : m_sections) { + for (Section& temp_section : sections_) { if (boost::iequals(temp_section.get_name(), name.c_str())) { temp_section.mark_used(); return &temp_section; @@ -638,7 +638,7 @@ return *s; else throw wexception - ("in \"%s\" section [%s] not found", m_filename.c_str(), name.c_str()); + ("in \"%s\" section [%s] not found", filename_.c_str(), name.c_str()); } /** @@ -662,7 +662,7 @@ */ Section * Profile::get_next_section(char const * const name) { - for (Section& section : m_sections) { + for (Section& section : sections_) { if (!section.is_used()) { if (!name || boost::iequals(section.get_name(), name)) { section.mark_used(); @@ -676,7 +676,7 @@ Section & Profile::create_section (char const * const name) { - for (Section& section : m_sections) { + for (Section& section : sections_) { if (boost::iequals(section.get_name(), name)) { return section; } @@ -687,8 +687,8 @@ Section & Profile::create_section_duplicate(char const * const name) { - m_sections.push_back(Section(this, name)); - return m_sections.back(); + sections_.push_back(Section(this, name)); + return sections_.back(); } @@ -875,13 +875,13 @@ ("# Automatically created by Widelands %s (%s)\n", build_id().c_str(), build_type().c_str()); - for (const Section& temp_section : m_sections) { + for (const Section& temp_section : sections_) { if (used_only && !temp_section.is_used()) continue; fw.print_f("\n[%s]\n", temp_section.get_name()); - for (const Section::Value& temp_value : temp_section.m_values) { + for (const Section::Value& temp_value : temp_section.values_) { if (used_only && !temp_value.is_used()) continue; === modified file 'src/profile/profile.h' --- src/profile/profile.h 2015-01-27 20:35:25 +0000 +++ src/profile/profile.h 2016-02-14 15:52:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2006-2013 by the Widelands Development Team + * Copyright (C) 2002-2016 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -68,7 +68,7 @@ Value & operator= (Value); Value & operator= (Value && other); - char const * get_name() const {return m_name.c_str();} + char const * get_name() const {return name_.c_str();} bool is_used() const; void mark_used(); @@ -77,8 +77,8 @@ uint32_t get_natural () const; uint32_t get_positive() const; bool get_bool() const; - char const * get_string() const {return m_value.get();} - char * get_string() {return m_value.get();} + char const * get_string() const {return value_.get();} + char * get_string() {return value_.get();} Point get_point () const; void set_string(char const *); @@ -86,9 +86,9 @@ friend void swap(Value& first, Value& second); private: - bool m_used; - string m_name; - std::unique_ptr<char []> m_value; + bool used_; + string name_; + std::unique_ptr<char []> value_; Value() = default; }; @@ -103,7 +103,7 @@ Value * get_val (char const * name); Value * get_next_val(char const * name = nullptr); - uint32_t get_num_values() const {return m_values.size();} + uint32_t get_nuvalue_s() const {return values_.size();} char const * get_name() const; void set_name(const std::string&); @@ -176,10 +176,10 @@ Value & create_val_duplicate(char const * name, char const * value); private: - Profile * m_profile; - bool m_used; - std::string m_section_name; - ValueList m_values; + Profile * profile_; + bool used_; + std::string section_name_; + ValueList values_; }; /** @@ -241,10 +241,11 @@ Section & create_section_duplicate(char const * name); private: - std::string m_filename; using SectionList = std::vector<Section>; - SectionList m_sections; - int32_t m_error_level; + + std::string filename_; + SectionList sections_; + int32_t error_level_; DISALLOW_COPY_AND_ASSIGN(Profile); };
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp