/* * @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"); }
/* * @brief A client issued an rcon command. Shift down the remaining args and * redirect all output to the invoking client. */ static void Sv_Rcon_f(void) { const _Bool auth = Sv_RconAuthenticate(); const char *addr = Net_NetaddrToString(&net_from); // first print to the server console if (auth) Com_Print("Rcon from %s:\n%s\n", addr, net_message.data + 4); else Com_Print("Bad rcon from %s:\n%s\n", addr, net_message.data + 4); // then redirect the remaining output back to the client console_t rcon = { .Append = Sv_Rcon_Print }; sv_rcon_buffer[0] = '\0'; Con_AddConsole(&rcon); if (auth) { char cmd[MAX_STRING_CHARS]; cmd[0] = '\0'; for (int32_t i = 2; i < Cmd_Argc(); i++) { g_strlcat(cmd, Cmd_Argv(i), sizeof(cmd)); g_strlcat(cmd, " ", sizeof(cmd)); } Cmd_ExecuteString(cmd); } else { Com_Print("Bad rcon_password\n"); } Netchan_OutOfBandPrint(NS_UDP_SERVER, &net_from, "print\n%s", sv_rcon_buffer); Con_RemoveConsole(&rcon); }
/** * @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"); }