summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/tcp.cpp83
-rw-r--r--src/network/core/tcp.h17
-rw-r--r--src/network/network.cpp29
-rw-r--r--src/network/network_client.cpp30
-rw-r--r--src/network/network_server.cpp52
5 files changed, 110 insertions, 101 deletions
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index c79f5f14c..e27d86946 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -38,6 +38,28 @@ void NetworkTCPSocketHandler::Initialize()
this->command_queue = NULL;
}
+void NetworkTCPSocketHandler::Destroy()
+{
+ closesocket(this->sock);
+ this->writable = false;
+ this->has_quit = true;
+
+ /* Free all pending and partially received packets */
+ while (this->packet_queue != NULL) {
+ Packet *p = this->packet_queue->next;
+ delete this->packet_queue;
+ this->packet_queue = p;
+ }
+ delete this->packet_recv;
+ this->packet_recv = NULL;
+
+ while (this->command_queue != NULL) {
+ CommandPacket *p = this->command_queue->next;
+ free(this->command_queue);
+ this->command_queue = p;
+ }
+}
+
/**
* Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit
* A socket can make errors. When that happens this handles what to do.
@@ -67,9 +89,8 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection()
* soon as possible. This is the next tick, or maybe one tick later
* if the OS-network-buffer is full)
* @param packet the packet to send
- * @param cs the client to send to
*/
-void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs)
+void NetworkTCPSocketHandler::Send_Packet(Packet *packet)
{
Packet *p;
assert(packet != NULL);
@@ -77,10 +98,10 @@ void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs)
packet->PrepareToSend();
/* Locate last packet buffered for the client */
- p = cs->packet_queue;
+ p = this->packet_queue;
if (p == NULL) {
/* No packets yet */
- cs->packet_queue = packet;
+ this->packet_queue = packet;
} else {
/* Skip to the last packet */
while (p->next != NULL) p = p->next;
@@ -94,33 +115,32 @@ void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs)
* 2) the OS reports back that it can not send any more
* data right now (full network-buffer, it happens ;))
* 3) sending took too long
- * @param cs the client to send the packets for
*/
-bool NetworkSend_Packets(NetworkTCPSocketHandler *cs)
+bool NetworkTCPSocketHandler::Send_Packets()
{
ssize_t res;
Packet *p;
/* We can not write to this socket!! */
- if (!cs->writable) return false;
- if (!cs->IsConnected()) return false;
+ if (!this->writable) return false;
+ if (!this->IsConnected()) return false;
- p = cs->packet_queue;
+ p = this->packet_queue;
while (p != NULL) {
- res = send(cs->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
+ res = send(this->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
/* Something went wrong.. close client! */
DEBUG(net, 0, "send failed with error %d", err);
- cs->CloseConnection();
+ this->CloseConnection();
return false;
}
return true;
}
if (res == 0) {
/* Client/server has left us :( */
- cs->CloseConnection();
+ this->CloseConnection();
return false;
}
@@ -129,9 +149,9 @@ bool NetworkSend_Packets(NetworkTCPSocketHandler *cs)
/* Is this packet sent? */
if (p->pos == p->size) {
/* Go to the next packet */
- cs->packet_queue = p->next;
+ this->packet_queue = p->next;
delete p;
- p = cs->packet_queue;
+ p = this->packet_queue;
} else {
return true;
}
@@ -142,37 +162,36 @@ bool NetworkSend_Packets(NetworkTCPSocketHandler *cs)
/**
* Receives a packet for the given client
- * @param cs the client to (try to) receive a packet for
* @param status the variable to store the status into
* @return the received packet (or NULL when it didn't receive one)
*/
-Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *status)
+Packet *NetworkTCPSocketHandler::Recv_Packet(NetworkRecvStatus *status)
{
ssize_t res;
Packet *p;
*status = NETWORK_RECV_STATUS_OKAY;
- if (!cs->IsConnected()) return NULL;
+ if (!this->IsConnected()) return NULL;
- if (cs->packet_recv == NULL) {
- cs->packet_recv = new Packet(cs);
- if (cs->packet_recv == NULL) error("Failed to allocate packet");
+ if (this->packet_recv == NULL) {
+ this->packet_recv = new Packet(this);
+ if (this->packet_recv == NULL) error("Failed to allocate packet");
}
- p = cs->packet_recv;
+ p = this->packet_recv;
/* Read packet size */
if (p->pos < sizeof(PacketSize)) {
while (p->pos < sizeof(PacketSize)) {
/* Read the size of the packet */
- res = recv(cs->sock, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
+ res = recv(this->sock, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
/* Something went wrong... (104 is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err);
- *status = cs->CloseConnection();
+ *status = this->CloseConnection();
return NULL;
}
/* Connection would block, so stop for now */
@@ -180,7 +199,7 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
}
if (res == 0) {
/* Client/server has left */
- *status = cs->CloseConnection();
+ *status = this->CloseConnection();
return NULL;
}
p->pos += res;
@@ -190,20 +209,20 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
p->ReadRawPacketSize();
if (p->size > SEND_MTU) {
- *status = cs->CloseConnection();
+ *status = this->CloseConnection();
return NULL;
}
}
/* Read rest of packet */
while (p->pos < p->size) {
- res = recv(cs->sock, (char*)p->buffer + p->pos, p->size - p->pos, 0);
+ res = recv(this->sock, (char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
/* Something went wrong... (104 is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err);
- *status = cs->CloseConnection();
+ *status = this->CloseConnection();
return NULL;
}
/* Connection would block */
@@ -211,7 +230,7 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
}
if (res == 0) {
/* Client/server has left */
- *status = cs->CloseConnection();
+ *status = this->CloseConnection();
return NULL;
}
@@ -219,10 +238,16 @@ Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *statu
}
/* Prepare for receiving a new packet */
- cs->packet_recv = NULL;
+ this->packet_recv = NULL;
p->PrepareToRead();
return p;
}
+bool NetworkTCPSocketHandler::IsPacketQueueEmpty()
+{
+ return this->packet_queue == NULL;
+}
+
+
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index 232d6f91a..b7150a447 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -84,6 +84,9 @@ typedef enum {
/** Base socket handler for all TCP sockets */
class NetworkTCPSocketHandler : public NetworkSocketHandler {
/* TODO: rewrite into a proper class */
+private:
+ Packet *packet_queue; ///< Packets that are awaiting delivery
+ Packet *packet_recv; ///< Partially received packet
public:
uint16 index; ///< Client index
uint32 last_frame; ///< Last frame we have executed
@@ -93,20 +96,18 @@ public:
ClientStatus status; ///< Status of this client
bool writable; ///< Can we write to this socket?
- Packet *packet_queue; ///< Packets that are awaiting delivery
- Packet *packet_recv; ///< Partially received packet
-
CommandPacket *command_queue; ///< The command-queue awaiting delivery
NetworkRecvStatus CloseConnection();
void Initialize();
-};
+ void Destroy();
+ void Send_Packet(Packet *packet);
+ bool Send_Packets();
+ bool IsPacketQueueEmpty();
-
-void NetworkSend_Packet(Packet *packet, NetworkTCPSocketHandler *cs);
-Packet *NetworkRecv_Packet(NetworkTCPSocketHandler *cs, NetworkRecvStatus *status);
-bool NetworkSend_Packets(NetworkTCPSocketHandler *cs);
+ Packet *Recv_Packet(NetworkRecvStatus *status);
+};
#endif /* ENABLE_NETWORK */
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 5c0904cb7..cfeef9ed1 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -261,7 +261,7 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkTCPSocketHandler* c
SEND_COMMAND(PACKET_CLIENT_ERROR)(errorno);
// Dequeue all commands before closing the socket
- NetworkSend_Packets(DEREF_CLIENT(0));
+ DEREF_CLIENT(0)->Send_Packets();
}
_switch_mode = SM_MENU;
@@ -629,24 +629,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs)
NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX);
}
- closesocket(cs->sock);
- cs->writable = false;
- cs->has_quit = true;
-
- // Free all pending and partially received packets
- while (cs->packet_queue != NULL) {
- Packet *p = cs->packet_queue->next;
- free(cs->packet_queue);
- cs->packet_queue = p;
- }
- free(cs->packet_recv);
- cs->packet_recv = NULL;
-
- while (cs->command_queue != NULL) {
- CommandPacket *p = cs->command_queue->next;
- free(cs->command_queue);
- cs->command_queue = p;
- }
+ cs->Destroy();
// Close the gap in the client-list
ci = DEREF_CLIENT_INFO(cs);
@@ -827,7 +810,7 @@ static void NetworkClose(void)
FOR_ALL_CLIENTS(cs) {
if (!_network_server) {
SEND_COMMAND(PACKET_CLIENT_QUIT)("leaving");
- NetworkSend_Packets(cs);
+ cs->Send_Packets();
}
NetworkCloseClient(cs);
}
@@ -1066,7 +1049,7 @@ void NetworkReboot(void)
NetworkTCPSocketHandler *cs;
FOR_ALL_CLIENTS(cs) {
SEND_COMMAND(PACKET_SERVER_NEWGAME)(cs);
- NetworkSend_Packets(cs);
+ cs->Send_Packets();
}
}
@@ -1090,7 +1073,7 @@ void NetworkDisconnect(void)
NetworkTCPSocketHandler *cs;
FOR_ALL_CLIENTS(cs) {
SEND_COMMAND(PACKET_SERVER_SHUTDOWN)(cs);
- NetworkSend_Packets(cs);
+ cs->Send_Packets();
}
}
@@ -1172,7 +1155,7 @@ static void NetworkSend(void)
NetworkTCPSocketHandler *cs;
FOR_ALL_CLIENTS(cs) {
if (cs->writable) {
- NetworkSend_Packets(cs);
+ cs->Send_Packets();
if (cs->status == STATUS_MAP) {
// This client is in the middle of a map-send, call the function for that
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index ffa5f1fa0..df4e2a646 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -48,7 +48,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
@@ -75,7 +75,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
p->Send_uint8 (_network_playas); // PlayAs
p->Send_uint8 (NETLANG_ANY); // Language
p->Send_string(_network_unique_id);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
@@ -87,7 +87,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_NEWGRFS_CHECKED);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password)
@@ -102,7 +102,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type,
Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD);
p->Send_uint8 (type);
p->Send_string(password);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP)
@@ -115,7 +115,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK)
@@ -128,7 +128,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK)
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK)
@@ -143,7 +143,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK)
Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK);
p->Send_uint32(_frame_counter);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
// Send a command packet to the server
@@ -172,7 +172,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
p->Send_string(cp->text);
p->Send_uint8 (cp->callback);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
// Send a chat-packet over the network
@@ -194,7 +194,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType
p->Send_uint8 (type);
p->Send_uint8 (dest);
p->Send_string(msg);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
// Send an error-packet over the network
@@ -209,7 +209,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno)
Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR);
p->Send_uint8(errorno);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password)
@@ -223,7 +223,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password)
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD);
p->Send_string(password);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
@@ -237,7 +237,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME);
p->Send_string(name);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
// Send an quit-packet over the network
@@ -252,7 +252,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg)
Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT);
p->Send_string(leavemsg);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command)
@@ -260,7 +260,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *
Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON);
p->Send_string(pass);
p->Send_string(command);
- NetworkSend_Packet(p, MY_CLIENT);
+ MY_CLIENT->Send_Packet(p);
}
@@ -855,7 +855,7 @@ NetworkRecvStatus NetworkClient_ReadPackets(NetworkTCPSocketHandler *cs)
Packet *p;
NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY;
- while (res == NETWORK_RECV_STATUS_OKAY && (p = NetworkRecv_Packet(cs, &res)) != NULL) {
+ while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet(&res)) != NULL) {
byte type = p->Recv_uint8();
if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) {
res = _network_client_packet[type](p);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index be85ce7f7..d65d0e80c 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -53,7 +53,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkTCPSocketHandler
p->Send_string(ci->client_name);
p->Send_string(ci->unique_id);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
}
@@ -78,7 +78,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
p->Send_uint8 (active);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
return;
}
@@ -117,7 +117,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
p->Send_string(_network_player_info[player->index].players);
}
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
@@ -125,7 +125,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
p->Send_uint8 (0);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs, NetworkErrorCode error)
@@ -141,7 +141,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs,
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
p->Send_uint8(error);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
GetNetworkErrorMsg(str, error, lastof(str));
@@ -173,7 +173,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs,
cs->has_quit = true;
// Make sure the data get's there before we close the connection
- NetworkSend_Packets(cs);
+ cs->Send_Packets();
// The client made a mistake, so drop his connection now!
NetworkCloseClient(cs);
@@ -202,7 +202,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHECK_NEWGRFS)(NetworkTCPSocketHandl
cs->Send_GRFIdentifier(p, c);
}
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkTCPSocketHandler *cs, NetworkPasswordType type)
@@ -216,7 +216,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkTCPSocketHandl
Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD);
p->Send_uint8(type);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME)
@@ -239,7 +239,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME)
p = NetworkSend_Init(PACKET_SERVER_WELCOME);
p->Send_uint16(cs->index);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
// Transmit info about all the active clients
FOR_ALL_CLIENTS(new_cs) {
@@ -270,7 +270,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT)
p = NetworkSend_Init(PACKET_SERVER_WAIT);
p->Send_uint8(waiting);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
// This sends the map to the client
@@ -319,7 +319,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
p->Send_uint8 (MAP_PACKET_START);
p->Send_uint32(_frame_counter);
p->Send_uint32(ftell(file_pointer));
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
fseek(file_pointer, 0, SEEK_SET);
@@ -342,12 +342,12 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
if (ferror(file_pointer)) error("Error reading temporary network savegame!");
p->size += res;
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
if (feof(file_pointer)) {
// Done reading!
Packet *p = NetworkSend_Init(PACKET_SERVER_MAP);
p->Send_uint8(MAP_PACKET_END);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
// Set the status to DONE_MAP, no we will wait for the client
// to send it is ready (maybe that happens like never ;))
@@ -381,8 +381,8 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
}
// Send all packets (forced) and check if we have send it all
- NetworkSend_Packets(cs);
- if (cs->packet_queue == NULL) {
+ cs->Send_Packets();
+ if (cs->IsPacketQueueEmpty()) {
// All are sent, increase the sent_packets
sent_packets *= 2;
} else {
@@ -407,7 +407,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_JOIN)(NetworkTCPSocketHandler *cs, u
p->Send_uint16(client_index);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
@@ -433,7 +433,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_FRAME)
p->Send_uint32(_sync_seed_2);
#endif
#endif
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC)
@@ -455,7 +455,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SYNC)
#ifdef NETWORK_SEND_DOUBLE_SEED
p->Send_uint32(_sync_seed_2);
#endif
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs, CommandPacket *cp)
@@ -485,7 +485,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs
p->Send_uint8 (cp->callback);
p->Send_uint32(cp->frame);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkTCPSocketHandler *cs, NetworkAction action, uint16 client_index, bool self_send, const char *msg)
@@ -506,7 +506,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkTCPSocketHandler *cs, N
p->Send_uint8 (self_send);
p->Send_string(msg);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkTCPSocketHandler *cs, uint16 client_index, NetworkErrorCode errorno)
@@ -525,7 +525,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkTCPSocketHandler
p->Send_uint16(client_index);
p->Send_uint8 (errorno);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkTCPSocketHandler *cs, uint16 client_index, const char *leavemsg)
@@ -544,7 +544,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkTCPSocketHandler *cs, u
p->Send_uint16(client_index);
p->Send_string(leavemsg);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN)
@@ -557,7 +557,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN)
//
Packet *p = NetworkSend_Init(PACKET_SERVER_SHUTDOWN);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME)
@@ -570,7 +570,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME)
//
Packet *p = NetworkSend_Init(PACKET_SERVER_NEWGAME);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkTCPSocketHandler *cs, uint16 color, const char *command)
@@ -579,7 +579,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_RCON)(NetworkTCPSocketHandler *cs, u
p->Send_uint16(color);
p->Send_string(command);
- NetworkSend_Packet(p, cs);
+ cs->Send_Packet(p);
}
// **********
@@ -1463,7 +1463,7 @@ bool NetworkServer_ReadPackets(NetworkTCPSocketHandler *cs)
{
Packet *p;
NetworkRecvStatus res;
- while ((p = NetworkRecv_Packet(cs, &res)) != NULL) {
+ while ((p = cs->Recv_Packet(&res)) != NULL) {
byte type = p->Recv_uint8();
if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->has_quit) {
_network_server_packet[type](cs, p);