Merge lp:~widelands-dev/widelands/bug-1395278-network into lp:widelands
- bug-1395278-network
- Merge into trunk
Proposed by
Klaus Halfmann
Status: | Merged |
---|---|
Merged at revision: | 7831 |
Proposed branch: | lp:~widelands-dev/widelands/bug-1395278-network |
Merge into: | lp:widelands |
Diff against target: |
2159 lines (+440/-430) 10 files modified
src/network/internet_gaming.cc (+193/-184) src/network/internet_gaming.h (+40/-39) src/network/netclient.cc (+34/-34) src/network/netclient.h (+4/-5) src/network/nethost.cc (+43/-43) src/network/nethost.h (+8/-8) src/network/network.cc (+38/-38) src/network/network.h (+12/-12) src/profile/profile.cc (+52/-52) src/profile/profile.h (+16/-15) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-1395278-network |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+285990@code.launchpad.net |
Commit message
Refactored member variable names in src/network and src/profile.
Description of the change
Make member variables like <member>_ mostly in network.
To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote : | # |
Revision history for this message
GunChleoc (gunchleoc) wrote : | # |
I have fixed a few cases of overgeneration, this is good to go now.
The potential memory leak should be investigated. I am not familiar with the networking code, but maybe we could use a unique_ptr there?
@bunnybot merge
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/network/internet_gaming.cc' |
2 | --- src/network/internet_gaming.cc 2016-02-06 11:11:24 +0000 |
3 | +++ src/network/internet_gaming.cc 2016-02-15 12:35:46 +0000 |
4 | @@ -1,5 +1,5 @@ |
5 | /* |
6 | - * Copyright (C) 2004-2006, 2008-2009, 2012-2013 by the Widelands Development Team |
7 | + * Copyright (C) 2004-2016 by the Widelands Development Team |
8 | * |
9 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License |
11 | @@ -35,56 +35,56 @@ |
12 | /// Private constructor by purpose: NEVER call directly. Always call InternetGaming::ref(), this will ensure |
13 | /// that only one instance is running at time. |
14 | InternetGaming::InternetGaming() : |
15 | - m_sock (nullptr), |
16 | - m_sockset (nullptr), |
17 | - m_state (OFFLINE), |
18 | - m_reg (false), |
19 | - m_port (INTERNET_GAMING_PORT), |
20 | - m_clientrights (INTERNET_CLIENT_UNREGISTERED), |
21 | - m_gameip (""), |
22 | - clientupdateonmetaserver (true), |
23 | - gameupdateonmetaserver (true), |
24 | - clientupdate (false), |
25 | - gameupdate (false), |
26 | - time_offset (0), |
27 | - waittimeout (std::numeric_limits<int32_t>::max()), |
28 | - lastping (time(nullptr)) |
29 | + sock_ (nullptr), |
30 | + sockset_ (nullptr), |
31 | + state_ (OFFLINE), |
32 | + reg_ (false), |
33 | + port_ (INTERNET_GAMING_PORT), |
34 | + clientrights_ (INTERNET_CLIENT_UNREGISTERED), |
35 | + gameip_ (""), |
36 | + clientupdateonmetaserver_(true), |
37 | + gameupdateonmetaserver_ (true), |
38 | + clientupdate_ (false), |
39 | + gameupdate_ (false), |
40 | + time_offset_ (0), |
41 | + waittimeout_ (std::numeric_limits<int32_t>::max()), |
42 | + lastping_ (time(nullptr)) |
43 | { |
44 | // Fill the list of possible messages from the server |
45 | InternetGamingMessages::fill_map(); |
46 | |
47 | // Set connection tracking variables to 0 |
48 | - lastbrokensocket[0] = 0; |
49 | - lastbrokensocket[1] = 0; |
50 | + lastbrokensocket_[0] = 0; |
51 | + lastbrokensocket_[1] = 0; |
52 | |
53 | } |
54 | |
55 | /// resets all stored variables without the chat messages for a clean new login (not relogin) |
56 | void InternetGaming::reset() { |
57 | - m_sock = nullptr; |
58 | - m_sockset = nullptr; |
59 | - m_state = OFFLINE; |
60 | - m_pwd = ""; |
61 | - m_reg = false; |
62 | - m_meta = INTERNET_GAMING_METASERVER; |
63 | - m_port = INTERNET_GAMING_PORT; |
64 | - m_clientname = ""; |
65 | - m_clientrights = INTERNET_CLIENT_UNREGISTERED; |
66 | - m_gamename = ""; |
67 | - m_gameip = ""; |
68 | - clientupdateonmetaserver = true; |
69 | - gameupdateonmetaserver = true; |
70 | - clientupdate = false; |
71 | - gameupdate = false; |
72 | - time_offset = 0; |
73 | - waitcmd = ""; |
74 | - waittimeout = std::numeric_limits<int32_t>::max(); |
75 | - lastbrokensocket[0] = 0; |
76 | - lastbrokensocket[1] = 0; |
77 | - lastping = time(nullptr); |
78 | + sock_ = nullptr; |
79 | + sockset_ = nullptr; |
80 | + state_ = OFFLINE; |
81 | + pwd_ = ""; |
82 | + reg_ = false; |
83 | + meta_ = INTERNET_GAMING_METASERVER; |
84 | + port_ = INTERNET_GAMING_PORT; |
85 | + clientname_ = ""; |
86 | + clientrights_ = INTERNET_CLIENT_UNREGISTERED; |
87 | + gamename_ = ""; |
88 | + gameip_ = ""; |
89 | + clientupdateonmetaserver_= true; |
90 | + gameupdateonmetaserver_ = true; |
91 | + clientupdate_ = false; |
92 | + gameupdate_ = false; |
93 | + time_offset_ = 0; |
94 | + waitcmd_ = ""; |
95 | + waittimeout_ = std::numeric_limits<int32_t>::max(); |
96 | + lastbrokensocket_[0] = 0; |
97 | + lastbrokensocket_[1] = 0; |
98 | + lastping_ = time(nullptr); |
99 | |
100 | - clientlist.clear(); |
101 | - gamelist.clear(); |
102 | + clientlist_.clear(); |
103 | + gamelist_.clear(); |
104 | } |
105 | |
106 | |
107 | @@ -104,18 +104,18 @@ |
108 | // First of all try to connect to the metaserver |
109 | log("InternetGaming: Connecting to the metaserver.\n"); |
110 | IPaddress peer; |
111 | - if (hostent * const he = gethostbyname(m_meta.c_str())) { |
112 | + if (hostent * const he = gethostbyname(meta_.c_str())) { |
113 | peer.host = (reinterpret_cast<in_addr *>(he->h_addr_list[0]))->s_addr; |
114 | DIAG_OFF("-Wold-style-cast") |
115 | - peer.port = htons(m_port); |
116 | + peer.port = htons(port_); |
117 | DIAG_ON("-Wold-style-cast") |
118 | } else |
119 | throw WLWarning |
120 | (_("Connection problem"), "%s", _("Widelands could not connect to the metaserver.")); |
121 | |
122 | - SDLNet_ResolveHost (&peer, m_meta.c_str(), m_port); |
123 | - m_sock = SDLNet_TCP_Open(&peer); |
124 | - if (m_sock == nullptr) |
125 | + SDLNet_ResolveHost (&peer, meta_.c_str(), port_); |
126 | + sock_ = SDLNet_TCP_Open(&peer); |
127 | + if (sock_ == nullptr) |
128 | throw WLWarning |
129 | (_("Could not establish connection to host"), |
130 | _ |
131 | @@ -123,11 +123,11 @@ |
132 | "Either there was no metaserver running at the supposed port or\n" |
133 | "your network setup is broken.")); |
134 | |
135 | - m_sockset = SDLNet_AllocSocketSet(1); |
136 | - SDLNet_TCP_AddSocket (m_sockset, m_sock); |
137 | + sockset_ = SDLNet_AllocSocketSet(1); |
138 | + SDLNet_TCP_AddSocket (sockset_, sock_); |
139 | |
140 | // Of course not 100% true, but we just care about an answer at all, so we reset this tracker |
141 | - lastping = time(nullptr); |
142 | + lastping_ = time(nullptr); |
143 | } |
144 | |
145 | |
146 | @@ -136,12 +136,12 @@ |
147 | bool InternetGaming::login |
148 | (const std::string & nick, const std::string & pwd, bool reg, const std::string & meta, uint32_t port) |
149 | { |
150 | - assert(m_state == OFFLINE); |
151 | + assert(state_ == OFFLINE); |
152 | |
153 | - m_pwd = pwd; |
154 | - m_reg = reg; |
155 | - m_meta = meta; |
156 | - m_port = port; |
157 | + pwd_ = pwd; |
158 | + reg_ = reg; |
159 | + meta_ = meta; |
160 | + port_ = port; |
161 | |
162 | initialize_connection(); |
163 | |
164 | @@ -155,17 +155,17 @@ |
165 | s.string(bool2str(reg)); |
166 | if (reg) |
167 | s.string(pwd); |
168 | - s.send(m_sock); |
169 | + s.send(sock_); |
170 | |
171 | // Now let's see, whether the metaserver is answering |
172 | uint32_t const secs = time(nullptr); |
173 | - m_state = CONNECTING; |
174 | + state_ = CONNECTING; |
175 | while (INTERNET_GAMING_TIMEOUT > time(nullptr) - secs) { |
176 | handle_metaserver_communication(); |
177 | // Check if we are a step further... if yes handle_packet has taken care about all the |
178 | // paperwork, so we put our feet up and just return. ;) |
179 | - if (m_state != CONNECTING) { |
180 | - if (m_state == LOBBY) { |
181 | + if (state_ != CONNECTING) { |
182 | + if (state_ == LOBBY) { |
183 | format_and_add_chat("", "", true, _("For hosting a game, please take a look at the notes at:")); |
184 | format_and_add_chat("", "", true, "http://wl.widelands.org/wiki/InternetGaming"); |
185 | return true; |
186 | @@ -194,22 +194,22 @@ |
187 | SendPacket s; |
188 | s.string(IGPCMD_RELOGIN); |
189 | s.string(boost::lexical_cast<std::string>(INTERNET_GAMING_PROTOCOL_VERSION)); |
190 | - s.string(m_clientname); |
191 | + s.string(clientname_); |
192 | s.string(build_id()); |
193 | - s.string(bool2str(m_reg)); |
194 | - if (m_reg) |
195 | - s.string(m_pwd); |
196 | - s.send(m_sock); |
197 | + s.string(bool2str(reg_)); |
198 | + if (reg_) |
199 | + s.string(pwd_); |
200 | + s.send(sock_); |
201 | |
202 | // Now let's see, whether the metaserver is answering |
203 | uint32_t const secs = time(nullptr); |
204 | - m_state = CONNECTING; |
205 | + state_ = CONNECTING; |
206 | while (INTERNET_GAMING_TIMEOUT > time(nullptr) - secs) { |
207 | handle_metaserver_communication(); |
208 | // Check if we are a step further... if yes handle_packet has taken care about all the |
209 | // paperwork, so we put our feet up and just return. ;) |
210 | - if (m_state != CONNECTING) { |
211 | - if (m_state == LOBBY) { |
212 | + if (state_ != CONNECTING) { |
213 | + if (state_ == LOBBY) { |
214 | break; |
215 | } else if (error()) |
216 | return false; |
217 | @@ -222,13 +222,13 @@ |
218 | } |
219 | |
220 | // Client is reconnected, so let's try resend the timeouted command. |
221 | - if (waitcmd == IGPCMD_GAME_CONNECT) |
222 | - join_game(m_gamename); |
223 | - else if (waitcmd == IGPCMD_GAME_OPEN) { |
224 | - m_state = IN_GAME; |
225 | + if (waitcmd_ == IGPCMD_GAME_CONNECT) |
226 | + join_game(gamename_); |
227 | + else if (waitcmd_ == IGPCMD_GAME_OPEN) { |
228 | + state_ = IN_GAME; |
229 | open_game(); |
230 | - } else if (waitcmd == IGPCMD_GAME_START) { |
231 | - m_state = IN_GAME; |
232 | + } else if (waitcmd_ == IGPCMD_GAME_START) { |
233 | + state_ = IN_GAME; |
234 | set_game_playing(); |
235 | } |
236 | |
237 | @@ -245,7 +245,7 @@ |
238 | SendPacket s; |
239 | s.string(IGPCMD_DISCONNECT); |
240 | s.string(msgcode); |
241 | - s.send(m_sock); |
242 | + s.send(sock_); |
243 | |
244 | const std::string & msg = InternetGamingMessages::get_message(msgcode); |
245 | log("InternetGaming: logout(%s)\n", msg.c_str()); |
246 | @@ -255,46 +255,53 @@ |
247 | } |
248 | |
249 | |
250 | +/** |
251 | + * Handle situation when reading from socket failed. |
252 | + */ |
253 | +void InternetGaming::handle_failed_read() { |
254 | + set_error(); |
255 | + const std::string & msg = InternetGamingMessages::get_message("CONNECTION_LOST"); |
256 | + log("InternetGaming: Error: %s\n", msg.c_str()); |
257 | + format_and_add_chat("", "", true, msg); |
258 | + |
259 | + // Check how much time passed since the socket broke the last time |
260 | + // Maybe something is completely wrong at the moment? |
261 | + // At least it seems to be, if the socket broke three times in the last 10 seconds... |
262 | + time_t now = time(nullptr); |
263 | + if ((now - lastbrokensocket_[1] < 10) && (now - lastbrokensocket_[0] < 10)) { |
264 | + reset(); |
265 | + set_error(); |
266 | + return; |
267 | + } |
268 | + lastbrokensocket_[1] = lastbrokensocket_[0]; |
269 | + lastbrokensocket_[0] = now; |
270 | + |
271 | + // Try to relogin |
272 | + if (!relogin()) { |
273 | + // Do not try to relogin again automatically. |
274 | + reset(); |
275 | + set_error(); |
276 | + } |
277 | +} |
278 | + |
279 | |
280 | /// handles all communication between the metaserver and the client |
281 | void InternetGaming::handle_metaserver_communication() { |
282 | if (error()) |
283 | return; |
284 | try { |
285 | - while (m_sock != nullptr && SDLNet_CheckSockets(m_sockset, 0) > 0) { |
286 | + while (sock_ != nullptr && SDLNet_CheckSockets(sockset_, 0) > 0) { |
287 | // Perform only one read operation, then process all packets |
288 | // from this read. This ensures that we process DISCONNECT |
289 | // packets that are followed immediately by connection close. |
290 | - if (!m_deserializer.read(m_sock)) { |
291 | - set_error(); |
292 | - const std::string & msg = InternetGamingMessages::get_message("CONNECTION_LOST"); |
293 | - log("InternetGaming: Error: %s\n", msg.c_str()); |
294 | - format_and_add_chat("", "", true, msg); |
295 | - |
296 | - // Check how much time passed since the socket broke the last time |
297 | - // Maybe something is completely wrong at the moment? |
298 | - // At least it seems to be, if the socket broke three times in the last 10 seconds... |
299 | - time_t now = time(nullptr); |
300 | - if ((now - lastbrokensocket[1] < 10) && (now - lastbrokensocket[0] < 10)) { |
301 | - reset(); |
302 | - set_error(); |
303 | - return; |
304 | - } |
305 | - lastbrokensocket[1] = lastbrokensocket[0]; |
306 | - lastbrokensocket[0] = now; |
307 | - |
308 | - // Try to relogin |
309 | - if (!relogin()) { |
310 | - // Do not try to relogin again automatically. |
311 | - reset(); |
312 | - set_error(); |
313 | - } |
314 | + if (!deserializer_.read(sock_)) { |
315 | + handle_failed_read(); |
316 | return; |
317 | } |
318 | |
319 | // Process all the packets from the last read |
320 | - while (m_sock && m_deserializer.avail()) { |
321 | - RecvPacket packet(m_deserializer); |
322 | + while (sock_ && deserializer_.avail()) { |
323 | + RecvPacket packet(deserializer_); |
324 | handle_packet(packet); |
325 | } |
326 | } |
327 | @@ -305,31 +312,31 @@ |
328 | set_error(); |
329 | } |
330 | |
331 | - if (m_state == LOBBY) { |
332 | + if (state_ == LOBBY) { |
333 | // client is in the lobby and therefore we want realtime information updates |
334 | - if (clientupdateonmetaserver) { |
335 | + if (clientupdateonmetaserver_) { |
336 | SendPacket s; |
337 | s.string(IGPCMD_CLIENTS); |
338 | - s.send(m_sock); |
339 | + s.send(sock_); |
340 | |
341 | - clientupdateonmetaserver = false; |
342 | + clientupdateonmetaserver_ = false; |
343 | } |
344 | |
345 | - if (gameupdateonmetaserver) { |
346 | + if (gameupdateonmetaserver_) { |
347 | SendPacket s; |
348 | s.string(IGPCMD_GAMES); |
349 | - s.send(m_sock); |
350 | + s.send(sock_); |
351 | |
352 | - gameupdateonmetaserver = false; |
353 | + gameupdateonmetaserver_ = false; |
354 | } |
355 | } |
356 | |
357 | - if (!waitcmd.empty()) { |
358 | + if (!waitcmd_.empty()) { |
359 | // Check if timeout is reached |
360 | time_t now = time(nullptr); |
361 | - if (now > waittimeout) { |
362 | + if (now > waittimeout_) { |
363 | set_error(); |
364 | - waittimeout = std::numeric_limits<int32_t>::max(); |
365 | + waittimeout_ = std::numeric_limits<int32_t>::max(); |
366 | log("InternetGaming: reached a timeout for an awaited answer of the metaserver!\n"); |
367 | if (!relogin()) { |
368 | // Do not try to relogin again automatically. |
369 | @@ -341,7 +348,7 @@ |
370 | |
371 | // Check connection to the metaserver |
372 | // Was a ping received in the last 4 minutes? |
373 | - if (time(nullptr) - lastping > 240) { |
374 | + if (time(nullptr) - lastping_ > 240) { |
375 | // Try to relogin |
376 | set_error(); |
377 | if (!relogin()) { |
378 | @@ -376,19 +383,19 @@ |
379 | } |
380 | |
381 | // Are we already online? |
382 | - if (m_state == CONNECTING) { |
383 | + if (state_ == CONNECTING) { |
384 | if (cmd == IGPCMD_LOGIN) { |
385 | // Clients request to login was granted |
386 | - m_clientname = packet.string(); |
387 | - m_clientrights = packet.string(); |
388 | - m_state = LOBBY; |
389 | - log("InternetGaming: Client %s logged in.\n", m_clientname.c_str()); |
390 | + clientname_ = packet.string(); |
391 | + clientrights_ = packet.string(); |
392 | + state_ = LOBBY; |
393 | + log("InternetGaming: Client %s logged in.\n", clientname_.c_str()); |
394 | return; |
395 | |
396 | } else if (cmd == IGPCMD_RELOGIN) { |
397 | // Clients request to relogin was granted |
398 | - m_state = LOBBY; |
399 | - log("InternetGaming: Client %s relogged in.\n", m_clientname.c_str()); |
400 | + state_ = LOBBY; |
401 | + log("InternetGaming: Client %s relogged in.\n", clientname_.c_str()); |
402 | format_and_add_chat("", "", true, _("Successfully reconnected to the metaserver!")); |
403 | return; |
404 | |
405 | @@ -429,17 +436,17 @@ |
406 | |
407 | else if (cmd == IGPCMD_TIME) { |
408 | // Client received the server time |
409 | - time_offset = boost::lexical_cast<int>(packet.string()) - time(nullptr); |
410 | + time_offset_ = boost::lexical_cast<int>(packet.string()) - time(nullptr); |
411 | log |
412 | (ngettext |
413 | ("InternetGaming: Server time offset is %u second.", |
414 | - "InternetGaming: Server time offset is %u seconds.", time_offset), |
415 | - time_offset); |
416 | + "InternetGaming: Server time offset is %u seconds.", time_offset_), |
417 | + time_offset_); |
418 | std::string temp = |
419 | (boost::format |
420 | (ngettext("Server time offset is %u second.", |
421 | - "Server time offset is %u seconds.", time_offset)) |
422 | - % time_offset) |
423 | + "Server time offset is %u seconds.", time_offset_)) |
424 | + % time_offset_) |
425 | .str(); |
426 | format_and_add_chat("", "", true, temp); |
427 | } |
428 | @@ -448,9 +455,9 @@ |
429 | // Client received a PING and should immediately PONG as requested |
430 | SendPacket s; |
431 | s.string(IGPCMD_PONG); |
432 | - s.send(m_sock); |
433 | + s.send(sock_); |
434 | |
435 | - lastping = time(nullptr); |
436 | + lastping_ = time(nullptr); |
437 | } |
438 | |
439 | else if (cmd == IGPCMD_CHAT) { |
440 | @@ -465,27 +472,27 @@ |
441 | bool personal = type == "private"; |
442 | bool system = type == "system"; |
443 | |
444 | - format_and_add_chat(sender, personal ? m_clientname : "", system, message); |
445 | + format_and_add_chat(sender, personal ? clientname_ : "", system, message); |
446 | } |
447 | |
448 | else if (cmd == IGPCMD_GAMES_UPDATE) { |
449 | // Client received a note, that the list of games was changed |
450 | log("InternetGaming: Game update on metaserver.\n"); |
451 | - gameupdateonmetaserver = true; |
452 | + gameupdateonmetaserver_ = true; |
453 | } |
454 | |
455 | else if (cmd == IGPCMD_GAMES) { |
456 | // Client received the new list of games |
457 | uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff; |
458 | - std::vector<InternetGame> old = gamelist; |
459 | - gamelist.clear(); |
460 | + std::vector<InternetGame> old = gamelist_; |
461 | + gamelist_.clear(); |
462 | log("InternetGaming: Received a game list update with %u items.\n", number); |
463 | for (uint8_t i = 0; i < number; ++i) { |
464 | InternetGame * ing = new InternetGame(); |
465 | ing->name = packet.string(); |
466 | ing->build_id = packet.string(); |
467 | ing->connectable = str2bool(packet.string()); |
468 | - gamelist.push_back(*ing); |
469 | + gamelist_.push_back(*ing); |
470 | |
471 | bool found = false; |
472 | for (std::vector<InternetGame>::size_type j = 0; j < old.size(); ++j) |
473 | @@ -507,20 +514,20 @@ |
474 | format_and_add_chat |
475 | ("", "", true, (boost::format(_("The game %s has been closed")) % old[i].name).str()); |
476 | |
477 | - gameupdate = true; |
478 | + gameupdate_ = true; |
479 | } |
480 | |
481 | else if (cmd == IGPCMD_CLIENTS_UPDATE) { |
482 | // Client received a note, that the list of clients was changed |
483 | log("InternetGaming: Client update on metaserver.\n"); |
484 | - clientupdateonmetaserver = true; |
485 | + clientupdateonmetaserver_ = true; |
486 | } |
487 | |
488 | else if (cmd == IGPCMD_CLIENTS) { |
489 | // Client received the new list of clients |
490 | uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff; |
491 | - std::vector<InternetClient> old = clientlist; |
492 | - clientlist.clear(); |
493 | + std::vector<InternetClient> old = clientlist_; |
494 | + clientlist_.clear(); |
495 | log("InternetGaming: Received a client list update with %u items.\n", number); |
496 | for (uint8_t i = 0; i < number; ++i) { |
497 | InternetClient * inc = new InternetClient(); |
498 | @@ -529,7 +536,7 @@ |
499 | inc->game = packet.string(); |
500 | inc->type = packet.string(); |
501 | inc->points = packet.string(); |
502 | - clientlist.push_back(*inc); |
503 | + clientlist_.push_back(*inc); |
504 | |
505 | bool found = old.empty(); // do not show all clients, if this instance is the actual change |
506 | for (std::vector<InternetClient>::size_type j = 0; j < old.size(); ++j) |
507 | @@ -551,28 +558,28 @@ |
508 | format_and_add_chat |
509 | ("", "", true, (boost::format(_("%s left the lobby")) % old[i].name).str()); |
510 | |
511 | - clientupdate = true; |
512 | + clientupdate_ = true; |
513 | } |
514 | |
515 | else if (cmd == IGPCMD_GAME_OPEN) { |
516 | // Client received the acknowledgment, that the game was opened |
517 | - assert (waitcmd == IGPCMD_GAME_OPEN); |
518 | - waitcmd = ""; |
519 | + assert (waitcmd_ == IGPCMD_GAME_OPEN); |
520 | + waitcmd_ = ""; |
521 | } |
522 | |
523 | else if (cmd == IGPCMD_GAME_CONNECT) { |
524 | // Client received the ip for the game it wants to join |
525 | - assert (waitcmd == IGPCMD_GAME_CONNECT); |
526 | - waitcmd = ""; |
527 | + assert (waitcmd_ == IGPCMD_GAME_CONNECT); |
528 | + waitcmd_ = ""; |
529 | // save the received ip, so the client cann connect to the game |
530 | - m_gameip = packet.string(); |
531 | - log("InternetGaming: Received ip of the game to join: %s.\n", m_gameip.c_str()); |
532 | + gameip_ = packet.string(); |
533 | + log("InternetGaming: Received ip of the game to join: %s.\n", gameip_.c_str()); |
534 | } |
535 | |
536 | else if (cmd == IGPCMD_GAME_START) { |
537 | // Client received the acknowledgment, that the game was started |
538 | - assert (waitcmd == IGPCMD_GAME_START); |
539 | - waitcmd = ""; |
540 | + assert (waitcmd_ == IGPCMD_GAME_START); |
541 | + waitcmd_ = ""; |
542 | } |
543 | |
544 | else if (cmd == IGPCMD_ERROR) { |
545 | @@ -597,7 +604,7 @@ |
546 | // Something went wrong with the newly opened game |
547 | message = InternetGamingMessages::get_message(reason); |
548 | // we got our answer, so no need to wait anymore |
549 | - waitcmd = ""; |
550 | + waitcmd_ = ""; |
551 | } |
552 | message = (boost::format(_("ERROR: %s")) % message).str(); |
553 | |
554 | @@ -623,7 +630,7 @@ |
555 | /// \returns the ip of the game the client is on or wants to join (or the client is hosting) |
556 | /// or 0, if no ip available. |
557 | const std::string & InternetGaming::ip() { |
558 | - return m_gameip; |
559 | + return gameip_; |
560 | } |
561 | |
562 | |
563 | @@ -636,35 +643,35 @@ |
564 | SendPacket s; |
565 | s.string(IGPCMD_GAME_CONNECT); |
566 | s.string(gamename); |
567 | - s.send(m_sock); |
568 | - m_gamename = gamename; |
569 | - log("InternetGaming: Client tries to join a game with the name %s\n", m_gamename.c_str()); |
570 | - m_state = IN_GAME; |
571 | + s.send(sock_); |
572 | + gamename_ = gamename; |
573 | + log("InternetGaming: Client tries to join a game with the name %s\n", gamename_.c_str()); |
574 | + state_ = IN_GAME; |
575 | |
576 | |
577 | // From now on we wait for a reply from the metaserver |
578 | - waitcmd = IGPCMD_GAME_CONNECT; |
579 | - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
580 | + waitcmd_ = IGPCMD_GAME_CONNECT; |
581 | + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
582 | } |
583 | |
584 | |
585 | |
586 | -/// called by a client to open a new game with name m_gamename |
587 | +/// called by a client to open a new game with name gamename_ |
588 | void InternetGaming::open_game() { |
589 | if (!logged_in()) |
590 | return; |
591 | |
592 | SendPacket s; |
593 | s.string(IGPCMD_GAME_OPEN); |
594 | - s.string(m_gamename); |
595 | + s.string(gamename_); |
596 | s.string("1024"); // Used to be maxclients, no longer used. |
597 | - s.send(m_sock); |
598 | - log("InternetGaming: Client opened a game with the name %s.\n", m_gamename.c_str()); |
599 | - m_state = IN_GAME; |
600 | + s.send(sock_); |
601 | + log("InternetGaming: Client opened a game with the name %s.\n", gamename_.c_str()); |
602 | + state_ = IN_GAME; |
603 | |
604 | // From now on we wait for a reply from the metaserver |
605 | - waitcmd = IGPCMD_GAME_OPEN; |
606 | - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
607 | + waitcmd_ = IGPCMD_GAME_OPEN; |
608 | + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
609 | } |
610 | |
611 | |
612 | @@ -676,12 +683,12 @@ |
613 | |
614 | SendPacket s; |
615 | s.string(IGPCMD_GAME_START); |
616 | - s.send(m_sock); |
617 | - log("InternetGaming: Client announced the start of the game %s.\n", m_gamename.c_str()); |
618 | + s.send(sock_); |
619 | + log("InternetGaming: Client announced the start of the game %s.\n", gamename_.c_str()); |
620 | |
621 | // From now on we wait for a reply from the metaserver |
622 | - waitcmd = IGPCMD_GAME_START; |
623 | - waittimeout = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
624 | + waitcmd_ = IGPCMD_GAME_START; |
625 | + waittimeout_ = time(nullptr) + INTERNET_GAMING_TIMEOUT; |
626 | } |
627 | |
628 | |
629 | @@ -694,21 +701,21 @@ |
630 | |
631 | SendPacket s; |
632 | s.string(IGPCMD_GAME_DISCONNECT); |
633 | - s.send(m_sock); |
634 | - |
635 | - m_gameip = ""; |
636 | - m_state = LOBBY; |
637 | - |
638 | - log("InternetGaming: Client announced the disconnect from the game %s.\n", m_gamename.c_str()); |
639 | + s.send(sock_); |
640 | + |
641 | + gameip_ = ""; |
642 | + state_ = LOBBY; |
643 | + |
644 | + log("InternetGaming: Client announced the disconnect from the game %s.\n", gamename_.c_str()); |
645 | } |
646 | |
647 | |
648 | |
649 | /// \returns whether the local gamelist was updated |
650 | -/// \note this function resets gameupdate. So if you call it, please really handle the output. |
651 | +/// \note this function resets gameupdate_. So if you call it, please really handle the output. |
652 | bool InternetGaming::update_for_games() { |
653 | - bool temp = gameupdate; |
654 | - gameupdate = false; |
655 | + bool temp = gameupdate_; |
656 | + gameupdate_ = false; |
657 | return temp; |
658 | } |
659 | |
660 | @@ -716,16 +723,17 @@ |
661 | |
662 | /// \returns the tables in the room, if no error occured |
663 | const std::vector<InternetGame> & InternetGaming::games() { |
664 | - return error() ? * (new std::vector<InternetGame>()) : gamelist; |
665 | + // TODO(Hasi50): in case of error() this is a memory leak? should return some unmodifiable singleton. |
666 | + return error() ? * (new std::vector<InternetGame>()) : gamelist_; |
667 | } |
668 | |
669 | |
670 | |
671 | -/// \returns whether the local clientlist was updated |
672 | -/// \note this function resets clientupdate. So if you call it, please really handle the output. |
673 | +/// \returns whether the local clientlist_ was updated |
674 | +/// \note this function resets clientupdate_. So if you call it, please really handle the output. |
675 | bool InternetGaming::update_for_clients() { |
676 | - bool temp = clientupdate; |
677 | - clientupdate = false; |
678 | + bool temp = clientupdate_; |
679 | + clientupdate_ = false; |
680 | return temp; |
681 | } |
682 | |
683 | @@ -733,7 +741,8 @@ |
684 | |
685 | /// \returns the players in the room, if no error occured |
686 | const std::vector<InternetClient> & InternetGaming::clients() { |
687 | - return error() ? * (new std::vector<InternetClient>()) : clientlist; |
688 | + // TODO(Hasi50): in case of error() this is a memory leak? should return some unmodifiable singleton. |
689 | + return error() ? * (new std::vector<InternetClient>()) : clientlist_; |
690 | } |
691 | |
692 | |
693 | @@ -760,9 +769,9 @@ |
694 | s.string(msg.substr(space + 1)); // message |
695 | s.string(msg.substr(1, space - 1)); // recipient |
696 | |
697 | - format_and_add_chat(m_clientname, msg.substr(1, space - 1), false, msg.substr(space + 1)); |
698 | + format_and_add_chat(clientname_, msg.substr(1, space - 1), false, msg.substr(space + 1)); |
699 | |
700 | - } else if (m_clientrights == INTERNET_CLIENT_SUPERUSER && msg.size() && *msg.begin() == '/') { |
701 | + } else if (clientrights_ == INTERNET_CLIENT_SUPERUSER && msg.size() && *msg.begin() == '/') { |
702 | // This is either a /me command, a super user command, or well... just a chat message beginning |
703 | // with a "/" - let's see... |
704 | |
705 | @@ -799,14 +808,14 @@ |
706 | } |
707 | // send the request to change the motd |
708 | m.string(arg); |
709 | - m.send(m_sock); |
710 | + m.send(sock_); |
711 | return; |
712 | } else if (cmd == "announcement") { |
713 | // send the request to change the motd |
714 | SendPacket m; |
715 | m.string(IGPCMD_ANNOUNCEMENT); |
716 | m.string(arg); |
717 | - m.send(m_sock); |
718 | + m.send(sock_); |
719 | return; |
720 | } else |
721 | // let everything else pass |
722 | @@ -818,7 +827,7 @@ |
723 | s.string(""); |
724 | } |
725 | |
726 | - s.send(m_sock); |
727 | + s.send(sock_); |
728 | } |
729 | |
730 | /** |
731 | @@ -858,9 +867,9 @@ |
732 | c.recipient = to; |
733 | |
734 | receive(c); |
735 | - if (system && (m_state == IN_GAME)) { |
736 | + if (system && (state_ == IN_GAME)) { |
737 | // Save system chat messages seperately as well, so the nethost can import and show them in game; |
738 | c.msg = "METASERVER: " + msg; |
739 | - ingame_system_chat.push_back(c); |
740 | + ingame_system_chat_.push_back(c); |
741 | } |
742 | } |
743 | |
744 | === modified file 'src/network/internet_gaming.h' |
745 | --- src/network/internet_gaming.h 2015-01-21 20:57:11 +0000 |
746 | +++ src/network/internet_gaming.h 2016-02-15 12:35:46 +0000 |
747 | @@ -1,5 +1,5 @@ |
748 | /* |
749 | - * Copyright (C) 2004-2006, 2008-2009, 2012-2013 by the Widelands Development Team |
750 | + * Copyright (C) 2004-2016 by the Widelands Development Team |
751 | * |
752 | * This program is free software; you can redistribute it and/or |
753 | * modify it under the terms of the GNU General Public License |
754 | @@ -70,9 +70,9 @@ |
755 | void logout(const std::string & msgcode = "CONNECTION_CLOSED"); |
756 | |
757 | /// \returns whether the client is logged in |
758 | - bool logged_in() {return (m_state == LOBBY) || (m_state == CONNECTING) || (m_state == IN_GAME);} |
759 | - bool error() {return (m_state == COMMUNICATION_ERROR);} |
760 | - void set_error() {m_state = COMMUNICATION_ERROR; gameupdate = true; clientupdate = true;} |
761 | + bool logged_in() {return (state_ == LOBBY) || (state_ == CONNECTING) || (state_ == IN_GAME);} |
762 | + bool error() {return (state_ == COMMUNICATION_ERROR);} |
763 | + void set_error() {state_ = COMMUNICATION_ERROR; gameupdate_ = true; clientupdate_ = true;} |
764 | |
765 | void handle_metaserver_communication(); |
766 | |
767 | @@ -91,16 +91,16 @@ |
768 | const std::vector<InternetClient> & clients(); |
769 | |
770 | /// sets the name of the local server as shown in the games list |
771 | - void set_local_servername(const std::string & name) {m_gamename = name;} |
772 | + void set_local_servername(const std::string & name) {gamename_ = name;} |
773 | |
774 | /// \returns the name of the local server |
775 | - std::string & get_local_servername() {return m_gamename;} |
776 | + std::string & get_local_servername() {return gamename_;} |
777 | |
778 | /// \returns the name of the local client |
779 | - std::string & get_local_clientname() {return m_clientname;} |
780 | + std::string & get_local_clientname() {return clientname_;} |
781 | |
782 | /// \returns the rights of the local client |
783 | - std::string & get_local_clientrights() {return m_clientrights;} |
784 | + std::string & get_local_clientrights() {return clientrights_;} |
785 | |
786 | |
787 | /// ChatProvider: sends a message via the metaserver. |
788 | @@ -108,26 +108,27 @@ |
789 | |
790 | /// ChatProvider: adds the message to the message list and calls parent. |
791 | void receive(const ChatMessage & msg) { |
792 | - messages.push_back(msg); |
793 | + messages_.push_back(msg); |
794 | Notifications::publish(msg); |
795 | } |
796 | |
797 | /// ChatProvider: returns the list of chatmessages. |
798 | - const std::vector<ChatMessage> & get_messages() const override {return messages;} |
799 | + const std::vector<ChatMessage> & get_messages() const override {return messages_;} |
800 | |
801 | /// Silence the internet lobby chat if we are in game as we do not see the messages anyways |
802 | - bool sound_off() override {return m_state == IN_GAME;} |
803 | + bool sound_off() override {return state_ == IN_GAME;} |
804 | |
805 | - /// writes the ingame_system_chat messages to \arg msg and resets it afterwards |
806 | + /// writes the ingame_system_chat_ messages to \arg msg and resets it afterwards |
807 | void get_ingame_system_messages(std::vector<ChatMessage> & msg) { |
808 | - msg = ingame_system_chat; |
809 | - ingame_system_chat.clear(); |
810 | + msg = ingame_system_chat_; |
811 | + ingame_system_chat_.clear(); |
812 | } |
813 | |
814 | private: |
815 | InternetGaming(); |
816 | |
817 | void handle_packet(RecvPacket & packet); |
818 | + void handle_failed_read(); |
819 | |
820 | // conversion functions |
821 | bool str2bool(std::string); |
822 | @@ -137,13 +138,13 @@ |
823 | |
824 | |
825 | /// The socket that connects us to the host |
826 | - TCPsocket m_sock; |
827 | + TCPsocket sock_; |
828 | |
829 | /// Socket set used for selection |
830 | - SDLNet_SocketSet m_sockset; |
831 | + SDLNet_SocketSet sockset_; |
832 | |
833 | /// Deserializer acts as a buffer for packets (reassembly/splitting up) |
834 | - Deserializer m_deserializer; |
835 | + Deserializer deserializer_; |
836 | |
837 | /// Current state of this class |
838 | enum { |
839 | @@ -152,42 +153,42 @@ |
840 | LOBBY, |
841 | IN_GAME, |
842 | COMMUNICATION_ERROR |
843 | - } m_state; |
844 | + } state_; |
845 | |
846 | /// data saved for possible relogin |
847 | - std::string m_pwd; |
848 | - bool m_reg; |
849 | - std::string m_meta; |
850 | - uint32_t m_port; |
851 | + std::string pwd_; |
852 | + bool reg_; |
853 | + std::string meta_; |
854 | + uint32_t port_; |
855 | |
856 | /// local clients name and rights |
857 | - std::string m_clientname; |
858 | - std::string m_clientrights; |
859 | + std::string clientname_; |
860 | + std::string clientrights_; |
861 | |
862 | /// informations of the clients game |
863 | - std::string m_gamename; |
864 | - std::string m_gameip; |
865 | + std::string gamename_; |
866 | + std::string gameip_; |
867 | |
868 | /// Metaserver informations |
869 | - bool clientupdateonmetaserver; |
870 | - bool gameupdateonmetaserver; |
871 | - bool clientupdate; |
872 | - bool gameupdate; |
873 | - std::vector<InternetClient> clientlist; |
874 | - std::vector<InternetGame> gamelist; |
875 | - int32_t time_offset; |
876 | + bool clientupdateonmetaserver_; |
877 | + bool gameupdateonmetaserver_; |
878 | + bool clientupdate_; |
879 | + bool gameupdate_; |
880 | + std::vector<InternetClient> clientlist_; |
881 | + std::vector<InternetGame> gamelist_; |
882 | + int32_t time_offset_; |
883 | |
884 | /// ChatProvider: chat messages |
885 | - std::vector<ChatMessage> messages; |
886 | - std::vector<ChatMessage> ingame_system_chat; |
887 | + std::vector<ChatMessage> messages_; |
888 | + std::vector<ChatMessage> ingame_system_chat_; |
889 | |
890 | /// An important response of the metaserver, the client is waiting for. |
891 | - std::string waitcmd; |
892 | - int32_t waittimeout; |
893 | + std::string waitcmd_; |
894 | + int32_t waittimeout_; |
895 | |
896 | /// Connection tracking specific variables |
897 | - time_t lastbrokensocket[2]; |
898 | - time_t lastping; |
899 | + time_t lastbrokensocket_[2]; /// last times when socket last broke in s. |
900 | + time_t lastping_; |
901 | |
902 | }; |
903 | |
904 | |
905 | === modified file 'src/network/netclient.cc' |
906 | --- src/network/netclient.cc 2016-02-14 21:18:03 +0000 |
907 | +++ src/network/netclient.cc 2016-02-15 12:35:46 +0000 |
908 | @@ -1,5 +1,5 @@ |
909 | /* |
910 | - * Copyright (C) 2008-2013, 2015 by the Widelands Development Team |
911 | + * Copyright (C) 2008-2016 by the Widelands Development Team |
912 | * |
913 | * This program is free software; you can redistribute it and/or |
914 | * modify it under the terms of the GNU General Public License |
915 | @@ -100,7 +100,7 @@ |
916 | |
917 | NetClient::NetClient |
918 | (IPaddress * const svaddr, const std::string & playername, bool internet) |
919 | -: d(new NetClientImpl), m_internet(internet) |
920 | +: d(new NetClientImpl), internet_(internet) |
921 | { |
922 | d->sock = SDLNet_TCP_Open(svaddr); |
923 | if (d->sock == nullptr) |
924 | @@ -122,7 +122,7 @@ |
925 | d->game = nullptr; |
926 | d->realspeed = 0; |
927 | d->desiredspeed = 1000; |
928 | - file = nullptr; |
929 | + file_ = nullptr; |
930 | |
931 | // Get the default win condition script |
932 | d->settings.win_condition_script = d->settings.win_condition_scripts.front(); |
933 | @@ -159,7 +159,7 @@ |
934 | d->modal = nullptr; |
935 | if (code == FullscreenMenuBase::MenuTarget::kBack) { |
936 | // if this is an internet game, tell the metaserver that client is back in the lobby. |
937 | - if (m_internet) |
938 | + if (internet_) |
939 | InternetGaming::ref().set_game_done(); |
940 | return; |
941 | } |
942 | @@ -210,7 +210,7 @@ |
943 | (boost::format("netclient_%d") % static_cast<int>(d->settings.usernum)).str()); |
944 | |
945 | // if this is an internet game, tell the metaserver that the game is done. |
946 | - if (m_internet) |
947 | + if (internet_) |
948 | InternetGaming::ref().set_game_done(); |
949 | d->modal = nullptr; |
950 | d->game = nullptr; |
951 | @@ -613,8 +613,8 @@ |
952 | d->settings.mapname.c_str(), d->settings.mapfilename.c_str()); |
953 | |
954 | // New map was set, so we clean up the buffer of a previously requested file |
955 | - if (file) |
956 | - delete file; |
957 | + if (file_) |
958 | + delete file_; |
959 | break; |
960 | } |
961 | |
962 | @@ -653,13 +653,13 @@ |
963 | s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); |
964 | s.send(d->sock); |
965 | |
966 | - if (file) |
967 | - delete file; |
968 | + if (file_) |
969 | + delete file_; |
970 | |
971 | - file = new NetTransferFile(); |
972 | - file->bytes = bytes; |
973 | - file->filename = path; |
974 | - file->md5sum = md5; |
975 | + file_ = new NetTransferFile(); |
976 | + file_->bytes = bytes; |
977 | + file_->filename = path; |
978 | + file_->md5sum = md5; |
979 | size_t position = path.rfind(g_fs->file_separator(), path.size() - 2); |
980 | if (position != std::string::npos) { |
981 | path.resize(position); |
982 | @@ -672,7 +672,7 @@ |
983 | // Only go on, if we are waiting for a file part at the moment. It can happen, that an "unrequested" |
984 | // part is send by the server if the map was changed just a moment ago and there was an outstanding |
985 | // request from the client. |
986 | - if (!file) |
987 | + if (!file_) |
988 | return; // silently ignore |
989 | |
990 | uint32_t part = packet.unsigned_32(); |
991 | @@ -682,7 +682,7 @@ |
992 | SendPacket s; |
993 | s.unsigned_8(NETCMD_FILE_PART); |
994 | s.unsigned_32(part); |
995 | - s.string(file->md5sum); |
996 | + s.string(file_->md5sum); |
997 | s.send(d->sock); |
998 | |
999 | FilePart fp; |
1000 | @@ -693,37 +693,37 @@ |
1001 | if (packet.data(buf, size) != size) |
1002 | log("Readproblem. Will try to go on anyways\n"); |
1003 | memcpy(fp.part, &buf[0], size); |
1004 | - file->parts.push_back(fp); |
1005 | + file_->parts.push_back(fp); |
1006 | |
1007 | // Write file to disk as soon as all parts arrived |
1008 | - uint32_t left = (file->bytes - NETFILEPARTSIZE * part); |
1009 | + uint32_t left = (file_->bytes - NETFILEPARTSIZE * part); |
1010 | if (left <= NETFILEPARTSIZE) { |
1011 | FileWrite fw; |
1012 | - left = file->bytes; |
1013 | + left = file_->bytes; |
1014 | uint32_t i = 0; |
1015 | // Put all data together |
1016 | while (left > 0) { |
1017 | uint32_t writeout |
1018 | = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; |
1019 | - fw.data(file->parts[i].part, writeout, FileWrite::Pos::null()); |
1020 | + fw.data(file_->parts[i].part, writeout, FileWrite::Pos::null()); |
1021 | left -= writeout; |
1022 | ++i; |
1023 | } |
1024 | // Now really write the file |
1025 | - fw.write(*g_fs, file->filename.c_str()); |
1026 | + fw.write(*g_fs, file_->filename.c_str()); |
1027 | |
1028 | // Check for consistence |
1029 | FileRead fr; |
1030 | - fr.open(*g_fs, file->filename); |
1031 | - |
1032 | - std::unique_ptr<char[]> complete(new char[file->bytes]); |
1033 | - |
1034 | - fr.data_complete(complete.get(), file->bytes); |
1035 | + fr.open(*g_fs, file_->filename); |
1036 | + |
1037 | + std::unique_ptr<char[]> complete(new char[file_->bytes]); |
1038 | + |
1039 | + fr.data_complete(complete.get(), file_->bytes); |
1040 | SimpleMD5Checksum md5sum; |
1041 | - md5sum.data(complete.get(), file->bytes); |
1042 | + md5sum.data(complete.get(), file_->bytes); |
1043 | md5sum.finish_checksum(); |
1044 | std::string localmd5 = md5sum.get_checksum().str(); |
1045 | - if (localmd5 != file->md5sum) { |
1046 | + if (localmd5 != file_->md5sum) { |
1047 | // Something went wrong! We have to rerequest the file. |
1048 | s.reset(); |
1049 | s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); |
1050 | @@ -733,7 +733,7 @@ |
1051 | s.unsigned_8(NETCMD_CHAT); |
1052 | s.string(_("/me 's file failed md5 checksumming.")); |
1053 | s.send(d->sock); |
1054 | - g_fs->fs_unlink(file->filename); |
1055 | + g_fs->fs_unlink(file_->filename); |
1056 | } |
1057 | // Check file for validity |
1058 | bool invalid = false; |
1059 | @@ -741,22 +741,22 @@ |
1060 | // Saved game check - does Widelands recognize the file as saved game? |
1061 | Widelands::Game game; |
1062 | try { |
1063 | - Widelands::GameLoader gl(file->filename, game); |
1064 | + Widelands::GameLoader gl(file_->filename, game); |
1065 | } catch (...) { |
1066 | invalid = true; |
1067 | } |
1068 | } else { |
1069 | // Map check - does Widelands recognize the file as map? |
1070 | Widelands::Map map; |
1071 | - std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(file->filename); |
1072 | + std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(file_->filename); |
1073 | if (!ml) |
1074 | invalid = true; |
1075 | } |
1076 | if (invalid) { |
1077 | - g_fs->fs_unlink(file->filename); |
1078 | + g_fs->fs_unlink(file_->filename); |
1079 | // Restore original file, if there was one before |
1080 | - if (g_fs->file_exists(backup_file_name(file->filename))) |
1081 | - g_fs->fs_rename(backup_file_name(file->filename), file->filename); |
1082 | + if (g_fs->file_exists(backup_file_name(file_->filename))) |
1083 | + g_fs->fs_rename(backup_file_name(file_->filename), file_->filename); |
1084 | s.reset(); |
1085 | s.unsigned_8(NETCMD_CHAT); |
1086 | s.string |
1087 | @@ -916,7 +916,7 @@ |
1088 | void NetClient::handle_network () |
1089 | { |
1090 | // if this is an internet game, handle the metaserver network |
1091 | - if (m_internet) |
1092 | + if (internet_) |
1093 | InternetGaming::ref().handle_metaserver_communication(); |
1094 | try { |
1095 | while (d->sock != nullptr && SDLNet_CheckSockets(d->sockset, 0) > 0) { |
1096 | |
1097 | === modified file 'src/network/netclient.h' |
1098 | --- src/network/netclient.h 2016-02-06 11:11:24 +0000 |
1099 | +++ src/network/netclient.h 2016-02-15 12:35:46 +0000 |
1100 | @@ -1,5 +1,5 @@ |
1101 | /* |
1102 | - * Copyright (C) 2008-2012 by the Widelands Development Team |
1103 | + * Copyright (C) 2008-2016 by the Widelands Development Team |
1104 | * |
1105 | * This program is free software; you can redistribute it and/or |
1106 | * modify it under the terms of the GNU General Public License |
1107 | @@ -103,8 +103,6 @@ |
1108 | /// for unique backupname |
1109 | std::string backup_file_name(std::string & path) {return path + "~backup";} |
1110 | |
1111 | - NetTransferFile * file; |
1112 | - |
1113 | void syncreport() override; |
1114 | |
1115 | void handle_packet(RecvPacket &); |
1116 | @@ -115,8 +113,9 @@ |
1117 | void disconnect |
1118 | (const std::string & reason, const std::string & arg = "", bool sendreason = true, bool showmsg = true); |
1119 | |
1120 | - NetClientImpl * d; |
1121 | - bool m_internet; |
1122 | + NetTransferFile * file_; |
1123 | + NetClientImpl * d; |
1124 | + bool internet_; |
1125 | }; |
1126 | |
1127 | #endif // end of include guard: WL_NETWORK_NETCLIENT_H |
1128 | |
1129 | === modified file 'src/network/nethost.cc' |
1130 | --- src/network/nethost.cc 2016-02-14 21:18:03 +0000 |
1131 | +++ src/network/nethost.cc 2016-02-15 12:35:46 +0000 |
1132 | @@ -1,5 +1,5 @@ |
1133 | /* |
1134 | - * Copyright (C) 2008-2013, 2015 by the Widelands Development Team |
1135 | + * Copyright (C) 2008-2016 by the Widelands Development Team |
1136 | * |
1137 | * This program is free software; you can redistribute it and/or |
1138 | * modify it under the terms of the GNU General Public License |
1139 | @@ -583,8 +583,8 @@ |
1140 | NetHost::NetHost (const std::string & playername, bool internet) |
1141 | : |
1142 | d(new NetHostImpl(this)), |
1143 | - m_internet(internet), |
1144 | - m_forced_pause(false) |
1145 | + internet_(internet), |
1146 | + forced_pause_(false) |
1147 | { |
1148 | log("[Host]: starting up.\n"); |
1149 | |
1150 | @@ -618,7 +618,7 @@ |
1151 | hostuser.position = UserSettings::none(); |
1152 | hostuser.ready = true; |
1153 | d->settings.users.push_back(hostuser); |
1154 | - file = nullptr; // Initialize as 0 pointer - unfortunately needed in struct. |
1155 | + file_ = nullptr; // Initialize as 0 pointer - unfortunately needed in struct. |
1156 | } |
1157 | |
1158 | NetHost::~NetHost () |
1159 | @@ -638,7 +638,7 @@ |
1160 | |
1161 | delete d->promoter; |
1162 | delete d; |
1163 | - delete file; |
1164 | + delete file_; |
1165 | } |
1166 | |
1167 | const std::string & NetHost::get_local_playername() const |
1168 | @@ -690,13 +690,13 @@ |
1169 | const FullscreenMenuBase::MenuTarget code = lm.run<FullscreenMenuBase::MenuTarget>(); |
1170 | if (code == FullscreenMenuBase::MenuTarget::kBack) { |
1171 | // if this is an internet game, tell the metaserver that client is back in the lobby. |
1172 | - if (m_internet) |
1173 | + if (internet_) |
1174 | InternetGaming::ref().set_game_done(); |
1175 | return; |
1176 | } |
1177 | |
1178 | // if this is an internet game, tell the metaserver that the game started |
1179 | - if (m_internet) |
1180 | + if (internet_) |
1181 | InternetGaming::ref().set_game_playing(); |
1182 | |
1183 | for (uint32_t i = 0; i < d->clients.size(); ++i) { |
1184 | @@ -776,7 +776,7 @@ |
1185 | delete tips; |
1186 | |
1187 | // if this is an internet game, tell the metaserver that the game is done. |
1188 | - if (m_internet) |
1189 | + if (internet_) |
1190 | InternetGaming::ref().set_game_done(); |
1191 | clear_computer_players(); |
1192 | } catch (...) { |
1193 | @@ -1161,30 +1161,30 @@ |
1194 | // Read in the file |
1195 | FileRead fr; |
1196 | fr.open(*g_fs, mapfilename); |
1197 | - if (file) |
1198 | - delete file; |
1199 | - file = new NetTransferFile(); |
1200 | - file->filename = mapfilename; |
1201 | - uint32_t leftparts = file->bytes = fr.get_size(); |
1202 | + if (file_) |
1203 | + delete file_; |
1204 | + file_ = new NetTransferFile(); |
1205 | + file_->filename = mapfilename; |
1206 | + uint32_t leftparts = file_->bytes = fr.get_size(); |
1207 | while (leftparts > 0) { |
1208 | uint32_t readout = (leftparts > NETFILEPARTSIZE) ? NETFILEPARTSIZE : leftparts; |
1209 | FilePart fp; |
1210 | memcpy(fp.part, fr.data(readout), readout); |
1211 | - file->parts.push_back(fp); |
1212 | + file_->parts.push_back(fp); |
1213 | leftparts -= readout; |
1214 | } |
1215 | - std::vector<char> complete(file->bytes); |
1216 | + std::vector<char> complete(file_->bytes); |
1217 | fr.set_file_pos(0); |
1218 | - fr.data_complete(&complete[0], file->bytes); |
1219 | + fr.data_complete(&complete[0], file_->bytes); |
1220 | SimpleMD5Checksum md5sum; |
1221 | - md5sum.data(&complete[0], file->bytes); |
1222 | + md5sum.data(&complete[0], file_->bytes); |
1223 | md5sum.finish_checksum(); |
1224 | - file->md5sum = md5sum.get_checksum().str(); |
1225 | + file_->md5sum = md5sum.get_checksum().str(); |
1226 | } else { |
1227 | // reset previously offered map / saved game |
1228 | - if (file) { |
1229 | - delete file; |
1230 | - file = nullptr; |
1231 | + if (file_) { |
1232 | + delete file_; |
1233 | + file_ = nullptr; |
1234 | } |
1235 | } |
1236 | |
1237 | @@ -1613,8 +1613,8 @@ |
1238 | //Scan-build reports that access to bytes here results in a dereference of null pointer. |
1239 | //This is a false positive. |
1240 | //See https://bugs.launchpad.net/widelands/+bug/1198919 |
1241 | - s.unsigned_32(file->bytes); |
1242 | - s.string(file->md5sum); |
1243 | + s.unsigned_32(file_->bytes); |
1244 | + s.string(file_->md5sum); |
1245 | return true; |
1246 | } |
1247 | |
1248 | @@ -1720,9 +1720,9 @@ |
1249 | s.send(client.sock); |
1250 | |
1251 | // If possible, offer the map / savegame as transfer |
1252 | - if (file) { |
1253 | + if (file_) { |
1254 | s.reset(); |
1255 | - if (write_map_transfer_info(s, file->filename)) |
1256 | + if (write_map_transfer_info(s, file_->filename)) |
1257 | s.send(client.sock); |
1258 | } |
1259 | |
1260 | @@ -1924,7 +1924,7 @@ |
1261 | uint32_t const oldnetworkspeed = d->networkspeed; |
1262 | |
1263 | // First check if a pause was forced by the host |
1264 | - if (m_forced_pause) |
1265 | + if (forced_pause_) |
1266 | d->networkspeed = 0; |
1267 | |
1268 | else { |
1269 | @@ -2073,7 +2073,7 @@ |
1270 | } |
1271 | |
1272 | // if this is an internet game, handle the metaserver information |
1273 | - if (m_internet) { |
1274 | + if (internet_) { |
1275 | InternetGaming::ref().handle_metaserver_communication(); |
1276 | // Maybe an important message was send on the metaserver, |
1277 | // that we should show in game as well. |
1278 | @@ -2112,9 +2112,9 @@ |
1279 | } |
1280 | } |
1281 | |
1282 | - // If a pause was forced or if the players all pause, send a ping regularly |
1283 | - // to keep the sockets up and running |
1284 | - if ((m_forced_pause || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { |
1285 | + // If a pause was forced or if the players all pause, send a ping regularly |
1286 | + // to keep the sockets up and running |
1287 | + if ((forced_pause_ || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { |
1288 | d->lastpauseping = time(nullptr); |
1289 | |
1290 | SendPacket s; |
1291 | @@ -2320,10 +2320,10 @@ |
1292 | } |
1293 | |
1294 | case NETCMD_NEW_FILE_AVAILABLE: { |
1295 | - if (!file) // Do we have a file for sending |
1296 | + if (!file_) // Do we have a file for sending |
1297 | throw DisconnectException("REQUEST_OF_N_E_FILE"); |
1298 | send_system_message_code |
1299 | - ("STARTED_SENDING_FILE", file->filename, d->settings.users.at(client.usernum).name); |
1300 | + ("STARTED_SENDING_FILE", file_->filename, d->settings.users.at(client.usernum).name); |
1301 | send_file_part(client.sock, 0); |
1302 | // Remember client as "currently receiving file" |
1303 | d->settings.users[client.usernum].ready = false; |
1304 | @@ -2336,19 +2336,19 @@ |
1305 | } |
1306 | |
1307 | case NETCMD_FILE_PART: { |
1308 | - if (!file) // Do we have a file for sending |
1309 | + if (!file_) // Do we have a file for sending |
1310 | throw DisconnectException("REQUEST_OF_N_E_FILE"); |
1311 | uint32_t part = r.unsigned_32(); |
1312 | std::string x = r.string(); |
1313 | - if (x != file->md5sum) { |
1314 | - log("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file->md5sum.c_str()); |
1315 | + if (x != file_->md5sum) { |
1316 | + log("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file_->md5sum.c_str()); |
1317 | return; // Surely the file was changed, so we cancel here. |
1318 | } |
1319 | - if (part >= file->parts.size()) |
1320 | + if (part >= file_->parts.size()) |
1321 | throw DisconnectException("REQUEST_OF_N_E_FILEPART"); |
1322 | - if (part == file->parts.size() - 1) { |
1323 | + if (part == file_->parts.size() - 1) { |
1324 | send_system_message_code |
1325 | - ("COMPLETED_FILE_TRANSFER", file->filename, d->settings.users.at(client.usernum).name); |
1326 | + ("COMPLETED_FILE_TRANSFER", file_->filename, d->settings.users.at(client.usernum).name); |
1327 | d->settings.users[client.usernum].ready = true; |
1328 | SendPacket s; |
1329 | s.unsigned_8(NETCMD_SETTING_USER); |
1330 | @@ -2361,8 +2361,8 @@ |
1331 | if (part % 100 == 0) |
1332 | send_system_message_code |
1333 | ("SENDING_FILE_PART", |
1334 | - (boost::format("%i/%i") % part % (file->parts.size() + 1)).str(), |
1335 | - file->filename, d->settings.users.at(client.usernum).name); |
1336 | + (boost::format("%i/%i") % part % (file_->parts.size() + 1)).str(), |
1337 | + file_->filename, d->settings.users.at(client.usernum).name); |
1338 | send_file_part(client.sock, part); |
1339 | break; |
1340 | } |
1341 | @@ -2373,9 +2373,9 @@ |
1342 | } |
1343 | |
1344 | void NetHost::send_file_part(TCPsocket csock, uint32_t part) { |
1345 | - assert(part < file->parts.size()); |
1346 | + assert(part < file_->parts.size()); |
1347 | |
1348 | - uint32_t left = file->bytes - NETFILEPARTSIZE * part; |
1349 | + uint32_t left = file_->bytes - NETFILEPARTSIZE * part; |
1350 | uint32_t size = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; |
1351 | |
1352 | // Send the part |
1353 | @@ -2383,7 +2383,7 @@ |
1354 | s.unsigned_8(NETCMD_FILE_PART); |
1355 | s.unsigned_32(part); |
1356 | s.unsigned_32(size); |
1357 | - s.data(file->parts[part].part, size); |
1358 | + s.data(file_->parts[part].part, size); |
1359 | s.send(csock); |
1360 | } |
1361 | |
1362 | |
1363 | === modified file 'src/network/nethost.h' |
1364 | --- src/network/nethost.h 2016-02-06 12:49:40 +0000 |
1365 | +++ src/network/nethost.h 2016-02-15 12:35:46 +0000 |
1366 | @@ -1,5 +1,5 @@ |
1367 | /* |
1368 | - * Copyright (C) 2008-2012 by the Widelands Development Team |
1369 | + * Copyright (C) 2008-2016 by the Widelands Development Team |
1370 | * |
1371 | * This program is free software; you can redistribute it and/or |
1372 | * modify it under the terms of the GNU General Public License |
1373 | @@ -94,19 +94,18 @@ |
1374 | void report_result(uint8_t player, Widelands::PlayerEndResult result, const std::string & info) override; |
1375 | |
1376 | void force_pause() { |
1377 | - m_forced_pause = true; |
1378 | + forced_pause_ = true; |
1379 | update_network_speed(); |
1380 | } |
1381 | |
1382 | void end_forced_pause() { |
1383 | - m_forced_pause = false; |
1384 | + forced_pause_ = false; |
1385 | update_network_speed(); |
1386 | } |
1387 | |
1388 | - bool forced_pause() {return m_forced_pause;} |
1389 | + bool forced_pause() {return forced_pause_;} |
1390 | |
1391 | private: |
1392 | - NetTransferFile * file; |
1393 | |
1394 | void send_system_message_code |
1395 | (const std::string &, |
1396 | @@ -153,9 +152,10 @@ |
1397 | const std::string & arg = ""); |
1398 | void reaper(); |
1399 | |
1400 | - NetHostImpl * d; |
1401 | - bool m_internet; |
1402 | - bool m_forced_pause; |
1403 | + NetTransferFile * file_; |
1404 | + NetHostImpl * d; |
1405 | + bool internet_; |
1406 | + bool forced_pause_; |
1407 | }; |
1408 | |
1409 | |
1410 | |
1411 | === modified file 'src/network/network.cc' |
1412 | --- src/network/network.cc 2015-11-21 10:16:52 +0000 |
1413 | +++ src/network/network.cc 2016-02-15 12:35:46 +0000 |
1414 | @@ -1,5 +1,5 @@ |
1415 | /* |
1416 | - * Copyright (C) 2004-2009, 2015 by the Widelands Development Team |
1417 | + * Copyright (C) 2004-2016 by the Widelands Development Team |
1418 | * |
1419 | * This program is free software; you can redistribute it and/or |
1420 | * modify it under the terms of the GNU General Public License |
1421 | @@ -25,12 +25,12 @@ |
1422 | |
1423 | |
1424 | CmdNetCheckSync::CmdNetCheckSync(uint32_t const dt, SyncCallback * const cb) : |
1425 | -Command (dt), m_callback(cb) |
1426 | +Command (dt), callback_(cb) |
1427 | {} |
1428 | |
1429 | |
1430 | void CmdNetCheckSync::execute (Widelands::Game &) { |
1431 | - m_callback->syncreport(); |
1432 | + callback_->syncreport(); |
1433 | } |
1434 | |
1435 | |
1436 | @@ -41,22 +41,22 @@ |
1437 | |
1438 | void NetworkTime::reset(int32_t const ntime) |
1439 | { |
1440 | - m_networktime = m_time = ntime; |
1441 | - m_lastframe = SDL_GetTicks(); |
1442 | - m_latency = 0; |
1443 | + networktime_ = time_ = ntime; |
1444 | + lastframe_ = SDL_GetTicks(); |
1445 | + latency_ = 0; |
1446 | } |
1447 | |
1448 | void NetworkTime::fastforward() |
1449 | { |
1450 | - m_time = m_networktime; |
1451 | - m_lastframe = SDL_GetTicks(); |
1452 | + time_ = networktime_; |
1453 | + lastframe_ = SDL_GetTicks(); |
1454 | } |
1455 | |
1456 | void NetworkTime::think(uint32_t const speed) |
1457 | { |
1458 | uint32_t const curtime = SDL_GetTicks(); |
1459 | - int32_t delta = curtime - m_lastframe; |
1460 | - m_lastframe = curtime; |
1461 | + int32_t delta = curtime - lastframe_; |
1462 | + lastframe_ = curtime; |
1463 | |
1464 | // in case weird things are happening with the system time |
1465 | // (e.g. debugger, extremely slow simulation, ...) |
1466 | @@ -67,55 +67,55 @@ |
1467 | |
1468 | delta = (delta * speed) / 1000; |
1469 | |
1470 | - int32_t const behind = m_networktime - m_time; |
1471 | + int32_t const behind = networktime_ - time_; |
1472 | |
1473 | // Play catch up |
1474 | uint32_t speedup = 0; |
1475 | - if (m_latency > static_cast<uint32_t>(10 * delta)) |
1476 | + if (latency_ > static_cast<uint32_t>(10 * delta)) |
1477 | // just try to kill as much of the latency as possible if we are that |
1478 | // far behind |
1479 | - speedup = m_latency / 3; |
1480 | - else if (m_latency > static_cast<uint32_t>(delta)) |
1481 | + speedup = latency_ / 3; |
1482 | + else if (latency_ > static_cast<uint32_t>(delta)) |
1483 | speedup = delta / 8; // speed up by 12.5% |
1484 | if (static_cast<int32_t>(delta + speedup) > behind) |
1485 | speedup = behind - delta; |
1486 | |
1487 | delta += speedup; |
1488 | - m_latency -= speedup; |
1489 | + latency_ -= speedup; |
1490 | |
1491 | if (delta > behind) |
1492 | delta = behind; |
1493 | |
1494 | - m_time += delta; |
1495 | + time_ += delta; |
1496 | } |
1497 | |
1498 | int32_t NetworkTime::time() const |
1499 | { |
1500 | - return m_time; |
1501 | + return time_; |
1502 | } |
1503 | |
1504 | int32_t NetworkTime::networktime() const |
1505 | { |
1506 | - return m_networktime; |
1507 | + return networktime_; |
1508 | } |
1509 | |
1510 | void NetworkTime::receive(int32_t const ntime) |
1511 | { |
1512 | - if (ntime < m_networktime) |
1513 | + if (ntime < networktime_) |
1514 | throw wexception("NetworkTime: Time appears to be running backwards."); |
1515 | |
1516 | - uint32_t const behind = m_networktime - m_time; |
1517 | + uint32_t const behind = networktime_ - time_; |
1518 | |
1519 | - m_latency = behind < m_latency ? behind : ((m_latency * 7) + behind) / 8; |
1520 | + latency_ = behind < latency_ ? behind : ((latency_ * 7) + behind) / 8; |
1521 | |
1522 | #if 0 |
1523 | log |
1524 | ("NetworkTime: New networktime %i (local time %i), behind %i, latency " |
1525 | "%u\n", |
1526 | - ntime, m_time, m_networktime - m_time, m_latency); |
1527 | + ntime, time_, networktime_ - time_, latency_); |
1528 | #endif |
1529 | |
1530 | - m_networktime = ntime; |
1531 | + networktime_ = ntime; |
1532 | } |
1533 | |
1534 | |
1535 | @@ -158,32 +158,32 @@ |
1536 | |
1537 | RecvPacket::RecvPacket (Deserializer & des) |
1538 | { |
1539 | - uint16_t const size = des.queue[0] << 8 | des.queue[1]; |
1540 | + uint16_t const size = des.queue_[0] << 8 | des.queue_[1]; |
1541 | |
1542 | // The following should be caught by Deserializer::read and ::avail |
1543 | - assert(des.queue.size() >= static_cast<size_t>(size)); |
1544 | + assert(des.queue_.size() >= static_cast<size_t>(size)); |
1545 | assert(size >= 2); |
1546 | |
1547 | - buffer.insert(buffer.end(), des.queue.begin() + 2, des.queue.begin() + size); |
1548 | - m_index = 0; |
1549 | + buffer.insert(buffer.end(), des.queue_.begin() + 2, des.queue_.begin() + size); |
1550 | + index_ = 0; |
1551 | |
1552 | - des.queue.erase(des.queue.begin(), des.queue.begin() + size); |
1553 | + des.queue_.erase(des.queue_.begin(), des.queue_.begin() + size); |
1554 | } |
1555 | |
1556 | size_t RecvPacket::data(void * const packet_data, size_t const bufsize) |
1557 | { |
1558 | - if (m_index + bufsize > buffer.size()) |
1559 | + if (index_ + bufsize > buffer.size()) |
1560 | throw wexception("Packet too short"); |
1561 | |
1562 | for (size_t read = 0; read < bufsize; ++read) |
1563 | - static_cast<uint8_t *>(packet_data)[read] = buffer[m_index++]; |
1564 | + static_cast<uint8_t *>(packet_data)[read] = buffer[index_++]; |
1565 | |
1566 | return bufsize; |
1567 | } |
1568 | |
1569 | bool RecvPacket::end_of_file() const |
1570 | { |
1571 | - return m_index < buffer.size(); |
1572 | + return index_ < buffer.size(); |
1573 | } |
1574 | |
1575 | bool Deserializer::read(TCPsocket sock) |
1576 | @@ -193,9 +193,9 @@ |
1577 | if (bytes <= 0) |
1578 | return false; |
1579 | |
1580 | - queue.insert(queue.end(), &buffer[0], &buffer[bytes]); |
1581 | + queue_.insert(queue_.end(), &buffer[0], &buffer[bytes]); |
1582 | |
1583 | - return queue.size() < 2 || 2 <= (queue[0] << 8 | queue[1]); |
1584 | + return queue_.size() < 2 || 2 <= (queue_[0] << 8 | queue_[1]); |
1585 | } |
1586 | |
1587 | /** |
1588 | @@ -203,14 +203,14 @@ |
1589 | */ |
1590 | bool Deserializer::avail() const |
1591 | { |
1592 | - if (queue.size() < 2) |
1593 | + if (queue_.size() < 2) |
1594 | return false; |
1595 | |
1596 | - const uint16_t size = queue[0] << 8 | queue[1]; |
1597 | + const uint16_t size = queue_[0] << 8 | queue_[1]; |
1598 | if (size < 2) |
1599 | return false; |
1600 | |
1601 | - return queue.size() >= static_cast<size_t>(size); |
1602 | + return queue_.size() >= static_cast<size_t>(size); |
1603 | } |
1604 | |
1605 | |
1606 | @@ -223,10 +223,10 @@ |
1607 | vsnprintf(buffer, sizeof(buffer), fmt, va); |
1608 | va_end(va); |
1609 | } |
1610 | - m_what = buffer; |
1611 | + what_ = buffer; |
1612 | } |
1613 | |
1614 | char const * DisconnectException::what() const noexcept |
1615 | { |
1616 | - return m_what.c_str(); |
1617 | + return what_.c_str(); |
1618 | } |
1619 | |
1620 | === modified file 'src/network/network.h' |
1621 | --- src/network/network.h 2016-01-18 19:35:25 +0000 |
1622 | +++ src/network/network.h 2016-02-15 12:35:46 +0000 |
1623 | @@ -1,5 +1,5 @@ |
1624 | /* |
1625 | - * Copyright (C) 2004-2008, 2012, 2015 by the Widelands Development Team |
1626 | + * Copyright (C) 2004-2016 by the Widelands Development Team |
1627 | * |
1628 | * This program is free software; you can redistribute it and/or |
1629 | * modify it under the terms of the GNU General Public License |
1630 | @@ -53,7 +53,7 @@ |
1631 | Widelands::QueueCommandTypes id() const override {return Widelands::QueueCommandTypes::kNetCheckSync;} |
1632 | |
1633 | private: |
1634 | - SyncCallback * m_callback; |
1635 | + SyncCallback * callback_; |
1636 | }; |
1637 | |
1638 | |
1639 | @@ -79,13 +79,13 @@ |
1640 | void receive(int32_t ntime); |
1641 | |
1642 | private: |
1643 | - int32_t m_networktime; |
1644 | - int32_t m_time; |
1645 | + int32_t networktime_; |
1646 | + int32_t time_; |
1647 | |
1648 | - uint32_t m_lastframe; |
1649 | + uint32_t lastframe_; |
1650 | |
1651 | /// This is an attempt to measure how far behind the network time we are. |
1652 | - uint32_t m_latency; |
1653 | + uint32_t latency_; |
1654 | }; |
1655 | |
1656 | |
1657 | @@ -118,7 +118,7 @@ |
1658 | |
1659 | private: |
1660 | std::vector<uint8_t> buffer; |
1661 | - size_t m_index; |
1662 | + size_t index_; |
1663 | }; |
1664 | |
1665 | struct FilePart { |
1666 | @@ -150,7 +150,7 @@ |
1667 | |
1668 | private: |
1669 | friend struct RecvPacket; |
1670 | - std::vector<uint8_t> queue; |
1671 | + std::vector<uint8_t> queue_; |
1672 | }; |
1673 | |
1674 | |
1675 | @@ -169,7 +169,7 @@ |
1676 | const char * what() const noexcept override; |
1677 | |
1678 | private: |
1679 | - std::string m_what; |
1680 | + std::string what_; |
1681 | }; |
1682 | |
1683 | /** |
1684 | @@ -177,7 +177,7 @@ |
1685 | * should be terminated because an unexpected message got received that is disallowed by the protocol. |
1686 | */ |
1687 | struct ProtocolException : public std::exception { |
1688 | - explicit ProtocolException(uint8_t code) {m_what = code;} |
1689 | + explicit ProtocolException(uint8_t code) {what_ = code;} |
1690 | |
1691 | /// do NOT use!!! This exception shall only return the command number of the received message |
1692 | /// via \ref ProtocolException:number() |
1693 | @@ -186,10 +186,10 @@ |
1694 | } |
1695 | |
1696 | /// \returns the command number of the received message |
1697 | - virtual int number() const {return m_what;} |
1698 | + virtual int number() const {return what_;} |
1699 | private: |
1700 | // no uint8_t, as lexical_cast does not support that format |
1701 | - int m_what; |
1702 | + int what_; |
1703 | }; |
1704 | |
1705 | #endif // end of include guard: WL_NETWORK_NETWORK_H |
1706 | |
1707 | === modified file 'src/profile/profile.cc' |
1708 | --- src/profile/profile.cc 2015-11-28 22:29:26 +0000 |
1709 | +++ src/profile/profile.cc 2016-02-15 12:35:46 +0000 |
1710 | @@ -1,5 +1,5 @@ |
1711 | /* |
1712 | - * Copyright (C) 2002, 2006-2013 by the Widelands Development Team |
1713 | + * Copyright (C) 2002-2016 by the Widelands Development Team |
1714 | * |
1715 | * This program is free software; you can redistribute it and/or |
1716 | * modify it under the terms of the GNU General Public License |
1717 | @@ -77,17 +77,17 @@ |
1718 | Profile g_options(Profile::err_log); |
1719 | |
1720 | Section::Value::Value(const string & nname, const char * const nval) : |
1721 | - m_used(false), |
1722 | - m_name(nname) |
1723 | + used_(false), |
1724 | + name_(nname) |
1725 | { |
1726 | set_string(nval); |
1727 | } |
1728 | |
1729 | Section::Value::Value(const Section::Value & o) : |
1730 | - m_used(o.m_used), |
1731 | - m_name(o.m_name) |
1732 | + used_(o.used_), |
1733 | + name_(o.name_) |
1734 | { |
1735 | - set_string(o.m_value.get()); |
1736 | + set_string(o.value_.get()); |
1737 | } |
1738 | |
1739 | Section::Value::Value(Section::Value && o) |
1740 | @@ -113,18 +113,18 @@ |
1741 | |
1742 | bool Section::Value::is_used() const |
1743 | { |
1744 | - return m_used; |
1745 | + return used_; |
1746 | } |
1747 | |
1748 | void Section::Value::mark_used() |
1749 | { |
1750 | - m_used = true; |
1751 | + used_ = true; |
1752 | } |
1753 | |
1754 | int32_t Section::Value::get_int() const |
1755 | { |
1756 | char * endp; |
1757 | - long int const i = strtol(m_value.get(), &endp, 0); |
1758 | + long int const i = strtol(value_.get(), &endp, 0); |
1759 | if (*endp) |
1760 | throw wexception("%s: '%s' is not an integer", get_name(), get_string()); |
1761 | int32_t const result = i; |
1762 | @@ -138,7 +138,7 @@ |
1763 | uint32_t Section::Value::get_natural() const |
1764 | { |
1765 | char * endp; |
1766 | - long long int i = strtoll(m_value.get(), &endp, 0); |
1767 | + long long int i = strtoll(value_.get(), &endp, 0); |
1768 | if (*endp || i < 0) |
1769 | throw wexception("%s: '%s' is not natural", get_name(), get_string()); |
1770 | return i; |
1771 | @@ -148,7 +148,7 @@ |
1772 | uint32_t Section::Value::get_positive() const |
1773 | { |
1774 | char * endp; |
1775 | - long long int i = strtoll(m_value.get(), &endp, 0); |
1776 | + long long int i = strtoll(value_.get(), &endp, 0); |
1777 | if (*endp || i < 1) |
1778 | throw wexception("%s: '%s' is not positive", get_name(), get_string()); |
1779 | return i; |
1780 | @@ -158,10 +158,10 @@ |
1781 | bool Section::Value::get_bool() const |
1782 | { |
1783 | for (int32_t i = 0; i < TRUE_WORDS; ++i) |
1784 | - if (boost::iequals(m_value.get(), trueWords[i])) |
1785 | + if (boost::iequals(value_.get(), trueWords[i])) |
1786 | return true; |
1787 | for (int32_t i = 0; i < FALSE_WORDS; ++i) |
1788 | - if (boost::iequals(m_value.get(), falseWords[i])) |
1789 | + if (boost::iequals(value_.get(), falseWords[i])) |
1790 | return false; |
1791 | |
1792 | throw wexception("%s: '%s' is not a boolean value", get_name(), get_string()); |
1793 | @@ -170,7 +170,7 @@ |
1794 | |
1795 | Point Section::Value::get_point() const |
1796 | { |
1797 | - char * endp = m_value.get(); |
1798 | + char * endp = value_.get(); |
1799 | long int const x = strtol(endp, &endp, 0); |
1800 | long int const y = strtol(endp, &endp, 0); |
1801 | if (*endp) |
1802 | @@ -184,17 +184,17 @@ |
1803 | using std::copy; |
1804 | |
1805 | const auto len = strlen(value) + 1; |
1806 | - m_value.reset(new char[len]); |
1807 | - copy(value, value + len, m_value.get()); |
1808 | + value_.reset(new char[len]); |
1809 | + copy(value, value + len, value_.get()); |
1810 | } |
1811 | |
1812 | void swap(Section::Value & first, Section::Value & second) |
1813 | { |
1814 | using std::swap; |
1815 | |
1816 | - swap(first.m_name, second.m_name); |
1817 | - swap(first.m_value, second.m_value); |
1818 | - swap(first.m_used, second.m_used); |
1819 | + swap(first.name_, second.name_); |
1820 | + swap(first.value_, second.value_); |
1821 | + swap(first.used_, second.used_); |
1822 | } |
1823 | |
1824 | |
1825 | @@ -207,21 +207,21 @@ |
1826 | */ |
1827 | |
1828 | char const * Section::get_name() const { |
1829 | - return m_section_name.c_str(); |
1830 | + return section_name_.c_str(); |
1831 | } |
1832 | void Section::set_name(const std::string& name) { |
1833 | - m_section_name = name; |
1834 | + section_name_ = name; |
1835 | } |
1836 | |
1837 | Section::Section(Profile * const prof, const std::string & name) : |
1838 | -m_profile(prof), m_used(false), m_section_name(name) {} |
1839 | +profile_(prof), used_(false), section_name_(name) {} |
1840 | |
1841 | /** Section::is_used() |
1842 | * |
1843 | */ |
1844 | bool Section::is_used() const |
1845 | { |
1846 | - return m_used; |
1847 | + return used_; |
1848 | } |
1849 | |
1850 | /** Section::mark_used() |
1851 | @@ -229,7 +229,7 @@ |
1852 | */ |
1853 | void Section::mark_used() |
1854 | { |
1855 | - m_used = true; |
1856 | + used_ = true; |
1857 | } |
1858 | |
1859 | /** Section::check_used() |
1860 | @@ -238,9 +238,9 @@ |
1861 | */ |
1862 | void Section::check_used() const |
1863 | { |
1864 | - for (const Value& temp_value : m_values) { |
1865 | + for (const Value& temp_value : values_) { |
1866 | if (!temp_value.is_used()) { |
1867 | - m_profile->error |
1868 | + profile_->error |
1869 | ("Section [%s], key '%s' not used (did you spell the name " |
1870 | "correctly?)", |
1871 | get_name(), temp_value.get_name()); |
1872 | @@ -251,7 +251,7 @@ |
1873 | |
1874 | bool Section::has_val(char const * const name) const |
1875 | { |
1876 | - for (const Value& temp_value : m_values) { |
1877 | + for (const Value& temp_value : values_) { |
1878 | if (boost::iequals(temp_value.get_name(), name)) { |
1879 | return true; |
1880 | } |
1881 | @@ -268,7 +268,7 @@ |
1882 | */ |
1883 | Section::Value * Section::get_val(char const * const name) |
1884 | { |
1885 | - for (Value& value : m_values) { |
1886 | + for (Value& value : values_) { |
1887 | if (boost::iequals(value.get_name(), name)) { |
1888 | value.mark_used(); |
1889 | return &value; |
1890 | @@ -286,7 +286,7 @@ |
1891 | */ |
1892 | Section::Value * Section::get_next_val(char const * const name) |
1893 | { |
1894 | - for (Value& value : m_values) { |
1895 | + for (Value& value : values_) { |
1896 | if (!value.is_used()) { |
1897 | if (!name || boost::iequals(value.get_name(), name)) { |
1898 | value.mark_used(); |
1899 | @@ -300,7 +300,7 @@ |
1900 | Section::Value & Section::create_val |
1901 | (char const * const name, char const * const value) |
1902 | { |
1903 | - for (Value& temp_value : m_values) { |
1904 | + for (Value& temp_value : values_) { |
1905 | if (boost::iequals(temp_value.get_name(), name)) { |
1906 | temp_value.set_string(value); |
1907 | return temp_value; |
1908 | @@ -312,8 +312,8 @@ |
1909 | Section::Value & Section::create_val_duplicate |
1910 | (char const * const name, char const * const value) |
1911 | { |
1912 | - m_values.emplace_back(name, value); |
1913 | - return m_values.back(); |
1914 | + values_.emplace_back(name, value); |
1915 | + return values_.back(); |
1916 | } |
1917 | |
1918 | /** |
1919 | @@ -400,7 +400,7 @@ |
1920 | try { |
1921 | return v->get_int(); |
1922 | } catch (const std::exception & e) { |
1923 | - m_profile->error("%s", e.what()); |
1924 | + profile_->error("%s", e.what()); |
1925 | } |
1926 | |
1927 | return def; |
1928 | @@ -413,7 +413,7 @@ |
1929 | try { |
1930 | return v->get_natural(); |
1931 | } catch (const std::exception & e) { |
1932 | - m_profile->error("%s", e.what()); |
1933 | + profile_->error("%s", e.what()); |
1934 | return def; |
1935 | } |
1936 | else |
1937 | @@ -428,7 +428,7 @@ |
1938 | try { |
1939 | return v->get_positive(); |
1940 | } catch (const std::exception & e) { |
1941 | - m_profile->error("%s", e.what()); |
1942 | + profile_->error("%s", e.what()); |
1943 | return def; |
1944 | } |
1945 | } |
1946 | @@ -455,7 +455,7 @@ |
1947 | try { |
1948 | return v->get_bool(); |
1949 | } catch (const std::exception & e) { |
1950 | - m_profile->error("%s", e.what()); |
1951 | + profile_->error("%s", e.what()); |
1952 | } |
1953 | |
1954 | return def; |
1955 | @@ -540,7 +540,7 @@ |
1956 | */ |
1957 | Profile::Profile(int32_t error_level) |
1958 | { |
1959 | - m_error_level = error_level; |
1960 | + error_level_ = error_level; |
1961 | } |
1962 | |
1963 | /** |
1964 | @@ -553,7 +553,7 @@ |
1965 | (char const * const filename, |
1966 | char const * const global_section, |
1967 | int32_t const error_level) |
1968 | - : m_filename(filename), m_error_level(error_level) |
1969 | + : filename_(filename), error_level_(error_level) |
1970 | { |
1971 | read(filename, global_section); |
1972 | } |
1973 | @@ -563,7 +563,7 @@ |
1974 | char const * const global_section, |
1975 | const std::string & textdomain, |
1976 | int32_t const error_level) |
1977 | - : m_filename(filename), m_error_level(error_level) |
1978 | + : filename_(filename), error_level_(error_level) |
1979 | { |
1980 | i18n::Textdomain td(textdomain); |
1981 | read(filename, global_section); |
1982 | @@ -576,7 +576,7 @@ |
1983 | */ |
1984 | void Profile::error(char const * const fmt, ...) const |
1985 | { |
1986 | - if (m_error_level == err_ignore) |
1987 | + if (error_level_ == err_ignore) |
1988 | return; |
1989 | |
1990 | char buffer[256]; |
1991 | @@ -586,10 +586,10 @@ |
1992 | vsnprintf(buffer, sizeof(buffer), fmt, va); |
1993 | va_end(va); |
1994 | |
1995 | - if (m_error_level == err_log) |
1996 | - log("[%s] %s\n", m_filename.c_str(), buffer); |
1997 | + if (error_level_ == err_log) |
1998 | + log("[%s] %s\n", filename_.c_str(), buffer); |
1999 | else |
2000 | - throw wexception("[%s] %s", m_filename.c_str(), buffer); |
2001 | + throw wexception("[%s] %s", filename_.c_str(), buffer); |
2002 | } |
2003 | |
2004 | /** Profile::check_used() |
2005 | @@ -598,7 +598,7 @@ |
2006 | */ |
2007 | void Profile::check_used() const |
2008 | { |
2009 | - for (const Section& temp_section : m_sections) { |
2010 | + for (const Section& temp_section : sections_) { |
2011 | if (!temp_section.is_used()) { |
2012 | error |
2013 | ("Section [%s] not used (did you spell the name correctly?)", |
2014 | @@ -619,7 +619,7 @@ |
2015 | */ |
2016 | Section * Profile::get_section(const std::string & name) |
2017 | { |
2018 | - for (Section& temp_section : m_sections) { |
2019 | + for (Section& temp_section : sections_) { |
2020 | if (boost::iequals(temp_section.get_name(), name.c_str())) { |
2021 | temp_section.mark_used(); |
2022 | return &temp_section; |
2023 | @@ -638,7 +638,7 @@ |
2024 | return *s; |
2025 | else |
2026 | throw wexception |
2027 | - ("in \"%s\" section [%s] not found", m_filename.c_str(), name.c_str()); |
2028 | + ("in \"%s\" section [%s] not found", filename_.c_str(), name.c_str()); |
2029 | } |
2030 | |
2031 | /** |
2032 | @@ -662,7 +662,7 @@ |
2033 | */ |
2034 | Section * Profile::get_next_section(char const * const name) |
2035 | { |
2036 | - for (Section& section : m_sections) { |
2037 | + for (Section& section : sections_) { |
2038 | if (!section.is_used()) { |
2039 | if (!name || boost::iequals(section.get_name(), name)) { |
2040 | section.mark_used(); |
2041 | @@ -676,7 +676,7 @@ |
2042 | |
2043 | Section & Profile::create_section (char const * const name) |
2044 | { |
2045 | - for (Section& section : m_sections) { |
2046 | + for (Section& section : sections_) { |
2047 | if (boost::iequals(section.get_name(), name)) { |
2048 | return section; |
2049 | } |
2050 | @@ -687,8 +687,8 @@ |
2051 | |
2052 | Section & Profile::create_section_duplicate(char const * const name) |
2053 | { |
2054 | - m_sections.push_back(Section(this, name)); |
2055 | - return m_sections.back(); |
2056 | + sections_.push_back(Section(this, name)); |
2057 | + return sections_.back(); |
2058 | } |
2059 | |
2060 | |
2061 | @@ -875,13 +875,13 @@ |
2062 | ("# Automatically created by Widelands %s (%s)\n", |
2063 | build_id().c_str(), build_type().c_str()); |
2064 | |
2065 | - for (const Section& temp_section : m_sections) { |
2066 | + for (const Section& temp_section : sections_) { |
2067 | if (used_only && !temp_section.is_used()) |
2068 | continue; |
2069 | |
2070 | fw.print_f("\n[%s]\n", temp_section.get_name()); |
2071 | |
2072 | - for (const Section::Value& temp_value : temp_section.m_values) { |
2073 | + for (const Section::Value& temp_value : temp_section.values_) { |
2074 | if (used_only && !temp_value.is_used()) |
2075 | continue; |
2076 | |
2077 | |
2078 | === modified file 'src/profile/profile.h' |
2079 | --- src/profile/profile.h 2015-01-27 20:35:25 +0000 |
2080 | +++ src/profile/profile.h 2016-02-15 12:35:46 +0000 |
2081 | @@ -1,5 +1,5 @@ |
2082 | /* |
2083 | - * Copyright (C) 2002, 2006-2013 by the Widelands Development Team |
2084 | + * Copyright (C) 2002-2016 by the Widelands Development Team |
2085 | * |
2086 | * This program is free software; you can redistribute it and/or |
2087 | * modify it under the terms of the GNU General Public License |
2088 | @@ -68,7 +68,7 @@ |
2089 | Value & operator= (Value); |
2090 | Value & operator= (Value && other); |
2091 | |
2092 | - char const * get_name() const {return m_name.c_str();} |
2093 | + char const * get_name() const {return name_.c_str();} |
2094 | |
2095 | bool is_used() const; |
2096 | void mark_used(); |
2097 | @@ -77,8 +77,8 @@ |
2098 | uint32_t get_natural () const; |
2099 | uint32_t get_positive() const; |
2100 | bool get_bool() const; |
2101 | - char const * get_string() const {return m_value.get();} |
2102 | - char * get_string() {return m_value.get();} |
2103 | + char const * get_string() const {return value_.get();} |
2104 | + char * get_string() {return value_.get();} |
2105 | Point get_point () const; |
2106 | |
2107 | void set_string(char const *); |
2108 | @@ -86,9 +86,9 @@ |
2109 | friend void swap(Value& first, Value& second); |
2110 | |
2111 | private: |
2112 | - bool m_used; |
2113 | - string m_name; |
2114 | - std::unique_ptr<char []> m_value; |
2115 | + bool used_; |
2116 | + string name_; |
2117 | + std::unique_ptr<char []> value_; |
2118 | |
2119 | Value() = default; |
2120 | }; |
2121 | @@ -103,7 +103,7 @@ |
2122 | |
2123 | Value * get_val (char const * name); |
2124 | Value * get_next_val(char const * name = nullptr); |
2125 | - uint32_t get_num_values() const {return m_values.size();} |
2126 | + uint32_t get_num_values() const {return values_.size();} |
2127 | |
2128 | char const * get_name() const; |
2129 | void set_name(const std::string&); |
2130 | @@ -176,10 +176,10 @@ |
2131 | Value & create_val_duplicate(char const * name, char const * value); |
2132 | |
2133 | private: |
2134 | - Profile * m_profile; |
2135 | - bool m_used; |
2136 | - std::string m_section_name; |
2137 | - ValueList m_values; |
2138 | + Profile * profile_; |
2139 | + bool used_; |
2140 | + std::string section_name_; |
2141 | + ValueList values_; |
2142 | }; |
2143 | |
2144 | /** |
2145 | @@ -241,10 +241,11 @@ |
2146 | Section & create_section_duplicate(char const * name); |
2147 | |
2148 | private: |
2149 | - std::string m_filename; |
2150 | using SectionList = std::vector<Section>; |
2151 | - SectionList m_sections; |
2152 | - int32_t m_error_level; |
2153 | + |
2154 | + std::string filename_; |
2155 | + SectionList sections_; |
2156 | + int32_t error_level_; |
2157 | |
2158 | DISALLOW_COPY_AND_ASSIGN(Profile); |
2159 | }; |
Continuous integration builds have changed state:
Travis build 690. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 109176686. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ bug_1395278_ network- 541.
Appveyor build 541. State: success. Details: https:/