chojrak
Banned User
- Joined
- Oct 25, 2008
- Messages
- 5,832
- Solutions
- 2
- Reaction score
- 160
I re-wrote your script, it's now more clear and more up-to-date
(Note: Haven't tested, i hope it works.)
(Note: Haven't tested, i hope it works.)
Code:
local config = {
websites = {
urls = {
"http://google.com",
"http://wikipedia.org"
},
status = {
true,
true
}
},
security = {
kickall = true,
save = true,
shutdown = true
}
}
config.security.kickall = getBooleanFromString(config.security.kickall)
config.security.save = getBooleanFromString(config.security.save)
config.security.shutdown = getBooleanFromString(config.security.shutdown)
function onThink(interval, lastExecution)
for i = 1, #config.websites.urls do
local tmpUrl = config.websites.urls[i]
if(not socket.http.request(tmpUrl))
config.websites.status[i] = false
print(">> ".. tmpUrl .." seems to be offline.")
else
config.websites.status[i] = true
end
end
if(not isInArray(config.websites.status, true)) then
print(">> Server is probably under attack...")
if(config.security.kickall) then
for _, player in ipairs(getPlayersOnline()) do
doRemoveCreature(player)
end
print("\tAll players were kicked.")
end
if(config.security.save) then
doSaveServer(false)
print("\tServer has been saved.")
end
if(config.security.shutdown) then
doSetGameState(GAMESTATE_SHUTDOWN)
print("\tShutting down...")
end
end
return true
end
Last edited: