Ejemplo n.º 1
0
/*
 * @brief Shuts down the game module. This is called when the game is unloaded
 * (complements G_Init).
 */
void G_Shutdown(void) {

	gi.Print("  Game shutdown...\n");

#ifdef HAVE_MYSQL
	if(mysql != NULL)
	mysql_close(mysql); // and db
#endif

	gi.FreeTag(MEM_TAG_GAME_LEVEL);
	gi.FreeTag(MEM_TAG_GAME);
}
Ejemplo n.º 2
0
/*
 * Frees tags and closes frag_log.  This is called when the game is unloaded
 * (complements G_Init).
 */
void G_Shutdown(void) {

	gi.Print("  Game shutdown...\n");

	if (frag_log != NULL)
		gi.CloseFile(frag_log); // close frag_log

	if (chat_log != NULL)
		gi.CloseFile(chat_log); // and chat_log

#ifdef HAVE_MYSQL
	if(mysql != NULL)
		mysql_close(mysql); // and db
#endif

	gi.FreeTags(TAG_LEVEL);
	gi.FreeTags(TAG_GAME);
}
Ejemplo n.º 3
0
/*
 * G_ParseMapList
 *
 * Populates a g_map_list_t from a text file.  See default/maps.lst
 */
static void G_ParseMapList(const char *file_name) {
	void *buf;
	const char *buffer;
	unsigned int i, j, k, l;
	const char *c;
	boolean_t map;
	g_map_list_elt_t *elt;

	G_InitMapList();

	if (gi.LoadFile(file_name, &buf) == -1) {
		gi.Print("Couldn't open %s\n", file_name);
		return;
	}

	buffer = (char *) buf;

	i = 0;
	map = false;
	while (true) {

		c = ParseToken(&buffer);

		if (*c == '\0')
			break;

		if (*c == '{')
			map = true;

		if (!map) // skip any whitespace between maps
			continue;

		elt = &g_map_list.maps[i];

		if (!strcmp(c, "name")) {
			strncpy(elt->name, ParseToken(&buffer), sizeof(elt->name) - 1);
			continue;
		}

		if (!strcmp(c, "title")) {
			strncpy(elt->title, ParseToken(&buffer), sizeof(elt->title) - 1);
			continue;
		}

		if (!strcmp(c, "sky")) {
			strncpy(elt->sky, ParseToken(&buffer), sizeof(elt->sky) - 1);
			continue;
		}

		if (!strcmp(c, "weather")) {
			strncpy(elt->weather, ParseToken(&buffer), sizeof(elt->weather) - 1);
			continue;
		}

		if (!strcmp(c, "gravity")) {
			elt->gravity = atoi(ParseToken(&buffer));
			continue;
		}

		if (!strcmp(c, "gameplay")) {
			elt->gameplay = G_GameplayByName(ParseToken(&buffer));
			continue;
		}

		if (!strcmp(c, "teams")) {
			elt->teams = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "ctf")) {
			elt->ctf = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "match")) {
			elt->match = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "rounds")) {
			elt->rounds = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "frag_limit")) {
			elt->frag_limit = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "round_limit")) {
			elt->round_limit = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "capture_limit")) {
			elt->capture_limit = strtoul(ParseToken(&buffer), NULL, 0);
			continue;
		}

		if (!strcmp(c, "time_limit")) {
			elt->time_limit = atof(ParseToken(&buffer));
			continue;
		}

		if (!strcmp(c, "give")) {
			strncpy(elt->give, ParseToken(&buffer), sizeof(elt->give) - 1);
			continue;
		}

		if (!strcmp(c, "music")) {
			strncpy(elt->music, ParseToken(&buffer), sizeof(elt->music) - 1);
			continue;
		}

		if (!strcmp(c, "weight")) {
			elt->weight = atof(ParseToken(&buffer));
			continue;
		}

		if (*c == '}') { // close it out
			map = false;

			/*printf("Loaded map %s:\n"
			 "title: %s\n"
			 "sky: %s\n"
			 "weather: %s\n"
			 "gravity: %d\n"
			 "gameplay: %ud\n"
			 "teams: %ud\n"
			 "ctf: %ud\n"
			 "match: %ud\n"
			 "rounds: %ud\n"
			 "frag_limit: %ud\n"
			 "round_limit: %ud\n"
			 "capture_limit: %ud\n"
			 "time_limit: %f\n"
			 "give: %s\n"
			 "music: %s\n"
			 "weight: %f\n",
			 map->name, map->title, map->sky, map->weather, map->gravity,
			 map->gameplay, map->teams, map->ctf, map->match, map->rounds,
			 map->frag_limit, map->round_limit, map->capture_limit,
			 map->time_limit, map->give, map->music, map->weight);*/

			// accumulate total weight
			g_map_list.total_weight += elt->weight;

			if (++i == MAX_MAP_LIST_ELTS)
				break;
		}
	}

	g_map_list.count = i;
	g_map_list.index = 0;

	gi.TagFree(buf);

	// thou shalt not divide by zero
	if (!g_map_list.total_weight)
		g_map_list.total_weight = 1.0;

	// compute the weighted index list
	for (i = 0, l = 0; i < g_map_list.count; i++) {

		elt = &g_map_list.maps[i];
		k = (elt->weight / g_map_list.total_weight) * MAP_LIST_WEIGHT;

		for (j = 0; j < k; j++)
			g_map_list.weighted_index[l++] = i;
	}
}
Ejemplo n.º 4
0
/*
 * G_Init
 *
 * This will be called when the game module is first loaded.
 */
void G_Init(void) {

	gi.Print("  Game initialization...\n");

	memset(&g_game, 0, sizeof(g_game));

	gi.Cvar("game_name", GAME_NAME, CVAR_SERVER_INFO | CVAR_NO_SET, NULL);
	gi.Cvar("game_date", __DATE__, CVAR_SERVER_INFO | CVAR_NO_SET, NULL);

	g_auto_join = gi.Cvar("g_auto_join", "1", CVAR_SERVER_INFO, NULL);
	g_capture_limit = gi.Cvar("g_capture_limit", "8", CVAR_SERVER_INFO, NULL);
	g_chat_log = gi.Cvar("g_chat_log", "0", 0, NULL);
	g_cheats = gi.Cvar("g_cheats", "0", CVAR_SERVER_INFO, NULL);
	g_ctf = gi.Cvar("g_ctf", "0", CVAR_SERVER_INFO, NULL);
	g_frag_limit = gi.Cvar("g_frag_limit", "30", CVAR_SERVER_INFO, NULL);
	g_frag_log = gi.Cvar("g_frag_log", "0", 0, NULL);
	g_friendly_fire = gi.Cvar("g_friendly_fire", "1", CVAR_SERVER_INFO, NULL);
	g_gameplay = gi.Cvar("g_gameplay", "0", CVAR_SERVER_INFO, NULL);
	g_gravity = gi.Cvar("g_gravity", "800", CVAR_SERVER_INFO, NULL);
	g_match = gi.Cvar("g_match", "0", CVAR_SERVER_INFO, NULL);
	g_max_entities = gi.Cvar("g_max_entities", "1024", CVAR_LATCH, NULL);
	g_mysql = gi.Cvar("g_mysql", "0", 0, NULL);
	g_mysql_db = gi.Cvar("g_mysql_db", "quake2world", 0, NULL);
	g_mysql_host = gi.Cvar("g_mysql_host", "localhost", 0, NULL);
	g_mysql_password = gi.Cvar("g_mysql_password", "", 0, NULL);
	g_mysql_user = gi.Cvar("g_mysql_user", "quake2world", 0, NULL);
	g_player_projectile = gi.Cvar("g_player_projectile", "1", CVAR_SERVER_INFO,
			NULL);
	g_random_map = gi.Cvar("g_random_map", "0", 0, NULL);
	g_round_limit = gi.Cvar("g_round_limit", "30", CVAR_SERVER_INFO, NULL);
	g_rounds = gi.Cvar("g_rounds", "0", CVAR_SERVER_INFO, NULL);
	g_spawn_farthest = gi.Cvar("g_spawn_farthest", "0", CVAR_SERVER_INFO, NULL);
	g_teams = gi.Cvar("g_teams", "0", CVAR_SERVER_INFO, NULL);
	g_time_limit = gi.Cvar("g_time_limit", "20", CVAR_SERVER_INFO, NULL);
	g_voting = gi.Cvar("g_voting", "1", CVAR_SERVER_INFO, "Activates voting");

	password = gi.Cvar("password", "", CVAR_USER_INFO, NULL);

	sv_max_clients = gi.Cvar("sv_max_clients", "8",
			CVAR_SERVER_INFO | CVAR_LATCH, NULL);
	dedicated = gi.Cvar("dedicated", "0", CVAR_NO_SET, NULL);

	if (g_frag_log->value)
		gi.OpenFile("frag_log.log", &frag_log, FILE_APPEND);

	if (g_chat_log->value)
		gi.OpenFile("chat_log.log", &chat_log, FILE_APPEND);

#ifdef HAVE_MYSQL
	if(g_mysql->value) { //init database

		mysql = mysql_init(NULL);

		mysql_real_connect(mysql, g_mysql_host->string,
				g_mysql_user->string, g_mysql_password->string,
				g_mysql_db->string, 0, NULL, 0
		);

		if(mysql != NULL)
		gi.Print("    MySQL connection to %s/%s", g_mysql_host->string,
				g_mysql_user->string);
	}
#endif

	G_ParseMapList("maps.lst");

	G_InitItems();

	// initialize entities and clients for this game
	g_game.edicts = gi.TagMalloc(g_max_entities->integer * sizeof(g_edict_t),
			TAG_GAME);
	g_game.clients = gi.TagMalloc(sv_max_clients->integer * sizeof(g_client_t),
			TAG_GAME);

	ge.edicts = g_game.edicts;
	ge.max_edicts = g_max_entities->integer;
	ge.num_edicts = sv_max_clients->integer + 1;

	// set these to false to avoid spurious game restarts and alerts on init
	g_gameplay->modified = g_teams->modified = g_match->modified
			= g_rounds->modified = g_ctf->modified = g_cheats->modified
					= g_frag_limit->modified = g_round_limit->modified
							= g_capture_limit->modified
									= g_time_limit->modified = false;

	gi.Print("  Game initialized.\n");
}
Ejemplo n.º 5
0
/*
 * @brief This will be called when the game module is first loaded.
 */
void G_Init(void) {

	gi.Print("  Game initialization...\n");

	memset(&g_game, 0, sizeof(g_game));

	gi.Cvar("game_name", GAME_NAME, CVAR_SERVER_INFO | CVAR_NO_SET, NULL);
	gi.Cvar("game_date", __DATE__, CVAR_SERVER_INFO | CVAR_NO_SET, NULL);

	g_ammo_respawn_time = gi.Cvar("g_ammo_respawn_time", "20.0", CVAR_SERVER_INFO,
			"Ammo respawn interval in seconds");
	g_auto_join = gi.Cvar("g_auto_join", "1", CVAR_SERVER_INFO,
			"Automatically assigns players to teams");
	g_capture_limit = gi.Cvar("g_capture_limit", "8", CVAR_SERVER_INFO,
			"The capture limit per level");
	g_cheats = gi.Cvar("g_cheats", "0", CVAR_SERVER_INFO, NULL);
	g_ctf = gi.Cvar("g_ctf", "0", CVAR_SERVER_INFO, "Enables capture the flag gameplay");
	g_frag_limit = gi.Cvar("g_frag_limit", "30", CVAR_SERVER_INFO, "The frag limit per level");
	g_friendly_fire = gi.Cvar("g_friendly_fire", "1", CVAR_SERVER_INFO, "Enables friendly fire");
	g_gameplay = gi.Cvar("g_gameplay", "0", CVAR_SERVER_INFO,
			"Selects deathmatch, arena, or instagib combat");
	g_gravity = gi.Cvar("g_gravity", "800", CVAR_SERVER_INFO, NULL);
	g_match = gi.Cvar("g_match", "0", CVAR_SERVER_INFO,
			"Enables match play requiring players to ready");
	g_max_entities = gi.Cvar("g_max_entities", "1024", CVAR_LATCH, NULL);
	g_motd = gi.Cvar("g_motd", "", CVAR_SERVER_INFO,
			"Message of the day, shown to clients on initial connect");
	g_mysql = gi.Cvar("g_mysql", "0", 0, NULL);
	g_mysql_db = gi.Cvar("g_mysql_db", "quake2world", 0, NULL);
	g_mysql_host = gi.Cvar("g_mysql_host", "localhost", 0, NULL);
	g_mysql_password = gi.Cvar("g_mysql_password", "", 0, NULL);
	g_mysql_user = gi.Cvar("g_mysql_user", "quake2world", 0, NULL);
	g_password = gi.Cvar("g_password", "", CVAR_USER_INFO, "The server password");
	g_player_projectile = gi.Cvar("g_player_projectile", "1.0", CVAR_SERVER_INFO,
			"Scales player velocity to projectiles");
	g_random_map = gi.Cvar("g_random_map", "0", 0, "Enables map shuffling");
	g_respawn_protection = gi.Cvar("g_respawn_protection", "0.0", 0,
			"Respawn protection in seconds");
	g_round_limit = gi.Cvar("g_round_limit", "30", CVAR_SERVER_INFO,
			"The number of rounds to run per level");
	g_rounds = gi.Cvar("g_rounds", "0", CVAR_SERVER_INFO,
			"Enables rounds-based play, where last player standing wins");
	g_show_attacker_stats = gi.Cvar("g_show_attacker_stats", "1", CVAR_SERVER_INFO, NULL);
	g_spawn_farthest = gi.Cvar("g_spawn_farthest", "1", CVAR_SERVER_INFO, NULL);
	g_spectator_chat = gi.Cvar("g_spectator_chat", "1", CVAR_SERVER_INFO,
			"If enabled, spectators can only talk to other spectators");
	g_teams = gi.Cvar("g_teams", "0", CVAR_SERVER_INFO, "Enables teams-based play");
	g_time_limit = gi.Cvar("g_time_limit", "20.0", CVAR_SERVER_INFO,
			"The time limit per level in minutes");
	g_voting = gi.Cvar("g_voting", "1", CVAR_SERVER_INFO, "Activates voting");
	g_weapon_respawn_time = gi.Cvar("g_weapon_respawn_time", "5.0", CVAR_SERVER_INFO,
			"Weapon respawn interval in seconds");

	sv_max_clients = gi.Cvar("sv_max_clients", "8", CVAR_SERVER_INFO | CVAR_LATCH, NULL);
	sv_hostname = gi.Cvar("sv_hostname", "Quake2World", CVAR_SERVER_INFO, NULL);
	dedicated = gi.Cvar("dedicated", "0", CVAR_NO_SET, NULL);

#ifdef HAVE_MYSQL
	if(g_mysql->value) { //init database

		mysql = mysql_init(NULL);

		mysql_real_connect(mysql, g_mysql_host->string,
				g_mysql_user->string, g_mysql_password->string,
				g_mysql_db->string, 0, NULL, 0
		);

		if(mysql != NULL)
		gi.Print("    MySQL connection to %s/%s", g_mysql_host->string,
				g_mysql_user->string);
	}
#endif

	G_ParseMapList("maps.lst");

	// initialize entities and clients for this game
	g_game.edicts = gi.Malloc(g_max_entities->integer * sizeof(g_edict_t), MEM_TAG_GAME);
	g_game.clients = gi.Malloc(sv_max_clients->integer * sizeof(g_client_t), MEM_TAG_GAME);

	ge.edicts = g_game.edicts;
	ge.max_edicts = g_max_entities->integer;
	ge.num_edicts = sv_max_clients->integer + 1;

	G_Ai_Init(); // initialize the AI

	// set these to false to avoid spurious game restarts and alerts on init
	g_gameplay->modified = g_teams->modified = g_match->modified = g_rounds->modified
			= g_ctf->modified = g_cheats->modified = g_frag_limit->modified
					= g_round_limit->modified = g_capture_limit->modified = g_time_limit->modified
							= false;

	gi.Print("  Game initialized\n");
}