aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--FICS/ficsmain.c181
1 files changed, 99 insertions, 82 deletions
diff --git a/FICS/ficsmain.c b/FICS/ficsmain.c
index faf77c9..b246e6a 100644
--- a/FICS/ficsmain.c
+++ b/FICS/ficsmain.c
@@ -60,104 +60,121 @@ PRIVATE void usage(char *progname)
exit(1);
}
-PRIVATE void GetArgs(int argc, char *argv[])
+PRIVATE void
+GetArgs(int argc, char *argv[])
{
- int i;
-
- port = DEFAULT_PORT;
- withConsole = 0;
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- switch (argv[i][1]) {
- case 'p':
- if (i == argc - 1)
- usage(argv[0]);
- i++;
- if (sscanf(argv[i], "%d", &port) != 1)
- usage(argv[0]);
- break;
- case 'C':
- fprintf(stderr, "-C Not implemented!\n");
- exit(1);
- withConsole = 1;
- break;
- case 'h':
- usage(argv[0]);
- break;
- }
- } else {
- usage(argv[0]);
- }
- }
+ port = DEFAULT_PORT;
+ withConsole = 0;
+
+ for (int i = 1; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ switch (argv[i][1]) {
+ case 'p':
+ if (i == argc - 1)
+ usage(argv[0]);
+ i++;
+ if (sscanf(argv[i], "%d", &port) != 1)
+ usage(argv[0]);
+ break;
+ case 'C':
+ fprintf(stderr, "-C Not implemented!\n");
+ exit(1);
+ withConsole = 1;
+ break;
+ case 'h':
+ usage(argv[0]);
+ break;
+ }
+ } else {
+ usage(argv[0]);
+ }
+ }
}
-PRIVATE void main_event_loop(void) {
-int current_socket;
-char command_string[MAX_STRING_LENGTH];
-
- while (1) {
- ngc2(command_string, HEARTBEATTIME);
- if (process_heartbeat(&current_socket) == COM_LOGOUT) {
- process_disconnection(current_socket);
- net_close_connection(current_socket);
- }
- }
+PRIVATE void
+main_event_loop(void)
+{
+ char command_string[MAX_STRING_LENGTH];
+ int current_socket;
+
+ while (1) {
+ ngc2(command_string, HEARTBEATTIME);
+ if (process_heartbeat(&current_socket) == COM_LOGOUT) {
+ process_disconnection(current_socket);
+ net_close_connection(current_socket);
+ }
+ }
}
-void TerminateServer(int sig)
+void
+TerminateServer(int sig)
{
- fprintf(stderr, "FICS: Got signal %d\n", sig);
- output_shut_mess();
- TerminateCleanup();
- net_close();
- exit(1);
+ fprintf(stderr, "FICS: Got signal %d\n", sig);
+ output_shut_mess();
+ TerminateCleanup();
+ net_close();
+ exit(1);
}
-void BrokenPipe(int sig)
+void
+BrokenPipe(int sig)
{
- fprintf(stderr, "FICS: Got Broken Pipe\n");
+ fprintf(stderr, "FICS: Got Broken Pipe\n");
}
-PUBLIC int main(int argc, char *argv[])
+PUBLIC int
+main(int argc, char *argv[])
{
-
#ifdef DEBUG
#ifdef HAVE_MALLOC_DEBUG
- malloc_debug(16);
+ malloc_debug(16);
#endif
#endif
- GetArgs(argc, argv);
- signal(SIGTERM, TerminateServer);
- signal(SIGINT, TerminateServer);
- signal(SIGPIPE, BrokenPipe);
- if (net_init(port)) {
- fprintf(stderr, "FICS: Network initialize failed on port %d.\n", port);
- exit(1);
- }
- startuptime = time(0);
- strcpy ( fics_hostname, SERVER_HOSTNAME );
- quota_time = 60;
- player_high = 0;
- game_high = 0;
- srand(startuptime);
- fprintf(stderr, "FICS: Initialized on port %d at %s.\n", port, strltime(&startuptime));
- fprintf(stderr, "FICS: commands_init()\n");
- commands_init();
- fprintf(stderr, "FICS: rating_init()\n");
- rating_init();
- fprintf(stderr, "FICS: wild_init()\n");
- wild_init();
+ GetArgs(argc, argv);
+
+ signal(SIGINT, TerminateServer);
+ signal(SIGPIPE, BrokenPipe);
+ signal(SIGTERM, TerminateServer);
+
+ if (net_init(port)) {
+ fprintf(stderr, "FICS: Network initialize failed on port %d.\n",
+ port);
+ exit(1);
+ }
+
+ startuptime = time(0);
+ strcpy(fics_hostname, SERVER_HOSTNAME);
+ game_high = 0;
+ player_high = 0;
+ quota_time = 60;
+ srand(startuptime);
+
+ fprintf(stderr, "FICS: Initialized on port %d at %s.\n", port,
+ strltime(&startuptime));
+ fprintf(stderr, "FICS: commands_init()\n");
+ commands_init();
+
+ fprintf(stderr, "FICS: rating_init()\n");
+ rating_init();
+
+ fprintf(stderr, "FICS: wild_init()\n");
+ wild_init();
+
#ifndef IGNORE_ECO
- fprintf(stderr, "FICS: book init()\n");
- BookInit();
+ fprintf(stderr, "FICS: book init()\n");
+ BookInit();
#endif
- fprintf(stderr, "FICS: player_array_init()\n");
- player_array_init();
- player_init(withConsole);
- main_event_loop();
- fprintf(stderr, "FICS: Closing down.\n");
- output_shut_mess();
- net_close();
- return 0;
+
+ fprintf(stderr, "FICS: player_array_init()\n");
+ player_array_init();
+ fprintf(stderr, "FICS: player_init(withConsole=%d)\n", withConsole);
+ player_init(withConsole);
+
+ main_event_loop();
+
+ fprintf(stderr, "FICS: Closing down.\n");
+ output_shut_mess();
+ net_close();
+
+ return 0;
}