2020-06-07 23:24:48 +02:00
|
|
|
local Event = require 'utils.event'
|
2020-08-14 22:07:54 +02:00
|
|
|
local session = require 'utils.datastore.session_data'
|
2020-06-07 23:24:48 +02:00
|
|
|
local Timestamp = require 'utils.timestamp'
|
|
|
|
local Server = require 'utils.server'
|
2020-06-28 14:55:31 +02:00
|
|
|
local Color = require 'utils.color_presets'
|
2020-06-07 23:24:48 +02:00
|
|
|
|
2020-06-28 14:55:31 +02:00
|
|
|
local font_color = Color.warning
|
|
|
|
local font_welcome = {r = 150, g = 100, b = 255, a = 255}
|
2020-06-07 23:24:48 +02:00
|
|
|
local font = 'default-game'
|
|
|
|
local format = string.format
|
2018-12-18 10:42:37 +02:00
|
|
|
|
|
|
|
local brain = {
|
2020-06-07 23:24:48 +02:00
|
|
|
[1] = {'Our Discord server is at: https://getcomfy.eu/discord'},
|
|
|
|
[2] = {
|
2020-08-21 20:32:07 +02:00
|
|
|
'Need an admin? Join our discord at: https://getcomfy.eu/discord,',
|
2020-08-21 20:32:54 +02:00
|
|
|
'and report it in #i-need-halp',
|
2020-08-21 20:32:07 +02:00
|
|
|
'If you have played for more than 5h in our maps then,',
|
2020-06-28 14:55:31 +02:00
|
|
|
'you are eligible to run the command /jail and /free'
|
2020-06-07 23:24:48 +02:00
|
|
|
},
|
2020-10-24 14:46:14 +02:00
|
|
|
[3] = {'Scenario repository for download:', 'https://github.com/M3wM3w/ComfyFactorio'},
|
|
|
|
[4] = {
|
|
|
|
'If you feel like the server is lagging, run the following command:',
|
|
|
|
'/server-ups',
|
|
|
|
'This will display the server UPS on your top right screen.'
|
2020-11-11 23:19:39 +02:00
|
|
|
},
|
|
|
|
[5] = {
|
|
|
|
"If you're not trusted - ask a trusted player or an admin to trust you."
|
2020-10-24 14:46:14 +02:00
|
|
|
}
|
2018-12-18 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local links = {
|
2020-06-07 23:24:48 +02:00
|
|
|
['admin'] = brain[2],
|
|
|
|
['administrator'] = brain[2],
|
|
|
|
['discord'] = brain[1],
|
|
|
|
['download'] = brain[3],
|
|
|
|
['github'] = brain[3],
|
|
|
|
['greifer'] = brain[2],
|
|
|
|
['grief'] = brain[2],
|
|
|
|
['griefer'] = brain[2],
|
|
|
|
['griefing'] = brain[2],
|
|
|
|
['mod'] = brain[2],
|
|
|
|
['moderator'] = brain[2],
|
|
|
|
['scenario'] = brain[3],
|
|
|
|
['stealing'] = brain[2],
|
|
|
|
['stole'] = brain[2],
|
|
|
|
['troll'] = brain[2],
|
2020-10-24 14:46:14 +02:00
|
|
|
['lag'] = brain[4],
|
2020-11-11 23:19:39 +02:00
|
|
|
['lagging'] = brain[4],
|
|
|
|
['trust'] = brain[5],
|
|
|
|
['trusted'] = brain[5],
|
|
|
|
['untrusted'] = brain[5]
|
2018-12-18 10:42:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local function on_player_created(event)
|
2019-06-24 19:57:24 +02:00
|
|
|
local player = game.players[event.player_index]
|
2020-06-28 14:55:31 +02:00
|
|
|
player.print('[font=' .. font .. ']' .. 'Join the comfy discord >> getcomfy.eu/discord' .. '[/font]', font_welcome)
|
2018-12-18 10:42:37 +02:00
|
|
|
end
|
|
|
|
|
2019-06-24 13:12:13 +02:00
|
|
|
commands.add_command(
|
|
|
|
'trust',
|
2019-06-29 10:13:52 +02:00
|
|
|
'Promotes a player to trusted!',
|
2019-06-24 13:12:13 +02:00
|
|
|
function(cmd)
|
2019-07-07 13:00:50 +02:00
|
|
|
local trusted = session.get_trusted_table()
|
2019-06-24 13:12:13 +02:00
|
|
|
local player = game.player
|
|
|
|
|
2020-08-14 22:41:45 +02:00
|
|
|
if player and player.valid then
|
|
|
|
if not player.admin then
|
|
|
|
player.print("You're not admin!", {r = 1, g = 0.5, b = 0.1})
|
|
|
|
return
|
2019-06-24 13:12:13 +02:00
|
|
|
end
|
|
|
|
|
2020-06-07 23:24:48 +02:00
|
|
|
if cmd.parameter == nil then
|
|
|
|
return
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
local target_player = game.players[cmd.parameter]
|
|
|
|
if target_player then
|
2020-08-14 22:41:45 +02:00
|
|
|
if trusted[target_player.name] then
|
2020-06-07 23:24:48 +02:00
|
|
|
game.print(target_player.name .. ' is already trusted!')
|
|
|
|
return
|
|
|
|
end
|
2019-07-07 13:00:50 +02:00
|
|
|
trusted[target_player.name] = true
|
2020-06-07 23:24:48 +02:00
|
|
|
game.print(target_player.name .. ' is now a trusted player.', {r = 0.22, g = 0.99, b = 0.99})
|
2019-07-04 18:56:45 +02:00
|
|
|
for _, a in pairs(game.connected_players) do
|
2020-08-14 22:41:45 +02:00
|
|
|
if a.admin and a.name ~= player.name then
|
2020-11-11 23:19:39 +02:00
|
|
|
a.print('[ADMIN]: ' .. player.name .. ' trusted ' .. target_player.name, {r = 1, g = 0.5, b = 0.1})
|
2019-07-04 18:56:45 +02:00
|
|
|
end
|
2019-06-24 19:57:24 +02:00
|
|
|
end
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
else
|
2020-06-07 23:24:48 +02:00
|
|
|
if cmd.parameter == nil then
|
|
|
|
return
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
local target_player = game.players[cmd.parameter]
|
|
|
|
if target_player then
|
2020-06-07 23:24:48 +02:00
|
|
|
if trusted[target_player.name] == true then
|
|
|
|
game.print(target_player.name .. ' is already trusted!')
|
|
|
|
return
|
|
|
|
end
|
2019-07-07 13:00:50 +02:00
|
|
|
trusted[target_player.name] = true
|
2020-06-07 23:24:48 +02:00
|
|
|
game.print(target_player.name .. ' is now a trusted player.', {r = 0.22, g = 0.99, b = 0.99})
|
2019-07-04 18:56:45 +02:00
|
|
|
end
|
2019-06-24 13:12:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
commands.add_command(
|
|
|
|
'untrust',
|
2019-06-29 10:13:52 +02:00
|
|
|
'Demotes a player from trusted!',
|
2019-06-24 13:12:13 +02:00
|
|
|
function(cmd)
|
2019-07-07 13:00:50 +02:00
|
|
|
local trusted = session.get_trusted_table()
|
2019-06-24 13:12:13 +02:00
|
|
|
local player = game.player
|
|
|
|
local p
|
|
|
|
|
|
|
|
if player then
|
2019-07-04 18:56:45 +02:00
|
|
|
if player ~= nil then
|
|
|
|
p = player.print
|
|
|
|
if not player.admin then
|
|
|
|
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
p = log
|
2019-06-24 13:12:13 +02:00
|
|
|
end
|
|
|
|
|
2020-06-07 23:24:48 +02:00
|
|
|
if cmd.parameter == nil then
|
|
|
|
return
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
local target_player = game.players[cmd.parameter]
|
2020-06-07 23:24:48 +02:00
|
|
|
if target_player then
|
|
|
|
if trusted[target_player.name] == false then
|
|
|
|
game.print(target_player.name .. ' is already untrusted!')
|
|
|
|
return
|
|
|
|
end
|
2019-07-07 13:00:50 +02:00
|
|
|
trusted[target_player.name] = false
|
2020-06-07 23:24:48 +02:00
|
|
|
game.print(target_player.name .. ' is now untrusted.', {r = 0.22, g = 0.99, b = 0.99})
|
2019-07-04 18:56:45 +02:00
|
|
|
for _, a in pairs(game.connected_players) do
|
|
|
|
if a.admin == true and a.name ~= player.name then
|
2020-11-11 23:19:39 +02:00
|
|
|
a.print('[ADMIN]: ' .. player.name .. ' untrusted ' .. target_player.name, {r = 1, g = 0.5, b = 0.1})
|
2019-07-04 18:56:45 +02:00
|
|
|
end
|
2019-06-24 19:57:24 +02:00
|
|
|
end
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
else
|
2020-06-07 23:24:48 +02:00
|
|
|
if cmd.parameter == nil then
|
|
|
|
return
|
|
|
|
end
|
2019-07-04 18:56:45 +02:00
|
|
|
local target_player = game.players[cmd.parameter]
|
2020-06-07 23:24:48 +02:00
|
|
|
if target_player then
|
|
|
|
if trusted[target_player.name] == false then
|
|
|
|
game.print(target_player.name .. ' is already untrusted!')
|
|
|
|
return
|
|
|
|
end
|
2019-07-07 13:00:50 +02:00
|
|
|
trusted[target_player.name] = false
|
2020-06-07 23:24:48 +02:00
|
|
|
game.print(target_player.name .. ' is now untrusted.', {r = 0.22, g = 0.99, b = 0.99})
|
2019-07-04 18:56:45 +02:00
|
|
|
end
|
2019-06-24 13:12:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2018-12-19 11:43:25 +02:00
|
|
|
|
|
|
|
local function process_bot_answers(event)
|
2019-06-24 19:57:24 +02:00
|
|
|
local player = game.players[event.player_index]
|
2020-12-28 13:05:59 +02:00
|
|
|
if player.admin then
|
|
|
|
return
|
|
|
|
end
|
2019-06-24 19:57:24 +02:00
|
|
|
local message = event.message
|
|
|
|
message = string.lower(message)
|
2020-06-07 23:24:48 +02:00
|
|
|
for word in string.gmatch(message, '%g+') do
|
2019-06-24 19:57:24 +02:00
|
|
|
if links[word] then
|
|
|
|
for _, bot_answer in pairs(links[word]) do
|
2020-06-07 23:24:48 +02:00
|
|
|
player.print('[font=' .. font .. ']' .. bot_answer .. '[/font]', font_color)
|
2019-06-24 19:57:24 +02:00
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2018-12-18 10:42:37 +02:00
|
|
|
end
|
|
|
|
|
2018-12-19 11:43:25 +02:00
|
|
|
local function on_console_chat(event)
|
2020-06-07 23:24:48 +02:00
|
|
|
if not event.player_index then
|
|
|
|
return
|
|
|
|
end
|
2020-10-24 14:46:14 +02:00
|
|
|
local secs = Server.get_current_time()
|
|
|
|
if not secs then
|
|
|
|
return
|
|
|
|
end
|
2020-06-07 23:24:48 +02:00
|
|
|
process_bot_answers(event)
|
2018-12-19 11:43:25 +02:00
|
|
|
end
|
|
|
|
|
2018-12-19 16:59:31 +02:00
|
|
|
--share vision of silent-commands with other admins
|
2020-06-07 23:24:48 +02:00
|
|
|
local function on_console_command(event)
|
|
|
|
local cmd = event.command
|
|
|
|
if not event.player_index then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local param = event.parameters
|
|
|
|
|
|
|
|
if not player.admin then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local server_time = Server.get_current_time()
|
|
|
|
if server_time then
|
2020-06-07 23:35:18 +02:00
|
|
|
server_time = format(' (Server time: %s)', Timestamp.to_string(server_time))
|
2020-06-07 23:24:48 +02:00
|
|
|
else
|
2020-06-07 23:39:26 +02:00
|
|
|
server_time = ' at tick: ' .. game.tick
|
2020-06-07 23:24:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if string.len(param) <= 0 then
|
|
|
|
param = nil
|
|
|
|
end
|
|
|
|
|
2020-06-09 22:58:02 +02:00
|
|
|
local commands = {
|
|
|
|
['editor'] = true,
|
|
|
|
['silent-command'] = true,
|
2020-06-24 12:40:18 +02:00
|
|
|
['sc'] = true,
|
|
|
|
['debug'] = true
|
2020-06-09 22:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if not commands[cmd] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-06-07 23:24:48 +02:00
|
|
|
if player then
|
2020-06-09 22:58:02 +02:00
|
|
|
for _, p in pairs(game.connected_players) do
|
|
|
|
if p.admin == true and p.name ~= player.name then
|
|
|
|
if param then
|
2020-11-11 23:19:39 +02:00
|
|
|
p.print(player.name .. ' ran: ' .. cmd .. ' "' .. param .. '" ' .. server_time, {r = 0.22, g = 0.99, b = 0.99})
|
2020-06-09 22:58:02 +02:00
|
|
|
else
|
|
|
|
p.print(player.name .. ' ran: ' .. cmd .. server_time, {r = 0.22, g = 0.99, b = 0.99})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-07 23:24:48 +02:00
|
|
|
if param then
|
2020-06-07 23:39:26 +02:00
|
|
|
print(player.name .. ' ran: ' .. cmd .. ' "' .. param .. '" ' .. server_time)
|
2020-06-07 23:24:48 +02:00
|
|
|
return
|
|
|
|
else
|
|
|
|
print(player.name .. ' ran: ' .. cmd .. server_time)
|
|
|
|
return
|
2019-06-24 19:57:24 +02:00
|
|
|
end
|
2020-06-07 23:24:48 +02:00
|
|
|
else
|
|
|
|
if param then
|
2020-06-07 23:39:26 +02:00
|
|
|
print('ran: ' .. cmd .. ' "' .. param .. '" ' .. server_time)
|
2020-06-07 23:24:48 +02:00
|
|
|
return
|
|
|
|
else
|
|
|
|
print('ran: ' .. cmd .. server_time)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2018-12-19 11:43:25 +02:00
|
|
|
end
|
|
|
|
|
2020-06-07 23:24:48 +02:00
|
|
|
Event.add(defines.events.on_player_created, on_player_created)
|
|
|
|
Event.add(defines.events.on_console_chat, on_console_chat)
|
|
|
|
Event.add(defines.events.on_console_command, on_console_command)
|