diff -puN --- comm.old Thu Aug 20 13:13:06 2009 +++ comm.cpp Thu Aug 20 13:49:07 2009 @@ -100,7 +100,7 @@ extern const char *circlemud_version; extern int circle_restrict; extern int mini_mud; extern FILE *player_fl; -extern ush_int DFLT_PORT; +extern int DFLT_PORT; extern const char *DFLT_DIR; extern const char *DFLT_IP; extern const char *LOGNAME; @@ -157,6 +157,10 @@ log_info logs[NLOG] = { {NULL, "log/imlog.txt", "ИНГРЕДИЕНТНАЯ МАГИЯ"} }; +/* Port options ( These need to be altered in order to add more ports.) */ +int ports[10] = {8888,8889,-1,-1,-1,-1,-1,-1,-1,-1}; +socket_t mother_descs[10] = {8888,8889,-1,-1,-1,-1,-1,-1,-1,-1}; + char src_path[4096]; /* functions in this file */ @@ -170,9 +174,9 @@ ssize_t perform_socket_write(socket_t de void sanity_check(void); void circle_sleep(struct timeval *timeout); int get_from_q(struct txt_q *queue, char *dest, int *aliased); -void init_game(ush_int port); +void init_game(int ports[]); void signal_setup(void); -void game_loop(socket_t mother_desc); +void game_loop(socket_t mother_descs[]); socket_t init_socket(ush_int port); int new_descriptor(socket_t s); @@ -321,9 +325,9 @@ int main(int argc, char **argv) malloc_options = "A"; #endif - ush_int port; - int pos = 1; const char *dir; + extern int ports[10]; + int i = 0, pos = 1; print_time(); printf(" Virtustan MUD starting\n"); @@ -348,7 +352,7 @@ printf(" Virtustan MUD starting\n"); GUSIDefaultSetup(); #endif - port = DFLT_PORT; + ports[0] = DFLT_PORT; dir = DFLT_DIR; while ((pos < argc) && (*(argv[pos]) == '-')) { @@ -412,8 +416,9 @@ printf(" Virtustan MUD starting\n"); if (!isdigit(*argv[pos])) { printf("Usage: %s [-c] [-m] [-q] [-r] [-s] [-d pathname] [port #]\n", argv[0]); exit(1); - } else if ((port = atoi(argv[pos])) <= 1024) { - printf("SYSERR: Illegal port number %d.\n", port); + } else if (!(ports[i] = atoi(argv[pos]))) { + printf("SYSERR: Illegal port number.\n"); + exit(1); } } @@ -436,14 +441,14 @@ printf(" Virtustan MUD starting\n"); if (scheck) { boot_world(); log("Done."); - } else { - log("Running game on port %d.", port); + } + else { // стль и буст юзаются уже немало где, а про их экспешены никто не думает // пока хотя бы стльные ловить и просто логировать факт того, что мы вышли // по эксепшену для удобства отладки и штатного сброса сислога в файл, т.к. в коре будет фиг try { - init_game(port); + init_game(ports); } catch (std::exception &e) { log("STD exception: %s", e.what()); @@ -459,9 +464,10 @@ printf(" Virtustan MUD starting\n"); /* Init sockets, run game, and cleanup sockets */ -void init_game(ush_int port) +void init_game(int ports[]) { - socket_t mother_desc; + int i; + extern socket_t mother_descs[10]; /* We don't want to restart if we crash before we get up. */ touch(KILLSCRIPT_FILE); @@ -471,8 +477,11 @@ void init_game(ush_int port) log("Finding player limit."); max_players = get_max_players(); - log("Opening mother connection."); - mother_desc = init_socket(port); + log("Binding interface to ports:"); + for (i = 0; ports[i] != -1;i++) { + log( " Opening port %d ...", ports[i]); + mother_descs[i] = init_socket(ports[i]); + } boot_db(); @@ -485,7 +494,7 @@ void init_game(ush_int port) remove(KILLSCRIPT_FILE); log("Entering game loop."); - game_loop(mother_desc); + game_loop(mother_descs); flush_player_index(); if (circle_shutdown == 2) { @@ -506,7 +515,9 @@ void init_game(ush_int port) while (descriptor_list) close_socket(descriptor_list, TRUE); - CLOSE_SOCKET(mother_desc); + for (i = 0; mother_descs[i] != -1;i++) + close(mother_descs[i]); + if (circle_reboot != 2 && olc_save_list) { /* Don't save zones. */ struct olc_save_info *entry, *next_entry; int rznum; @@ -803,11 +814,11 @@ inline void rotate(log_info * li, long p } inline void process_io(fd_set input_set, fd_set output_set, fd_set exc_set, fd_set null_set, - socket_t mother_desc, int maxdesc) + socket_t mother_desc[], int maxdesc) { DESCRIPTOR_DATA *d, *next_d; char comm[MAX_INPUT_LENGTH]; - int aliased; + int aliased, i; /* Poll (without blocking) for new input, output, and exceptions */ if (select(maxdesc + 1, &input_set, &output_set, &exc_set, &null_time) @@ -818,8 +829,10 @@ inline void process_io(fd_set input_set, return; } /* If there are new connections waiting, accept them. */ - if (FD_ISSET(mother_desc, &input_set)) - new_descriptor(mother_desc); + for (i = 0; mother_descs[i] != -1;i++) { + if (FD_ISSET(mother_descs[i], &input_set)) + new_descriptor(mother_descs[i]); + } /* Kick out the freaky folks in the exception set and marked for close */ for (d = descriptor_list; d; d = next_d) { @@ -952,13 +965,13 @@ inline void process_io(fd_set input_set, * output and sending it out to players, and calling "heartbeat" functions * such as mobile_activity(). */ -void game_loop(socket_t mother_desc) +void game_loop(socket_t mother_descs[]) { fd_set input_set, output_set, exc_set, null_set; struct timeval last_time, opt_time, process_time, temp_time; struct timeval before_sleep, now, timeout; DESCRIPTOR_DATA *d; - int missed_pulses = 0, maxdesc; + int missed_pulses = 0, maxdesc, i; /* initialize various time values */ null_time.tv_sec = 0; @@ -976,8 +989,11 @@ void game_loop(socket_t mother_desc) log("No connections. Going to sleep."); make_who2html(); FD_ZERO(&input_set); - FD_SET(mother_desc, &input_set); - if (select(mother_desc + 1, &input_set, (fd_set *) 0, (fd_set *) 0, NULL) < 0) { + for (i = 0;mother_descs[i] != -1;i++) + FD_SET(mother_descs[i], &input_set); + + if (select(mother_descs[i-1] + 1, &input_set, (fd_set *) 0, (fd_set *) 0, NULL) < 0) { + if (errno == EINTR) log("Waking up to process signal."); else @@ -990,14 +1006,18 @@ void game_loop(socket_t mother_desc) FD_ZERO(&input_set); FD_ZERO(&output_set); FD_ZERO(&exc_set); - FD_SET(mother_desc, &input_set); - maxdesc = mother_desc; + maxdesc = -1; + /* add all mother sockets */ + for (i = 0; mother_descs[i] != -1;i++) { + FD_SET(mother_descs[i], &input_set); + if (mother_descs[i] > maxdesc) + maxdesc = mother_descs[i]; + } + for (d = descriptor_list; d; d = d->next) { -#ifndef CIRCLE_WINDOWS if (d->descriptor > maxdesc) - maxdesc = d->descriptor; -#endif + maxdesc = d->descriptor; FD_SET(d->descriptor, &input_set); FD_SET(d->descriptor, &output_set); FD_SET(d->descriptor, &exc_set); @@ -1064,7 +1084,7 @@ void game_loop(socket_t mother_desc) /* Now execute the heartbeat functions */ while (missed_pulses--) { - process_io(input_set, output_set, exc_set, null_set, mother_desc, maxdesc); + process_io(input_set, output_set, exc_set, null_set, mother_descs, maxdesc); heartbeat(); } @@ -1746,9 +1766,8 @@ struct in_addr *get_bind_addr() } /* Put the address that we've finally decided on into the logs */ - if (bind_addr.s_addr == htonl(INADDR_ANY)) - log("Binding to all IP interfaces on this host."); - else + if (!bind_addr.s_addr == htonl(INADDR_ANY)) + log("Binding only to IP address %s", inet_ntoa(bind_addr)); return (&bind_addr); --- config.old Thu Aug 20 13:13:23 2009 +++ config.cpp Thu Aug 20 13:37:23 2009 @@ -235,7 +235,7 @@ room_vnum unreg_start_room = 103; * Change the PORT= line in autorun instead of (or in addition to) * changing this. */ -ush_int DFLT_PORT = 8888; +int DFLT_PORT = 8888; /* * IP address to which the MUD should bind. This is only useful if