Page 1 of 1

coding help

Posted: Thu Feb 11, 2010 9:11 pm
by Hamburg11
Hello

Why must max clients be set during startup and restart and not while a game is in progress? I would like to change this value realtime but am having trouble doing this. :confused: Can someone please help??

Re: coding help

Posted: Fri Feb 12, 2010 6:08 am
by ^misantropia^
Game mod or engine mod? With the former it isn't possible because the engine allocates memory for exactly sv_maxclients client structures.

Re: coding help

Posted: Fri Feb 12, 2010 3:54 pm
by Hamburg11
I have been trying to do this in the engine mod, which from your post is my problem. Where should I be looking to do this in the game mod?

Re: coding help

Posted: Fri Feb 12, 2010 6:42 pm
by Silicone_Milk
I don't know where the code is exactly since I haven't opened the source in about a year now but...

I suppose you could always allocate enough memory for exactly 64 clients and have a bool flag saying whether that slot is usable or not.

You could then start a game with 4 max players and then change it to 10 and the next 6 slots in the array would be flagged as open while the other 54 remain flagged as closed.

Not the most memory efficient way of doing things but it should be easier on the cpu since you won't be doing unnecessary callocs and mallocs. The less you have to mess with memory the better imo.

misantropia probably has a more eloquent idea though.

Re: coding help

Posted: Fri Feb 12, 2010 8:21 pm
by ^misantropia^
Maybe more eloquent but probably not more elegant. I'd force sv_maxclients to 64 so there is room for the max # of clients and have a shadow cvar that determines how many clients may actually be active. Be sure to patch SVC_Info() in server/sv_main.c so server browsers report the actual client limit. Keep in mind you have to do something smart when the admin sets the client limit to something below the number of players currently playing.

Re: coding help

Posted: Fri Feb 12, 2010 8:21 pm
by ^misantropia^
But in all fairness, I wouldn't probably do anything. Why fix something that fundamentally works?

Re: coding help

Posted: Fri Feb 12, 2010 8:30 pm
by Silicone_Milk
Wonder why I completely forgot about cvars =\