Page 1 of 1
API request : admin commands & chat parsing
Posted: Thu Oct 13, 2016 12:46 pm
by LotA
The only actual way to kick/ban players is by using either /kick or /ban commands as an admin.
We need a way to do this even if no admin is connected, via the lua api (so we can build votekick systems for instance)
something like :
kick (uint player-id, string reason)
ban (uint player-id, uint ban-duration, string reason)
mute (uint player-id, uint duration)
Also noted people requesting a way to get the ping of players
In the meantime, it could be really handy to be able to somehow parse the chat. Guis are great but custom chat commands are still a must have
I could see something like event on_chat_message
contains
uint player id
string[] words
Thanks you devs

Re: API request : admin commands & chat parsing
Posted: Thu Oct 13, 2016 1:26 pm
by aubergine18
Mods can already provide a
remote interface which players can access via the console using hte `/c` prefix, for example:
Code: Select all
/c remote.call( 'someNamespace', 'someMehtod', { someData } )
For allowing custom console messages, which would potentially be nicer for players in some contexts, maybe a `custom-console` prototype could be added (working in much the same way as `custom-input`)?
Code: Select all
data:extend {
{
type = "custom-console",
name = "bob", -- must prefix console messages with /bob <msg>
}
}
Scripts could then listen for events like so:
Code: Select all
script.on_event( "bob", function( event )
-- event.message = <msg> typed by player
end )
So if player types `/bob foo` in to console, then `event.message` == `"foo"`.
The game would reject any constom-console prototypes using reserved names (eg. existing commands for vanilla game), it would be up to modders to ensure their console command nanes are unique.
Something I'd like even more would be akin to Sublime Text's command palette (see 3rd slide on their home page):
https://www.sublimetext.com/
Mods could register their own commands to the list and user simply has to type few chars to select desired command. If it weren't for the localisation issues, this sort of thing could be implemented by mods (currently there is no way for mods to access the localised text, meaning mods can never achieve any reliable level of list filtering).
Re: API request : admin commands & chat parsing
Posted: Thu Oct 13, 2016 2:40 pm
by LotA
Remote calls are great, but not ease-of-use enough to my opinion. At least, not for everyday/everybody use within a scenario
edit : Moreover, remote calls are lua commands and you might not want to give access to lua commands to everybody
A custom console like you propose would be neat on that matter clean and all. But i guess it would require quite work...
With just this simple chat event i described , one can already define words as commands trigger in a very similar manner
Code: Select all
script.on_event( defines.script.on_chat_message, function( event )
-- you can even easily test / set permissions/rights managments
if arg[0] == "!command" and has_permission(event.player_index) then
-- do something, using arg[n] as additionnal params
end
end )
Modders just have to take care their command doesn't conflict with any other but i guess that's fine
Additionally, this event can be used to prevent spam / injuring etc
Re: API request : admin commands & chat parsing
Posted: Thu Oct 13, 2016 7:57 pm
by aubergine18
event handler return values are ignored, so how would the event be able to prevent messages/commands being echoed to team, player, etc?
Re: API request : admin commands & chat parsing
Posted: Thu Oct 13, 2016 9:05 pm
by LotA
afaik there is no way to chat restrict player, I guess a mute option is also to be asked.
Indeed this event wouldn't let you "filter" the message and censor it but it would let you analyze it and sanction the author preventing further messages
Re: API request : admin commands & chat parsing
Posted: Fri Oct 21, 2016 12:34 pm
by aubergine18
Been thinking about this some more recently, IMO rather than just listening to everything in chat, it would be far better to have a way to denote custom commands (other than /c remote.call).
They could be prefixed with exclamation mark `!` (aka "pling"). Whenever that appears at start of a console input, an event `on_pling` gets fired. The event could have following props:
* tick
* player_index
* name = all chars between the initial `!` and first space or EOL, whichever comes first.
* message = the full message, with `!` removed (or an array of 'words' = split full message on space char, ie. words can contain numbers, punctuation etc)
For example, the recently released Map Ping mod, could listen for `!!` ( `name == '!'` ) and place a map marker.
Code: Select all
script.on_event( defines.events.on_pling, function( data )
if data.name == "!" then
-- put map marker at game.players[data.player_index].position
end
end
If a mod added the Factorio Bot as sort of a player-controlled drone, the player could communicate with it via commands (more engaging than a GUI imo)...
> !bot follow
> !bot mine
> !bot defend
Code: Select all
if data.name == bot then
-- take second word as command
-- look up command handler function in some dictionary
-- if found, invoke it
end
Using dictionaries it is fairly trivial to handle different languages, so long as the commands are kept nice and simple. Most stuff can be determined based on the player - eg. where they are, what they've selected/opened, etc.
Pling commands would be echoed to the player who entered them, but not other players. Invoked code in mods could optionally .print() responses or create explosion entity on map for notification sound (like the Map Ping mod does). Unrecognised plings would be ignored silently.
Re: API request : admin commands & chat parsing
Posted: Fri Oct 21, 2016 5:31 pm
by Rseding91
The API was specifically setup so that mods can't do what admins can do so it can't be abused through the console or by mods (mod demotes actual admin/kicks actual admin).
Re: API request : admin commands & chat parsing
Posted: Fri Oct 21, 2016 10:53 pm
by aubergine18
What about the other uses though, such the "pling commands" as an alternate interaction model for mod-human interaction?
Re: API request : admin commands & chat parsing
Posted: Sat Oct 22, 2016 12:14 am
by aubergine18
Another use for pling commands:
!say hello folks
A mod could parse the "say" command and display remaining text as a flying-text over players' head on the map. This would make it easy to have localised communications that only people in that area of map can see, all done via familiar chat interface. Other players in proximity would see the flying-text and could respond via their own console.
Idea based on: Player text balloons and taunts
viewtopic.php?f=6&t=34936
Re: API request : admin commands & chat parsing
Posted: Mon Oct 24, 2016 11:57 am
by LotA
Rseding91 wrote:The API was specifically setup so that mods can't do what admins can do so it can't be abused through the console or by mods (mod demotes actual admin/kicks actual admin).
I certainly agree that demoting/promoting must only be an admin user action because that would be a huge security leak. Moreover, it's not that hard to build a permission/rights management script. But as a minecraft modder and server administrator (of course those games are much different still...) I can assure you that it's absolutely needed to be able to automatize kick/ban under certain circumstances.
In minecraft it's mostly about cheats and glitchs. But it's also about grief which can be a problem for factorio mp too as any griefer can ruin hours of cooperative play in a few seconds. Currently, if no admin is connected, a griefer is just free to do anything he wants. That's why I wanted to build a votekick system. But teleporting the player to a new surface just feels "poor". I even think that more powerful systems with automatic detection and sanctioning of behaviors/actions will, at some point, be a must have.
I don't really see a problem regarding mods.. It's your job as a server owner to install & configure mods... Just don't install untrustworthy mods. If we need more security, make it so admins can't be kicked through lua
And for commands, well as long as they're not available for anyone (and you certainly should never do that) well there can't be any problem. (And that's why we also need to be able to parse the game chat)