static bool Set_nickName(xp_option_t *opt, const char *value) { UNUSED_PARAM(opt); assert(value); /* * This is a hack. User name will be used as nickname, * look in Set_userName(). */ if (strlen(value) == 0) return true; strlcpy(connectParam.nick_name, value, sizeof(connectParam.nick_name)); CAP_LETTER(connectParam.nick_name[0]); if (connectParam.nick_name[0] < 'A' || connectParam.nick_name[0] > 'Z') { warn("Your player name \"%s\" should start with an uppercase letter.", connectParam.nick_name); connectParam.nick_name[0] = 'X'; } if (Check_nick_name(connectParam.nick_name) == NAME_ERROR) { char nick[MAX_NAME_LEN]; strlcpy(nick, connectParam.nick_name, sizeof(nick)); Fix_nick_name(connectParam.nick_name); warn("Fixing nick from \"%s\" to \"%s\".\n", nick, connectParam.nick_name); } /*warn("Nick name set to \"%s\".\n", connectParam.nick_name);*/ return true; }
void Parse_options(int *argcp, char **argvp, char *realName, char *host, int *port, int *my_team, int *list, int *join, int *motd, char *nickName, char *dispName, char *shut_msg) { int i, j, firstKeyDef, num; keys_t key; KeySym ks; char *ptr, *str, *myName = "xpilot", *myClass = "XPilot", resValue[MAX_CHARS]; XrmDatabase argDB, rDB; XrmInitialize(); argDB = 0; XrmParseCommand(&argDB, opts, NELEM(opts), myName, argcp, argvp); /* * Check for bad arguments. */ for (i = 1; i < *argcp; i++) { if (argvp[i][0] == '-') { errno = 0; error("Unknown option '%s'", argvp[i]); error("Type: %s -help to see a list of options", argvp[0]); exit(1); } } if (Get_resource(argDB, myName, myClass, "help", NULL, resValue, sizeof resValue) != 0) { Usage(); } if (Get_resource(argDB, myName, myClass, "version", NULL, resValue, sizeof resValue) != 0) { puts(TITLE); exit(0); } Get_resource(argDB, myName, myClass, "shutdown", "", shut_msg, MAX_CHARS); if (Get_string_resource(argDB, myName, myClass, "display", NULL, dispName, MAX_DISP_LEN) == 0 || dispName[0] == '\0') { #ifdef VMS if ((ptr = getenv("DECW$DISPLAY")) != NULL) { #else if ((ptr = getenv("DISPLAY")) != NULL) { #endif strncpy(dispName, ptr, MAX_DISP_LEN); dispName[MAX_DISP_LEN - 1] = '\0'; } else { #ifdef VMS strcpy(dispName, "::0.0"); sprintf(dispName, "%s::0.0", host); #else strcpy(dispName, ":0.0"); #endif } } if ((dpy = XOpenDisplay(dispName)) == NULL) { error("Can't open display '%s'", dispName); exit(1); } Get_resource(argDB, myName, myClass, "visual", "", visualName, sizeof visualName); if (strncasecmp(visualName, "list", 4) == 0) { List_visuals(); exit(0); } Get_file_defaults(&rDB, myName, myClass); XrmMergeDatabases(argDB, &rDB); Get_string_resource(rDB, myName, myClass, "geometry", "", resValue, sizeof resValue); geometry = strdup(resValue); Get_resource(rDB, myName, myClass, "name", realName, nickName, MAX_NAME_LEN); CAP_LETTER(nickName[0]); if (nickName[0] < 'A' || nickName[0] > 'Z') { errno = 0; error("Your player name \"%s\" should start with an uppercase letter", nickName); exit(1); } strncpy(realname, realName, sizeof(realname) - 1); strncpy(name, nickName, sizeof(name) - 1); Get_int_resource(rDB, myName, myClass, "team", TEAM_NOT_SET, my_team); if (*my_team < 0 || *my_team > 9) { *my_team = TEAM_NOT_SET; } team = *my_team; Get_int_resource(rDB, myName, myClass, "port", SERVER_PORT, port); Get_bool_resource(rDB, myName, myClass, "list", "False", list); Get_bool_resource(rDB, myName, myClass, "join", "False", join); Get_bool_resource(rDB, myName, myClass, "motd", "True", motd); Get_float_resource(rDB, myName, myClass, "power", 45.0, &power); Get_float_resource(rDB, myName, myClass, "turnSpeed", 35.0, &turnspeed); Get_float_resource(rDB, myName, myClass, "turnResistance", 0.12, &turnresistance); Get_float_resource(rDB, myName, myClass, "altPower", 35.0, &power_s); Get_float_resource(rDB, myName, myClass, "altTurnSpeed", 25.0, &turnspeed_s); Get_float_resource(rDB, myName, myClass, "altTurnResistance", 0.12, &turnresistance_s); Get_float_resource(rDB, myName, myClass, "sparkProb", 0.50, &spark_prob); spark_rand = (int)(spark_prob * MAX_SPARK_RAND + 0.5f); Get_int_resource(rDB, myName, myClass, "charsPerSecond", 50, &charsPerSecond); Get_bool_resource(rDB, myName, myClass, "markingLights", "True", &i); markingLights = (i == false) ? false : true; Get_int_resource(rDB, myName, myClass, "backgroundPointDist", 8, &map_point_distance); Get_int_resource(rDB, myName, myClass, "backgroundPointSize", DEF_MAP_POINT_SIZE, &map_point_size); LIMIT(map_point_size, MIN_MAP_POINT_SIZE, MAX_MAP_POINT_SIZE); Get_int_resource(rDB, myName, myClass, "sparkSize", DEF_SPARK_SIZE, &spark_size); LIMIT(spark_size, MIN_SPARK_SIZE, MAX_SPARK_SIZE); Get_resource(rDB, myName, myClass, "visual", "", visualName, sizeof visualName); Get_bool_resource(rDB, myName, myClass, "mono", "False", &i); mono = (i != 0) ? true : false; Get_bool_resource(rDB, myName, myClass, "colorSwitch", "True", &i); colorSwitch = (i != 0) ? true : false; Get_int_resource(rDB, myName, myClass, "maxColors", 4, &maxColors); Get_string_resource(rDB, myName, myClass, "black", "", color_names[BLACK], sizeof(color_names[BLACK])); Get_string_resource(rDB, myName, myClass, "white", "", color_names[WHITE], sizeof(color_names[WHITE])); Get_string_resource(rDB, myName, myClass, "blue", "", color_names[BLUE], sizeof(color_names[BLUE])); Get_string_resource(rDB, myName, myClass, "red", "", color_names[RED], sizeof(color_names[RED])); for (i = 0; i < MAX_COLORS; i++) { char buf[8], def[MAX_COLOR_LEN]; sprintf(buf, "color%d", i); strcpy(def, (i < NUM_COLORS) ? color_names[i] : ""); Get_string_resource(rDB, myName, myClass, buf, def, color_names[i], sizeof(color_names[i])); } instruments = 0; Get_bool_resource(rDB, myName, myClass, "showShipName", "True", &i); if (i) { SET_BIT(instruments, SHOW_SHIP_NAME); } Get_bool_resource(rDB, myName, myClass, "showHUD", "True", &i); if (i) { SET_BIT(instruments, SHOW_HUD_INSTRUMENTS); } Get_bool_resource(rDB, myName, myClass, "verticalHUDLine", "False", &i); if (i) { SET_BIT(instruments, SHOW_HUD_VERTICAL); } Get_bool_resource(rDB, myName, myClass, "horizontalHUDLine", "True", &i); if (i) { SET_BIT(instruments, SHOW_HUD_HORIZONTAL); } Get_bool_resource(rDB, myName, myClass, "fuelMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_FUEL_METER); } Get_bool_resource(rDB, myName, myClass, "fuelGauge", "True", &i); if (i) { SET_BIT(instruments, SHOW_FUEL_GAUGE); } Get_bool_resource(rDB, myName, myClass, "turnSpeedMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_TURNSPEED_METER); } Get_bool_resource(rDB, myName, myClass, "powerMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_POWER_METER); } Get_bool_resource(rDB, myName, myClass, "packetSizeMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_SIZE_METER); } Get_bool_resource(rDB, myName, myClass, "packetLossMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_LOSS_METER); } Get_bool_resource(rDB, myName, myClass, "packetDropMeter", "False", &i); if (i) { SET_BIT(instruments, SHOW_PACKET_DROP_METER); } Get_bool_resource(rDB, myName, myClass, "slidingRadar", "False", &i); if (i) { SET_BIT(instruments, SHOW_SLIDING_RADAR); } Get_bool_resource(rDB, myName, myClass, "outlineWorld", "False", &i); if (i) { SET_BIT(instruments, SHOW_OUTLINE_WORLD); } Get_bool_resource(rDB, myName, myClass, "clock", "False", &i); if (i) { SET_BIT(instruments, SHOW_CLOCK); } Get_float_resource(rDB, myName, myClass, "speedFactHUD", 0.0, &hud_move_fact); Get_float_resource(rDB, myName, myClass, "speedFactPTR", 0.0, &ptr_move_fact); Get_int_resource(rDB, myName, myClass, "fuelNotify", 500, &fuelLevel3); Get_int_resource(rDB, myName, myClass, "fuelWarning", 200, &fuelLevel2); Get_int_resource(rDB, myName, myClass, "fuelCritical", 100, &fuelLevel1); Get_resource(rDB, myName, myClass, "gameFont", GAME_FONT, gameFontName, sizeof gameFontName); Get_resource(rDB, myName, myClass, "messageFont", MESSAGE_FONT, messageFontName, sizeof messageFontName); Get_resource(rDB, myName, myClass, "scoreListFont", SCORE_LIST_FONT, scoreListFontName, sizeof scoreListFontName); Get_resource(rDB, myName, myClass, "buttonFont", BUTTON_FONT, buttonFontName, sizeof buttonFontName); Get_resource(rDB, myName, myClass, "textFont", TEXT_FONT, textFontName, sizeof textFontName); Get_resource(rDB, myName, myClass, "talkFont", TALK_FONT, talkFontName, sizeof talkFontName); Get_int_resource(rDB, myName, myClass, "receiveWindowSize", DEF_RECEIVE_WINDOW_SIZE, &receive_window_size); LIMIT(receive_window_size, MIN_RECEIVE_WINDOW_SIZE, MAX_RECEIVE_WINDOW_SIZE); #ifdef SOUND Get_string_resource(rDB, myName, myClass, "sounds", SOUNDFILE, sounds, sizeof sounds); Get_int_resource(rDB, myName, myClass, "maxVolume", 100, &maxVolume); Get_resource(rDB, myName, myClass, "audioServer", NULL, audioServer, sizeof audioServer); #endif Get_bool_resource(rDB, myName, myClass, "toggleShield", "False", &toggle_shield); /* * Key bindings */ maxKeyDefs = 2 * NUM_KEYS; if ((keyDefs = (keydefs_t *) malloc(maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } num = 0; for (i = 0; i < NELEM(keyResources); i++) { key = keyResources[i].key; Get_resource(rDB, myName, myClass, keyResources[i].resource, keyResources[i].fallback, resValue, sizeof resValue); firstKeyDef = num; for (str = strtok(resValue, " \t\r\n"); str != NULL; str = strtok(NULL, " \t\r\n")) { if ((ks = XStringToKeysym(str)) == NoSymbol) { printf("\"%s\" is not a valid keysym.\n", str); continue; } for (j = firstKeyDef; j < num; j++) { if (keyDefs[j].keysym == ks && keyDefs[j].key == key) { break; } } if (j < num) { continue; } if (num >= maxKeyDefs) { maxKeyDefs += NUM_KEYS; if ((keyDefs = (keydefs_t *) realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } } keyDefs[num].keysym = ks; keyDefs[num].key = key; num++; } } if (num < maxKeyDefs) { maxKeyDefs = num; if ((keyDefs = (keydefs_t *) realloc(keyDefs, maxKeyDefs * sizeof(keydefs_t))) == NULL) { error("No memory for key bindings"); exit(1); } } XrmDestroyDatabase(rDB); #ifdef SOUND audioInit(dispName); #endif /* SOUND */ }