Merge lp:~widelands-dev/widelands/net-user-type into lp:widelands

Proposed by Notabilis
Status: Merged
Merged at revision: 8674
Proposed branch: lp:~widelands-dev/widelands/net-user-type
Merge into: lp:widelands
Diff against target: 244 lines (+41/-56)
6 files modified
src/network/internet_gaming.cc (+3/-12)
src/network/internet_gaming.h (+0/-1)
src/network/internet_gaming_protocol.h (+4/-7)
src/ui_fsmenu/internet_lobby.cc (+21/-19)
src/wui/gamechatpanel.cc (+12/-16)
src/wui/gamechatpanel.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/net-user-type
Reviewer Review Type Date Requested Status
Klaus Halfmann review, compile Approve
GunChleoc Approve
Review via email: mp+343754@code.launchpad.net

Commit message

Cleaner transmission of client status

Description of the change

Some small changes regarding transmitted client status and IRC clients.

- That a metaserver client is an IRC user is now transmitted as permission instead of as build-id. Avoids the theoretical problem that a Widelands client could have a build-id of "IRC".

- No longer block private messages to IRC users client side. This is now blocked on the metaserver.

- No longer sending (not existing) "points" of a user when transmitting the client list. If someone has an objection against removing these "points" (e.g., there are plans to use them), please say so.

- cleaning up code for "messages beeps" when receiving a non-system message.

Note: Don't merge/deploy this, I should do that myself since the protocol version has not been changed yet.

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

Oh, and does someone know something about the "bots"?

  static const std::string INTERNET_CLIENT_BOT = "BOT";

I removed it now since it does not seem to be used, neither in Widelands nor on the metaserver.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I don't know anything about bots, sorry.

I think the points can go - they were never displayed anyway, and the screen space is now used for displaying the client version.

Code LGTM :)

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

Continuous integration builds have changed state:

Travis build 3393. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/369523180.
Appveyor build 3199. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_net_user_type-3199.

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

* I assume that "BOT" was intended for chat or game Bots (we have/had some on irc, do we?)

* A first review of the diffs shows me no obvious Issues, some nits in the comments.

* I will now compile the code an do some review on the complete internet_gaming* files.
  (More for me to get familiar with that code)

* Notabalis: I will try to be online with that version starting at perhaps 16:00 CEST,
  so we can try you changes "live" in chat and on IRC.
  Maybe we can hunt down these IRC Bots, too?

* GunCheloc: FYI with latest XCode updates Apple has pushed clang to a newer version,
  so a lot of newer options finally work here and some warnigns are finally gone:
  Apple LLVM version 9.1.0 (clang-902.0.39.1)
  Target: x86_64-apple-darwin17.5.0
  Thread model: posix
  InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

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

I checekd the Multiplayer lobby and it looks garbled now,
will you need a screenshot?

I did a small improvemenet in gamechatpanel.cc, not sure if I should commit it?

review: Needs Fixing (compile, testplay)
Revision history for this message
GunChleoc (gunchleoc) wrote :

@Klaus: Glad it's working better now. I have opened a bug to update Travis with the new version too: https://bugs.launchpad.net/widelands/+bug/1766069

Revision history for this message
Notabilis (notabilis27) wrote :

Sorry, should have mentioned it: This branch is not compatible with the currently running metaserver. So its "fine" that it looks strange.

Feel free to commit your change. I will look at your suggestions later on.

Revision history for this message
Notabilis (notabilis27) wrote :

It looks indeed as it might have been a game or chat bot. But I don't know whether there have been any at some time. I am not aware of any that are currently active.

Thanks for the review and for fixing the one nit. I replaced the numeric constants with const variables, an enum wasn't possible since we have to compare the values. But it looks much better now.

Regarding testing this branch: If you want to test a branch which changes something on the online gaming protocol (or the relay protocol), you have to run your own metaserver based on the matching branch of it (https://github.com/widelands/widelands_metaserver/pull/29 is the merge request on the metaserver code).
To make widelands use your local metaserver, start it with "--metaserver=localhost" as parameter. Later on you have to either clean the line from the configuration file or start with "--metaserver=widelands.org".

Revision history for this message
GunChleoc (gunchleoc) wrote :

Can you please document the metaserver option in a separate branch? This is where it should go:

https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/src/wlapplication_messages.cc

Revision history for this message
Notabilis (notabilis27) wrote :

Oh! I wasn't aware that this isn't documented. Thanks for the pointer, I will do so.

Revision history for this message
kaputtnik (franku) wrote :

The bot is maybe a holdover from the time ggz was used?

http://www.ggzgamingzone.org

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

Sorry I was unable to the get wlms server going:

klaus$ ./go/bin/wlms
2018/05/01 10:07:50 No configuration found, using in-memory database
2018/05/01 10:07:50 Using 127.0.0.1 and fe80::1 as IP addresses of the relay
2018/05/01 10:07:50 Unable to connect to relay server at localhost: dial tcp [::1]:7398: connect: connection refused
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13152c1]

goroutine 53 [running]:
main.(*Server).mainLoop(0xc4201480c0)
 /Users/klaus/go/src/github.com/widelands/widelands_metaserver/wlms/server.go:450 +0x41
created by main.CreateServerUsing
 /Users/klaus/go/src/github.com/widelands/widelands_metaserver/wlms/server.go:445 +0x5b0

And I was unbale to git checkout that pullrequerst, either. No time to really deep dive into that code yet.

Still the code change is ok for me. So how to we get this into the offical server now?

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

> So how to we get this into the offical server now?

We leave that up to Notabilis. He knows how to do it :)

Do not merge this branch, let him handle it, because it needs to be coordinated.

Revision history for this message
Notabilis (notabilis27) wrote :

Hm, well... Unfortunately its not easy to get it running, actually I am surprised you got that far. I had quite some trouble getting it compiled when I first tried to.
What is missing in your case is a running relay server. Seems that the "documentation" is incomplete, sorry for that. You have to compile and run the wlnr executable, afterwards the wlms can connect to it and it should start correctly.
Currently I am working on some semi-automated test scripts for the metaserver but they are far from useful yet.

I will do some local testing with my three branches now and if they work together, I will merge and deploy them.

Revision history for this message
Notabilis (notabilis27) wrote :

@bunnybot merge

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks for the reviews! The new version is online and seems to be working. If someone notices a bug, please say so.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Will do. Thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc 2018-04-07 16:59:00 +0000
+++ src/network/internet_gaming.cc 2018-04-22 16:47:03 +0000
@@ -606,8 +606,7 @@
606 inc.build_id = packet.string();606 inc.build_id = packet.string();
607 inc.game = packet.string();607 inc.game = packet.string();
608 inc.type = packet.string();608 inc.type = packet.string();
609 inc.points = packet.string();609 if (inc.type == INTERNET_CLIENT_IRC) {
610 if (inc.build_id == "IRC") {
611 irc.push_back(inc);610 irc.push_back(inc);
612 // No "join" or "left" messages for IRC users611 // No "join" or "left" messages for IRC users
613 continue;612 continue;
@@ -631,7 +630,7 @@
631 clientlist_.insert(clientlist_.end(), irc.begin(), irc.end());630 clientlist_.insert(clientlist_.end(), irc.begin(), irc.end());
632631
633 for (InternetClient& client : old) {632 for (InternetClient& client : old) {
634 if (client.name.size() && client.build_id != "IRC") {633 if (client.name.size() && client.type != INTERNET_CLIENT_IRC) {
635 format_and_add_chat(634 format_and_add_chat(
636 "", "", true, (boost::format(_("%s left the lobby")) % client.name).str());635 "", "", true, (boost::format(_("%s left the lobby")) % client.name).str());
637 }636 }
@@ -867,17 +866,9 @@
867 _("Message could not be sent: Was this supposed to be a private message?"));866 _("Message could not be sent: Was this supposed to be a private message?"));
868 return;867 return;
869 }868 }
870 std::string recipient = msg.substr(1, space - 1);
871 for (const InternetClient& client : clientlist_) {
872 if (recipient == client.name && client.build_id == "IRC") {
873 format_and_add_chat(
874 "", "", true, _("Private messages to IRC users are not supported."));
875 return;
876 }
877 }
878869
879 s.string(trimmed); // message870 s.string(trimmed); // message
880 s.string(recipient); // recipient871 s.string(msg.substr(1, space - 1)); // recipient
881872
882 format_and_add_chat(clientname_, msg.substr(1, space - 1), false, msg.substr(space + 1));873 format_and_add_chat(clientname_, msg.substr(1, space - 1), false, msg.substr(space + 1));
883874
884875
=== modified file 'src/network/internet_gaming.h'
--- src/network/internet_gaming.h 2018-04-07 16:59:00 +0000
+++ src/network/internet_gaming.h 2018-04-22 16:47:03 +0000
@@ -37,7 +37,6 @@
37 std::string build_id;37 std::string build_id;
38 std::string game;38 std::string game;
39 std::string type;39 std::string type;
40 std::string points; // Currently unused
41};40};
4241
43/// A simple network game struct42/// A simple network game struct
4443
=== modified file 'src/network/internet_gaming_protocol.h'
--- src/network/internet_gaming_protocol.h 2018-04-07 16:59:00 +0000
+++ src/network/internet_gaming_protocol.h 2018-04-22 16:47:03 +0000
@@ -71,7 +71,7 @@
71static const std::string INTERNET_CLIENT_UNREGISTERED = "UNREGISTERED";71static const std::string INTERNET_CLIENT_UNREGISTERED = "UNREGISTERED";
72static const std::string INTERNET_CLIENT_REGISTERED = "REGISTERED";72static const std::string INTERNET_CLIENT_REGISTERED = "REGISTERED";
73static const std::string INTERNET_CLIENT_SUPERUSER = "SUPERUSER";73static const std::string INTERNET_CLIENT_SUPERUSER = "SUPERUSER";
74static const std::string INTERNET_CLIENT_BOT = "BOT";74static const std::string INTERNET_CLIENT_IRC = "IRC";
7575
76/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *76/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77 * COMMUNICATION PROTOCOL BETWEEN CLIENT AND METASERVER *77 * COMMUNICATION PROTOCOL BETWEEN CLIENT AND METASERVER *
@@ -322,10 +322,8 @@
322322
323/**323/**
324 * Sent by the metaserver to inform the client, that the list of clients was changed. No payload is324 * Sent by the metaserver to inform the client, that the list of clients was changed. No payload is
325 * sent,325 * sent, as e.g. clients in a game are not really interested about other clients and we want to
326 * as e.g. clients in a game are not really interested about other clients and we want to keep326 * keep traffic as low as possible.
327 * traffic
328 * as low as possible.
329 *327 *
330 * To get the new list of clients, the client must send \ref IGPCMD_CLIENT328 * To get the new list of clients, the client must send \ref IGPCMD_CLIENT
331 */329 */
@@ -338,9 +336,8 @@
338 * \li string: Number of client packages and for uint8_t i = 0; i < num; ++i {:336 * \li string: Number of client packages and for uint8_t i = 0; i < num; ++i {:
339 * \li string: Name of the client337 * \li string: Name of the client
340 * \li string: Widelands version338 * \li string: Widelands version
341 * \li string: Game the player is connected to, else empty.339 * \li string: Game the player is connected to, else empty
342 * \li string: Clients rights (see client rights section above)340 * \li string: Clients rights (see client rights section above)
343 * \li string: Points of the client
344 * }341 * }
345 */342 */
346static const std::string IGPCMD_CLIENTS = "CLIENTS";343static const std::string IGPCMD_CLIENTS = "CLIENTS";
347344
=== modified file 'src/ui_fsmenu/internet_lobby.cc'
--- src/ui_fsmenu/internet_lobby.cc 2018-04-07 16:59:00 +0000
+++ src/ui_fsmenu/internet_lobby.cc 2018-04-22 16:47:03 +0000
@@ -35,6 +35,16 @@
35#include "random/random.h"35#include "random/random.h"
36#include "ui_basic/messagebox.h"36#include "ui_basic/messagebox.h"
3737
38namespace {
39
40 // Constants for convert_clienttype() / compare_clienttype()
41 const uint8_t kClientUnregistered = 0;
42 const uint8_t kClientRegistered = 1;
43 const uint8_t kClientSuperuser = 2;
44 // 3 was INTERNET_CLIENT_BOT which is not used
45 const uint8_t kClientIRC = 4;
46}
47
38FullscreenMenuInternetLobby::FullscreenMenuInternetLobby(char const* const nick,48FullscreenMenuInternetLobby::FullscreenMenuInternetLobby(char const* const nick,
39 char const* const pwd,49 char const* const pwd,
40 bool registered)50 bool registered)
@@ -232,13 +242,13 @@
232242
233uint8_t FullscreenMenuInternetLobby::convert_clienttype(const std::string& type) {243uint8_t FullscreenMenuInternetLobby::convert_clienttype(const std::string& type) {
234 if (type == INTERNET_CLIENT_REGISTERED)244 if (type == INTERNET_CLIENT_REGISTERED)
235 return 1;245 return kClientRegistered;
236 if (type == INTERNET_CLIENT_SUPERUSER)246 if (type == INTERNET_CLIENT_SUPERUSER)
237 return 2;247 return kClientSuperuser;
238 if (type == INTERNET_CLIENT_BOT)248 if (type == INTERNET_CLIENT_IRC)
239 return 3;249 return kClientIRC;
240 // if (type == INTERNET_CLIENT_UNREGISTERED)250 // if (type == INTERNET_CLIENT_UNREGISTERED)
241 return 0;251 return kClientUnregistered;
242}252}
243253
244/**254/**
@@ -262,27 +272,24 @@
262 er.set_string(2, client.build_id);272 er.set_string(2, client.build_id);
263 er.set_string(3, client.game);273 er.set_string(3, client.game);
264274
265 if (client.build_id == "IRC") {
266 // No icon for IRC users
267 continue;
268 }
269
270 const Image* pic;275 const Image* pic;
271 switch (convert_clienttype(client.type)) {276 switch (convert_clienttype(client.type)) {
272 case 0: // UNREGISTERED277 case kClientUnregistered:
273 pic = g_gr->images().get("images/wui/overlays/roadb_red.png");278 pic = g_gr->images().get("images/wui/overlays/roadb_red.png");
274 er.set_picture(0, pic);279 er.set_picture(0, pic);
275 break;280 break;
276 case 1: // REGISTERED281 case kClientRegistered:
277 pic = g_gr->images().get("images/wui/overlays/roadb_yellow.png");282 pic = g_gr->images().get("images/wui/overlays/roadb_yellow.png");
278 er.set_picture(0, pic);283 er.set_picture(0, pic);
279 break;284 break;
280 case 2: // SUPERUSER285 case kClientSuperuser:
281 case 3: // BOT
282 pic = g_gr->images().get("images/wui/overlays/roadb_green.png");286 pic = g_gr->images().get("images/wui/overlays/roadb_green.png");
283 er.set_color(RGBColor(0, 255, 0));287 er.set_color(RGBColor(0, 255, 0));
284 er.set_picture(0, pic);288 er.set_picture(0, pic);
285 break;289 break;
290 case kClientIRC:
291 // No icon for IRC users
292 continue;
286 default:293 default:
287 continue;294 continue;
288 }295 }
@@ -301,11 +308,6 @@
301 if (clientsonline_list_.has_selection()) {308 if (clientsonline_list_.has_selection()) {
302 UI::Table<const InternetClient* const>::EntryRecord& er = clientsonline_list_.get_record(i);309 UI::Table<const InternetClient* const>::EntryRecord& er = clientsonline_list_.get_record(i);
303310
304 if (er.get_string(2) == "IRC") {
305 // No PM to IRC users
306 return;
307 }
308
309 std::string temp("@");311 std::string temp("@");
310 temp += er.get_string(1);312 temp += er.get_string(1);
311 std::string text(chat.get_edit_text());313 std::string text(chat.get_edit_text());
312314
=== modified file 'src/wui/gamechatpanel.cc'
--- src/wui/gamechatpanel.cc 2018-04-07 16:59:00 +0000
+++ src/wui/gamechatpanel.cc 2018-04-22 16:47:03 +0000
@@ -45,7 +45,7 @@
45 g_gr->images().get("images/ui_basic/but1.png"),45 g_gr->images().get("images/ui_basic/but1.png"),
46 UI::MultilineTextarea::ScrollMode::kScrollLogForced),46 UI::MultilineTextarea::ScrollMode::kScrollLogForced),
47 editbox(this, 0, h - 20, w, 20, 2),47 editbox(this, 0, h - 20, w, 20, 2),
48 chat_message_counter(std::numeric_limits<uint32_t>::max()) {48 chat_message_counter(0) {
49 editbox.ok.connect(boost::bind(&GameChatPanel::key_enter, this));49 editbox.ok.connect(boost::bind(&GameChatPanel::key_enter, this));
50 editbox.cancel.connect(boost::bind(&GameChatPanel::key_escape, this));50 editbox.cancel.connect(boost::bind(&GameChatPanel::key_escape, this));
51 editbox.activate_history(true);51 editbox.activate_history(true);
@@ -65,31 +65,27 @@
65void GameChatPanel::recalculate() {65void GameChatPanel::recalculate() {
66 const std::vector<ChatMessage> msgs = chat_.get_messages();66 const std::vector<ChatMessage> msgs = chat_.get_messages();
6767
68 size_t msgs_size = msgs.size();
68 std::string str = "<rt>";69 std::string str = "<rt>";
69 for (uint32_t i = 0; i < msgs.size(); ++i) {70 for (uint32_t i = 0; i < msgs_size; ++i) {
70 str += format_as_richtext(msgs[i]);71 str += format_as_richtext(msgs[i]);
71 }72 }
72 str += "</rt>";73 str += "</rt>";
7374
74 chatbox.set_text(str);75 chatbox.set_text(str);
7576
76 // If there are new messages, play a sound77 if (chat_message_counter < msgs_size) { // are there new messages?
77 if (0 < msgs.size() && msgs.size() != chat_message_counter) {78 if (!chat_.sound_off()) { // play a sound, if needed
78 // computer generated ones are ignored79 for (size_t i = chat_message_counter; i < msgs_size; ++i) {
79 // Note: if many messages arrive simultaneously,80 if (msgs[i].sender.empty()) {
80 // the latest is a system message and some others81 continue; // System message. Don't play a sound
81 // are not, then this act wrong!82 }
82 if (!msgs.back().sender.empty() && !chat_.sound_off()) {83 // Got a message that is no system message. Beep
83 // The latest message is not a system message
84 if (std::string::npos == msgs.back().sender.find("(IRC)") &&
85 chat_message_counter < msgs.size()) {
86 // The latest message was not relayed from IRC.
87 // The above built-in string constant should match
88 // that of the IRC bridge.
89 play_new_chat_message();84 play_new_chat_message();
85 break;
90 }86 }
91 }87 }
92 chat_message_counter = msgs.size();88 chat_message_counter = msgs_size;
93 }89 }
94}90}
9591
9692
=== modified file 'src/wui/gamechatpanel.h'
--- src/wui/gamechatpanel.h 2018-04-07 16:59:00 +0000
+++ src/wui/gamechatpanel.h 2018-04-22 16:47:03 +0000
@@ -58,7 +58,7 @@
58 ChatProvider& chat_;58 ChatProvider& chat_;
59 UI::MultilineTextarea chatbox;59 UI::MultilineTextarea chatbox;
60 UI::EditBox editbox;60 UI::EditBox editbox;
61 uint32_t chat_message_counter;61 size_t chat_message_counter;
62 std::unique_ptr<Notifications::Subscriber<ChatMessage>> chat_message_subscriber_;62 std::unique_ptr<Notifications::Subscriber<ChatMessage>> chat_message_subscriber_;
63};63};
6464

Subscribers

People subscribed via source and target branches

to status/vote changes: