Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The /shutdown command is broken. #7223

Closed
jhcole opened this issue Apr 7, 2018 · 3 comments
Closed

The /shutdown command is broken. #7223

jhcole opened this issue Apr 7, 2018 · 3 comments
Labels
Bug Issues that were confirmed to be a bug @ Server / Client / Env.

Comments

@jhcole
Copy link

jhcole commented Apr 7, 2018

Issue type
  • Bug report
Minetest version
460b375cad05cd1c32a061aeef2fd1dfb3fb95b4
OS / Hardware

ALL

Summary

The /shutdown command is buggy.

Steps to reproduce

Type

/shutdown 90 true some message

Expected behavior

The server waits 90 seconds to shutdown then clients display the shutdown message and present a button to reconnect.

Actual behavior

The server shuts-down immediately. Clients present a generic shutdown message and do not display a button to reconnect.

See builtin/game/chatcommands.lua line 827.

@SmallJoker SmallJoker added Bug Issues that were confirmed to be a bug @ Server / Client / Env. labels Apr 7, 2018
@mtango688
Copy link
Contributor

Shutdown 900 gives a message of "Shutting down in 1m 30s" by the way.

@SmallJoker
Copy link
Member

SmallJoker commented Apr 7, 2018

Possible string.match pattern:
delay, reconnect, message = param:match("^%s*(%-?%d+)%s+([%a%d]+)(.*)")

local delay, reconnect, message = param:match("([^ ][-]?[0-9]+)([^ ]+)(.*)")

local tests = {
	"60 yes  Need to restart.",
	"-1   1", -- Empty message but valid
	"120  0",
	"120 true  NUMBER 15",
	"600 false Cheese steak jimmy's"
}

for i, v in pairs(tests) do
	delay, reconnect, message = v:match("^%s*(%-?%d+)%s+([%a%d]+)(.*)")
	assert(delay)
	assert(reconnect)
	assert(message)

	print(delay, reconnect, message)
end

@jhcole
Copy link
Author

jhcole commented Apr 8, 2018

How about this

local tests = {
	"",
	"9",
	"73",
	"817",
	"  817",
	"1e3",
	"120 0",
	"120 1",
	"120 y",
	"120 yes",
	"120 no",
	"120 true",
	"120 false",
	"120  false", -- extra space
	"120 true a shutdown message",
	"120   true    a  shutdown message", -- odd spacing
	"120 true 3.14159 and some words",
	"-1",
	"-1 1", -- setting reconnect is pointless with a negative delay
	"-31 1 this message will never be seen",
}

for _, param in ipairs(tests) do
	local delay, reconnect, message = nil, nil, nil
	delay, param = param:match("^%s*(%S+)(.*)")
	if param then reconnect, param = param:match("^%s*(%S+)(.*)") end
	if param then message = param:match("^%s*(.+)") end
	delay = tonumber(delay) or 0
	message = message or ""
	print(delay, reconnect, message)
end

All tests pass

> dofile 'test.lua'
0       nil
9       nil
73      nil
817     nil
817     nil
1000    nil
120     0
120     1
120     y
120     yes
120     no
120     true
120     false
120     false
120     true    a shutdown message
120     true    a  shutdown message
120     true    3.14159 and some words
-1      nil
-1      1
-31     1       this message will never be seen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Server / Client / Env.
Projects
None yet
Development

No branches or pull requests

3 participants