// process an entered line of text and maybe perform a command on it (return 1 if an action was performed, 0 if not) int multi_msg_check_command(char *str) { int idx; char *prefix = NULL, *predicate = NULL, param[MULTI_MSG_MAX_TEXT_LEN+1]; char temp_str[MULTI_MSG_MAX_TEXT_LEN+1]; // look for a colon if(strstr(str,":") == NULL){ return 0; } // we don't want to modify the original string, which strtok() does strcpy_s(temp_str, str); // try and find a command prefix prefix = strtok(temp_str, ":"); if (prefix == NULL) return 0; // get all the text after the message predicate = strtok(NULL, NOX("\n\0")); if (predicate == NULL) return 0; // store the text as the actual parameter strcpy_s(param, predicate); drop_leading_white_space(param); // go through all existing commands and see what we can do for(idx=0;idx<MULTI_MSG_CMD_COUNT;idx++){ if(!stricmp(prefix,Multi_msg_commands[idx])){ // perform the command multi_msg_perform_command(idx,param); // return true return 1; } } // apply the results as a general expression, if we're in message all mode if(Multi_msg_mode == MULTI_MSG_ALL){ strcpy_s(Multi_msg_text,param); // send the chat packet send_game_chat_packet(Net_player, Multi_msg_text, MULTI_MSG_EXPR,NULL, prefix); // echo the message locally multi_msg_display_mission_text(Multi_msg_text, MY_NET_PLAYER_NUM); // return true return 1; } // no commands performed return 0; }
// displays (renders) the training message to the screen void message_training_display() { char *str, buf[256]; int i, z, x, y, height, mode, count; Training_msg_visible = 0; message_training_que_check(); training_obj_display(); if (Training_failure){ return; } if (timestamp_elapsed(Training_msg_timestamp) || !strlen(Training_text)){ return; } message_translate_tokens(Training_buf, Training_text); training_process_msg(Training_text); Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_sizes, Training_lines, MAX_TRAINING_MSG_LINES); Assert(Training_num_lines > 0); for (i=0; i<Training_num_lines; i++) { Training_lines[i][Training_line_sizes[i]] = 0; drop_leading_white_space(Training_lines[i]); } if (Training_num_lines <= 0){ return; } height = gr_get_font_height(); gr_set_shader(&Training_msg_glass); gr_shade(Training_msg_window_coords[gr_screen.res][0], Training_msg_window_coords[gr_screen.res][1], TRAINING_MSG_WINDOW_WIDTH, Training_num_lines * height + height); gr_set_color_fast(&Color_bright_blue); mode = count = 0; Training_msg_visible = 1; for (i=0; i<Training_num_lines; i++) { // loop through all lines of message str = Training_lines[i]; z = 0; x = Training_msg_window_coords[gr_screen.res][0] + (TRAINING_MSG_WINDOW_WIDTH - TRAINING_LINE_WIDTH) / 2; y = Training_msg_window_coords[gr_screen.res][1] + i * height + height / 2 + 1; while (*str) { // loop through each character of each line if ((count < MAX_TRAINING_MSG_MODS) && (str == Training_msg_mods[count].pos)) { buf[z] = 0; gr_printf(x, y, buf); gr_get_string_size(&z, NULL, buf); x += z; z = 0; mode = Training_msg_mods[count++].mode; switch (mode) { case TMMOD_NORMAL: gr_set_color_fast(&Color_bright_blue); break; case TMMOD_BOLD: gr_set_color_fast(&Color_white); break; } } buf[z++] = *str++; } if (z) { buf[z] = 0; gr_printf(x, y, "%s", buf); } } Training_msg_method = 0; // if (Training_msg_method) { // char *msg = "Press a key to continue"; // gr_get_string_size(&i, NULL, msg); // gr_printf(TRAINING_MSG_WINDOW_X + TRAINING_MSG_WINDOW_WIDTH / 2 - i / 2, TRAINING_MSG_WINDOW_Y + (Training_num_lines + 2) * height, msg); // } if ((Training_voice >= 0) && (Training_num_lines > 0) && !(Training_msg_timestamp)) { if (Training_voice_type) z = audiostream_is_playing(Training_voice_handle); else z = snd_is_playing(Training_voice_handle); if (!z) Training_msg_timestamp = timestamp(2000); // 2 second delay } }
void multi_options_read_config() { CFILE *in; char str[512]; char *tok = NULL; // set default value for the global multi options Multi_options_g.reset(); ushort forced_port = (ushort)os_config_read_uint(NULL, "ForcePort", 0); Multi_options_g.port = (Cmdline_network_port >= 0) ? (ushort)Cmdline_network_port : forced_port == 0 ? (ushort)DEFAULT_GAME_PORT : forced_port; Multi_options_g.log = (Cmdline_multi_log) ? 1 : 0; // read in the config file in = cfopen(MULTI_CFG_FILE, "rt", CFILE_NORMAL, CF_TYPE_DATA); // if we failed to open the config file, user default settings if (in == NULL) { nprintf(("Network","Failed to open network config file, using default settings\n")); } else { while ( !cfeof(in) ) { // read in the game info memset(str, 0, 512); cfgets(str, 512, in); // parse the first line tok = strtok(str, " \t"); // check the token if (tok != NULL) { drop_leading_white_space(tok); drop_trailing_white_space(tok); } else { continue; } // all possible options // only standalone cares about the following options if (Is_standalone) { // setup PXO mode if ( SETTING("+pxo") ) { NEXT_TOKEN(); if (tok != NULL) { strncpy(Multi_fs_tracker_channel, tok, MAX_PATH-1); } } else // set the standalone server's permanent name if ( SETTING("+name") ) { NEXT_TOKEN(); if (tok != NULL) { strncpy(Multi_options_g.std_pname, tok, STD_NAME_LEN); } } else // standalone won't allow voice transmission if ( SETTING("+no_voice") ) { Multi_options_g.std_voice = 0; } else // set the max # of players on the standalone if ( SETTING("+max_players") ) { NEXT_TOKEN(); if (tok != NULL) { if ( !((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS)) ) { Multi_options_g.std_max_players = atoi(tok); } } } else // ban a player if ( SETTING("+ban") ) { NEXT_TOKEN(); if (tok != NULL) { std_add_ban(tok); } } else // set the standalone host password if ( SETTING("+passwd") ) { NEXT_TOKEN(); if (tok != NULL) { strncpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN); #ifdef _WIN32 // yuck extern HWND Multi_std_host_passwd; SetWindowText(Multi_std_host_passwd, Multi_options_g.std_passwd); #else // TODO: get password ? // argh, gonna have to figure out how to do this - mharris 07/07/2002 #endif } } else // set standalone to low updates if ( SETTING("+low_update") ) { Multi_options_g.std_datarate = OBJ_UPDATE_LOW; } else // set standalone to medium updates if ( SETTING("+med_update") ) { Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM; } else // set standalone to high updates if ( SETTING("+high_update") ) { Multi_options_g.std_datarate = OBJ_UPDATE_HIGH; } else // set standalone to high updates if ( SETTING("+lan_update") ) { Multi_options_g.std_datarate = OBJ_UPDATE_LAN; } else // use pxo flag if ( SETTING("+use_pxo") ) { Om_tracker_flag = 1; } else // standalone pxo login user if ( SETTING("+pxo_login") ) { NEXT_TOKEN(); if (tok != NULL) { strncpy(Multi_options_g.std_pxo_login, tok, MULTI_TRACKER_STRING_LEN); } } else // standalone pxo login password if ( SETTING("+pxo_password") ) { NEXT_TOKEN(); if (tok != NULL) { strncpy(Multi_options_g.std_pxo_password, tok, MULTI_TRACKER_STRING_LEN); } } else if ( SETTING("+webui_root") ) { NEXT_TOKEN(); if (tok != NULL) { Multi_options_g.webuiRootDirectory = SCP_string(tok); } } else if ( SETTING("+webapi_username") ) { NEXT_TOKEN(); if (tok != NULL) { Multi_options_g.webapiUsername = SCP_string(tok); } } else if ( SETTING("+webapi_password") ) { NEXT_TOKEN(); if (tok != NULL) { Multi_options_g.webapiPassword = SCP_string(tok); } } else if ( SETTING("+webapi_server_port") ) { NEXT_TOKEN(); if (tok != NULL) { long int result = strtol(tok, NULL, 10); if(result <= 0 || result > USHRT_MAX) { mprintf(("ERROR: Invalid or out of range webapi_server_port '%s' specified in multi.cfg, must be integer between 1024 and %i.\n", tok, USHRT_MAX)); } else if(result < 1024) { mprintf(("ERROR: webapi_server_port '%ld' in multi.cfg is too low, must be between 1024 and %d.\n", result, USHRT_MAX)); } else { mprintf(("Using webapi_server_port '%ld' from multi.cfg.\n", result)); Multi_options_g.webapiPort = (ushort) result; } } } } // ... common to all modes ... // ip addr of user tracker if ( SETTING("+user_server") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.user_tracker_ip, tok); } } else // ip addr of game tracker if ( SETTING("+game_server") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.game_tracker_ip, tok); } } else // port to use for the game/user tracker (FS2NetD) if ( SETTING("+server_port") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.tracker_port, tok); } } else // ip addr of pxo chat server if ( SETTING("+chat_server") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.pxo_ip, tok); } } else // url of pilot rankings page if ( SETTING("+rank_url") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.pxo_rank_url, tok); } } else // url of pxo account create page if ( SETTING("+create_url") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.pxo_create_url, tok); } } else // url of pxo account verify page if ( SETTING("+verify_url") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.pxo_verify_url, tok); } } else // url of pxo banners if ( SETTING("+banner_url") ) { NEXT_TOKEN(); if (tok != NULL) { strcpy_s(Multi_options_g.pxo_banner_url, tok); } } else // set the max datarate for high updates if ( SETTING("+datarate") ) { NEXT_TOKEN(); if (tok != NULL) { if ( atoi(tok) >= 4000 ) { Multi_options_g.datarate_cap = atoi(tok); } } } else // get the proxy server if ( SETTING("+http_proxy") ) { NEXT_TOKEN(); if (tok != NULL) { char *ip = strtok(tok, ":"); if (ip != NULL) { strcpy_s(Multi_options_proxy, ip); } ip = strtok(NULL, ""); if (ip != NULL) { Multi_options_proxy_port = (ushort)atoi(ip); } else { strcpy_s(Multi_options_proxy, ""); } } } } // close the config file cfclose(in); in = NULL; } #ifndef _WIN32 if (Is_standalone) { std_configLoaded(&Multi_options_g); } #endif }