coding help

Locked
Hamburg11
Posts: 2
Joined: Thu Feb 11, 2010 9:08 pm

coding help

Post 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??
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: coding help

Post 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.
Hamburg11
Posts: 2
Joined: Thu Feb 11, 2010 9:08 pm

Re: coding help

Post 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?
Silicone_Milk
Posts: 2237
Joined: Sat Mar 12, 2005 10:49 pm

Re: coding help

Post 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.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: coding help

Post 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.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: coding help

Post by ^misantropia^ »

But in all fairness, I wouldn't probably do anything. Why fix something that fundamentally works?
Silicone_Milk
Posts: 2237
Joined: Sat Mar 12, 2005 10:49 pm

Re: coding help

Post by Silicone_Milk »

Wonder why I completely forgot about cvars =\
Locked