Merge lp:~widelands-dev/widelands/fix_asan_crash_nethost into lp:widelands
- fix_asan_crash_nethost
- Merge into trunk
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 | ||||
Related bugs: |
|
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 MultiPlayerPlay
Description of the change
To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2863. State: passed. Details: https:/
Appveyor build 2672. State: success. Details: https:/
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 | 587 | disconnect_client(i, "GAME_STARTED_AT_CONNECT"); | 587 | disconnect_client(i, "GAME_STARTED_AT_CONNECT"); |
6 | 588 | } | 588 | } |
7 | 589 | 589 | ||
11 | 590 | SendPacket s; | 590 | SendPacket packet; |
12 | 591 | s.unsigned_8(NETCMD_LAUNCH); | 591 | packet.unsigned_8(NETCMD_LAUNCH); |
13 | 592 | broadcast(s); | 592 | broadcast(packet); |
14 | 593 | 593 | ||
15 | 594 | Widelands::Game game; | 594 | Widelands::Game game; |
16 | 595 | game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); | 595 | game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); |
17 | @@ -704,10 +704,10 @@ | |||
18 | 704 | } else if (curtime - d->last_heartbeat >= SERVER_TIMESTAMP_INTERVAL) { | 704 | } else if (curtime - d->last_heartbeat >= SERVER_TIMESTAMP_INTERVAL) { |
19 | 705 | d->last_heartbeat = curtime; | 705 | d->last_heartbeat = curtime; |
20 | 706 | 706 | ||
25 | 707 | SendPacket s; | 707 | SendPacket packet; |
26 | 708 | s.unsigned_8(NETCMD_TIME); | 708 | packet.unsigned_8(NETCMD_TIME); |
27 | 709 | s.signed_32(d->pseudo_networktime); | 709 | packet.signed_32(d->pseudo_networktime); |
28 | 710 | broadcast(s); | 710 | broadcast(packet); |
29 | 711 | 711 | ||
30 | 712 | committed_network_time(d->pseudo_networktime); | 712 | committed_network_time(d->pseudo_networktime); |
31 | 713 | 713 | ||
32 | @@ -724,11 +724,11 @@ | |||
33 | 724 | void GameHost::send_player_command(Widelands::PlayerCommand& pc) { | 724 | void GameHost::send_player_command(Widelands::PlayerCommand& pc) { |
34 | 725 | pc.set_duetime(d->committed_networktime + 1); | 725 | pc.set_duetime(d->committed_networktime + 1); |
35 | 726 | 726 | ||
41 | 727 | SendPacket s; | 727 | SendPacket packet; |
42 | 728 | s.unsigned_8(NETCMD_PLAYERCOMMAND); | 728 | packet.unsigned_8(NETCMD_PLAYERCOMMAND); |
43 | 729 | s.signed_32(pc.duetime()); | 729 | packet.signed_32(pc.duetime()); |
44 | 730 | pc.serialize(s); | 730 | pc.serialize(packet); |
45 | 731 | broadcast(s); | 731 | broadcast(packet); |
46 | 732 | d->game->enqueue_command(&pc); | 732 | d->game->enqueue_command(&pc); |
47 | 733 | 733 | ||
48 | 734 | committed_network_time(d->committed_networktime + 1); | 734 | committed_network_time(d->committed_networktime + 1); |
49 | @@ -746,38 +746,38 @@ | |||
50 | 746 | return; | 746 | return; |
51 | 747 | 747 | ||
52 | 748 | if (msg.recipient.empty()) { | 748 | if (msg.recipient.empty()) { |
60 | 749 | SendPacket s; | 749 | SendPacket packet; |
61 | 750 | s.unsigned_8(NETCMD_CHAT); | 750 | packet.unsigned_8(NETCMD_CHAT); |
62 | 751 | s.signed_16(msg.playern); | 751 | packet.signed_16(msg.playern); |
63 | 752 | s.string(msg.sender); | 752 | packet.string(msg.sender); |
64 | 753 | s.string(msg.msg); | 753 | packet.string(msg.msg); |
65 | 754 | s.unsigned_8(0); | 754 | packet.unsigned_8(0); |
66 | 755 | broadcast(s); | 755 | broadcast(packet); |
67 | 756 | 756 | ||
68 | 757 | d->chat.receive(msg); | 757 | d->chat.receive(msg); |
69 | 758 | } else { // personal messages | 758 | } else { // personal messages |
72 | 759 | SendPacket s; | 759 | SendPacket packet; |
73 | 760 | s.unsigned_8(NETCMD_CHAT); | 760 | packet.unsigned_8(NETCMD_CHAT); |
74 | 761 | 761 | ||
75 | 762 | // Is this a pm for the host player? | 762 | // Is this a pm for the host player? |
76 | 763 | if (d->localplayername == msg.recipient) { | 763 | if (d->localplayername == msg.recipient) { |
77 | 764 | d->chat.receive(msg); | 764 | d->chat.receive(msg); |
78 | 765 | // Write the SendPacket - will be used below to show that the message | 765 | // Write the SendPacket - will be used below to show that the message |
79 | 766 | // was received. | 766 | // was received. |
85 | 767 | s.signed_16(msg.playern); | 767 | packet.signed_16(msg.playern); |
86 | 768 | s.string(msg.sender); | 768 | packet.string(msg.sender); |
87 | 769 | s.string(msg.msg); | 769 | packet.string(msg.msg); |
88 | 770 | s.unsigned_8(1); | 770 | packet.unsigned_8(1); |
89 | 771 | s.string(msg.recipient); | 771 | packet.string(msg.recipient); |
90 | 772 | } else { // Find the recipient | 772 | } else { // Find the recipient |
91 | 773 | int32_t clientnum = check_client(msg.recipient); | 773 | int32_t clientnum = check_client(msg.recipient); |
92 | 774 | if (clientnum >= 0) { | 774 | if (clientnum >= 0) { |
99 | 775 | s.signed_16(msg.playern); | 775 | packet.signed_16(msg.playern); |
100 | 776 | s.string(msg.sender); | 776 | packet.string(msg.sender); |
101 | 777 | s.string(msg.msg); | 777 | packet.string(msg.msg); |
102 | 778 | s.unsigned_8(1); | 778 | packet.unsigned_8(1); |
103 | 779 | s.string(msg.recipient); | 779 | packet.string(msg.recipient); |
104 | 780 | d->net->send(d->clients.at(clientnum).sock_id, s); | 780 | d->net->send(d->clients.at(clientnum).sock_id, packet); |
105 | 781 | log( | 781 | log( |
106 | 782 | "[Host]: personal chat: from %s to %s\n", msg.sender.c_str(), msg.recipient.c_str()); | 782 | "[Host]: personal chat: from %s to %s\n", msg.sender.c_str(), msg.recipient.c_str()); |
107 | 783 | } else { | 783 | } else { |
108 | @@ -791,10 +791,10 @@ | |||
109 | 791 | d->chat.receive(err); | 791 | d->chat.receive(err); |
110 | 792 | return; // nothing left to do! | 792 | return; // nothing left to do! |
111 | 793 | } | 793 | } |
116 | 794 | s.signed_16(-2); // System message | 794 | packet.signed_16(-2); // System message |
117 | 795 | s.string(""); | 795 | packet.string(""); |
118 | 796 | s.string(fail); | 796 | packet.string(fail); |
119 | 797 | s.unsigned_8(0); | 797 | packet.unsigned_8(0); |
120 | 798 | } | 798 | } |
121 | 799 | } | 799 | } |
122 | 800 | 800 | ||
123 | @@ -819,7 +819,7 @@ | |||
124 | 819 | if (d->clients.at(j).usernum == static_cast<int16_t>(i)) | 819 | if (d->clients.at(j).usernum == static_cast<int16_t>(i)) |
125 | 820 | break; | 820 | break; |
126 | 821 | if (j < d->clients.size()) | 821 | if (j < d->clients.size()) |
128 | 822 | d->net->send(d->clients.at(j).sock_id, s); | 822 | d->net->send(d->clients.at(j).sock_id, packet); |
129 | 823 | else | 823 | else |
130 | 824 | // Better no wexception it would break the whole game | 824 | // Better no wexception it would break the whole game |
131 | 825 | log("WARNING: user was found but no client is connected to it!\n"); | 825 | log("WARNING: user was found but no client is connected to it!\n"); |
132 | @@ -904,13 +904,13 @@ | |||
133 | 904 | const std::string& b, | 904 | const std::string& b, |
134 | 905 | const std::string& c) { | 905 | const std::string& c) { |
135 | 906 | // First send to all clients | 906 | // First send to all clients |
143 | 907 | SendPacket s; | 907 | SendPacket packet; |
144 | 908 | s.unsigned_8(NETCMD_SYSTEM_MESSAGE_CODE); | 908 | packet.unsigned_8(NETCMD_SYSTEM_MESSAGE_CODE); |
145 | 909 | s.string(code); | 909 | packet.string(code); |
146 | 910 | s.string(a); | 910 | packet.string(a); |
147 | 911 | s.string(b); | 911 | packet.string(b); |
148 | 912 | s.string(c); | 912 | packet.string(c); |
149 | 913 | broadcast(s); | 913 | broadcast(packet); |
150 | 914 | 914 | ||
151 | 915 | // Now add to our own chatbox | 915 | // Now add to our own chatbox |
152 | 916 | ChatMessage msg(NetworkGamingMessages::get_message(code, a, b, c)); | 916 | ChatMessage msg(NetworkGamingMessages::get_message(code, a, b, c)); |
153 | @@ -967,7 +967,7 @@ | |||
154 | 967 | 967 | ||
155 | 968 | std::vector<PlayerSettings>::size_type oldplayers = d->settings.players.size(); | 968 | std::vector<PlayerSettings>::size_type oldplayers = d->settings.players.size(); |
156 | 969 | 969 | ||
158 | 970 | SendPacket s; | 970 | SendPacket packet; |
159 | 971 | 971 | ||
160 | 972 | // Care about the host | 972 | // Care about the host |
161 | 973 | if (static_cast<int32_t>(maxplayers) <= d->settings.playernum && | 973 | if (static_cast<int32_t>(maxplayers) <= d->settings.playernum && |
162 | @@ -989,11 +989,11 @@ | |||
163 | 989 | d->clients.at(j).playernum = UserSettings::none(); | 989 | d->clients.at(j).playernum = UserSettings::none(); |
164 | 990 | 990 | ||
165 | 991 | // Broadcast change | 991 | // Broadcast change |
171 | 992 | s.reset(); | 992 | packet.reset(); |
172 | 993 | s.unsigned_8(NETCMD_SETTING_USER); | 993 | packet.unsigned_8(NETCMD_SETTING_USER); |
173 | 994 | s.unsigned_32(i); | 994 | packet.unsigned_32(i); |
174 | 995 | write_setting_user(s, i); | 995 | write_setting_user(packet, i); |
175 | 996 | broadcast(s); | 996 | broadcast(packet); |
176 | 997 | } | 997 | } |
177 | 998 | } | 998 | } |
178 | 999 | 999 | ||
179 | @@ -1016,16 +1016,16 @@ | |||
180 | 1016 | } | 1016 | } |
181 | 1017 | 1017 | ||
182 | 1018 | // Broadcast new map info | 1018 | // Broadcast new map info |
187 | 1019 | s.reset(); | 1019 | packet.reset(); |
188 | 1020 | s.unsigned_8(NETCMD_SETTING_MAP); | 1020 | packet.unsigned_8(NETCMD_SETTING_MAP); |
189 | 1021 | write_setting_map(s); | 1021 | write_setting_map(packet); |
190 | 1022 | broadcast(s); | 1022 | broadcast(packet); |
191 | 1023 | 1023 | ||
192 | 1024 | // Broadcast new player settings | 1024 | // Broadcast new player settings |
197 | 1025 | s.reset(); | 1025 | packet.reset(); |
198 | 1026 | s.unsigned_8(NETCMD_SETTING_ALLPLAYERS); | 1026 | packet.unsigned_8(NETCMD_SETTING_ALLPLAYERS); |
199 | 1027 | write_setting_all_players(s); | 1027 | write_setting_all_players(packet); |
200 | 1028 | broadcast(s); | 1028 | broadcast(packet); |
201 | 1029 | 1029 | ||
202 | 1030 | // If possible, offer the map / saved game as transfer | 1030 | // If possible, offer the map / saved game as transfer |
203 | 1031 | // TODO(unknown): not yet able to handle directory type maps / savegames | 1031 | // TODO(unknown): not yet able to handle directory type maps / savegames |
204 | @@ -1060,9 +1060,10 @@ | |||
205 | 1060 | } | 1060 | } |
206 | 1061 | } | 1061 | } |
207 | 1062 | 1062 | ||
211 | 1063 | s.reset(); | 1063 | packet.reset(); |
212 | 1064 | if (write_map_transfer_info(s, mapfilename)) | 1064 | if (write_map_transfer_info(packet, mapfilename)) { |
213 | 1065 | broadcast(s); | 1065 | broadcast(packet); |
214 | 1066 | } | ||
215 | 1066 | } | 1067 | } |
216 | 1067 | 1068 | ||
217 | 1068 | void GameHost::set_player_state(uint8_t const number, | 1069 | void GameHost::set_player_state(uint8_t const number, |
218 | @@ -1138,18 +1139,18 @@ | |||
219 | 1138 | player.name = get_computer_player_name(number); | 1139 | player.name = get_computer_player_name(number); |
220 | 1139 | 1140 | ||
221 | 1140 | // Broadcast change to player | 1141 | // Broadcast change to player |
228 | 1141 | SendPacket s; | 1142 | SendPacket packet; |
229 | 1142 | s.reset(); | 1143 | packet.reset(); |
230 | 1143 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1144 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
231 | 1144 | s.unsigned_8(number); | 1145 | packet.unsigned_8(number); |
232 | 1145 | write_setting_player(s, number); | 1146 | write_setting_player(packet, number); |
233 | 1146 | broadcast(s); | 1147 | broadcast(packet); |
234 | 1147 | 1148 | ||
235 | 1148 | // Let clients know whether their slot has changed | 1149 | // Let clients know whether their slot has changed |
240 | 1149 | s.reset(); | 1150 | packet.reset(); |
241 | 1150 | s.unsigned_8(NETCMD_SETTING_ALLUSERS); | 1151 | packet.unsigned_8(NETCMD_SETTING_ALLUSERS); |
242 | 1151 | write_setting_all_users(s); | 1152 | write_setting_all_users(packet); |
243 | 1152 | broadcast(s); | 1153 | broadcast(packet); |
244 | 1153 | } | 1154 | } |
245 | 1154 | 1155 | ||
246 | 1155 | void GameHost::set_player_tribe(uint8_t const number, | 1156 | void GameHost::set_player_tribe(uint8_t const number, |
247 | @@ -1179,11 +1180,11 @@ | |||
248 | 1179 | player.initialization_index = 0; | 1180 | player.initialization_index = 0; |
249 | 1180 | 1181 | ||
250 | 1181 | // broadcast changes | 1182 | // broadcast changes |
256 | 1182 | SendPacket s; | 1183 | SendPacket packet; |
257 | 1183 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1184 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
258 | 1184 | s.unsigned_8(number); | 1185 | packet.unsigned_8(number); |
259 | 1185 | write_setting_player(s, number); | 1186 | write_setting_player(packet, number); |
260 | 1186 | broadcast(s); | 1187 | broadcast(packet); |
261 | 1187 | return; | 1188 | return; |
262 | 1188 | } | 1189 | } |
263 | 1189 | } | 1190 | } |
264 | @@ -1205,11 +1206,11 @@ | |||
265 | 1205 | player.initialization_index = index; | 1206 | player.initialization_index = index; |
266 | 1206 | 1207 | ||
267 | 1207 | // broadcast changes | 1208 | // broadcast changes |
273 | 1208 | SendPacket s; | 1209 | SendPacket packet; |
274 | 1209 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1210 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
275 | 1210 | s.unsigned_8(number); | 1211 | packet.unsigned_8(number); |
276 | 1211 | write_setting_player(s, number); | 1212 | write_setting_player(packet, number); |
277 | 1212 | broadcast(s); | 1213 | broadcast(packet); |
278 | 1213 | return; | 1214 | return; |
279 | 1214 | } else | 1215 | } else |
280 | 1215 | log("Attempted to change to out-of-range initialization index %u " | 1216 | log("Attempted to change to out-of-range initialization index %u " |
281 | @@ -1230,11 +1231,11 @@ | |||
282 | 1230 | player.random_ai = random_ai; | 1231 | player.random_ai = random_ai; |
283 | 1231 | 1232 | ||
284 | 1232 | // Broadcast changes | 1233 | // Broadcast changes |
290 | 1233 | SendPacket s; | 1234 | SendPacket packet; |
291 | 1234 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1235 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
292 | 1235 | s.unsigned_8(number); | 1236 | packet.unsigned_8(number); |
293 | 1236 | write_setting_player(s, number); | 1237 | write_setting_player(packet, number); |
294 | 1237 | broadcast(s); | 1238 | broadcast(packet); |
295 | 1238 | } | 1239 | } |
296 | 1239 | 1240 | ||
297 | 1240 | void GameHost::set_player_name(uint8_t const number, const std::string& name) { | 1241 | void GameHost::set_player_name(uint8_t const number, const std::string& name) { |
298 | @@ -1249,11 +1250,11 @@ | |||
299 | 1249 | player.name = name; | 1250 | player.name = name; |
300 | 1250 | 1251 | ||
301 | 1251 | // Broadcast changes | 1252 | // Broadcast changes |
307 | 1252 | SendPacket s; | 1253 | SendPacket packet; |
308 | 1253 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1254 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
309 | 1254 | s.unsigned_8(number); | 1255 | packet.unsigned_8(number); |
310 | 1255 | write_setting_player(s, number); | 1256 | write_setting_player(packet, number); |
311 | 1256 | broadcast(s); | 1257 | broadcast(packet); |
312 | 1257 | } | 1258 | } |
313 | 1258 | 1259 | ||
314 | 1259 | void GameHost::set_player_closeable(uint8_t const number, bool closeable) { | 1260 | void GameHost::set_player_closeable(uint8_t const number, bool closeable) { |
315 | @@ -1288,11 +1289,11 @@ | |||
316 | 1288 | player.tribe = sharedplr.tribe; | 1289 | player.tribe = sharedplr.tribe; |
317 | 1289 | 1290 | ||
318 | 1290 | // Broadcast changes | 1291 | // Broadcast changes |
324 | 1291 | SendPacket s; | 1292 | SendPacket packet; |
325 | 1292 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1293 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
326 | 1293 | s.unsigned_8(number); | 1294 | packet.unsigned_8(number); |
327 | 1294 | write_setting_player(s, number); | 1295 | write_setting_player(packet, number); |
328 | 1295 | broadcast(s); | 1296 | broadcast(packet); |
329 | 1296 | } | 1297 | } |
330 | 1297 | 1298 | ||
331 | 1298 | void GameHost::set_player(uint8_t const number, const PlayerSettings& ps) { | 1299 | void GameHost::set_player(uint8_t const number, const PlayerSettings& ps) { |
332 | @@ -1303,11 +1304,11 @@ | |||
333 | 1303 | player = ps; | 1304 | player = ps; |
334 | 1304 | 1305 | ||
335 | 1305 | // Broadcast changes | 1306 | // Broadcast changes |
341 | 1306 | SendPacket s; | 1307 | SendPacket packet; |
342 | 1307 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1308 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
343 | 1308 | s.unsigned_8(number); | 1309 | packet.unsigned_8(number); |
344 | 1309 | write_setting_player(s, number); | 1310 | write_setting_player(packet, number); |
345 | 1310 | broadcast(s); | 1311 | broadcast(packet); |
346 | 1311 | } | 1312 | } |
347 | 1312 | 1313 | ||
348 | 1313 | void GameHost::set_player_number(uint8_t const number) { | 1314 | void GameHost::set_player_number(uint8_t const number) { |
349 | @@ -1318,10 +1319,10 @@ | |||
350 | 1318 | d->settings.win_condition_script = wc; | 1319 | d->settings.win_condition_script = wc; |
351 | 1319 | 1320 | ||
352 | 1320 | // Broadcast changes | 1321 | // Broadcast changes |
357 | 1321 | SendPacket s; | 1322 | SendPacket packet; |
358 | 1322 | s.unsigned_8(NETCMD_WIN_CONDITION); | 1323 | packet.unsigned_8(NETCMD_WIN_CONDITION); |
359 | 1323 | s.string(wc); | 1324 | packet.string(wc); |
360 | 1324 | broadcast(s); | 1325 | broadcast(packet); |
361 | 1325 | } | 1326 | } |
362 | 1326 | 1327 | ||
363 | 1327 | void GameHost::switch_to_player(uint32_t user, uint8_t number) { | 1328 | void GameHost::switch_to_player(uint32_t user, uint8_t number) { |
364 | @@ -1367,11 +1368,11 @@ | |||
365 | 1367 | } | 1368 | } |
366 | 1368 | 1369 | ||
367 | 1369 | // Broadcast the user changes to everybody | 1370 | // Broadcast the user changes to everybody |
373 | 1370 | SendPacket s; | 1371 | SendPacket packet; |
374 | 1371 | s.unsigned_8(NETCMD_SETTING_USER); | 1372 | packet.unsigned_8(NETCMD_SETTING_USER); |
375 | 1372 | s.unsigned_32(user); | 1373 | packet.unsigned_32(user); |
376 | 1373 | write_setting_user(s, user); | 1374 | write_setting_user(packet, user); |
377 | 1374 | broadcast(s); | 1375 | broadcast(packet); |
378 | 1375 | } | 1376 | } |
379 | 1376 | 1377 | ||
380 | 1377 | void GameHost::set_player_team(uint8_t number, Widelands::TeamNumber team) { | 1378 | void GameHost::set_player_team(uint8_t number, Widelands::TeamNumber team) { |
381 | @@ -1380,11 +1381,11 @@ | |||
382 | 1380 | d->settings.players.at(number).team = team; | 1381 | d->settings.players.at(number).team = team; |
383 | 1381 | 1382 | ||
384 | 1382 | // Broadcast changes | 1383 | // Broadcast changes |
390 | 1383 | SendPacket s; | 1384 | SendPacket packet; |
391 | 1384 | s.unsigned_8(NETCMD_SETTING_PLAYER); | 1385 | packet.unsigned_8(NETCMD_SETTING_PLAYER); |
392 | 1385 | s.unsigned_8(number); | 1386 | packet.unsigned_8(number); |
393 | 1386 | write_setting_player(s, number); | 1387 | write_setting_player(packet, number); |
394 | 1387 | broadcast(s); | 1388 | broadcast(packet); |
395 | 1388 | } | 1389 | } |
396 | 1389 | 1390 | ||
397 | 1390 | void GameHost::set_multiplayer_game_settings() { | 1391 | void GameHost::set_multiplayer_game_settings() { |
398 | @@ -1476,11 +1477,11 @@ | |||
399 | 1476 | } | 1477 | } |
400 | 1477 | 1478 | ||
401 | 1478 | /** | 1479 | /** |
403 | 1479 | * If possible, this function writes the MapTransferInfo to SendPacket & s | 1480 | * If possible, this function writes the MapTransferInfo to SendPacket & packet |
404 | 1480 | * | 1481 | * |
405 | 1481 | * \returns true if the data was written, else false | 1482 | * \returns true if the data was written, else false |
406 | 1482 | */ | 1483 | */ |
408 | 1483 | bool GameHost::write_map_transfer_info(SendPacket& s, std::string mapfilename) { | 1484 | bool GameHost::write_map_transfer_info(SendPacket& packet, std::string mapfilename) { |
409 | 1484 | // TODO(unknown): not yet able to handle directory type maps / savegames | 1485 | // TODO(unknown): not yet able to handle directory type maps / savegames |
410 | 1485 | if (g_fs->is_directory(mapfilename)) { | 1486 | if (g_fs->is_directory(mapfilename)) { |
411 | 1486 | log("Map/Save is a directory! No way for making it available a.t.m.!\n"); | 1487 | log("Map/Save is a directory! No way for making it available a.t.m.!\n"); |
412 | @@ -1489,13 +1490,13 @@ | |||
413 | 1489 | 1490 | ||
414 | 1490 | // Write the new map/save file information, so client can decide whether it | 1491 | // Write the new map/save file information, so client can decide whether it |
415 | 1491 | // needs the file. | 1492 | // needs the file. |
418 | 1492 | s.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); | 1493 | packet.unsigned_8(NETCMD_NEW_FILE_AVAILABLE); |
419 | 1493 | s.string(mapfilename); | 1494 | packet.string(mapfilename); |
420 | 1494 | // Scan-build reports that access to bytes here results in a dereference of null pointer. | 1495 | // Scan-build reports that access to bytes here results in a dereference of null pointer. |
421 | 1495 | // This is a false positive. | 1496 | // This is a false positive. |
422 | 1496 | // See https://bugs.launchpad.net/widelands/+bug/1198919 | 1497 | // See https://bugs.launchpad.net/widelands/+bug/1198919 |
425 | 1497 | s.unsigned_32(file_->bytes); // NOLINT | 1498 | packet.unsigned_32(file_->bytes); // NOLINT |
426 | 1498 | s.string(file_->md5sum); | 1499 | packet.string(file_->md5sum); |
427 | 1499 | return true; | 1500 | return true; |
428 | 1500 | } | 1501 | } |
429 | 1501 | 1502 | ||
430 | @@ -1579,62 +1580,63 @@ | |||
431 | 1579 | 1580 | ||
432 | 1580 | log("[Host]: Client %u: welcome to usernum %u\n", number, client.usernum); | 1581 | log("[Host]: Client %u: welcome to usernum %u\n", number, client.usernum); |
433 | 1581 | 1582 | ||
439 | 1582 | SendPacket s; | 1583 | SendPacket packet; |
440 | 1583 | s.unsigned_8(NETCMD_HELLO); | 1584 | packet.unsigned_8(NETCMD_HELLO); |
441 | 1584 | s.unsigned_8(NETWORK_PROTOCOL_VERSION); | 1585 | packet.unsigned_8(NETWORK_PROTOCOL_VERSION); |
442 | 1585 | s.unsigned_32(client.usernum); | 1586 | packet.unsigned_32(client.usernum); |
443 | 1586 | d->net->send(client.sock_id, s); | 1587 | d->net->send(client.sock_id, packet); |
444 | 1587 | // even if the network protocol is the same, the data might be different. | 1588 | // even if the network protocol is the same, the data might be different. |
445 | 1588 | if (client.build_id != build_id()) | 1589 | if (client.build_id != build_id()) |
446 | 1589 | send_system_message_code("DIFFERENT_WL_VERSION", effective_name, client.build_id, build_id()); | 1590 | send_system_message_code("DIFFERENT_WL_VERSION", effective_name, client.build_id, build_id()); |
447 | 1590 | // Send information about currently selected map / savegame | 1591 | // Send information about currently selected map / savegame |
449 | 1591 | s.reset(); | 1592 | packet.reset(); |
450 | 1592 | 1593 | ||
454 | 1593 | s.unsigned_8(NETCMD_SETTING_MAP); | 1594 | packet.unsigned_8(NETCMD_SETTING_MAP); |
455 | 1594 | write_setting_map(s); | 1595 | write_setting_map(packet); |
456 | 1595 | d->net->send(client.sock_id, s); | 1596 | d->net->send(client.sock_id, packet); |
457 | 1596 | 1597 | ||
458 | 1597 | // If possible, offer the map / savegame as transfer | 1598 | // If possible, offer the map / savegame as transfer |
459 | 1598 | if (file_) { | 1599 | if (file_) { |
463 | 1599 | s.reset(); | 1600 | packet.reset(); |
464 | 1600 | if (write_map_transfer_info(s, file_->filename)) | 1601 | if (write_map_transfer_info(packet, file_->filename)) { |
465 | 1601 | d->net->send(client.sock_id, s); | 1602 | d->net->send(client.sock_id, packet); |
466 | 1603 | } | ||
467 | 1602 | } | 1604 | } |
468 | 1603 | 1605 | ||
469 | 1604 | // Send the tribe information to the new client. | 1606 | // Send the tribe information to the new client. |
473 | 1605 | s.reset(); | 1607 | packet.reset(); |
474 | 1606 | s.unsigned_8(NETCMD_SETTING_TRIBES); | 1608 | packet.unsigned_8(NETCMD_SETTING_TRIBES); |
475 | 1607 | s.unsigned_8(d->settings.tribes.size()); | 1609 | packet.unsigned_8(d->settings.tribes.size()); |
476 | 1608 | for (const TribeBasicInfo& tribe : d->settings.tribes) { | 1610 | for (const TribeBasicInfo& tribe : d->settings.tribes) { |
478 | 1609 | s.string(tribe.name); | 1611 | packet.string(tribe.name); |
479 | 1610 | size_t const nr_initializations = tribe.initializations.size(); | 1612 | size_t const nr_initializations = tribe.initializations.size(); |
481 | 1611 | s.unsigned_8(nr_initializations); | 1613 | packet.unsigned_8(nr_initializations); |
482 | 1612 | for (const TribeBasicInfo::Initialization& init : tribe.initializations) | 1614 | for (const TribeBasicInfo::Initialization& init : tribe.initializations) |
484 | 1613 | s.string(init.script); | 1615 | packet.string(init.script); |
485 | 1614 | } | 1616 | } |
502 | 1615 | d->net->send(client.sock_id, s); | 1617 | d->net->send(client.sock_id, packet); |
503 | 1616 | 1618 | ||
504 | 1617 | s.reset(); | 1619 | packet.reset(); |
505 | 1618 | s.unsigned_8(NETCMD_SETTING_ALLPLAYERS); | 1620 | packet.unsigned_8(NETCMD_SETTING_ALLPLAYERS); |
506 | 1619 | write_setting_all_players(s); | 1621 | write_setting_all_players(packet); |
507 | 1620 | d->net->send(client.sock_id, s); | 1622 | d->net->send(client.sock_id, packet); |
508 | 1621 | 1623 | ||
509 | 1622 | s.reset(); | 1624 | packet.reset(); |
510 | 1623 | s.unsigned_8(NETCMD_SETTING_ALLUSERS); | 1625 | packet.unsigned_8(NETCMD_SETTING_ALLUSERS); |
511 | 1624 | write_setting_all_users(s); | 1626 | write_setting_all_users(packet); |
512 | 1625 | d->net->send(client.sock_id, s); | 1627 | d->net->send(client.sock_id, packet); |
513 | 1626 | 1628 | ||
514 | 1627 | s.reset(); | 1629 | packet.reset(); |
515 | 1628 | s.unsigned_8(NETCMD_WIN_CONDITION); | 1630 | packet.unsigned_8(NETCMD_WIN_CONDITION); |
516 | 1629 | s.string(d->settings.win_condition_script); | 1631 | packet.string(d->settings.win_condition_script); |
517 | 1630 | d->net->send(client.sock_id, s); | 1632 | d->net->send(client.sock_id, packet); |
518 | 1631 | 1633 | ||
519 | 1632 | // Broadcast new information about the player to everybody | 1634 | // Broadcast new information about the player to everybody |
525 | 1633 | s.reset(); | 1635 | packet.reset(); |
526 | 1634 | s.unsigned_8(NETCMD_SETTING_USER); | 1636 | packet.unsigned_8(NETCMD_SETTING_USER); |
527 | 1635 | s.unsigned_32(client.usernum); | 1637 | packet.unsigned_32(client.usernum); |
528 | 1636 | write_setting_user(s, client.usernum); | 1638 | write_setting_user(packet, client.usernum); |
529 | 1637 | broadcast(s); | 1639 | broadcast(packet); |
530 | 1638 | 1640 | ||
531 | 1639 | // Check if there is an unoccupied player left and if, assign. | 1641 | // Check if there is an unoccupied player left and if, assign. |
532 | 1640 | for (uint8_t i = 0; i < d->settings.players.size(); ++i) | 1642 | for (uint8_t i = 0; i < d->settings.players.size(); ++i) |
533 | @@ -1731,9 +1733,9 @@ | |||
534 | 1731 | d->waiting = true; | 1733 | d->waiting = true; |
535 | 1732 | broadcast_real_speed(0); | 1734 | broadcast_real_speed(0); |
536 | 1733 | 1735 | ||
540 | 1734 | SendPacket s; | 1736 | SendPacket packet; |
541 | 1735 | s.unsigned_8(NETCMD_WAIT); | 1737 | packet.unsigned_8(NETCMD_WAIT); |
542 | 1736 | broadcast(s); | 1738 | broadcast(packet); |
543 | 1737 | } | 1739 | } |
544 | 1738 | } else { | 1740 | } else { |
545 | 1739 | if (nrdelayed == 0) { | 1741 | if (nrdelayed == 0) { |
546 | @@ -1748,10 +1750,10 @@ | |||
547 | 1748 | void GameHost::broadcast_real_speed(uint32_t const speed) { | 1750 | void GameHost::broadcast_real_speed(uint32_t const speed) { |
548 | 1749 | assert(speed <= std::numeric_limits<uint16_t>::max()); | 1751 | assert(speed <= std::numeric_limits<uint16_t>::max()); |
549 | 1750 | 1752 | ||
554 | 1751 | SendPacket s; | 1753 | SendPacket packet; |
555 | 1752 | s.unsigned_8(NETCMD_SETSPEED); | 1754 | packet.unsigned_8(NETCMD_SETSPEED); |
556 | 1753 | s.unsigned_16(speed); | 1755 | packet.unsigned_16(speed); |
557 | 1754 | broadcast(s); | 1756 | broadcast(packet); |
558 | 1755 | } | 1757 | } |
559 | 1756 | 1758 | ||
560 | 1757 | /** | 1759 | /** |
561 | @@ -1829,10 +1831,10 @@ | |||
562 | 1829 | 1831 | ||
563 | 1830 | log("[Host]: Requesting sync reports for time %i\n", d->syncreport_time); | 1832 | log("[Host]: Requesting sync reports for time %i\n", d->syncreport_time); |
564 | 1831 | 1833 | ||
569 | 1832 | SendPacket s; | 1834 | SendPacket packet; |
570 | 1833 | s.unsigned_8(NETCMD_SYNCREQUEST); | 1835 | packet.unsigned_8(NETCMD_SYNCREQUEST); |
571 | 1834 | s.signed_32(d->syncreport_time); | 1836 | packet.signed_32(d->syncreport_time); |
572 | 1835 | broadcast(s); | 1837 | broadcast(packet); |
573 | 1836 | 1838 | ||
574 | 1837 | d->game->enqueue_command( | 1839 | d->game->enqueue_command( |
575 | 1838 | new CmdNetCheckSync(d->syncreport_time, [this] { sync_report_callback(); })); | 1840 | new CmdNetCheckSync(d->syncreport_time, [this] { sync_report_callback(); })); |
576 | @@ -1870,9 +1872,9 @@ | |||
577 | 1870 | 1872 | ||
578 | 1871 | d->game->save_syncstream(true); | 1873 | d->game->save_syncstream(true); |
579 | 1872 | 1874 | ||
583 | 1873 | SendPacket s; | 1875 | SendPacket packet; |
584 | 1874 | s.unsigned_8(NETCMD_INFO_DESYNC); | 1876 | packet.unsigned_8(NETCMD_INFO_DESYNC); |
585 | 1875 | broadcast(s); | 1877 | broadcast(packet); |
586 | 1876 | 1878 | ||
587 | 1877 | disconnect_client(i, "CLIENT_DESYNCED"); | 1879 | disconnect_client(i, "CLIENT_DESYNCED"); |
588 | 1878 | // Pause the game, so that host and client have time to handle the | 1880 | // Pause the game, so that host and client have time to handle the |
589 | @@ -1948,9 +1950,9 @@ | |||
590 | 1948 | if ((forced_pause_ || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { | 1950 | if ((forced_pause_ || real_speed() == 0) && (time(nullptr) > (d->lastpauseping + 20))) { |
591 | 1949 | d->lastpauseping = time(nullptr); | 1951 | d->lastpauseping = time(nullptr); |
592 | 1950 | 1952 | ||
596 | 1951 | SendPacket s; | 1953 | SendPacket send_packet; |
597 | 1952 | s.unsigned_8(NETCMD_PING); | 1954 | send_packet.unsigned_8(NETCMD_PING); |
598 | 1953 | broadcast(s); | 1955 | broadcast(send_packet); |
599 | 1954 | } | 1956 | } |
600 | 1955 | 1957 | ||
601 | 1956 | reaper(); | 1958 | reaper(); |
602 | @@ -1984,9 +1986,9 @@ | |||
603 | 1984 | if (cmd == NETCMD_METASERVER_PING) { | 1986 | if (cmd == NETCMD_METASERVER_PING) { |
604 | 1985 | log("[Host]: Received ping from metaserver.\n"); | 1987 | log("[Host]: Received ping from metaserver.\n"); |
605 | 1986 | // Send PING back | 1988 | // Send PING back |
609 | 1987 | SendPacket s; | 1989 | SendPacket packet; |
610 | 1988 | s.unsigned_8(NETCMD_METASERVER_PING); | 1990 | packet.unsigned_8(NETCMD_METASERVER_PING); |
611 | 1989 | d->net->send(client.sock_id, s); | 1991 | d->net->send(client.sock_id, packet); |
612 | 1990 | 1992 | ||
613 | 1991 | // Remove metaserver from list of clients | 1993 | // Remove metaserver from list of clients |
614 | 1992 | client.playernum = UserSettings::not_connected(); | 1994 | client.playernum = UserSettings::not_connected(); |
615 | @@ -2155,11 +2157,11 @@ | |||
616 | 2155 | send_file_part(client.sock_id, 0); | 2157 | send_file_part(client.sock_id, 0); |
617 | 2156 | // Remember client as "currently receiving file" | 2158 | // Remember client as "currently receiving file" |
618 | 2157 | d->settings.users[client.usernum].ready = false; | 2159 | d->settings.users[client.usernum].ready = false; |
624 | 2158 | SendPacket s; | 2160 | SendPacket packet; |
625 | 2159 | s.unsigned_8(NETCMD_SETTING_USER); | 2161 | packet.unsigned_8(NETCMD_SETTING_USER); |
626 | 2160 | s.unsigned_32(client.usernum); | 2162 | packet.unsigned_32(client.usernum); |
627 | 2161 | write_setting_user(s, client.usernum); | 2163 | write_setting_user(packet, client.usernum); |
628 | 2162 | broadcast(s); | 2164 | broadcast(packet); |
629 | 2163 | break; | 2165 | break; |
630 | 2164 | } | 2166 | } |
631 | 2165 | 2167 | ||
632 | @@ -2179,11 +2181,11 @@ | |||
633 | 2179 | send_system_message_code( | 2181 | send_system_message_code( |
634 | 2180 | "COMPLETED_FILE_TRANSFER", file_->filename, d->settings.users.at(client.usernum).name); | 2182 | "COMPLETED_FILE_TRANSFER", file_->filename, d->settings.users.at(client.usernum).name); |
635 | 2181 | d->settings.users[client.usernum].ready = true; | 2183 | d->settings.users[client.usernum].ready = true; |
641 | 2182 | SendPacket s; | 2184 | SendPacket packet; |
642 | 2183 | s.unsigned_8(NETCMD_SETTING_USER); | 2185 | packet.unsigned_8(NETCMD_SETTING_USER); |
643 | 2184 | s.unsigned_32(client.usernum); | 2186 | packet.unsigned_32(client.usernum); |
644 | 2185 | write_setting_user(s, client.usernum); | 2187 | write_setting_user(packet, client.usernum); |
645 | 2186 | broadcast(s); | 2188 | broadcast(packet); |
646 | 2187 | return; | 2189 | return; |
647 | 2188 | } | 2190 | } |
648 | 2189 | ++part; | 2191 | ++part; |
649 | @@ -2207,12 +2209,12 @@ | |||
650 | 2207 | uint32_t size = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; | 2209 | uint32_t size = (left > NETFILEPARTSIZE) ? NETFILEPARTSIZE : left; |
651 | 2208 | 2210 | ||
652 | 2209 | // Send the part | 2211 | // Send the part |
659 | 2210 | SendPacket s; | 2212 | SendPacket packet; |
660 | 2211 | s.unsigned_8(NETCMD_FILE_PART); | 2213 | packet.unsigned_8(NETCMD_FILE_PART); |
661 | 2212 | s.unsigned_32(part); | 2214 | packet.unsigned_32(part); |
662 | 2213 | s.unsigned_32(size); | 2215 | packet.unsigned_32(size); |
663 | 2214 | s.data(file_->parts[part].part, size); | 2216 | packet.data(file_->parts[part].part, size); |
664 | 2215 | d->net->send(csock_id, s); | 2217 | d->net->send(csock_id, packet); |
665 | 2216 | } | 2218 | } |
666 | 2217 | 2219 | ||
667 | 2218 | void GameHost::disconnect_player_controller(uint8_t const number, const std::string& name) { | 2220 | void GameHost::disconnect_player_controller(uint8_t const number, const std::string& name) { |
668 | @@ -2265,11 +2267,11 @@ | |||
669 | 2265 | send_system_message_code( | 2267 | send_system_message_code( |
670 | 2266 | "CLIENT_X_LEFT_GAME", d->settings.users.at(client.usernum).name, reason, arg); | 2268 | "CLIENT_X_LEFT_GAME", d->settings.users.at(client.usernum).name, reason, arg); |
671 | 2267 | 2269 | ||
677 | 2268 | SendPacket s; | 2270 | SendPacket packet; |
678 | 2269 | s.unsigned_8(NETCMD_SETTING_USER); | 2271 | packet.unsigned_8(NETCMD_SETTING_USER); |
679 | 2270 | s.unsigned_32(client.usernum); | 2272 | packet.unsigned_32(client.usernum); |
680 | 2271 | write_setting_user(s, client.usernum); | 2273 | write_setting_user(packet, client.usernum); |
681 | 2272 | broadcast(s); | 2274 | broadcast(packet); |
682 | 2273 | } else | 2275 | } else |
683 | 2274 | send_system_message_code("UNKNOWN_LEFT_GAME", reason, arg); | 2276 | send_system_message_code("UNKNOWN_LEFT_GAME", reason, arg); |
684 | 2275 | 2277 | ||
685 | @@ -2277,13 +2279,14 @@ | |||
686 | 2277 | 2279 | ||
687 | 2278 | if (client.sock_id > 0) { | 2280 | if (client.sock_id > 0) { |
688 | 2279 | if (sendreason) { | 2281 | if (sendreason) { |
696 | 2280 | SendPacket s; | 2282 | SendPacket packet; |
697 | 2281 | s.unsigned_8(NETCMD_DISCONNECT); | 2283 | packet.unsigned_8(NETCMD_DISCONNECT); |
698 | 2282 | s.unsigned_8(arg.empty() ? 1 : 2); | 2284 | packet.unsigned_8(arg.empty() ? 1 : 2); |
699 | 2283 | s.string(reason); | 2285 | packet.string(reason); |
700 | 2284 | if (!arg.empty()) | 2286 | if (!arg.empty()) { |
701 | 2285 | s.string(arg); | 2287 | packet.string(arg); |
702 | 2286 | d->net->send(client.sock_id, s); | 2288 | } |
703 | 2289 | d->net->send(client.sock_id, packet); | ||
704 | 2287 | } | 2290 | } |
705 | 2288 | 2291 | ||
706 | 2289 | d->net->close(client.sock_id); | 2292 | d->net->close(client.sock_id); |
707 | 2290 | 2293 | ||
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 | 61 | // Name needs to be initialized after the dropdown, otherwise the layout function will | 61 | // Name needs to be initialized after the dropdown, otherwise the layout function will |
713 | 62 | // crash. | 62 | // crash. |
714 | 63 | name(this, 0, 0, w - h - UI::Scrollbar::kSize * 11 / 5, h), | 63 | name(this, 0, 0, w - h - UI::Scrollbar::kSize * 11 / 5, h), |
716 | 64 | s(settings), | 64 | settings_(settings), |
717 | 65 | id_(id), | 65 | id_(id), |
718 | 66 | slot_selection_locked_(false) { | 66 | slot_selection_locked_(false) { |
719 | 67 | set_size(w, h); | 67 | set_size(w, h); |
720 | @@ -106,7 +106,7 @@ | |||
721 | 106 | /// This will update the client's player slot with the value currently selected in the slot | 106 | /// This will update the client's player slot with the value currently selected in the slot |
722 | 107 | /// dropdown. | 107 | /// dropdown. |
723 | 108 | void set_slot() { | 108 | void set_slot() { |
725 | 109 | const GameSettings& settings = s->settings(); | 109 | const GameSettings& settings = settings_->settings(); |
726 | 110 | if (id_ != settings.usernum) { | 110 | if (id_ != settings.usernum) { |
727 | 111 | return; | 111 | return; |
728 | 112 | } | 112 | } |
729 | @@ -114,7 +114,7 @@ | |||
730 | 114 | if (slot_dropdown_.has_selection()) { | 114 | if (slot_dropdown_.has_selection()) { |
731 | 115 | const uint8_t new_slot = slot_dropdown_.get_selected(); | 115 | const uint8_t new_slot = slot_dropdown_.get_selected(); |
732 | 116 | if (new_slot != settings.users.at(id_).position) { | 116 | if (new_slot != settings.users.at(id_).position) { |
734 | 117 | s->set_player_number(slot_dropdown_.get_selected()); | 117 | settings_->set_player_number(slot_dropdown_.get_selected()); |
735 | 118 | } | 118 | } |
736 | 119 | } | 119 | } |
737 | 120 | slot_selection_locked_ = false; | 120 | slot_selection_locked_ = false; |
738 | @@ -147,7 +147,7 @@ | |||
739 | 147 | 147 | ||
740 | 148 | /// Take care of visibility and current values | 148 | /// Take care of visibility and current values |
741 | 149 | void update() { | 149 | void update() { |
743 | 150 | const GameSettings& settings = s->settings(); | 150 | const GameSettings& settings = settings_->settings(); |
744 | 151 | const UserSettings& user_setting = settings.users.at(id_); | 151 | const UserSettings& user_setting = settings.users.at(id_); |
745 | 152 | 152 | ||
746 | 153 | if (user_setting.position == UserSettings::not_connected()) { | 153 | if (user_setting.position == UserSettings::not_connected()) { |
747 | @@ -161,7 +161,7 @@ | |||
748 | 161 | 161 | ||
749 | 162 | UI::Dropdown<uintptr_t> slot_dropdown_; /// Select the player slot. | 162 | UI::Dropdown<uintptr_t> slot_dropdown_; /// Select the player slot. |
750 | 163 | UI::Textarea name; /// Client nick name | 163 | UI::Textarea name; /// Client nick name |
752 | 164 | GameSettingsProvider* const s; | 164 | GameSettingsProvider* const settings_; |
753 | 165 | uint8_t const id_; /// User number | 165 | uint8_t const id_; /// User number |
754 | 166 | bool slot_selection_locked_; // Ensure that dropdowns will close on selection. | 166 | bool slot_selection_locked_; // Ensure that dropdowns will close on selection. |
755 | 167 | std::unique_ptr<Notifications::Subscriber<NoteGameSettings>> subscriber_; | 167 | std::unique_ptr<Notifications::Subscriber<NoteGameSettings>> subscriber_; |
756 | @@ -176,7 +176,7 @@ | |||
757 | 176 | GameSettingsProvider* const settings, | 176 | GameSettingsProvider* const settings, |
758 | 177 | NetworkPlayerSettingsBackend* const npsb) | 177 | NetworkPlayerSettingsBackend* const npsb) |
759 | 178 | : UI::Box(parent, 0, 0, UI::Box::Horizontal, w, h, kPadding / 2), | 178 | : UI::Box(parent, 0, 0, UI::Box::Horizontal, w, h, kPadding / 2), |
761 | 179 | s(settings), | 179 | settings_(settings), |
762 | 180 | n(npsb), | 180 | n(npsb), |
763 | 181 | id_(id), | 181 | id_(id), |
764 | 182 | player(this, | 182 | player(this, |
765 | @@ -227,23 +227,26 @@ | |||
766 | 227 | add_space(0); | 227 | add_space(0); |
767 | 228 | 228 | ||
768 | 229 | subscriber_ = | 229 | subscriber_ = |
786 | 230 | Notifications::subscribe<NoteGameSettings>([this](const NoteGameSettings& note) { | 230 | Notifications::subscribe<NoteGameSettings>( |
787 | 231 | switch (note.action) { | 231 | [this](const NoteGameSettings& note) { |
788 | 232 | case NoteGameSettings::Action::kMap: | 232 | const std::vector<PlayerSettings> & players = settings_->settings().players; |
789 | 233 | // We don't care about map updates, since we receive enough notifications for the | 233 | switch (note.action) { |
790 | 234 | // slots. | 234 | case NoteGameSettings::Action::kMap: |
791 | 235 | break; | 235 | // We don't care about map updates, since we receive enough notifications for the |
792 | 236 | default: | 236 | // slots. |
793 | 237 | if (s->settings().players.empty()) { | 237 | break; |
794 | 238 | // No map/savegame yet | 238 | default: |
795 | 239 | return; | 239 | if (players.empty()) { |
796 | 240 | } | 240 | // No map/savegame yet |
797 | 241 | if (id_ == note.position || | 241 | return; |
798 | 242 | s->settings().players[id_].state == PlayerSettings::State::kShared) { | 242 | } |
799 | 243 | update(); | 243 | if (id_ == note.position || |
800 | 244 | } | 244 | (id_ < players.size() && |
801 | 245 | } | 245 | players.at(id_).state == PlayerSettings::State::kShared)) { |
802 | 246 | }); | 246 | update(); |
803 | 247 | } | ||
804 | 248 | } | ||
805 | 249 | }); | ||
806 | 247 | 250 | ||
807 | 248 | // Init dropdowns | 251 | // Init dropdowns |
808 | 249 | update(); | 252 | update(); |
809 | @@ -263,7 +266,7 @@ | |||
810 | 263 | /// This will update the game settings for the type with the value | 266 | /// This will update the game settings for the type with the value |
811 | 264 | /// currently selected in the type dropdown. | 267 | /// currently selected in the type dropdown. |
812 | 265 | void set_type() { | 268 | void set_type() { |
814 | 266 | if (!s->can_change_player_state(id_)) { | 269 | if (!settings_->can_change_player_state(id_)) { |
815 | 267 | return; | 270 | return; |
816 | 268 | } | 271 | } |
817 | 269 | type_selection_locked_ = true; | 272 | type_selection_locked_ = true; |
818 | @@ -328,7 +331,7 @@ | |||
819 | 328 | type_dropdown_.add( | 331 | type_dropdown_.add( |
820 | 329 | _("Open"), "open", g_gr->images().get("images/ui_basic/continue.png"), false, _("Open")); | 332 | _("Open"), "open", g_gr->images().get("images/ui_basic/continue.png"), false, _("Open")); |
821 | 330 | 333 | ||
823 | 331 | type_dropdown_.set_enabled(s->can_change_player_state(id_)); | 334 | type_dropdown_.set_enabled(settings_->can_change_player_state(id_)); |
824 | 332 | 335 | ||
825 | 333 | // Now select the entry according to server settings | 336 | // Now select the entry according to server settings |
826 | 334 | const PlayerSettings& player_setting = settings.players[id_]; | 337 | const PlayerSettings& player_setting = settings.players[id_]; |
827 | @@ -360,9 +363,9 @@ | |||
828 | 360 | 363 | ||
829 | 361 | /// Whether the client who is running the UI is allowed to change the tribe for this player slot. | 364 | /// Whether the client who is running the UI is allowed to change the tribe for this player slot. |
830 | 362 | bool has_tribe_access() { | 365 | bool has_tribe_access() { |
834 | 363 | return s->settings().players[id_].state == PlayerSettings::State::kShared ? | 366 | return settings_->settings().players[id_].state == PlayerSettings::State::kShared ? |
835 | 364 | s->can_change_player_init(id_) : | 367 | settings_->can_change_player_init(id_) : |
836 | 365 | s->can_change_player_tribe(id_); | 368 | settings_->can_change_player_tribe(id_); |
837 | 366 | } | 369 | } |
838 | 367 | 370 | ||
839 | 368 | /// This will update the game settings for the tribe or shared_in with the value | 371 | /// This will update the game settings for the tribe or shared_in with the value |
840 | @@ -371,7 +374,7 @@ | |||
841 | 371 | if (!has_tribe_access()) { | 374 | if (!has_tribe_access()) { |
842 | 372 | return; | 375 | return; |
843 | 373 | } | 376 | } |
845 | 374 | const PlayerSettings& player_settings = s->settings().players[id_]; | 377 | const PlayerSettings& player_settings = settings_->settings().players[id_]; |
846 | 375 | tribe_selection_locked_ = true; | 378 | tribe_selection_locked_ = true; |
847 | 376 | tribes_dropdown_.set_disable_style(player_settings.state == PlayerSettings::State::kShared ? | 379 | tribes_dropdown_.set_disable_style(player_settings.state == PlayerSettings::State::kShared ? |
848 | 377 | UI::ButtonDisableStyle::kPermpressed : | 380 | UI::ButtonDisableStyle::kPermpressed : |
849 | @@ -451,7 +454,7 @@ | |||
850 | 451 | /// This will update the game settings for the initialization with the value | 454 | /// This will update the game settings for the initialization with the value |
851 | 452 | /// currently selected in the initialization dropdown. | 455 | /// currently selected in the initialization dropdown. |
852 | 453 | void set_init() { | 456 | void set_init() { |
854 | 454 | if (!s->can_change_player_init(id_)) { | 457 | if (!settings_->can_change_player_init(id_)) { |
855 | 455 | return; | 458 | return; |
856 | 456 | } | 459 | } |
857 | 457 | init_selection_locked_ = true; | 460 | init_selection_locked_ = true; |
858 | @@ -487,7 +490,7 @@ | |||
859 | 487 | } | 490 | } |
860 | 488 | 491 | ||
861 | 489 | init_dropdown_.set_visible(true); | 492 | init_dropdown_.set_visible(true); |
863 | 490 | init_dropdown_.set_enabled(s->can_change_player_init(id_)); | 493 | init_dropdown_.set_enabled(settings_->can_change_player_init(id_)); |
864 | 491 | } | 494 | } |
865 | 492 | 495 | ||
866 | 493 | /// This will update the team settings with the value currently selected in the teams dropdown. | 496 | /// This will update the team settings with the value currently selected in the teams dropdown. |
867 | @@ -524,12 +527,12 @@ | |||
868 | 524 | } | 527 | } |
869 | 525 | team_dropdown_.select(player_setting.team); | 528 | team_dropdown_.select(player_setting.team); |
870 | 526 | team_dropdown_.set_visible(true); | 529 | team_dropdown_.set_visible(true); |
872 | 527 | team_dropdown_.set_enabled(s->can_change_player_team(id_)); | 530 | team_dropdown_.set_enabled(settings_->can_change_player_team(id_)); |
873 | 528 | } | 531 | } |
874 | 529 | 532 | ||
875 | 530 | /// Refresh all user interfaces | 533 | /// Refresh all user interfaces |
876 | 531 | void update() { | 534 | void update() { |
878 | 532 | const GameSettings& settings = s->settings(); | 535 | const GameSettings& settings = settings_->settings(); |
879 | 533 | if (id_ >= settings.players.size()) { | 536 | if (id_ >= settings.players.size()) { |
880 | 534 | set_visible(false); | 537 | set_visible(false); |
881 | 535 | return; | 538 | return; |
882 | @@ -556,7 +559,7 @@ | |||
883 | 556 | // Trigger update for the other players for shared_in mode when slots open and close | 559 | // Trigger update for the other players for shared_in mode when slots open and close |
884 | 557 | if (last_state_ != player_setting.state) { | 560 | if (last_state_ != player_setting.state) { |
885 | 558 | last_state_ = player_setting.state; | 561 | last_state_ = player_setting.state; |
887 | 559 | for (PlayerSlot slot = 0; slot < s->settings().players.size(); ++slot) { | 562 | for (PlayerSlot slot = 0; slot < settings_->settings().players.size(); ++slot) { |
888 | 560 | if (slot != id_) { | 563 | if (slot != id_) { |
889 | 561 | n->set_player_state(slot, settings.players[slot].state); | 564 | n->set_player_state(slot, settings.players[slot].state); |
890 | 562 | } | 565 | } |
891 | @@ -564,7 +567,7 @@ | |||
892 | 564 | } | 567 | } |
893 | 565 | } | 568 | } |
894 | 566 | 569 | ||
896 | 567 | GameSettingsProvider* const s; | 570 | GameSettingsProvider* const settings_; |
897 | 568 | NetworkPlayerSettingsBackend* const n; | 571 | NetworkPlayerSettingsBackend* const n; |
898 | 569 | PlayerSlot const id_; | 572 | PlayerSlot const id_; |
899 | 570 | 573 | ||
900 | @@ -594,8 +597,8 @@ | |||
901 | 594 | GameSettingsProvider* const settings, | 597 | GameSettingsProvider* const settings, |
902 | 595 | uint32_t buth) | 598 | uint32_t buth) |
903 | 596 | : UI::Box(parent, x, y, UI::Box::Horizontal, w, h, 8 * kPadding), | 599 | : UI::Box(parent, x, y, UI::Box::Horizontal, w, h, 8 * kPadding), |
906 | 597 | s(settings), | 600 | settings_(settings), |
907 | 598 | npsb(new NetworkPlayerSettingsBackend(s)), | 601 | npsb(new NetworkPlayerSettingsBackend(settings_)), |
908 | 599 | clientbox(this, 0, 0, UI::Box::Vertical), | 602 | clientbox(this, 0, 0, UI::Box::Vertical), |
909 | 600 | playerbox(this, 0, 0, UI::Box::Vertical, w * 9 / 15, h, kPadding), | 603 | playerbox(this, 0, 0, UI::Box::Vertical, w * 9 / 15, h, kPadding), |
910 | 601 | buth_(buth) { | 604 | buth_(buth) { |
911 | @@ -611,7 +614,7 @@ | |||
912 | 611 | multi_player_player_groups.resize(kMaxPlayers); | 614 | multi_player_player_groups.resize(kMaxPlayers); |
913 | 612 | for (PlayerSlot i = 0; i < multi_player_player_groups.size(); ++i) { | 615 | for (PlayerSlot i = 0; i < multi_player_player_groups.size(); ++i) { |
914 | 613 | multi_player_player_groups.at(i) = | 616 | multi_player_player_groups.at(i) = |
916 | 614 | new MultiPlayerPlayerGroup(&playerbox, playerbox.get_w(), buth_, i, s, npsb.get()); | 617 | new MultiPlayerPlayerGroup(&playerbox, playerbox.get_w(), buth_, i, settings, npsb.get()); |
917 | 615 | playerbox.add(multi_player_player_groups.at(i)); | 618 | playerbox.add(multi_player_player_groups.at(i)); |
918 | 616 | } | 619 | } |
919 | 617 | playerbox.add_space(0); | 620 | playerbox.add_space(0); |
920 | @@ -627,7 +630,7 @@ | |||
921 | 627 | 630 | ||
922 | 628 | /// Update which slots are available based on current settings. | 631 | /// Update which slots are available based on current settings. |
923 | 629 | void MultiPlayerSetupGroup::update() { | 632 | void MultiPlayerSetupGroup::update() { |
925 | 630 | const GameSettings& settings = s->settings(); | 633 | const GameSettings& settings = settings_->settings(); |
926 | 631 | 634 | ||
927 | 632 | // Update / initialize client groups | 635 | // Update / initialize client groups |
928 | 633 | if (multi_player_client_groups.size() < settings.users.size()) { | 636 | if (multi_player_client_groups.size() < settings.users.size()) { |
929 | @@ -636,7 +639,7 @@ | |||
930 | 636 | for (uint32_t i = 0; i < settings.users.size(); ++i) { | 639 | for (uint32_t i = 0; i < settings.users.size(); ++i) { |
931 | 637 | if (!multi_player_client_groups.at(i)) { | 640 | if (!multi_player_client_groups.at(i)) { |
932 | 638 | multi_player_client_groups.at(i) = | 641 | multi_player_client_groups.at(i) = |
934 | 639 | new MultiPlayerClientGroup(&clientbox, clientbox.get_w(), buth_, i, s); | 642 | new MultiPlayerClientGroup(&clientbox, clientbox.get_w(), buth_, i, settings_); |
935 | 640 | clientbox.add(multi_player_client_groups.at(i), UI::Box::Resizing::kFullSize); | 643 | clientbox.add(multi_player_client_groups.at(i), UI::Box::Resizing::kFullSize); |
936 | 641 | multi_player_client_groups.at(i)->layout(); | 644 | multi_player_client_groups.at(i)->layout(); |
937 | 642 | } | 645 | } |
938 | 643 | 646 | ||
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 | 57 | void update(); | 57 | void update(); |
944 | 58 | void draw(RenderTarget& dst) override; | 58 | void draw(RenderTarget& dst) override; |
945 | 59 | 59 | ||
947 | 60 | GameSettingsProvider* const s; | 60 | GameSettingsProvider* const settings_; |
948 | 61 | std::unique_ptr<NetworkPlayerSettingsBackend> npsb; | 61 | std::unique_ptr<NetworkPlayerSettingsBackend> npsb; |
949 | 62 | std::vector<MultiPlayerClientGroup*> multi_player_client_groups; // not owned | 62 | std::vector<MultiPlayerClientGroup*> multi_player_client_groups; // not owned |
950 | 63 | std::vector<MultiPlayerPlayerGroup*> multi_player_player_groups; // not owned | 63 | std::vector<MultiPlayerPlayerGroup*> multi_player_player_groups; // not owned |
LGTM :)
Those index shifts were a major pain in the butt too when I implemented that.
@bunnybot merge