Jernsygurnsy Posted January 5, 2016 Share Posted January 5, 2016 I am extremely new to coding in LUA, and I have been trying to set up a simple mod to prevent people from joining when the server hits a certain amount of players. For example if #AllPlayers >= 6 thenTheNet:SetAllowIncomingConnections(false)elseTheNet:SetAllowIncomingConnections(true)end This appears to work fine if one of the shards has 6 or more players on it, however if there are 5 players in the caves and 5 in the overworld, it does not seem to work. Is there some way I would be able to combine the two arrays and then run a check against the combined result? Or alternatively, a way to pull from the total players that are displayed on the server browser? For example, data\scripts\screens\serverlistingscreen.lua has the following function: function ServerListingScreen:IsValidWithFilters(server) which checks server.current_players and server.max_players, however I have not been able to find what is passing the value of server in to that function. Any help with this would be greatly appreciated. Link to comment Share on other sites More sharing options...
DarkXero Posted January 5, 2016 Share Posted January 5, 2016 Putmax_players = 6under [NETWORK] of the settings.ini of your dedicated server. It's in the folder your server uses to save stuff, maybe it's DoNotStarveTogetherDedicated. If you still insist on using your code, useTheNet:GetPlayerCount()instead of #AllPlayers Link to comment Share on other sites More sharing options...
Jernsygurnsy Posted January 5, 2016 Author Share Posted January 5, 2016 Putmax_players = 6under [NETWORK] of the settings.ini of your dedicated server. It's in the folder your server uses to save stuff, maybe it's DoNotStarveTogetherDedicated. If you still insist on using your code, useTheNet:GetPlayerCount()instead of #AllPlayers Great, that looks like exactly the function I need. I'll give that a try when I get home, thanks DarkXero. In regards to changing the settings.ini - I probably should have expanded on my reasoning for this. The above was just an example, I'm actually hosting a 12 player server and want it to be locked when it's at capacity - 1, that way I can deactivate it myself when I want to hop on without having to worry about the server being full. I guess a better alternative would be to add a password, however I'm not sure if that can be achieved without resetting the server? Now I need to try and work out how inst:ListenForEvent works so I can get it to automatically run. Link to comment Share on other sites More sharing options...
DarkXero Posted January 5, 2016 Share Posted January 5, 2016 that way I can deactivate it myself when I want to hop on without having to worry about the server being full. I guess a better alternative would be to add a password, however I'm not sure if that can be achieved without resetting the server? There's a way to change the password without resetting the server.TheNet:SetDefaultServerPassword("newpassword")However, what I suggest here is to make use of the whitelist feature.[00:00:00]: OnLoadPermissionList: APP:Klei/DoNotStarveTogether/save/blocklist.txt (Failure)[00:00:00]: OnLoadPermissionList: APP:Klei/DoNotStarveTogether/save/adminlist.txt (Failure)[00:00:00]: OnLoadUserIdList: APP:Klei/DoNotStarveTogether/save/whitelist.txt (Failure)There can be three txts in the save folder of your server. Each txt file has 1 ID per line. Blocklist has banned IDs.Adminlist has IDs with admin powers.Whitelist has IDs that are granted reserved slots. Create a whitelist.txt, go ingame and press backspace and look down right or type print(ThePlayer.userid) on console.Get your ID, should look like KU_123abcXYZ something.Put your ID in the whitelist.Now, 1 slot will be reserved for you, the server has practically 5 slots if you are not in. Remember to put 1 ID per line if you want to whitelist friends. Link to comment Share on other sites More sharing options...
Jernsygurnsy Posted January 5, 2016 Author Share Posted January 5, 2016 However, what I suggest here is to make use of the whitelist feature. Ah, ok, that practically achieves exactly what I'm after. Thank you once again! I might still keep fiddling around with the mod since it's helping me become more familiar with Lua and modding for DST, but I will simply use what I learn from it in future projects. Link to comment Share on other sites More sharing options...
Jernsygurnsy Posted January 7, 2016 Author Share Posted January 7, 2016 So I have gotten around to creating the script, however when TheNet:SetDefaultServerPassword() is set by the script, it doesn't seem to show that the server has a password in the master list, and does not prompt the player to enter a password when connecting; it simply knocks them back with an incorrect password error. Additionally whenever I try to connect to the server using whatever password I have set via TheNet:SetDefaultServerPassword(), I get knocked back with an incorrect password error. This is true for both setting the password via the command line and setting it via the script. Below is my script, maybe you will be able to see something that I'm missing?AddComponentPostInit("playerspawner", function(OnPlayerSpawn, inst) inst:ListenForEvent("ms_playerjoined", function (inst, player) GLOBAL.TheNet:GetPlayerCount() >= 6 then print("hello from 1") GLOBAL.TheNet:SetDefaultServerPassword("password") end end) inst:ListenForEvent("ms_playerleft", function (inst, player) if GLOBAL.TheNet:GetPlayerCount() <= 5 then print("hello from 2") GLOBAL.TheNet:SetDefaultServerPassword("") end end)end) Link to comment Share on other sites More sharing options...
DarkXero Posted January 8, 2016 Share Posted January 8, 2016 Below is my script, maybe you will be able to see something that I'm missing? There's an IF missing.AddComponentPostInit("playerspawner", function(self, inst) inst:ListenForEvent("ms_playerjoined", function(inst, player) if GLOBAL.TheNet:GetPlayerCount() >= 6 then -- MISSING IF print("hello from 1") GLOBAL.TheNet:SetDefaultServerPassword("password") end end) inst:ListenForEvent("ms_playerleft", function(inst, player) if GLOBAL.TheNet:GetPlayerCount() <= 5 then print("hello from 2") GLOBAL.TheNet:SetDefaultServerPassword("") end end)end)However it doesn't matter because I tried the correct script out and also via commands, and changing the DefaultServerPassword doesn't update the server password until you restart it. I figured that if it worked with max players, it would work with this, but there must be something else happening in the backstage. Stick to the whitelist or SetAllowIncomingConnections. Link to comment Share on other sites More sharing options...
Jernsygurnsy Posted January 8, 2016 Author Share Posted January 8, 2016 There's an IF missing.AddComponentPostInit("playerspawner", function(self, inst) inst:ListenForEvent("ms_playerjoined", function(inst, player) if GLOBAL.TheNet:GetPlayerCount() >= 6 then -- MISSING IF print("hello from 1") GLOBAL.TheNet:SetDefaultServerPassword("password") end end) inst:ListenForEvent("ms_playerleft", function(inst, player) if GLOBAL.TheNet:GetPlayerCount() <= 5 then print("hello from 2") GLOBAL.TheNet:SetDefaultServerPassword("") end end)end)However it doesn't matter because I tried the correct script out and also via commands, and changing the DefaultServerPassword doesn't update the server password until you restart it. I figured that if it worked with max players, it would work with this, but there must be something else happening in the backstage. Stick to the whitelist or SetAllowIncomingConnections. Oh jeez, good pick up, thank you. Must have accidentally removed that when I copied it across and was fixing up the spacing Damn that's a shame. Maybe if I set a password in the settings.ini, removing the password after the server has started and then setting a password might default to whatever is set in the settings.ini (assuming SetDefaultServerPassword() is basically just flagging something as true or false), worth trying at least. If that doesn't work I guess whitelist and SetAllowIncomingConnections will be the way to go. What I'm currently trying to achieve is having a password for slots 6, 8 and 9 and having slot 9 whitelisted solely for me. Using SetAllowIncomingConnections will achieve this as well, but involves manually deactivating it when I want to log in. In regards to the whitelist - I'm running the dedicated server via the steam tool, and having multiple entries isn't working. Looking at blocklist.txt though I noticed entries were separated by what notepad is returning as a superscript o. I have separated my entries in the whitelist with this character (copy pasted) as opposed to using new lines and it appears to be working now, though I didn't get a chance to test it thoroughly. Thanks for testing and confirming the password issue, is it worth reporting this as a bug? Link to comment Share on other sites More sharing options...
DarkXero Posted January 8, 2016 Share Posted January 8, 2016 Thanks for testing and confirming the password issue, is it worth reporting this as a bug? I don't think it's a bug, no. The adminlist works for me without the o . Weird. Glad you could work stuff out. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now