Forum

> > CS2D > Scripts > Changing server port at runtime.
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Changing server port at runtime.

3 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Changing server port at runtime.

MikuAuahDark
User Off Offline

Zitieren
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
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

alt Re: Changing server port at runtime.

Hajt
User Off Offline

Zitieren
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

alt Re: Changing server port at runtime.

DC
Admin Off Offline

Zitieren
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.
1× editiert, zuletzt 22.01.20 22:19:59
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht