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

Proposed by SirVer
Status: Merged
Merged at revision: 7830
Proposed branch: lp:~widelands-dev/widelands/syncstream_on_option
Merge into: lp:widelands
Diff against target: 336 lines (+73/-97)
6 files modified
src/network/netclient.cc (+1/-3)
src/network/nethost.cc (+1/-3)
src/ui_fsmenu/options.cc (+6/-30)
src/ui_fsmenu/options.h (+2/-5)
src/wlapplication.cc (+61/-51)
src/wlapplication_messages.cc (+2/-5)
To merge this branch: bzr merge lp:~widelands-dev/widelands/syncstream_on_option
Reviewer Review Type Date Requested Status
GunChleoc code Approve
Tino Approve
Review via email: mp+286004@code.launchpad.net

Commit message

- Remove --remove-replays and --remove-syncstreams. We now always delete them if they were autogenerated and older than 4 weeks.
- Adds --write-syncstreams option which defaults to true for now. This will give us more debug information for future desyncs.

Description of the change

Now that I finished this debug aid, I think I have another idea why my last lockstep change was not correct.... Still, this get's rid of two useless options and adds a more useful one (though I'd argue that option should probably never be set to false anyways, so maybe we could just remove it).

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

Does compile and the wss file is written on windows.

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM

review: Approve (code)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested deleting of old replay files and added a string tweak. I think this is ready now.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/network/netclient.cc'
2--- src/network/netclient.cc 2016-02-11 06:56:47 +0000
3+++ src/network/netclient.cc 2016-02-15 10:51:01 +0000
4@@ -168,9 +168,7 @@
5 d->server_is_waiting = true;
6
7 Widelands::Game game;
8-#ifndef NDEBUG
9- game.set_write_syncstream(true);
10-#endif
11+ game.set_write_syncstream(g_options.pull_section("global").get_bool("write_syncstreams", true));
12
13 try {
14 UI::ProgressWindow* loader_ui = new UI::ProgressWindow("images/loadscreens/progress.png");
15
16=== modified file 'src/network/nethost.cc'
17--- src/network/nethost.cc 2016-02-07 07:41:45 +0000
18+++ src/network/nethost.cc 2016-02-15 10:51:01 +0000
19@@ -709,9 +709,7 @@
20 broadcast(s);
21
22 Widelands::Game game;
23-#ifndef NDEBUG
24- game.set_write_syncstream(true);
25-#endif
26+ game.set_write_syncstream(g_options.pull_section("global").get_bool("write_syncstreams", true));
27
28 try {
29 std::unique_ptr<UI::ProgressWindow> loader_ui;
30
31=== modified file 'src/ui_fsmenu/options.cc'
32--- src/ui_fsmenu/options.cc 2016-02-07 16:31:06 +0000
33+++ src/ui_fsmenu/options.cc 2016-02-15 10:51:01 +0000
34@@ -202,17 +202,9 @@
35 "",
36 g_gr->images().get("images/ui_basic/but3.png"), UI::SpinBox::Type::kBig),
37
38- sb_remove_replays_
39- (&box_saving_, 0, 0, column_width_, 250,
40- opt.remove_replays, 0, 365, _("Remove replays older than:"),
41- /** TRANSLATORS: Options: Remove Replays older than: */
42- /** TRANSLATORS: This will have a number added in front of it */
43- ngettext("day", "days", opt.remove_replays),
44- g_gr->images().get("images/ui_basic/but3.png"), UI::SpinBox::Type::kBig),
45-
46 nozip_(&box_saving_, Point(0, 0), _("Do not zip widelands data files (maps, replays and savegames)"),
47 "", column_width_),
48- remove_syncstreams_(&box_saving_, Point(0, 0), _("Remove Syncstream dumps on startup"),
49+ write_syncstreams_(&box_saving_, Point(0, 0), _("Write syncstreams in network games to debug desyncs"),
50 "", column_width_),
51
52 // Game options
53@@ -278,9 +270,8 @@
54 // Saving
55 box_saving_.add(&sb_autosave_, UI::Align::kLeft);
56 box_saving_.add(&sb_rolling_autosave_, UI::Align::kLeft);
57- box_saving_.add(&sb_remove_replays_, UI::Align::kLeft);
58 box_saving_.add(&nozip_, UI::Align::kLeft);
59- box_saving_.add(&remove_syncstreams_, UI::Align::kLeft);
60+ box_saving_.add(&write_syncstreams_, UI::Align::kLeft);
61
62 // Game
63 box_game_.add(&auto_roadbuild_mode_, UI::Align::kLeft);
64@@ -306,14 +297,6 @@
65 (&FullscreenMenuOptions::update_sb_autosave_unit,
66 boost::ref(*this)));
67 }
68- /** TRANSLATORS Options: Remove Replays older than: */
69- sb_remove_replays_.add_replacement(0, _("Never"));
70- for (UI::Button* temp_button : sb_remove_replays_.get_buttons()) {
71- temp_button->sigclicked.connect
72- (boost::bind
73- (&FullscreenMenuOptions::update_sb_remove_replays_unit,
74- boost::ref(*this)));
75- }
76 for (UI::Button* temp_button : sb_dis_panel_.get_buttons()) {
77 temp_button->sigclicked.connect
78 (boost::bind
79@@ -386,7 +369,7 @@
80
81 // Saving options
82 nozip_ .set_state(opt.nozip);
83- remove_syncstreams_ .set_state(opt.remove_syncstreams);
84+ write_syncstreams_ .set_state(opt.write_syncstreams);
85
86 // Game options
87 auto_roadbuild_mode_ .set_state(opt.auto_roadbuild_mode);
88@@ -403,10 +386,6 @@
89 sb_autosave_.set_unit(ngettext("minute", "minutes", sb_autosave_.get_value()));
90 }
91
92-void FullscreenMenuOptions::update_sb_remove_replays_unit() {
93- sb_remove_replays_.set_unit(ngettext("day", "days", sb_remove_replays_.get_value()));
94-}
95-
96 void FullscreenMenuOptions::update_sb_dis_panel_unit() {
97 sb_dis_panel_.set_unit(ngettext("pixel", "pixels", sb_dis_panel_.get_value()));
98 }
99@@ -505,9 +484,8 @@
100 // Saving options
101 os_.autosave = sb_autosave_.get_value();
102 os_.rolling_autosave = sb_rolling_autosave_.get_value();
103- os_.remove_replays = sb_remove_replays_.get_value();
104 os_.nozip = nozip_.get_state();
105- os_.remove_syncstreams = remove_syncstreams_.get_state();
106+ os_.write_syncstreams = write_syncstreams_.get_state();
107
108 // Game options
109 os_.auto_roadbuild_mode = auto_roadbuild_mode_.get_state();
110@@ -574,9 +552,8 @@
111 // Saving options
112 opt.autosave = opt_section_.get_int("autosave", DEFAULT_AUTOSAVE_INTERVAL * 60);
113 opt.rolling_autosave = opt_section_.get_int("rolling_autosave", 5);
114- opt.remove_replays = opt_section_.get_int("remove_replays", 0);
115 opt.nozip = opt_section_.get_bool("nozip", false);
116- opt.remove_syncstreams = opt_section_.get_bool("remove_syncstreams", true);
117+ opt.write_syncstreams = opt_section_.get_bool("write_syncstreams", true);
118
119 // Game options
120 opt.auto_roadbuild_mode = opt_section_.get_bool("auto_roadbuild_mode", true);
121@@ -618,9 +595,8 @@
122 // Saving options
123 opt_section_.set_int("autosave", opt.autosave * 60);
124 opt_section_.set_int("rolling_autosave", opt.rolling_autosave);
125- opt_section_.set_int("remove_replays", opt.remove_replays);
126 opt_section_.set_bool("nozip", opt.nozip);
127- opt_section_.set_bool("remove_syncstreams", opt.remove_syncstreams);
128+ opt_section_.set_bool("write_syncstreams", opt.write_syncstreams);
129
130 // Game options
131 opt_section_.set_bool("auto_roadbuild_mode", opt.auto_roadbuild_mode);
132
133=== modified file 'src/ui_fsmenu/options.h'
134--- src/ui_fsmenu/options.h 2016-01-02 22:07:47 +0000
135+++ src/ui_fsmenu/options.h 2016-02-15 10:51:01 +0000
136@@ -63,9 +63,8 @@
137 // Saving options
138 int32_t autosave; // autosave interval in minutes
139 int32_t rolling_autosave; // number of file to use for rolling autosave
140- uint32_t remove_replays;
141 bool nozip;
142- bool remove_syncstreams;
143+ bool write_syncstreams;
144
145 // Game options
146 bool auto_roadbuild_mode;
147@@ -100,7 +99,6 @@
148
149 private:
150 void update_sb_autosave_unit();
151- void update_sb_remove_replays_unit();
152 void update_sb_dis_panel_unit();
153 void update_sb_dis_border_unit();
154
155@@ -151,9 +149,8 @@
156 // Saving options
157 UI::SpinBox sb_autosave_;
158 UI::SpinBox sb_rolling_autosave_;
159- UI::SpinBox sb_remove_replays_;
160 UI::Checkbox nozip_;
161- UI::Checkbox remove_syncstreams_;
162+ UI::Checkbox write_syncstreams_;
163
164 // Game options
165 UI::Checkbox auto_roadbuild_mode_;
166
167=== modified file 'src/wlapplication.cc'
168--- src/wlapplication.cc 2016-02-07 07:16:24 +0000
169+++ src/wlapplication.cc 2016-02-15 10:51:01 +0000
170@@ -97,6 +97,10 @@
171
172 namespace {
173
174+// The time in seconds for how long old replays/syncstreams should be kept
175+// around, in seconds. Right now this is 4 weeks.
176+constexpr double kReplayKeepAroundTime = 4 * 7 * 24 * 60 * 60;
177+
178 /**
179 * Shut the hardware down: stop graphics mode, stop sound handler
180 */
181@@ -174,6 +178,49 @@
182 chdir(get_executable_directory().c_str());
183 #endif
184 }
185+
186+// Extracts a long from 'text' into 'val' returning true if all of the string
187+// was valid. If not, the content of 'val' is undefined.
188+bool to_long(const std::string& text, long* val) {
189+ const char* start = text.c_str();
190+ char* end;
191+ *val = strtol(start, &end, 10);
192+ return *end == '\0';
193+}
194+
195+// Extracts the creation date from 'path' which is expected to
196+// match "YYYY-MM-DD*". Returns false if no date could be extracted.
197+bool extract_creation_day(const std::string& path, tm* tfile) {
198+ const std::string filename = FileSystem::fs_filename(path.c_str());
199+ memset(tfile, 0, sizeof(tm));
200+
201+ long day, month, year;
202+ if (!to_long(filename.substr(8, 2), &day)) {
203+ return false;
204+ }
205+ if (!to_long(filename.substr(5, 2), &month)) {
206+ return false;
207+ }
208+ if (!to_long(filename.substr(0, 4), &year)) {
209+ return false;
210+ }
211+
212+ tfile->tm_mday = day;
213+ tfile->tm_mon = month - 1;
214+ tfile->tm_year = year - 1900;
215+ return tfile;
216+}
217+
218+// Returns true if 'filename' was autogenerated, i.e. if 'extract_creation_day' can return a date
219+// and it is old enough to be deleted.
220+bool is_autogenerated_and_expired(const std::string& filename) {
221+ tm tfile;
222+ if (!extract_creation_day(filename, &tfile)) {
223+ return false;
224+ }
225+ return std::difftime(time(nullptr), mktime(&tfile)) > kReplayKeepAroundTime;
226+}
227+
228 } // namespace
229
230 void WLApplication::setup_homedir() {
231@@ -676,14 +723,13 @@
232 s.get_int("panel_snap_distance");
233 s.get_int("autosave");
234 s.get_int("rolling_autosave");
235- s.get_int("remove_replays");
236 s.get_bool("single_watchwin");
237 s.get_bool("auto_roadbuild_mode");
238 s.get_bool("workareapreview");
239 s.get_bool("nozip");
240 s.get_bool("snap_windows_only_when_overlapping");
241 s.get_bool("dock_windows_to_edges");
242- s.get_bool("remove_syncstreams");
243+ s.get_bool("write_syncstreams");
244 s.get_bool("sound_at_message");
245 s.get_bool("transparent_chat");
246 s.get_string("registered");
247@@ -1379,58 +1425,22 @@
248 */
249 void WLApplication::cleanup_replays()
250 {
251- FilenameSet files;
252-
253- Section & s = g_options.pull_section("global");
254-
255- if (s.get_bool("remove_syncstreams", true)) {
256- files =
257- filter(g_fs->list_directory(REPLAY_DIR),
258- [](const std::string& fn) {return boost::ends_with(fn, REPLAY_SUFFIX ".wss");});
259-
260- for
261- (FilenameSet::iterator filename = files.begin();
262- filename != files.end();
263- ++filename)
264- {
265- log("Delete syncstream %s\n", filename->c_str());
266- g_fs->fs_unlink(*filename);
267+ for (const std::string& filename :
268+ filter(g_fs->list_directory(REPLAY_DIR),
269+ [](const std::string& fn) { return boost::ends_with(fn, REPLAY_SUFFIX ".wss"); })) {
270+ if (is_autogenerated_and_expired(filename)) {
271+ log("Delete syncstream %s\n", filename.c_str());
272+ g_fs->fs_unlink(filename);
273 }
274 }
275
276- time_t tnow = time(nullptr);
277-
278- if (s.get_int("remove_replays", 0)) {
279- files =
280- filter(g_fs->list_directory(REPLAY_DIR),
281- [](const std::string& fn) {return boost::ends_with(fn, REPLAY_SUFFIX);});
282-
283- for
284- (FilenameSet::iterator filename = files.begin();
285- filename != files.end();
286- ++filename)
287- {
288- std::string file = g_fs->fs_filename(filename->c_str());
289- std::string timestr = file.substr(0, file.find(' '));
290-
291- if (19 != timestr.size())
292- continue;
293-
294- tm tfile;
295- memset(&tfile, 0, sizeof(tm));
296-
297- tfile.tm_mday = atoi(timestr.substr(8, 2).c_str());
298- tfile.tm_mon = atoi(timestr.substr(5, 2).c_str()) - 1;
299- tfile.tm_year = atoi(timestr.substr(0, 4).c_str()) - 1900;
300-
301- double tdiff = std::difftime(tnow, mktime(&tfile)) / 86400;
302-
303- if (tdiff > s.get_int("remove_replays")) {
304- log("Delete replay %s\n", file.c_str());
305-
306- g_fs->fs_unlink(*filename);
307- g_fs->fs_unlink(*filename + ".wgf");
308- }
309+ for (const std::string& filename :
310+ filter(g_fs->list_directory(REPLAY_DIR),
311+ [](const std::string& fn) { return boost::ends_with(fn, REPLAY_SUFFIX); })) {
312+ if (is_autogenerated_and_expired(filename)) {
313+ log("Deleting replay %s\n", filename.c_str());
314+ g_fs->fs_unlink(filename);
315+ g_fs->fs_unlink(filename + ".wgf");
316 }
317 }
318 }
319
320=== modified file 'src/wlapplication_messages.cc'
321--- src/wlapplication_messages.cc 2016-02-06 11:11:24 +0000
322+++ src/wlapplication_messages.cc 2016-02-15 10:51:01 +0000
323@@ -63,11 +63,8 @@
324 " The locale to use.") << endl
325 /** TRANSLATORS: You may translate true/false, also as on/off or yes/no, but */
326 /** TRANSLATORS: it HAS TO BE CONSISTENT with the translation in the widelands textdomain */
327- << _(" --remove_syncstreams=[true|false]\n"
328- " Remove syncstream files on startup") << endl
329- << _(" --remove_replays=[...]\n"
330- " Remove replays after this number of days.\n"
331- " If this is 0, replays are not deleted.") << endl
332+ << _(" --write_syncstreams=[true|false]\n"
333+ " Create syncstreams to help debug network games.") << endl
334 << _(" --autosave=[...] Automatically save each n minutes") << endl
335 << _(" --rolling_autosave=[...]\n"
336 " Use this many files for rolling autosaves") << endl << endl

Subscribers

People subscribed via source and target branches

to status/vote changes: