https://github.com/libsdl-org/Maelstrom/commit/22c5004b5260978d245123394fcb6b52d6888803
From 22c5004b5260978d245123394fcb6b52d6888803 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 30 Oct 2011 11:40:37 -0400
Subject: [PATCH] Removed the network server, we're going to focus on LAN play.
---
Maelstrom-netd.c | 402 -------------------------------------------
Makefile.am | 2 +-
Makefile.in | 37 +---
netlogic/logic.cpp | 14 --
netlogic/netplay.cpp | 244 ++------------------------
netlogic/netplay.h | 1 -
6 files changed, 27 insertions(+), 673 deletions(-)
delete mode 100644 Maelstrom-netd.c
diff --git a/Maelstrom-netd.c b/Maelstrom-netd.c
deleted file mode 100644
index dc87ab64..00000000
--- a/Maelstrom-netd.c
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- Maelstrom: Open Source version of the classic game by Ambrosia Software
- Copyright (C) 1997-2011 Sam Lantinga
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-
-
-/* Here we go... */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-
-/* We wait in a loop for players to connect and tell us how many people
- are playing. Then, once all players have connected, then we broadcast
- the addresses of all players, and then start again.
-
- Note: We rely on our MAX_PLAYERS and the client's MAX_PLAYERS being
- the same. Otherwise we crash.
-*/
-
-#include "netlogic/protocol.h"
-
-#define MAX_CONNECTIONS 64
-#define UNCONNECTED 0
-#define CONNECTED 1
-#define ACTIVE 2
-#define TIMEOUT 300 /* timeout in seconds */
-
-typedef struct {
- int state;
- int sockfd;
- time_t timestamp;
- int player;
- int numplayers;
- unsigned char *packet;
- int packetlen;
- struct sockaddr_in raddr;
- } connection;
-
-connection players[MAX_CONNECTIONS];
-
-/* This function disconnects a player */
-void DisconnectPlayer(int which)
-{
- if ( players[which].state == ACTIVE )
- (void) free(players[which].packet);
- close(players[which].sockfd);
- players[which].state = UNCONNECTED;
-printf("Player on slot %d has been disconnected.\n", which);
-}
-
-void SendError(int which, const char *message)
-{
- unsigned char mesgbuf[BUFSIZ];
- int mesglen;
-
- mesglen = (2+strlen(message)+1);
- if ( mesglen > BUFSIZ ) {
- fprintf(stderr, "Fatal error: error message too long!\n");
- exit(3);
- }
- mesgbuf[0] = mesglen;
- mesgbuf[1] = NET_ABORT;
- strcpy((char *)&mesgbuf[2], message);
-printf("Sending error '%s' to player in slot %d\n", message, which);
- (void) write(players[which].sockfd, mesgbuf, mesglen);
-
- DisconnectPlayer(which);
-}
-
-/* Uh oh, a fatal error. Tell all currently connected players, and exit. */
-void Fatal(const char *message)
-{
- int i;
-
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state != UNCONNECTED )
- SendError(i, message);
- }
- exit(3);
-}
-
-/* This function checks for player timeouts */
-void CheckPlayers(void)
-{
- int i;
- time_t now;
-
- now = time(NULL);
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state != CONNECTED )
- continue;
- if ( (now-players[i].timestamp) > TIMEOUT ) {
- SendError(i, "Server timed out waiting for packet");
- }
- }
-}
-
-/* This is the function that makes the server go 'round. :) */
-/* We check to see if all advertised players have connected, and
- if so we blast everyone's address to each player.
-*/
-void CheckNewGame(void)
-{
- unsigned char buffer[BUFSIZ];
- int first, i;
- int numplayers, players_on;
- int positions[MAX_PLAYERS];
-
- /* Find the first player */
- for ( i=0, first=(-1); i<MAX_CONNECTIONS; ++i ) {
- if ( (players[i].state == ACTIVE) && (players[i].player == 0) )
- break;
- }
- if ( i == MAX_CONNECTIONS ) /* No first player... */
- return;
-
- /* Now make sure everyone else agrees with the first player */
- first = i;
- numplayers = players[first].numplayers;
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state != ACTIVE )
- continue;
- if ( players[i].numplayers != numplayers ) {
- char message[BUFSIZ];
- sprintf(message,
- "There are %d, not %d players in this game",
- numplayers, players[i].numplayers);
- SendError(i, (char*)buffer);
- }
- }
-
- /* Now see if there are enough players! */
- for ( i=0, players_on=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state == ACTIVE ) {
- positions[players[i].player] = i;
- ++players_on;
- }
- }
- /* We've rejected all duplicate players, and extra players,
- so players_on shouldn't be greater than numplayers.
- */
- if ( players_on == numplayers ) { /* Let's party!! */
- char *ptr;
- int len;
-
-printf("Let's party!!\n");
- len = (2+players[first].packetlen);
- buffer[1] = NEW_GAME;
- memcpy(&buffer[2], players[first].packet,
- players[first].packetlen);
- ptr = (char *)&buffer[len];
- for ( i=0; i<numplayers; ++i ) {
- connection *player = &players[positions[i]];
-
- strcpy(ptr, inet_ntoa(player->raddr.sin_addr));
-printf("Setting up player %d at host %s and port ", i+1, ptr);
- len += strlen(ptr)+1;
- ptr += strlen(ptr)+1;
- sprintf(ptr, "%d", ntohs(player->raddr.sin_port));
-printf("%s\n", ptr);
- len += strlen(ptr)+1;
- ptr += strlen(ptr)+1;
- }
- buffer[0] = len;
-
- for ( i=0; i<numplayers; ++i ) {
- (void) write(players[positions[i]].sockfd, buffer, len);
- DisconnectPlayer(positions[i]);
- }
- }
-}
-
-void I_Crashed(int sig)
-{
- if ( sig == SIGSEGV )
- Fatal("Server crashed!");
- else
- Fatal("Server shut down!");
- exit(sig);
-}
-
-int main(int argc, char *argv[])
-{
- int netfd, i, slot;
- struct sockaddr_in serv_addr;
-
- /******************************************************
- *
- * Phase 1: Initialization
- *
- ******************************************************/
-
- /* Create a socket */
- if ( (netfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
- perror("Can't open stream socket");
- exit(3);
- }
- /* Bind it to our address */
- memset(&serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(NETPLAY_PORT-1);
- if (bind(netfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
- perror("Can't bind local address");
- exit(3);
- }
- if ( listen(netfd, MAX_PLAYERS) < 0 ) {
- perror("listen() failed");
- exit(3);
- }
-
- /* Initialize player structures */
- for ( i=0; i<MAX_CONNECTIONS; ++i )
- players[i].state = UNCONNECTED;
-
- signal(SIGINT, I_Crashed);
- signal(SIGSEGV, I_Crashed);
-
-
- /******************************************************
- *
- * Phase 2: Wait for all players
- *
- ******************************************************/
-printf("Waiting for players...\n");
- for ( ; ; ) {
- fd_set fdset;
- struct timeval tv;
- int maxfd = 0;
-
- FD_ZERO(&fdset);
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state != UNCONNECTED ) {
- if ( maxfd < players[i].sockfd )
- maxfd = players[i].sockfd;
- FD_SET(players[i].sockfd, &fdset);
- }
- }
- if ( maxfd < netfd )
- maxfd = netfd;
- FD_SET(netfd, &fdset);
-
- tv.tv_sec = 60;
- tv.tv_usec = 0;
- if ( select(maxfd+1, &fdset, NULL, NULL, &tv) <= 0 ) {
- if ( errno != 0 ) {
- perror("select() error");
- exit(3);
- }
- CheckPlayers();
- continue;
- }
-
- /* Check for new players first */
- if ( FD_ISSET(netfd, &fdset) ) {
- int sockfd;
- socklen_t clilen;
-
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state == UNCONNECTED )
- break;
- }
- if ( i == MAX_CONNECTIONS ) {
- fprintf(stderr, "Out of connections!!\n");
- exit(3);
- }
- slot = i;
-
- clilen = sizeof(players[slot].raddr);
- if ( (sockfd=accept(netfd, (struct sockaddr *)
- &players[slot].raddr, &clilen)) < 0 ) {
- perror("accept() error");
- exit(3);
- }
- players[slot].timestamp = time(NULL);
- players[slot].sockfd = sockfd;
- players[slot].state = CONNECTED;
-printf("Connection received on port %d\n", i);
-
- /* We continue so that we can get all players quickly */
- continue;
- }
-
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- unsigned char data[BUFSIZ];
- unsigned long cliport;
- int len, player;
- int numplayers;
-
- if ( (players[i].state == UNCONNECTED) ||
- ! FD_ISSET(players[i].sockfd, &fdset) )
- continue;
-
- /* A player with active data! */
- slot = i;
- if ( (len=read(players[slot].sockfd, data, BUFSIZ))
- <= 0 ) {
- /* Wierd. Close connection */
- DisconnectPlayer(slot);
- continue;
- }
-
- /* Are they cancelling a connection? */
- if ( data[0] == NET_ABORT ) {
- DisconnectPlayer(slot);
- continue;
- }
-
- if ( data[0] != NEW_GAME ) {
- fprintf(stderr,
- "Unknown client packet: 0x%.2x\n",
- data[0]);
- DisconnectPlayer(slot);
- continue;
- }
-
- if ( len != NEW_PACKETLEN+4+1 ) {
- fprintf(stderr,
- "Short client packet! (len was %d, expected %d)\n",
- len, NEW_PACKETLEN+4+1);
- SendError(slot, "Server received short packet");
- continue;
- }
-
-
- /* Yay! Active connection! */
- player = data[1];
- /* Be wary, client sizeof(unsigned long) and our
- sizeof(unsigned long) may differ. We assume
- sizeof(unsigned long) is 4.
- */
- memcpy(&cliport, &data[NEW_PACKETLEN], sizeof(cliport));
- numplayers = data[NEW_PACKETLEN+4];
- for ( i=0; i<MAX_CONNECTIONS; ++i ) {
- if ( players[i].state == ACTIVE ) {
- if ( player == players[i].player )
- break;
- }
- }
- /* Is there already player N? */
- if ( i != MAX_CONNECTIONS ) {
- char message[BUFSIZ];
-
- sprintf(message, "Player %d is already on!",
- player+1);
- SendError(slot, message);
- continue;
- }
-
- /* Set the player up */
- players[slot].state = ACTIVE;
- players[slot].player = player;
- players[slot].numplayers = numplayers;
- players[slot].packetlen = len-(2+4+1);
- if ( (players[slot].packet = (unsigned char *)
- malloc(players[slot].packetlen)) == NULL) {
- perror("Out of memory");
- Fatal("Server ran out of memory");
- }
- memcpy(players[slot].packet, &data[2],
- players[slot].packetlen);
- /* This is important! */
- players[slot].raddr.sin_port =
- htons((short)ntohl(cliport));
-printf("Player %d arrived on port %d\n", player+1, slot);
-printf(" the remote address is %s:%u\n",
- inet_ntoa(players[slot].raddr.sin_addr),
- ntohs(players[slot].raddr.sin_port));
- }
- CheckNewGame();
- CheckPlayers();
- }
- /* Never reached */
-}
-
diff --git a/Makefile.am b/Makefile.am
index ca10aa3d..fac58578 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
-bin_PROGRAMS = Maelstrom Maelstrom-netd
+bin_PROGRAMS = Maelstrom
Maelstrom_SOURCES = \
Maelstrom.h \
diff --git a/Makefile.in b/Makefile.in
index 3300230c..87042e1f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -33,7 +33,7 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
-bin_PROGRAMS = Maelstrom$(EXEEXT) Maelstrom-netd$(EXEEXT)
+bin_PROGRAMS = Maelstrom$(EXEEXT)
subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Maelstrom.spec.in \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
@@ -62,23 +62,20 @@ am_Maelstrom_OBJECTS = MaelstromUI.$(OBJEXT) controls.$(OBJEXT) \
Maelstrom_OBJECTS = $(am_Maelstrom_OBJECTS)
Maelstrom_DEPENDENCIES = $(LOGIC)/liblogic.a screenlib/libSDLscreen.a \
maclib/libSDLmac.a utils/libutils.a
-Maelstrom_netd_SOURCES = Maelstrom-netd.c
-Maelstrom_netd_OBJECTS = Maelstrom-netd.$(OBJEXT)
-Maelstrom_netd_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
- $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
-o $@
-SOURCES = $(Maelstrom_SOURCES) Maelstrom-netd.c
-DIST_SOURCES = $(Maelstrom_SOURCES) Maelstrom-netd.c
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(Maelstrom_SOURCES)
+DIST_SOURCES = $(Maelstrom_SOURCES)
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
html-recursive info-recursive install-data-recursive \
install-dvi-recursive install-exec-recursive \
@@ -282,7 +279,7 @@ DIST_SUBDIRS = $(SUBDIRS)
all: all-recursive
.SUFFIXES:
-.SUFFIXES: .c .cpp .o .obj
+.SUFFIXES: .cpp .o .obj
am--refresh:
@:
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@@ -344,9 +341,6 @@ clean-binPROGRAMS:
Maelstrom$(EXEEXT): $(Maelstrom_OBJECTS) $(Maelstrom_DEPENDENCIES)
@rm -f Maelstrom$(EXEEXT)
$(CXXLINK) $(Maelstrom_OBJECTS) $(Maelstrom_LDADD) $(LIBS)
-Maelstrom-netd$(EXEEXT): $(Maelstrom_netd_OBJECTS) $(Maelstrom_netd_DEPENDENCIES)
- @rm -f Maelstrom-netd$(EXEEXT)
- $(LINK) $(Maelstrom_netd_OBJECTS) $(Maelstrom_netd_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -360,7 +354,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MacDialogEditbox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MacDialogLabel.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MacDialogRadioButton.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Maelstrom-netd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MaelstromUI.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UIElementIcon.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UIElementKeyButton.Po@am__quote@
@@ -375,20 +368,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rect.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scores.Po@am__quote@
-.c.o:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c $<
-
-.c.obj:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
-
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
diff --git a/netlogic/logic.cpp b/netlogic/logic.cpp
index fbd6382c..c971e8d4 100644
--- a/netlogic/logic.cpp
+++ b/netlogic/logic.cpp
@@ -31,7 +31,6 @@ void LogicUsage(void)
{
error(
" -player N[@host][:port] # Designate player N (at host and/or port)\n"
-" -server N@host[:port] # Play with N players using server at host\n"
" -deathmatch [N] # Play deathmatch to N frags (default = 8)\n"
);
}
@@ -67,19 +66,6 @@ int LogicParseArgs(char ***argvptr, int *argcptr)
return(0);
}
- /* Check for the '-server' option */
- if ( strcmp(argv[1], "-server") == 0 ) {
- if ( ! argv[2] ) {
- error("The '-server' option requires an argument!\n");
- PrintUsage();
- }
- if ( SetServer(argv[2]) < 0 )
- exit(1);
- ++(*argvptr);
- --(*argcptr);
- return(0);
- }
-
/* Check for the '-deathmatch' option */
if ( strcmp(argv[1], "-deathmatch") == 0 ) {
if ( argv[2] && ((gDeathMatch=atoi(argv[2])) > 0) ) {
diff --git a/netlogic/netplay.cpp b/netlogic/netplay.cpp
index bbb73781..563f4364 100644
--- a/netlogic/netplay.cpp
+++ b/netlogic/netplay.cpp
@@ -40,7 +40,7 @@ UDPsocket gNetFD;
static int GotPlayer[MAX_PLAYERS];
static IPaddress PlayAddr[MAX_PLAYERS];
static IPaddress ServAddr;
-static int FoundUs, UseServer;
+static int FoundUs;
static Uint32 NextFrame;
UDPpacket *OutBound[2];
static int CurrOut;
@@ -97,7 +97,6 @@ int InitNetData(void)
FoundUs = 0;
gOurPlayer = -1;
gDeathMatch = 0;
- UseServer = 0;
for ( i=0; i<MAX_PLAYERS; ++i ) {
GotPlayer[i] = 0;
SyncPtrs[0][i] = NULL;
@@ -176,47 +175,6 @@ int AddPlayer(const char *playerstr)
return(0);
}
-int SetServer(char *serverstr)
-{
- int portnum;
- char *host=NULL, *port=NULL;
-
- /* Extract host and port information */
- if ( (host=strchr(serverstr, '@')) == NULL ) {
- error(
- "Server host must be specified in the -server option.\r\n");
- PrintUsage();
- } else
- *(host++) = '\0';
- if ( (port=strchr(serverstr, ':')) != NULL )
- *(port++) = '\0';
-
- /* We should know how many players we have now */
- if (((gNumPlayers = atoi(serverstr)) <= 0) ||
- (gNumPlayers > MAX_PLAYERS)) {
- error(
-"The number of players must be an integer between 1 and %d inclusive.\r\n",
- MAX_PLAYERS);
- PrintUsage();
- }
-
- /* Resolve the remote address */
- if ( port ) {
- portnum = atoi(port);
- } else {
- portnum = NETPLAY_PORT-1;
- }
- SDLNet_ResolveHost(&ServAddr, host, portnum);
- if ( ServAddr.host == INADDR_NONE ) {
- error("Couldn't resolve host name for %s\r\n", host);
- return(-1);
- }
-
- /* We're done! */
- UseServer = 1;
- return(0);
-}
-
/* This MUST be called after command line options have been processed. */
int CheckPlayers(void)
{
@@ -224,23 +182,21 @@ int CheckPlayers(void)
int port;
/* Check to make sure we have all the players */
- if ( ! UseServer ) {
- for ( i=0, gNumPlayers=0; i<MAX_PLAYERS; ++i ) {
- if ( GotPlayer[i] )
- ++gNumPlayers;
- }
- /* Add ourselves if needed */
- if ( gNumPlayers == 0 ) {
- AddPlayer("1");
- gNumPlayers = 1;
- FoundUs = 1;
- }
- for ( i=0; i<gNumPlayers; ++i ) {
- if ( ! GotPlayer[i] ) {
- error(
+ for ( i=0, gNumPlayers=0; i<MAX_PLAYERS; ++i ) {
+ if ( GotPlayer[i] )
+ ++gNumPlayers;
+ }
+ /* Add ourselves if needed */
+ if ( gNumPlayers == 0 ) {
+ AddPlayer("1");
+ gNumPlayers = 1;
+ FoundUs = 1;
+ }
+ for ( i=0; i<gNumPlayers; ++i ) {
+ if ( ! GotPlayer[i] ) {
+ error(
"Player %d not specified! Use the -player option for all players.\r\n", i+1);
- return(-1);
- }
+ return(-1);
}
}
if ( ! FoundUs ) {
@@ -278,11 +234,9 @@ int CheckPlayers(void)
}
/* Bind all of our players to the channels */
- if ( ! UseServer ) {
- for ( i=0; i<gNumPlayers; ++i ) {
- SDLNet_UDP_Bind(gNetFD, 0, &PlayAddr[i]);
- SDLNet_UDP_Bind(gNetFD, i+1, &PlayAddr[i]);
- }
+ for ( i=0; i<gNumPlayers; ++i ) {
+ SDLNet_UDP_Bind(gNetFD, 0, &PlayAddr[i]);
+ SDLNet_UDP_Bind(gNetFD, i+1, &PlayAddr[i]);
}
return(0);
}
@@ -501,160 +455,6 @@ static void ErrorMessage(const char *message)
SDL_Delay(3000);
}
-/* If we use an address server, we go here, instead of using Send_NewGame()
- and Await_NewGame()
-
- The server simply sucks up packets until it gets all player packets.
- It then does error checking, making sure all players agree about who
- they are and how many players will be in the game. Then it spits a
- packet containing all the player addresses to each player, and then
- waits for a new game...
-
- We will send a "Hi there" packet to the server and keep resending until
- either the server sends back an error packet, we get an abort signal from
- the user, or we get an addresses packet from the server.
-*/
-static int AlertServer(int *Wave, int *Lives, int *Turbo)
-{
- TCPsocket sock;
- SDLNet_SocketSet socketset;
- Uint8 netbuf[BUFSIZ], sendbuf[NEW_PACKETLEN+4+1];
- char *ptr;
- int i, len, lenread;
- Uint32 lives, seed;
- int waiting;
- int status;
- const char *message = NULL;
-
- /* Our address server connection is through TCP */
- Message("Connecting to Address Server");
- sock = SDLNet_TCP_Open(&ServAddr);
- if ( sock == NULL ) {
- ErrorMessage("Connection failed");
- return(-1);
- }
- socketset = SDLNet_AllocSocketSet(1);
- if ( socketset == NULL ) {
- status = -1;
- message = "Couldn't create socket set";
- goto done;
- }
- SDLNet_TCP_AddSocket(socketset, sock);
-
- MakeNewPacket(*Wave, *Lives, *Turbo, sendbuf);
- len = NEW_PACKETLEN;
- SDLNet_Write32(SDL_SwapBE16(PlayAddr[gOurPlayer].port), sendbuf+len);
- len += 4;
- sendbuf[len] = (Uint8)gNumPlayers;
- len += 1;
- if ( SDLNet_TCP_Send(sock, sendbuf, len) != len ) {
- status = -1;
- message = "Socket write error";
- goto done;
- }
-
- Message("Waiting for other players");
- status = 0;
- len = 0;
- lenread = 0;
- waiting = 1;
- while ( waiting ) {
- if ( SDLNet_CheckSockets(socketset, 1000) <= 0 ) {
- HandleEvents(0);
- /* Peek at key buffer for Quit key */
- for ( i=(PDATA_OFFSET+1); i<OutLen; i += 2 ) {
- if ( OutBuf[i] == ABORT_KEY ) {
- netbuf[0] = NET_ABORT;
- SDLNet_TCP_Send(sock, netbuf, 1);
- waiting = 0;
- status = -1;
- }
- }
- OutLen = PDATA_OFFSET;
- continue;
- }
-
- /* We are guaranteed that there is data here */
- len = SDLNet_TCP_Recv(sock, &netbuf[len], BUFSIZ-len-1);
- if ( len <= 0 ) {
- waiting = 0;
- status = -1;
- message = "Error reading player addresses";
- continue;
- }
- lenread += len;
-
- /* The very first byte is a packet length */
- if ( len < netbuf[0] )
- continue;
-
- if ( netbuf[0] <= 1 ) {
- waiting = 0;
- status = -1;
- message = "Error: Short server packet!";
- continue;
- }
- switch ( netbuf[1] ) {
- case NEW_GAME: /* Extract parameters, addresses */
- *Turbo = (int)netbuf[2];
- len = 3;
- *Wave = SDLNet_Read32(&netbuf[len]);
- len += 4;
- lives = SDLNet_Read32(&netbuf[len]);
- len += 4;
- if ( lives & 0x8000 )
- gDeathMatch = (lives&(~0x8000));
- else
- *Lives = lives;
- seed = SDLNet_Read32(&netbuf[len]);
- len += 4;
- SeedRandom(seed);
-//error("Seed is 0x%x\r\n", seed);
-
- ptr = (char *)&netbuf[len];
- for ( i=0; i<gNumPlayers; ++i ) {
- if ( i == gOurPlayer ) {
- /* Skip address */
- ptr += (strlen(ptr)+1);
- ptr += (strlen(ptr)+1);
- continue;
- }
-
- /* Resolve the remote address */
- char *host, *port;
- host = ptr;
- ptr += strlen(host)+1;
- port = ptr;
- ptr += strlen(port)+1;
- SDLNet_ResolveHost(&PlayAddr[i], host, atoi(port));
-//printf("Port = %s\r\n", ptr);
- }
- waiting = 0;
- break;
-
- case NET_ABORT: /* Some error? */
- netbuf[len] = '\0';
- message = (char *)&netbuf[2];
- waiting = 0;
- status = -1;
- break;
-
- default: /* Huh? */
- break;
- }
- }
- for ( i=0; i<gNumPlayers; ++i ) {
- SDLNet_UDP_Bind(gNetFD, 0, &PlayAddr[i]);
- SDLNet_UDP_Bind(gNetFD, i+1, &PlayAddr[i]);
- }
- NextFrame = 0L;
-done:
- if ( (status < 0) && message ) {
- ErrorMessage(message);
- }
- return(status);
-}
-
/* This function sends a NEWGAME packet, and waits for all other players
to respond in kind.
This function is not very robust in handling errors such as multiple
@@ -670,10 +470,6 @@ int Send_NewGame(int *Wave, int *Lives, int *Turbo)
int i;
UDPpacket newgame, sent;
- /* Don't do the usual rigamarole if we have a game server */
- if ( UseServer )
- return(AlertServer(Wave, Lives, Turbo));
-
/* Send all the packets */
MakeNewPacket(*Wave, *Lives, *Turbo, sendbuf);
newgame.data = sendbuf;
@@ -771,10 +567,6 @@ int Await_NewGame(int *Wave, int *Lives, int *Turbo)
UDPpacket sent;
Uint32 lives, seed;
- /* Don't do the usual rigamarole if we have a game server */
- if ( UseServer )
- return(AlertServer(Wave, Lives, Turbo));
-
/* Get ready to wait for server */
Message("Awaiting Player 1 (server)");
sent.data = netbuf;
diff --git a/netlogic/netplay.h b/netlogic/netplay.h
index 689e65b1..0855738c 100644
--- a/netlogic/netplay.h
+++ b/netlogic/netplay.h
@@ -24,7 +24,6 @@
extern int InitNetData(void);
extern void HaltNetData(void);
extern int AddPlayer(const char *playerstr);
-extern int SetServer(char *serverstr);
extern int CheckPlayers(void);
extern void QueueKey(unsigned char Op, unsigned char Type);
extern int SyncNetwork(void);