void load_entrable_list() { FILE *f = NULL; char strLine[255]; int off; memset(entrable_objects, 0, sizeof(entrable_objects)); nr_entrable_objects = 0; f=open_file_data("entrable.lst", "rb"); if(f == NULL) { LOG_ERROR("%s: %s \"entrable.lst\": %s\n", reg_error_str, cant_open_file, strerror(errno)); return; } while (nr_entrable_objects < MAX_ENTRABLE_OBJECTS) { if (fscanf(f, "%254s", strLine) != 1) break; my_tolower(strLine); off = *strLine == '/' ? 1 : 0; my_strncp(entrable_objects[nr_entrable_objects], strLine+off, OBJ_NAME_SIZE); nr_entrable_objects++; if (!fgets(strLine, sizeof(strLine), f)) break; } fclose(f); // Sort the list so we can use binary search qsort(entrable_objects, nr_entrable_objects, OBJ_NAME_SIZE, (int(*)(const void*,const void*))strcmp); }
void read_mapinfo () { FILE *fin; char line[256]; int maps_size, imap; char *cmt_pos; char cont_name[64]; unsigned short continent, x_start, y_start, x_end, y_end; char map_name[128]; maps_size = DEFAULT_CONTMAPS_SIZE; continent_maps = calloc (maps_size, sizeof (struct draw_map)); imap = 0; fin = open_file_data ("mapinfo.lst", "r"); if (fin == NULL){ LOG_ERROR("%s: %s \"mapinfo.lst\"\n", reg_error_str, cant_open_file); } else { while (fgets (line, sizeof (line), fin) != NULL) { // strip comments cmt_pos = strchr (line, '#'); if (cmt_pos != NULL) *cmt_pos = '\0'; if (sscanf (line, "%63s %hu %hu %hu %hu %127s ", cont_name, &x_start, &y_start, &x_end, &y_end, map_name) != 6) // not a valid line continue; if (strcasecmp (cont_name, "Seridia") == 0) continent = 0; else if (strcasecmp (cont_name, "Irilion") == 0) continent = 1; else // not a valid continent continue; if (imap >= maps_size - 1) { // Uh oh, we didn't allocate enough space maps_size += DEFAULT_CONTMAPS_SIZE; continent_maps = realloc (continent_maps, maps_size * sizeof (struct draw_map)); } continent_maps[imap].cont = continent; continent_maps[imap].x_start = x_start; continent_maps[imap].y_start = y_start; continent_maps[imap].x_end = x_end; continent_maps[imap].y_end = y_end; continent_maps[imap].name = malloc ((strlen (map_name) + 1) * sizeof (char)); strcpy(continent_maps[imap].name, map_name); imap++; } fclose (fin); } continent_maps[imap].cont = 0; continent_maps[imap].x_start = 0; continent_maps[imap].y_start = 0; continent_maps[imap].x_end = 0; continent_maps[imap].y_end = 0; continent_maps[imap].name = NULL; }
void init_commands(const char *filename) { FILE *fp = open_file_data(filename, "r"); if(fp == NULL) { LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, filename, strerror(errno)); } else { /* Read keywords from commands.lst */ char buffer[255]; size_t buffer_len; char *ptr; while(fgets(buffer, sizeof(buffer), fp)) { /* Get rid of comments */ if((ptr = strchr(buffer, '#')) != NULL) { *ptr = '\0'; } buffer_len = strlen(buffer); /* Skip empty lines */ if(strcmp(buffer, "\r\n") != 0 && strcmp(buffer, "\n") != 0 && strlen(buffer) > 0) { /* Get rid of the newline. */ if(buffer[buffer_len-2] == '\r' && buffer[buffer_len-1] == '\n') { buffer[buffer_len-2] = '\0'; } else if(buffer[buffer_len-1] == '\n') { buffer[buffer_len-1] = '\0'; } add_command(buffer, NULL); } } fclose(fp); } #ifdef MORE_ATTACHED_ACTORS_DEBUG add_command("horse", &horse_cmd); #endif #ifdef NECK_ITEMS_DEBUG add_command("set_neck", &set_neck); #endif add_command("emotes", &print_emotes); #ifdef EMOTES_DEBUG add_command("add_emote", &add_emote); add_command("send_cmd", &send_cmd); add_command("set_idle", &set_idle); add_command("set_action", &set_action); #endif add_command("marker_color", &command_mark_color); add_command("calc", &command_calc); add_command("cls", &command_cls); add_command(cmd_markpos, &command_markpos); add_command(cmd_mark, &command_mark); add_command(cmd_unmark, &command_unmark); add_command(cmd_stats, &command_stats); add_command("ping", &command_ping); #ifdef CUSTOM_UPDATE add_command("update", &command_update); add_command("update_status", &command_update_status); #endif /* CUSTOM_UPDATE */ add_command(cmd_time, &command_time); add_command(cmd_date, &command_date); add_command("quit", &command_quit); add_command("exit", &command_quit); add_command(cmd_exit, &command_quit); add_command("mem", &command_mem); add_command("cache", &command_mem); add_command("ver", &command_ver); add_command("vers", &command_ver); add_command(cmd_ignores, &list_ignores); add_command(cmd_ignore, &command_ignore); add_command(cmd_filters, &list_filters); add_command(cmd_filter, &command_filter); add_command(cmd_unignore, &command_unignore); add_command(cmd_unfilter, &command_unfilter); add_command(cmd_glinfo, &command_glinfo); add_command(cmd_knowledge_short, &knowledge_command); add_command(cmd_knowledge, &knowledge_command); add_command("log conn data", &command_log_conn_data); add_command(cmd_msg, &command_msg); add_command(cmd_afk, &command_afk); add_command("jc", &command_jlc);//since we only mess with the part after the add_command("lc", &command_jlc);//command, one function can do both add_command("channel_colors", &command_channel_colors); add_command(help_cmd_str, &command_help); add_command("sto", &command_storage); add_command("storage", &command_storage); add_command("accept_buddy", &command_accept_buddy); #ifdef NEW_SOUND add_command("current_song", &display_song_name); #endif // NEW_SOUND add_command("find", &history_grep); add_command("save", &save_local_data); add_command("url", &url_command); add_command("chat_to_counters", &chat_to_counters_command); add_command(cmd_session_counters, &session_counters); add_command("exp", &show_exp); #ifdef CONTEXT_MENUS_TEST add_command("cmtest", &cm_test_window); #endif add_command("alias", &alias_command); add_command("unalias", &unalias_command); add_command("aliases", &aliases_command); add_command("ckdata", &command_ckdata); #if defined(BUFF_DURATION_DEBUG) add_command("buffd", &command_buff_duration); #endif add_command(cmd_reload_icons, &reload_icon_window); add_command(cmd_open_url, &command_open_url); add_command(cmd_show_spell, &command_show_spell); add_command(cmd_cast_spell, &command_cast_spell); add_command(cmd_keypress, &command_keypress); add_command(cmd_user_menu_wait_time_ms, &command_set_user_menu_wait_time_ms); add_command("relogin", &command_relogin); command_buffer_offset = NULL; }
// initialize the auto update system, start the downloading void init_update() { FILE *fp; if(update_busy){ return; } // initialize variables update_busy++; update_attempt_count= 0; // no downloads have been attempted temp_counter= 0; //start with download name with 0 restart_required= 0; // no restart needed yet allow_restart= 1; // automated restart allowed // create the mutex & init the download que if(!download_mutex){ // file_update_clear_old(); // There is no reason to delete all the previous files. We only remove the ones out of date. download_mutex= SDL_CreateMutex(); download_queue_size= 0; memset(download_queue, 0, sizeof(download_queue)); download_cur_file= NULL; download_cur_md5= NULL; } // load the server list num_update_servers= 0; update_server[0]= '\0'; fp = open_file_data("mirrors.lst", "r"); if(fp == NULL){ LOG_ERROR("%s: %s \"mirrors.lst\": %s\n", reg_error_str, cant_open_file, strerror(errno)); } else { char buffer[1024]; char *ptr; ptr= fgets(buffer, sizeof(buffer), fp); while(ptr && !ferror(fp) && num_update_servers < sizeof(update_servers)){ int len= strlen(buffer); // is this line worth handling? if(len > 6 && *buffer > ' ' && *buffer != '#'){ while(isspace(buffer[len-1])){ buffer[len-1]= '\0'; len--; } if(len > 6){ update_servers[num_update_servers++]= strdup(buffer); } } // read the next line ptr= fgets(buffer, sizeof(buffer), fp); } if(fp){ fclose(fp); } } if(!num_update_servers) { // oops, no mirror file, no downloading update_servers[0]= ""; return; } // start the process if(download_mutex){ strcpy(files_lst, "files.lst"); is_this_files_lst= 1; handle_update_download(NULL); } }