Merge lp:~widelands-dev/widelands/bug-net-error-game-connect into lp:widelands

Proposed by Notabilis
Status: Merged
Merged at revision: 8896
Proposed branch: lp:~widelands-dev/widelands/bug-net-error-game-connect
Merge into: lp:widelands
Diff against target: 223 lines (+71/-38)
4 files modified
src/network/internet_gaming.cc (+53/-17)
src/network/internet_gaming.h (+7/-0)
src/network/internet_gaming_messages.cc (+2/-9)
src/ui_fsmenu/internet_lobby.cc (+9/-12)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-net-error-game-connect
Reviewer Review Type Date Requested Status
Klaus Halfmann review, compile, debug, test Approve
GunChleoc Approve
Review via email: mp+357477@code.launchpad.net

Commit message

Fixes on the communication between widelands and the metaserver:
- Permit answering PING requests even while logging in
- Printing current time to console when logging in.
  Eases finding the corresponding log entry on the metaserver when debugging
- Re-enabling and fixing unused code for whisper message to nonexisting player
- Handling error message when trying to join a non-existing game
- Avoid hanging client even after being notified about the non-existing game
- Removed no longer needed error messages

Description of the change

A bunch of smaller fixes regarding the metaserver. Nothing that should change anything in the "normal" case, but offers better / more correct handling of some errors.

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

Continuous integration builds have changed state:

Travis build 4157. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/444116111.
Appveyor build 3954. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_net_error_game_connect-3954.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, not tested.

This should to into Build20, because it affects server load.

review: Approve
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Complied this and did a "poor mans coverage" in the debugger.
I was able to hit about 50% of the changed code.

Hitting the rest would need tweaking of the metaserver or such.
But this is all reasonable for me.

@bunnybot mergre

review: Approve (review, compile, debug, test)
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for testing!

Let Notabilis take care of the merging, because there is also a Metaserver change.

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks for the reviews!
This branch can be merged immediately, the changes to the metaserver are no requirement.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/network/internet_gaming.cc'
2--- src/network/internet_gaming.cc 2018-08-24 07:58:04 +0000
3+++ src/network/internet_gaming.cc 2018-10-20 15:50:44 +0000
4@@ -353,6 +353,14 @@
5 }
6 }
7 return;
8+ } else if (cmd == IGPCMD_PING) {
9+ // Client received a PING and should immediately PONG as requested
10+ SendPacket s;
11+ s.string(IGPCMD_PONG);
12+ net->send(s);
13+
14+ lastping_ = time(nullptr);
15+ return;
16 }
17
18 // Are we already online?
19@@ -389,7 +397,10 @@
20 format_and_add_chat("", "", true, _("For reporting bugs, visit:"));
21 format_and_add_chat("", "", true, "https://wl.widelands.org/wiki/ReportingBugs/");
22 state_ = LOBBY;
23- log("InternetGaming: Client %s logged in.\n", clientname_.c_str());
24+ // Append UTC time to login message to ease linking between client output and
25+ // metaserver logs. The string returned by asctime is terminated by \n
26+ const time_t now = time(nullptr);
27+ log("InternetGaming: Client %s logged in at UTC %s", clientname_.c_str(), asctime(gmtime(&now)));
28 return;
29
30 } else if (cmd == IGPCMD_ERROR) {
31@@ -408,8 +419,7 @@
32 logout();
33 set_error();
34 log("InternetGaming: Expected a LOGIN, PWD_CHALLENGE or ERROR packet from server, but "
35- "received "
36- "command %s. Maybe the metaserver is using a different protocol version?",
37+ "received command %s. Maybe the metaserver is using a different protocol version?\n",
38 cmd.c_str());
39 throw WLWarning(
40 _("Unexpected packet"),
41@@ -443,15 +453,6 @@
42 format_and_add_chat("", "", true, temp);
43 }
44
45- else if (cmd == IGPCMD_PING) {
46- // Client received a PING and should immediately PONG as requested
47- SendPacket s;
48- s.string(IGPCMD_PONG);
49- net->send(s);
50-
51- lastping_ = time(nullptr);
52- }
53-
54 else if (cmd == IGPCMD_CHAT) {
55 // Client received a chat message
56 std::string sender = packet.string();
57@@ -617,11 +618,11 @@
58 if (subcmd == IGPCMD_CHAT) {
59 // Something went wrong with the chat message the user sent.
60 message += _("Chat message could not be sent.");
61- if (reason == "NO_SUCH_USER")
62+ if (reason == "NO_SUCH_USER") {
63 message = (boost::format("%s %s") % message %
64- (boost::format(InternetGamingMessages::get_message(reason)) %
65- packet.string().c_str()))
66+ InternetGamingMessages::get_message(reason))
67 .str();
68+ }
69 }
70
71 else if (subcmd == IGPCMD_GAME_OPEN) {
72@@ -630,17 +631,30 @@
73 // we got our answer, so no need to wait anymore
74 waitcmd_ = "";
75 }
76- message = (boost::format(_("ERROR: %s")) % message).str();
77+
78+ else if (subcmd == IGPCMD_GAME_CONNECT && reason == "NO_SUCH_GAME") {
79+ log("InternetGaming: The game no longer exists, maybe it has just been closed\n");
80+ message = InternetGamingMessages::get_message(reason);
81+ assert(waitcmd_ == IGPCMD_GAME_CONNECT);
82+ waitcmd_ = "";
83+ }
84+ if (!message.empty()) {
85+ message = (boost::format(_("ERROR: %s")) % message).str();
86+ } else {
87+ message = (boost::format(_("An unexpected error message has been received about command %1%: %2%"))
88+ % subcmd % reason).str();
89+ }
90
91 // Finally send the error message as system chat to the client.
92 format_and_add_chat("", "", true, message);
93 }
94
95- else
96+ else {
97 // Inform the client about the unknown command
98 format_and_add_chat(
99 "", "", true,
100 (boost::format(_("Received an unknown command from the metaserver: %s")) % cmd).str());
101+ }
102
103 } catch (WLWarning& e) {
104 format_and_add_chat("", "", true, e.what());
105@@ -653,6 +667,28 @@
106 return gameips_;
107 }
108
109+bool InternetGaming::wait_for_ips() {
110+ // Wait until the metaserver provided us with an IP address
111+ uint32_t const secs = time(nullptr);
112+ const bool is_waiting_for_connect = (waitcmd_ == IGPCMD_GAME_CONNECT);
113+ while (!gameips_.first.is_valid()) {
114+ if (error()) {
115+ return false;
116+ }
117+ if (is_waiting_for_connect && waitcmd_.empty()) {
118+ // Was trying to join a game but failed.
119+ // It probably means that the game is no longer available
120+ return false;
121+ }
122+ handle_metaserver_communication();
123+ // give some time for the answer + for a relogin, if a problem occurs.
124+ if ((kInternetGamingTimeout * 5 / 3) < time(nullptr) - secs) {
125+ return false;
126+ }
127+ }
128+ return true;
129+}
130+
131 const std::string InternetGaming::relay_password() {
132 return relay_password_;
133 }
134
135=== modified file 'src/network/internet_gaming.h'
136--- src/network/internet_gaming.h 2018-04-21 14:48:54 +0000
137+++ src/network/internet_gaming.h 2018-10-20 15:50:44 +0000
138@@ -107,6 +107,13 @@
139 const std::pair<NetAddress, NetAddress>& ips();
140
141 /**
142+ * Blocks for some time until either the ips() method is able to return the IPs of the relay
143+ * or an error occurred or the timeout is met.
144+ * @return \c True iff ips() can return something.
145+ */
146+ bool wait_for_ips();
147+
148+ /**
149 * Returns the password required to connect to the relay server as host.
150 */
151 const std::string relay_password();
152
153=== modified file 'src/network/internet_gaming_messages.cc'
154--- src/network/internet_gaming_messages.cc 2018-04-07 16:59:00 +0000
155+++ src/network/internet_gaming_messages.cc 2018-10-20 15:50:44 +0000
156@@ -40,7 +40,8 @@
157 void InternetGamingMessages::fill_map() {
158 // Messages from the metaserver (https://github.com/widelands/widelands_metaserver) to the
159 // clients.
160- igmessages["NO_SUCH_USER"] = _("There is no user with the name %s logged in!");
161+ igmessages["NO_SUCH_USER"] = _("There is no user with this name logged in.");
162+ igmessages["NO_SUCH_GAME"] = _("The game no longer exists, maybe it has just been closed.");
163 igmessages["WRONG_PASSWORD"] = _("The sent password was incorrect!");
164 igmessages["UNSUPPORTED_PROTOCOL"] = _("The protocol version you are using is not supported!");
165 igmessages["ALREADY_LOGGED_IN"] = _("You are already logged in!");
166@@ -53,12 +54,4 @@
167 igmessages["NO_ANSWER"] = _("Metaserver did not answer");
168 igmessages["CLIENT_TIMEOUT"] =
169 _("You got disconnected from the metaserver, as you did not answer a PING request in time.");
170- igmessages["GAME_TIMEOUT"] =
171- _("The metaserver was unable to connect to your game. Most likely it can’t be connected to "
172- "from the "
173- "internet! Please take a look at http://wl.widelands.org/wiki/InternetGaming to learn how "
174- "to set up "
175- "your internet connection for hosting a game online.");
176- igmessages["NOT_LOGGED_IN"] = _(
177- "You tried to log back in, but the server has no knowledge of your previous state anymore.");
178 }
179
180=== modified file 'src/ui_fsmenu/internet_lobby.cc'
181--- src/ui_fsmenu/internet_lobby.cc 2018-05-07 05:35:32 +0000
182+++ src/ui_fsmenu/internet_lobby.cc 2018-10-20 15:50:44 +0000
183@@ -362,23 +362,19 @@
184 }
185
186 bool FullscreenMenuInternetLobby::wait_for_ip() {
187- // Wait until the metaserver provided us with an IP address
188- uint32_t const secs = time(nullptr);
189- while (!InternetGaming::ref().ips().first.is_valid()) {
190- InternetGaming::ref().handle_metaserver_communication();
191- // give some time for the answer + for a relogin, if a problem occurs.
192- if ((kInternetGamingTimeout * 5 / 3) < time(nullptr) - secs) {
193+ if (!InternetGaming::ref().wait_for_ips()) {
194+ // Only display a message box if a network error occurred
195+ if (InternetGaming::ref().error()) {
196 // Show a popup warning message
197 const std::string warning(
198 _("Widelands was unable to get the IP address of the server in time. "
199- "There seems to be a network problem, either on your side or on the side "
200- "of the server.\n"));
201+ "There seems to be a network problem, either on your side or on the side "
202+ "of the server.\n"));
203 UI::WLMessageBox mmb(this, _("Connection Timed Out"), warning,
204- UI::WLMessageBox::MBoxType::kOk, UI::Align::kLeft);
205+ UI::WLMessageBox::MBoxType::kOk, UI::Align::kLeft);
206 mmb.run<UI::Panel::Returncodes>();
207- InternetGaming::ref().set_error();
208- return false;
209 }
210+ return false;
211 }
212 return true;
213 }
214@@ -422,8 +418,9 @@
215 // Tell the metaserver about it
216 InternetGaming::ref().open_game();
217
218- // Wait for his response with the IPs of the relay server
219+ // Wait for the response with the IPs of the relay server
220 if (!wait_for_ip()) {
221+ InternetGaming::ref().set_error();
222 return;
223 }
224

Subscribers

People subscribed via source and target branches

to status/vote changes: