Where does "Error: Invalid command received" come from?

Where does "Error: Invalid command received" come from?

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Google_Frog
Moderator
Posts: 2436
Joined: 12 Oct 2007, 09:24

Where does "Error: Invalid command received" come from?

Post by Google_Frog » 01 Apr 2014, 14:55

There is a new error in the development engine to warn us when commands are being given to positions outside the map. I don't quite see the point of it as simply failing to apply the command leads to clearer lua code in most cases. But I am willing to work with the restriction.

I think I have added boundary checks for all of the occurrences within the synced gadgets of Zero-K but I still get a lot of these errors. So I need to know exactly what can cause them. Which lua environment trigger this error? Can players send invalid commands to each other with their widgets just to spam errors.
0 x

SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Where does "Error: Invalid command received" come from?

Post by SirMaverick » 01 Apr 2014, 21:56

https://github.com/spring/spring/blob/d ... I.cpp#L447

Seems to be either unload or build commands.
0 x

User avatar
AF
AI Developer
Posts: 20669
Joined: 14 Sep 2004, 11:32

Re: Where does "Error: Invalid command received" come from?

Post by AF » 01 Apr 2014, 23:55

Instead of a dynamic_cast would it not be cheaper to just check if the units def can build?
0 x

abma
Spring Developer
Posts: 3548
Joined: 01 Jun 2009, 00:08

Re: Where does "Error: Invalid command received" come from?

Post by abma » 02 Apr 2014, 09:32

this message means: a command was received which was/is invalid and is dropped.

before spring silently dropped these commands. if i remember right commands are dropped for example, when a move order with a pos outside of map is received.

error message comes from here: https://github.com/spring/spring/blob/d ... I.cpp#L378


AF: idk the code, but imo your suggestion makes no sense or i don't understand it. it seems you've looked only at VERY few lines of that code. (this should be already checked somewhere else)
0 x

User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Where does "Error: Invalid command received" come from?

Post by jK » 02 Apr 2014, 10:33

abma wrote:this message means: a command was received which was/is invalid and is dropped.
GF is right that ppl can code widgets that spam such incorrect cmds and so annoy the players. Maybe log the message max 3 times?
abma wrote:AF: idk the code, but imo your suggestion makes no sense or i don't understand it. it seems you've looked only at VERY few lines of that code. (this should be already checked somewhere else)
He meant that dynamic_cast is slow. But it's no perforamnce critical code, so doesn't matter.
0 x

Google_Frog
Moderator
Posts: 2436
Joined: 12 Oct 2007, 09:24

Re: Where does "Error: Invalid command received" come from?

Post by Google_Frog » 02 Apr 2014, 11:03

This message should be removed because it a widget is able to trigger errors on other people's computers. Limiting the number of errors reported is not a solution because these errors are still basically guaranteed to occur every game. This reflects poorly on the game and people are likely to just ignore the error whenever it occurs.
0 x

User avatar
Silentwings
Moderator
Posts: 3586
Joined: 25 Oct 2008, 00:23

Re: Where does "Error: Invalid command received" come from?

Post by Silentwings » 02 Apr 2014, 11:19

This message should be removed because it a widget is able to trigger errors on other people's computers.
I agree with this - could the check for "is this command pos outside of map" be moved into unsynced code and only trigger a local error?

Otherwise people will see an error and blame either (1) their own widgets or (2) the mod, when in fact neither is at fault. People seeing this error, including me, have no way to find the source of the error.

(By parsing the replay I could probably determine which player caused the error, but I doubt many people know how to do that. And even then I have the trouble of convincing someone else that their widget has recently been broken by some engine change and that they have to try and work out which widget it is, then they probably have to find either me or the author to fix it... essentially impossible!)
0 x

abma
Spring Developer
Posts: 3548
Joined: 01 Jun 2009, 00:08

Re: Where does "Error: Invalid command received" come from?

Post by abma » 02 Apr 2014, 11:40

hu? did i missinterpret sth.? the error shouldn't be forwared to other players, it just "happens" to all players... (=wrong commands are forwarded to all players and executed there)

but good point, its bad to show it for all as the "remote" people didn't trigger them. but thats exactly the point, why it should show an error, so it can be fixed.
0 x

Google_Frog
Moderator
Posts: 2436
Joined: 12 Oct 2007, 09:24

Re: Where does "Error: Invalid command received" come from?

Post by Google_Frog » 02 Apr 2014, 12:36

I don't think that there is much misinterpreting. We are saying "players can cause errors for each other" because from the point of view of a player it is unimportant exactly how the error ended up in their chat. For them forwarding an error is the same as being sent an invalid command which causes an error. The cases are pretty similar for us too.

As far as I can tell the error exists as an incentive to prevent Lua from sending commands which will do nothing. I assume this was done because it is much more expensive for the engine to process invalid commands than for Lua to avoid sending them. Is this is not the case then the change just increases code complexity for no reason.

I don't think that the error will prevent people from writing widgets which send invalid commands. For a player to fix an error spamming widget they would have to:
  • Notice that they are causing the error.
  • Care that they are causing the error.
  • Determine which of their widgets is causing the error.
  • Be able to update their widget (either through knowing Lua or having a widget which is frequently updated in an easy to find place).
All of these tasks are difficult and I doubt that there are many players who fulfill the requirements. It does not take very many players to make the error common. I predict that players would just accept the error as a small flaw in this engine version, they have accepted larger problems. At least this is what would happen to the unmaintained games. I would put a filter in the ZK widget handler to remove this error from chat to make it just something to wade through in infologs.
0 x

User avatar
AF
AI Developer
Posts: 20669
Joined: 14 Sep 2004, 11:32

Re: Where does "Error: Invalid command received" come from?

Post by AF » 02 Apr 2014, 12:43

Widget sends command, command gets routed by server and sent to all players, sim code reaches command on all machines, sim code outputs the error on all machines?

And yes, JK understood me right, dynamic_cast does indeed check if its a builder, but 2 dynamic casts are slower than simply checking a bool value in an existing data structure.
0 x

abma
Spring Developer
Posts: 3548
Joined: 01 Jun 2009, 00:08

Re: Where does "Error: Invalid command received" come from?

Post by abma » 02 Apr 2014, 13:41

@Google_Frog:

problem is: before this change nobody noticed that commands were dropped. This also happened for AI's. What do you suggest, that such invalid commands can be found? Silently dropping commands is really bad, i'm sure you will take a very long time to find out, why these are dropped if you rely for some reason on it. This is the reason why this message was added.

sending invalid commands to the engine just wastes resources imo especially when you have to check/calculate a map position anyway, which is on map. very likely the code has a bug when this happens.
0 x

User avatar
Anarchid
Posts: 1380
Joined: 30 Nov 2008, 04:31

Re: Where does "Error: Invalid command received" come from?

Post by Anarchid » 02 Apr 2014, 14:05

Put it into a different log section?
0 x

User avatar
Silentwings
Moderator
Posts: 3586
Joined: 25 Oct 2008, 00:23

Re: Where does "Error: Invalid command received" come from?

Post by Silentwings » 02 Apr 2014, 14:11

it just "happens" to all players...
The order is given locally, so afaics it can be checked locally in unsynced engine code to see if it's valid (i.e. inside map) and, if it's bad, an error message about it printed only locally? Then only valid orders are sent through the network and invalid ones are still identifiable on the client that tries to send them (which is also the only place where anyone has any chance of finding the cause).
Last edited by Silentwings on 02 Apr 2014, 14:18, edited 1 time in total.
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Where does "Error: Invalid command received" come from?

Post by knorke » 02 Apr 2014, 14:15

For finding bugs the message would have to give more info:
I think currently one can not even tell whether it is wiget,gadget or AI causing the invalid command?
With more info it could be useful tool but then should also should be a confing in springsettings.cfg maybe. There already is http://springrts.com/wiki/Springsetting ... ogSections
For playing it seems preferable just to silently drop invalid commands.
sending invalid commands to the engine just wastes resources imo especially when you have to check/calculate a map position anyway, which is on map. very likely the code has a bug when this happens.
Maybe not bugs but bit lazy scripting.
Scripter might have taken into account that sometimes a few orders get dropped off the map. Bit lazy but in a way also elegant.

For example wupgets that give commands relative to unit positions, something like:

Code: Select all

x,y,z=GetUnitPosition (unitID)
GiveOrder (unitID, cmd.patrol, x+100,y-blub,z)
GiveOrder (unitID, cmd.patrol, x-100,y+blub,z,"shift")
Works "always", except if unit is close to edge of map.
Of course can add a "is this commander valid checks" before every GiveOrder. But is bit cumbersome.
For performance is the "packet limit reached" flood protection thing not enough (?)
0 x

abma
Spring Developer
Posts: 3548
Joined: 01 Jun 2009, 00:08

Re: Where does "Error: Invalid command received" come from?

Post by abma » 02 Apr 2014, 14:17

Silentwings wrote:The order is given locally, so afaics it can be checked locally in unsynced engine code to see if it's valid (i.e. inside map) and, if it's bad, an error message about it printed only locally? Then only valid orders are sent through the network and invalid ones are identifiable on the client that tries to send them (which is also the only place where anyone has any chance of finding the cause).
code-wise this would require to check the same twice in engine -> bad.

it should be possible to check if the command comes from the local player and only then print a message, but not sure, maybe thats how it should/could be done.
0 x

User avatar
Silentwings
Moderator
Posts: 3586
Joined: 25 Oct 2008, 00:23

Re: Where does "Error: Invalid command received" come from?

Post by Silentwings » 02 Apr 2014, 14:24

code-wise this would require to check the same twice -> bad.
I don't see why it would require the same check twice, afaics each command would pass through exactly one local check; so no need to check it again. That said, imo that duplication is better than giving widget coders (who often don't write good code) the chance to cause error messages on everyone else's screens.

The situation as it stands right now requires duplication; widgets that previously relied on the 'dropping' behaviour (which can be for good reasons, as knorke points out) would now have to include an extra check that they weren't giving an out of map command.
check if the command comes from the local player and only then print a message
Yes, I agree.
0 x

User avatar
Anarchid
Posts: 1380
Joined: 30 Nov 2008, 04:31

Re: Where does "Error: Invalid command received" come from?

Post by Anarchid » 02 Apr 2014, 14:59

I don't see why it would require the same check twice, afaics each command would pass through exactly one local check; so no need to check it again
You cannot trust the remote machines to be honest, so you need to double-check when receiving the command, too.

If you trus them and don't do a check-on-receive, then you get an even nastier situation where a malicious remote machine can cause you to crash or desync by letting you process an invalid command.
0 x

Google_Frog
Moderator
Posts: 2436
Joined: 12 Oct 2007, 09:24

Re: Where does "Error: Invalid command received" come from?

Post by Google_Frog » 02 Apr 2014, 15:21

abma wrote:@Google_Frog:

problem is: before this change nobody noticed that commands were dropped. This also happened for AI's. What do you suggest, that such invalid commands can be found? Silently dropping commands is really bad, i'm sure you will take a very long time to find out, why these are dropped if you rely for some reason on it. This is the reason why this message was added.

sending invalid commands to the engine just wastes resources imo especially when you have to check/calculate a map position anyway, which is on map. very likely the code has a bug when this happens.
Who was silently dropping commands really bad for? I have done quite a bit with Lua and have never had a problem with it. I have given move orders relative to unit position and in this case dropping makes sense. I wanted a unit to move in a certain direction but if it is at the edge of the map the command was simply dropped.

If it is really bad for performance reasons do you have anything more than an opinion about the performance impact?

I've never had a problem with dropped commands but I don't know about things that I have not done, such as non-Lua AI. If this is a useful tool then there could be a setting to enable it. Spring could even have an extra debug mode toggle which enables logging of many errors like this which are rather minor and that should not be displayed in normal gameplay.
0 x

User avatar
Silentwings
Moderator
Posts: 3586
Joined: 25 Oct 2008, 00:23

Re: Where does "Error: Invalid command received" come from?

Post by Silentwings » 02 Apr 2014, 15:28

You cannot trust the remote machines to be honest,
Everything about springs architecture producing fair games already relies on this.
If you trus them and don't do a check-on-receive, then you get an even nastier situation where a malicious remote machine can cause you to crash or desync by letting you process an invalid command.
Just drop any invalid command that gets inside the synced part of the engine silently, as was previously the case. Presumably there is ~0 cost involved in that (and the other option - duplicating the check inside lua code - is much more expensive).
0 x

User avatar
Anarchid
Posts: 1380
Joined: 30 Nov 2008, 04:31

Re: Where does "Error: Invalid command received" come from?

Post by Anarchid » 02 Apr 2014, 15:51

Everything about springs architecture producing fair games already relies on this.
Please list current exploits that allow one to remotely crash remote instances of spring with malformed input?
0 x

Post Reply

Return to “Engine”