Page MenuHomeWildfire Games

Lobby: Don't display a timestamp when an invalid command is sent
ClosedPublic

Authored by Imarok on Nov 28 2017, 5:15 PM.

Details

Summary

When someones sends an invalid command e.g. /k/k (Two slashes, so that it also can be sent with pidgin.) in the lobby chat by using an external xmpp client, 0ad displays just a timestamp and nothing else. This patch fixes that behaviour by just ignoring invalid commands. Demonstrated without any comment or explanation to me by Hanniba_Baraq (same as @Hannibal_Barca ?).

Test Plan

Use an external xmpp client and send e.g. /k/k. 0ad should display nothing.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Imarok created this revision.Nov 28 2017, 5:15 PM
Imarok edited the summary of this revision. (Show Details)Nov 28 2017, 5:19 PM
Imarok added a subscriber: Hannibal_Barca.
elexis accepted this revision.Nov 28 2017, 5:26 PM
elexis added a subscriber: elexis.

Yes, all of that.

Accept under the condition to not contradict the function comment and not add a jshint warning.

This revision is now accepted and ready to land.Nov 28 2017, 5:26 PM
In D1077#42802, @elexis wrote:

Yes, all of that.

Accept under the condition to not contradict the function comment

What do you mean? Because we say we return a string in the jsdoc comment?

Yes. jshint also has the ability to show a warning if some return statements dont return something explicitly when others do afaik.

Vulcan added a subscriber: Vulcan.Nov 28 2017, 6:05 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
Executing section Default...
Executing section Source...
Executing section JS...

binaries/data/mods/public/gui/lobby/lobby.js
| 637| »   »   case·'name':
|    | [NORMAL] JSHintBear:
|    | Expected a 'break' statement before 'default'.
In D1077#42811, @elexis wrote:

Yes. jshint also has the ability to show a warning if some return statements dont return something explicitly when others do afaik.

So just returning "" or false?

In D1077#42829, @Imarok wrote:

So just returning "" or false?

If you see a benefit in not always returning a string, inform me prior or after the commit and correct the JSdoc comment that would be lying in that case before the commit.

Also one might think about "command isnt supported" message

In D1077#42833, @elexis wrote:

Also one might think about "command isnt supported" message

Only when the user inputs a wrong command and that is already done.
When someone else is spamming invalid commands into the lobby it should just be ignored by everyone else.

In D1077#42841, @Imarok wrote:
In D1077#42833, @elexis wrote:

Also one might think about "command isnt supported" message

Only when the user inputs a wrong command and that is already done.
When someone else is spamming invalid commands into the lobby it should just be ignored by everyone else.

Ah. Such bugs indeed have Hannibal written on it :D

Imarok updated this revision to Diff 4425.Nov 28 2017, 7:13 PM

js doc(will commit soon ;)

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (308 tests)....................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
Executing section Default...
Executing section Source...
Executing section JS...

binaries/data/mods/public/gui/lobby/lobby.js
| 637| »   »   case·'name':
|    | [NORMAL] JSHintBear:
|    | Expected a 'break' statement before 'default'.
elexis requested changes to this revision.Nov 28 2017, 7:32 PM

Thats not what I said

This revision now requires changes to proceed.Nov 28 2017, 7:32 PM
elexis accepted this revision.Nov 29 2017, 12:26 AM
elexis added inline comments.
binaries/data/mods/public/gui/lobby/lobby.js
1375 ↗(On Diff #4425)

return undefined; or return "";

This revision is now accepted and ready to land.Nov 29 2017, 12:26 AM
Imarok added inline comments.Nov 29 2017, 3:36 PM
binaries/data/mods/public/gui/lobby/lobby.js
1375 ↗(On Diff #4425)

Isn't return; the same as return undefined;?
If not, where is the difference?

elexis added inline comments.Nov 29 2017, 3:49 PM
binaries/data/mods/public/gui/lobby/lobby.js
1375 ↗(On Diff #4425)

return; and return undefined; both return undefined.

return; is most often if not always used for procedures/methods/voids where the return value is not read from.
So reading return; the reader often doesn't realize that undefined is actually returned and in these cases actually processed.

The conclusion is to always return a value explicitly or always return undefined implicitly.

ESLint throws a linting warning for that reason, see link.
Didn't we even enable that? If not, why?

Imarok added inline comments.Nov 29 2017, 4:12 PM
binaries/data/mods/public/gui/lobby/lobby.js
1375 ↗(On Diff #4425)

Hmm, Ok, then I'll just go with the empty string.
Regarding to D213 L23 it seems like it consistent-return warning is enabled.

This revision was automatically updated to reflect the committed changes.