summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/packet.cpp7
-rw-r--r--src/network/core/tcp.cpp9
-rw-r--r--src/network/core/udp.cpp9
3 files changed, 15 insertions, 10 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index d75d78c7e..38d00d8c0 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -5,6 +5,8 @@
#include "../../stdafx.h"
#include "../../macros.h"
#include "../../string.h"
+#include "../../helpers.hpp"
+#include "../network_data.h"
#include "packet.h"
@@ -24,7 +26,8 @@ extern void NORETURN CDECL error(const char *str, ...);
*/
Packet *NetworkSend_Init(const PacketType type)
{
- Packet *packet = malloc(sizeof(Packet));
+ Packet *packet;
+ MallocT(&packet, 1);
/* An error is inplace here, because it simply means we ran out of memory. */
if (packet == NULL) error("Failed to allocate Packet");
@@ -109,7 +112,7 @@ void NetworkSend_string(Packet *packet, const char* data)
*/
-extern uint CloseConnection(NetworkClientState *cs);
+extern NetworkRecvStatus CloseConnection(NetworkClientState *cs);
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read)
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 9261ea049..ce00335fe 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -12,6 +12,7 @@
#include "../network_data.h"
#include "packet.h"
#include "tcp.h"
+#include "../../helpers.hpp"
/**
* @file tcp.c Basic functions to receive and send TCP packets.
@@ -99,7 +100,7 @@ bool NetworkSend_Packets(NetworkClientState *cs)
p = cs->packet_queue;
while (p != NULL) {
- res = send(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
+ res = send(cs->socket, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -148,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
if (cs->socket == INVALID_SOCKET) return NULL;
if (cs->packet_recv == NULL) {
- cs->packet_recv = malloc(sizeof(Packet));
+ MallocT(&cs->packet_recv, 1);
if (cs->packet_recv == NULL) error("Failed to allocate packet");
/* Set pos to zero! */
cs->packet_recv->pos = 0;
@@ -161,7 +162,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
if (p->pos < sizeof(PacketSize)) {
while (p->pos < sizeof(PacketSize)) {
/* Read the size of the packet */
- res = recv(cs->socket, p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
+ res = recv(cs->socket, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -191,7 +192,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
/* Read rest of packet */
while (p->pos < p->size) {
- res = recv(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
+ res = recv(cs->socket, (char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 6699b4b87..91d751fd5 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -5,6 +5,7 @@
#include "../../stdafx.h"
#include "../../debug.h"
#include "../../macros.h"
+#include "../../helpers.hpp"
#include "packet.h"
#include "udp.h"
@@ -92,7 +93,7 @@ void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in
NetworkSend_FillPacketSize(p);
/* Send the buffer */
- res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
+ res = sendto(udp, (const char*)p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
/* Check for any errors, but ignore it otherwise */
if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR());
@@ -114,7 +115,7 @@ void NetworkUDPReceive(const SOCKET udp)
client_len = sizeof(client_addr);
/* Try to receive anything */
- nbytes = recvfrom(udp, p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
+ nbytes = recvfrom(udp, (char*)p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
/* We got some bytes for the base header of the packet. */
if (nbytes > 2) {
@@ -256,7 +257,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
uint num_grfs = NetworkRecv_uint8(cs, p);
for (i = 0; i < num_grfs; i++) {
- c = calloc(1, sizeof(*c));
+ CallocT(&c, 1);
NetworkRecv_GRFIdentifier(cs, p, c);
HandleIncomingNetworkGameInfoGRFConfig(c);
@@ -290,7 +291,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
info->map_width = NetworkRecv_uint16(cs, p);
info->map_height = NetworkRecv_uint16(cs, p);
info->map_set = NetworkRecv_uint8 (cs, p);
- info->dedicated = NetworkRecv_uint8 (cs, p);
+ info->dedicated = (NetworkRecv_uint8 (cs, p) != 0);
}
}