Esempio n. 1
0
/*
 * ==================
 * SV_Frame
 *
 * ==================
 */
void SV_Frame(int msec)
{
    time_before_game = time_after_game = 0;

    // if server is not active, do nothing
    if (!svs.initialized)
    {
        return;
    }

    svs.realtime += msec;

    // keep the random time dependent
    rand();

    // check timeouts
    SV_CheckTimeouts();

    // get packets from clients
    SV_ReadPackets();

    // move autonomous things around if enough time has passed
    if (!sv_timedemo->value && (svs.realtime < sv.time))
    {
        // never let the time get too far off
        if (sv.time - svs.realtime > 100)
        {
            if (sv_showclamp->value)
            {
                Com_Printf("sv lowclamp\n");
            }
            svs.realtime = sv.time - 100;
        }
        NET_Sleep(sv.time - svs.realtime);
        return;
    }

    // update ping based on the last known frame from all clients
    SV_CalcPings();

    // give the clients some timeslices
    SV_GiveMsec();

    // let everything in the world think and move
    SV_RunGameFrame();

    // send messages back to the clients that had packets read this frame
    SV_SendClientMessages();

    // save the entire world state if recording a serverdemo
    SV_RecordDemoMessage();

    // send a heartbeat to the master if needed
    Master_Heartbeat();

    // clear teleport flags, etc for next frame
    SV_PrepWorldFrame();
}
Esempio n. 2
0
/**
 * @sa Qcommon_Frame
 */
void SV_Frame (int now, void *data)
{
	Com_ReadFromPipe();

	/* change the gametype even if no server is running (e.g. the first time) */
	if (sv_dedicated->integer && sv_gametype->modified) {
		Com_SetGameType();
		sv_gametype->modified = false;
	}

	if (sv_dedicated->integer) {
		const char *s;
		do {
			s = Sys_ConsoleInput();
			if (s)
				Cbuf_AddText(va("%s\n", s));
		} while (s);
	}

	/* if server is not active, do nothing */
	if (!svs.initialized) {
#ifdef DEDICATED_ONLY
		Com_Printf("Starting next map from the mapcycle\n");
		SV_NextMapcycle();
#endif
		return;
	}

	svs.realtime = now;

	/* keep the random time dependent */
	rand();

	SV_CheckSpawnSoldiers();
	SV_CheckStartMatch();
	SV_CheckTimeouts();

	if (!sv_threads->integer)
		SV_RunGameFrame();
	else
		/* signal the game frame thread to wake up */
		SDL_CondSignal(svs.gameFrameCond);
	SV_LogHandleOutput();

	/* next map in the cycle */
	if (sv->endgame && sv_maxclients->integer > 1)
		SV_NextMapcycle();

	/* send a heartbeat to the master if needed */
	Master_Heartbeat();
	SV_PingPlayers();

	/* server is empty - so shutdown */
	if (svs.abandon && svs.killserver)
		SV_Shutdown("Server disconnected.", false);
}
Esempio n. 3
0
/**
 * @brief Thread for the game frame function
 * @sa SV_RunGameFrame
 * @sa SV_Frame
 */
int SV_RunGameFrameThread (void *data)
{
	do {
		const ScopedMutex scopedMutex(svs.serverMutex);
		SDL_CondWait(svs.gameFrameCond, svs.serverMutex);
		SV_RunGameFrame();
	} while (!sv->endgame);

	return 0;
}
Esempio n. 4
0
/**
 * @brief Thread for the game frame function
 * @sa SV_RunGameFrame
 * @sa SV_Frame
 */
int SV_RunGameFrameThread (void *data)
{
	do {
		TH_MutexLock(svs.serverMutex);
		TH_MutexCondWait(svs.serverMutex, svs.gameFrameCond);
		SV_RunGameFrame();
		TH_MutexUnlock(svs.serverMutex);
	} while (!sv->endgame);

	return 0;
}
Esempio n. 5
0
/*
* SV_Frame
*/
void SV_Frame( int realmsec, int gamemsec )
{
	const unsigned int wrappingPoint = 0x70000000;

	time_before_game = time_after_game = 0;

	// if server is not active, do nothing
	if( !svs.initialized )
	{
		SV_CheckDefaultMap();
		return;
	}

	svs.realtime += realmsec;
	svs.gametime += gamemsec;

	// advance to next map if the server is running for too long (numbers taken from q3 src)
	if( svs.realtime > wrappingPoint || svs.gametime > wrappingPoint || sv.framenum >= wrappingPoint )
	{
		Cbuf_AddText( "wait; vstr nextmap\n" );
		SV_ShutdownGame( "Restarting server due to time wrapping", qtrue );
		return;
	}

	// check timeouts
	SV_CheckTimeouts();

	// get packets from clients
	SV_ReadPackets();

	// let everything in the world think and move
	if( SV_RunGameFrame( gamemsec ) )
	{
		// send messages back to the clients that had packets read this frame
		SV_SendClientMessages();

		// write snap to server demo file
		SV_Demo_WriteSnap();

		// run matchmaker stuff
		SV_CheckMatchUUID();

		SV_MM_Frame();

		// send a heartbeat to the master if needed
		SV_MasterHeartbeat();

		// clear teleport flags, etc for next frame
		ge->ClearSnap();
	}

	SV_CheckAutoUpdate();
}
Esempio n. 6
0
/**
 * @sa Qcommon_Frame
 */
void SV_Frame (int now, void *data)
{
	/* change the gametype even if no server is running (e.g. the first time) */
	if (sv_dedicated->integer && sv_gametype->modified) {
		Com_SetGameType();
		sv_gametype->modified = qfalse;
	}

	if (sv_dedicated->integer) {
		const char *s;
		do {
			s = Sys_ConsoleInput();
			if (s)
				Cbuf_AddText(va("%s\n", s));
		} while (s);
	}

	/* if server is not active, do nothing */
	if (!svs.initialized)
		return;

	svs.realtime = now;

	/* keep the random time dependent */
	rand();

	SV_CheckGameStart();

	if (!sv_threads->integer)
		SV_RunGameFrame();
	else
		/* signal the game frame thread to wake up */
		SDL_CondSignal(svs.gameFrameCond);

	/* next map in the cycle */
	if (sv->endgame && sv_maxclients->integer > 1)
		SV_NextMapcycle();

	/* send a heartbeat to the master if needed */
	Master_Heartbeat();

	/* server is empty - so shutdown */
	if (svs.abandon && svs.killserver)
		SV_Shutdown("Server disconnected.", qfalse);
}
Esempio n. 7
0
/*
==================
Host_ServerFrame

==================
*/
void Host_ServerFrame( void )
{
	// if server is not active, do nothing
	if( !svs.initialized ) return;

	svgame.globals->frametime = host.frametime;

	// check timeouts
	SV_CheckTimeouts ();

	// check clients timewindow
	SV_CheckCmdTimes ();

	// read packets from clients
	SV_ReadPackets ();

	// update ping based on the last known frame from all clients
	SV_CalcPings ();

	// refresh serverinfo on the client side
	SV_UpdateServerInfo ();

	// refresh physic movevars on the client side
	SV_UpdateMovevars ( false );

	// let everything in the world think and move
	SV_RunGameFrame ();
		
	// send messages back to the clients that had packets read this frame
	SV_SendClientMessages ();

	// clear edict flags for next frame
	SV_PrepWorldFrame ();

	// send a heartbeat to the master if needed
	Master_Heartbeat ();
}
Esempio n. 8
0
/**
 * @sa Qcommon_Frame
 */
void SV_Frame (int now, void* data)
{
    Com_ReadFromPipe();

    /* change the gametype even if no server is running (e.g. the first time) */
    if (sv_dedicated->integer && sv_gametype->modified) {
        Com_SetGameType();
        sv_gametype->modified = false;
    }

    if (sv_dedicated->integer) {
        const char* s;
        do {
            s = Sys_ConsoleInput();
            if (s)
                Cbuf_AddText("%s\n", s);
        } while (s);
    }

    /* if server is not active, do nothing */
    if (!svs.initialized) {
#ifdef DEDICATED_ONLY
        Com_Printf("Starting next map from the mapcycle\n");
        SV_NextMapcycle();
#endif
        return;
    }

    svs.realtime = now;

    /* if time is about to hit the 32nd bit, kick all clients
     * and clear sv.time, rather
     * than checking for negative time wraparound everywhere.
     * 2giga-milliseconds = 23 days, so it won't be too often */
    if (svs.realtime > 0x70000000) {
        SV_Map(true, sv->name, sv->assembly);
        return;
    }

    /* keep the random time dependent */
    rand();

    SV_CheckSpawnSoldiers();
    SV_CheckStartMatch();
    SV_CheckTimeouts();

    if (!sv_threads->integer)
        SV_RunGameFrame();
    else
        /* signal the game frame thread to wake up */
        SDL_CondSignal(svs.gameFrameCond);
    SV_LogHandleOutput();

    /* next map in the cycle */
    if (sv->endgame && sv_maxclients->integer > 1)
        SV_NextMapcycle();

    /* send a heartbeat to the master if needed */
    Master_Heartbeat();
    SV_PingPlayers();

    /* server is empty - so shutdown */
    if (svs.abandon && svs.killserver)
        SV_Shutdown("Server disconnected.", false);
}