示例#1
0
/*
 * @brief A download message has been received from the server.
 */
static void Cl_ParseDownload(void) {
	int32_t size, percent;

	// read the data
	size = Net_ReadShort(&net_message);
	percent = Net_ReadByte(&net_message);
	if (size < 0) {
		Com_Debug("Server does not have this file\n");
		if (cls.download.file) {
			// if here, we tried to resume a file but the server said no
			Fs_Close(cls.download.file);
			cls.download.file = NULL;
		}
		Cl_RequestNextDownload();
		return;
	}

	// open the file if not opened yet
	if (!cls.download.file) {

		if (!(cls.download.file = Fs_OpenWrite(cls.download.tempname))) {
			net_message.read += size;
			Com_Warn("Failed to open %s\n", cls.download.tempname);
			Cl_RequestNextDownload();
			return;
		}
	}

	Fs_Write(cls.download.file, net_message.data + net_message.read, 1, size);

	net_message.read += size;

	if (percent != 100) {
		Net_WriteByte(&cls.net_chan.message, CL_CMD_STRING);
		Net_WriteString(&cls.net_chan.message, "nextdl");
	} else {
		Fs_Close(cls.download.file);
		cls.download.file = NULL;

		// add new archives to the search path
		if (Fs_Rename(cls.download.tempname, cls.download.name)) {
			if (strstr(cls.download.name, ".zip")) {
				Fs_AddToSearchPath(cls.download.name);
			}
		} else {
			Com_Error(ERR_DROP, "Failed to rename %s\n", cls.download.name);
		}

		// get another file if needed
		Cl_RequestNextDownload();
	}
}
示例#2
0
END_TEST

START_TEST(check_Ms_BlacklistServer) {
	file_t *f = Fs_OpenAppend("servers-blacklist");
	ck_assert_msg(f != NULL, "Failed to open servers-blacklist");

	const char *test = "192.168.0.*\n";
	int64_t len = Fs_Write(f, (void *) test, 1, strlen(test));

	ck_assert_msg((size_t) len == strlen(test), "Failed to write servers-blacklist");
	ck_assert_msg(Fs_Close(f), "Failed to close servers-blacklist");

	struct sockaddr_in addr;
	memset(&addr, 0, sizeof(addr));

	*(in_addr_t *) &addr.sin_addr = inet_addr("192.168.0.1");
	addr.sin_family = AF_INET;
	addr.sin_port = htons(PORT_SERVER);

	ck_assert_msg(Ms_BlacklistServer(&addr), "Missed %s", inet_ntoa(addr.sin_addr));

	*(in_addr_t *) &addr.sin_addr = inet_addr("127.0.0.1");

	ck_assert_msg(!Ms_BlacklistServer(&addr), "False positive for %s", inet_ntoa(addr.sin_addr));

}
示例#3
0
文件: qaas.c 项目: EEmmanuel7/quetoo
/*
 * @brief
 */
void WriteAASFile(void) {
	char path[MAX_QPATH];
	file_t *f;

	StripExtension(bsp_name, path);
	g_strlcat(path, ".aas", sizeof(path));

	if (!(f = Fs_OpenWrite(path))) {
		Com_Error(ERR_FATAL, "Couldn't open %s for writing\n", path);
	}

	Com_Print("Writing %d AAS nodes..\n", d_aas.num_nodes);

	SwapAASFile();

	d_bsp_header_t header;
	memset(&header, 0, sizeof(header));

	header.ident = LittleLong(AAS_IDENT);
	header.version = LittleLong(AAS_VERSION);

	Fs_Write(f, &header, 1, sizeof(header));

	d_bsp_lump_t *lump = &header.lumps[AAS_LUMP_NODES];
	WriteLump(f, lump, d_aas.nodes, sizeof(d_aas_node_t) * d_aas.num_nodes);

	// rewrite the header with the populated lumps

	Fs_Seek(f, 0);
	Fs_Write(f, &header, 1, sizeof(header));

	Fs_Close(f);
}
示例#4
0
/*
 * @brief Initializes the client console.
 */
void Cl_InitConsole(void) {

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

	cl_console.Append = Cl_Print;

	Con_AddConsole(&cl_console);

	file_t *file = Fs_OpenRead("history");
	if (file) {
		Con_ReadHistory(&cl_console, file);
		Fs_Close(file);
	} else {
		Com_Debug("Couldn't read history");
	}

	memset(&cl_chat_console, 0, sizeof(cl_chat_console));
	cl_chat_console.level = PRINT_CHAT | PRINT_TEAM_CHAT;
	
	cl_draw_chat = Cvar_Get("cl_draw_chat", "1", 0, "Draw recent chat messages");
	cl_draw_notify = Cvar_Get("cl_draw_notify", "1", 0, "Draw recent console activity");

	cl_notify_lines = Cvar_Get("cl_console_notify_lines", "3", CVAR_ARCHIVE, NULL);
	cl_notify_time = Cvar_Get("cl_notify_time", "3.0", CVAR_ARCHIVE, NULL);

	cl_chat_lines = Cvar_Get("cl_chat_lines", "3", CVAR_ARCHIVE, NULL);
	cl_chat_time = Cvar_Get("cl_chat_time", "10.0", CVAR_ARCHIVE, NULL);

	Cmd_Add("cl_toggle_console", Cl_ToggleConsole_f, CMD_SYSTEM | CMD_CLIENT, "Toggle the console");
	Cmd_Add("cl_message_mode", Cl_MessageMode_f, CMD_CLIENT, "Activate chat");
	Cmd_Add("cl_message_mode_2", Cl_MessageMode2_f, CMD_CLIENT, "Activate team chat");

	Com_Print("Client console initialized\n");
}
示例#5
0
/*
 * @brief Wipes the sv_server_t structure after freeing any references it holds.
 */
static void Sv_ClearState() {

	if (svs.initialized) { // if we were intialized, cleanup

		if (sv.demo_file) {
			Fs_Close(sv.demo_file);
		}
	}

	memset(&sv, 0, sizeof(sv));
	Com_QuitSubsystem(Q2W_SERVER);

	svs.real_time = 0;
	svs.next_heartbeat = 0;
}
示例#6
0
文件: cl_demo.c 项目: jdolan/quetoo
/**
 * @brief Stop recording a demo
 */
void Cl_Stop_f(void) {
	int32_t len = -1;

	if (!cls.demo_file) {
		Com_Print("Not recording a demo\n");
		return;
	}

	// finish up
	Fs_Write(cls.demo_file, &len, sizeof(len), 1);
	Fs_Close(cls.demo_file);

	cls.demo_file = NULL;
	Com_Print("Stopped demo\n");
}
示例#7
0
	}END_TEST

START_TEST(check_Fs_OpenWrite)
	{
		file_t *f = Fs_OpenWrite(__func__);

		ck_assert_msg(f != NULL, "Failed to open %s", __func__);

		const char *testing = "testing";
		int64_t len = Fs_Write(f, (void *) testing, 1, strlen(testing));

		ck_assert_msg((size_t) len == strlen(testing), "Failed to write %s", __func__);
		ck_assert_msg(Fs_Close(f), "Failed to close %s", __func__);

	}END_TEST
示例#8
0
/*
 * @brief Shuts down the client console.
 */
void Cl_ShutdownConsole(void) {

	Con_RemoveConsole(&cl_console);

	file_t *file = Fs_OpenWrite("history");
	if (file) {
		Con_WriteHistory(&cl_console, file);
		Fs_Close(file);
	} else {
		Com_Warn("Couldn't write history\n");
	}

	Cmd_Remove("cl_toggle_console");
	Cmd_Remove("cl_message_mode");
	Cmd_Remove("cl_message_mode_2");

	Com_Print("Client console shutdown\n");
}
示例#9
0
/*
 * @brief
 */
void WritePortalFile(tree_t *tree) {
    char filename[MAX_OSPATH];
    node_t *head_node;

    Com_Verbose("--- WritePortalFile ---\n");

    head_node = tree->head_node;
    num_visclusters = 0;
    num_visportals = 0;

    FreeTreePortals_r(head_node);

    MakeHeadnodePortals(tree);

    CreateVisPortals_r(head_node);

    // set the cluster field in every leaf and count the total number of portals
    NumberLeafs_r(head_node);

    // write the file
    StripExtension(map_name, filename);
    strcat(filename, ".prt");

    if (!(prtfile = Fs_OpenWrite(filename)))
        Com_Error(ERR_FATAL, "Error opening %s\n", filename);

    Fs_Print(prtfile, "%s\n", PORTALFILE);
    Fs_Print(prtfile, "%i\n", num_visclusters);
    Fs_Print(prtfile, "%i\n", num_visportals);

    Com_Verbose("%5i visclusters\n", num_visclusters);
    Com_Verbose("%5i visportals\n", num_visportals);

    WritePortalFile_r(head_node);

    Fs_Close(prtfile);

    // we need to store the clusters out now because ordering
    // issues made us do this after writebsp...
    clusterleaf = 1;
    SaveClusters_r(head_node);

    Com_Verbose("--- WritePortalFile complete ---\n");
}
示例#10
0
/**
 * @brief
 */
void Sv_ShutdownConsole(void) {

	if (!dedicated->value) {
		return;
	}

	endwin();

	Con_RemoveConsole(&sv_console);

	file_t *file = Fs_OpenWrite("history");
	if (file) {
		Con_WriteHistory(&sv_console, file);
		Fs_Close(file);
	} else {
		Com_Warn("Couldn't write history\n");
	}

#if defined(_WIN32)
	FreeConsole();
#endif
}
示例#11
0
/*
 * @brief
 */
void Cl_ParseServerMessage(void) {
	int32_t cmd, old_cmd;
	char *s;
	int32_t i;

	if (cl_show_net_messages->integer == 1)
		Com_Print("%u ", (uint32_t) net_message.size);
	else if (cl_show_net_messages->integer >= 2)
		Com_Print("------------------\n");

	cl.byte_counter += net_message.size;
	cmd = 0;

	// parse the message
	while (true) {
		if (net_message.read > net_message.size) {
			Com_Error(ERR_DROP, "Bad server message\n");
		}

		old_cmd = cmd;
		cmd = Net_ReadByte(&net_message);

		if (cmd == -1) {
			Cl_ShowNet("END OF MESSAGE");
			break;
		}

		if (cl_show_net_messages->integer >= 2 && sv_cmd_names[cmd])
			Cl_ShowNet(sv_cmd_names[cmd]);

		switch (cmd) {

			case SV_CMD_BASELINE:
				Cl_ParseBaseline();
				break;

			case SV_CMD_CBUF_TEXT:
				s = Net_ReadString(&net_message);
				Cbuf_AddText(s);
				break;

			case SV_CMD_CONFIG_STRING:
				Cl_ParseConfigString();
				break;

			case SV_CMD_DISCONNECT:
				Com_Error(ERR_DROP, "Server disconnected\n");
				break;

			case SV_CMD_DOWNLOAD:
				Cl_ParseDownload();
				break;

			case SV_CMD_FRAME:
				Cl_ParseFrame();
				break;

			case SV_CMD_PRINT:
				i = Net_ReadByte(&net_message);
				s = Net_ReadString(&net_message);
				if (i == PRINT_CHAT) {
					if (Cl_IgnoreChatMessage(s)) // filter /ignore'd chatters
						break;
					if (*cl_chat_sound->string) // trigger chat sound
						S_StartLocalSample(cl_chat_sound->string);
				} else if (i == PRINT_TEAMCHAT) {
					if (Cl_IgnoreChatMessage(s)) // filter /ignore'd chatters
						break;
					if (*cl_team_chat_sound->string) // trigger chat sound
						S_StartLocalSample(cl_team_chat_sound->string);
				}
				Com_Print("%s", s);
				break;

			case SV_CMD_RECONNECT:
				Com_Print("Server disconnected, reconnecting...\n");
				// stop download
				if (cls.download.file) {
					if (cls.download.http) // clean up http downloads
						Cl_HttpDownload_Complete();
					else
						// or just stop legacy ones
						Fs_Close(cls.download.file);
					cls.download.name[0] = '\0';
					cls.download.file = NULL;
				}
				cls.state = CL_CONNECTING;
				cls.connect_time = 0; // fire immediately
				break;

			case SV_CMD_SERVER_DATA:
				Cl_ParseServerData();
				break;

			case SV_CMD_SOUND:
				Cl_ParseSound();
				break;

			default:
				// delegate to the client game module before failing
				if (!cls.cgame->ParseMessage(cmd)) {
					Com_Error(ERR_DROP, "Illegible server message:\n"
							" %d: last command was %s\n", cmd, sv_cmd_names[old_cmd]);
				}
				break;
		}
	}

	Cl_AddNetGraph();

	Cl_WriteDemoMessage();
}
示例#12
0
/**
 * @brief
 */
void Sv_InitConsole(void) {

	if (!dedicated->value) {
		return;
	}

#if defined(_WIN32)
	if (AllocConsole()) {
		freopen("CONIN$", "r", stdin);
		freopen("CONOUT$", "w", stdout);
		freopen("CONERR$", "w", stderr);
	} else {
		Com_Warn("Failed to allocate console: %u\n", (uint32_t) GetLastError());
	}
#endif

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

	sv_console_state.window = initscr();
	sv_console_state.dirty = true;

	cbreak();
	noecho();
	keypad(sv_console_state.window, TRUE);
	nodelay(sv_console_state.window, TRUE);
	curs_set(1);

	if (has_colors() == TRUE) {
		start_color();
		use_default_colors();
		init_pair(CON_COLOR_RED, COLOR_RED, -1);
		init_pair(CON_COLOR_GREEN, COLOR_GREEN, -1);
		init_pair(CON_COLOR_YELLOW, COLOR_YELLOW, -1);
		init_pair(CON_COLOR_BLUE, COLOR_BLUE, -1);
		init_pair(CON_COLOR_CYAN, COLOR_CYAN, -1);
		init_pair(CON_COLOR_MAGENTA, COLOR_MAGENTA, -1);
		init_pair(CON_COLOR_WHITE, COLOR_WHITE, -1);
	}

#ifdef SIGWINCH
	signal(SIGWINCH, Sv_ResizeConsole);
#endif

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

	sv_console.Append = Sv_Print;

	Con_AddConsole(&sv_console);

	if (dedicated->value) {
		file_t *file = Fs_OpenRead("history");
		if (file) {
			Con_ReadHistory(&sv_console, file);
			Fs_Close(file);
		} else {
			Com_Debug(DEBUG_SERVER, "Couldn't read history");
		}
	}

	Com_Print("Server console initialized\n");
}