summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-02-02 23:16:58 +0000
committerrubidium <rubidium@openttd.org>2007-02-02 23:16:58 +0000
commit500f9a971ac2d1a723fceaf499117de85396ff65 (patch)
treeece046363ec9db44c4f305a66b7863bd5113cfb2 /src/network/core
parent9ddd227eb3757473bce23b4cafec894a4e4eaa36 (diff)
downloadopenttd-500f9a971ac2d1a723fceaf499117de85396ff65.tar.xz
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/packet.cpp15
-rw-r--r--src/network/core/packet.h2
-rw-r--r--src/network/core/udp.cpp8
3 files changed, 20 insertions, 5 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 28d6ea377..e5f4493ed 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -80,8 +80,16 @@ void Packet::PrepareToSend(void)
* sent first.
*
* So 0x01234567 would be sent as 67 45 23 01.
+ *
+ * A bool is sent as a uint8 where zero means false
+ * and non-zero means true.
*/
+void Packet::Send_bool(bool data)
+{
+ this->Send_uint8(data ? 1 : 0);
+}
+
void Packet::Send_uint8(uint8 data)
{
assert(this->size < sizeof(this->buffer) - sizeof(data));
@@ -133,7 +141,7 @@ void Packet::Send_string(const char* data)
/**
* Receiving commands
* Again, the next couple of functions are endian-safe
- * see the comment before NetworkSend_uint8 for more info.
+ * see the comment before Send_bool for more info.
*/
@@ -173,6 +181,11 @@ void Packet::PrepareToRead(void)
this->pos = sizeof(PacketSize);
}
+bool Packet::Recv_bool(void)
+{
+ return this->Recv_uint8() != 0;
+}
+
uint8 Packet::Recv_uint8(void)
{
uint8 n;
diff --git a/src/network/core/packet.h b/src/network/core/packet.h
index b39de554b..50abf7ec1 100644
--- a/src/network/core/packet.h
+++ b/src/network/core/packet.h
@@ -45,6 +45,7 @@ public:
/* Sending/writing of packets */
void PrepareToSend(void);
+ void Send_bool (bool data);
void Send_uint8 (uint8 data);
void Send_uint16(uint16 data);
void Send_uint32(uint32 data);
@@ -56,6 +57,7 @@ public:
void PrepareToRead(void);
bool CanReadFromPacket (uint bytes_to_read);
+ bool Recv_bool (void);
uint8 Recv_uint8 (void);
uint16 Recv_uint16(void);
uint32 Recv_uint32(void);
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index cfde82aea..cc83577ef 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -190,7 +190,7 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
p->Send_string(info->server_name);
p->Send_string(info->server_revision);
p->Send_uint8 (info->server_lang);
- p->Send_uint8 (info->use_password);
+ p->Send_bool (info->use_password);
p->Send_uint8 (info->clients_max);
p->Send_uint8 (info->clients_on);
p->Send_uint8 (info->spectators_on);
@@ -198,7 +198,7 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
p->Send_uint16(info->map_width);
p->Send_uint16(info->map_height);
p->Send_uint8 (info->map_set);
- p->Send_uint8 (info->dedicated);
+ p->Send_bool (info->dedicated);
}
/**
@@ -249,7 +249,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
p->Recv_string(info->server_name, sizeof(info->server_name));
p->Recv_string(info->server_revision, sizeof(info->server_revision));
info->server_lang = p->Recv_uint8 ();
- info->use_password = (p->Recv_uint8 () != 0);
+ info->use_password = p->Recv_bool ();
info->clients_max = p->Recv_uint8 ();
info->clients_on = p->Recv_uint8 ();
info->spectators_on = p->Recv_uint8 ();
@@ -261,7 +261,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
info->map_width = p->Recv_uint16();
info->map_height = p->Recv_uint16();
info->map_set = p->Recv_uint8 ();
- info->dedicated = (p->Recv_uint8() != 0);
+ info->dedicated = p->Recv_bool ();
if (info->server_lang >= NETWORK_NUM_LANGUAGES) info->server_lang = 0;
if (info->map_set >= NETWORK_NUM_LANDSCAPES) info->map_set = 0;