Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#3545 closed defect (fixed)

[PATCH] Freeze the game using cheats

Reported by: elexis Owned by: Stan
Priority: Should Have Milestone: Alpha 20
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Reproduce:

  1. Start a game with cheats enabled
  2. Select a building
  3. Type "salad bowl 99999999999"

It will attempt to spawn that many units with unintended consequences (for example rebooting windows).

This has been used by at least one troll to crash games.

Attachments (4)

3545.diff (1.0 KB ) - added by Stan 9 years ago.
This patch limits the number of batch cheat spawnable units to 500 add a comment, and document a bit the cheat function.
3545.1.diff (1.0 KB ) - added by Stan 9 years ago.
This patch limits the max number of spawnable units to the maxpop, preventing lag and abuse. It's no longer needed to replace the for loop too.
3545.2.diff (1.0 KB ) - added by Stan 9 years ago.
Updated.
3545.3.diff (1.0 KB ) - added by Stan 8 years ago.
Raise the limit to 600 if Tardis cheat is enabled, MaxPop + 100 otherwise.

Download all attachments as: .zip

Change History (18)

by Stan, 9 years ago

Attachment: 3545.diff added

This patch limits the number of batch cheat spawnable units to 500 add a comment, and document a bit the cheat function.

comment:1 by Stan, 9 years ago

Keywords: patch review added
Owner: set to Stan
Status: newassigned
Summary: Crash the game using cheats[PATCH] Crash the game using cheats

While we are at it some things could be improved:

  • We could batch create units 5 by 5 to save some function calls if that helps (If number is high enough ofc)
  • We could replace the for lopp by a for in to clean it up.
  • We could check for MaxPop to prevent it from going over 1000

I'm leaving this patch as is, waiting for feedback by the person who will commit it.

Last edited 9 years ago by Stan (previous) (diff)

comment:2 by Stan, 9 years ago

Milestone: BacklogAlpha 20

comment:3 by elexis, 9 years ago

  • Notice this patch does the check in the right place. If a cheat is typed, it will be sent as a simulation command and that one will call the cheat-function. Thus a script kidde can't just remove the check and repeat the exploit. (Thus we don't have the problem of trusting the client).
  • Use something like input.parameter = Math.max(<LIMIT>, input.parameter)
  • Reducing the number doesn't seem sufficient. To many units can still be created by repeating the command.

Proposal: How about only spawning as many units as the population limit allows? This is the only way I can imagine to completely solve the problem.

by Stan, 9 years ago

Attachment: 3545.1.diff added

This patch limits the max number of spawnable units to the maxpop, preventing lag and abuse. It's no longer needed to replace the for loop too.

comment:4 by elexis, 9 years ago

Milestone: Alpha 20Alpha 19

No reason to wait, patch looks sufficient to be commited.

  • one space missing after input.parameter
  • Comment could be changed a bit
    • it's obvious that a function uses its argument
    • you could mention that the function executes a simulation command

by Stan, 9 years ago

Attachment: 3545.2.diff added

Updated.

comment:5 by mimo, 9 years ago

Why is the limit (maxPop-currentPop) ? I fully agree about limiting the number of spawned units, but the limitation at maxPop seems too strict to me ? we may imagine some new SP player having a hard time against the AI with already a pop near the max and needing to spawn more units with the cheat. Would seem more reasonnable to me to put the limit at n*maxPop (with n=2 a sensible value).

comment:6 by Josh, 8 years ago

How about we limit it to 100 over the maximum population? That should be plenty of room. (more than that would probably be too slow anyway)

We should also display a message to the user if there isn't any population room.

in reply to:  6 ; comment:7 by elexis, 8 years ago

Replying to Josh:

How about we limit it to 100

Then you can repeat it to crash the game. (Two keystrokes needed with the javascript console to repeat)

We should also display a message to the user if there isn't any population room.

Might be an idea, but it will be visible to all players since it's in the simulation.

in reply to:  7 ; comment:8 by Josh, 8 years ago

Replying to elexis:

Replying to Josh:

How about we limit it to 100

Then you can repeat it to crash the game. (Two keystrokes needed with the javascript console to repeat)

We should also display a message to the user if there isn't any population room.

Might be an idea, but it will be visible to all players since it's in the simulation.

Please don't take my comment out of context. I said, "How about we limit it to 100 over the maximum population?" (emphasis added).

It also looks to me like Cheat is not a network-synchronized command, but triggers a set of network-synchronized commands. Without a full architecture review, I cannot be sure if user-triggered cheat commands go through the GuiInterface. If they do, you can just return a failure status to the caller through that without much work.

comment:9 by Stan, 8 years ago

I will update the patch thank you Josh for looking into it.

by Stan, 8 years ago

Attachment: 3545.3.diff added

Raise the limit to 600 if Tardis cheat is enabled, MaxPop + 100 otherwise.

in reply to:  8 comment:10 by elexis, 8 years ago

Replying to Josh:

Please don't take my comment out of context. I said, "How about we limit it to 100 over the maximum population?" (emphasis added).

Ah, sorry, didn't understand that. You are right, that could be done.

It also looks to me like Cheat is not a network-synchronized command, but triggers a set of network-synchronized commands.

Cheats can only be sent as simulation commands:

  • Cheats are parsed locally and sent as simulation commands: see submitChatInput() calling executeCheat() calling Engine.PostNetworkCommand() with type="cheat" queueing the network simulation command, which will call Cheat() in Cheat.js identically for all clients.
  • Clients don't look for cheats in other players chat: see handleNetMessage() in messages.js calling addChatMessage() calling parseChatCommands(), but no Cheat-code.

If any player has some custom cheat, he will just become OOS, crash him/herself and doesn't affect the other clients.

comment:11 by elexis, 8 years ago

I made some brief tests spawning units (which actually don't have a space to spawn):

  • 5k units -> 10 seconds
  • 10k units -> 15 seconds
  • 20k units -> 30 seconds

So spawning at most 500 units should be fine.


Second Proposal: I remember the sunken ship lag (r16636) also crashed games. A ship with 20 or more units inside often took more than 30 seconds of simulation time and thus disconnected the host, crashing the game.

This bus seems identical, maybe we can even adopt the fix in r16636 so that it would stop trying to spawn immediately after one unit doesn't find space to be spawned?? This would be the ideal fix.

We should still use the limitation as spawning an infinte amount of units will still result in lag-of-death.

comment:12 by elexis, 8 years ago

Milestone: Alpha 19Alpha 20

Since we have #3546 now, this can wait.

comment:13 by elexis, 8 years ago

Resolution: fixed
Status: assignedclosed

In 17474:

Limit the number of units spawned when using cheats to prevent freezing the game. Based on patch by Stan, fixes #3545.

comment:14 by elexis, 8 years ago

Keywords: review removed
Priority: Must HaveShould Have
Summary: [PATCH] Crash the game using cheats[PATCH] Freeze the game using cheats

Thanks for the patch.

Notice though that it's Math.min, not Math.Min. Please make sure to use the correct function names.

I don't see the point in adding magic values, hence I didn't add the +100. If you want to spawn more units using cheats, use the max-population cheat or play with the "unlimited pop" setting.

Note: See TracTickets for help on using tickets.