? console.c ? console.h Index: Makefile.am =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/Makefile.am,v retrieving revision 1.7 diff -u -r1.7 Makefile.am --- Makefile.am 1999/01/09 03:33:35 1.7 +++ Makefile.am 1999/01/21 09:46:59 @@ -4,6 +4,8 @@ INCLUDES = -I$(srcdir)/../common -I$(srcdir)/../ai civserver_SOURCES = \ + console.c \ + console.h \ cityhand.c \ cityhand.h \ citytools.c \ Index: cityhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v retrieving revision 1.32 diff -u -r1.32 cityhand.c --- cityhand.c 1999/01/09 03:33:37 1.32 +++ cityhand.c 1999/01/21 09:46:59 @@ -128,7 +128,7 @@ { struct city *pcity, *othercity; int i; -/* printf("Creating city %s\n", name); */ + flog(LOG_DEBUG, "Creating city %s\n", name); gamelog(GAMELOG_FOUNDC,"%s (%i, %i) founded by the %s", name, x,y, get_race_name_plural(pplayer->race)); pcity=(struct city *)malloc(sizeof(struct city)); @@ -476,7 +476,7 @@ struct city *pcity; pcity=find_city_by_id(preq->city_id); if (!pcity) { - printf("Pcity null in handle_city_change (%s, id = %d)!\n", pplayer->name, preq->city_id); + flog(LOG_DEBUG, "Pcity null in handle_city_change (%s, id = %d)!\n", pplayer->name, preq->city_id); return; } if(!player_owns_city(pplayer, pcity)) Index: cityturn.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v retrieving revision 1.46 diff -u -r1.46 cityturn.c --- cityturn.c 1999/01/17 11:29:12 1.46 +++ cityturn.c 1999/01/21 09:47:00 @@ -578,8 +578,6 @@ *foodneed -= 2 * (*workers - 1 - e); *prodneed -= (*workers - 1 - e); -/*printf("%s, %d workers, %d luxneed, %d e\n", pcity->name, *workers, luxneed, e);*/ - if (city_happy(pcity) && wants_to_be_bigger(pcity) && pcity->size > 4) *foodneed += 1; city_map_iterate(x, y) { @@ -866,8 +864,8 @@ if (!game.players[pcity->owner].ai.control) ai_eval_buildings(pcity); /* so that ai_advisor is smart even for humans */ ai_advisor_choose_building(pcity, &choice); /* much smarter version -- Syela */ -/*printf("Advisor_choose_build got %d/%d from ai_advisor_choose_building.\n", - choice.choice, choice.want);*/ + flog(LOG_DEBUG, "Advisor_choose_build got %d/%d from ai_advisor_choose_building.\n", + choice.choice, choice.want); id = choice.choice; want = choice.want; @@ -1025,9 +1023,7 @@ } if (!space_part) { city_refresh(pcity); - /* printf("Trying advisor_choose_build.\n"); */ advisor_choose_build(pcity); - /* printf("Advisor_choose_build didn't kill us.\n"); */ notify_player_ex(pplayer, pcity->x, pcity->y, E_IMP_AUTO, "Game: %s is now building %s", pcity->name, improvement_types[pcity->currently_building].name); @@ -1169,7 +1165,7 @@ } iswork--; if (iswork+city_specialists(pcity)!=size) { - printf("%s is bugged: size:%d workers:%d elvis: %d tax:%d sci:%d\n", pcity->name,size,iswork, pcity->ppl_elvis, pcity->ppl_taxman, pcity->ppl_scientist); + flog(LOG_DEBUG, "%s is bugged: size:%d workers:%d elvis: %d tax:%d sci:%d\n", pcity->name,size,iswork, pcity->ppl_elvis, pcity->ppl_taxman, pcity->ppl_scientist); auto_arrange_workers(pcity); } } Index: civserver.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v retrieving revision 1.59 diff -u -r1.59 civserver.c --- civserver.c 1999/01/17 11:29:13 1.59 +++ civserver.c 1999/01/21 09:47:00 @@ -59,6 +59,7 @@ #include #include #include +#include void show_ending(); void end_game(); @@ -97,10 +98,6 @@ int is_new_game=1; -/* The following is unused, AFAICT. --dwp */ -char usage[] = -"Usage: %s [-fhlpgv] [--file] [--help] [--log] [--port]\n\t[--gamelog] [--version]\n"; - int port=DEFAULT_SOCK_PORT; int nocity_send=0; @@ -185,7 +182,7 @@ } else if(!strcmp("-s", argv[i]) || !strcmp("--server", argv[i])) { if(++iturn_done=0; } @@ -702,7 +686,7 @@ update_pollution(); do_apollo_program(); make_history_report(); -/* printf("Turn ended.\n"); */ + flog(LOG_DEBUG, "Turn ended.\n"); return 1; } @@ -730,10 +714,11 @@ game_save(&file); - if(!section_file_save(&file, filename)) - printf("Failed saving game as %s\n", filename); - else - printf("Game saved as %s\n", filename); + if(!section_file_save(&file, filename)) { + console_write(200,"Failed saving game as %s", filename); + flog(LOG_NORMAL, "Failed saving game as %s\n", filename); + } else + console_write(100,"Game saved as %s", filename); section_file_free(&file); gamelog_save(); @@ -746,11 +731,11 @@ void start_game(void) { if(server_state!=PRE_GAME_STATE) { - puts("the game is already running."); + console_write(300,"the game is already running."); return; } - puts("starting game."); + console_write(100,"starting game."); server_state=SELECT_RACES_STATE; /* loaded ??? */ force_end_of_sniff=1; @@ -1367,8 +1352,10 @@ game.players[i].is_connected=0; announce_ai_player(&game.players[i]); set_ai_level_direct(&game.players[i], game.players[i].ai.skill_level); - } else - printf ("Error creating new ai player: %s\n", player_name); + } else { + console_write(200,"Error creating new ai player: %s\n", player_name); + flog(LOG_NORMAL, "Error creating new ai player: %s\n", player_name); + } } send_server_info_to_metaserver(1); Index: mapgen.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v retrieving revision 1.15 diff -u -r1.15 mapgen.c --- mapgen.c 1998/12/12 12:07:35 1.15 +++ mapgen.c 1999/01/21 09:47:00 @@ -630,7 +630,7 @@ to spread them out on the different islands. **************************************************************************/ -void choose_start_positions(void) +void create_start_positions(void) { int nr=0; int dist=40; Index: mapgen.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/mapgen.h,v retrieving revision 1.1 diff -u -r1.1 mapgen.h --- mapgen.h 1998/05/01 03:51:44 1.1 +++ mapgen.h 1999/01/21 09:47:00 @@ -16,7 +16,7 @@ void map_fractal_generate(void); int is_water_adjacent(int x, int y); void flood_it(int loaded); -void choose_start_positions(void); +void create_start_positions(void); Index: meta.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v retrieving revision 1.2 diff -u -r1.2 meta.c --- meta.c 1998/12/21 16:12:04 1.2 +++ meta.c 1999/01/21 09:47:00 @@ -12,6 +12,7 @@ #include #include #include +#include #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff @@ -61,8 +62,8 @@ { if((hp = gethostbyname(servername)) ==NULL) { perror("Metaserver: address error"); - printf("Not reporting to the metaserver in this game\n"); - printf("Use option --nometa to always enforce this\n"); + console_write(201,"Not reporting to the metaserver in this game"); + console_write(201,"Use option --nometa to always enforce this"); fflush(stdout); return; } @@ -78,9 +79,9 @@ if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("metaserver: can't open datagram socket"); - printf("Not reporting to the metaserver in this game\n"); - printf("Use option --nometa to always enforce this\n> "); - fflush(stdout); + console_write(201,"Not reporting to the metaserver in this game"); + console_write(201,"Use option --nometa to always enforce this"); + console_flush(); return; } /* @@ -93,9 +94,9 @@ cli_addr.sin_port = htons(0); if(bind(sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0) { perror("metaserver: can't bind local address"); - printf("Not reporting to the metaserver in this game\n"); - printf("Use option --nometa to always enforce this\n> "); - fflush(stdout); + console_write(201,"Not reporting to the metaserver in this game"); + console_write(201,"Use option --nometa to always enforce this"); + console_flush(); return; } Index: sernet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v retrieving revision 1.8 diff -u -r1.8 sernet.c --- sernet.c 1998/12/21 16:12:06 1.8 +++ sernet.c 1999/01/21 09:47:00 @@ -132,7 +132,7 @@ *(buf+didget)='\0'; handle_stdin_input(buf); - show_prompt(); + console_show_prompt(); } else { /* input from a player */ for(i=0; i #include #include +#include extern struct move_cost_map warmap; signed short int minimap[MAP_MAX_WIDTH][MAP_MAX_HEIGHT]; @@ -887,7 +888,7 @@ best_newv = 0; /* Bad Things happen without this line! :( -- Syela */ if (0 && best_newv > 0) - printf("Settler %d@(%d,%d) wants to %d at (%d,%d) with desire %d\n", + flog(LOG_DEBUG,"Settler %d@(%d,%d) wants to %d at (%d,%d) with desire %d\n", punit->id, punit->x, punit->y, best_act, gx, gy, best_newv); save_newv = best_newv; @@ -1005,7 +1006,7 @@ if (choice.want > 0) ai_choose_ferryboat(pplayer, mycity, &choice); if (0 && best_newv != save_newv) - printf("Settler %d@(%d,%d) wants to %d at (%d,%d) with desire %d\n", + flog(LOG_DEBUG,"Settler %d@(%d,%d) wants to %d at (%d,%d) with desire %d\n", punit->id, punit->x, punit->y, best_act, gx, gy, best_newv); /* if (map_get_terrain(punit->x, punit->y) == T_OCEAN) Index: stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.42 diff -u -r1.42 stdinhand.c --- stdinhand.c 1999/01/17 11:29:17 1.42 +++ stdinhand.c 1999/01/21 09:47:01 @@ -28,6 +28,7 @@ #include #include #include +#include extern int gamelog_level; extern char metaserver_info_line[256]; @@ -469,19 +470,6 @@ static char horiz_line[] = "------------------------------------------------------------------------------"; -void show_prompt() -{ - static int first=1; - - if (first) - printf("\nGet a list of the available commands with 'h'.\n"); - - printf("> "); - fflush(stdout); - - first = 0; -} - /************************************************************************** ... **************************************************************************/ @@ -490,7 +478,7 @@ strncpy(metaserver_info_line, arg, 256); metaserver_info_line[256-1]='\0'; if (send_server_info_to_metaserver(1) == 0) - printf("Not reporting to the metaserver in this game\n"); + console_write(201,"Not reporting to the metaserver in this game"); } /*************************************************************** @@ -555,7 +543,7 @@ if (server_state==SELECT_RACES_STATE || (server_state == PRE_GAME_STATE && !map_is_empty())) { - printf("Please wait until the game has started to save.\n"); + console_write(200,"Please wait until the game has started to save."); return; } @@ -564,9 +552,9 @@ game_save(&file); if(!section_file_save(&file, arg)) - printf("Failed saving game as %s\n", arg); + console_write(200,"Failed saving game as %s", arg); else - printf("Game saved as %s\n", arg); + console_write(100,"Game saved as %s", arg); section_file_free(&file); } @@ -579,19 +567,19 @@ struct player *pplayer; if (test_player_name(arg) != PNameOk) { - puts("Name is either empty or too long, so it cannot be an AI."); + console_write(200, "Name is either empty or too long, so it cannot be an AI."); return; } pplayer=find_player_by_name(arg); if (!pplayer) { - puts("No player by that name."); + console_write(200,"No player by that name."); return; } pplayer->ai.control = !pplayer->ai.control; if (pplayer->ai.control) { notify_player(0, "Game: %s is now AI-controlled.", pplayer->name); - printf("%s is now under AI control.\n",pplayer->name); + console_write(100,"%s is now under AI control.",pplayer->name); if (pplayer->ai.skill_level==0) { pplayer->ai.skill_level = game.skill_level; } @@ -601,7 +589,7 @@ set_ai_level(arg, pplayer->ai.skill_level); } else { notify_player(0, "Game: %s is now human.", pplayer->name); - printf("%s is now under human control.\n",pplayer->name); + console_write(100,"%s is now under human control.",pplayer->name); } send_player_info(pplayer,0); } @@ -628,19 +616,19 @@ if ((PNameStatus = test_player_name(arg)) == PNameEmpty) { - puts("Can't use an empty name."); + console_write(200,"Can't use an empty name."); return; } if (PNameStatus == PNameTooLong) { - puts("The name exceeds the maximum of 9 chars."); + console_write(200,"The name exceeds the maximum of 9 chars."); return; } if ((pplayer=find_player_by_name(arg))) { - puts("A player already exists by that name."); + console_write(200,"A player already exists by that name."); return; } @@ -648,7 +636,7 @@ pplayer = find_player_by_name(arg); if (!pplayer) { - printf ("Error creating new ai player: %s\n", arg); + console_write(200,"Error creating new ai player: %s", arg); return; } @@ -657,6 +645,8 @@ pplayer->is_connected=0; notify_player(0, "Game: %s has been added as an AI-controlled player.", pplayer->name); + console_write(100, "Game: %s has been added as an AI-controlled player.", + pplayer->name); } @@ -668,14 +658,14 @@ struct player *pplayer; if (test_player_name(arg) != PNameOk) { - puts("Name is either empty or too long, so it cannot be a player."); + console_write(200,"Name is either empty or too long, so it cannot be a player."); return; } pplayer=find_player_by_name(arg); if(!pplayer) { - puts("No player by that name."); + console_write(200,"No player by that name."); return; } @@ -704,31 +694,33 @@ if (*command) { cmd=lookup_cmd(command); if (cmd==-1) { - puts("No explanation for that yet."); + console_write(200,"No explanation for that yet."); return; } else { struct settings_s *op = &settings[cmd]; - printf("Option: %s\n", op->name); - printf("Description: %s.\n", op->short_help); + console_write(100,"Option: %s", op->name); + console_write(100,"Description: %s.", op->short_help); if(op->extra_help && strcmp(op->extra_help,"")!=0) { - puts(op->extra_help); + console_write(100,op->extra_help); } - printf("Status: %s\n", (sset_is_changeable(cmd) + console_write(100,"Status: %s", (sset_is_changeable(cmd) ? "changeable" : "fixed")); - printf("Value: %d, Minimum: %d, Default: %d, Maximum: %d\n", + console_write(100,"Value: %d, Minimum: %d, Default: %d, Maximum: %d", *(op->value), op->min_value, op->default_value, op->max_value); } } else { - puts(horiz_line); - puts("Explanations are available for the following server options:"); - puts(horiz_line); + console_write(0,horiz_line); + console_write(0,"Explanations are available for the following server options:"); + console_write(0,horiz_line); + console_dump(0, ""); for (i=0;settings[i].name;i++) { - printf("%-19s%c",settings[i].name, ((i+1)%4) ? ' ' : '\n'); + console_dump(-1,"%-19s%c",settings[i].name, ((i+1)%4) ? ' ' : '\n'); + if (!((i+1)%4) && settings[i].name) console_dump(0,""); } - if ((i)%4!=0) puts(""); - puts(horiz_line); + if ((i)%4!=0) console_write(-1,""); + console_write(0,horiz_line); } } @@ -770,7 +762,7 @@ pplayer->ai.fuzzy = fuzzy_of_skill_level(level); pplayer->ai.expand = expansionism_of_skill_level(level); pplayer->ai.skill_level = level; - printf("%s is now %s.\n", pplayer->name, name_of_skill_level(level)); + console_write(100,"%s is now %s.", pplayer->name, name_of_skill_level(level)); } void set_ai_level(char *name, int level) @@ -779,7 +771,7 @@ int i; if (test_player_name(name) == PNameTooLong) { - puts("Name is too long, so it cannot be a player."); + console_write(200,"Name is too long, so it cannot be a player."); return; } @@ -791,7 +783,7 @@ if (pplayer->ai.control) { set_ai_level_direct(pplayer, level); } else { - printf("%s is not controlled by the AI.\n", pplayer->name); + console_write(200,"%s is not controlled by the AI.", pplayer->name); } } else if(test_player_name(name) == PNameEmpty) { for (i = 0; i < game.nplayers; i++) { @@ -800,16 +792,16 @@ set_ai_level_direct(pplayer, level); } } - printf("Setting game.skill_level to %d.\n", level); + console_write(100,"Setting game.skill_level to %d.", level); game.skill_level = level; } else { - printf("%s is not the name of any player.\n", name); + console_write(200,"%s is not the name of any player.", name); } } void crash_and_burn(void) { - printf("Crashing and burning.\n"); + console_write(0,"Crashing and burning."); assert(0); } @@ -821,29 +813,29 @@ void show_command(char *str) { int i, len1; - puts(horiz_line); - len1 = printf("%-*s value (min , max) ", SSET_MAX_LEN, "Option"); - puts("description"); - puts(horiz_line); + console_write(0,horiz_line); + len1 = console_dump(0,"%-*s value (min , max) ", SSET_MAX_LEN, "Option"); + console_write(-1,"description"); + console_write(0,horiz_line); for (i=0;settings[i].name;i++) { struct settings_s *op = &settings[i]; int len; - len = printf("%-*s %c%c%-4d (%d,%d)", SSET_MAX_LEN, op->name, + len = console_dump(0,"%-*s %c%c%-4d (%d,%d)", SSET_MAX_LEN, op->name, (sset_is_changeable(i) ? '#' : ' '), ((*op->value==op->default_value) ? '*' : ' '), *op->value, op->min_value, op->max_value); /* Line up the descriptions: */ if(len < len1) { - printf("%*s", (len1-len), " "); + console_dump(-1,"%*s", (len1-len), " "); } else { - printf(" "); + console_dump(-1," "); } - puts(op->short_help); + console_write(-1,op->short_help); } - puts(horiz_line); - puts("* means that it's the default for that option"); - puts("# means the option may be changed"); - puts(horiz_line); + console_write(0,horiz_line); + console_write(0,"* means that it's the default for that option"); + console_write(0,"# means the option may be changed"); + console_write(0,horiz_line); } void set_command(char *str) @@ -864,11 +856,11 @@ cmd=lookup_cmd(command); if (cmd==-1) { - puts("Undefined argument. Usage: set