2019-01-02 17:34:17 +02:00
|
|
|
local Game = require 'utils.game'
|
|
|
|
local Timestamp = require 'utils.timestamp'
|
|
|
|
local Command = require 'utils.command'
|
2019-02-08 23:55:57 +02:00
|
|
|
local Settings = require 'utils.redmew_settings'
|
2019-02-03 01:10:40 +02:00
|
|
|
local Utils = require 'utils.core'
|
|
|
|
local Report = require 'features.report'
|
|
|
|
local Server = require 'features.server'
|
2019-01-31 01:36:57 +02:00
|
|
|
local Walkabout = require 'features.walkabout'
|
2019-01-29 01:59:28 +02:00
|
|
|
local PlayerStats = require 'features.player_stats'
|
2019-02-08 23:55:57 +02:00
|
|
|
local Rank = require 'features.rank_system'
|
|
|
|
local Donator = require 'features.donator'
|
2019-01-02 17:34:17 +02:00
|
|
|
|
|
|
|
local format = string.format
|
|
|
|
local ceil = math.ceil
|
2019-01-22 22:03:34 +02:00
|
|
|
local concat = table.concat
|
2019-02-02 17:08:09 +02:00
|
|
|
local pcall = pcall
|
|
|
|
local tostring = tostring
|
|
|
|
local tonumber = tonumber
|
|
|
|
local pairs = pairs
|
2019-01-02 17:34:17 +02:00
|
|
|
|
|
|
|
--- Kill a player with fish as the cause of death.
|
|
|
|
local function do_fish_kill(player, suicide)
|
|
|
|
local c = player.character
|
|
|
|
if not c then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local e = player.surface.create_entity {name = 'fish', position = player.position}
|
|
|
|
c.die(player.force, e)
|
|
|
|
|
|
|
|
-- Don't want people killing themselves for free fish.
|
|
|
|
if suicide then
|
|
|
|
e.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Kill a player: admins and the server can kill others, non-admins can only kill themselves
|
|
|
|
local function kill(args, player)
|
|
|
|
local target_name = args.player
|
|
|
|
local target
|
|
|
|
if target_name then
|
|
|
|
target = game.players[target_name]
|
|
|
|
if not target then
|
|
|
|
Game.player_print(format('Player %s was not found.', target_name))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-31 01:36:57 +02:00
|
|
|
if (player and Walkabout.is_on_walkabout(player.index)) or (target and Walkabout.is_on_walkabout(target.index)) then
|
2019-01-02 17:34:17 +02:00
|
|
|
Game.player_print("A player on walkabout cannot be killed by a mere fish, don't waste your efforts.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not target and player then
|
|
|
|
if not do_fish_kill(player, true) then
|
|
|
|
Game.player_print("Sorry, you don't have a character to kill.")
|
|
|
|
end
|
|
|
|
elseif player then
|
|
|
|
if target == player then
|
|
|
|
if not do_fish_kill(player, true) then
|
|
|
|
Game.player_print("Sorry, you don't have a character to kill.")
|
|
|
|
end
|
|
|
|
elseif target and player.admin then
|
|
|
|
if not do_fish_kill(target) then
|
|
|
|
Game.player_print(table.concat {"'Sorry, '", target.name, "' doesn't have a character to kill."})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Game.player_print("Sorry you don't have permission to use the kill command on other players.")
|
|
|
|
end
|
|
|
|
elseif target then
|
|
|
|
if not do_fish_kill(target) then
|
|
|
|
Game.player_print(table.concat {"'Sorry, '", target.name, "' doesn't have a character to kill."})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Check players' afk times
|
|
|
|
local function afk()
|
|
|
|
local count = 0
|
|
|
|
for _, v in pairs(game.players) do
|
|
|
|
if v.afk_time > 300 then
|
|
|
|
count = count + 1
|
|
|
|
local time = ' '
|
|
|
|
if v.afk_time > 21600 then
|
|
|
|
time = time .. math.floor(v.afk_time / 216000) .. ' hours '
|
|
|
|
end
|
|
|
|
if v.afk_time > 3600 then
|
|
|
|
time = time .. math.floor(v.afk_time / 3600) % 60 .. ' minutes and '
|
|
|
|
end
|
|
|
|
time = time .. math.floor(v.afk_time / 60) % 60 .. ' seconds.'
|
|
|
|
Game.player_print(v.name .. ' has been afk for' .. time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if count == 0 then
|
|
|
|
Game.player_print('No players afk.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Lets a player set their zoom level
|
|
|
|
local function zoom(args, player)
|
|
|
|
if tonumber(args.zoom) then
|
|
|
|
player.zoom = tonumber(args.zoom)
|
|
|
|
else
|
|
|
|
Game.player_print('You must give zoom a number.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Creates an alert for the player at the location of their target
|
|
|
|
local function find_player(args, player)
|
|
|
|
local name = args.player
|
|
|
|
|
|
|
|
local target = game.players[name]
|
|
|
|
if not target then
|
|
|
|
Game.player_print('player ' .. name .. ' not found')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
target = target.character
|
|
|
|
if not target or not target.valid then
|
|
|
|
Game.player_print('player ' .. name .. ' does not have a character')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
player.add_custom_alert(target, {type = 'virtual', name = 'signal-F'}, name, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Turns on rail block visualization for player
|
|
|
|
local function show_rail_block(_, player)
|
|
|
|
local vs = player.game_view_settings
|
|
|
|
local show = not vs.show_rail_block_visualisation
|
|
|
|
vs.show_rail_block_visualisation = show
|
|
|
|
|
|
|
|
Game.player_print('show_rail_block_visualisation set to ' .. tostring(show))
|
|
|
|
end
|
|
|
|
|
2019-01-29 01:59:28 +02:00
|
|
|
--- Provides the time on the server
|
2019-01-02 17:34:17 +02:00
|
|
|
local function server_time(_, player)
|
|
|
|
local p
|
|
|
|
if not player then
|
|
|
|
p = print
|
|
|
|
elseif player.valid then
|
|
|
|
p = player.print
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local secs = Server.get_current_time()
|
|
|
|
if secs == nil then
|
|
|
|
p('Server time is not available, is this game running on a Redmew server?')
|
|
|
|
else
|
|
|
|
p(Timestamp.to_string(secs))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-08 22:58:12 +02:00
|
|
|
local function search_command(arguments)
|
2019-01-02 17:34:17 +02:00
|
|
|
local keyword = arguments.keyword
|
2019-01-03 19:16:50 +02:00
|
|
|
local p = Game.player_print
|
2019-01-02 17:34:17 +02:00
|
|
|
if #keyword < 2 then
|
|
|
|
p('Keyword should be 2 characters or more')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local per_page = 7
|
|
|
|
local matches = Command.search(keyword)
|
|
|
|
local count = #matches
|
|
|
|
|
|
|
|
if count == 0 then
|
|
|
|
p('---- 0 Search Results ----')
|
|
|
|
p(format('No commands found matching "%s"', keyword))
|
|
|
|
p('-------------------------')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local page = tonumber(arguments.page)
|
|
|
|
local pages = ceil(count / per_page)
|
|
|
|
|
|
|
|
if nil == page then
|
|
|
|
p('Page should be a valid number')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- just show the last page
|
|
|
|
if page > pages then
|
|
|
|
page = pages
|
|
|
|
end
|
|
|
|
|
|
|
|
if page < 1 then
|
|
|
|
page = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local page_start = per_page * (page - 1) + 1
|
|
|
|
local page_end = per_page * page
|
|
|
|
page_end = page_end <= count and page_end or count
|
|
|
|
|
|
|
|
p(format('---- %d Search %s -----', count, count == 1 and 'Result' or 'Results'))
|
|
|
|
p(format('Searching for: "%s"', keyword))
|
|
|
|
for i = page_start, page_end do
|
|
|
|
p(format('[%d] /%s', i, matches[i]))
|
|
|
|
end
|
|
|
|
p(format('-------- Page %d / %d --------', page, pages))
|
|
|
|
end
|
|
|
|
|
2019-01-22 22:03:34 +02:00
|
|
|
local function list_seeds()
|
|
|
|
local seeds = {}
|
|
|
|
local count_of_seeds = 0
|
|
|
|
for _, surface in pairs(game.surfaces) do
|
|
|
|
seeds[count_of_seeds + 1] = surface.name
|
|
|
|
seeds[count_of_seeds + 2] = ': '
|
|
|
|
seeds[count_of_seeds + 3] = tostring(surface.map_gen_settings.seed)
|
|
|
|
count_of_seeds = count_of_seeds + 4
|
|
|
|
seeds[count_of_seeds] = ', '
|
|
|
|
end
|
|
|
|
|
|
|
|
seeds[#seeds] = nil
|
|
|
|
seeds = concat(seeds)
|
|
|
|
Game.player_print(seeds)
|
|
|
|
end
|
|
|
|
|
2019-01-27 08:27:57 +02:00
|
|
|
local function print_version()
|
2019-01-27 21:40:07 +02:00
|
|
|
local version_str
|
|
|
|
if global.redmew_version then
|
|
|
|
version_str = global.redmew_version
|
|
|
|
else
|
|
|
|
version_str = 'This map was created from source code, only releases (zips with names) and server saves have versions'
|
|
|
|
end
|
|
|
|
Game.player_print(version_str)
|
2019-01-27 08:27:57 +02:00
|
|
|
end
|
|
|
|
|
2019-01-29 01:59:28 +02:00
|
|
|
--- Prints information about the target player
|
|
|
|
local function print_player_info(args, player)
|
|
|
|
local name = args.player
|
|
|
|
local target = game.players[name]
|
|
|
|
if not target then
|
|
|
|
Game.player_print('Target not found')
|
2019-02-03 01:14:48 +02:00
|
|
|
return
|
2019-01-29 01:59:28 +02:00
|
|
|
end
|
2019-02-03 01:14:48 +02:00
|
|
|
|
2019-01-31 02:33:11 +02:00
|
|
|
local index = target.index
|
2019-01-29 01:59:28 +02:00
|
|
|
local info_t = {
|
|
|
|
'Name: ' .. name,
|
2019-02-03 01:09:01 +02:00
|
|
|
target.connected and 'Online: yes' or 'Online: no',
|
2019-01-31 02:33:11 +02:00
|
|
|
'Index: ' .. target.index,
|
2019-02-13 03:20:35 +02:00
|
|
|
--'Rank: ' .. Rank.get_player_rank_name(name),
|
2019-02-08 23:55:57 +02:00
|
|
|
Donator.is_donator(target.name) and 'Donator: yes' or 'Donator: no',
|
2019-01-31 02:33:11 +02:00
|
|
|
'Time played: ' .. Utils.format_time(target.online_time),
|
2019-02-03 01:19:59 +02:00
|
|
|
'AFK time: ' .. Utils.format_time(target.afk_time or 0),
|
2019-01-31 02:33:11 +02:00
|
|
|
'Force: ' .. target.force.name,
|
|
|
|
'Surface: ' .. target.surface.name,
|
|
|
|
'Tag: ' .. target.tag,
|
2019-01-29 01:59:28 +02:00
|
|
|
'Distance walked: ' .. PlayerStats.get_walk_distance(index),
|
|
|
|
'Coin earned: ' .. PlayerStats.get_coin_earned(index),
|
|
|
|
'Coin spent: ' .. PlayerStats.get_coin_spent(index),
|
|
|
|
'Deaths: ' .. PlayerStats.get_death_count(index),
|
|
|
|
'Crafted items: ' .. PlayerStats.get_crafted_item(index),
|
|
|
|
'Chat messages: ' .. PlayerStats.get_console_chat(index)
|
|
|
|
}
|
2019-01-31 02:33:11 +02:00
|
|
|
Game.player_print(concat(info_t, '\n- '))
|
2019-01-29 01:59:28 +02:00
|
|
|
|
2019-01-31 02:33:11 +02:00
|
|
|
if (not player or player.admin) and args.inventory then
|
|
|
|
local m_inventory = target.get_inventory(defines.inventory.player_main)
|
|
|
|
m_inventory = m_inventory.get_contents()
|
|
|
|
local q_inventory = target.get_inventory(defines.inventory.player_quickbar)
|
|
|
|
q_inventory = q_inventory.get_contents()
|
2019-01-29 01:59:28 +02:00
|
|
|
Game.player_print('Main and hotbar inventories: ')
|
|
|
|
Game.player_print(serpent.line(m_inventory))
|
|
|
|
Game.player_print(serpent.line(q_inventory))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-08 22:58:12 +02:00
|
|
|
-- Command registrations
|
2019-01-02 17:34:17 +02:00
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'kill',
|
|
|
|
{
|
|
|
|
description = 'Will kill you.',
|
|
|
|
arguments = {'player'},
|
|
|
|
default_values = {player = false},
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
kill
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'afk',
|
|
|
|
{
|
|
|
|
description = 'Shows how long players have been afk.',
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
afk
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'zoom',
|
|
|
|
{
|
|
|
|
description = 'Sets your zoom.',
|
2019-01-29 01:59:28 +02:00
|
|
|
arguments = {'zoom'}
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
zoom
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'find',
|
|
|
|
{
|
|
|
|
description = 'shows an alert on the map where the player is located',
|
2019-01-29 01:59:28 +02:00
|
|
|
arguments = {'player'}
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
find_player
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'show-rail-block',
|
|
|
|
{
|
2019-01-29 01:59:28 +02:00
|
|
|
description = 'Toggles rail block visualisation.'
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
show_rail_block
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'server-time',
|
|
|
|
{
|
|
|
|
description = "Prints the server's time.",
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
server_time
|
|
|
|
)
|
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'search-command',
|
|
|
|
{
|
|
|
|
description = 'Search for commands matching the keyword in name or description',
|
|
|
|
arguments = {'keyword', 'page'},
|
2019-01-03 19:09:26 +02:00
|
|
|
default_values = {page = 1},
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
search_command
|
|
|
|
)
|
|
|
|
|
2019-01-22 22:03:34 +02:00
|
|
|
Command.add(
|
|
|
|
'seeds',
|
|
|
|
{
|
|
|
|
description = 'List the seeds of all surfaces',
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-22 22:03:34 +02:00
|
|
|
},
|
|
|
|
list_seeds
|
|
|
|
)
|
|
|
|
|
2019-01-27 08:27:57 +02:00
|
|
|
Command.add(
|
|
|
|
'redmew-version',
|
|
|
|
{
|
|
|
|
description = 'Prints the version of the RedMew scenario',
|
2019-01-29 01:59:28 +02:00
|
|
|
allowed_by_server = true
|
2019-01-27 08:27:57 +02:00
|
|
|
},
|
|
|
|
print_version
|
|
|
|
)
|
|
|
|
|
2019-01-29 01:59:28 +02:00
|
|
|
Command.add(
|
|
|
|
'whois',
|
|
|
|
{
|
2019-01-31 02:33:11 +02:00
|
|
|
description = 'provides information about a given player, admins can see the inventory of a player by adding "yes" as a second argument',
|
2019-01-29 01:59:28 +02:00
|
|
|
arguments = {'player', 'inventory'},
|
|
|
|
default_values = {inventory = false},
|
|
|
|
allowed_by_server = true
|
|
|
|
},
|
|
|
|
print_player_info
|
|
|
|
)
|
|
|
|
|
|
|
|
-- Commands with no functions, only calls to other modules
|
2019-01-02 17:34:17 +02:00
|
|
|
|
|
|
|
Command.add(
|
|
|
|
'report',
|
|
|
|
{
|
|
|
|
description = 'Reports a user to admins',
|
|
|
|
arguments = {'player', 'message'},
|
2019-01-29 01:59:28 +02:00
|
|
|
capture_excess_arguments = true
|
2019-01-02 17:34:17 +02:00
|
|
|
},
|
|
|
|
Report.report_command
|
|
|
|
)
|
|
|
|
|
2019-01-30 05:52:43 +02:00
|
|
|
-- No man's land / free for all
|
2019-02-02 19:09:56 +02:00
|
|
|
Command.add('redmew-setting-set', {
|
2019-02-02 17:08:09 +02:00
|
|
|
description = 'Set a setting for yourself',
|
|
|
|
arguments = {'setting_name', 'new_value'},
|
|
|
|
capture_excess_arguments = true,
|
|
|
|
}, function (arguments, player)
|
|
|
|
local value
|
|
|
|
local setting_name = arguments.setting_name
|
2019-02-02 19:09:56 +02:00
|
|
|
local success, data = pcall(function()
|
2019-02-02 17:08:09 +02:00
|
|
|
value = Settings.set(player.index, setting_name, arguments.new_value)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not success then
|
2019-02-04 18:37:23 +02:00
|
|
|
local i = data:find('%s')
|
|
|
|
player.print(data:sub(i + 1))
|
2019-02-02 17:08:09 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
player.print(format('Changed "%s" to: "%s"', setting_name, value))
|
|
|
|
end)
|
|
|
|
|
2019-02-02 19:09:56 +02:00
|
|
|
Command.add('redmew-setting-get', {
|
2019-02-02 17:08:09 +02:00
|
|
|
description = 'Display a setting value for yourself',
|
|
|
|
arguments = {'setting_name'},
|
|
|
|
}, function (arguments, player)
|
|
|
|
local value
|
|
|
|
local setting_name = arguments.setting_name
|
2019-02-02 19:09:56 +02:00
|
|
|
local success, data = pcall(function()
|
2019-02-02 17:08:09 +02:00
|
|
|
value = Settings.get(player.index, setting_name)
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not success then
|
2019-02-04 18:37:23 +02:00
|
|
|
local i = data:find('%s')
|
|
|
|
player.print(data:sub(i + 1))
|
2019-02-02 17:08:09 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
player.print(format('Setting "%s" has a value of: "%s"', setting_name, value))
|
|
|
|
end)
|
2019-02-02 17:28:22 +02:00
|
|
|
|
2019-02-02 19:09:56 +02:00
|
|
|
Command.add('redmew-setting-all', {
|
2019-02-02 17:28:22 +02:00
|
|
|
description = 'Display all settings for yourself',
|
|
|
|
}, function (_, player)
|
|
|
|
for name, value in pairs(Settings.all(player.index)) do
|
|
|
|
player.print(format('%s=%s', name, value))
|
|
|
|
end
|
|
|
|
end)
|