Merge lp:~widelands-dev/widelands/fix_asan_crash_nethost into lp:widelands

Proposed by SirVer
Status: Merged
Merged at revision: 8507
Proposed branch: lp:~widelands-dev/widelands/fix_asan_crash_nethost
Merge into: lp:widelands
Diff against target: 950 lines (+255/-249)
3 files modified
src/network/gamehost.cc (+211/-208)
src/wui/multiplayersetupgroup.cc (+43/-40)
src/wui/multiplayersetupgroup.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_asan_crash_nethost
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+334288@code.launchpad.net

Commit message

Renamed some variables and fixed an ASAN reported crash.

The bug was that in MultiPlayerPlayerGroup, settings_->settings().players[id] was used. This vector always has the length of the players in the map. But id runs from 0 to MAX_PLAYERS - 1. The fix was simply to check that id < players.size().

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

Those index shifts were a major pain in the butt too when I implemented that.

@bunnybot merge

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2863. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/307774210.
Appveyor build 2672. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fix_asan_crash_nethost-2672.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/network/gamehost.cc'
2--- src/network/gamehost.cc 2017-11-14 08:15:48 +0000
3+++ src/network/gamehost.cc 2017-11-27 07:16:30 +0000
4@@ -587,9 +587,9 @@
5 disconnect_client(i, "GAME_STARTED_AT_CONNECT");
6 }
7
8- SendPacket s;
9- s.unsigned_8(NETCMD_LAUNCH);
10- broadcast(s);
11+ SendPacket packet;
12+ packet.unsigned_8(NETCMD_LAUNCH);
13+ broadcast(packet);
14
15 Widelands::Game game;
16 game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false));
17@@ -704,10 +704,10 @@
18 } else if (curtime - d->last_heartbeat >= SERVER_TIMESTAMP_INTERVAL) {
19 d->last_heartbeat = curtime;
20
21- SendPacket s;
22- s.unsigned_8(NETCMD_TIME);
23- s.signed_32(d->pseudo_networktime);
24- broadcast(s);
25+ SendPacket packet;
26+ packet.unsigned_8(NETCMD_TIME);
27+ packet.signed_32(d->pseudo_networktime);
28+ broadcast(packet);
29
30 committed_network_time(d->pseudo_networktime);
31
32@@ -724,11 +724,11 @@
33 void GameHost::send_player_command(Widelands::PlayerCommand& pc) {
34 pc.set_duetime(d->committed_networktime + 1);
35
36- SendPacket s;
37- s.unsigned_8(NETCMD_PLAYERCOMMAND);
38- s.signed_32(pc.duetime());
39- pc.serialize(s);
40- broadcast(s);
41+ SendPacket packet;
42+ packet.unsigned_8(NETCMD_PLAYERCOMMAND);
43+ packet.signed_32(pc.duetime());
44+ pc.serialize(packet);
45+ broadcast(packet);
46 d->game->enqueue_command(&pc);
47
48 committed_network_time(d->committed_networktime + 1);
49@@ -746,38 +746,38 @@
50 return;
51
52 if (msg.recipient.empty()) {
53- SendPacket s;
54- s.unsigned_8(NETCMD_CHAT);
55- s.signed_16(msg.playern);
56- s.string(msg.sender);
57- s.string(msg.msg);
58- s.unsigned_8(0);
59- broadcast(s);
60+ SendPacket packet;
61+ packet.unsigned_8(NETCMD_CHAT);
62+ packet.signed_16(msg.playern);
63+ packet.string(msg.sender);
64+ packet.string(msg.msg);
65+ packet.unsigned_8(0);
66+ broadcast(packet);
67
68 d->chat.receive(msg);
69 } else { // personal messages
70- SendPacket s;
71- s.unsigned_8(NETCMD_CHAT);
72+ SendPacket packet;
73+ packet.unsigned_8(NETCMD_CHAT);
74
75 // Is this a pm for the host player?
76 if (d->localplayername == msg.recipient) {
77 d->chat.receive(msg);
78 // Write the SendPacket - will be used below to show that the message
79 // was received.
80- s.signed_16(msg.playern);
81- s.string(msg.sender);
82- s.string(msg.msg);
83- s.unsigned_8(1);
84- s.string(msg.recipient);
85+ packet.signed_16(msg.playern);
86+ packet.string(msg.sender);
87+ packet.string(msg.msg);
88+ packet.unsigned_8(1);
89+ packet.string(msg.recipient);
90 } else { // Find the recipient
91 int32_t clientnum = check_client(msg.recipient);
92 if (clientnum >= 0) {
93- s.signed_16(msg.playern);
94- s.string(msg.sender);
95- s.string(msg.msg);
96- s.unsigned_8(1);
97- s.string(msg.recipient);
98- d->net->send(d->clients.at(clientnum).sock_id, s);
99+ packet.signed_16(msg.playern);
100+ packet.string(msg.sender);
101+ packet.string(msg.msg);
102+ packet.unsigned_8(1);
103+ packet.string(msg.recipient);
104+ d->net->send(d->clients.at(clientnum).sock_id, packet);
105 log(
106 "[Host]: personal chat: from %s to %s\n", msg.sender.c_str(), msg.recipient.c_str());
107 } else {
108@@ -791,10 +791,10 @@
109 d->chat.receive(err);
110 return; // nothing left to do!
111 }
112- s.signed_16(-2); // System message
113- s.string("");
114- s.string(fail);
115- s.unsigned_8(0);
116+ packet.signed_16(-2); // System message
117+ packet.string("");
118+ packet.string(fail);
119+ packet.unsigned_8(0);
120 }
121 }
122
123@@ -819,7 +819,7 @@
124 if (d->clients.at(j).usernum == static_cast<int16_t>(i))
125 break;
126 if (j < d->clients.size())
127- d->net->send(d->clients.at(j).sock_id, s);
128+ d->net->send(d->clients.at(j).sock_id, packet);
129 else
130 // Better no wexception it would break the whole game
131 log("WARNING: user was found but no client is connected to it!\n");
132@@ -904,13 +904,13 @@
133 const std::string& b,
134 const std::string& c) {
135 // First send to all clients
136- SendPacket s;
137- s.unsigned_8(NETCMD_SYSTEM_MESSAGE_CODE);
138- s.string(code);
139- s.string(a);
140- s.string(b);
141- s.string(c);
142- broadcast(s);
143+ SendPacket packet;
144+ packet.unsigned_8(NETCMD_SYSTEM_MESSAGE_CODE);
145+ packet.string(code);
146+ packet.string(a);
147+ packet.string(b);
148+ packet.string(c);
149+ broadcast(packet);
150
151 // Now add to our own chatbox
152 ChatMessage msg(NetworkGamingMessages::get_message(code, a, b, c));
153@@ -967,7 +967,7 @@
154
155 std::vector<PlayerSettings>::size_type oldplayers = d->settings.players.size();
156
157- SendPacket s;
158+ SendPacket packet;
159
160 // Care about the host
161 if (static_cast<int32_t>(maxplayers) <= d->settings.playernum &&
162@@ -989,11 +989,11 @@
163 d->clients.at(j).playernum = UserSettings::none();
164
165 // Broadcast change
166- s.reset();
167- s.unsigned_8(NETCMD_SETTING_USER);
168- s.unsigned_32(i);
169- write_setting_user(s, i);
170- broadcast(s);
171+ packet.reset();
172+ packet.unsigned_8(NETCMD_SETTING_USER);
173+ packet.unsigned_32(i);
174+ write_setting_user(packet, i);
175+ broadcast(packet);
176 }
177 }
178
179@@ -1016,16 +1016,16 @@
180 }
181
182 // Broadcast new map info
183- s.reset();
184- s.unsigned_8(NETCMD_SETTING_MAP);
185- write_setting_map(s);
186- broadcast(s);
187+ packet.reset();
188+ packet.unsigned_8(NETCMD_SETTING_MAP);
189+ write_setting_map(packet);
190+ broadcast(packet);
191
192 // Broadcast new player settings
193- s.reset();
194- s.unsigned_8(NETCMD_SETTING_ALLPLAYERS);
195- write_setting_all_players(s);
196- broadcast(s);
197+ packet.reset();
198+ packet.unsigned_8(NETCMD_SETTING_ALLPLAYERS);
199+ write_setting_all_players(packet);
200+ broadcast(packet);
201
202 // If possible, offer the map / saved game as transfer
203 // TODO(unknown): not yet able to handle directory type maps / savegames
204@@ -1060,9 +1060,10 @@
205 }
206 }
207
208- s.reset();
209- if (write_map_transfer_info(s, mapfilename))
210- broadcast(s);
211+ packet.reset();
212+ if (write_map_transfer_info(packet, mapfilename)) {
213+ broadcast(packet);
214+ }
215 }
216
217 void GameHost::set_player_state(uint8_t const number,
218@@ -1138,18 +1139,18 @@
219 player.name = get_computer_player_name(number);
220
221 // Broadcast change to player
222- SendPacket s;
223- s.reset();
224- s.unsigned_8(NETCMD_SETTING_PLAYER);
225- s.unsigned_8(number);
226- write_setting_player(s, number);
227- broadcast(s);
228+ SendPacket packet;
229+ packet.reset();
230+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
231+ packet.unsigned_8(number);
232+ write_setting_player(packet, number);
233+ broadcast(packet);
234
235 // Let clients know whether their slot has changed
236- s.reset();
237- s.unsigned_8(NETCMD_SETTING_ALLUSERS);
238- write_setting_all_users(s);
239- broadcast(s);
240+ packet.reset();
241+ packet.unsigned_8(NETCMD_SETTING_ALLUSERS);
242+ write_setting_all_users(packet);
243+ broadcast(packet);
244 }
245
246 void GameHost::set_player_tribe(uint8_t const number,
247@@ -1179,11 +1180,11 @@
248 player.initialization_index = 0;
249
250 // broadcast changes
251- SendPacket s;
252- s.unsigned_8(NETCMD_SETTING_PLAYER);
253- s.unsigned_8(number);
254- write_setting_player(s, number);
255- broadcast(s);
256+ SendPacket packet;
257+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
258+ packet.unsigned_8(number);
259+ write_setting_player(packet, number);
260+ broadcast(packet);
261 return;
262 }
263 }
264@@ -1205,11 +1206,11 @@
265 player.initialization_index = index;
266
267 // broadcast changes
268- SendPacket s;
269- s.unsigned_8(NETCMD_SETTING_PLAYER);
270- s.unsigned_8(number);
271- write_setting_player(s, number);
272- broadcast(s);
273+ SendPacket packet;
274+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
275+ packet.unsigned_8(number);
276+ write_setting_player(packet, number);
277+ broadcast(packet);
278 return;
279 } else
280 log("Attempted to change to out-of-range initialization index %u "
281@@ -1230,11 +1231,11 @@
282 player.random_ai = random_ai;
283
284 // Broadcast changes
285- SendPacket s;
286- s.unsigned_8(NETCMD_SETTING_PLAYER);
287- s.unsigned_8(number);
288- write_setting_player(s, number);
289- broadcast(s);
290+ SendPacket packet;
291+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
292+ packet.unsigned_8(number);
293+ write_setting_player(packet, number);
294+ broadcast(packet);
295 }
296
297 void GameHost::set_player_name(uint8_t const number, const std::string& name) {
298@@ -1249,11 +1250,11 @@
299 player.name = name;
300
301 // Broadcast changes
302- SendPacket s;
303- s.unsigned_8(NETCMD_SETTING_PLAYER);
304- s.unsigned_8(number);
305- write_setting_player(s, number);
306- broadcast(s);
307+ SendPacket packet;
308+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
309+ packet.unsigned_8(number);
310+ write_setting_player(packet, number);
311+ broadcast(packet);
312 }
313
314 void GameHost::set_player_closeable(uint8_t const number, bool closeable) {
315@@ -1288,11 +1289,11 @@
316 player.tribe = sharedplr.tribe;
317
318 // Broadcast changes
319- SendPacket s;
320- s.unsigned_8(NETCMD_SETTING_PLAYER);
321- s.unsigned_8(number);
322- write_setting_player(s, number);
323- broadcast(s);
324+ SendPacket packet;
325+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
326+ packet.unsigned_8(number);
327+ write_setting_player(packet, number);
328+ broadcast(packet);
329 }
330
331 void GameHost::set_player(uint8_t const number, const PlayerSettings& ps) {
332@@ -1303,11 +1304,11 @@
333 player = ps;
334
335 // Broadcast changes
336- SendPacket s;
337- s.unsigned_8(NETCMD_SETTING_PLAYER);
338- s.unsigned_8(number);
339- write_setting_player(s, number);
340- broadcast(s);
341+ SendPacket packet;
342+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
343+ packet.unsigned_8(number);
344+ write_setting_player(packet, number);
345+ broadcast(packet);
346 }
347
348 void GameHost::set_player_number(uint8_t const number) {
349@@ -1318,10 +1319,10 @@
350 d->settings.win_condition_script = wc;
351
352 // Broadcast changes
353- SendPacket s;
354- s.unsigned_8(NETCMD_WIN_CONDITION);
355- s.string(wc);
356- broadcast(s);
357+ SendPacket packet;
358+ packet.unsigned_8(NETCMD_WIN_CONDITION);
359+ packet.string(wc);
360+ broadcast(packet);
361 }
362
363 void GameHost::switch_to_player(uint32_t user, uint8_t number) {
364@@ -1367,11 +1368,11 @@
365 }
366
367 // Broadcast the user changes to everybody
368- SendPacket s;
369- s.unsigned_8(NETCMD_SETTING_USER);
370- s.unsigned_32(user);
371- write_setting_user(s, user);
372- broadcast(s);
373+ SendPacket packet;
374+ packet.unsigned_8(NETCMD_SETTING_USER);
375+ packet.unsigned_32(user);
376+ write_setting_user(packet, user);
377+ broadcast(packet);
378 }
379
380 void GameHost::set_player_team(uint8_t number, Widelands::TeamNumber team) {
381@@ -1380,11 +1381,11 @@
382 d->settings.players.at(number).team = team;
383
384 // Broadcast changes
385- SendPacket s;
386- s.unsigned_8(NETCMD_SETTING_PLAYER);
387- s.unsigned_8(number);
388- write_setting_player(s, number);
389- broadcast(s);
390+ SendPacket packet;
391+ packet.unsigned_8(NETCMD_SETTING_PLAYER);
392+ packet.unsigned_8(number);
393+ write_setting_player(packet, number);
394+ broadcast(packet);
395 }
396
397 void GameHost::set_multiplayer_game_settings() {
398@@ -1476,11 +1477,11 @@
399 }
400
401 /**
402-* If possible, this function writes the MapTransferInfo to SendPacket & s
403+* If possible, this function writes the MapTransferInfo to SendPacket & packet
404 *
405 * \returns true if the data was written, else false
406 */
407-bool GameHost::write_map_transfer_info(SendPacket& s, std::string mapfilename) {
408+bool GameHost::write_map_transfer_info(SendPacket& packet, std::string mapfilename) {
409 // TODO(unknown): not yet able to handle directory type maps / savegames
410 if (g_fs->is_directory(mapfilename)) {
411 log("Map/Save is a directory! No way for making it available a.t.m.!\n");
412@@ -1489,13 +1490,13 @@
413
414 // Write the new map/save file information, so client can decide whether it
415 // needs the file.
416- s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE);
417- s.string(mapfilename);
418+ packet.unsigned_8(NETCMD_NEW_FILE_AVAILABLE);
419+ packet.string(mapfilename);
420 // Scan-build reports that access to bytes here results in a dereference of null pointer.
421 // This is a false positive.
422 // See https://bugs.launchpad.net/widelands/+bug/1198919
423- s.unsigned_32(file_->bytes); // NOLINT
424- s.string(file_->md5sum);
425+ packet.unsigned_32(file_->bytes); // NOLINT
426+ packet.string(file_->md5sum);
427 return true;
428 }
429
430@@ -1579,62 +1580,63 @@
431
432 log("[Host]: Client %u: welcome to usernum %u\n", number, client.usernum);
433
434- SendPacket s;
435- s.unsigned_8(NETCMD_HELLO);
436- s.unsigned_8(NETWORK_PROTOCOL_VERSION);
437- s.unsigned_32(client.usernum);
438- d->net->send(client.sock_id, s);
439+ SendPacket packet;
440+ packet.unsigned_8(NETCMD_HELLO);
441+ packet.unsigned_8(NETWORK_PROTOCOL_VERSION);
442+ packet.unsigned_32(client.usernum);
443+ d->net->send(client.sock_id, packet);
444 // even if the network protocol is the same, the data might be different.
445 if (client.build_id != build_id())
446 send_system_message_code("DIFFERENT_WL_VERSION", effective_name, client.build_id, build_id());
447 // Send information about currently selected map / savegame
448- s.reset();
449+ packet.reset();
450
451- s.unsigned_8(NETCMD_SETTING_MAP);
452- write_setting_map(s);
453- d->net->send(client.sock_id, s);
454+ packet.unsigned_8(NETCMD_SETTING_MAP);
455+ write_setting_map(packet);
456+ d->net->send(client.sock_id, packet);
457
458 // If possible, offer the map / savegame as transfer
459 if (file_) {
460- s.reset();
461- if (write_map_transfer_info(s, file_->filename))
462- d->net->send(client.sock_id, s);
463+ packet.reset();
464+ if (write_map_transfer_info(packet, file_->filename)) {
465+ d->net->send(client.sock_id, packet);
466+ }
467 }
468
469 // Send the tribe information to the new client.
470- s.reset();
471- s.unsigned_8(NETCMD_SETTING_TRIBES);
472- s.unsigned_8(d->settings.tribes.size());
473+ packet.reset();
474+ packet.unsigned_8(NETCMD_SETTING_TRIBES);
475+ packet.unsigned_8(d->settings.tribes.size());
476 for (const TribeBasicInfo& tribe : d->settings.tribes) {
477- s.string(tribe.name);
478+ packet.string(tribe.name);
479 size_t const nr_initializations = tribe.initializations.size();
480- s.unsigned_8(nr_initializations);
481+ packet.unsigned_8(nr_initializations);
482 for (const TribeBasicInfo::Initialization& init : tribe.initializations)
483- s.string(init.script);
484+ packet.string(init.script);
485 }
486- d->net->send(client.sock_id, s);
487-
488- s.reset();
489- s.unsigned_8(NETCMD_SETTING_ALLPLAYERS);
490- write_setting_all_players(s);
491- d->net->send(client.sock_id, s);
492-
493- s.reset();
494- s.unsigned_8(NETCMD_SETTING_ALLUSERS);
495- write_setting_all_users(s);
496- d->net->send(client.sock_id, s);
497-
498- s.reset();
499- s.unsigned_8(NETCMD_WIN_CONDITION);
500- s.string(d->settings.win_condition_script);
501- d->net->send(client.sock_id, s);
502+ d->net->send(client.sock_id, packet);
503+
504+ packet.reset();
505+ packet.unsigned_8(NETCMD_SETTING_ALLPLAYERS);
506+ write_setting_all_players(packet);
507+ d->net->send(client.sock_id, packet);
508+
509+ packet.reset();
510+ packet.unsigned_8(NETCMD_SETTING_ALLUSERS);
511+ write_setting_all_users(packet);
512+ d->net->send(client.sock_id, packet);
513+
514+ packet.reset();
515+ packet.unsigned_8(NETCMD_WIN_CONDITION);
516+ packet.string(d->settings.win_condition_script);
517+ d->net->send(client.sock_id, packet);
518
519 // Broadcast new information about the player to everybody
520- s.reset();
521- s.unsigned_8(NETCMD_SETTING_USER);
522- s.unsigned_32(client.usernum);
523- write_setting_user(s, client.usernum);
524- broadcast(s);
525+ packet.reset();
526+ packet.unsigned_8(NETCMD_SETTING_USER);
527+ packet.unsigned_32(client.usernum);
528+ write_setting_user(packet, client.usernum);
529+ broadcast(packet);
530
531 // Check if there is an unoccupied player left and if, assign.
532 for (uint8_t i = 0; i < d->settings.players.size(); ++i)
533@@ -1731,9 +1733,9 @@
534 d->waiting = true;
535 broadcast_real_speed(0);
536
537- SendPacket s;
538- s.unsigned_8(NETCMD_WAIT);
539- broadcast(s);
540+ SendPacket packet;
541+ packet.unsigned_8(NETCMD_WAIT);
542+ broadcast(packet);
543 }
544 } else {
545 if (nrdelayed == 0) {
546@@ -1748,10 +1750,10 @@
547 void GameHost::broadcast_real_speed(uint32_t const speed) {
548 assert(speed <= std::numeric_limits<uint16_t>::max());
549
550- SendPacket s;
551- s.unsigned_8(NETCMD_SETSPEED);
552- s.unsigned_16(speed);
553- broadcast(s);
554+ SendPacket packet;
555+ packet.unsigned_8(NETCMD_SETSPEED);
556+ packet.unsigned_16(speed);
557+ broadcast(packet);
558 }
559
560 /**
561@@ -1829,10 +1831,10 @@
562
563 log("[Host]: Requesting sync reports for time %i\n", d->syncreport_time);
564
565- SendPacket s;
566- s.unsigned_8(NETCMD_SYNCREQUEST);
567- s.signed_32(d->syncreport_time);
568- broadcast(s);
569+ SendPacket packet;
570+ packet.unsigned_8(NETCMD_SYNCREQUEST);
571+ packet.signed_32(d->syncreport_time);
572+ broadcast(packet);
573
574 d->game->enqueue_command(
575 new CmdNetCheckSync(d->syncreport_time, [this] { sync_report_callback(); }));
576@@ -1870,9 +1872,9 @@
577
578 d->game->save_syncstream(true);
579
580- SendPacket s;
581- s.unsigned_8(NETCMD_INFO_DESYNC);
582- broadcast(s);
583+ SendPacket packet;
584+ packet.unsigned_8(NETCMD_INFO_DESYNC);
585+ broadcast(packet);
586
587 disconnect_client(i, "CLIENT_DESYNCED");
588 // Pause the game, so that host and client have time to handle the
589@@ -1948,9 +1950,9 @@
590 if ((forced_pause_ || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) {
591 d->lastpauseping = time(nullptr);
592
593- SendPacket s;
594- s.unsigned_8(NETCMD_PING);
595- broadcast(s);
596+ SendPacket send_packet;
597+ send_packet.unsigned_8(NETCMD_PING);
598+ broadcast(send_packet);
599 }
600
601 reaper();
602@@ -1984,9 +1986,9 @@
603 if (cmd == NETCMD_METASERVER_PING) {
604 log("[Host]: Received ping from metaserver.\n");
605 // Send PING back
606- SendPacket s;
607- s.unsigned_8(NETCMD_METASERVER_PING);
608- d->net->send(client.sock_id, s);
609+ SendPacket packet;
610+ packet.unsigned_8(NETCMD_METASERVER_PING);
611+ d->net->send(client.sock_id, packet);
612
613 // Remove metaserver from list of clients
614 client.playernum = UserSettings::not_connected();
615@@ -2155,11 +2157,11 @@
616 send_file_part(client.sock_id, 0);
617 // Remember client as "currently receiving file"
618 d->settings.users[client.usernum].ready = false;
619- SendPacket s;
620- s.unsigned_8(NETCMD_SETTING_USER);
621- s.unsigned_32(client.usernum);
622- write_setting_user(s, client.usernum);
623- broadcast(s);
624+ SendPacket packet;
625+ packet.unsigned_8(NETCMD_SETTING_USER);
626+ packet.unsigned_32(client.usernum);
627+ write_setting_user(packet, client.usernum);
628+ broadcast(packet);
629 break;
630 }
631
632@@ -2179,11 +2181,11 @@
633 send_system_message_code(
634 "COMPLETED_FILE_TRANSFER", file_->filename, d->settings.users.at(client.usernum).name);
635 d->settings.users[client.usernum].ready = true;
636- SendPacket s;
637- s.unsigned_8(NETCMD_SETTING_USER);
638- s.unsigned_32(client.usernum);
639- write_setting_user(s, client.usernum);
640- broadcast(s);
641+ SendPacket packet;
642+ packet.unsigned_8(NETCMD_SETTING_USER);
643+ packet.unsigned_32(client.usernum);
644+ write_setting_user(packet, client.usernum);
645+ broadcast(packet);
646 return;
647 }
648 ++part;
649@@ -2207,12 +2209,12 @@
650 uint32_t size = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left;
651
652 // Send the part
653- SendPacket s;
654- s.unsigned_8(NETCMD_FILE_PART);
655- s.unsigned_32(part);
656- s.unsigned_32(size);
657- s.data(file_->parts[part].part, size);
658- d->net->send(csock_id, s);
659+ SendPacket packet;
660+ packet.unsigned_8(NETCMD_FILE_PART);
661+ packet.unsigned_32(part);
662+ packet.unsigned_32(size);
663+ packet.data(file_->parts[part].part, size);
664+ d->net->send(csock_id, packet);
665 }
666
667 void GameHost::disconnect_player_controller(uint8_t const number, const std::string& name) {
668@@ -2265,11 +2267,11 @@
669 send_system_message_code(
670 "CLIENT_X_LEFT_GAME", d->settings.users.at(client.usernum).name, reason, arg);
671
672- SendPacket s;
673- s.unsigned_8(NETCMD_SETTING_USER);
674- s.unsigned_32(client.usernum);
675- write_setting_user(s, client.usernum);
676- broadcast(s);
677+ SendPacket packet;
678+ packet.unsigned_8(NETCMD_SETTING_USER);
679+ packet.unsigned_32(client.usernum);
680+ write_setting_user(packet, client.usernum);
681+ broadcast(packet);
682 } else
683 send_system_message_code("UNKNOWN_LEFT_GAME", reason, arg);
684
685@@ -2277,13 +2279,14 @@
686
687 if (client.sock_id > 0) {
688 if (sendreason) {
689- SendPacket s;
690- s.unsigned_8(NETCMD_DISCONNECT);
691- s.unsigned_8(arg.empty() ? 1 : 2);
692- s.string(reason);
693- if (!arg.empty())
694- s.string(arg);
695- d->net->send(client.sock_id, s);
696+ SendPacket packet;
697+ packet.unsigned_8(NETCMD_DISCONNECT);
698+ packet.unsigned_8(arg.empty() ? 1 : 2);
699+ packet.string(reason);
700+ if (!arg.empty()) {
701+ packet.string(arg);
702+ }
703+ d->net->send(client.sock_id, packet);
704 }
705
706 d->net->close(client.sock_id);
707
708=== modified file 'src/wui/multiplayersetupgroup.cc'
709--- src/wui/multiplayersetupgroup.cc 2017-09-02 21:48:44 +0000
710+++ src/wui/multiplayersetupgroup.cc 2017-11-27 07:16:30 +0000
711@@ -61,7 +61,7 @@
712 // Name needs to be initialized after the dropdown, otherwise the layout function will
713 // crash.
714 name(this, 0, 0, w - h - UI::Scrollbar::kSize * 11 / 5, h),
715- s(settings),
716+ settings_(settings),
717 id_(id),
718 slot_selection_locked_(false) {
719 set_size(w, h);
720@@ -106,7 +106,7 @@
721 /// This will update the client's player slot with the value currently selected in the slot
722 /// dropdown.
723 void set_slot() {
724- const GameSettings& settings = s->settings();
725+ const GameSettings& settings = settings_->settings();
726 if (id_ != settings.usernum) {
727 return;
728 }
729@@ -114,7 +114,7 @@
730 if (slot_dropdown_.has_selection()) {
731 const uint8_t new_slot = slot_dropdown_.get_selected();
732 if (new_slot != settings.users.at(id_).position) {
733- s->set_player_number(slot_dropdown_.get_selected());
734+ settings_->set_player_number(slot_dropdown_.get_selected());
735 }
736 }
737 slot_selection_locked_ = false;
738@@ -147,7 +147,7 @@
739
740 /// Take care of visibility and current values
741 void update() {
742- const GameSettings& settings = s->settings();
743+ const GameSettings& settings = settings_->settings();
744 const UserSettings& user_setting = settings.users.at(id_);
745
746 if (user_setting.position == UserSettings::not_connected()) {
747@@ -161,7 +161,7 @@
748
749 UI::Dropdown<uintptr_t> slot_dropdown_; /// Select the player slot.
750 UI::Textarea name; /// Client nick name
751- GameSettingsProvider* const s;
752+ GameSettingsProvider* const settings_;
753 uint8_t const id_; /// User number
754 bool slot_selection_locked_; // Ensure that dropdowns will close on selection.
755 std::unique_ptr<Notifications::Subscriber<NoteGameSettings>> subscriber_;
756@@ -176,7 +176,7 @@
757 GameSettingsProvider* const settings,
758 NetworkPlayerSettingsBackend* const npsb)
759 : UI::Box(parent, 0, 0, UI::Box::Horizontal, w, h, kPadding / 2),
760- s(settings),
761+ settings_(settings),
762 n(npsb),
763 id_(id),
764 player(this,
765@@ -227,23 +227,26 @@
766 add_space(0);
767
768 subscriber_ =
769- Notifications::subscribe<NoteGameSettings>([this](const NoteGameSettings& note) {
770- switch (note.action) {
771- case NoteGameSettings::Action::kMap:
772- // We don't care about map updates, since we receive enough notifications for the
773- // slots.
774- break;
775- default:
776- if (s->settings().players.empty()) {
777- // No map/savegame yet
778- return;
779- }
780- if (id_ == note.position ||
781- s->settings().players[id_].state == PlayerSettings::State::kShared) {
782- update();
783- }
784- }
785- });
786+ Notifications::subscribe<NoteGameSettings>(
787+ [this](const NoteGameSettings& note) {
788+ const std::vector<PlayerSettings> & players = settings_->settings().players;
789+ switch (note.action) {
790+ case NoteGameSettings::Action::kMap:
791+ // We don't care about map updates, since we receive enough notifications for the
792+ // slots.
793+ break;
794+ default:
795+ if (players.empty()) {
796+ // No map/savegame yet
797+ return;
798+ }
799+ if (id_ == note.position ||
800+ (id_ < players.size() &&
801+ players.at(id_).state == PlayerSettings::State::kShared)) {
802+ update();
803+ }
804+ }
805+ });
806
807 // Init dropdowns
808 update();
809@@ -263,7 +266,7 @@
810 /// This will update the game settings for the type with the value
811 /// currently selected in the type dropdown.
812 void set_type() {
813- if (!s->can_change_player_state(id_)) {
814+ if (!settings_->can_change_player_state(id_)) {
815 return;
816 }
817 type_selection_locked_ = true;
818@@ -328,7 +331,7 @@
819 type_dropdown_.add(
820 _("Open"), "open", g_gr->images().get("images/ui_basic/continue.png"), false, _("Open"));
821
822- type_dropdown_.set_enabled(s->can_change_player_state(id_));
823+ type_dropdown_.set_enabled(settings_->can_change_player_state(id_));
824
825 // Now select the entry according to server settings
826 const PlayerSettings& player_setting = settings.players[id_];
827@@ -360,9 +363,9 @@
828
829 /// Whether the client who is running the UI is allowed to change the tribe for this player slot.
830 bool has_tribe_access() {
831- return s->settings().players[id_].state == PlayerSettings::State::kShared ?
832- s->can_change_player_init(id_) :
833- s->can_change_player_tribe(id_);
834+ return settings_->settings().players[id_].state == PlayerSettings::State::kShared ?
835+ settings_->can_change_player_init(id_) :
836+ settings_->can_change_player_tribe(id_);
837 }
838
839 /// This will update the game settings for the tribe or shared_in with the value
840@@ -371,7 +374,7 @@
841 if (!has_tribe_access()) {
842 return;
843 }
844- const PlayerSettings& player_settings = s->settings().players[id_];
845+ const PlayerSettings& player_settings = settings_->settings().players[id_];
846 tribe_selection_locked_ = true;
847 tribes_dropdown_.set_disable_style(player_settings.state == PlayerSettings::State::kShared ?
848 UI::ButtonDisableStyle::kPermpressed :
849@@ -451,7 +454,7 @@
850 /// This will update the game settings for the initialization with the value
851 /// currently selected in the initialization dropdown.
852 void set_init() {
853- if (!s->can_change_player_init(id_)) {
854+ if (!settings_->can_change_player_init(id_)) {
855 return;
856 }
857 init_selection_locked_ = true;
858@@ -487,7 +490,7 @@
859 }
860
861 init_dropdown_.set_visible(true);
862- init_dropdown_.set_enabled(s->can_change_player_init(id_));
863+ init_dropdown_.set_enabled(settings_->can_change_player_init(id_));
864 }
865
866 /// This will update the team settings with the value currently selected in the teams dropdown.
867@@ -524,12 +527,12 @@
868 }
869 team_dropdown_.select(player_setting.team);
870 team_dropdown_.set_visible(true);
871- team_dropdown_.set_enabled(s->can_change_player_team(id_));
872+ team_dropdown_.set_enabled(settings_->can_change_player_team(id_));
873 }
874
875 /// Refresh all user interfaces
876 void update() {
877- const GameSettings& settings = s->settings();
878+ const GameSettings& settings = settings_->settings();
879 if (id_ >= settings.players.size()) {
880 set_visible(false);
881 return;
882@@ -556,7 +559,7 @@
883 // Trigger update for the other players for shared_in mode when slots open and close
884 if (last_state_ != player_setting.state) {
885 last_state_ = player_setting.state;
886- for (PlayerSlot slot = 0; slot < s->settings().players.size(); ++slot) {
887+ for (PlayerSlot slot = 0; slot < settings_->settings().players.size(); ++slot) {
888 if (slot != id_) {
889 n->set_player_state(slot, settings.players[slot].state);
890 }
891@@ -564,7 +567,7 @@
892 }
893 }
894
895- GameSettingsProvider* const s;
896+ GameSettingsProvider* const settings_;
897 NetworkPlayerSettingsBackend* const n;
898 PlayerSlot const id_;
899
900@@ -594,8 +597,8 @@
901 GameSettingsProvider* const settings,
902 uint32_t buth)
903 : UI::Box(parent, x, y, UI::Box::Horizontal, w, h, 8 * kPadding),
904- s(settings),
905- npsb(new NetworkPlayerSettingsBackend(s)),
906+ settings_(settings),
907+ npsb(new NetworkPlayerSettingsBackend(settings_)),
908 clientbox(this, 0, 0, UI::Box::Vertical),
909 playerbox(this, 0, 0, UI::Box::Vertical, w * 9 / 15, h, kPadding),
910 buth_(buth) {
911@@ -611,7 +614,7 @@
912 multi_player_player_groups.resize(kMaxPlayers);
913 for (PlayerSlot i = 0; i < multi_player_player_groups.size(); ++i) {
914 multi_player_player_groups.at(i) =
915- new MultiPlayerPlayerGroup(&playerbox, playerbox.get_w(), buth_, i, s, npsb.get());
916+ new MultiPlayerPlayerGroup(&playerbox, playerbox.get_w(), buth_, i, settings, npsb.get());
917 playerbox.add(multi_player_player_groups.at(i));
918 }
919 playerbox.add_space(0);
920@@ -627,7 +630,7 @@
921
922 /// Update which slots are available based on current settings.
923 void MultiPlayerSetupGroup::update() {
924- const GameSettings& settings = s->settings();
925+ const GameSettings& settings = settings_->settings();
926
927 // Update / initialize client groups
928 if (multi_player_client_groups.size() < settings.users.size()) {
929@@ -636,7 +639,7 @@
930 for (uint32_t i = 0; i < settings.users.size(); ++i) {
931 if (!multi_player_client_groups.at(i)) {
932 multi_player_client_groups.at(i) =
933- new MultiPlayerClientGroup(&clientbox, clientbox.get_w(), buth_, i, s);
934+ new MultiPlayerClientGroup(&clientbox, clientbox.get_w(), buth_, i, settings_);
935 clientbox.add(multi_player_client_groups.at(i), UI::Box::Resizing::kFullSize);
936 multi_player_client_groups.at(i)->layout();
937 }
938
939=== modified file 'src/wui/multiplayersetupgroup.h'
940--- src/wui/multiplayersetupgroup.h 2017-06-26 11:32:11 +0000
941+++ src/wui/multiplayersetupgroup.h 2017-11-27 07:16:30 +0000
942@@ -57,7 +57,7 @@
943 void update();
944 void draw(RenderTarget& dst) override;
945
946- GameSettingsProvider* const s;
947+ GameSettingsProvider* const settings_;
948 std::unique_ptr<NetworkPlayerSettingsBackend> npsb;
949 std::vector<MultiPlayerClientGroup*> multi_player_client_groups; // not owned
950 std::vector<MultiPlayerPlayerGroup*> multi_player_player_groups; // not owned

Subscribers

People subscribed via source and target branches

to status/vote changes: