[chocolate-doom] 08/79: String read/write functions

Jonathan Dowland jmtd at moszumanska.debian.org
Mon Jan 30 15:07:19 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 0caa1149ff6a96e930f4ebce0db45457e0661b2e
Author: Simon Howard <fraggle at gmail.com>
Date:   Sun Jan 1 23:51:41 2006 +0000

    String read/write functions
    
    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 236
---
 src/net_packet.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/net_packet.h |  7 ++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/src/net_packet.c b/src/net_packet.c
index 923f92b..5144382 100644
--- a/src/net_packet.c
+++ b/src/net_packet.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_packet.c 229 2005-10-30 19:56:15Z fraggle $
+// $Id: net_packet.c 236 2006-01-01 23:51:41Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.2  2006/01/01 23:51:41  fraggle
+// String read/write functions
+//
 // Revision 1.1  2005/10/30 19:56:15  fraggle
 // Add foundation code for the new networking system
 //
@@ -121,6 +124,38 @@ boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data)
     return true;
 }
 
+// Read a string from the packet.  Returns NULL if a terminating 
+// NUL character was not found before the end of the packet.
+
+char *NET_ReadString(net_packet_t *packet)
+{
+    char *start;
+
+    start = (char *) packet->data + packet->pos;
+
+    // Search forward for a NUL character
+
+    while (packet->pos < packet->len && packet->data[packet->pos] != '\0')
+    {
+        ++packet->pos;
+    }
+
+    if (packet->pos >= packet->len)
+    {
+        // Reached the end of the packet
+
+        return NULL;
+    }
+
+    // packet->data[packet->pos] == '\0': We have reached a terminating
+    // NULL.  Skip past this NULL and continue reading immediately 
+    // after it.
+
+    ++packet->pos;
+    
+    return start;
+}
+
 // Dynamically increases the size of a packet
 
 static void NET_IncreasePacket(net_packet_t *packet)
@@ -185,6 +220,24 @@ void NET_WriteInt32(net_packet_t *packet, unsigned int i)
     packet->len += 4;
 }
 
+void NET_WriteString(net_packet_t *packet, char *string)
+{
+    byte *p;
+
+    // Increase the packet size until large enough to hold the string
+
+    while (packet->len + strlen(string) + 1 > packet->alloced)
+    {
+        NET_IncreasePacket(packet);
+    }
+
+    p = packet->data + packet->len;
+
+    strcpy((char *) p, string);
+
+    packet->len += strlen(string) + 1;
+}
+
 
 
 
diff --git a/src/net_packet.h b/src/net_packet.h
index f2b1905..f5583d6 100644
--- a/src/net_packet.h
+++ b/src/net_packet.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_packet.h 229 2005-10-30 19:56:15Z fraggle $
+// $Id: net_packet.h 236 2006-01-01 23:51:41Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.2  2006/01/01 23:51:41  fraggle
+// String read/write functions
+//
 // Revision 1.1  2005/10/30 19:56:15  fraggle
 // Add foundation code for the new networking system
 //
@@ -41,9 +44,11 @@ void NET_FreePacket(net_packet_t *packet);
 boolean NET_ReadInt8(net_packet_t *packet, unsigned int *data);
 boolean NET_ReadInt16(net_packet_t *packet, unsigned int *data);
 boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data);
+char *NET_ReadString(net_packet_t *packet);
 void NET_WriteInt8(net_packet_t *packet, unsigned int i);
 void NET_WriteInt16(net_packet_t *packet, unsigned int i);
 void NET_WriteInt32(net_packet_t *packet, unsigned int i);
+void NET_WriteString(net_packet_t *packet, char *string);
 
 #endif /* #ifndef NET_PACKET_H */
 

-- 
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