]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/accept.c
Update copyright notice.
[empserver] / src / lib / player / accept.c
index 29d6560c978ebc030091d93ef2b9d8e0453ef4e2..ba2ca2e9b272504347dbf9367fd93f638de2f267 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 
 #include "prototypes.h"
 #include "misc.h"
-#include "bit.h"
 #include "proto.h"
 #include "empthread.h"
 #include "player.h"
 #include "file.h"
-#include "io_mask.h"
 #include "empio.h"
 #include "power.h"
 #include "common.h"
@@ -46,6 +44,7 @@
 #include "optlist.h"
 
 #if !defined(_WIN32)
+#include <arpa/inet.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/time.h>
@@ -75,13 +74,23 @@ struct player *
 player_new(int s, struct sockaddr_in *sin)
 {
     struct player *lp;
+#ifdef RESOLVE_IPADDRESS
     struct hostent *hostp;
+#endif
 
-    lp = (struct player *)calloc(1, sizeof(struct player));
-    bzero((s_char *)lp, sizeof(struct player));
+    lp = (struct player *)malloc(sizeof(struct player));
+    if (!lp)
+      return NULL;
+    memset(lp, 0, sizeof(struct player));
     if (sin) {
-       /* update uses dummy player */
-       /* so does the market updater */
+       /* real player, not dummy created by update and market update */
+       lp->iop = io_open(s,
+                         IO_READ | IO_WRITE | IO_NBLOCK,
+                         IO_BUFSIZE, 0, 0);
+       if (!lp->iop) {
+           free(lp);
+           return NULL;
+       }
        emp_insque(&lp->queue, &Players);
        strcpy(lp->hostaddr, inet_ntoa(sin->sin_addr));
 #ifdef RESOLVE_IPADDRESS
@@ -94,8 +103,6 @@ player_new(int s, struct sockaddr_in *sin)
        lp->cnum = 255;
        lp->curid = -1;
        time(&lp->curup);
-       lp->iop = io_open(s, IO_READ | IO_WRITE | IO_NBLOCK,
-                         IO_BUFSIZE, 0, 0);
     }
     return lp;
 }
@@ -187,15 +194,13 @@ player_wakeup(struct player *pl)
 
 /*ARGSUSED*/
 void
-player_accept(void *argv)
+player_accept(void *unused)
 {
-    extern s_char *loginport;
     struct sockaddr_in sin;
     struct servent *sp;
     int s;
     short port;
     int val;
-    int maxfd;
     struct player *np;
     int len;
     int ns;
@@ -224,8 +229,7 @@ player_accept(void *argv)
        exit(1);
     }
 #else
-    logerror
-       ("Alpha/Linux?  You don't support SO_REUSEADDR yet, do you?\n");
+    logerror("Alpha/Linux?  You don't support SO_REUSEADDR yet, do you?\n");
 #endif
     if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        logerror("inet socket bind");
@@ -243,7 +247,6 @@ player_accept(void *argv)
        exit(1);
     }
 #endif
-    maxfd = getfdtablesize() - 1;
     while (1) {
        empth_select(s, EMPTH_FD_READ);
        len = sizeof(sin);
@@ -254,13 +257,12 @@ player_accept(void *argv)
        }
        (void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE,
                         (char *)&set, sizeof(set));
-       if (ns >= maxfd) {
-           logerror("new fd %d, max %d, no fd's left for new user",
-                    ns, maxfd);
-           close(ns);
-           continue;
-       }
        np = player_new(ns, &sin);
+       if (!np) {
+           logerror("can't create player for fd %d", ns);
+           close(ns);
+           continue;
+       }
        /* XXX may not be big enough */
        stacksize = 100000
 /* budget */  + max(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,