/*
* 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 "empthread.h"
#include "player.h"
#include "file.h"
-#include "io_mask.h"
#include "empio.h"
#include "power.h"
#include "common.h"
#include "optlist.h"
#if !defined(_WIN32)
+#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/time.h>
player_new(int s, struct sockaddr_in *sin)
{
struct player *lp;
+#ifdef RESOLVE_IPADDRESS
struct hostent *hostp;
+#endif
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
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;
}
/*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;
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");
exit(1);
}
#endif
- maxfd = getfdtablesize() - 1;
while (1) {
empth_select(s, EMPTH_FD_READ);
len = sizeof(sin);
}
(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,