[chocolate-doom] 56/79: Game start packets

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:07:25 UTC 2017


This is an automated email from the git hooks/post-receive script.

jmtd pushed a commit to annotated tag chocolate-doom-0.1.3
in repository chocolate-doom.

commit af6bdd73396e166417484c2efe4a0eb48aac780e
Author: Simon Howard <fraggle at gmail.com>
Date:   Thu Jan 12 02:11:52 2006 +0000

    Game start packets
    
    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 284
---
 src/net_client.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/net_client.h |  6 +++++-
 src/net_gui.c    | 11 ++++++++++-
 src/net_server.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 124 insertions(+), 4 deletions(-)

diff --git a/src/net_client.c b/src/net_client.c
index 6ff437c..f70a7c0 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 80ea111..85eb595 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 8427554..1ee0555 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 0fb058a..8991202 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/chocolate-doom.git



More information about the Pkg-games-commits mailing list