remove reference comments after functions
[netris.git] / server.c
index 39222bf6da6623ee14838c5bd426cae2ab8c6c7c..bcf3f04ece98235ebeb6cd63ac765c03b8408323 100644 (file)
--- a/server.c
+++ b/server.c
 #define HEADER_SIZE sizeof(netint4[3])
 
 static struct option options[] = {
-       { "wait",               0, 0, 'w' },
-       { "port",               1, 0, 'p' },
-       { "quadra",             1, 0, 'q' },
-       { "min-players",1, 0, 'm' },
-       { "max-players",1, 0, 'x' },
-       { "continuous", 1, 0, 'c' },
-       { "speed",              1, 0, 'i' },
-       { "seed",               1, 0, 's' },
-       { "verbose",    0, 0, 'v' },
-       { "info",               0, 0, 'H' },
-       { "help",               0, 0, 'h' },
-       { 0,                    0, 0,  0 }
+       { "wait",        0, 0, 'w' },
+       { "port",        1, 0, 'p' },
+       { "quadra",      1, 0, 'q' },
+       { "min-players", 1, 0, 'm' },
+       { "max-players", 1, 0, 'x' },
+       { "continuous",  1, 0, 'c' },
+       { "speed",       1, 0, 'i' },
+       { "seed",        1, 0, 's' },
+       { "verbose",     0, 0, 'v' },
+       { "info",        0, 0, 'H' },
+       { "help",        0, 0, 'h' },
+       { 0,             0, 0,  0  }
 };
 
 static char minplayers = 2;
@@ -91,12 +91,12 @@ void SendPacketTo(short playa, short uid, NetPacketType type, int size, void *da
                if (size > 0 && data && MyWrite(netGen[playa].fd, data, size) != size)
                        die("write");
        }
-} //SendPacketTo
+}
 
 static MyEventType AlarmGenFunc(EventGenRec *gen, MyEvent *event)
 {
        return E_alarm;
-} //AlarmGenFunc
+}
 
 void SCloseNet(short playa)
 { //kick some connection's ass!
@@ -105,14 +105,14 @@ void SCloseNet(short playa)
        if (netGen[playa].fd >= 0) {
                if (Players[playa].alive >= 0) {
                        SendPacketTo(playa, 0, NP_endConn, 0, NULL);
-                       do{} while (WaitMyEvent(&event, EM_net) != E_lostConn);
+                       do {} while (WaitMyEvent(&event, EM_net) != E_lostConn);
                } //say bye to player
                close(netGen[playa].fd);
                netGen[playa].fd = -1;
        }
        if (netGen[playa].next)
                RemoveEventGen(&netGen[playa]);
-} //SCloseNet
+}
 
 void CloseNets(void)
 { //nou oogjes dicht en snaveltjes toe
@@ -122,7 +122,7 @@ void CloseNets(void)
        for (i = 1; i < MAX_SCREENS; i++)
                SCloseNet(i); //bye everybuddy
        fprintf(stderr, "* All Done\n\n");
-} //CloseNets
+}
 
 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event)
 { //receive
@@ -158,7 +158,7 @@ MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event)
                return E_lostConn;
        } //client sent quit signal
        return E_net;
-} //NetGenFunc
+}
 
 
 static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event)
@@ -188,7 +188,7 @@ static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event)
                                sprintf(Players[new].host, "%s", inet_ntoa(addr.sin_addr));
                                if (addr.sin_family == AF_INET) {
                                        host = gethostbyaddr((void *)&addr.sin_addr,
-                                                       sizeof(struct in_addr), AF_INET);
+                                                            sizeof(struct in_addr), AF_INET);
                                        if (host) {
                                                strncpy(Players[new].host, host->h_name,
                                                        sizeof(Players[new].host) - 1);
@@ -197,7 +197,7 @@ static MyEventType ConnGenFunc(EventGenRec *gen, MyEvent *event)
                                }
                        } //E_connect
        return E_connect;
-} //ConnGenFunc
+}
 
 void CountPlayers(void)
 { //count number of players/teams
@@ -211,7 +211,7 @@ void CountPlayers(void)
                        } //player of same team counted before
                playercount++;
        } //player alive
-} //CountPlayers
+}
 
 int StartServer(void)
 {
@@ -221,7 +221,7 @@ int StartServer(void)
        int paused = 1;
        int i;
        char teams[10][7] = { "", "Green", "Cyan", "Blue", "Purple",
-                                                       "Red", "Grey", "White", "*Orange" };
+                             "Red", "Grey", "White", "*Orange" };
 
        do {
                switch (WaitMyEvent(&event, EM_any)) {
@@ -251,7 +251,7 @@ int StartServer(void)
                                                major = ntoh4(versiondata[0]);
                                                protocolVersion = ntoh4(versiondata[1]);
                                                if (major != MAJOR_VERSION
-                                               || protocolVersion != PROTOCOL_VERSION) {
+                                                || protocolVersion != PROTOCOL_VERSION) {
                                                        snprintf(data, sizeof(data),
                                                                "Version mismatch: received %d.%d",
                                                                major, protocolVersion);
@@ -365,7 +365,7 @@ int StartServer(void)
                                        sendtoall:
 //                                             if (event.u.net.type >= NP_pause)
                                                if (event.u.net.type >= NP_rotright
-                                               && Game.started < 2)
+                                                && Game.started < 2)
                                                        break;
                                                for (i = 1; i < MAX_SCREENS; i++)
                                                        if (i != event.u.net.sender)
@@ -418,57 +418,35 @@ int StartServer(void)
                } //game (ready to) start(ed)
        } while (1);
        fprintf(stderr, "* Exiting server\n");
-} //StartServer
+}
 
 
 void SHeader(void)
 {
        fprintf(stderr,
-         "NETRIS Server %s\t(c) 2002 Shiar <shiar@shiar.org>\n\n",
-         version_string);
+               "NETRIS Server %s\t(c) 2002 Shiar <shiar@shiar.org>\n\n",
+               version_string);
 }
 
 void SUsage(void)
 {
        SHeader();
        fprintf(stderr,
-         "Usage: netris <options>\n"
-         "\n"
-         "  -h, --help\t\tPrint this usage information\n"
-         "  -H, --info\t\tShow distribution and warranty information\n"
-         "\n"
-         "  -p, --port <port>\tSet port number (default is %d)\n"
-         "\n"
-         "  -s, --seed <seed>\tStart with given random seed\n"
-         "  -i, --speed <sec>\tSet the initial step-down interval, in seconds\n"
-         "  -m, --min-players <2>\tNumber of players required before starting the game\n"
-         "  -x, --max-players <8>\tMaximum number of players allowed in the game\n"
-         "  -c, --continuous\tDon'n quit the game\n"
-         "\n", DEFAULT_PORT);
+               "Usage: netris <options>\n"
+               "\n"
+               "  -h, --help\t\tPrint this usage information\n"
+               "  -H, --info\t\tShow distribution and warranty information\n"
+               "\n"
+               "  -p, --port <port>\tSet port number (default is %d)\n"
+               "\n"
+               "  -s, --seed <seed>\tStart with given random seed\n"
+               "  -i, --speed <sec>\tSet the initial step-down interval, in seconds\n"
+               "  -m, --min-players <2>\tNumber of players required before starting the game\n"
+               "  -x, --max-players <8>\tMaximum number of players allowed in the game\n"
+               "  -c, --continuous\tDon'n quit the game\n"
+               "\n", DEFAULT_PORT);
 }
 
-/*
-void DistInfo(void)
-{
-       SHeader();
-       fprintf(stderr,
-         "This program is free software; you can redistribute it and/or modify\n"
-         "it under the terms of the GNU General Public License as published by\n"
-         "the Free Software Foundation; either version 2 of the License, or\n"
-         "(at your option) any later version.\n"
-         "\n"
-         "This program is distributed in the hope that it will be useful,\n"
-         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-         "GNU General Public License for more details.\n"
-         "\n"
-         "You should have received a copy of the GNU General Public License\n"
-         "along with this program; if not, write to the Free Software\n"
-         "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
-         "\n");
-} //DistInfo
-*/
-
 void WriteConf(void)
 {
        FILE *file_out;
@@ -483,45 +461,46 @@ void WriteConf(void)
 
        fclose(file_out);
        fprintf(stderr, "Wrote new game configuration to %s\n", CONFIG_FILE);
-} //WriteConf
+}
 
 void HandleOption(char tag, char *value)
 {
        switch (tag) {
-               case 'v':       //verbose
+               case 'v':  //verbose
                        verbose = 1;
                        break;
-               case 'p':       //port
+               case 'p':  //port
                        port = atoi(value);
                        break;
-               case 'c':       //min-players
+               case 'c':  //min-players
                        Game.continuous = atoi(value);
                        break;
-               case 'm':       //min-players
+               case 'm':  //min-players
                        minplayers = atoi(value);
                        break;
-               case 'x':       //max-players
+               case 'x':  //max-players
                        maxplayers = atoi(value);
                        if (maxplayers >= MAX_SCREENS)
                                maxplayers = MAX_SCREENS;
                        break;
-               case 'q':       //quadra-style gravity
+               case 'q':  //quadra-style gravity
                        Game.gravity ^= 1;
                        break;
-               case 'i':       //speed (of level 1)
+               case 'i':  //speed (of level 1)
                        Game.initspeed = atof(value) * 1e6;
                        break;
-               case 's':       //seed
+               case 's':  //seed
                        Game.seed = atoi(value);
                        break;
-               case 'H':       //info
+               case 'H':  //info
+                       SHeader();
                        DistInfo(); exit(0);
-               case 'h':       //help
+               case 'h':  //help
                        SUsage(); exit(0);
                default:
                        break;
        }
-} //HandleParam
+}
 
 void ReadConf(char *filename)
 {
@@ -537,8 +516,8 @@ void ReadConf(char *filename)
                        if ((ch = strchr(buf, '#')))
                                *ch = '\0'; // truncate string from # char
                        for (i = strlen(buf)-1; i >= 0; i--)
-                               if (buf[i] == ' ' || buf[i] == '\t'
-                               || buf[i] == '\n' || buf[i] == 13)
+                               if (buf[i] == ' '  || buf[i] == '\t'
+                                || buf[i] == '\n' || buf[i] == 13)
                                        buf[i] = '\0';
                                else break;
 
@@ -556,7 +535,7 @@ void ReadConf(char *filename)
                fprintf(stderr, "Unable to open config file %s.\n", filename);
        } //defaults
 
-} //ReadConf
+}
 
 void CatchInt(int sig)
 {
@@ -585,8 +564,9 @@ int main(int argc, char **argv)
 //             ReadConf(optarg);
 //     else
        ReadConf(CONFIG_FILE);
-       while ((ch = getopt_long(argc, argv,
-                       "hHvqp:i:s:c:m:x:", options, NULL)) != -1)
+       while ((ch = getopt_long(
+               argc, argv, "hHvqp:i:s:c:m:x:", options, NULL
+       )) != -1)
                HandleOption(ch, optarg);
        if (optind < argc) {
                SUsage();
@@ -616,7 +596,7 @@ int main(int argc, char **argv)
                        die("socket");
                val1 = 1;
                setsockopt(connGen.fd, SOL_SOCKET, SO_REUSEADDR,
-                               (void *)&val1, sizeof(val1));
+                       (void *)&val1, sizeof(val1));
                if (bind(connGen.fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
                        die("bind");
                if (listen(connGen.fd, 1) < 0)