English Changing server port at runtime.

3 replies
Goto Page
To the start Previous 1 Next To the start
Up
MikuAuahDark
User
Offline Off
I think this should belong to Servers category, but it involves Lua script, so I'll just post it here.

I have an idea of a multiple server which shares same data as the other server instance. The whole CS2D dedicated server start/stop is controlled with Luvit (Node.js equivalent to Lua). The plan is to let the Luvit app spawn 4 dedicated server using 1 CS2D directory (as it uses exactly same scripts for the 4 dedicated servers) and tell the dedicated server later which port to use. The port range is 36901 for the first dedicated server, 36902 for the 2nd dedicated server, and so on.

As I can't modify cs2d cmd sv_hostport at server.cfg, I have script something like this in my server.lua
Code:
1
2
3
4
initializeServer(function(name, port)
     parse("sv_name \""..name.."\")
     parse("sv_hostport "..port)
end)

initializeServer
purpose is to connect back to the Luvit app which is listening to specific port where the Luvit app will send the server name and the port to the connected dedicated server. This part works, I receive the server name and the port, but line 3 at code above seem has no effect. I still see the server in my LAN tab (which means the server still listen on 36963, which is NOT what I want). PS: the function
initializeServer
waits indefinely, effectively stopping the whole CS2D dedicated execution until it receive the name and the port necessary.

The question is how can I change the server port when server.lua is loaded? I can't change the port in server.cfg!

Thanks,
AuahDark
file cs2d LuaJIT for Dedicated Server (11) JIT POWER! | Know your Lua errors! | Draw stuff at Pixelize Art --xx-- server!
22.01.20 01:53:17 pm
Up
Hajt
User
Offline Off
Port change require server restart.. Btw there is -sys command line param so you can specific what directory you want to use, also you could have 1 dir for lua just dofile with scripts path in each server.lua
Yooo. We are playing mix matches 5on5 in evening hours on the server CS2D.TK | Mix/Match, you can join us, server password is match. Statistics, leaderboard can be found under the following link.
22.01.20 09:14:28 pm
Up
DC
Admin
Offline Off
Yep, what user Hajt said. The port must be set BEFORE the server starts using it. Any Lua you may run inside the CS2D is executed too late and can't change the port.
I'm not sure but a simple map change AFTER changing the port might work. Because a map change is basically a server restart.

Using different sys folders like user Hajt explained is highly recommended when running multiple servers on the same machine.

You can also set the port directly via commandline:
-port PORT

(note that when using this you won't be able to change the port anymore at all)

edit: yep, mapchange helps. pimped the cs2d cmd sv_hostport and cs2d cmd sv_map docs accordingly.
edited 1×, last 22.01.20 10:19:59 pm
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
23.01.20 04:53:59 am
Up
MikuAuahDark
User
Offline Off
I see. Looks like
-port <port>
does what I want, thank you very much.
file cs2d LuaJIT for Dedicated Server (11) JIT POWER! | Know your Lua errors! | Draw stuff at Pixelize Art --xx-- server!
To the start Previous 1 Next To the start