summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2006-01-12 02:11:52 +0000
committerSimon Howard2006-01-12 02:11:52 +0000
commitaf6bdd73396e166417484c2efe4a0eb48aac780e (patch)
treec5c5cfac2cf4ab1716006eb4b75a1944f01ae4d2 /src
parent2cfa7c372d5eec32e2fe893cbe999d9434427395 (diff)
downloadchocolate-doom-af6bdd73396e166417484c2efe4a0eb48aac780e.tar.gz
chocolate-doom-af6bdd73396e166417484c2efe4a0eb48aac780e.tar.bz2
chocolate-doom-af6bdd73396e166417484c2efe4a0eb48aac780e.zip
Game start packets
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 284
Diffstat (limited to 'src')
-rw-r--r--src/net_client.c60
-rw-r--r--src/net_client.h6
-rw-r--r--src/net_gui.c11
-rw-r--r--src/net_server.c51
4 files changed, 124 insertions, 4 deletions
diff --git a/src/net_client.c b/src/net_client.c
index 6ff437cb..f70a7c0a 100644
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.c 279 2006-01-10 19:59:26Z fraggle $
+// $Id: net_client.c 284 2006-01-12 02:11:52Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.17 2006/01/12 02:11:52 fraggle
+// Game start packets
+//
// Revision 1.16 2006/01/10 19:59:25 fraggle
// Reliable packet transport mechanism
//
@@ -96,6 +99,7 @@
#include "net_io.h"
#include "net_packet.h"
#include "net_server.h"
+#include "net_structrw.h"
typedef enum
{
@@ -157,6 +161,29 @@ static void NET_CL_Shutdown(void)
}
}
+void NET_CL_StartGame(void)
+{
+ net_packet_t *packet;
+ net_gamesettings_t settings;
+
+ // Fill in game settings structure with appropriate parameters
+ // for the new game
+
+ settings.ticdup = 1;
+ settings.extratics = 0;
+ settings.deathmatch = deathmatch;
+ settings.episode = startepisode;
+ settings.map = startmap;
+ settings.skill = startskill;
+
+ // Send packet
+
+ packet = NET_Conn_NewReliable(&client_connection,
+ NET_PACKET_TYPE_GAMESTART);
+
+ NET_WriteSettings(packet, &settings);
+}
+
// data received while we are waiting for the game to start
static void NET_CL_ParseWaitingData(net_packet_t *packet)
@@ -211,6 +238,36 @@ static void NET_CL_ParseWaitingData(net_packet_t *packet)
}
}
+static void NET_CL_ParseGameStart(net_packet_t *packet)
+{
+ net_gamesettings_t settings;
+ unsigned int player_number, num_players;
+ int i;
+
+ if (!NET_ReadInt8(packet, &player_number)
+ || !NET_ReadInt8(packet, &num_players)
+ || !NET_ReadSettings(packet, &settings))
+ {
+ return;
+ }
+
+ consoleplayer = player_number;
+
+ for (i=0; i<MAXPLAYERS; ++i)
+ {
+ playeringame[i] = i < num_players;
+ }
+
+ client_state = CLIENT_STATE_IN_GAME;
+
+ deathmatch = settings.deathmatch;
+ ticdup = settings.ticdup;
+// extratic = settings.extratics;
+ startepisode = settings.episode;
+ startmap = settings.map;
+ startskill = settings.skill;
+}
+
// parse a received packet
static void NET_CL_ParsePacket(net_packet_t *packet)
@@ -235,6 +292,7 @@ static void NET_CL_ParsePacket(net_packet_t *packet)
break;
case NET_PACKET_TYPE_GAMESTART:
+ NET_CL_ParseGameStart(packet);
break;
case NET_PACKET_TYPE_GAMEDATA:
diff --git a/src/net_client.h b/src/net_client.h
index 80ea111d..85eb595d 100644
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.h 278 2006-01-09 02:03:39Z fraggle $
+// $Id: net_client.h 284 2006-01-12 02:11:52Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.10 2006/01/12 02:11:52 fraggle
+// Game start packets
+//
// Revision 1.9 2006/01/09 02:03:39 fraggle
// Send clients their player number, and indicate on the waiting screen
// which client we are.
@@ -74,6 +77,7 @@ boolean NET_CL_Connect(net_addr_t *addr);
void NET_CL_Disconnect(void);
void NET_CL_Run(void);
void NET_CL_Init(void);
+void NET_CL_StartGame();
void NET_Init(void);
extern boolean net_client_connected;
diff --git a/src/net_gui.c b/src/net_gui.c
index 8427554c..1ee0555f 100644
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_gui.c 280 2006-01-10 22:14:13Z fraggle $
+// $Id: net_gui.c 284 2006-01-12 02:11:52Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.8 2006/01/12 02:11:52 fraggle
+// Game start packets
+//
// Revision 1.7 2006/01/10 22:14:13 fraggle
// Shut up compiler warnings
//
@@ -183,6 +186,12 @@ static void ProcessEvents(void)
RandomMusic();
}
+ else if (ev->type == ev_keydown && ev->data1 == ' ')
+ {
+ // Start game
+
+ NET_CL_StartGame();
+ }
}
}
diff --git a/src/net_server.c b/src/net_server.c
index 0fb058a0..89912028 100644
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_server.c 279 2006-01-10 19:59:26Z fraggle $
+// $Id: net_server.c 284 2006-01-12 02:11:52Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.20 2006/01/12 02:11:52 fraggle
+// Game start packets
+//
// Revision 1.19 2006/01/10 19:59:26 fraggle
// Reliable packet transport mechanism
//
@@ -110,6 +113,7 @@
#include "net_packet.h"
#include "net_server.h"
#include "net_sdl.h"
+#include "net_structrw.h"
typedef enum
{
@@ -137,6 +141,7 @@ static net_client_t clients[MAXNETNODES];
static net_context_t *server_context;
static int sv_gamemode;
static int sv_gamemission;
+static net_gamesettings_t sv_settings;
static void NET_SV_DisconnectClient(net_client_t *client)
{
@@ -383,6 +388,49 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
}
}
+// Parse a game start packet
+
+static void NET_SV_ParseGameStart(net_packet_t *packet, net_client_t *client)
+{
+ net_gamesettings_t settings;
+ net_packet_t *startpacket;
+ int i;
+
+ if (client != NET_SV_Controller())
+ {
+ // Only the controller can start a new game
+
+ return;
+ }
+
+ if (!NET_ReadSettings(packet, &settings))
+ {
+ // Malformed packet
+
+ return;
+ }
+
+ // Change server state
+
+ server_state = SERVER_IN_GAME;
+ sv_settings = settings;
+
+ // Send start packets to each connected node
+
+ for (i=0; i<MAXNETNODES; ++i)
+ {
+ if (ClientConnected(&clients[i]))
+ {
+ startpacket = NET_Conn_NewReliable(&clients[i].connection,
+ NET_PACKET_TYPE_GAMESTART);
+
+ NET_WriteInt8(startpacket, NET_SV_NumClients());
+ NET_WriteInt8(startpacket, NET_SV_ClientIndex(&clients[i]));
+ NET_WriteSettings(startpacket, &settings);
+ }
+ }
+}
+
// Process a packet received by the server
static void NET_SV_Packet(net_packet_t *packet, net_addr_t *addr)
@@ -422,6 +470,7 @@ static void NET_SV_Packet(net_packet_t *packet, net_addr_t *addr)
switch (packet_type)
{
case NET_PACKET_TYPE_GAMESTART:
+ NET_SV_ParseGameStart(packet, client);
break;
default:
// unknown packet type