Changes:
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 19 Jun 2014 18:22:03 +0000 (18:22 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 19 Jun 2014 18:22:03 +0000 (18:22 +0000)
- Some GCC 4 related fixes
- Drop usage of mmstring, which needs some source changes for x86_64

I noticed that some more work would at least be needed:
- Client should notify the user when it connects, authenticates,
  and report errors graphically rather than using only fprintf(3).
- There appears to be occasional authentication synchronization issues
  and possibly other network synchronization issues during the session.
  The a connection might need to be retried to succeed, and an established
  working session may suddenly end with a client read error.  The exact
  reasons have not been investigated yet.

13 files changed:
mmsoftware/mystic_ships/client/GNUmakefile
mmsoftware/mystic_ships/client/src/conf.h
mmsoftware/mystic_ships/client/src/recvq.c
mmsoftware/mystic_ships/client/src/thread_msg.c
mmsoftware/mystic_ships/common/packets_common.h
mmsoftware/mystic_ships/server/GNUmakefile
mmsoftware/mystic_ships/server/src/client.c
mmsoftware/mystic_ships/server/src/daemon.c
mmsoftware/mystic_ships/server/src/kqueue.c
mmsoftware/mystic_ships/server/src/net.c
mmsoftware/mystic_ships/server/src/packets.c
mmsoftware/mystic_ships/server/src/recvq.c
mmsoftware/mystic_ships/server/src/sendq.c

index a681414..c393a36 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.1 2006/12/31 08:32:39 mmondor Exp $
+# $Id: GNUmakefile,v 1.2 2014/06/19 18:22:03 mmondor Exp $
 
 CC := cc
 RM := rm
@@ -68,7 +68,8 @@ OBJTARGET := $(shell $(TOUCH) $(TMPDIR)/obj.c && \
        $(OBJDUMP) -t $(TMPDIR)/obj.o | \
        $(GREP) 'file format' | $(AWK) '{print $$4}' \
        && $(RM) $(TMPDIR)/obj.o $(TMPDIR)/obj.c)
-OBJARCH := $(shell echo $(OBJTARGET) | $(AWK) -F '-' '{print $$2}')
+#OBJARCH := $(shell echo $(OBJTARGET) | $(AWK) -F '-' '{print $$2}')
+OBJARCH := i386
 SEED := $(shell date +%s)
 
 # Architecture independent settings follow
index 4cb04d8..7f471cb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: conf.h,v 1.1 2006/12/31 08:32:39 mmondor Exp $ */
+/* $Id: conf.h,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -14,7 +14,7 @@
  * Various hardcoded configuration parameters.
  */
 
-#define SERVER_HOST    "hal.xisop"
+#define SERVER_HOST    "192.168.1.15"
 /*#define SERVER_HOST  "tms-play.pulsar-zone.net"*/
 
 #define SERVER_PORT    7777
index 3596f2f..bb15078 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: recvq.c,v 1.1 2006/12/31 08:32:39 mmondor Exp $ */
+/* $Id: recvq.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -110,8 +110,12 @@ recvq_read(recvq_t *q)
         * packets.
         */
        if ((s = SDLNet_TCP_Recv(q->sock, rbuffer, RBUFFER_SIZE)) == -1 ||
-           s == 0)
+           s == 0) {
+               (void) fprintf(stderr,
+                   "SDLNet_TCP_Recv() == %d - %d - %s\n",
+                   s, errno, SDLNet_GetError());
                return -1;
+       }
 
 #ifdef USE_ENCRYPTION
        /* Decrypt incomming data */
@@ -126,8 +130,11 @@ recvq_read(recvq_t *q)
        q->zin.next_out = (Bytef *)ibuffer;
        q->zin.avail_out = IBUFFER_SIZE;
        if ((ret = inflate(&q->zin, Z_SYNC_FLUSH)) != Z_OK &&
-           ret != Z_STREAM_END)
+           ret != Z_STREAM_END) {
+               (void) fprintf(stderr,
+                   "inflate() error\n");
                return -1;
+       }
        buf = (int8_t *)ibuffer;
        s = IBUFFER_SIZE - q->zin.avail_out;
 #else
index 3fdd4dd..f98b3b5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: thread_msg.c,v 1.2 2007/12/29 19:13:37 mmondor Exp $ */
+/* $Id: thread_msg.c,v 1.3 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (C) 2006, Matthew Mondor
@@ -426,6 +426,7 @@ thread_amsg_setcallback(thread_amsg_t *msg,
 {
 
        ASSERT(msg != NULL);
+
        msg->callback = callback;
        msg->callback_arg = callback_arg;
 }
index 421e9d7..c92b5ca 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets_common.h,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: packets_common.h,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -124,7 +124,7 @@ struct svpacket_message {
  * Client to server packets
  */
 
-enum cpacket_tyoes {
+enum cpacket_types {
        CPACKET_AUTH = 0,
        CPACKET_PING,
        CPACKET_PONG,
index 4a91bac..0370962 100644 (file)
@@ -1,8 +1,8 @@
-# $Id: GNUmakefile,v 1.1 2006/12/31 08:32:40 mmondor Exp $
+# $Id: GNUmakefile,v 1.2 2014/06/19 18:22:03 mmondor Exp $
 
-MMLIB_PATH := ../../../mmlib
+MMLIB_PATH := ../../mmlib
 
-MMLIBS := $(addprefix $(MMLIB_PATH)/,mmpool.o mmstring.o mmarch.o)
+MMLIBS := $(addprefix $(MMLIB_PATH)/,mmpool.o mmarch.o)
 LIBS := -lc -lm -lz
 OBJS := $(addprefix src/,main.o trigonometry.o net.o kqueue.o sendq.o recvq.o \
        packets.o daemon.o client.o ships.o torp.o enc.o) \
index 092568b..b8f0c06 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.2 2007/12/05 23:47:57 mmondor Exp $ */
+/* $Id: client.c,v 1.3 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -73,8 +73,8 @@ client_write(client_t *c, uint8_t *buf, size_t size, int buffer)
 
        if (sendq_write(&c->sendq, buf, size, client_enable_write_polling, c,
            buffer) == -1) {
-               syslog(LOG_NOTICE, "sendq_write(%u) - %s", size,
-                   strerror(errno));
+               syslog(LOG_NOTICE, "sendq_write(%u) - %s",
+                   (unsigned int)size, strerror(errno));
                return -1;
        }
 
@@ -175,7 +175,7 @@ client_timeout(void)
         * We can safely use DLIST_FOREACH() since client_destroy_mark()
         * doesn't yet destroy the node, and we're single-threaded.
         */
-       DLIST_FOREACH(&clients_list, (client_t *)c) {
+       DLIST_FOREACH(&clients_list, c) {
                if (current_time - c->created >= TIMEOUT_SECONDS &&
                    c->recvq.recvpackets == 0)
                        client_destroy_mark(c);
index 7756b62..0d46461 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: daemon.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: daemon.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -20,8 +20,6 @@
 #include <syslog.h>
 #include <unistd.h>
 
-#include <mmstring.h>
-
 #include <conf.h>
 
 
@@ -81,7 +79,7 @@ pidfile_write(const char *file)
 
        if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600)) != -1) {
                (void) snprintf(str, 15, "%d\n", getpid());
-               (void) write(fd, str, mm_strlen(str));
+               (void) write(fd, str, strlen(str));
                (void) close(fd);
        } else  
                syslog(LOG_NOTICE, "pidfile_write() - open(%s) - %s",
index e783cc8..deec56c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: kqueue.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: kqueue.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -87,8 +87,8 @@ kqueue_addtimer(int id, int64_t ms)
        EV_SET(sev, id, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, ms,
            (intptr_t)NULL); 
        if (kevent(kqid, sev, 1, NULL, 0, NULL) == -1) {
-               syslog(LOG_NOTICE, "kevent_addtimer(%d) - kevent(%lld) - %s",
-                   id, ms, strerror(errno));
+               syslog(LOG_NOTICE, "kevent_addtimer(%d) - kevent(%" PRId64
+                   ") - %s", id, ms, strerror(errno));
                exit(EXIT_FAILURE);
        }
 }
@@ -121,8 +121,9 @@ kqueue_main(void)
                        /* Report errors if any */
                        if ((kev->flags & EV_ERROR) != 0) {
                                syslog(LOG_NOTICE,
-                                   "EV_ERROR: ident=%d filter=%d flags=%d "
-                                   "fflags=%d data=%lld udata=%p",
+                                   "EV_ERROR: ident=%" PRIuPTR " filter=%"
+                                   PRIu32 " flags=%" PRIu32 " fflags=%"
+                                   PRIu32 " data=%" PRId64 " udata=%p",
                                    kev->ident, kev->filter, kev->flags,
                                    kev->fflags, kev->data,
                                    (void *)kev->udata);
index 6206c2e..c01348c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: net.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: net.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -21,8 +21,6 @@
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 
-#include <mmstring.h>
-
 #include <net.h>
 #include <conf.h>
 
@@ -56,7 +54,7 @@ net_listen(const char *addr, int port, int backlog)
 
        fd = -1;
 
-       mm_memclr(&server, sizeof(struct sockaddr_in));
+       memset(&server, 0, sizeof(struct sockaddr_in));
        server.sin_family = AF_INET;
        if (inet_pton(AF_INET, addr, &server.sin_addr) != 1) {
                syslog(LOG_NOTICE, "inet_pton(%s) - %s", addr,
index 2168a78..b25d696 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: packets.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: packets.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -26,8 +26,8 @@
 #include <syslog.h>
 #include <string.h>
 
-#include <mmstring.h>
 #include <mmarch.h>
+#include <mmlist.h>
 #include <mmlog.h>
 
 #include <packets_common.h>
@@ -165,7 +165,7 @@ k:
        torps_update();
 
        /* XXX Send all ships and all torps to all clients for now */
-       DLIST_FOREACH(&clients_list, (node_t *)c) {
+       DLIST_FOREACH(&clients_list, c) {
                client_t        *c2;
                torp_t          *t;
 
@@ -189,7 +189,7 @@ k:
                                c->slowcnt = c->slowlevel;
                }
 
-               DLIST_FOREACH(&clients_list, (node_t *)c2) {
+               DLIST_FOREACH(&clients_list, c2) {
 
                        if (!c2->authenticated)
                                continue;
@@ -201,7 +201,7 @@ k:
                        }
                }
 
-               DLIST_FOREACH(&torps_list, (node_t *)t) {
+               DLIST_FOREACH(&torps_list, t) {
                        if (spacket_torp_send(c, t) == -1)
                                break;
                }
@@ -342,7 +342,7 @@ cpacket_auth_handler(client_t *c, uint16_t *ptr)
         */
        validuser = 0;
        (void) memset(plogin, '\0', 16);
-       (void) strncpy(plogin, SERVER_LOGIN, 15);
+       (void) strncpy((char *)plogin, SERVER_LOGIN, 15);
        if (memcmp(p->login, plogin, 16) == 0)
                validuser = 1;
        else
@@ -357,7 +357,7 @@ cpacket_auth_handler(client_t *c, uint16_t *ptr)
         */
        /* XXX If !validuser we should use a dummy password */
        (void) memset(ppasswd, '\0', 32);
-       (void) strncpy(ppasswd, SERVER_PASSWD, 31);
+       (void) strncpy((char *)ppasswd, SERVER_PASSWD, 31);
 
        hmac_sha1((uint8_t *)c->noncerand1, 32, ppasswd, 32, hmac1);
        hmac_rmd160((uint8_t *)c->noncerand1, 32, ppasswd, 32, &hmac1[20]);
index 6cd296d..72f9489 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: recvq.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: recvq.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -14,8 +14,6 @@
 #include <string.h>
 #include <syslog.h>
 
-#include <mmstring.h>
-
 #include <recvq.h>
 #include <conf.h>
 
@@ -39,9 +37,9 @@
 
 
 
-static int8_t  rbuffer[RBUFFER_SIZE];
+static uint8_t         rbuffer[RBUFFER_SIZE];
 #ifdef USE_COMPRESSION
-static char    ibuffer[IBUFFER_SIZE];
+static unsigned char   ibuffer[IBUFFER_SIZE];
 #endif
 
 
@@ -125,7 +123,7 @@ int
 recvq_read(recvq_t *q)
 {
        ssize_t         s;
-       int8_t          *ptr, *tptr, *buf;
+       uint8_t         *ptr, *tptr, *buf;
        client_t        *c = (client_t *)q->client;
 
        /*
@@ -268,7 +266,7 @@ complete:
                                        syslog(LOG_NOTICE,
                                            "recvq_read(%d) - "
                                            "Invalid packet size %d",
-                                           q->fd, q->length);
+                                           q->fd, (int)q->length);
                                        q->variable = -1;
                                        q->length = -1;
                                        return -1;
@@ -349,7 +347,7 @@ recvq_content_reset(recvq_t *q)
                register size_t s;
 
                s = q->tail - q->ptail;
-               (void) mm_memcpy(q->buffer, &q->buffer[q->ptail], s);
+               (void) memcpy(q->buffer, &q->buffer[q->ptail], s);
                q->tail = s;
        } else
                q->tail = 0;
index e2e428c..1c077b6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: sendq.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: sendq.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -17,7 +17,6 @@
 #include <unistd.h>
 
 #include <mmlist.h>
-#include <mmstring.h>
 
 #include <sendq.h>
 #include <client.h>
@@ -39,7 +38,7 @@
 
 
 #ifdef USE_COMPRESSION
-static char            dbuffer[DBUFFER_SIZE];
+static unsigned char   dbuffer[DBUFFER_SIZE];
 #endif
 
 
@@ -159,7 +158,7 @@ sendq_write(sendq_t *q, uint8_t *buf, size_t size,
                if (q->tail + size > q->size)
                        return -1;
 
-               (void) mm_memcpy(&q->buffer[q->tail], buf, size);
+               (void) memcpy(&q->buffer[q->tail], buf, size);
                q->tail += size;
                if (bfunc != NULL && buffer)
                        bfunc(bfuncarg);
@@ -217,8 +216,8 @@ sendq_zflush(sendq_t *q, void (*bfunc)(void *), void *bfuncarg)
 #endif
 
 #ifdef USE_COMPRESSION
-       char    ch;
-       size_t  size;
+       unsigned char   ch;
+       size_t          size;
 
        q->zout.next_in = &ch;
        q->zout.avail_in = 0;
@@ -237,7 +236,7 @@ sendq_zflush(sendq_t *q, void (*bfunc)(void *), void *bfuncarg)
                        mmenc_encrypt(&q->enc_out, dbuffer, size);
 #endif
 
-               (void) mm_memcpy(&q->buffer[q->tail], dbuffer, size);
+               (void) memcpy(&q->buffer[q->tail], dbuffer, size);
                q->tail += size;
                if (bfunc != NULL)
                        bfunc(bfuncarg);