summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-02-01 23:26:44 +0000
committerrubidium <rubidium@openttd.org>2007-02-01 23:26:44 +0000
commit16ce6def09f83351328ad326eb329c96ca13fe70 (patch)
treeb1cb00fad194dbe2ece25ee0bdeec5ef0065019c
parent19c90a3bc0b8499c78b5edffff5557bf0b3de79b (diff)
downloadopenttd-16ce6def09f83351328ad326eb329c96ca13fe70.tar.xz
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
-rw-r--r--src/network/core/core.cpp8
-rw-r--r--src/network/core/packet.cpp125
-rw-r--r--src/network/core/packet.h33
-rw-r--r--src/network/core/udp.cpp82
-rw-r--r--src/network/network_client.cpp156
-rw-r--r--src/network/network_server.cpp172
-rw-r--r--src/network/network_udp.cpp96
7 files changed, 333 insertions, 339 deletions
diff --git a/src/network/core/core.cpp b/src/network/core/core.cpp
index 894529a05..7c187ddcd 100644
--- a/src/network/core/core.cpp
+++ b/src/network/core/core.cpp
@@ -99,9 +99,9 @@ void NetworkCoreShutdown(void)
void NetworkSocketHandler::Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf)
{
uint j;
- NetworkSend_uint32(p, grf->grfid);
+ p->Send_uint32(grf->grfid);
for (j = 0; j < sizeof(grf->md5sum); j++) {
- NetworkSend_uint8 (p, grf->md5sum[j]);
+ p->Send_uint8 (grf->md5sum[j]);
}
}
@@ -113,9 +113,9 @@ void NetworkSocketHandler::Send_GRFIdentifier(Packet *p, const GRFIdentifier *gr
void NetworkSocketHandler::Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf)
{
uint j;
- grf->grfid = NetworkRecv_uint32(this, p);
+ grf->grfid = p->Recv_uint32();
for (j = 0; j < sizeof(grf->md5sum); j++) {
- grf->md5sum[j] = NetworkRecv_uint8(this, p);
+ grf->md5sum[j] = p->Recv_uint8();
}
}
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 653566e32..28d6ea377 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -63,7 +63,7 @@ Packet *NetworkSend_Init(PacketType type)
/**
* Writes the packet size from the raw packet from packet->size
*/
-void Packet::PrepareToSend()
+void Packet::PrepareToSend(void)
{
assert(this->cs == NULL && this->next == NULL);
@@ -82,52 +82,51 @@ void Packet::PrepareToSend()
* So 0x01234567 would be sent as 67 45 23 01.
*/
-void NetworkSend_uint8(Packet *packet, uint8 data)
+void Packet::Send_uint8(uint8 data)
{
- assert(packet->size < sizeof(packet->buffer) - sizeof(data));
- packet->buffer[packet->size++] = data;
+ assert(this->size < sizeof(this->buffer) - sizeof(data));
+ this->buffer[this->size++] = data;
}
-void NetworkSend_uint16(Packet *packet, uint16 data)
+void Packet::Send_uint16(uint16 data)
{
- assert(packet->size < sizeof(packet->buffer) - sizeof(data));
- packet->buffer[packet->size++] = GB(data, 0, 8);
- packet->buffer[packet->size++] = GB(data, 8, 8);
+ assert(this->size < sizeof(this->buffer) - sizeof(data));
+ this->buffer[this->size++] = GB(data, 0, 8);
+ this->buffer[this->size++] = GB(data, 8, 8);
}
-void NetworkSend_uint32(Packet *packet, uint32 data)
+void Packet::Send_uint32(uint32 data)
{
- assert(packet->size < sizeof(packet->buffer) - sizeof(data));
- packet->buffer[packet->size++] = GB(data, 0, 8);
- packet->buffer[packet->size++] = GB(data, 8, 8);
- packet->buffer[packet->size++] = GB(data, 16, 8);
- packet->buffer[packet->size++] = GB(data, 24, 8);
+ assert(this->size < sizeof(this->buffer) - sizeof(data));
+ this->buffer[this->size++] = GB(data, 0, 8);
+ this->buffer[this->size++] = GB(data, 8, 8);
+ this->buffer[this->size++] = GB(data, 16, 8);
+ this->buffer[this->size++] = GB(data, 24, 8);
}
-void NetworkSend_uint64(Packet *packet, uint64 data)
+void Packet::Send_uint64(uint64 data)
{
- assert(packet->size < sizeof(packet->buffer) - sizeof(data));
- packet->buffer[packet->size++] = GB(data, 0, 8);
- packet->buffer[packet->size++] = GB(data, 8, 8);
- packet->buffer[packet->size++] = GB(data, 16, 8);
- packet->buffer[packet->size++] = GB(data, 24, 8);
- packet->buffer[packet->size++] = GB(data, 32, 8);
- packet->buffer[packet->size++] = GB(data, 40, 8);
- packet->buffer[packet->size++] = GB(data, 48, 8);
- packet->buffer[packet->size++] = GB(data, 56, 8);
+ assert(this->size < sizeof(this->buffer) - sizeof(data));
+ this->buffer[this->size++] = GB(data, 0, 8);
+ this->buffer[this->size++] = GB(data, 8, 8);
+ this->buffer[this->size++] = GB(data, 16, 8);
+ this->buffer[this->size++] = GB(data, 24, 8);
+ this->buffer[this->size++] = GB(data, 32, 8);
+ this->buffer[this->size++] = GB(data, 40, 8);
+ this->buffer[this->size++] = GB(data, 48, 8);
+ this->buffer[this->size++] = GB(data, 56, 8);
}
/**
* Sends a string over the network. It sends out
* the string + '\0'. No size-byte or something.
- * @param packet packet to send the string in
* @param data the string to send
*/
-void NetworkSend_string(Packet *packet, const char* data)
+void Packet::Send_string(const char* data)
{
assert(data != NULL);
- assert(packet->size < sizeof(packet->buffer) - strlen(data) - 1);
- while ((packet->buffer[packet->size++] = *data++) != '\0') {}
+ assert(this->size < sizeof(this->buffer) - strlen(data) - 1);
+ while ((this->buffer[this->size++] = *data++) != '\0') {}
}
@@ -139,14 +138,14 @@ void NetworkSend_string(Packet *packet, const char* data)
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
-static inline bool CanReadFromPacket(NetworkSocketHandler *cs, const Packet *packet, const uint bytes_to_read)
+bool Packet::CanReadFromPacket(uint bytes_to_read)
{
/* Don't allow reading from a quit client/client who send bad data */
- if (cs->HasClientQuit()) return false;
+ if (this->cs->HasClientQuit()) return false;
/* Check if variable is within packet-size */
- if (packet->pos + bytes_to_read > packet->size) {
- cs->CloseConnection();
+ if (this->pos + bytes_to_read > this->size) {
+ this->cs->CloseConnection();
return false;
}
@@ -156,7 +155,7 @@ static inline bool CanReadFromPacket(NetworkSocketHandler *cs, const Packet *pac
/**
* Reads the packet size from the raw packet and stores it in the packet->size
*/
-void Packet::ReadRawPacketSize()
+void Packet::ReadRawPacketSize(void)
{
assert(this->cs != NULL && this->next == NULL);
this->size = (PacketSize)this->buffer[0];
@@ -166,7 +165,7 @@ void Packet::ReadRawPacketSize()
/**
* Prepares the packet so it can be read
*/
-void Packet::PrepareToRead()
+void Packet::PrepareToRead(void)
{
this->ReadRawPacketSize();
@@ -174,59 +173,59 @@ void Packet::PrepareToRead()
this->pos = sizeof(PacketSize);
}
-uint8 NetworkRecv_uint8(NetworkSocketHandler *cs, Packet *packet)
+uint8 Packet::Recv_uint8(void)
{
uint8 n;
- if (!CanReadFromPacket(cs, packet, sizeof(n))) return 0;
+ if (!this->CanReadFromPacket(sizeof(n))) return 0;
- n = packet->buffer[packet->pos++];
+ n = this->buffer[this->pos++];
return n;
}
-uint16 NetworkRecv_uint16(NetworkSocketHandler *cs, Packet *packet)
+uint16 Packet::Recv_uint16(void)
{
uint16 n;
- if (!CanReadFromPacket(cs, packet, sizeof(n))) return 0;
+ if (!this->CanReadFromPacket(sizeof(n))) return 0;
- n = (uint16)packet->buffer[packet->pos++];
- n += (uint16)packet->buffer[packet->pos++] << 8;
+ n = (uint16)this->buffer[this->pos++];
+ n += (uint16)this->buffer[this->pos++] << 8;
return n;
}
-uint32 NetworkRecv_uint32(NetworkSocketHandler *cs, Packet *packet)
+uint32 Packet::Recv_uint32(void)
{
uint32 n;
- if (!CanReadFromPacket(cs, packet, sizeof(n))) return 0;
+ if (!this->CanReadFromPacket(sizeof(n))) return 0;
- n = (uint32)packet->buffer[packet->pos++];
- n += (uint32)packet->buffer[packet->pos++] << 8;
- n += (uint32)packet->buffer[packet->pos++] << 16;
- n += (uint32)packet->buffer[packet->pos++] << 24;
+ n = (uint32)this->buffer[this->pos++];
+ n += (uint32)this->buffer[this->pos++] << 8;
+ n += (uint32)this->buffer[this->pos++] << 16;
+ n += (uint32)this->buffer[this->pos++] << 24;
return n;
}
-uint64 NetworkRecv_uint64(NetworkSocketHandler *cs, Packet *packet)
+uint64 Packet::Recv_uint64(void)
{
uint64 n;
- if (!CanReadFromPacket(cs, packet, sizeof(n))) return 0;
+ if (!this->CanReadFromPacket(sizeof(n))) return 0;
- n = (uint64)packet->buffer[packet->pos++];
- n += (uint64)packet->buffer[packet->pos++] << 8;
- n += (uint64)packet->buffer[packet->pos++] << 16;
- n += (uint64)packet->buffer[packet->pos++] << 24;
- n += (uint64)packet->buffer[packet->pos++] << 32;
- n += (uint64)packet->buffer[packet->pos++] << 40;
- n += (uint64)packet->buffer[packet->pos++] << 48;
- n += (uint64)packet->buffer[packet->pos++] << 56;
+ n = (uint64)this->buffer[this->pos++];
+ n += (uint64)this->buffer[this->pos++] << 8;
+ n += (uint64)this->buffer[this->pos++] << 16;
+ n += (uint64)this->buffer[this->pos++] << 24;
+ n += (uint64)this->buffer[this->pos++] << 32;
+ n += (uint64)this->buffer[this->pos++] << 40;
+ n += (uint64)this->buffer[this->pos++] << 48;
+ n += (uint64)this->buffer[this->pos++] << 56;
return n;
}
/** Reads a string till it finds a '\0' in the stream */
-void NetworkRecv_string(NetworkSocketHandler *cs, Packet *p, char *buffer, size_t size)
+void Packet::Recv_string(char *buffer, size_t size)
{
PacketSize pos;
char *bufp = buffer;
@@ -234,17 +233,17 @@ void NetworkRecv_string(NetworkSocketHandler *cs, Packet *p, char *buffer, size_
/* Don't allow reading from a closed socket */
if (cs->HasClientQuit()) return;
- pos = p->pos;
- while (--size > 0 && pos < p->size && (*buffer++ = p->buffer[pos++]) != '\0') {}
+ pos = this->pos;
+ while (--size > 0 && pos < this->size && (*buffer++ = this->buffer[pos++]) != '\0') {}
- if (size == 0 || pos == p->size) {
+ if (size == 0 || pos == this->size) {
*buffer = '\0';
/* If size was sooner to zero then the string in the stream
* skip till the \0, so than packet can be read out correctly for the rest */
- while (pos < p->size && p->buffer[pos] != '\0') pos++;
+ while (pos < this->size && this->buffer[pos] != '\0') pos++;
pos++;
}
- p->pos = pos;
+ this->pos = pos;
str_validate(bufp);
}
diff --git a/src/network/core/packet.h b/src/network/core/packet.h
index 8b0607485..b39de554b 100644
--- a/src/network/core/packet.h
+++ b/src/network/core/packet.h
@@ -42,25 +42,28 @@ public:
Packet(NetworkSocketHandler *cs);
Packet(PacketType type);
- void PrepareToSend();
+ /* Sending/writing of packets */
+ void PrepareToSend(void);
- void ReadRawPacketSize();
- void PrepareToRead();
-};
+ void Send_uint8 (uint8 data);
+ void Send_uint16(uint16 data);
+ void Send_uint32(uint32 data);
+ void Send_uint64(uint64 data);
+ void Send_string(const char* data);
+ /* Reading/receiving of packets */
+ void ReadRawPacketSize(void);
+ void PrepareToRead(void);
-Packet *NetworkSend_Init(PacketType type);
-void NetworkSend_uint8 (Packet *packet, uint8 data);
-void NetworkSend_uint16(Packet *packet, uint16 data);
-void NetworkSend_uint32(Packet *packet, uint32 data);
-void NetworkSend_uint64(Packet *packet, uint64 data);
-void NetworkSend_string(Packet *packet, const char* data);
+ bool CanReadFromPacket (uint bytes_to_read);
+ uint8 Recv_uint8 (void);
+ uint16 Recv_uint16(void);
+ uint32 Recv_uint32(void);
+ uint64 Recv_uint64(void);
+ void Recv_string(char* buffer, size_t size);
+};
-uint8 NetworkRecv_uint8 (NetworkSocketHandler *cs, Packet *packet);
-uint16 NetworkRecv_uint16(NetworkSocketHandler *cs, Packet *packet);
-uint32 NetworkRecv_uint32(NetworkSocketHandler *cs, Packet *packet);
-uint64 NetworkRecv_uint64(NetworkSocketHandler *cs, Packet *packet);
-void NetworkRecv_string(NetworkSocketHandler *cs, Packet *packet, char* buffer, size_t size);
+Packet *NetworkSend_Init(PacketType type);
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 865b2ad3a..cfde82aea 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -146,7 +146,7 @@ void NetworkUDPSocketHandler::ReceivePackets()
*/
void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameInfo *info)
{
- NetworkSend_uint8 (p, NETWORK_GAME_INFO_VERSION);
+ p->Send_uint8 (NETWORK_GAME_INFO_VERSION);
/*
* Please observe the order.
@@ -169,7 +169,7 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
for (c = info->grfconfig; c != NULL; c = c->next) {
if (!HASBIT(c->flags, GCF_STATIC)) count++;
}
- NetworkSend_uint8 (p, count); // Send number of GRFs
+ p->Send_uint8 (count); // Send number of GRFs
/* Send actual GRF Identifications */
for (c = info->grfconfig; c != NULL; c = c->next) {
@@ -178,27 +178,27 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
}
/* NETWORK_GAME_INFO_VERSION = 3 */
- NetworkSend_uint32(p, info->game_date);
- NetworkSend_uint32(p, info->start_date);
+ p->Send_uint32(info->game_date);
+ p->Send_uint32(info->start_date);
/* NETWORK_GAME_INFO_VERSION = 2 */
- NetworkSend_uint8 (p, info->companies_max);
- NetworkSend_uint8 (p, info->companies_on);
- NetworkSend_uint8 (p, info->spectators_max);
+ p->Send_uint8 (info->companies_max);
+ p->Send_uint8 (info->companies_on);
+ p->Send_uint8 (info->spectators_max);
/* NETWORK_GAME_INFO_VERSION = 1 */
- NetworkSend_string(p, info->server_name);
- NetworkSend_string(p, info->server_revision);
- NetworkSend_uint8 (p, info->server_lang);
- NetworkSend_uint8 (p, info->use_password);
- NetworkSend_uint8 (p, info->clients_max);
- NetworkSend_uint8 (p, info->clients_on);
- NetworkSend_uint8 (p, info->spectators_on);
- NetworkSend_string(p, info->map_name);
- NetworkSend_uint16(p, info->map_width);
- NetworkSend_uint16(p, info->map_height);
- NetworkSend_uint8 (p, info->map_set);
- NetworkSend_uint8 (p, info->dedicated);
+ 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_uint8 (info->clients_max);
+ p->Send_uint8 (info->clients_on);
+ p->Send_uint8 (info->spectators_on);
+ p->Send_string(info->map_name);
+ p->Send_uint16(info->map_width);
+ p->Send_uint16(info->map_height);
+ p->Send_uint8 (info->map_set);
+ p->Send_uint8 (info->dedicated);
}
/**
@@ -210,7 +210,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
{
static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
- info->game_info_version = NetworkRecv_uint8(this, p);
+ info->game_info_version = p->Recv_uint8();
/*
* Please observe the order.
@@ -224,7 +224,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
case 4: {
GRFConfig **dst = &info->grfconfig;
uint i;
- uint num_grfs = NetworkRecv_uint8(this, p);
+ uint num_grfs = p->Recv_uint8();
for (i = 0; i < num_grfs; i++) {
GRFConfig *c = CallocT<GRFConfig>(1);
@@ -237,31 +237,31 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
}
} /* Fallthrough */
case 3:
- info->game_date = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
- info->start_date = clamp(NetworkRecv_uint32(this, p), 0, MAX_DATE);
+ info->game_date = clamp(p->Recv_uint32(), 0, MAX_DATE);
+ info->start_date = clamp(p->Recv_uint32(), 0, MAX_DATE);
/* Fallthrough */
case 2:
- info->companies_max = NetworkRecv_uint8 (this, p);
- info->companies_on = NetworkRecv_uint8 (this, p);
- info->spectators_max = NetworkRecv_uint8 (this, p);
+ info->companies_max = p->Recv_uint8 ();
+ info->companies_on = p->Recv_uint8 ();
+ info->spectators_max = p->Recv_uint8 ();
/* Fallthrough */
case 1:
- NetworkRecv_string(this, p, info->server_name, sizeof(info->server_name));
- NetworkRecv_string(this, p, info->server_revision, sizeof(info->server_revision));
- info->server_lang = NetworkRecv_uint8 (this, p);
- info->use_password = (NetworkRecv_uint8 (this, p) != 0);
- info->clients_max = NetworkRecv_uint8 (this, p);
- info->clients_on = NetworkRecv_uint8 (this, p);
- info->spectators_on = NetworkRecv_uint8 (this, p);
+ 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->clients_max = p->Recv_uint8 ();
+ info->clients_on = p->Recv_uint8 ();
+ info->spectators_on = p->Recv_uint8 ();
if (info->game_info_version < 3) { // 16 bits dates got scrapped and are read earlier
- info->game_date = NetworkRecv_uint16(this, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
- info->start_date = NetworkRecv_uint16(this, p) + DAYS_TILL_ORIGINAL_BASE_YEAR;
+ info->game_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR;
+ info->start_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR;
}
- NetworkRecv_string(this, p, info->map_name, sizeof(info->map_name));
- info->map_width = NetworkRecv_uint16(this, p);
- info->map_height = NetworkRecv_uint16(this, p);
- info->map_set = NetworkRecv_uint8 (this, p);
- info->dedicated = (NetworkRecv_uint8(this, p) != 0);
+ p->Recv_string(info->map_name, sizeof(info->map_name));
+ info->map_width = p->Recv_uint16();
+ info->map_height = p->Recv_uint16();
+ info->map_set = p->Recv_uint8 ();
+ info->dedicated = (p->Recv_uint8() != 0);
if (info->server_lang >= NETWORK_NUM_LANGUAGES) info->server_lang = 0;
if (info->map_set >= NETWORK_NUM_LANDSCAPES) info->map_set = 0;
@@ -286,7 +286,7 @@ void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, const struct sockaddr_i
/* New packet == new client, which has not quit yet */
this->has_quit = false;
- type = (PacketUDPType)NetworkRecv_uint8(this, p);
+ type = (PacketUDPType)p->Recv_uint8();
switch (this->HasClientQuit() ? PACKET_UDP_END : type) {
UDP_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER);
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index c1fb84c63..ffa5f1fa0 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -70,11 +70,11 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
p = NetworkSend_Init(PACKET_CLIENT_JOIN);
- NetworkSend_string(p, _openttd_revision);
- NetworkSend_string(p, _network_player_name); // Player name
- NetworkSend_uint8(p, _network_playas); // PlayAs
- NetworkSend_uint8(p, NETLANG_ANY); // Language
- NetworkSend_string(p, _network_unique_id);
+ p->Send_string(_openttd_revision);
+ p->Send_string(_network_player_name); // Player name
+ p->Send_uint8 (_network_playas); // PlayAs
+ p->Send_uint8 (NETLANG_ANY); // Language
+ p->Send_string(_network_unique_id);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -100,8 +100,8 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type,
// String: Password
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD);
- NetworkSend_uint8(p, type);
- NetworkSend_string(p, password);
+ p->Send_uint8 (type);
+ p->Send_string(password);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -142,7 +142,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK)
Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK);
- NetworkSend_uint32(p, _frame_counter);
+ p->Send_uint32(_frame_counter);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -164,13 +164,13 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND);
- NetworkSend_uint8(p, cp->player);
- NetworkSend_uint32(p, cp->cmd);
- NetworkSend_uint32(p, cp->p1);
- NetworkSend_uint32(p, cp->p2);
- NetworkSend_uint32(p, (uint32)cp->tile);
- NetworkSend_string(p, cp->text);
- NetworkSend_uint8(p, cp->callback);
+ p->Send_uint8 (cp->player);
+ p->Send_uint32(cp->cmd);
+ p->Send_uint32(cp->p1);
+ p->Send_uint32(cp->p2);
+ p->Send_uint32((uint32)cp->tile);
+ p->Send_string(cp->text);
+ p->Send_uint8 (cp->callback);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -190,10 +190,10 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType
Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT);
- NetworkSend_uint8(p, action);
- NetworkSend_uint8(p, type);
- NetworkSend_uint8(p, dest);
- NetworkSend_string(p, msg);
+ p->Send_uint8 (action);
+ p->Send_uint8 (type);
+ p->Send_uint8 (dest);
+ p->Send_string(msg);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -208,7 +208,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR);
- NetworkSend_uint8(p, errorno);
+ p->Send_uint8(errorno);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -222,7 +222,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD);
- NetworkSend_string(p, password);
+ p->Send_string(password);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -236,7 +236,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME);
- NetworkSend_string(p, name);
+ p->Send_string(name);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -251,15 +251,15 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT);
- NetworkSend_string(p, leavemsg);
+ p->Send_string(leavemsg);
NetworkSend_Packet(p, MY_CLIENT);
}
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command)
{
Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON);
- NetworkSend_string(p, pass);
- NetworkSend_string(p, command);
+ p->Send_string(pass);
+ p->Send_string(command);
NetworkSend_Packet(p, MY_CLIENT);
}
@@ -294,33 +294,33 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
byte company_info_version;
int i;
- company_info_version = NetworkRecv_uint8(MY_CLIENT, p);
+ company_info_version = p->Recv_uint8();
if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
byte total;
PlayerID current;
- total = NetworkRecv_uint8(MY_CLIENT, p);
+ total = p->Recv_uint8();
// There is no data at all..
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
- current = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
+ current = (Owner)p->Recv_uint8();
if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
- NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
- _network_player_info[current].inaugurated_year = NetworkRecv_uint32(MY_CLIENT, p);
- _network_player_info[current].company_value = NetworkRecv_uint64(MY_CLIENT, p);
- _network_player_info[current].money = NetworkRecv_uint64(MY_CLIENT, p);
- _network_player_info[current].income = NetworkRecv_uint64(MY_CLIENT, p);
- _network_player_info[current].performance = NetworkRecv_uint16(MY_CLIENT, p);
- _network_player_info[current].use_password = NetworkRecv_uint8(MY_CLIENT, p);
+ p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
+ _network_player_info[current].inaugurated_year = p->Recv_uint32();
+ _network_player_info[current].company_value = p->Recv_uint64();
+ _network_player_info[current].money = p->Recv_uint64();
+ _network_player_info[current].income = p->Recv_uint64();
+ _network_player_info[current].performance = p->Recv_uint16();
+ _network_player_info[current].use_password = p->Recv_uint8();
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
- _network_player_info[current].num_vehicle[i] = NetworkRecv_uint16(MY_CLIENT, p);
+ _network_player_info[current].num_vehicle[i] = p->Recv_uint16();
for (i = 0; i < NETWORK_STATION_TYPES; i++)
- _network_player_info[current].num_station[i] = NetworkRecv_uint16(MY_CLIENT, p);
+ _network_player_info[current].num_station[i] = p->Recv_uint16();
- NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].players, sizeof(_network_player_info[current].players));
+ p->Recv_string(_network_player_info[current].players, sizeof(_network_player_info[current].players));
InvalidateWindow(WC_NETWORK_WINDOW, 0);
@@ -336,13 +336,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
{
NetworkClientInfo *ci;
- uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
- PlayerID playas = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
+ uint16 index = p->Recv_uint16();
+ PlayerID playas = (Owner)p->Recv_uint8();
char name[NETWORK_NAME_LENGTH];
char unique_id[NETWORK_NAME_LENGTH];
- NetworkRecv_string(MY_CLIENT, p, name, sizeof(name));
- NetworkRecv_string(MY_CLIENT, p, unique_id, sizeof(unique_id));
+ p->Recv_string(name, sizeof(name));
+ p->Recv_string(unique_id, sizeof(unique_id));
if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
@@ -387,7 +387,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
{
- NetworkErrorCode error = (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
switch (error) {
/* We made an error in the protocol, and our connection is closed.... */
@@ -422,7 +422,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS)
{
- uint grf_count = NetworkRecv_uint8(MY_CLIENT, p);
+ uint grf_count = p->Recv_uint8();
NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;
/* Check all GRFs */
@@ -453,7 +453,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
{
- NetworkPasswordType type = (NetworkPasswordType)NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkPasswordType type = (NetworkPasswordType)p->Recv_uint8();
switch (type) {
case NETWORK_GAME_PASSWORD:
@@ -467,7 +467,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME)
{
- _network_own_client_index = NetworkRecv_uint16(MY_CLIENT, p);
+ _network_own_client_index = p->Recv_uint16();
// Start receiving the map
SEND_COMMAND(PACKET_CLIENT_GETMAP)();
@@ -477,7 +477,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WAIT)
{
_network_join_status = NETWORK_JOIN_STATUS_WAITING;
- _network_join_waiting = NetworkRecv_uint8(MY_CLIENT, p);
+ _network_join_waiting = p->Recv_uint8();
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
// We are put on hold for receiving the map.. we need GUI for this ;)
@@ -494,7 +494,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
byte maptype;
- maptype = NetworkRecv_uint8(MY_CLIENT, p);
+ maptype = p->Recv_uint8();
if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
@@ -509,10 +509,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
return NETWORK_RECV_STATUS_SAVEGAME;
}
- _frame_counter = _frame_counter_server = _frame_counter_max = NetworkRecv_uint32(MY_CLIENT, p);
+ _frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
_network_join_kbytes = 0;
- _network_join_kbytes_total = NetworkRecv_uint32(MY_CLIENT, p) / 1024;
+ _network_join_kbytes_total = p->Recv_uint32() / 1024;
/* If the network connection has been closed due to loss of connection
* or when _network_join_kbytes_total is 0, the join status window will
@@ -583,16 +583,16 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME)
{
- _frame_counter_server = NetworkRecv_uint32(MY_CLIENT, p);
- _frame_counter_max = NetworkRecv_uint32(MY_CLIENT, p);
+ _frame_counter_server = p->Recv_uint32();
+ _frame_counter_max = p->Recv_uint32();
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
// Test if the server supports this option
// and if we are at the frame the server is
if (p->pos < p->size) {
_sync_frame = _frame_counter_server;
- _sync_seed_1 = NetworkRecv_uint32(MY_CLIENT, p);
+ _sync_seed_1 = p->Recv_uint32();
#ifdef NETWORK_SEND_DOUBLE_SEED
- _sync_seed_2 = NetworkRecv_uint32(MY_CLIENT, p);
+ _sync_seed_2 = p->Recv_uint32();
#endif
}
#endif
@@ -611,10 +611,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
{
- _sync_frame = NetworkRecv_uint32(MY_CLIENT, p);
- _sync_seed_1 = NetworkRecv_uint32(MY_CLIENT, p);
+ _sync_frame = p->Recv_uint32();
+ _sync_seed_1 = p->Recv_uint32();
#ifdef NETWORK_SEND_DOUBLE_SEED
- _sync_seed_2 = NetworkRecv_uint32(MY_CLIENT, p);
+ _sync_seed_2 = p->Recv_uint32();
#endif
return NETWORK_RECV_STATUS_OKAY;
@@ -623,15 +623,15 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
{
CommandPacket *cp = MallocT<CommandPacket>(1);
- cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p);
- cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
- cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);
- cp->p2 = NetworkRecv_uint32(MY_CLIENT, p);
- cp->tile = NetworkRecv_uint32(MY_CLIENT, p);
- NetworkRecv_string(MY_CLIENT, p, cp->text, sizeof(cp->text));
- cp->callback = NetworkRecv_uint8(MY_CLIENT, p);
- cp->frame = NetworkRecv_uint32(MY_CLIENT, p);
- cp->next = NULL;
+ cp->player = (PlayerID)p->Recv_uint8();
+ cp->cmd = p->Recv_uint32();
+ cp->p1 = p->Recv_uint32();
+ cp->p2 = p->Recv_uint32();
+ cp->tile = p->Recv_uint32();
+ p->Recv_string(cp->text, sizeof(cp->text));
+ cp->callback = p->Recv_uint8();
+ cp->frame = p->Recv_uint32();
+ cp->next = NULL;
// The server did send us this command..
// queue it in our own queue, so we can handle it in the upcoming frame!
@@ -653,10 +653,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN];
const NetworkClientInfo *ci = NULL, *ci_to;
- NetworkAction action = (NetworkAction)NetworkRecv_uint8(MY_CLIENT, p);
- uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
- bool self_send = (NetworkRecv_uint8(MY_CLIENT, p) != 0);
- NetworkRecv_string(MY_CLIENT, p, msg, MAX_TEXT_MSG_LEN);
+ NetworkAction action = (NetworkAction)p->Recv_uint8();
+ uint16 index = p->Recv_uint16();
+ bool self_send = (p->Recv_uint8() != 0);
+ p->Recv_string(msg, MAX_TEXT_MSG_LEN);
ci_to = NetworkFindClientInfoFromIndex(index);
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
@@ -700,8 +700,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
uint16 index;
NetworkClientInfo *ci;
- index = NetworkRecv_uint16(MY_CLIENT, p);
- GetNetworkErrorMsg(str, (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p), lastof(str));
+ index = p->Recv_uint16();
+ GetNetworkErrorMsg(str, (NetworkErrorCode)p->Recv_uint8(), lastof(str));
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
@@ -722,8 +722,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
uint16 index;
NetworkClientInfo *ci;
- index = NetworkRecv_uint16(MY_CLIENT, p);
- NetworkRecv_string(MY_CLIENT, p, str, lengthof(str));
+ index = p->Recv_uint16();
+ p->Recv_string(str, lengthof(str));
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
@@ -746,7 +746,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
uint16 index;
NetworkClientInfo *ci;
- index = NetworkRecv_uint16(MY_CLIENT, p);
+ index = p->Recv_uint16();
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL)
@@ -781,8 +781,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON)
char rcon_out[NETWORK_RCONCOMMAND_LENGTH];
uint16 color_code;
- color_code = NetworkRecv_uint16(MY_CLIENT, p);
- NetworkRecv_string(MY_CLIENT, p, rcon_out, sizeof(rcon_out));
+ color_code = p->Recv_uint16();
+ p->Recv_string(rcon_out, sizeof(rcon_out));
IConsolePrint(color_code, rcon_out);
@@ -856,7 +856,7 @@ NetworkRecvStatus NetworkClient_ReadPackets(NetworkTCPSocketHandler *cs)
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY;
while (res == NETWORK_RECV_STATUS_OKAY && (p = NetworkRecv_Packet(cs, &res)) != NULL) {
- byte type = NetworkRecv_uint8(MY_CLIENT, p);
+ byte type = p->Recv_uint8();
if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) {
res = _network_client_packet[type](p);
} else {
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 16137036e..be85ce7f7 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -48,10 +48,10 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkTCPSocketHandler
if (ci->client_index != NETWORK_EMPTY_INDEX) {
Packet *p = NetworkSend_Init(PACKET_SERVER_CLIENT_INFO);
- NetworkSend_uint16(p, ci->client_index);
- NetworkSend_uint8 (p, ci->client_playas);
- NetworkSend_string(p, ci->client_name);
- NetworkSend_string(p, ci->unique_id);
+ p->Send_uint16(ci->client_index);
+ p->Send_uint8 (ci->client_playas);
+ p->Send_string(ci->client_name);
+ p->Send_string(ci->unique_id);
NetworkSend_Packet(p, cs);
}
@@ -75,8 +75,8 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
if (active == 0) {
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
- NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION);
- NetworkSend_uint8 (p, active);
+ p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
+ p->Send_uint8 (active);
NetworkSend_Packet(p, cs);
return;
@@ -89,36 +89,32 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
- NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION);
- NetworkSend_uint8 (p, active);
- NetworkSend_uint8 (p, player->index);
+ p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
+ p->Send_uint8 (active);
+ p->Send_uint8 (player->index);
- NetworkSend_string(p, _network_player_info[player->index].company_name);
- NetworkSend_uint32(p, _network_player_info[player->index].inaugurated_year);
- NetworkSend_uint64(p, _network_player_info[player->index].company_value);
- NetworkSend_uint64(p, _network_player_info[player->index].money);
- NetworkSend_uint64(p, _network_player_info[player->index].income);
- NetworkSend_uint16(p, _network_player_info[player->index].performance);
+ p->Send_string(_network_player_info[player->index].company_name);
+ p->Send_uint32(_network_player_info[player->index].inaugurated_year);
+ p->Send_uint64(_network_player_info[player->index].company_value);
+ p->Send_uint64(_network_player_info[player->index].money);
+ p->Send_uint64(_network_player_info[player->index].income);
+ p->Send_uint16(_network_player_info[player->index].performance);
/* Send 1 if there is a passord for the company else send 0 */
- if (_network_player_info[player->index].password[0] != '\0') {
- NetworkSend_uint8(p, 1);
- } else {
- NetworkSend_uint8(p, 0);
- }
+ p->Send_uint8(StrEmpty(_network_player_info[player->index].password) ? 0 : 1);
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
- NetworkSend_uint16(p, _network_player_info[player->index].num_vehicle[i]);
+ p->Send_uint16(_network_player_info[player->index].num_vehicle[i]);
}
for (i = 0; i < NETWORK_STATION_TYPES; i++) {
- NetworkSend_uint16(p, _network_player_info[player->index].num_station[i]);
+ p->Send_uint16(_network_player_info[player->index].num_station[i]);
}
if (_network_player_info[player->index].players[0] == '\0') {
- NetworkSend_string(p, "<none>");
+ p->Send_string("<none>");
} else {
- NetworkSend_string(p, _network_player_info[player->index].players);
+ p->Send_string(_network_player_info[player->index].players);
}
NetworkSend_Packet(p, cs);
@@ -126,8 +122,8 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
- NetworkSend_uint8 (p, NETWORK_COMPANY_INFO_VERSION);
- NetworkSend_uint8 (p, 0);
+ p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
+ p->Send_uint8 (0);
NetworkSend_Packet(p, cs);
}
@@ -144,7 +140,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs,
char str[100];
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
- NetworkSend_uint8(p, error);
+ p->Send_uint8(error);
NetworkSend_Packet(p, cs);
GetNetworkErrorMsg(str, error, lastof(str));
@@ -201,7 +197,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHECK_NEWGRFS)(NetworkTCPSocketHandl
for (c = _grfconfig; c != NULL; c = c->next) grf_count++;
- NetworkSend_uint8 (p, grf_count);
+ p->Send_uint8 (grf_count);
for (c = _grfconfig; c != NULL; c = c->next) {
cs->Send_GRFIdentifier(p, c);
}
@@ -219,7 +215,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkTCPSocketHandl
//
Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD);
- NetworkSend_uint8(p, type);
+ p->Send_uint8(type);
NetworkSend_Packet(p, cs);
}
@@ -242,7 +238,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME)
_network_game_info.clients_on++;
p = NetworkSend_Init(PACKET_SERVER_WELCOME);
- NetworkSend_uint16(p, cs->index);
+ p->Send_uint16(cs->index);
NetworkSend_Packet(p, cs);
// Transmit info about all the active clients
@@ -273,7 +269,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT)
}
p = NetworkSend_Init(PACKET_SERVER_WAIT);
- NetworkSend_uint8(p, waiting);
+ p->Send_uint8(waiting);
NetworkSend_Packet(p, cs);
}
@@ -320,9 +316,9 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
// Now send the _frame_counter and how many packets are coming
p = NetworkSend_Init(PACKET_SERVER_MAP);
- NetworkSend_uint8(p, MAP_PACKET_START);
- NetworkSend_uint32(p, _frame_counter);
- NetworkSend_uint32(p, ftell(file_pointer));
+ p->Send_uint8 (MAP_PACKET_START);
+ p->Send_uint32(_frame_counter);
+ p->Send_uint32(ftell(file_pointer));
NetworkSend_Packet(p, cs);
fseek(file_pointer, 0, SEEK_SET);
@@ -340,7 +336,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
int res;
for (i = 0; i < sent_packets; i++) {
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
- NetworkSend_uint8(p, MAP_PACKET_NORMAL);
+ p->Send_uint8(MAP_PACKET_NORMAL);
res = (int)fread(p->buffer + p->size, 1, SEND_MTU - p->size, file_pointer);
if (ferror(file_pointer)) error("Error reading temporary network savegame!");
@@ -350,7 +346,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
if (feof(file_pointer)) {
// Done reading!
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
- NetworkSend_uint8(p, MAP_PACKET_END);
+ p->Send_uint8(MAP_PACKET_END);
NetworkSend_Packet(p, cs);
// Set the status to DONE_MAP, no we will wait for the client
@@ -409,7 +405,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkTCPSocketHandler *cs, u
Packet *p = NetworkSend_Init(PACKET_SERVER_JOIN);
- NetworkSend_uint16(p, client_index);
+ p->Send_uint16(client_index);
NetworkSend_Packet(p, cs);
}
@@ -429,12 +425,12 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_FRAME)
//
Packet *p = NetworkSend_Init(PACKET_SERVER_FRAME);
- NetworkSend_uint32(p, _frame_counter);
- NetworkSend_uint32(p, _frame_counter_max);
+ p->Send_uint32(_frame_counter);
+ p->Send_uint32(_frame_counter_max);
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
- NetworkSend_uint32(p, _sync_seed_1);
+ p->Send_uint32(_sync_seed_1);
#ifdef NETWORK_SEND_DOUBLE_SEED
- NetworkSend_uint32(p, _sync_seed_2);
+ p->Send_uint32(_sync_seed_2);
#endif
#endif
NetworkSend_Packet(p, cs);
@@ -453,11 +449,11 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC)
//
Packet *p = NetworkSend_Init(PACKET_SERVER_SYNC);
- NetworkSend_uint32(p, _frame_counter);
- NetworkSend_uint32(p, _sync_seed_1);
+ p->Send_uint32(_frame_counter);
+ p->Send_uint32(_sync_seed_1);
#ifdef NETWORK_SEND_DOUBLE_SEED
- NetworkSend_uint32(p, _sync_seed_2);
+ p->Send_uint32(_sync_seed_2);
#endif
NetworkSend_Packet(p, cs);
}
@@ -480,14 +476,14 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs
Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND);
- NetworkSend_uint8(p, cp->player);
- NetworkSend_uint32(p, cp->cmd);
- NetworkSend_uint32(p, cp->p1);
- NetworkSend_uint32(p, cp->p2);
- NetworkSend_uint32(p, cp->tile);
- NetworkSend_string(p, cp->text);
- NetworkSend_uint8(p, cp->callback);
- NetworkSend_uint32(p, cp->frame);
+ p->Send_uint8 (cp->player);
+ p->Send_uint32(cp->cmd);
+ p->Send_uint32(cp->p1);
+ p->Send_uint32(cp->p2);
+ p->Send_uint32(cp->tile);
+ p->Send_string(cp->text);
+ p->Send_uint8 (cp->callback);
+ p->Send_uint32(cp->frame);
NetworkSend_Packet(p, cs);
}
@@ -505,10 +501,10 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkTCPSocketHandler *cs, N
Packet *p = NetworkSend_Init(PACKET_SERVER_CHAT);
- NetworkSend_uint8(p, action);
- NetworkSend_uint16(p, client_index);
- NetworkSend_uint8(p, self_send);
- NetworkSend_string(p, msg);
+ p->Send_uint8 (action);
+ p->Send_uint16(client_index);
+ p->Send_uint8 (self_send);
+ p->Send_string(msg);
NetworkSend_Packet(p, cs);
}
@@ -526,8 +522,8 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkTCPSocketHandler
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR_QUIT);
- NetworkSend_uint16(p, client_index);
- NetworkSend_uint8(p, errorno);
+ p->Send_uint16(client_index);
+ p->Send_uint8 (errorno);
NetworkSend_Packet(p, cs);
}
@@ -545,8 +541,8 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkTCPSocketHandler *cs, u
Packet *p = NetworkSend_Init(PACKET_SERVER_QUIT);
- NetworkSend_uint16(p, client_index);
- NetworkSend_string(p, leavemsg);
+ p->Send_uint16(client_index);
+ p->Send_string(leavemsg);
NetworkSend_Packet(p, cs);
}
@@ -581,8 +577,8 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkTCPSocketHandler *cs, u
{
Packet *p = NetworkSend_Init(PACKET_SERVER_RCON);
- NetworkSend_uint16(p, color);
- NetworkSend_string(p, command);
+ p->Send_uint16(color);
+ p->Send_string(command);
NetworkSend_Packet(p, cs);
}
@@ -621,7 +617,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
NetworkLanguage client_lang;
char client_revision[NETWORK_REVISION_LENGTH];
- NetworkRecv_string(cs, p, client_revision, sizeof(client_revision));
+ p->Recv_string(client_revision, sizeof(client_revision));
#if defined(WITH_REV) || defined(WITH_REV_HACK)
// Check if the client has revision control enabled
@@ -633,10 +629,10 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
}
#endif
- NetworkRecv_string(cs, p, name, sizeof(name));
- playas = (Owner)NetworkRecv_uint8(cs, p);
- client_lang = (NetworkLanguage)NetworkRecv_uint8(cs, p);
- NetworkRecv_string(cs, p, unique_id, sizeof(unique_id));
+ p->Recv_string(name, sizeof(name));
+ playas = (Owner)p->Recv_uint8();
+ client_lang = (NetworkLanguage)p->Recv_uint8();
+ p->Recv_string(unique_id, sizeof(unique_id));
if (cs->has_quit) return;
@@ -694,8 +690,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
char password[NETWORK_PASSWORD_LENGTH];
const NetworkClientInfo *ci;
- type = (NetworkPasswordType)NetworkRecv_uint8(cs, p);
- NetworkRecv_string(cs, p, password, sizeof(password));
+ type = (NetworkPasswordType)p->Recv_uint8();
+ p->Recv_string(password, sizeof(password));
if (cs->status == STATUS_INACTIVE && type == NETWORK_GAME_PASSWORD) {
// Check game-password
@@ -841,14 +837,14 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
return;
}
- cp->player = (Owner)NetworkRecv_uint8(cs, p);
- cp->cmd = NetworkRecv_uint32(cs, p);
- cp->p1 = NetworkRecv_uint32(cs, p);
- cp->p2 = NetworkRecv_uint32(cs, p);
- cp->tile = NetworkRecv_uint32(cs, p);
- NetworkRecv_string(cs, p, cp->text, lengthof(cp->text));
+ cp->player = (Owner)p->Recv_uint8();
+ cp->cmd = p->Recv_uint32();
+ cp->p1 = p->Recv_uint32();
+ cp->p2 = p->Recv_uint32();
+ cp->tile = p->Recv_uint32();
+ p->Recv_string(cp->text, lengthof(cp->text));
- callback = NetworkRecv_uint8(cs, p);
+ callback = p->Recv_uint8();
if (cs->has_quit) return;
@@ -930,7 +926,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
NetworkTCPSocketHandler *new_cs;
char str[100];
char client_name[NETWORK_CLIENT_NAME_LENGTH];
- NetworkErrorCode errorno = (NetworkErrorCode)NetworkRecv_uint8(cs, p);
+ NetworkErrorCode errorno = (NetworkErrorCode)p->Recv_uint8();
// The client was never joined.. thank the client for the packet, but ignore it
if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
@@ -969,7 +965,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
return;
}
- NetworkRecv_string(cs, p, str, lengthof(str));
+ p->Recv_string(str, lengthof(str));
NetworkGetClientName(client_name, sizeof(client_name), cs);
@@ -986,7 +982,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
{
- uint32 frame = NetworkRecv_uint32(cs, p);
+ uint32 frame = p->Recv_uint32();
/* The client is trying to catch up with the server */
if (cs->status == STATUS_PRE_ACTIVE) {
@@ -1113,12 +1109,12 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
{
- NetworkAction action = (NetworkAction)NetworkRecv_uint8(cs, p);
- DestType desttype = (DestType)NetworkRecv_uint8(cs, p);
- int dest = NetworkRecv_uint8(cs, p);
+ NetworkAction action = (NetworkAction)p->Recv_uint8();
+ DestType desttype = (DestType)p->Recv_uint8();
+ int dest = p->Recv_uint8();
char msg[MAX_TEXT_MSG_LEN];
- NetworkRecv_string(cs, p, msg, MAX_TEXT_MSG_LEN);
+ p->Recv_string(msg, MAX_TEXT_MSG_LEN);
NetworkServer_HandleChat(action, desttype, dest, msg, cs->index);
}
@@ -1128,7 +1124,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
char password[NETWORK_PASSWORD_LENGTH];
const NetworkClientInfo *ci;
- NetworkRecv_string(cs, p, password, sizeof(password));
+ p->Recv_string(password, sizeof(password));
ci = DEREF_CLIENT_INFO(cs);
if (IsValidPlayer(ci->client_playas)) {
@@ -1141,7 +1137,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
char client_name[NETWORK_CLIENT_NAME_LENGTH];
NetworkClientInfo *ci;
- NetworkRecv_string(cs, p, client_name, sizeof(client_name));
+ p->Recv_string(client_name, sizeof(client_name));
ci = DEREF_CLIENT_INFO(cs);
if (cs->has_quit) return;
@@ -1163,8 +1159,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_RCON)
if (_network_game_info.rcon_password[0] == '\0') return;
- NetworkRecv_string(cs, p, pass, sizeof(pass));
- NetworkRecv_string(cs, p, command, sizeof(command));
+ p->Recv_string(pass, sizeof(pass));
+ p->Recv_string(command, sizeof(command));
if (strcmp(pass, _network_game_info.rcon_password) != 0) {
DEBUG(net, 0, "[rcon] wrong password from client-id %d", cs->index);
@@ -1468,7 +1464,7 @@ bool NetworkServer_ReadPackets(NetworkTCPSocketHandler *cs)
Packet *p;
NetworkRecvStatus res;
while ((p = NetworkRecv_Packet(cs, &res)) != NULL) {
- byte type = NetworkRecv_uint8(cs, p);
+ byte type = p->Recv_uint8();
if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->has_quit) {
_network_server_packet[type](cs, p);
} else {
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index cbce618b4..b7e8b6f94 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -100,8 +100,8 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
Packet packet(PACKET_UDP_SERVER_DETAIL_INFO);
/* Send the amount of active companies */
- NetworkSend_uint8 (&packet, NETWORK_COMPANY_INFO_VERSION);
- NetworkSend_uint8 (&packet, ActivePlayerCount());
+ packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
+ packet.Send_uint8 (ActivePlayerCount());
/* Fetch the latest version of everything */
NetworkPopulateCompanyInfo();
@@ -114,51 +114,47 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
current++;
/* Send the information */
- NetworkSend_uint8 (&packet, current);
+ packet.Send_uint8 (current);
- NetworkSend_string(&packet, _network_player_info[player->index].company_name);
- NetworkSend_uint32(&packet, _network_player_info[player->index].inaugurated_year);
- NetworkSend_uint64(&packet, _network_player_info[player->index].company_value);
- NetworkSend_uint64(&packet, _network_player_info[player->index].money);
- NetworkSend_uint64(&packet, _network_player_info[player->index].income);
- NetworkSend_uint16(&packet, _network_player_info[player->index].performance);
+ packet.Send_string(_network_player_info[player->index].company_name);
+ packet.Send_uint32(_network_player_info[player->index].inaugurated_year);
+ packet.Send_uint64(_network_player_info[player->index].company_value);
+ packet.Send_uint64(_network_player_info[player->index].money);
+ packet.Send_uint64(_network_player_info[player->index].income);
+ packet.Send_uint16(_network_player_info[player->index].performance);
/* Send 1 if there is a passord for the company else send 0 */
- if (_network_player_info[player->index].password[0] != '\0') {
- NetworkSend_uint8(&packet, 1);
- } else {
- NetworkSend_uint8(&packet, 0);
- }
+ packet.Send_uint8 (StrEmpty(_network_player_info[player->index].password) ? 0 : 1);
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
- NetworkSend_uint16(&packet, _network_player_info[player->index].num_vehicle[i]);
+ packet.Send_uint16(_network_player_info[player->index].num_vehicle[i]);
for (i = 0; i < NETWORK_STATION_TYPES; i++)
- NetworkSend_uint16(&packet, _network_player_info[player->index].num_station[i]);
+ packet.Send_uint16(_network_player_info[player->index].num_station[i]);
/* Find the clients that are connected to this player */
FOR_ALL_CLIENTS(cs) {
ci = DEREF_CLIENT_INFO(cs);
if (ci->client_playas == player->index) {
/* The uint8 == 1 indicates that a client is following */
- NetworkSend_uint8 (&packet, 1);
- NetworkSend_string(&packet, ci->client_name);
- NetworkSend_string(&packet, ci->unique_id);
- NetworkSend_uint32(&packet, ci->join_date);
+ packet.Send_uint8 (1);
+ packet.Send_string(ci->client_name);
+ packet.Send_string(ci->unique_id);
+ packet.Send_uint32(ci->join_date);
}
}
/* Also check for the server itself */
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
if (ci->client_playas == player->index) {
/* The uint8 == 1 indicates that a client is following */
- NetworkSend_uint8 (&packet, 1);
- NetworkSend_string(&packet, ci->client_name);
- NetworkSend_string(&packet, ci->unique_id);
- NetworkSend_uint32(&packet, ci->join_date);
+ packet.Send_uint8 (1);
+ packet.Send_string(ci->client_name);
+ packet.Send_string(ci->unique_id);
+ packet.Send_uint32(ci->join_date);
}
/* Indicates end of client list */
- NetworkSend_uint8(&packet, 0);
+ packet.Send_uint8(0);
}
/* And check if we have any spectators */
@@ -166,10 +162,10 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
ci = DEREF_CLIENT_INFO(cs);
if (!IsValidPlayer(ci->client_playas)) {
/* The uint8 == 1 indicates that a client is following */
- NetworkSend_uint8 (&packet, 1);
- NetworkSend_string(&packet, ci->client_name);
- NetworkSend_string(&packet, ci->unique_id);
- NetworkSend_uint32(&packet, ci->join_date);
+ packet.Send_uint8 (1);
+ packet.Send_string(ci->client_name);
+ packet.Send_string(ci->unique_id);
+ packet.Send_uint32(ci->join_date);
}
}
@@ -177,14 +173,14 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
if (!IsValidPlayer(ci->client_playas)) {
/* The uint8 == 1 indicates that a client is following */
- NetworkSend_uint8 (&packet, 1);
- NetworkSend_string(&packet, ci->client_name);
- NetworkSend_string(&packet, ci->unique_id);
- NetworkSend_uint32(&packet, ci->join_date);
+ packet.Send_uint8 (1);
+ packet.Send_string(ci->client_name);
+ packet.Send_string(ci->unique_id);
+ packet.Send_uint32(ci->join_date);
}
/* Indicates end of client list */
- NetworkSend_uint8(&packet, 0);
+ packet.Send_uint8(0);
this->SendPacket(&packet, client_addr);
}
@@ -213,7 +209,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
DEBUG(net, 6, "[udp] newgrf data request from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port));
- num_grfs = NetworkRecv_uint8 (this, p);
+ num_grfs = p->Recv_uint8 ();
if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
for (i = 0; i < num_grfs; i++) {
@@ -241,7 +237,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
if (in_reply_count == 0) return;
Packet packet(PACKET_UDP_SERVER_NEWGRFS);
- NetworkSend_uint8 (&packet, in_reply_count);
+ packet.Send_uint8(in_reply_count);
for (i = 0; i < in_reply_count; i++) {
char name[NETWORK_GRF_NAME_LENGTH];
@@ -249,7 +245,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
ttd_strlcpy(name, (in_reply[i]->name != NULL && !StrEmpty(in_reply[i]->name)) ?
in_reply[i]->name : in_reply[i]->filename, sizeof(name));
this->Send_GRFIdentifier(&packet, in_reply[i]);
- NetworkSend_string(&packet, name);
+ packet.Send_string(name);
}
this->SendPacket(&packet, client_addr);
@@ -308,7 +304,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE)
uint i;
Packet packet(PACKET_UDP_CLIENT_GET_NEWGRFS);
- NetworkSend_uint8 (&packet, in_request_count);
+ packet.Send_uint8(in_request_count);
for (i = 0; i < in_request_count; i++) {
this->Send_GRFIdentifier(&packet, in_request[i]);
}
@@ -347,12 +343,12 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST)
* an uint32 (ip) and an uint16 (port) for each pair
*/
- ver = NetworkRecv_uint8(this, p);
+ ver = p->Recv_uint8();
if (ver == 1) {
- for (i = NetworkRecv_uint16(this, p); i != 0 ; i--) {
- ip.s_addr = TO_LE32(NetworkRecv_uint32(this, p));
- port = NetworkRecv_uint16(this, p);
+ for (i = p->Recv_uint16(); i != 0 ; i--) {
+ ip.s_addr = TO_LE32(p->Recv_uint32());
+ port = p->Recv_uint16();
/* Somehow we reached the end of the packet */
if (this->HasClientQuit()) return;
@@ -369,7 +365,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
DEBUG(net, 6, "[udp] newgrf data reply from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port));
- num_grfs = NetworkRecv_uint8 (this, p);
+ num_grfs = p->Recv_uint8 ();
if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
for (i = 0; i < num_grfs; i++) {
@@ -378,7 +374,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
GRFConfig c;
this->Recv_GRFIdentifier(p, &c);
- NetworkRecv_string(this, p, name, sizeof(name));
+ p->Recv_string(name, sizeof(name));
/* An empty name is not possible under normal circumstances
* and causes problems when showing the NewGRF list. */
@@ -461,7 +457,7 @@ void NetworkUDPQueryMasterServer(void)
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST);
// packet only contains protocol version
- NetworkSend_uint8(&p, NETWORK_MASTER_SERVER_VERSION);
+ p.Send_uint8(NETWORK_MASTER_SERVER_VERSION);
_udp_client_socket->SendPacket(&p, &out_addr);
@@ -537,8 +533,8 @@ void NetworkUDPRemoveAdvertise(void)
/* Send the packet */
Packet p(PACKET_UDP_SERVER_UNREGISTER);
/* Packet is: Version, server_port */
- NetworkSend_uint8 (&p, NETWORK_MASTER_SERVER_VERSION);
- NetworkSend_uint16(&p, _network_server_port);
+ p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
+ p.Send_uint16(_network_server_port);
_udp_master_socket->SendPacket(&p, &out_addr);
}
@@ -585,9 +581,9 @@ void NetworkUDPAdvertise(void)
/* Send the packet */
Packet p(PACKET_UDP_SERVER_REGISTER);
/* Packet is: WELCOME_MESSAGE, Version, server_port */
- NetworkSend_string(&p, NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
- NetworkSend_uint8 (&p, NETWORK_MASTER_SERVER_VERSION);
- NetworkSend_uint16(&p, _network_server_port);
+ p.Send_string(NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
+ p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
+ p.Send_uint16(_network_server_port);
_udp_master_socket->SendPacket(&p, &out_addr);
}