Esempio n. 1
0
/*
============
G_InitGame

============
*/
void G_InitGame( int levelTime, int randomSeed, int restart ) {
	int					i;

	G_Printf ("------- Game Initialization -------\n");
	G_Printf ("gamename: %s\n", GAMEVERSION);
	G_Printf ("gamedate: %s\n", __DATE__);

	LUA_init();

	srand( randomSeed );

	G_RegisterCvars();

	G_ProcessIPBans();

	G_InitMemory();

	// set some level globals
	memset( &level, 0, sizeof( level ) );
	level.time = levelTime;
	level.startTime = levelTime;

	level.snd_fry = G_SoundIndex("sound/player/fry.wav");	// FIXME standing in lava / slime

	if ( g_gametype.integer != GT_SINGLE_PLAYER && g_logfile.string[0] ) {
		if ( g_logfileSync.integer ) {
			trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND_SYNC );
		} else {
			trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND );
		}
		if ( !level.logFile ) {
			G_Printf( "WARNING: Couldn't open logfile: %s\n", g_logfile.string );
		} else {
			char	serverinfo[MAX_INFO_STRING];

			trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );

			G_LogPrintf("------------------------------------------------------------\n" );
			G_LogPrintf("InitGame: %s\n", serverinfo );
		}
	} else {
		G_Printf( "Not logging to disk.\n" );
	}

	G_InitWorldSession();

	// initialize all entities for this game
	memset( g_entities, 0, MAX_GENTITIES * sizeof(g_entities[0]) );
	level.gentities = g_entities;

	// initialize all clients for this game
	level.maxclients = g_maxclients.integer;
	memset( g_clients, 0, MAX_CLIENTS * sizeof(g_clients[0]) );
	level.clients = g_clients;

	// set client fields on player ents
	for ( i=0 ; i<level.maxclients ; i++ ) {
		g_entities[i].client = level.clients + i;
	}

	// always leave room for the max number of clients,
	// even if they aren't all used, so numbers inside that
	// range are NEVER anything but clients
	level.num_entities = MAX_CLIENTS;

	for ( i=0 ; i<MAX_CLIENTS ; i++ ) {
		g_entities[i].classname = "clientslot";
	}

	// let the server system know where the entites are
	trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ), 
		&level.clients[0].ps, sizeof( level.clients[0] ) );

	// reserve some spots for dead player bodies
	InitBodyQue();

	ClearRegisteredItems();

	// parse the key/value pairs and spawn gentities
	G_SpawnEntitiesFromString();

	// general initialization
	G_FindTeams();

	// make sure we have flags for CTF, etc
	if( g_gametype.integer >= GT_TEAM ) {
		G_CheckTeamItems();
	}

	SaveRegisteredItems();

	G_Printf ("-----------------------------------\n");

	if( g_gametype.integer == GT_SINGLE_PLAYER || trap_Cvar_VariableIntegerValue( "com_buildScript" ) ) {
		G_ModelIndex( SP_PODIUM_MODEL );
	}

	if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
		BotAISetup( restart );
		BotAILoadMap( restart );
		G_InitBots( restart );
	}

	G_RemapTeamShaders();

}
Esempio n. 2
0
long RPC2_Init(const char *VId,		/* magic version string */
	       RPC2_Options *Options,
	       RPC2_PortIdent *Port,	/* array of portal ids */
	       long RetryCount,	   /* max number of retries before breaking conn*/
	       struct timeval *KAInterval	/* for keeping long RPC requests alive  */
	       )
{
    char *c;
    long i;
    PROCESS ctpid;
    struct RPC2_addrinfo *rpc2_localaddrs;
    long rc1 = RPC2_NOCONNECTION, rc2, rc;
    short port = 0;
    int verbose;
    char *env;

    rpc2_logfile = stderr;
    rpc2_tracefile = stderr;

    rpc2_Enter();
    say(1, RPC2_DebugLevel, "RPC2_Init()\n");
    say(999, RPC2_DebugLevel, "Runtime system version: \"%s\"\n", RPC2_VERSION);

    if (strcmp(VId, RPC2_VERSION) != 0)
    {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Wrong RPC2 version\n");
	rpc2_Quit (RPC2_WRONGVERSION);
    }

    /* rpc2_InitConn returns 0 if we're already initialized */
    if (rpc2_InitConn() == 0) rpc2_Quit(RPC2_SUCCESS);

    if (Options && (Options->Flags & RPC2_OPTION_IPV6))
	rpc2_ipv6ready = 1;

    env = getenv("RPC2SEC_KEYSIZE");
    if (env)
	RPC2_Preferred_Keysize = atoi(env);
    if (RPC2_Preferred_Keysize > 64)
	RPC2_Preferred_Keysize /= 8;

    /* Do we accept only secure connections, default is yes. This can be
     * disabled by setting the RPC2SEC_ONLY to 0, false, no, (nada, forgetit) */
    env = getenv("RPC2SEC_ONLY");
    RPC2_secure_only = !env || (env && memchr("0fFnN", *env, 5) == NULL);

    verbose = (Options && (Options->Flags & RPC2_OPTION_VERBOSE_INIT));
    secure_init(verbose);

    rpc2_InitMgrp();
    rpc2_InitHost();

    rpc2_localaddrs = rpc2_resolve(&rpc2_bindhost, Port);

    if (!rpc2_localaddrs) {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Couldn't get addrinfo for localhost!\n");
	rpc2_Quit(RPC2_FAIL);
    }

#ifdef PF_INET6
    rc1 = rpc2_CreateIPSocket(PF_INET6, &rpc2_v6RequestSocket,
			      rpc2_localaddrs, &port);
#endif
    rc2 = rpc2_CreateIPSocket(PF_INET, &rpc2_v4RequestSocket,
			      rpc2_localaddrs, &port);

    RPC2_freeaddrinfo(rpc2_localaddrs);

    /* rc should probably be the most 'positive' result of the two */
    rc = (rc1 > rc2) ? rc1 : rc2;
    if (rc < RPC2_ELIMIT) {
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Couldn't create socket\n");
	rpc2_Quit(rc);
    }

    rpc2_LocalPort.Tag = RPC2_PORTBYINETNUMBER;
    rpc2_LocalPort.Value.InetPortNumber = port;

    if (Port)
	*Port = rpc2_LocalPort;

    /* Initialize retry parameters */
    if (rpc2_InitRetry(RetryCount, KAInterval) != 0) {
	say(-1, RPC2_DebugLevel,"RPC2_Init(): Failed to init retryintervals\n");
	rpc2_Quit(RPC2_FAIL);
    }

    IOMGR_Initialize();
    TM_Init(&rpc2_TimerQueue);

    /* Register rpc2 packet handler with rpc2_SocketListener before
     * initializing the sideeffects */
    SL_RegisterHandler(RPC2_PROTOVERSION, rpc2_HandlePacket);
    
    /* Call side effect initialization routines */
    for (i = 0; i < SE_DefCount; i++)
	if (SE_DefSpecs[i].SE_Init != NULL)
	    if ((*SE_DefSpecs[i].SE_Init)() < RPC2_ELIMIT) {
		say(-1, RPC2_DebugLevel, "RPC2_Init(): Failed to init SE\n");
		rpc2_Quit(RPC2_SEFAIL2);
	    }

    c = "SocketListener";
    LWP_CreateProcess(rpc2_SocketListener, 32768, LWP_NORMAL_PRIORITY, NULL,
		      c, &rpc2_SocketListenerPID);

    c = "ClockTick";
    LWP_CreateProcess(rpc2_ClockTick, 16384, LWP_NORMAL_PRIORITY, NULL, c, &ctpid);

    LUA_init();

    if (rc != RPC2_SUCCESS)
	say(-1, RPC2_DebugLevel, "RPC2_Init(): Exiting with error\n");

    rpc2_Quit(rc);
}