game.is_multiplayer required

Post Reply
acabin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Apr 19, 2016 8:13 am
Contact:

game.is_multiplayer required

Post by acabin »

Because I'm working on a permission system, i'd like to let the people who load saves from singleplayer have admin and all permissions. Is that possible?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: game.is_multiplayer required

Post by Rseding91 »

Loading a save from single player already has the player as an admin.
If you want to get ahold of me I'm almost always on Discord.

acabin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Apr 19, 2016 8:13 am
Contact:

Re: game.is_multiplayer required

Post by acabin »

As my test, loading a multiplayer game at singleplayer would not give the player admin permission, for he can't run /permissions.

edit:
The player had been added to a permission group already.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: game.is_multiplayer required

Post by Rseding91 »

acabin wrote:As my test, loading a multiplayer game at singleplayer would not give the player admin permission, for he can't run /permissions.

edit:
The player had been added to a permission group already.
That's not what you said - you said loading single player games in multiplayer.
If you want to get ahold of me I'm almost always on Discord.

acabin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Apr 19, 2016 8:13 am
Contact:

Re: game.is_multiplayer required

Post by acabin »

Rseding91 wrote: That's not what you said - you said loading single player games in multiplayer.
It looks like my pool English leads to some misunderstood. I'll describe what I am doing:

1. Start a new game in MP
2. With the host's settings, my mod will move some players to a 'guest' group, which nearly can't do anything
3. If a 'guest' want to play the map offline, he will start a singleplayer game and load the save
4. In that case, I want to give the 'guest' all permissions and the player.admin flag

Now the problem:
I can't detect if the player is playing singleplayer or he is the only online player in a headless server.

So, I want a game.is_multiplayer or script.is_multiplayer flag or a way to check.

acabin
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Apr 19, 2016 8:13 am
Contact:

Re: game.is_multiplayer required

Post by acabin »

Is there any update? :D

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: game.is_multiplayer required

Post by Rseding91 »

acabin wrote:
Rseding91 wrote: That's not what you said - you said loading single player games in multiplayer.
It looks like my pool English leads to some misunderstood. I'll describe what I am doing:

1. Start a new game in MP
2. With the host's settings, my mod will move some players to a 'guest' group, which nearly can't do anything
3. If a 'guest' want to play the map offline, he will start a singleplayer game and load the save
4. In that case, I want to give the 'guest' all permissions and the player.admin flag

Now the problem:
I can't detect if the player is playing singleplayer or he is the only online player in a headless server.

So, I want a game.is_multiplayer or script.is_multiplayer flag or a way to check.
I see.

Unfortunately that's not going to be possible. That information isn't deterministic - the best you can do is detect if #game.players is > 1 but that's still not going to do it fully.
If you want to get ahold of me I'm almost always on Discord.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1029
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: game.is_multiplayer required

Post by quyxkh »

You could try something along the lines of (edit: the desync bilka warned about doesn't happen, but his instincts are good, fixed a lesser desync. but this stsill doesn't work: it appears on_player_joined _does_ fire in singleplayer loads of saved multiplayer maps. Oh, well.)
nope-doesnt-work
Last edited by quyxkh on Mon Feb 05, 2018 9:18 am, edited 1 time in total.

Bilka
Factorio Staff
Factorio Staff
Posts: 3140
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: game.is_multiplayer required

Post by Bilka »

quyxkh wrote:You could try something along the lines of

Code: Select all

joined_this_session =  {} -- control.lua gets rerun for each map init/load
script.on_event(defines.events.on_player_joined_game,function(ev) joined_this_session[ev.player_index]=true end)

-- setup so `/makemeaboss` in sp mode works right
function makemeaboss(cparms)
    if not joined_this_session[cparms.player_index]
    then -- your grant-boss-powers code here
    else game.print(game.players[cparms.player_index].name..' wants to be a boss.')
        end
    end
commands.add_command('makemeaboss',{'','use the source'},makemeaboss)
That's a fast and easy way to produce desyncs, congratulations. It should start desyncing on join after the second person joined, for the person that is joining. The person will be stuck in a desync loop and unable to ever join, unless the server is restarted and the person joins as the first person.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

quyxkh
Smart Inserter
Smart Inserter
Posts: 1029
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: game.is_multiplayer required

Post by quyxkh »

Testing shows it doesn't desync on load, it desyncs when a second player joins and the first player tries the command, because the second player wasn't there for the first player's join event. I fixed that by loading up the context when the client sees its first join event, I can't make it desync now.

But that doesn't help, because loading a save of an mp map in singleplayer mode fires on_player_joined_game anyway.

Anybody _really_ desperate to do this can just edit the mod locally.

Post Reply

Return to “Implemented mod requests”