Detecting a local vs ded server

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Detecting a local vs ded server

Post by Cobalt »

Im more curious about doing this in QC, but I checked my copy of Darkplaces src and found:

Code: Select all

	// no need if server is local and definitely not if this is a demo
	if (!cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD || cls.signon >= SIGNONS)
		return;

So I guess this is somehow checking if its a local listen server, and if not its assumed to be a ded server. As far as Quake C goes, I dont recall any way for the modder to detect the diference between the kinds of servers.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a local vs ded server

Post by Spike »

why should the modder care?
imho, doing things that require a distinction are a bug.

the only thing that is useful is whether a specific client is the local client or not. you can check for that by its ip.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

Ok, in the Game of CTF , not sure if you remember the original concept with the start map? Players vote on the episode to play by passing through the corresponding slipgates. Zoid seems to have coded in a seperate countdown timer exclusive from the normal "timelimit" cvar that normally decides when the level is over. I have decided to go back and use the timelimit cvar. Once the vote timer starts it now sets the timelimit cvar 60 seconds , and you can see it in your hud counting down. I decided to work with this way for now and not use the old countdown code.

The trick here is, once you set the cvar "timelimit" on the start map, you have to restore it to what its set to in the config file for the mod by doing a localcmd to run the file again. In my mod (which is DP based) it turns out I have to keep all the gameplayfix cvars in I think config.cfg, while settings like timelimit are in autoexec. I found that if I run the gameplayfix cvars again on the next map load in any of the files, they get messed up. There also seems to be an issue
because my ded server is on a Linux server , and my local server is Win environment. I have not isolated the reason why - I figure its engine stuff, so I thought this would be the cheapest way. I am able to do a commend such as : set dedicated 1 in the config file....for some reason DP seems to let you create your own different ones this way and read them back, but when you go to set it in QC with cvarset() it says that its not a valid cvar.


Spike wrote:why should the modder care?
imho, doing things that require a distinction are a bug.
the only thing that is useful is whether a specific client is the local client or not. you can check for that by its ip.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a local vs ded server

Post by Spike »

I don't really get fully what you're saying. are you saying that DP execs different configs if its a listen vs dedicated server?

learn how to use autocvars.
var float autocvar_mycvar = 4;

you can register cvars with a registercvar builtin or something (I think its in the 90-100 range, look it up).
cvar_set indeed expects the cvar to already exist. you can always do localcmd("set foo value\n") to set it if you really want (although yes, small delay).

hacking the timelimit cvar for things like that is hideous in the first place.
you can probably use the clientstat builtin to override it (but not globalstat because dp doesn't support that), so you should be able to cowardly avoid csqc that way. I've no idea which stat number dp shoves it into though.
then you can just use timelimit for match times, and some other cvar for vote times without hacking everything in a really clumsy-sounding way.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

Never heard of autocvar before, thanks. I looked it up here and saw you helping Seven with it a while ago. Will look into that some more...also the registercvar() for DP looks like it would resolve my problem. I am doing something like this :

Code: Select all


// DecodeLevelParms () >>> This is called whenever you spawn at the next level.
void () DecodeLevelParms =
{
// Set / check ded or listen type server
if (clienttype(self) == CLIENTTYPE_REAL) // We are a real client, not a bot
{


local entity ded;
ded = findfloat (world, colormap, 1);
if (ded == self)
if (self.netaddress == "local")
{
dedicated = 0;
 cvar_set ("dedicated", "0");
 }
 else
 {
 dedicated = 1;
 cvar_set ("dedicated", "1");
 }

 }


The problem here is I didnt register the "dedicated" cvar I created using : set dedicated 0 in the autoexec / config file....so at times I would see the message
its an unknown cvar when I would try to look it up. Then I cheated and made a global float : dedicated to correct it, but I guess this way I am doing it more or less can get the job done. I thought perhaps it would be a nice doo-dad for an engine side piece of code we could call in QC to find out faster and not need to do this....just a sugguestion.

Oh, on a side note....more on the DP side of things, I did find a bug years ago in DP that is still unresolved and it is only reproducable on a ded server. So I suppose in the case where someone had prvm_errordump active, and tried to use its dump to see if there were any major differences in the local dump vs the ded dump, having this as a cvar would be one thing they would automaticly see as a possible starting point in debugging.

During the dev of my mod, I am seeing some cases where it might be a good idea to track this because as I said, I seem to be encountering bugs that are exclusive to the way the Linux kernel handles things versus the Win, and since I use WIn localy, and Linux for the live Ded server, this may have its uses.
Last edited by Cobalt on Sat Aug 02, 2014 5:06 pm, edited 1 time in total.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a local vs ded server

Post by Spike »

why would you want to?
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

oops I was editing as you posted. Maybe not an engine side extension per say, but perhaps a new cvar "dedicated" or "listen" would be a better idea.

Spike wrote:why would you want to?
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Detecting a local vs ded server

Post by Spike »

so you need to know whether its running on linux, so you're instead testing to see if they used -dedicated on the commandline instead?
that's absurd.

if you really want to test to see if you're running on linux, use the cvar_type function and test for some linux-specific cvar. of course, due to the 'proper' dp builds all using sdl, you're screwed. you might be able to use strftime to see which C run time it was linked against, if the bug is caused by msvc or whatever.

but assuming that all and only dedicated servers are running on linux is stupid.

if both machines are under your control, surely you'll know which one you got the saved game from in the first place, so why do you need to set a cvar (which won't be shown in the saved game anyway)?


if you're seeing behavioural differences between linux and windows, then you should bitch at whoever is responsible. But probably you'll find out that its your own config issue.
If you're seeing differences between dedicated and listen servers, then its probably your own fault anyway. If you explain the difference that you're observing then maybe someone here will be able to point out exactly which part of the API you're failing to understand.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

Right. I guess mostly its because as humans we sometimes are doing stupid things in code - experimenting, and might get ahead of ourselves and forget there is a difference in some things in a local environment versus a ded. I dont know like the back of my hand 100% all the differences as far as the engine goes, because I am not yet an engine coder...so my idea comes from a QC perspective, not the engine. It might be useful in some troubleshooting situations.

I understand your perspective, because your knowledge of the engine is at a level where if you were looking at my code, maybe right away you would say its because config.cfg gets done first , then autoexec.cfg ....then worldspawn() or something simple, where when I see the problem, my way is to do some tests with qc to determine whats going on behind the scenes in the engine that I do not 100% understand.
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: Detecting a local vs ded server

Post by r00k »

woudn't

if (self.netaddress == "local")

be enough?

I have seen issues with manipulating strings on the hunk to differ from windows and linux, so I could see how this would be
useful.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

Hrm, not if we keep that in Decodelevelparms() function. Actually its a poor place to check for the server type. It only will run when the client connects for the first time, so if you have a ded server running with no players joined yet, "dedicated" will still be zero.

After some more experimenting, I wound up putting it in StartFrame ()

Code: Select all

	 
	 if (framecount == 10)
	 {
	  local entity ded;
ded = findfloat (ded, colormap, 1);
if (ded.netaddress == "local")
 cvar_set ("dedicated", "0");
 else
 cvar_set ("dedicated", "1");
	 }

I was messing with it in WorldSpawn() , but it seems the environment for the player slots is not yet set up yet there, so it did not work. Further tests revealed that after about (10) frames, the slots were put up, so I guess this is about the safest place to do it.

Yea, other Kernel or Hunk envoronments may vary.

NOTE: As opposed to findfloat(), on other engines where its not available, usually Nextent(world) winds up being the first player slot after everything else is set up, unless you are interupting the process I think by spawning a dynamic entity before all that. I believe they refer to map items as "Quaked" items or Quaked ents in some older stuff I once read about QC. I guess the Quaked stuff spawns after the player solts are put up....in some framecount number decided by the speed of the hardware being used I guess. So even though I am making my code here in a Win 64 bit environment, its still I guess possible the framecount number I picked could be too low if the system I upload it to live runs a tad slower, or like you say, if the Linux Kernel / Hunk stuff is doing something differently.

Anyhow, this is more or less pretty simple done in QC, so the need for an engine cvar oir extension may not be needed.


Oh , and I was looking for a good place to register the new cvar. Seems I had to go to StartFrame once again :

Code: Select all

if (!framecount)
registercvar ("dedicated", "0");


r00k wrote:woudn't

if (self.netaddress == "local")

be enough?

I have seen issues with manipulating strings on the hunk to differ from windows and linux, so I could see how this would be
useful.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: Detecting a local vs ded server

Post by frag.machine »

If I got your problem correctly, you want to mess with timelimit and later restore it to its original value, right ?
Wouldn't be enough to store the original value somewhere (maybe a global float) before changing the cvar and later just use this global ?
I must confess I fail to see why you took the confuse route of telling apart dedicated versus local versus Windows versus Linux...
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Detecting a local vs ded server

Post by Cobalt »

A global float gets dumped after a level change, to zero. I could have used an empty cvar such as "monsters" but I was already using that one for something else.

Im not 100% sure if the issue I am seeing is something stupid, such as a config file having the wrong stuff in it or if there is really an issue only when ded, not local or Linux, not Win. This was just a cheap way for me to track that possibility. I often write lots of otherwise meaningless QC checking things that I should know for sure by now, but if I see something unusual, I tend to take a few steps back, and try to find out for sure. Most the time it is somehting stupid I forgot.

frag.machine wrote:If I got your problem correctly, you want to mess with timelimit and later restore it to its original value, right ?
Wouldn't be enough to store the original value somewhere (maybe a global float) before changing the cvar and later just use this global ?
I must confess I fail to see why you took the confuse route of telling apart dedicated versus local versus Windows versus Linux...
Post Reply