Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS update: Vanilla/ntserv
Date: Monday May 31, 1999 @ 20:53
Author: cameron
Update of /home/netrek/cvsroot/Vanilla/ntserv
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv4218/ntserv
Modified Files:
daemonII.c distress.c getname.c main.c proto.h socket.c
Log Message:
* UPDATE: fixed a few compiler warnings using -Wall.
* UPDATE: added TCP_NODELAY to ntserv processes.
* DEBUGGING: changed error reporting again for ntserv processes.
****************************************
Index: Vanilla/ntserv/daemonII.c
diff -u Vanilla/ntserv/daemonII.c:1.19 Vanilla/ntserv/daemonII.c:1.20
--- Vanilla/ntserv/daemonII.c:1.19 Fri May 28 08:35:06 1999
+++ Vanilla/ntserv/daemonII.c Mon May 31 20:53:21 1999
@@ -51,7 +51,7 @@
static void check_load(void);
static int tournamentMode(void);
static void check_scummers(void);
-static void move(void);
+static void move(int ignored);
static void udplayersight(void);
static void udplayers(void);
static void changedir(struct player *sp);
@@ -127,7 +127,6 @@
{
register int i;
int x = 0;
- void move();
static struct itimerval udt;
int glfd, plfd;
@@ -441,7 +440,7 @@
}
-static void move(void)
+static void move(int ignored)
{
static int oldtourn=0;
static int oldmessage;
@@ -3834,7 +3833,7 @@
while ((pid = WAIT3(&status, WNOHANG, 0)) > 0) {
if (debug) {
- ERROR(1,( "Reaping: pid is %d (status: %lX)\n",
+ ERROR(1,( "Reaping: pid is %d (status: %d)\n",
pid, status));
}
}
Index: Vanilla/ntserv/distress.c
diff -u Vanilla/ntserv/distress.c:1.2 Vanilla/ntserv/distress.c:1.3
--- Vanilla/ntserv/distress.c:1.2 Fri Apr 30 15:18:42 1999
+++ Vanilla/ntserv/distress.c Mon May 31 20:53:22 1999
@@ -418,15 +418,15 @@
if (j->p_ship.s_type == STARBASE)
#ifdef LTD_STATS
- sprintf (tmp, "%5.2f\0", (float) ltd_kills(j, LTD_SB));
+ sprintf (tmp, "%5.2f", (float) ltd_kills(j, LTD_SB));
#else
- sprintf (tmp, "%5.2f\0", (float) j->p_stats.st_sbkills);
+ sprintf (tmp, "%5.2f", (float) j->p_stats.st_sbkills);
#endif
else
#ifdef LTD_STATS
- sprintf (tmp, "%5.2f\0", (float) ltd_kills(j, LTD_TOTAL));
+ sprintf (tmp, "%5.2f", (float) ltd_kills(j, LTD_TOTAL));
#else
- sprintf (tmp, "%5.2f\0", (float) j->p_stats.st_kills +
+ sprintf (tmp, "%5.2f", (float) j->p_stats.st_kills +
j->p_stats.st_tkills);
#endif
APPEND (pbuf1, tmp);
Index: Vanilla/ntserv/getname.c
diff -u Vanilla/ntserv/getname.c:1.5 Vanilla/ntserv/getname.c:1.6
--- Vanilla/ntserv/getname.c:1.5 Fri Apr 30 18:31:31 1999
+++ Vanilla/ntserv/getname.c Mon May 31 20:53:22 1999
@@ -7,7 +7,6 @@
#include "copyright2.h"
#include <stdio.h>
-/*#include <crypt.h>*/
#include <stddef.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -165,6 +164,9 @@
/* A new guy? */
if ((position== -1) && !lockout()) {
strcpy(player.name, namePick);
+ /* Linux: compiler warnings with -Wall here, as crypt is in unistd.h
+ but needs _XOPEN_SOURCE defined, which then breaks lots of other
+ things such as u_int. - Quozl */
strcpy(player.password, crypt(passPick, salt(namePick, sb)));
MZERO(&player.stats, sizeof(struct stats));
#ifdef LTD_STATS
Index: Vanilla/ntserv/main.c
diff -u Vanilla/ntserv/main.c:1.11 Vanilla/ntserv/main.c:1.12
--- Vanilla/ntserv/main.c:1.11 Fri May 28 08:35:07 1999
+++ Vanilla/ntserv/main.c Mon May 31 20:53:22 1999
@@ -138,18 +138,13 @@
me = NULL; /* UDP fix (?) */
if (callHost) {
- struct player bogus;
-
- me = &bogus;
- me->p_mapchars[0] = 'L';
- me->p_mapchars[2] = '\0';
if (!connectToClient(host,xtrekPort)) {
exit(0);
}
- me = NULL;
} else {
sock=0; /* newstartd gives us our connection on 0 */
checkSocket();
+ setNoDelay(sock);
initClientData(); /* "normally" called by connectToClient() */
}
starttime=time(NULL);
Index: Vanilla/ntserv/proto.h
diff -u Vanilla/ntserv/proto.h:1.1 Vanilla/ntserv/proto.h:1.2
--- Vanilla/ntserv/proto.h:1.1 Fri Apr 30 15:45:37 1999
+++ Vanilla/ntserv/proto.h Mon May 31 20:53:22 1999
@@ -1,4 +1,4 @@
-/* $Id: proto.h,v 1.1 1999/04/30 20:45:37 ahn Exp $
+/* $Id: proto.h,v 1.2 1999/06/01 01:53:22 cameron Exp $
*
* Function prototypes for externally accessed functions.
*/
@@ -173,6 +173,7 @@
/* socket.c */
struct player_spacket;
+void setNoDelay(int fd);
int connectToClient(char *machine, int port);
void checkSocket(void);
void initClientData(void);
Index: Vanilla/ntserv/socket.c
diff -u Vanilla/ntserv/socket.c:1.12 Vanilla/ntserv/socket.c:1.13
--- Vanilla/ntserv/socket.c:1.12 Fri May 28 08:35:07 1999
+++ Vanilla/ntserv/socket.c Mon May 31 20:53:22 1999
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.12 1999/05/28 13:35:07 cameron Exp $
+/* $Id: socket.c,v 1.13 1999/06/01 01:53:22 cameron Exp $
*/
/*
@@ -18,6 +18,7 @@
#include <sys/time.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <math.h>
@@ -335,6 +336,26 @@
void updateTorps(void);
void updatePlasmas(void);
+static char *whoami(void)
+{
+ if (me == NULL) return "Q?";
+ return me->p_mapchars;
+}
+
+void setNoDelay(int fd)
+{
+ int status;
+ int option_value = 1;
+
+ status = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &option_value, sizeof(option_value));
+ if (status < 0) {
+ ERROR(1,("%s: setsockopt() failed, %s\n", whoami(),
+ strerror(errno)));
+ /* can still play without this, proceed */
+ }
+}
+
int connectToClient(char *machine, int port)
{
int ns, stat, derrno, derrnol;
@@ -347,10 +368,10 @@
shutdown(sock,2);
sock= -1;
}
- ERROR(3,("%s start connect to %s:%d\n", me->p_mapchars, machine, port));
+ ERROR(3,("%s start connect to %s:%d\n", whoami(), machine, port));
if ((ns=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- ERROR(1,("%s: socket() failed, %s\n", me->p_mapchars, strerror(errno)));
+ ERROR(1,("%s: socket() failed, %s\n", whoami(), strerror(errno)));
exit(2);
}
@@ -361,7 +382,7 @@
addr.sin_addr.s_addr=remoteaddr;
} else if ((addr.sin_addr.s_addr = inet_addr(machine)) == -1) {
if ((hp = gethostbyname(machine)) == NULL) {
- ERROR(1,("%s: gethostbyname() failed, %s\n", me->p_mapchars,
+ ERROR(1,("%s: gethostbyname() failed, %s\n", whoami(),
strerror(errno)));
close(ns);
exit(1);
@@ -381,7 +402,7 @@
/* set the socket non-blocking */
stat = ioctl(ns, FIONBIO, "in");
if (stat < 0) {
- ERROR(1,("%s: ioctl(FIONBIO) failed, %s\n", me->p_mapchars,
+ ERROR(1,("%s: ioctl(FIONBIO) failed, %s\n", whoami(),
strerror(errno)));
close(ns);
return(0);
@@ -390,7 +411,7 @@
/* start a connection attempt */
stat = connect(ns, &addr, sizeof(addr));
if (stat < 0 && errno != EINPROGRESS) {
- ERROR(2,("%s: connect() failed, %s\n", me->p_mapchars,
+ ERROR(2,("%s: connect() failed, %s\n", whoami(),
strerror(errno)));
close(ns);
return(0);
@@ -403,13 +424,13 @@
FD_SET(ns, &writefds);
stat = select(32,0,&writefds,0,&timeout);
if (stat < 0) {
- ERROR(1,("%s: select() after connect() failed, %s\n", me->p_mapchars,
+ ERROR(1,("%s: select() after connect() failed, %s\n", whoami(),
strerror(errno)));
close(ns);
return(0);
}
if (stat == 0) {
- ERROR(3,("%s: connect timed out\n", me->p_mapchars));
+ ERROR(3,("%s: connect timed out\n", whoami()));
close(ns);
return(0);
}
@@ -425,16 +446,16 @@
case 0:
break;
case ECONNREFUSED:
- ERROR(3,("%s: connection refused\n", me->p_mapchars));
+ ERROR(3,("%s: connection refused\n", whoami()));
close(ns);
return(0);
case ENETUNREACH:
- ERROR(3,("%s: network unreachable\n", me->p_mapchars));
+ ERROR(3,("%s: network unreachable\n", whoami()));
close(ns);
return(0);
case ETIMEDOUT:
default:
- ERROR(3,("%s: connect() failed, %s\n", me->p_mapchars,
+ ERROR(3,("%s: connect() failed, %s\n", whoami(),
strerror(errno)));
close(ns);
return(0);
@@ -443,13 +464,14 @@
/* set the socket blocking */
stat = ioctl(ns, FIONBIO, "out");
if (stat < 0) {
- ERROR(1,("%s: ioctl(FIONBIO) failed, %s\n", me->p_mapchars,
+ ERROR(1,("%s: ioctl(FIONBIO) failed, %s\n", whoami(),
strerror(errno)));
close(ns);
return(0);
}
sock=ns;
+ setNoDelay(sock);
initClientData();
testtime = -1;
return(1);
@@ -693,7 +715,7 @@
#endif
if (packet->type<1 || packet->type>NUM_SIZES ||
sizes[(int)packet->type]==0) {
- ERROR(1,("%s: attempt to send strange packet %d %d\n", me->p_mapchars,
+ ERROR(1,("%s: attempt to send strange packet %d %d\n", whoami(),
packet->type,NUM_SIZES));
return;
}
@@ -707,7 +729,7 @@
t=bufptr-buf;
if (gwrite(sock, buf, t) != t) {
ERROR(1,("%s: gwrite(TCP) failed, %s, client marked dead\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
clientDead=1;
}
bufptr=buf;
@@ -754,8 +776,8 @@
#endif
case SP_UDP_REPLY: /* only reply when COMM_UDP is SWITCH_VERIFY */
/* these are non-critical updates; send them via UDP */
- V_UDPDIAG(("Sending type %d\n", packet->type));
- size=sizes[packet->type];
+ V_UDPDIAG(("Sending type %d\n", (int)packet->type));
+ size=sizes[(int)packet->type];
#ifdef PING
packets_sent ++;
#endif
@@ -763,7 +785,7 @@
t=udpbufptr-udpbuf;
if (gwrite(udpSock, udpbuf, t) != t) {
ERROR(1,("%s: gwrite(UDP) failed, %s, client marked dead once more\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
#ifdef EXTRA_GB
clientDead=1;
#endif
@@ -793,12 +815,12 @@
default:
/* these are critical packets; send them via TCP */
- size=sizes[packet->type];
+ size=sizes[(int)packet->type];
if (bufptr-buf+size >= BUFSIZE) {
t=bufptr-buf;
if (gwrite(sock, buf, t) != t) {
ERROR(1,("%s: critical gwrite(TCP) failed, %s, client marked dead\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
clientDead=1;
}
bufptr=buf /*+ addSequence(buf)*/;
@@ -822,7 +844,7 @@
t = bufptr - buf; /* GCC 2.4.5 Optimizer Bug don't touch this */
if (gwrite(sock, buf, t) != t) {
ERROR(1,("%s: flush gwrite(TCP) failed, %s, client marked dead\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
clientDead=1;
}
bufptr=buf /*+ addSequence(buf)*/;
@@ -851,7 +873,7 @@
t=udpbufptr-udpbuf;
if (gwrite(udpSock, udpbuf, t) != t){
ERROR(1,("%s: flush gwrite(UDP) failed, %s, client marked dead\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
#ifdef EXTRA_GB
clientDead=1;
#endif
@@ -959,7 +981,7 @@
if (0 > recvfrom(asock, buf, BUFSIZ*2, MSG_PEEK,
(struct sockaddr *)&moo, &s)) {
ERROR(1,("%s: portswap recvfrom() failed, %s\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
}
else {
UDPDIAG(("client port is really %d\n", ntohs(moo.sin_port)));
@@ -967,7 +989,7 @@
portswapflags &= ~4;
if (0 > connect(asock, (struct sockaddr *)&moo, sizeof(moo))) {
ERROR(1,("%s: portswap connect() failed, %s\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
}
}
}
@@ -985,7 +1007,7 @@
#ifdef DEBUG
/* (this happens when the client hits 'Q') */
ERROR(1,("%s: read() failed, %s\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
#endif
if (asock == udpSock) {
if (errno == ECONNREFUSED) {
@@ -997,7 +1019,7 @@
addr.sin_family = AF_INET;
if (connect(udpSock, &addr, sizeof(addr)) < 0) {
ERROR(1,("%s: hiccup connect() failed, %s\n",
- me->p_mapchars, strerror(errno)));
+ whoami(), strerror(errno)));
UDPDIAG(("Unable to reconnect\n"));
/* and fall through to disconnect */
} else {
@@ -1020,12 +1042,12 @@
}
bufptr=buf;
while (bufptr < buf+count) {
- if (*bufptr < 1 || *bufptr > NUM_PACKETS || handlers[*bufptr].size==0) {
+ if (*bufptr < 1 || *bufptr > NUM_PACKETS || handlers[(int)*bufptr].size==0) {
ERROR(1,("%s: unknown packet type: %d, aborting...\n",
- me->p_mapchars, *bufptr));
+ whoami(), *bufptr));
return (0);
}
- size=handlers[*bufptr].size;
+ size=handlers[(int)*bufptr].size;
if(size == -1){ /* variable packet */
switch(*bufptr){
case CP_S_MESSAGE:
@@ -1072,12 +1094,12 @@
* The code is a little ugly, but it isn't too bad to worry about
* yet.
*/
- packetsReceived[*bufptr]++;
+ packetsReceived[(int)*bufptr]++;
#ifdef PING
if(asock == udpSock)
packets_received ++;
#endif
- if (handlers[*bufptr].handler != NULL) {
+ if (handlers[(int)*bufptr].handler != NULL) {
if (((FD_ISSET(*bufptr, &inputMask)) &&
(me==NULL || !(me->p_flags & (PFWAR|PFREFITTING
#ifdef SB_TRANSWARP
@@ -1109,7 +1131,7 @@
me->p_flags &= ~PFSELFDEST;
new_warning(85,"Self Destruct has been canceled");
}
- (*(handlers[*bufptr].handler))(bufptr);
+ (*(handlers[(int)*bufptr].handler))(bufptr);
}
/* Otherwise we ignore the request */
} else {
@@ -1675,8 +1697,8 @@
}
if (fd == udpSock) {
/* do we want Hiccup code here? */
- UDPDIAG(("Tried to write %d, 0x%x, %d (error %d)\n",
- fd, wbuf, bytes, errno));
+ UDPDIAG(("write() failed, fd=%d, bytes=%d, errno=%d\n",
+ fd, bytes, errno));
printUdpInfo();
logmessage("UDP gwrite failed:");
}
@@ -1864,11 +1886,11 @@
MCOPY(testdata, mysp.data, RESERVED_SIZE);
serverName[0] = '\0';
if (gethostname(serverName, 64))
- ERROR(1,( "%s: gethostname() failed\n", me->p_mapchars,
+ ERROR(1,( "%s: gethostname() failed\n", whoami(),
strerror(errno)));
encryptReservedPacket(&mysp, &mycp, serverName, me->p_no);
if (MCMP(packet->resp, mycp.resp, RESERVED_SIZE) != 0) {
- ERROR(3, ("%s: user verified incorrectly.\n", me->p_mapchars));
+ ERROR(3, ("%s: user verified incorrectly.\n", whoami()));
testtime=1;
return;
}
@@ -1891,11 +1913,11 @@
serverName[0] = '\0';
if (gethostname(serverName, 64))
- ERROR(1,( "%s: gethostname() failed\n", me->p_mapchars,
+ ERROR(1,( "%s: gethostname() failed\n", whoami(),
strerror(errno)));
if (decryptRSAPacket(&mysp, packet, serverName))
{
- ERROR(3,("%s: user verified incorrectly.\n", me->p_mapchars));
+ ERROR(3,("%s: user verified incorrectly.\n", whoami()));
testtime=1;
return;
}
@@ -1919,11 +1941,11 @@
MCOPY(testdata, mysp.data, 16);
serverName[0] = '\0';
if (gethostname(serverName, 64))
- ERROR(1,( "%s: gethostname() failed\n", me->p_mapchars,
+ ERROR(1,( "%s: gethostname() failed, %s\n", whoami(),
strerror(errno)));
encryptReservedPacket(&mysp, &mycp, serverName, me->p_no);
if (MCMP(packet->resp, mycp.resp, 16) != 0) {
- ERROR(3,("%s: user verified incorrectly.\n", me->p_mapchars));
+ ERROR(3,("%s: user verified incorrectly.\n", whoami()));
testtime=1;
return;
}
@@ -2551,11 +2573,13 @@
return;
}
+#ifdef notdef
if (fatp->packet != (PTR) packet) {
ERROR(1,( "Fat error: fatp->packet=0x%.8lx, packet=0x%.8lx\n",
fatp->packet, packet));
return;
}
+#endif
/* step 2 : move this dude to temporary list 0 */
dequeue(fatp);
@@ -3061,7 +3085,7 @@
void forceShutdown(int s)
{
SIGNAL (SIGALRM, SIG_IGN);
- ERROR(1,("%s: shutdown on signal %d\n", me->p_mapchars, s));
+ ERROR(1,("%s: shutdown on signal %d\n", whoami(), s));
shutdown (sock, 2);
close (sock);
if (udpSock >= 0)