summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/address.cpp24
-rw-r--r--src/network/core/address.h2
-rw-r--r--src/network/core/host.cpp8
-rw-r--r--src/network/core/packet.cpp14
-rw-r--r--src/network/core/tcp.cpp38
-rw-r--r--src/network/core/tcp.h2
-rw-r--r--src/network/core/tcp_admin.cpp2
-rw-r--r--src/network/core/tcp_connect.cpp2
-rw-r--r--src/network/core/tcp_content.cpp14
-rw-r--r--src/network/core/tcp_game.cpp4
-rw-r--r--src/network/core/tcp_game.h6
-rw-r--r--src/network/core/tcp_http.cpp30
-rw-r--r--src/network/core/tcp_http.h10
-rw-r--r--src/network/core/tcp_listen.h2
-rw-r--r--src/network/core/udp.cpp8
-rw-r--r--src/network/core/udp.h2
-rw-r--r--src/network/network.cpp46
-rw-r--r--src/network/network_admin.cpp18
-rw-r--r--src/network/network_chat_gui.cpp12
-rw-r--r--src/network/network_client.cpp60
-rw-r--r--src/network/network_command.cpp38
-rw-r--r--src/network/network_content.cpp64
-rw-r--r--src/network/network_content.h2
-rw-r--r--src/network/network_content_gui.cpp34
-rw-r--r--src/network/network_func.h2
-rw-r--r--src/network/network_gamelist.cpp36
-rw-r--r--src/network/network_gui.cpp80
-rw-r--r--src/network/network_internal.h4
-rw-r--r--src/network/network_server.cpp112
-rw-r--r--src/network/network_udp.cpp36
30 files changed, 356 insertions, 356 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index 11b5d753f..3d5bd5d64 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -25,7 +25,7 @@ const char *NetworkAddress::GetHostname()
{
if (StrEmpty(this->hostname) && this->address.ss_family != AF_UNSPEC) {
assert(this->address_length != 0);
- getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), NULL, 0, NI_NUMERICHOST);
+ getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), nullptr, 0, NI_NUMERICHOST);
}
return this->hostname;
}
@@ -131,7 +131,7 @@ const sockaddr_storage *NetworkAddress::GetAddress()
* bothered to implement the specifications and allow '0' as value
* that means "don't care whether it is SOCK_STREAM or SOCK_DGRAM".
*/
- this->Resolve(this->address.ss_family, SOCK_STREAM, AI_ADDRCONFIG, NULL, ResolveLoopProc);
+ this->Resolve(this->address.ss_family, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ResolveLoopProc);
this->resolved = true;
}
return &this->address;
@@ -145,7 +145,7 @@ const sockaddr_storage *NetworkAddress::GetAddress()
bool NetworkAddress::IsFamily(int family)
{
if (!this->IsResolved()) {
- this->Resolve(family, SOCK_STREAM, AI_ADDRCONFIG, NULL, ResolveLoopProc);
+ this->Resolve(family, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ResolveLoopProc);
}
return this->address.ss_family == family;
}
@@ -167,7 +167,7 @@ bool NetworkAddress::IsInNetmask(const char *netmask)
/* Check for CIDR separator */
const char *chr_cidr = strchr(netmask, '/');
- if (chr_cidr != NULL) {
+ if (chr_cidr != nullptr) {
int tmp_cidr = atoi(chr_cidr + 1);
/* Invalid CIDR, treat as single host */
@@ -232,7 +232,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
seprintf(port_name, lastof(port_name), "%u", this->GetPort());
bool reset_hostname = false;
- /* Setting both hostname to NULL and port to 0 is not allowed.
+ /* Setting both hostname to nullptr and port to 0 is not allowed.
* As port 0 means bind to any port, the other must mean that
* we want to bind to 'all' IPs. */
if (StrEmpty(this->hostname) && this->address_length == 0 && this->GetPort() == 0) {
@@ -242,7 +242,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
strecpy(this->hostname, fam == AF_INET ? "0.0.0.0" : "::", lastof(this->hostname));
}
- int e = getaddrinfo(StrEmpty(this->hostname) ? NULL : this->hostname, port_name, &hints, &ai);
+ int e = getaddrinfo(StrEmpty(this->hostname) ? nullptr : this->hostname, port_name, &hints, &ai);
if (reset_hostname) strecpy(this->hostname, "", lastof(this->hostname));
@@ -255,18 +255,18 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
}
SOCKET sock = INVALID_SOCKET;
- for (struct addrinfo *runp = ai; runp != NULL; runp = runp->ai_next) {
+ for (struct addrinfo *runp = ai; runp != nullptr; runp = runp->ai_next) {
/* When we are binding to multiple sockets, make sure we do not
* connect to one with exactly the same address twice. That's
* of course totally unneeded ;) */
- if (sockets != NULL) {
+ if (sockets != nullptr) {
NetworkAddress address(runp->ai_addr, (int)runp->ai_addrlen);
if (sockets->Contains(address)) continue;
}
sock = func(runp);
if (sock == INVALID_SOCKET) continue;
- if (sockets == NULL) {
+ if (sockets == nullptr) {
this->address_length = (int)runp->ai_addrlen;
assert(sizeof(this->address) >= runp->ai_addrlen);
memcpy(&this->address, runp->ai_addr, runp->ai_addrlen);
@@ -323,7 +323,7 @@ SOCKET NetworkAddress::Connect()
{
DEBUG(net, 1, "Connecting to %s", this->GetAddressAsString());
- return this->Resolve(AF_UNSPEC, SOCK_STREAM, AI_ADDRCONFIG, NULL, ConnectLoopProc);
+ return this->Resolve(AF_UNSPEC, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ConnectLoopProc);
}
/**
@@ -386,9 +386,9 @@ static SOCKET ListenLoopProc(addrinfo *runp)
*/
void NetworkAddress::Listen(int socktype, SocketList *sockets)
{
- assert(sockets != NULL);
+ assert(sockets != nullptr);
- /* Setting both hostname to NULL and port to 0 is not allowed.
+ /* Setting both hostname to nullptr and port to 0 is not allowed.
* As port 0 means bind to any port, the other must mean that
* we want to bind to 'all' IPs. */
if (this->address_length == 0 && this->address.ss_family == AF_UNSPEC &&
diff --git a/src/network/core/address.h b/src/network/core/address.h
index bd1bab676..4dd0edbc0 100644
--- a/src/network/core/address.h
+++ b/src/network/core/address.h
@@ -84,7 +84,7 @@ public:
if (*hostname == '[') hostname++;
strecpy(this->hostname, StrEmpty(hostname) ? "" : hostname, lastof(this->hostname));
char *tmp = strrchr(this->hostname, ']');
- if (tmp != NULL) *tmp = '\0';
+ if (tmp != nullptr) *tmp = '\0';
memset(&this->address, 0, sizeof(this->address));
this->address.ss_family = family;
diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp
index 2bf862a4f..98a706e2f 100644
--- a/src/network/core/host.cpp
+++ b/src/network/core/host.cpp
@@ -45,7 +45,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // BE
return;
}
- char *output_pointer = NULL;
+ char *output_pointer = nullptr;
int output_length = _netstat(sock, &output_pointer, 1);
if (output_length < 0) {
DEBUG(net, 0, "[core] error running _netstat");
@@ -94,9 +94,9 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE
if (getifaddrs(&ifap) != 0) return;
- for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
+ for (ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) {
if (!(ifa->ifa_flags & IFF_BROADCAST)) continue;
- if (ifa->ifa_broadaddr == NULL) continue;
+ if (ifa->ifa_broadaddr == nullptr) continue;
if (ifa->ifa_broadaddr->sa_family != AF_INET) continue;
NetworkAddress addr(ifa->ifa_broadaddr, sizeof(sockaddr));
@@ -116,7 +116,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi
INTERFACE_INFO *ifo = CallocT<INTERFACE_INFO>(num);
for (;;) {
- if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, ifo, num * sizeof(*ifo), &len, NULL, NULL) == 0) break;
+ if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, nullptr, 0, ifo, num * sizeof(*ifo), &len, nullptr, nullptr) == 0) break;
free(ifo);
if (WSAGetLastError() != WSAEFAULT) {
closesocket(sock);
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 8cecd9bd2..fda8fdfeb 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -24,10 +24,10 @@
*/
Packet::Packet(NetworkSocketHandler *cs)
{
- assert(cs != NULL);
+ assert(cs != nullptr);
this->cs = cs;
- this->next = NULL;
+ this->next = nullptr;
this->pos = 0; // We start reading from here
this->size = 0;
this->buffer = MallocT<byte>(SEND_MTU);
@@ -39,8 +39,8 @@ Packet::Packet(NetworkSocketHandler *cs)
*/
Packet::Packet(PacketType type)
{
- this->cs = NULL;
- this->next = NULL;
+ this->cs = nullptr;
+ this->next = nullptr;
/* Skip the size so we can write that in before sending the packet */
this->pos = 0;
@@ -62,7 +62,7 @@ Packet::~Packet()
*/
void Packet::PrepareToSend()
{
- assert(this->cs == NULL && this->next == NULL);
+ assert(this->cs == nullptr && this->next == nullptr);
this->buffer[0] = GB(this->size, 0, 8);
this->buffer[1] = GB(this->size, 8, 8);
@@ -149,7 +149,7 @@ void Packet::Send_uint64(uint64 data)
*/
void Packet::Send_string(const char *data)
{
- assert(data != NULL);
+ assert(data != nullptr);
/* The <= *is* valid due to the fact that we are comparing sizes and not the index. */
assert(this->size + strlen(data) + 1 <= SEND_MTU);
while ((this->buffer[this->size++] = *data++) != '\0') {}
@@ -187,7 +187,7 @@ bool Packet::CanReadFromPacket(uint bytes_to_read)
*/
void Packet::ReadRawPacketSize()
{
- assert(this->cs != NULL && this->next == NULL);
+ assert(this->cs != nullptr && this->next == nullptr);
this->size = (PacketSize)this->buffer[0];
this->size += (PacketSize)this->buffer[1] << 8;
}
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 33b61688d..63d004a8f 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -24,7 +24,7 @@
*/
NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) :
NetworkSocketHandler(),
- packet_queue(NULL), packet_recv(NULL),
+ packet_queue(nullptr), packet_recv(nullptr),
sock(s), writable(false)
{
}
@@ -43,13 +43,13 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection(bool error)
NetworkSocketHandler::CloseConnection(error);
/* Free all pending and partially received packets */
- while (this->packet_queue != NULL) {
+ while (this->packet_queue != nullptr) {
Packet *p = this->packet_queue->next;
delete this->packet_queue;
this->packet_queue = p;
}
delete this->packet_recv;
- this->packet_recv = NULL;
+ this->packet_recv = nullptr;
return NETWORK_RECV_STATUS_OKAY;
}
@@ -63,7 +63,7 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection(bool error)
void NetworkTCPSocketHandler::SendPacket(Packet *packet)
{
Packet *p;
- assert(packet != NULL);
+ assert(packet != nullptr);
packet->PrepareToSend();
@@ -74,12 +74,12 @@ void NetworkTCPSocketHandler::SendPacket(Packet *packet)
/* Locate last packet buffered for the client */
p = this->packet_queue;
- if (p == NULL) {
+ if (p == nullptr) {
/* No packets yet */
this->packet_queue = packet;
} else {
/* Skip to the last packet */
- while (p->next != NULL) p = p->next;
+ while (p->next != nullptr) p = p->next;
p->next = packet;
}
}
@@ -104,7 +104,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
if (!this->IsConnected()) return SPS_CLOSED;
p = this->packet_queue;
- while (p != NULL) {
+ while (p != nullptr) {
res = send(this->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
@@ -142,15 +142,15 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down)
/**
* Receives a packet for the given client
- * @return The received packet (or NULL when it didn't receive one)
+ * @return The received packet (or nullptr when it didn't receive one)
*/
Packet *NetworkTCPSocketHandler::ReceivePacket()
{
ssize_t res;
- if (!this->IsConnected()) return NULL;
+ if (!this->IsConnected()) return nullptr;
- if (this->packet_recv == NULL) {
+ if (this->packet_recv == nullptr) {
this->packet_recv = new Packet(this);
}
@@ -167,15 +167,15 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
/* Something went wrong... (104 is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err);
this->CloseConnection();
- return NULL;
+ return nullptr;
}
/* Connection would block, so stop for now */
- return NULL;
+ return nullptr;
}
if (res == 0) {
/* Client/server has left */
this->CloseConnection();
- return NULL;
+ return nullptr;
}
p->pos += res;
}
@@ -185,7 +185,7 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
if (p->size > SEND_MTU) {
this->CloseConnection();
- return NULL;
+ return nullptr;
}
}
@@ -198,22 +198,22 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
/* Something went wrong... (104 is connection reset by peer) */
if (err != 104) DEBUG(net, 0, "recv failed with error %d", err);
this->CloseConnection();
- return NULL;
+ return nullptr;
}
/* Connection would block */
- return NULL;
+ return nullptr;
}
if (res == 0) {
/* Client/server has left */
this->CloseConnection();
- return NULL;
+ return nullptr;
}
p->pos += res;
}
/* Prepare for receiving a new packet */
- this->packet_recv = NULL;
+ this->packet_recv = nullptr;
p->PrepareToRead();
return p;
@@ -236,7 +236,7 @@ bool NetworkTCPSocketHandler::CanSendReceive()
FD_SET(this->sock, &write_fd);
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
- if (select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv) < 0) return false;
+ if (select(FD_SETSIZE, &read_fd, &write_fd, nullptr, &tv) < 0) return false;
this->writable = !!FD_ISSET(this->sock, &write_fd);
return FD_ISSET(this->sock, &read_fd) != 0;
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index f9e1e00cb..451b93071 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -52,7 +52,7 @@ public:
* Whether there is something pending in the send queue.
* @return true when something is pending in the send queue.
*/
- bool HasSendQueue() { return this->packet_queue != NULL; }
+ bool HasSendQueue() { return this->packet_queue != nullptr; }
NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET);
~NetworkTCPSocketHandler();
diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp
index 226bae024..98ef0f0a0 100644
--- a/src/network/core/tcp_admin.cpp
+++ b/src/network/core/tcp_admin.cpp
@@ -115,7 +115,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
NetworkRecvStatus NetworkAdminSocketHandler::ReceivePackets()
{
Packet *p;
- while ((p = this->ReceivePacket()) != NULL) {
+ while ((p = this->ReceivePacket()) != nullptr) {
NetworkRecvStatus res = this->HandlePacket(p);
if (res != NETWORK_RECV_STATUS_OKAY) return res;
}
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index d923688b1..13330108a 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -33,7 +33,7 @@ TCPConnecter::TCPConnecter(const NetworkAddress &address) :
address(address)
{
_tcp_connecters.push_back(this);
- if (!StartNewThread(NULL, "ottd:tcp", &TCPConnecter::ThreadEntry, this)) {
+ if (!StartNewThread(nullptr, "ottd:tcp", &TCPConnecter::ThreadEntry, this)) {
this->Connect();
}
}
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp
index 8257a7252..ee8baf48e 100644
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -47,8 +47,8 @@ void ContentInfo::TransferFrom(ContentInfo *other)
free(this->dependencies);
free(this->tags);
memcpy(this, other, sizeof(ContentInfo));
- other->dependencies = NULL;
- other->tags = NULL;
+ other->dependencies = nullptr;
+ other->tags = nullptr;
}
}
@@ -98,11 +98,11 @@ bool ContentInfo::IsValid() const
/**
* Search a textfile file next to this file in the content list.
* @param type The type of the textfile to search for.
- * @return The filename for the textfile, \c NULL otherwise.
+ * @return The filename for the textfile, \c nullptr otherwise.
*/
const char *ContentInfo::GetTextfile(TextfileType type) const
{
- if (this->state == INVALID) return NULL;
+ if (this->state == INVALID) return nullptr;
const char *tmp;
switch (this->type) {
default: NOT_REACHED();
@@ -120,7 +120,7 @@ const char *ContentInfo::GetTextfile(TextfileType type) const
break;
case CONTENT_TYPE_NEWGRF: {
const GRFConfig *gc = FindGRFConfig(BSWAP32(this->unique_id), FGCM_EXACT, this->md5sum);
- tmp = gc != NULL ? gc->filename : NULL;
+ tmp = gc != nullptr ? gc->filename : nullptr;
break;
}
case CONTENT_TYPE_BASE_GRAPHICS:
@@ -138,7 +138,7 @@ const char *ContentInfo::GetTextfile(TextfileType type) const
tmp = FindScenario(this, true);
break;
}
- if (tmp == NULL) return NULL;
+ if (tmp == nullptr) return nullptr;
return ::GetTextfile(type, GetContentInfoSubDir(this->type), tmp);
}
#endif /* OPENTTD_MSU */
@@ -209,7 +209,7 @@ bool NetworkContentSocketHandler::ReceivePackets()
Packet *p;
static const int MAX_PACKETS_TO_RECEIVE = 42;
int i = MAX_PACKETS_TO_RECEIVE;
- while (--i != 0 && (p = this->ReceivePacket()) != NULL) {
+ while (--i != 0 && (p = this->ReceivePacket()) != nullptr) {
bool cont = this->HandlePacket(p);
delete p;
if (!cont) return true;
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index 2d8a74a11..6d69d10d2 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -26,7 +26,7 @@
* Create a new socket for the game connection.
* @param s The socket to connect with.
*/
-NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(NULL), client_id(INVALID_CLIENT_ID),
+NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(nullptr), client_id(INVALID_CLIENT_ID),
last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick)
{
this->sock = s;
@@ -134,7 +134,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets()
{
Packet *p;
- while ((p = this->ReceivePacket()) != NULL) {
+ while ((p = this->ReceivePacket()) != nullptr) {
NetworkRecvStatus res = HandlePacket(p);
delete p;
if (res != NETWORK_RECV_STATUS_OKAY) return res;
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index b392cf717..eb8881adc 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -130,12 +130,12 @@ struct CommandPacket;
/** A queue of CommandPackets. */
class CommandQueue {
CommandPacket *first; ///< The first packet in the queue.
- CommandPacket *last; ///< The last packet in the queue; only valid when first != NULL.
+ CommandPacket *last; ///< The last packet in the queue; only valid when first != nullptr.
uint count; ///< The number of items in the queue.
public:
/** Initialise the command queue. */
- CommandQueue() : first(NULL), last(NULL), count(0) {}
+ CommandQueue() : first(nullptr), last(nullptr), count(0) {}
/** Clear the command queue. */
~CommandQueue() { this->Free(); }
void Append(CommandPacket *p);
@@ -537,7 +537,7 @@ public:
*/
inline void SetInfo(NetworkClientInfo *info)
{
- assert(info != NULL && this->info == NULL);
+ assert(info != nullptr && this->info == nullptr);
this->info = info;
}
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp
index 3e9cc8141..116232402 100644
--- a/src/network/core/tcp_http.cpp
+++ b/src/network/core/tcp_http.cpp
@@ -43,11 +43,11 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s,
redirect_depth(depth),
sock(s)
{
- size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == NULL ? 0 : strlen(data)) + 128;
+ size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == nullptr ? 0 : strlen(data)) + 128;
char *buffer = AllocaM(char, bufferSize);
DEBUG(net, 7, "[tcp/http] requesting %s%s", host, url);
- if (data != NULL) {
+ if (data != nullptr) {
seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, GetNetworkRevisionString(), (int)strlen(data), data);
} else {
seprintf(buffer, buffer + bufferSize - 1, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\n\r\n", url, host, GetNetworkRevisionString());
@@ -108,7 +108,7 @@ static const char * const LOCATION = "Location: "; ///< Header for l
int NetworkHTTPSocketHandler::HandleHeader()
{
assert(strlen(HTTP_1_0) == strlen(HTTP_1_1));
- assert(strstr(this->recv_buffer, END_OF_HEADER) != NULL);
+ assert(strstr(this->recv_buffer, END_OF_HEADER) != nullptr);
/* We expect a HTTP/1.[01] reply */
if (strncmp(this->recv_buffer, HTTP_1_0, strlen(HTTP_1_0)) != 0 &&
@@ -122,7 +122,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
/* Get the length of the document to receive */
char *length = strcasestr(this->recv_buffer, CONTENT_LENGTH);
- if (length == NULL) return_error("[tcp/http] missing 'content-length' header");
+ if (length == nullptr) return_error("[tcp/http] missing 'content-length' header");
/* Skip the header */
length += strlen(CONTENT_LENGTH);
@@ -163,7 +163,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
/* Redirect to other URL */
char *uri = strcasestr(this->recv_buffer, LOCATION);
- if (uri == NULL) return_error("[tcp/http] missing 'location' header for redirect");
+ if (uri == nullptr) return_error("[tcp/http] missing 'location' header for redirect");
uri += strlen(LOCATION);
@@ -178,7 +178,7 @@ int NetworkHTTPSocketHandler::HandleHeader()
if (ret != 0) return ret;
/* We've relinquished control of data now. */
- this->data = NULL;
+ this->data = nullptr;
/* Restore the header. */
*end_of_line = '\r';
@@ -195,22 +195,22 @@ int NetworkHTTPSocketHandler::HandleHeader()
/* static */ int NetworkHTTPSocketHandler::Connect(char *uri, HTTPCallback *callback, const char *data, int depth)
{
char *hname = strstr(uri, "://");
- if (hname == NULL) return_error("[tcp/http] invalid location");
+ if (hname == nullptr) return_error("[tcp/http] invalid location");
hname += 3;
char *url = strchr(hname, '/');
- if (url == NULL) return_error("[tcp/http] invalid location");
+ if (url == nullptr) return_error("[tcp/http] invalid location");
*url = '\0';
/* Fetch the hostname, and possible port number. */
- const char *company = NULL;
- const char *port = NULL;
+ const char *company = nullptr;
+ const char *port = nullptr;
ParseConnectionString(&company, &port, hname);
- if (company != NULL) return_error("[tcp/http] invalid hostname");
+ if (company != nullptr) return_error("[tcp/http] invalid hostname");
- NetworkAddress address(hname, port == NULL ? 80 : atoi(port));
+ NetworkAddress address(hname, port == nullptr ? 80 : atoi(port));
/* Restore the URL. */
*url = '/';
@@ -246,7 +246,7 @@ int NetworkHTTPSocketHandler::Receive()
if (res == 0) {
if (this->recv_length != 0) return -1;
- this->callback->OnReceiveData(NULL, 0);
+ this->callback->OnReceiveData(nullptr, 0);
return 0;
}
@@ -261,7 +261,7 @@ int NetworkHTTPSocketHandler::Receive()
char *end_of_header = strstr(this->recv_buffer, END_OF_HEADER);
this->recv_buffer[end] = prev;
- if (end_of_header == NULL) {
+ if (end_of_header == nullptr) {
if (read == lengthof(this->recv_buffer)) {
DEBUG(net, 0, "[tcp/http] header too big");
return -1;
@@ -308,7 +308,7 @@ int NetworkHTTPSocketHandler::Receive()
}
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
- int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
+ int n = select(FD_SETSIZE, &read_fd, nullptr, nullptr, &tv);
if (n == -1) return;
for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) {
diff --git a/src/network/core/tcp_http.h b/src/network/core/tcp_http.h
index 5a5cdd9f2..001942ffb 100644
--- a/src/network/core/tcp_http.h
+++ b/src/network/core/tcp_http.h
@@ -26,9 +26,9 @@ struct HTTPCallback {
/**
* We're receiving data.
- * @param data the received data, NULL when all data has been received.
+ * @param data the received data, nullptr when all data has been received.
* @param length the amount of received data, 0 when all data has been received.
- * @note When NULL is sent the HTTP socket handler is closed/freed.
+ * @note When nullptr is sent the HTTP socket handler is closed/freed.
*/
virtual void OnReceiveData(const char *data, size_t length) = 0;
@@ -68,7 +68,7 @@ public:
~NetworkHTTPSocketHandler();
static int Connect(char *uri, HTTPCallback *callback,
- const char *data = NULL, int depth = 0);
+ const char *data = nullptr, int depth = 0);
static void HTTPReceive();
};
@@ -91,7 +91,7 @@ public:
*/
NetworkHTTPContentConnecter(const NetworkAddress &address,
HTTPCallback *callback, const char *url,
- const char *data = NULL, int depth = 0) :
+ const char *data = nullptr, int depth = 0) :
TCPConnecter(address),
callback(callback),
url(stredup(url)),
@@ -116,7 +116,7 @@ public:
{
new NetworkHTTPSocketHandler(s, this->callback, this->address.GetHostname(), this->url, this->data, this->depth);
/* We've relinquished control of data now. */
- this->data = NULL;
+ this->data = nullptr;
}
};
diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h
index 5668e48b2..28b6de8ac 100644
--- a/src/network/core/tcp_listen.h
+++ b/src/network/core/tcp_listen.h
@@ -116,7 +116,7 @@ public:
}
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
- if (select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv) < 0) return false;
+ if (select(FD_SETSIZE, &read_fd, &write_fd, nullptr, &tv) < 0) return false;
/* accept clients.. */
for (auto &s : sockets) {
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 70bb0b9f0..853b19e1a 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -24,12 +24,12 @@
*/
NetworkUDPSocketHandler::NetworkUDPSocketHandler(NetworkAddressList *bind)
{
- if (bind != NULL) {
+ if (bind != nullptr) {
for (NetworkAddress &addr : *bind) {
this->bind.push_back(addr);
}
} else {
- /* As hostname NULL and port 0/NULL don't go well when
+ /* As hostname nullptr and port 0/nullptr don't go well when
* resolving it we need to add an address for each of
* the address families we support. */
this->bind.emplace_back(nullptr, 0, AF_INET);
@@ -176,13 +176,13 @@ void NetworkUDPSocketHandler::SendNetworkGameInfo(Packet *p, const NetworkGameIn
uint count = 0;
/* Count number of GRFs to send information about */
- for (c = info->grfconfig; c != NULL; c = c->next) {
+ for (c = info->grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) count++;
}
p->Send_uint8 (count); // Send number of GRFs
/* Send actual GRF Identifications */
- for (c = info->grfconfig; c != NULL; c = c->next) {
+ for (c = info->grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) this->SendGRFIdentifier(p, &c->ident);
}
}
diff --git a/src/network/core/udp.h b/src/network/core/udp.h
index fab232492..9ed2705ef 100644
--- a/src/network/core/udp.h
+++ b/src/network/core/udp.h
@@ -229,7 +229,7 @@ protected:
*/
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); }
public:
- NetworkUDPSocketHandler(NetworkAddressList *bind = NULL);
+ NetworkUDPSocketHandler(NetworkAddressList *bind = nullptr);
/** On destructing of this class, the socket needs to be closed */
virtual ~NetworkUDPSocketHandler() { this->Close(); }
diff --git a/src/network/network.cpp b/src/network/network.cpp
index ab3884c56..0cc415192 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -57,7 +57,7 @@ bool _network_available; ///< is network mode available?
bool _network_dedicated; ///< are we a dedicated server?
bool _is_network_server; ///< Does this client wants to be a network-server?
NetworkServerGameInfo _network_game_info; ///< Information about our game.
-NetworkCompanyState *_network_company_states = NULL; ///< Statistics about some companies.
+NetworkCompanyState *_network_company_states = nullptr; ///< Statistics about some companies.
ClientID _network_own_client_id; ///< Our client identifier.
ClientID _redirect_console_to_client; ///< If not invalid, redirect the console output to a client.
bool _network_need_advertise; ///< Whether we need to advertise.
@@ -119,7 +119,7 @@ NetworkClientInfo::~NetworkClientInfo()
/**
* Return the CI given it's client-identifier
* @param client_id the ClientID to search for
- * @return return a pointer to the corresponding NetworkClientInfo struct or NULL when not found
+ * @return return a pointer to the corresponding NetworkClientInfo struct or nullptr when not found
*/
/* static */ NetworkClientInfo *NetworkClientInfo::GetByClientID(ClientID client_id)
{
@@ -129,13 +129,13 @@ NetworkClientInfo::~NetworkClientInfo()
if (ci->client_id == client_id) return ci;
}
- return NULL;
+ return nullptr;
}
/**
* Return the client state given it's client-identifier
* @param client_id the ClientID to search for
- * @return return a pointer to the corresponding NetworkClientSocket struct or NULL when not found
+ * @return return a pointer to the corresponding NetworkClientSocket struct or nullptr when not found
*/
/* static */ ServerNetworkGameSocketHandler *ServerNetworkGameSocketHandler::GetByClientID(ClientID client_id)
{
@@ -145,7 +145,7 @@ NetworkClientInfo::~NetworkClientInfo()
if (cs->client_id == client_id) return cs;
}
- return NULL;
+ return nullptr;
}
byte NetworkSpectatorCount()
@@ -378,7 +378,7 @@ void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode)
char buffer[DRAW_STRING_BUFFER];
GetString(buffer, str, lastof(buffer));
- NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, NULL, buffer);
+ NetworkTextMessage(NETWORK_ACTION_SERVER_MESSAGE, CC_DEFAULT, false, nullptr, buffer);
break;
}
@@ -541,7 +541,7 @@ void NetworkClose(bool close_admins)
}
ServerNetworkGameSocketHandler::CloseListeners();
ServerNetworkAdminSocketHandler::CloseListeners();
- } else if (MyClient::my_client != NULL) {
+ } else if (MyClient::my_client != nullptr) {
MyClient::SendQuit();
MyClient::my_client->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
}
@@ -554,7 +554,7 @@ void NetworkClose(bool close_admins)
NetworkFreeLocalCommandQueue();
free(_network_company_states);
- _network_company_states = NULL;
+ _network_company_states = nullptr;
InitializeNetworkPools(close_admins);
}
@@ -608,8 +608,8 @@ void NetworkTCPQueryServer(NetworkAddress address)
void NetworkAddServer(const char *b)
{
if (*b != '\0') {
- const char *port = NULL;
- const char *company = NULL;
+ const char *port = nullptr;
+ const char *company = nullptr;
char host[NETWORK_HOSTNAME_LENGTH];
uint16 rport;
@@ -619,7 +619,7 @@ void NetworkAddServer(const char *b)
rport = NETWORK_DEFAULT_PORT;
ParseConnectionString(&company, &port, host);
- if (port != NULL) rport = atoi(port);
+ if (port != nullptr) rport = atoi(port);
NetworkUDPQueryServer(NetworkAddress(host, rport), true);
}
@@ -649,7 +649,7 @@ void NetworkRebuildHostList()
{
_network_host_list.clear();
- for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
+ for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
if (item->manually) _network_host_list.emplace_back(item->address.GetAddressAsString(false));
}
}
@@ -884,21 +884,21 @@ void NetworkGameLoop()
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
static Date next_date = 0;
static uint32 next_date_fract;
- static CommandPacket *cp = NULL;
+ static CommandPacket *cp = nullptr;
static bool check_sync_state = false;
static uint32 sync_state[2];
- if (f == NULL && next_date == 0) {
+ if (f == nullptr && next_date == 0) {
DEBUG(net, 0, "Cannot open commands.log");
next_date = 1;
}
- while (f != NULL && !feof(f)) {
+ while (f != nullptr && !feof(f)) {
if (_date == next_date && _date_fract == next_date_fract) {
- if (cp != NULL) {
- NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, NULL, cp->text, cp->company);
+ if (cp != nullptr) {
+ NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, nullptr, cp->text, cp->company);
DEBUG(net, 0, "injecting: %08x; %02x; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, (int)_current_company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text, GetCommandName(cp->cmd));
free(cp);
- cp = NULL;
+ cp = nullptr;
}
if (check_sync_state) {
if (sync_state[0] == _random.state[0] && sync_state[1] == _random.state[1]) {
@@ -912,16 +912,16 @@ void NetworkGameLoop()
}
}
- if (cp != NULL || check_sync_state) break;
+ if (cp != nullptr || check_sync_state) break;
char buff[4096];
- if (fgets(buff, lengthof(buff), f) == NULL) break;
+ if (fgets(buff, lengthof(buff), f) == nullptr) break;
char *p = buff;
/* Ignore the "[date time] " part of the message */
if (*p == '[') {
p = strchr(p, ']');
- if (p == NULL) break;
+ if (p == nullptr) break;
p += 2;
}
@@ -968,10 +968,10 @@ void NetworkGameLoop()
NOT_REACHED();
}
}
- if (f != NULL && feof(f)) {
+ if (f != nullptr && feof(f)) {
DEBUG(net, 0, "End of commands.log");
fclose(f);
- f = NULL;
+ f = nullptr;
}
#endif /* DEBUG_DUMP_COMMANDS */
if (_frame_counter >= _frame_counter_max) {
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 73ad0e192..9c5c43ab5 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -234,12 +234,12 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin(ClientID clien
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
{
/* Only send data when we're a proper client, not just someone trying to query the server. */
- if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
+ if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY;
Packet *p = new Packet(ADMIN_PACKET_SERVER_CLIENT_INFO);
p->Send_uint32(ci->client_id);
- p->Send_string(cs == NULL ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
+ p->Send_string(cs == nullptr ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
p->Send_string(ci->client_name);
p->Send_uint8 (ci->client_lang);
p->Send_uint32(ci->join_date);
@@ -734,16 +734,16 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
/* The admin is requesting client info. */
const NetworkClientSocket *cs;
if (d1 == UINT32_MAX) {
- this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
+ this->SendClientInfo(nullptr, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
FOR_ALL_CLIENT_SOCKETS(cs) {
this->SendClientInfo(cs, cs->GetInfo());
}
} else {
if (d1 == CLIENT_ID_SERVER) {
- this->SendClientInfo(NULL, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
+ this->SendClientInfo(nullptr, NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER));
} else {
cs = NetworkClientSocket::GetByClientID((ClientID)d1);
- if (cs != NULL) this->SendClientInfo(cs, cs->GetInfo());
+ if (cs != nullptr) this->SendClientInfo(cs, cs->GetInfo());
}
}
break;
@@ -757,7 +757,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
}
} else {
company = Company::GetIfValid(d1);
- if (company != NULL) this->SendCompanyInfo(company);
+ if (company != nullptr) this->SendCompanyInfo(company);
}
break;
@@ -884,7 +884,7 @@ void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
*/
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
{
- if (company == NULL) {
+ if (company == nullptr) {
DEBUG(net, 1, "[admin] Empty company given for update");
return;
}
@@ -906,7 +906,7 @@ void NetworkAdminCompanyInfo(const Company *company, bool new_company)
*/
void NetworkAdminCompanyUpdate(const Company *company)
{
- if (company == NULL) return;
+ if (company == nullptr) return;
ServerNetworkAdminSocketHandler *as;
FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
@@ -992,7 +992,7 @@ void NetworkAdminGameScript(const char *json)
*/
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
{
- ClientID client_id = owner == NULL ? _network_own_client_id : owner->client_id;
+ ClientID client_id = owner == nullptr ? _network_own_client_id : owner->client_id;
ServerNetworkAdminSocketHandler *as;
FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 21607e9e8..e7e22db99 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -46,7 +46,7 @@ struct ChatMessage {
};
/* used for chat window */
-static ChatMessage *_chatmsg_list = NULL; ///< The actual chat message list.
+static ChatMessage *_chatmsg_list = nullptr; ///< The actual chat message list.
static bool _chatmessage_dirty = false; ///< Does the chat message need repainting?
static bool _chatmessage_visible = false; ///< Is a chat message visible.
static bool _chat_tab_completion_active; ///< Whether tab completion is active.
@@ -57,7 +57,7 @@ static uint MAX_CHAT_MESSAGES = 0; ///< The limit of chat messages to sho
* the left and pixels from the bottom. The height is the maximum height.
*/
static PointDimension _chatmsg_box;
-static uint8 *_chatmessage_backup = NULL; ///< Backup in case text is moved.
+static uint8 *_chatmessage_backup = nullptr; ///< Backup in case text is moved.
/**
* Count the chat messages.
@@ -360,7 +360,7 @@ struct NetworkChatWindow : public Window {
}
}
- return NULL;
+ return nullptr;
}
/**
@@ -371,7 +371,7 @@ struct NetworkChatWindow : public Window {
static char *ChatTabCompletionFindText(char *buf)
{
char *p = strrchr(buf, ' ');
- if (p == NULL) return buf;
+ if (p == nullptr) return buf;
*p = '\0';
return p + 1;
@@ -400,7 +400,7 @@ struct NetworkChatWindow : public Window {
tb_buf = ChatTabCompletionFindText(pre_buf);
tb_len = strlen(tb_buf);
- while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) {
+ while ((cur_name = ChatTabCompletionNextItem(&item)) != nullptr) {
item++;
if (_chat_tab_completion_active) {
@@ -543,7 +543,7 @@ static const NWidgetPart _nested_chat_window_widgets[] = {
/** The description of the chat window. */
static WindowDesc _chat_window_desc(
- WDP_MANUAL, NULL, 0, 0,
+ WDP_MANUAL, nullptr, 0, 0,
WC_SEND_NETWORK_MSG, WC_NONE,
0,
_nested_chat_window_widgets, lengthof(_nested_chat_window_widgets)
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 4dc5a8041..7ebbdef51 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -50,7 +50,7 @@ struct PacketReader : LoadFilter {
size_t read_bytes; ///< The total number of read bytes.
/** Initialise everything. */
- PacketReader() : LoadFilter(NULL), buf(NULL), bufe(NULL), block(NULL), written_bytes(0), read_bytes(0)
+ PacketReader() : LoadFilter(nullptr), buf(nullptr), bufe(nullptr), block(nullptr), written_bytes(0), read_bytes(0)
{
}
@@ -143,9 +143,9 @@ void ClientNetworkEmergencySave()
* Create a new socket for the client side of the game connection.
* @param s The socket to connect with.
*/
-ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s), savegame(NULL), status(STATUS_INACTIVE)
+ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s), savegame(nullptr), status(STATUS_INACTIVE)
{
- assert(ClientNetworkGameSocketHandler::my_client == NULL);
+ assert(ClientNetworkGameSocketHandler::my_client == nullptr);
ClientNetworkGameSocketHandler::my_client = this;
}
@@ -153,7 +153,7 @@ ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler(SOCKET s) : Netwo
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
{
assert(ClientNetworkGameSocketHandler::my_client == this);
- ClientNetworkGameSocketHandler::my_client = NULL;
+ ClientNetworkGameSocketHandler::my_client = nullptr;
delete this->savegame;
}
@@ -301,7 +301,7 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
/** Our client's connection. */
-ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = NULL;
+ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = nullptr;
/** Last frame we performed an ack. */
static uint32 last_ack_frame;
@@ -320,9 +320,9 @@ static uint8 _network_server_max_spectators;
CompanyID _network_join_as;
/** Login password from -p argument */
-const char *_network_join_server_password = NULL;
+const char *_network_join_server_password = nullptr;
/** Company password from -P argument */
-const char *_network_join_company_password = NULL;
+const char *_network_join_company_password = nullptr;
/** Make sure the server ID length is the same as a md5 hash. */
assert_compile(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
@@ -533,7 +533,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, co
*/
bool ClientNetworkGameSocketHandler::IsConnected()
{
- return my_client != NULL && my_client->status == STATUS_ACTIVE;
+ return my_client != nullptr && my_client->status == STATUS_ACTIVE;
}
@@ -542,7 +542,7 @@ bool ClientNetworkGameSocketHandler::IsConnected()
* DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
************/
-extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL);
+extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
{
@@ -576,7 +576,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO(Pa
if (current >= MAX_COMPANIES) return NETWORK_RECV_STATUS_CLOSE_QUERY;
NetworkCompanyInfo *company_info = GetLobbyCompanyInfo(current);
- if (company_info == NULL) return NETWORK_RECV_STATUS_CLOSE_QUERY;
+ if (company_info == nullptr) return NETWORK_RECV_STATUS_CLOSE_QUERY;
p->Recv_string(company_info->company_name, sizeof(company_info->company_name));
company_info->inaugurated_year = p->Recv_uint32();
@@ -619,7 +619,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(Pac
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci != NULL) {
+ if (ci != nullptr) {
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
/* Client name changed, display the change */
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, name);
@@ -714,7 +714,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(P
/* Check whether we know this GRF */
const GRFConfig *f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
- if (f == NULL) {
+ if (f == nullptr) {
/* We do not know this GRF, bail out of initialization */
char buf[sizeof(c.md5sum) * 2 + 1];
md5sumToString(buf, lastof(buf), c.md5sum);
@@ -800,7 +800,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe
if (this->status < STATUS_AUTHORIZED || this->status >= STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
this->status = STATUS_MAP;
- if (this->savegame != NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ if (this->savegame != nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
this->savegame = new PacketReader();
@@ -818,7 +818,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN(Packe
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet *p)
{
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
- if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
_network_join_bytes_total = p->Recv_uint32();
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
@@ -829,7 +829,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_SIZE(Packet
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet *p)
{
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
- if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
/* We are still receiving data, put it to the file */
this->savegame->AddPacket(p);
@@ -843,7 +843,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DATA(Packet
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet *p)
{
if (this->status != STATUS_MAP) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
- if (this->savegame == NULL) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
+ if (this->savegame == nullptr) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
_network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
@@ -856,12 +856,12 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
* game, which would cause us to free this->savegame twice.
*/
LoadFilter *lf = this->savegame;
- this->savegame = NULL;
+ this->savegame = nullptr;
lf->Reset();
/* The map is done downloading, load it */
ClearErrorMessages();
- bool load_success = SafeLoad(NULL, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
+ bool load_success = SafeLoad(nullptr, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
/* Long savegame loads shouldn't affect the lag calculation! */
this->last_packet = _realtime_tick;
@@ -887,7 +887,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
* the server will give us a client-id and let us in */
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
ShowJoinStatusWindow();
- NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
+ NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
}
} else {
/* take control over an existing company */
@@ -952,7 +952,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet
cp.frame = p->Recv_uint32();
cp.my_cmd = p->Recv_bool();
- if (err != NULL) {
+ if (err != nullptr) {
IConsolePrintF(CC_ERROR, "WARNING: %s from server, dropping...", err);
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
@@ -967,7 +967,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
char name[NETWORK_NAME_LENGTH], msg[NETWORK_CHAT_LENGTH];
- const NetworkClientInfo *ci = NULL, *ci_to;
+ const NetworkClientInfo *ci = nullptr, *ci_to;
NetworkAction action = (NetworkAction)p->Recv_uint8();
ClientID client_id = (ClientID)p->Recv_uint32();
@@ -976,7 +976,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
int64 data = p->Recv_uint64();
ci_to = NetworkClientInfo::GetByClientID(client_id);
- if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
+ if (ci_to == nullptr) return NETWORK_RECV_STATUS_OKAY;
/* Did we initiate the action locally? */
if (self_send) {
@@ -1009,7 +1009,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
ci = ci_to;
}
- if (ci != NULL) {
+ if (ci != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), self_send, name, msg, data);
}
return NETWORK_RECV_STATUS_OKAY;
@@ -1022,8 +1022,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Pack
ClientID client_id = (ClientID)p->Recv_uint32();
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci != NULL) {
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
+ if (ci != nullptr) {
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
delete ci;
}
@@ -1039,8 +1039,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(Packet *p)
ClientID client_id = (ClientID)p->Recv_uint32();
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci != NULL) {
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
+ if (ci != nullptr) {
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
delete ci;
} else {
DEBUG(net, 0, "Unknown client (%d) is leaving the game", client_id);
@@ -1059,7 +1059,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(Packet *p)
ClientID client_id = (ClientID)p->Recv_uint32();
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci != NULL) {
+ if (ci != nullptr) {
NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name);
}
@@ -1129,7 +1129,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p)
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
/* Just make sure we do not try to use a client_index that does not exist */
- if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
+ if (ci == nullptr) return NETWORK_RECV_STATUS_OKAY;
/* if not valid player, force spectator, else check player exists */
if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
@@ -1253,7 +1253,7 @@ void NetworkUpdateClientName()
{
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
- if (ci == NULL) return;
+ if (ci == nullptr) return;
/* Don't change the name if it is the same as the old name */
if (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp
index 51317288e..472215a63 100644
--- a/src/network/network_command.cpp
+++ b/src/network/network_command.cpp
@@ -21,7 +21,7 @@
/** Table with all the callbacks we'll use for conversion*/
static CommandCallback * const _callback_table[] = {
- /* 0x00 */ NULL,
+ /* 0x00 */ nullptr,
/* 0x01 */ CcBuildPrimaryVehicle,
/* 0x02 */ CcBuildAirport,
/* 0x03 */ CcBuildBridge,
@@ -60,8 +60,8 @@ void CommandQueue::Append(CommandPacket *p)
{
CommandPacket *add = MallocT<CommandPacket>(1);
*add = *p;
- add->next = NULL;
- if (this->first == NULL) {
+ add->next = nullptr;
+ if (this->first == nullptr) {
this->first = add;
} else {
this->last->next = add;
@@ -79,15 +79,15 @@ CommandPacket *CommandQueue::Pop(bool ignore_paused)
{
CommandPacket **prev = &this->first;
CommandPacket *ret = this->first;
- CommandPacket *prev_item = NULL;
+ CommandPacket *prev_item = nullptr;
if (ignore_paused && _pause_mode != PM_UNPAUSED) {
- while (ret != NULL && !IsCommandAllowedWhilePaused(ret->cmd)) {
+ while (ret != nullptr && !IsCommandAllowedWhilePaused(ret->cmd)) {
prev_item = ret;
prev = &ret->next;
ret = ret->next;
}
}
- if (ret != NULL) {
+ if (ret != nullptr) {
if (ret == this->last) this->last = prev_item;
*prev = ret->next;
this->count--;
@@ -104,17 +104,17 @@ CommandPacket *CommandQueue::Peek(bool ignore_paused)
{
if (!ignore_paused || _pause_mode == PM_UNPAUSED) return this->first;
- for (CommandPacket *p = this->first; p != NULL; p = p->next) {
+ for (CommandPacket *p = this->first; p != nullptr; p = p->next) {
if (IsCommandAllowedWhilePaused(p->cmd)) return p;
}
- return NULL;
+ return nullptr;
}
/** Free everything that is in the queue. */
void CommandQueue::Free()
{
CommandPacket *cp;
- while ((cp = this->Pop()) != NULL) {
+ while ((cp = this->Pop()) != nullptr) {
free(cp);
}
assert(this->count == 0);
@@ -147,7 +147,7 @@ void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comman
c.cmd = cmd;
c.callback = callback;
- strecpy(c.text, (text != NULL) ? text : "", lastof(c.text));
+ strecpy(c.text, (text != nullptr) ? text : "", lastof(c.text));
if (_network_server) {
/* If we are the server, we queue the command in our 'special' queue.
@@ -180,7 +180,7 @@ void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comman
*/
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
{
- for (CommandPacket *p = _local_execution_queue.Peek(); p != NULL; p = p->next) {
+ for (CommandPacket *p = _local_execution_queue.Peek(); p != nullptr; p = p->next) {
CommandPacket c = *p;
c.callback = 0;
cs->outgoing_queue.Append(&c);
@@ -197,7 +197,7 @@ void NetworkExecuteLocalCommandQueue()
CommandQueue &queue = (_network_server ? _local_execution_queue : ClientNetworkGameSocketHandler::my_client->incoming_queue);
CommandPacket *cp;
- while ((cp = queue.Peek()) != NULL) {
+ while ((cp = queue.Peek()) != nullptr) {
/* The queue is always in order, which means
* that the first element will be executed first. */
if (_frame_counter < cp->frame) break;
@@ -245,13 +245,13 @@ static void DistributeCommandPacket(CommandPacket &cp, const NetworkClientSocket
if (cs->status >= NetworkClientSocket::STATUS_MAP) {
/* Callbacks are only send back to the client who sent them in the
* first place. This filters that out. */
- cp.callback = (cs != owner) ? NULL : callback;
+ cp.callback = (cs != owner) ? nullptr : callback;
cp.my_cmd = (cs == owner);
cs->outgoing_queue.Append(&cp);
}
}
- cp.callback = (cs != owner) ? NULL : callback;
+ cp.callback = (cs != owner) ? nullptr : callback;
cp.my_cmd = (cs == owner);
_local_execution_queue.Append(&cp);
}
@@ -271,7 +271,7 @@ static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owne
#endif
CommandPacket *cp;
- while (--to_go >= 0 && (cp = queue->Pop(true)) != NULL) {
+ while (--to_go >= 0 && (cp = queue->Pop(true)) != nullptr) {
DistributeCommandPacket(*cp, owner);
NetworkAdminCmdLogging(owner, cp);
free(cp);
@@ -282,7 +282,7 @@ static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owne
void NetworkDistributeCommands()
{
/* First send the server's commands. */
- DistributeQueue(&_local_wait_queue, NULL);
+ DistributeQueue(&_local_wait_queue, nullptr);
/* Then send the queues of the others. */
NetworkClientSocket *cs;
@@ -295,7 +295,7 @@ void NetworkDistributeCommands()
* Receives a command from the network.
* @param p the packet to read from.
* @param cp the struct to write the data to.
- * @return an error message. When NULL there has been no error.
+ * @return an error message. When nullptr there has been no error.
*/
const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *cp)
{
@@ -314,7 +314,7 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *c
if (callback >= lengthof(_callback_table)) return "invalid callback";
cp->callback = _callback_table[callback];
- return NULL;
+ return nullptr;
}
/**
@@ -338,7 +338,7 @@ void NetworkGameSocketHandler::SendCommand(Packet *p, const CommandPacket *cp)
if (callback == lengthof(_callback_table)) {
DEBUG(net, 0, "Unknown callback. (Pointer: %p) No callback sent", cp->callback);
- callback = 0; // _callback_table[0] == NULL
+ callback = 0; // _callback_table[0] == nullptr
}
p->Send_uint8 (callback);
}
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 168ecd429..8768d314e 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -35,7 +35,7 @@ ClientNetworkContentSocketHandler _network_content_client;
/** Wrapper function for the HasProc */
static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
{
- return FindGRFConfig(BSWAP32(ci->unique_id), md5sum ? FGCM_EXACT : FGCM_ANY, md5sum ? ci->md5sum : NULL) != NULL;
+ return FindGRFConfig(BSWAP32(ci->unique_id), md5sum ? FGCM_EXACT : FGCM_ANY, md5sum ? ci->md5sum : nullptr) != nullptr;
}
/**
@@ -79,7 +79,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
}
/* Find the appropriate check function */
- HasProc proc = NULL;
+ HasProc proc = nullptr;
switch (ci->type) {
case CONTENT_TYPE_NEWGRF:
proc = HasGRFConfig;
@@ -122,7 +122,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
break;
}
- if (proc != NULL) {
+ if (proc != nullptr) {
if (proc(ci, true)) {
ci->state = ContentInfo::ALREADY_HERE;
} else {
@@ -241,7 +241,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con
*/
void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bool send_md5sum)
{
- if (cv == NULL) return;
+ if (cv == nullptr) return;
this->Connect();
@@ -374,12 +374,12 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
* @param ci the information to get the filename from
* @param compressed should the filename end with .gz?
* @return a statically allocated buffer with the filename or
- * NULL when no filename could be made.
+ * nullptr when no filename could be made.
*/
static char *GetFullFilename(const ContentInfo *ci, bool compressed)
{
Subdirectory dir = GetContentInfoSubDir(ci->type);
- if (dir == NO_DIRECTORY) return NULL;
+ if (dir == NO_DIRECTORY) return nullptr;
static char buf[MAX_PATH];
FioGetFullPath(buf, lastof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename);
@@ -400,14 +400,14 @@ static bool GunzipFile(const ContentInfo *ci)
/* Need to open the file with fopen() to support non-ASCII on Windows. */
FILE *ftmp = fopen(GetFullFilename(ci, true), "rb");
- if (ftmp == NULL) return false;
+ if (ftmp == nullptr) return false;
/* Duplicate the handle, and close the FILE*, to avoid double-closing the handle later. */
gzFile fin = gzdopen(dup(fileno(ftmp)), "rb");
fclose(ftmp);
FILE *fout = fopen(GetFullFilename(ci, false), "wb");
- if (fin == NULL || fout == NULL) {
+ if (fin == nullptr || fout == nullptr) {
ret = false;
} else {
byte buff[8192];
@@ -441,8 +441,8 @@ static bool GunzipFile(const ContentInfo *ci)
}
}
- if (fin != NULL) gzclose(fin);
- if (fout != NULL) fclose(fout);
+ if (fin != nullptr) gzclose(fin);
+ if (fout != nullptr) fclose(fout);
return ret;
#else
@@ -452,7 +452,7 @@ static bool GunzipFile(const ContentInfo *ci)
bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
{
- if (this->curFile == NULL) {
+ if (this->curFile == nullptr) {
delete this->curInfo;
/* When we haven't opened a file this must be our first packet with metadata. */
this->curInfo = new ContentInfo;
@@ -473,7 +473,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
this->Close();
fclose(this->curFile);
- this->curFile = NULL;
+ this->curFile = nullptr;
return false;
}
@@ -494,14 +494,14 @@ bool ClientNetworkContentSocketHandler::BeforeDownload()
{
if (!this->curInfo->IsValid()) {
delete this->curInfo;
- this->curInfo = NULL;
+ this->curInfo = nullptr;
return false;
}
if (this->curInfo->filesize != 0) {
/* The filesize is > 0, so we are going to download it */
const char *filename = GetFullFilename(this->curInfo, true);
- if (filename == NULL || (this->curFile = fopen(filename, "wb")) == NULL) {
+ if (filename == nullptr || (this->curFile = fopen(filename, "wb")) == nullptr) {
/* Unless that fails of course... */
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
@@ -520,7 +520,7 @@ void ClientNetworkContentSocketHandler::AfterDownload()
/* We read nothing; that's our marker for end-of-stream.
* Now gunzip the tar and make it known. */
fclose(this->curFile);
- this->curFile = NULL;
+ this->curFile = nullptr;
if (GunzipFile(this->curInfo)) {
unlink(GetFullFilename(this->curInfo, true));
@@ -554,25 +554,25 @@ void ClientNetworkContentSocketHandler::OnFailure()
this->http_response.shrink_to_fit();
this->http_response_index = -2;
- if (this->curFile != NULL) {
+ if (this->curFile != nullptr) {
/* Revert the download progress when we are going for the old system. */
long size = ftell(this->curFile);
if (size > 0) this->OnDownloadProgress(this->curInfo, (int)-size);
fclose(this->curFile);
- this->curFile = NULL;
+ this->curFile = nullptr;
}
}
void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t length)
{
- assert(data == NULL || length != 0);
+ assert(data == nullptr || length != 0);
/* Ignore any latent data coming from a connection we closed. */
if (this->http_response_index == -2) return;
if (this->http_response_index == -1) {
- if (data != NULL) {
+ if (data != nullptr) {
/* Append the rest of the response. */
memcpy(grow(this->http_response, (uint)length), data, length);
return;
@@ -585,7 +585,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
}
}
- if (data != NULL) {
+ if (data != nullptr) {
/* We have data, so write it to the file. */
if (fwrite(data, 1, length, this->curFile) != length) {
/* Writing failed somehow, let try via the old method. */
@@ -598,7 +598,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
return;
}
- if (this->curFile != NULL) {
+ if (this->curFile != nullptr) {
/* We've finished downloading a file. */
this->AfterDownload();
}
@@ -616,7 +616,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
this->curInfo = new ContentInfo;
/** Check p for not being null and return calling OnFailure if that's not the case. */
-#define check_not_null(p) { if ((p) == NULL) { this->OnFailure(); return; } }
+#define check_not_null(p) { if ((p) == nullptr) { this->OnFailure(); return; } }
/** Check p for not being null and then terminate, or return calling OnFailure. */
#define check_and_terminate(p) { check_not_null(p); *(p) = '\0'; }
@@ -695,8 +695,8 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
ClientNetworkContentSocketHandler::ClientNetworkContentSocketHandler() :
NetworkContentSocketHandler(),
http_response_index(-2),
- curFile(NULL),
- curInfo(NULL),
+ curFile(nullptr),
+ curInfo(nullptr),
isConnecting(false),
lastActivity(_realtime_tick)
{
@@ -706,7 +706,7 @@ ClientNetworkContentSocketHandler::ClientNetworkContentSocketHandler() :
ClientNetworkContentSocketHandler::~ClientNetworkContentSocketHandler()
{
delete this->curInfo;
- if (this->curFile != NULL) fclose(this->curFile);
+ if (this->curFile != nullptr) fclose(this->curFile);
for (ContentInfo *ci : this->infos) delete ci;
}
@@ -798,14 +798,14 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
/**
* Get the content info based on a ContentID
* @param cid the ContentID to search for
- * @return the ContentInfo or NULL if not found
+ * @return the ContentInfo or nullptr if not found
*/
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
{
for (ContentInfo *ci : this->infos) {
if (ci->id == cid) return ci;
}
- return NULL;
+ return nullptr;
}
@@ -816,7 +816,7 @@ ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
void ClientNetworkContentSocketHandler::Select(ContentID cid)
{
ContentInfo *ci = this->GetContent(cid);
- if (ci == NULL || ci->state != ContentInfo::UNSELECTED) return;
+ if (ci == nullptr || ci->state != ContentInfo::UNSELECTED) return;
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -829,7 +829,7 @@ void ClientNetworkContentSocketHandler::Select(ContentID cid)
void ClientNetworkContentSocketHandler::Unselect(ContentID cid)
{
ContentInfo *ci = this->GetContent(cid);
- if (ci == NULL || !ci->IsSelected()) return;
+ if (ci == nullptr || !ci->IsSelected()) return;
ci->state = ContentInfo::UNSELECTED;
this->CheckDependencyState(ci);
@@ -937,7 +937,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* selected and thus can unselect when a dependency is removed. */
for (uint i = 0; i < ci->dependency_count; i++) {
ContentInfo *c = this->GetContent(ci->dependencies[i]);
- if (c == NULL) {
+ if (c == nullptr) {
this->DownloadContentInfo(ci->dependencies[i]);
} else if (c->state == ContentInfo::UNSELECTED) {
c->state = ContentInfo::AUTOSELECTED;
@@ -963,7 +963,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
for (uint i = 0; i < ci->dependency_count; i++) {
const ContentInfo *c = this->GetContent(ci->dependencies[i]);
- if (c == NULL) {
+ if (c == nullptr) {
DownloadContentInfo(ci->dependencies[i]);
continue;
}
@@ -1068,7 +1068,7 @@ void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci
void ClientNetworkContentSocketHandler::OnDownloadComplete(ContentID cid)
{
ContentInfo *ci = this->GetContent(cid);
- if (ci != NULL) {
+ if (ci != nullptr) {
ci->state = ContentInfo::ALREADY_HERE;
}
diff --git a/src/network/network_content.h b/src/network/network_content.h
index fb81925d2..b65321e0f 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -147,7 +147,7 @@ public:
extern ClientNetworkContentSocketHandler _network_content_client;
-void ShowNetworkContentListWindow(ContentVector *cv = NULL, ContentType type1 = CONTENT_TYPE_END, ContentType type2 = CONTENT_TYPE_END);
+void ShowNetworkContentListWindow(ContentVector *cv = nullptr, ContentType type1 = CONTENT_TYPE_END, ContentType type2 = CONTENT_TYPE_END);
void ShowMissingContentWindow(const struct GRFConfig *list);
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index b2e0dd795..f3eb597a6 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -95,7 +95,7 @@ static const NWidgetPart _nested_network_content_download_status_window_widgets[
/** Window description for the download window */
static WindowDesc _network_content_download_status_window_desc(
- WDP_CENTER, NULL, 0, 0,
+ WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_STATUS_WINDOW, WC_NONE,
WDF_MODAL,
_nested_network_content_download_status_window_widgets, lengthof(_nested_network_content_download_status_window_widgets)
@@ -238,7 +238,7 @@ public:
break;
case CONTENT_TYPE_NEWGRF:
- ScanNewGRFFiles(NULL);
+ ScanNewGRFFiles(nullptr);
break;
case CONTENT_TYPE_SCENARIO:
@@ -480,7 +480,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
}
/* previously selected item not in list anymore */
- this->selected = NULL;
+ this->selected = nullptr;
this->list_pos = 0;
}
@@ -501,7 +501,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
/** Make sure that the currently selected content info is within the visible part of the matrix */
void ScrollToSelected()
{
- if (this->selected == NULL) return;
+ if (this->selected == nullptr) return;
this->vscroll->ScrollTowards(this->list_pos);
}
@@ -521,7 +521,7 @@ public:
Window(desc),
auto_select(select_all),
filter_editbox(EDITBOX_MAX_SIZE),
- selected(NULL),
+ selected(nullptr),
list_pos(0)
{
this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT));
@@ -685,7 +685,7 @@ public:
SetDParam(0, this->filesize_sum);
DrawString(r.left + DETAIL_LEFT, r.right - DETAIL_RIGHT, r.bottom - FONT_HEIGHT_NORMAL - WD_PAR_VSEP_NORMAL, STR_CONTENT_TOTAL_DOWNLOAD_SIZE);
- if (this->selected == NULL) return;
+ if (this->selected == nullptr) return;
/* And fill the rest of the details when there's information to place there */
DrawStringMultiLine(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + DETAIL_TITLE_HEIGHT / 2, r.top + DETAIL_TITLE_HEIGHT, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, TC_FROMSTRING, SA_CENTER);
@@ -779,7 +779,7 @@ public:
void OnClick(Point pt, int widget, int click_count) override
{
if (widget >= WID_NCL_TEXTFILE && widget < WID_NCL_TEXTFILE + TFT_END) {
- if (this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE) return;
+ if (this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE) return;
ShowContentTextfileWindow((TextfileType)(widget - WID_NCL_TEXTFILE), this->selected);
return;
@@ -842,14 +842,14 @@ public:
break;
case WID_NCL_OPEN_URL:
- if (this->selected != NULL) {
+ if (this->selected != nullptr) {
extern void OpenBrowser(const char *url);
OpenBrowser(this->selected->url);
}
break;
case WID_NCL_DOWNLOAD:
- if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == NULL) new NetworkContentDownloadStatusWindow();
+ if (BringWindowToFrontById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) == nullptr) new NetworkContentDownloadStatusWindow();
break;
case WID_NCL_SEARCH_EXTERNAL:
@@ -893,7 +893,7 @@ public:
case WKC_SPACE:
case WKC_RETURN:
if (keycode == WKC_RETURN || !IsWidgetFocused(WID_NCL_FILTER)) {
- if (this->selected != NULL) {
+ if (this->selected != nullptr) {
_network_content_client.ToggleSelectedState(this->selected);
this->content.ForceResort();
this->InvalidateData();
@@ -1005,13 +1005,13 @@ public:
}
/* If data == 2 then the status window caused this OnInvalidate */
- this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != NULL && data != 2));
+ this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != nullptr && data != 2));
this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
- this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == NULL || StrEmpty(this->selected->url));
+ this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || StrEmpty(this->selected->url));
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
- this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == NULL || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == NULL);
+ this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || this->selected->GetTextfile(tft) == nullptr);
}
this->GetWidget<NWidgetCore>(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL;
@@ -1131,7 +1131,7 @@ static WindowDesc _network_content_list_desc(
/**
* Show the content list window with a given set of content
- * @param cv the content to show, or NULL when it has to search for itself
+ * @param cv the content to show, or nullptr when it has to search for itself
* @param type1 the first type to (only) show or #CONTENT_TYPE_END to show all.
* @param type2 the second type to (only) show in addition to type1. If type2 is != #CONTENT_TYPE_END, then also type1 should be != #CONTENT_TYPE_END.
* If type2 != #CONTENT_TYPE_END, then type1 != type2 must be true.
@@ -1141,7 +1141,7 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
#if defined(WITH_ZLIB)
std::bitset<CONTENT_TYPE_END> types;
_network_content_client.Clear();
- if (cv == NULL) {
+ if (cv == nullptr) {
assert(type1 != CONTENT_TYPE_END || type2 == CONTENT_TYPE_END);
assert(type1 == CONTENT_TYPE_END || type1 != type2);
_network_content_client.RequestContentList(type1);
@@ -1154,11 +1154,11 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
}
DeleteWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST);
- new NetworkContentListWindow(&_network_content_list_desc, cv != NULL, types);
+ new NetworkContentListWindow(&_network_content_list_desc, cv != nullptr, types);
#else
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
/* Connection failed... clean up the mess */
- if (cv != NULL) {
+ if (cv != nullptr) {
for (ContentInfo *ci : *cv) delete ci;
}
#endif /* WITH_ZLIB */
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 9adbb6e60..5cf01d32c 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -51,7 +51,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
void NetworkUpdateClientInfo(ClientID client_id);
void NetworkClientsToSpectators(CompanyID cid);
-void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL);
+void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = nullptr, const char *join_company_password = nullptr);
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
void NetworkClientSendRcon(const char *password, const char *command);
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp
index e9fc5f943..3b3afcb80 100644
--- a/src/network/network_gamelist.cpp
+++ b/src/network/network_gamelist.cpp
@@ -22,10 +22,10 @@
#include "../safeguards.h"
-NetworkGameList *_network_game_list = NULL;
+NetworkGameList *_network_game_list = nullptr;
/** The games to insert when the GUI thread has time for us. */
-static std::atomic<NetworkGameList *> _network_game_delayed_insertion_list(NULL);
+static std::atomic<NetworkGameList *> _network_game_delayed_insertion_list(nullptr);
/**
* Add a new item to the linked gamelist, but do it delayed in the next tick
@@ -43,12 +43,12 @@ static void NetworkGameListHandleDelayedInsert()
{
while (true) {
NetworkGameList *ins_item = _network_game_delayed_insertion_list.load(std::memory_order_relaxed);
- while (ins_item != NULL && !_network_game_delayed_insertion_list.compare_exchange_weak(ins_item, ins_item->next, std::memory_order_acq_rel)) {}
- if (ins_item == NULL) break; // No item left.
+ while (ins_item != nullptr && !_network_game_delayed_insertion_list.compare_exchange_weak(ins_item, ins_item->next, std::memory_order_acq_rel)) {}
+ if (ins_item == nullptr) break; // No item left.
NetworkGameList *item = NetworkGameListAddItem(ins_item->address);
- if (item != NULL) {
+ if (item != nullptr) {
if (StrEmpty(item->info.server_name)) {
ClearGRFConfigList(&item->info.grfconfig);
memset(&item->info, 0, sizeof(item->info));
@@ -78,22 +78,22 @@ NetworkGameList *NetworkGameListAddItem(NetworkAddress address)
if (StrEmpty(hostname) ||
strcmp(hostname, "0.0.0.0") == 0 ||
strcmp(hostname, "::") == 0) {
- return NULL;
+ return nullptr;
}
NetworkGameList *item, *prev_item;
- prev_item = NULL;
- for (item = _network_game_list; item != NULL; item = item->next) {
+ prev_item = nullptr;
+ for (item = _network_game_list; item != nullptr; item = item->next) {
if (item->address == address) return item;
prev_item = item;
}
item = CallocT<NetworkGameList>(1);
- item->next = NULL;
+ item->next = nullptr;
item->address = address;
- if (prev_item == NULL) {
+ if (prev_item == nullptr) {
_network_game_list = item;
} else {
prev_item->next = item;
@@ -111,10 +111,10 @@ NetworkGameList *NetworkGameListAddItem(NetworkAddress address)
*/
void NetworkGameListRemoveItem(NetworkGameList *remove)
{
- NetworkGameList *prev_item = NULL;
- for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
+ NetworkGameList *prev_item = nullptr;
+ for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
if (remove == item) {
- if (prev_item == NULL) {
+ if (prev_item == nullptr) {
_network_game_list = remove->next;
} else {
prev_item->next = remove->next;
@@ -123,7 +123,7 @@ void NetworkGameListRemoveItem(NetworkGameList *remove)
/* Remove GRFConfig information */
ClearGRFConfigList(&remove->info.grfconfig);
free(remove);
- remove = NULL;
+ remove = nullptr;
DEBUG(net, 4, "[gamelist] removed server from list");
NetworkRebuildHostList();
@@ -148,7 +148,7 @@ void NetworkGameListRequery()
if (++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return;
requery_cnt = 0;
- for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
+ for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
item->retries++;
if (item->retries < REFRESH_GAMEINFO_X_REQUERIES && (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT)) continue;
@@ -165,15 +165,15 @@ void NetworkGameListRequery()
*/
void NetworkAfterNewGRFScan()
{
- for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
+ for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
/* Reset compatibility state */
item->info.compatible = item->info.version_compatible;
- for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
+ for (GRFConfig *c = item->info.grfconfig; c != nullptr; c = c->next) {
assert(HasBit(c->flags, GCF_COPY));
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, c->ident.md5sum);
- if (f == NULL) {
+ if (f == nullptr) {
/* Don't know the GRF, so mark game incompatible and the (possibly)
* already resolved name for this GRF (another server has sent the
* name of the GRF already. */
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index fc5822641..2e85f7966 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -129,13 +129,13 @@ public:
this->resize_y = 0; // We never resize in this direction
/* First initialise some variables... */
- for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
+ for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
}
/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
- for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
+ for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
child_wid->current_x = child_wid->smallest_x;
child_wid->current_y = this->smallest_y;
}
@@ -172,7 +172,7 @@ public:
uint position = 0; // Place to put next child relative to origin of the container.
uint i = rtl ? lengthof(this->visible) - 1 : 0;
child_wid = rtl ? this->tail : this->head;
- while (child_wid != NULL) {
+ while (child_wid != nullptr) {
if (this->visible[i]) {
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
position += child_wid->current_x;
@@ -186,7 +186,7 @@ public:
void Draw(const Window *w) override
{
int i = 0;
- for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
+ for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
if (!this->visible[i++]) continue;
child_wid->Draw(w);
@@ -195,15 +195,15 @@ public:
NWidgetCore *GetWidgetFromPos(int x, int y) override
{
- if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
+ if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
int i = 0;
- for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
+ for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
if (!this->visible[i++]) continue;
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
- if (nwid != NULL) return nwid;
+ if (nwid != nullptr) return nwid;
}
- return NULL;
+ return nullptr;
}
/**
@@ -252,7 +252,7 @@ protected:
/* Create temporary array of games to use for listing */
this->servers.clear();
- for (NetworkGameList *ngl = _network_game_list; ngl != NULL; ngl = ngl->next) {
+ for (NetworkGameList *ngl = _network_game_list; ngl != nullptr; ngl = ngl->next) {
this->servers.push_back(ngl);
}
@@ -364,8 +364,8 @@ protected:
static bool CDECL NGameSearchFilter(NetworkGameList * const *item, StringFilter &sf)
{
- assert(item != NULL);
- assert((*item) != NULL);
+ assert(item != nullptr);
+ assert((*item) != nullptr);
sf.ResetState();
sf.AddLine((*item)->info.server_name);
@@ -460,7 +460,7 @@ public:
NetworkGameWindow(WindowDesc *desc) : Window(desc), name_editbox(NETWORK_CLIENT_NAME_LENGTH), filter_editbox(120)
{
this->list_pos = SLP_INVALID;
- this->server = NULL;
+ this->server = nullptr;
this->lock_offset = 5;
this->blot_offset = this->lock_offset + 3 + GetSpriteSize(SPR_LOCK).width;
@@ -479,7 +479,7 @@ public:
this->last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port));
this->server = this->last_joined;
- if (this->last_joined != NULL) NetworkUDPQueryServer(this->last_joined->address);
+ if (this->last_joined != nullptr) NetworkUDPQueryServer(this->last_joined->address);
this->requery_timer.SetInterval(MILLISECONDS_PER_TICK);
@@ -576,7 +576,7 @@ public:
case WID_NG_LASTJOINED:
/* Draw the last joined server, if any */
- if (this->last_joined != NULL) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
+ if (this->last_joined != nullptr) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
break;
case WID_NG_DETAILS:
@@ -606,16 +606,16 @@ public:
NetworkGameList *sel = this->server;
/* 'Refresh' button invisible if no server selected */
- this->SetWidgetDisabledState(WID_NG_REFRESH, sel == NULL);
+ this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
/* 'Join' button disabling conditions */
- this->SetWidgetDisabledState(WID_NG_JOIN, sel == NULL || // no Selected Server
+ this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
!sel->online || // Server offline
sel->info.clients_on >= sel->info.clients_max || // Server full
!sel->info.compatible); // Revision mismatch
/* 'NewGRF Settings' button invisible if no NewGRF is used */
- this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == NULL || !sel->online || sel->info.grfconfig == NULL);
- this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == NULL || !sel->online || sel->info.grfconfig == NULL || !sel->info.version_compatible || sel->info.compatible);
+ this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr);
+ this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
this->DrawWidgets();
}
@@ -628,7 +628,7 @@ public:
/* Draw the right menu */
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE);
- if (sel == NULL) {
+ if (sel == nullptr) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
} else if (!sel->online) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
@@ -722,8 +722,8 @@ public:
case WID_NG_MATRIX: { // Show available network games
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NG_MATRIX);
- this->server = (id_v < this->servers.size()) ? this->servers[id_v] : NULL;
- this->list_pos = (server == NULL) ? SLP_INVALID : id_v;
+ this->server = (id_v < this->servers.size()) ? this->servers[id_v] : nullptr;
+ this->list_pos = (server == nullptr) ? SLP_INVALID : id_v;
this->SetDirty();
/* FIXME the disabling should go into some InvalidateData, which is called instead of the SetDirty */
@@ -732,7 +732,7 @@ public:
}
case WID_NG_LASTJOINED: {
- if (this->last_joined != NULL) {
+ if (this->last_joined != nullptr) {
this->server = this->last_joined;
/* search the position of the newly selected server */
@@ -767,7 +767,7 @@ public:
break;
case WID_NG_JOIN: // Join Game
- if (this->server != NULL) {
+ if (this->server != nullptr) {
seprintf(_settings_client.network.last_host, lastof(_settings_client.network.last_host), "%s", this->server->address.GetHostname());
_settings_client.network.last_port = this->server->address.GetPort();
ShowNetworkLobbyWindow(this->server);
@@ -775,15 +775,15 @@ public:
break;
case WID_NG_REFRESH: // Refresh
- if (this->server != NULL) NetworkUDPQueryServer(this->server->address);
+ if (this->server != nullptr) NetworkUDPQueryServer(this->server->address);
break;
case WID_NG_NEWGRF: // NewGRF Settings
- if (this->server != NULL) ShowNewGRFSettings(false, false, false, &this->server->info.grfconfig);
+ if (this->server != nullptr) ShowNewGRFSettings(false, false, false, &this->server->info.grfconfig);
break;
case WID_NG_NEWGRF_MISSING: // Find missing content online
- if (this->server != NULL) ShowMissingContentWindow(this->server->info.grfconfig);
+ if (this->server != nullptr) ShowMissingContentWindow(this->server->info.grfconfig);
break;
}
}
@@ -862,11 +862,11 @@ public:
return ES_HANDLED;
}
- if (this->server != NULL) {
+ if (this->server != nullptr) {
if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
NetworkGameListRemoveItem(this->server);
- if (this->server == this->last_joined) this->last_joined = NULL;
- this->server = NULL;
+ if (this->server == this->last_joined) this->last_joined = nullptr;
+ this->server = nullptr;
this->list_pos = SLP_INVALID;
}
}
@@ -1244,7 +1244,7 @@ struct NetworkStartServerWindow : public Window {
void OnQueryTextFinished(char *str) override
{
- if (str == NULL) return;
+ if (str == nullptr) return;
if (this->widget_id == WID_NSS_SETPWD) {
strecpy(_settings_client.network.server_password, str, lastof(_settings_client.network.server_password));
@@ -1344,7 +1344,7 @@ static const NWidgetPart _nested_network_start_server_window_widgets[] = {
};
static WindowDesc _network_start_server_window_desc(
- WDP_CENTER, NULL, 0, 0,
+ WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_WINDOW, WC_NONE,
0,
_nested_network_start_server_window_widgets, lengthof(_nested_network_start_server_window_widgets)
@@ -1631,7 +1631,7 @@ static const NWidgetPart _nested_network_lobby_window_widgets[] = {
};
static WindowDesc _network_lobby_window_desc(
- WDP_CENTER, NULL, 0, 0,
+ WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_WINDOW, WC_NONE,
0,
_nested_network_lobby_window_widgets, lengthof(_nested_network_lobby_window_widgets)
@@ -1660,7 +1660,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company)
{
NetworkLobbyWindow *lobby = dynamic_cast<NetworkLobbyWindow*>(FindWindowById(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_LOBBY));
- return (lobby != NULL && company < MAX_COMPANIES) ? &lobby->company_info[company] : NULL;
+ return (lobby != nullptr && company < MAX_COMPANIES) ? &lobby->company_info[company] : nullptr;
}
/* The window below gives information about the connected clients
@@ -1680,7 +1680,7 @@ static const NWidgetPart _nested_client_list_popup_widgets[] = {
};
static WindowDesc _client_list_popup_desc(
- WDP_AUTO, NULL, 0, 0,
+ WDP_AUTO, nullptr, 0, 0,
WC_CLIENT_LIST_POPUP, WC_CLIENT_LIST,
0,
_nested_client_list_popup_widgets, lengthof(_nested_client_list_popup_widgets)
@@ -1825,7 +1825,7 @@ struct NetworkClientListPopupWindow : Window {
} else {
if (index < this->actions.size() && _cursor.pos.y >= this->top) {
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(this->client_id);
- if (ci != NULL) this->actions[index].proc(ci);
+ if (ci != nullptr) this->actions[index].proc(ci);
}
DeleteWindowByClass(WC_CLIENT_LIST_POPUP);
@@ -1840,7 +1840,7 @@ static void PopupClientList(ClientID client_id, int x, int y)
{
DeleteWindowByClass(WC_CLIENT_LIST_POPUP);
- if (NetworkClientInfo::GetByClientID(client_id) == NULL) return;
+ if (NetworkClientInfo::GetByClientID(client_id) == nullptr) return;
new NetworkClientListPopupWindow(&_client_list_popup_desc, x, y, client_id);
}
@@ -1986,7 +1986,7 @@ struct NetworkClientListWindow : Window {
client_no--;
}
- if (ci != NULL) PopupClientList(ci->client_id, pt.x + this->left, pt.y + this->top);
+ if (ci != nullptr) PopupClientList(ci->client_id, pt.x + this->left, pt.y + this->top);
}
}
@@ -2133,7 +2133,7 @@ static const NWidgetPart _nested_network_join_status_window_widgets[] = {
};
static WindowDesc _network_join_status_window_desc(
- WDP_CENTER, NULL, 0, 0,
+ WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_STATUS_WINDOW, WC_NONE,
WDF_MODAL,
_nested_network_join_status_window_widgets, lengthof(_nested_network_join_status_window_widgets)
@@ -2148,7 +2148,7 @@ void ShowJoinStatusWindow()
void ShowNetworkNeedPassword(NetworkPasswordType npt)
{
NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
- if (w == NULL) return;
+ if (w == nullptr) return;
w->password_type = npt;
StringID caption;
@@ -2227,7 +2227,7 @@ static const NWidgetPart _nested_network_company_password_window_widgets[] = {
};
static WindowDesc _network_company_password_window_desc(
- WDP_AUTO, NULL, 0, 0,
+ WDP_AUTO, nullptr, 0, 0,
WC_COMPANY_PASSWORD_WINDOW, WC_NONE,
0,
_nested_network_company_password_window_widgets, lengthof(_nested_network_company_password_window_widgets)
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index 2498d50d4..06dca992f 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -149,8 +149,8 @@ bool IsNetworkCompatibleVersion(const char *version);
* Everything we need to know about a command to be able to execute it.
*/
struct CommandPacket : CommandContainer {
- /** Make sure the pointer is NULL. */
- CommandPacket() : next(NULL), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
+ /** Make sure the pointer is nullptr. */
+ CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
CommandPacket *next; ///< the next command packet (if in queue)
CompanyID company; ///< company that is executing the command
uint32 frame; ///< the frame in which this packet is executed
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 8022f5ede..24b91e89b 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -67,7 +67,7 @@ struct PacketWriter : SaveFilter {
* Create the packet writer.
* @param cs The socket handler we're making the packets for.
*/
- PacketWriter(ServerNetworkGameSocketHandler *cs) : SaveFilter(NULL), cs(cs), current(NULL), total_size(0), packets(NULL)
+ PacketWriter(ServerNetworkGameSocketHandler *cs) : SaveFilter(nullptr), cs(cs), current(nullptr), total_size(0), packets(nullptr)
{
}
@@ -76,11 +76,11 @@ struct PacketWriter : SaveFilter {
{
std::unique_lock<std::mutex> lock(this->mutex);
- if (this->cs != NULL) this->exit_sig.wait(lock);
+ if (this->cs != nullptr) this->exit_sig.wait(lock);
/* This must all wait until the Destroy function is called. */
- while (this->packets != NULL) {
+ while (this->packets != nullptr) {
Packet *p = this->packets->next;
delete this->packets;
this->packets = p;
@@ -93,7 +93,7 @@ struct PacketWriter : SaveFilter {
* Begin the destruction of this packet writer. It can happen in two ways:
* in the first case the client disconnected while saving the map. In this
* case the saving has not finished and killed this PacketWriter. In that
- * case we simply set cs to NULL, triggering the appending to fail due to
+ * case we simply set cs to nullptr, triggering the appending to fail due to
* the connection problem and eventually triggering the destructor. In the
* second case the destructor is already called, and it is waiting for our
* signal which we will send. Only then the packets will be removed by the
@@ -103,7 +103,7 @@ struct PacketWriter : SaveFilter {
{
std::unique_lock<std::mutex> lock(this->mutex);
- this->cs = NULL;
+ this->cs = nullptr;
this->exit_sig.notify_all();
lock.unlock();
@@ -124,7 +124,7 @@ struct PacketWriter : SaveFilter {
*/
bool HasPackets()
{
- return this->packets != NULL;
+ return this->packets != nullptr;
}
/**
@@ -136,7 +136,7 @@ struct PacketWriter : SaveFilter {
Packet *p = this->packets;
this->packets = p->next;
- p->next = NULL;
+ p->next = nullptr;
return p;
}
@@ -144,23 +144,23 @@ struct PacketWriter : SaveFilter {
/** Append the current packet to the queue. */
void AppendQueue()
{
- if (this->current == NULL) return;
+ if (this->current == nullptr) return;
Packet **p = &this->packets;
- while (*p != NULL) {
+ while (*p != nullptr) {
p = &(*p)->next;
}
*p = this->current;
- this->current = NULL;
+ this->current = nullptr;
}
void Write(byte *buf, size_t size) override
{
/* We want to abort the saving when the socket is closed. */
- if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
+ if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
- if (this->current == NULL) this->current = new Packet(PACKET_SERVER_MAP_DATA);
+ if (this->current == nullptr) this->current = new Packet(PACKET_SERVER_MAP_DATA);
std::lock_guard<std::mutex> lock(this->mutex);
@@ -183,7 +183,7 @@ struct PacketWriter : SaveFilter {
void Finish() override
{
/* We want to abort the saving when the socket is closed. */
- if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
+ if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
std::lock_guard<std::mutex> lock(this->mutex);
@@ -226,9 +226,9 @@ ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
if (_redirect_console_to_client == this->client_id) _redirect_console_to_client = INVALID_CLIENT_ID;
OrderBackup::ResetUser(this->client_id);
- if (this->savegame != NULL) {
+ if (this->savegame != nullptr) {
this->savegame->Destroy();
- this->savegame = NULL;
+ this->savegame = nullptr;
}
}
@@ -236,12 +236,12 @@ Packet *ServerNetworkGameSocketHandler::ReceivePacket()
{
/* Only allow receiving when we have some buffer free; this value
* can go negative, but eventually it will become positive again. */
- if (this->receive_limit <= 0) return NULL;
+ if (this->receive_limit <= 0) return nullptr;
/* We can receive a packet, so try that and if needed account for
* the amount of received data. */
Packet *p = this->NetworkTCPSocketHandler::ReceivePacket();
- if (p != NULL) this->receive_limit -= p->size;
+ if (p != nullptr) this->receive_limit -= p->size;
return p;
}
@@ -264,7 +264,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
this->GetClientName(client_name, lastof(client_name));
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
/* Inform other clients of this... strange leaving ;) */
FOR_ALL_CLIENT_SOCKETS(new_cs) {
@@ -361,7 +361,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
/* Add the local player (if not dedicated) */
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
- if (ci != NULL && Company::IsValidID(ci->client_playas)) {
+ if (ci != nullptr && Company::IsValidID(ci->client_playas)) {
strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
}
@@ -371,7 +371,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
((ServerNetworkGameSocketHandler*)csi)->GetClientName(client_name, lastof(client_name));
ci = csi->GetInfo();
- if (ci != NULL && Company::IsValidID(ci->client_playas)) {
+ if (ci != nullptr && Company::IsValidID(ci->client_playas)) {
if (!StrEmpty(clients[ci->client_playas])) {
strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas]));
}
@@ -434,7 +434,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err
DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, strid);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTHORIZED && new_cs != this) {
@@ -463,12 +463,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
const GRFConfig *c;
uint grf_count = 0;
- for (c = _grfconfig; c != NULL; c = c->next) {
+ for (c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) grf_count++;
}
p->Send_uint8 (grf_count);
- for (c = _grfconfig; c != NULL; c = c->next) {
+ for (c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) this->SendGRFIdentifier(p, &c->ident);
}
@@ -607,7 +607,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
if (last_packet) {
/* Done reading, make sure saving is done as well */
this->savegame->Destroy();
- this->savegame = NULL;
+ this->savegame = nullptr;
/* Set the status to DONE_MAP, no we will wait for the client
* to send it is ready (maybe that happens like never ;)) */
@@ -615,17 +615,17 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
/* Find the best candidate for joining, i.e. the first joiner. */
NetworkClientSocket *new_cs;
- NetworkClientSocket *best = NULL;
+ NetworkClientSocket *best = nullptr;
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status == STATUS_MAP_WAIT) {
- if (best == NULL || best->GetInfo()->join_date > new_cs->GetInfo()->join_date || (best->GetInfo()->join_date == new_cs->GetInfo()->join_date && best->client_id > new_cs->client_id)) {
+ if (best == nullptr || best->GetInfo()->join_date > new_cs->GetInfo()->join_date || (best->GetInfo()->join_date == new_cs->GetInfo()->join_date && best->client_id > new_cs->client_id)) {
best = new_cs;
}
}
}
/* Is there someone else to join? */
- if (best != NULL) {
+ if (best != nullptr) {
/* Let the first start joining. */
best->status = STATUS_AUTHORIZED;
best->SendMap();
@@ -946,9 +946,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
this->status = STATUS_NEWGRFS_CHECK;
- if (_grfconfig == NULL) {
+ if (_grfconfig == nullptr) {
/* Behave as if we received PACKET_CLIENT_NEWGRFS_CHECKED */
- return this->Receive_CLIENT_NEWGRFS_CHECKED(NULL);
+ return this->Receive_CLIENT_NEWGRFS_CHECKED(nullptr);
}
return this->SendNewGRFCheck();
@@ -1032,7 +1032,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *
this->GetClientName(client_name, lastof(client_name));
- NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, NULL, this->client_id);
+ NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, nullptr, this->client_id);
/* Mark the client as pre-active, and wait for an ACK
* so we know he is done loading and in sync with us */
@@ -1089,7 +1089,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet
NetworkClientInfo *ci = this->GetInfo();
- if (err != NULL) {
+ if (err != nullptr) {
IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, this->GetClientIP());
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
@@ -1155,7 +1155,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p
DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, strid);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTHORIZED) {
@@ -1182,7 +1182,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p)
this->GetClientName(client_name, lastof(client_name));
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, nullptr, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTHORIZED && new_cs != this) {
@@ -1262,7 +1262,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
if ((ClientID)dest == CLIENT_ID_SERVER) {
ci = NetworkClientInfo::GetByClientID(from_id);
/* Display the text locally, and that is it */
- if (ci != NULL) {
+ if (ci != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
if (_settings_client.network.server_admin_chat) {
@@ -1284,7 +1284,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
if (from_id == CLIENT_ID_SERVER) {
ci = NetworkClientInfo::GetByClientID(from_id);
ci_to = NetworkClientInfo::GetByClientID((ClientID)dest);
- if (ci != NULL && ci_to != NULL) {
+ if (ci != nullptr && ci_to != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), true, ci_to->client_name, msg, data);
}
} else {
@@ -1301,10 +1301,10 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
/* If this is false, the message is already displayed on the client who sent it. */
bool show_local = true;
/* Find all clients that belong to this company */
- ci_to = NULL;
+ ci_to = nullptr;
FOR_ALL_CLIENT_SOCKETS(cs) {
ci = cs->GetInfo();
- if (ci != NULL && ci->client_playas == (CompanyID)dest) {
+ if (ci != nullptr && ci->client_playas == (CompanyID)dest) {
cs->SendChat(action, from_id, false, msg, data);
if (cs->client_id == from_id) show_local = false;
ci_to = ci; // Remember a client that is in the company for company-name
@@ -1318,17 +1318,17 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkClientInfo::GetByClientID(from_id);
ci_own = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
- if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
+ if (ci != nullptr && ci_own != nullptr && ci_own->client_playas == dest) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
if (from_id == CLIENT_ID_SERVER) show_local = false;
ci_to = ci_own;
}
/* There is no such client */
- if (ci_to == NULL) break;
+ if (ci_to == nullptr) break;
/* Display the message locally (so you know you have sent it) */
- if (ci != NULL && show_local) {
+ if (ci != nullptr && show_local) {
if (from_id == CLIENT_ID_SERVER) {
char name[NETWORK_NAME_LENGTH];
StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
@@ -1357,7 +1357,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
ci = NetworkClientInfo::GetByClientID(from_id);
- if (ci != NULL) {
+ if (ci != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
}
break;
@@ -1428,7 +1428,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CONN_LOST;
- if (ci != NULL) {
+ if (ci != nullptr) {
/* Display change */
if (NetworkFindName(client_name, lastof(client_name))) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name);
@@ -1591,7 +1591,7 @@ void NetworkUpdateClientInfo(ClientID client_id)
NetworkClientSocket *cs;
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci == NULL) return;
+ if (ci == nullptr) return;
DEBUG(desync, 1, "client: %08x; %02x; %02x; %04x", _date, _date_fract, (int)ci->client_playas, client_id);
@@ -1712,7 +1712,7 @@ bool NetworkFindName(char *new_name, const char *last)
}
/* Check if it is the same as the server-name */
ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
- if (ci != NULL) {
+ if (ci != nullptr) {
if (strcmp(ci->client_name, new_name) == 0) found_name = false; // name already in use
}
@@ -1743,7 +1743,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
}
ci = NetworkClientInfo::GetByClientID(client_id);
- if (ci == NULL) return false;
+ if (ci == nullptr) return false;
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, true, ci->client_name, new_name);
@@ -1778,7 +1778,7 @@ void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password,
static void NetworkHandleCommandQueue(NetworkClientSocket *cs)
{
CommandPacket *cp;
- while ((cp = cs->outgoing_queue.Pop()) != NULL) {
+ while ((cp = cs->outgoing_queue.Pop()) != nullptr) {
cs->SendCommand(cp);
free(cp);
}
@@ -1964,7 +1964,7 @@ void NetworkServerShowStatusToConsole()
NetworkClientSocket *cs;
FOR_ALL_CLIENT_SOCKETS(cs) {
NetworkClientInfo *ci = cs->GetInfo();
- if (ci == NULL) continue;
+ if (ci == nullptr) continue;
uint lag = NetworkCalculateLag(cs);
const char *status;
@@ -2131,7 +2131,7 @@ void ServerNetworkGameSocketHandler::GetClientName(char *client_name, const char
{
const NetworkClientInfo *ci = this->GetInfo();
- if (ci == NULL || StrEmpty(ci->client_name)) {
+ if (ci == nullptr || StrEmpty(ci->client_name)) {
seprintf(client_name, last, "Client #%4d", this->client_id);
} else {
strecpy(client_name, ci->client_name, last);
@@ -2162,12 +2162,12 @@ void NetworkPrintClients()
/**
* Perform all the server specific administration of a new company.
- * @param c The newly created company; can't be NULL.
- * @param ci The client information of the client that made the company; can be NULL.
+ * @param c The newly created company; can't be nullptr.
+ * @param ci The client information of the client that made the company; can be nullptr.
*/
void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
{
- assert(c != NULL);
+ assert(c != nullptr);
if (!_network_server) return;
@@ -2175,18 +2175,18 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
_network_company_states[c->index].password[0] = '\0';
NetworkServerUpdateCompanyPassworded(c->index, false);
- if (ci != NULL) {
- /* ci is NULL when replaying, or for AIs. In neither case there is a client. */
+ if (ci != nullptr) {
+ /* ci is nullptr when replaying, or for AIs. In neither case there is a client. */
ci->client_playas = c->index;
NetworkUpdateClientInfo(ci->client_id);
- NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, c->index);
+ NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, nullptr, ci->client_name, c->index);
}
/* Announce new company on network. */
NetworkAdminCompanyInfo(c, true);
- if (ci != NULL) {
- /* ci is NULL when replaying, or for AIs. In neither case there is a client.
+ if (ci != nullptr) {
+ /* ci is nullptr when replaying, or for AIs. In neither case there is a client.
We need to send Admin port update here so that they first know about the new company
and then learn about a possibly joining client (see FS#6025) */
NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 7674036e7..d9f625719 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -45,9 +45,9 @@ static const uint32 ADVERTISE_NORMAL_INTERVAL = 15 * 60 * 1000; ///< interval be
static const uint32 ADVERTISE_RETRY_INTERVAL = 10 * 1000; ///< re-advertise when no response after this many ms (10 seconds)
static const uint32 ADVERTISE_RETRY_TIMES = 3; ///< give up re-advertising after this much failed retries
-NetworkUDPSocketHandler *_udp_client_socket = NULL; ///< udp client socket
-NetworkUDPSocketHandler *_udp_server_socket = NULL; ///< udp server socket
-NetworkUDPSocketHandler *_udp_master_socket = NULL; ///< udp master socket
+NetworkUDPSocketHandler *_udp_client_socket = nullptr; ///< udp client socket
+NetworkUDPSocketHandler *_udp_server_socket = nullptr; ///< udp server socket
+NetworkUDPSocketHandler *_udp_master_socket = nullptr; ///< udp master socket
/**
* Helper function doing the actual work for querying the server.
@@ -69,7 +69,7 @@ static void DoNetworkUDPQueryServer(NetworkAddress &address, bool needs_mutex, b
if (needs_mutex) lock.lock();
/* Init the packet */
Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
- if (_udp_client_socket != NULL) _udp_client_socket->SendPacket(&p, &address);
+ if (_udp_client_socket != nullptr) _udp_client_socket->SendPacket(&p, &address);
}
/**
@@ -79,7 +79,7 @@ static void DoNetworkUDPQueryServer(NetworkAddress &address, bool needs_mutex, b
*/
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
{
- if (address.IsResolved() || !StartNewThread(NULL, "ottd:udp-query", &DoNetworkUDPQueryServer, std::move(address), true, std::move(manually))) {
+ if (address.IsResolved() || !StartNewThread(nullptr, "ottd:udp-query", &DoNetworkUDPQueryServer, std::move(address), true, std::move(manually))) {
DoNetworkUDPQueryServer(address, true, manually);
}
}
@@ -261,7 +261,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, Networ
/* Find the matching GRF file */
f = FindGRFConfig(c.grfid, FGCM_EXACT, c.md5sum);
- if (f == NULL) continue; // The GRF is unknown to this server
+ if (f == nullptr) continue; // The GRF is unknown to this server
/* If the reply might exceed the size of the packet, only reply
* the current list and do not send the other data.
@@ -332,7 +332,7 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAd
const GRFConfig *c;
uint in_request_count = 0;
- for (c = item->info.grfconfig; c != NULL; c = c->next) {
+ for (c = item->info.grfconfig; c != nullptr; c = c->next) {
if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
if (c->status != GCS_NOT_FOUND || strcmp(c->GetName(), UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
in_request[in_request_count] = c;
@@ -431,7 +431,7 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAdd
* If it exists and not resolved yet, then name of the fake GRF is
* overwritten with the name from the reply. */
GRFTextWrapper *unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false);
- if (unknown_name != NULL && strcmp(GetGRFStringFromGRFText(unknown_name->text), UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
+ if (unknown_name != nullptr && strcmp(GetGRFStringFromGRFText(unknown_name->text), UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
AddGRFTextToList(&unknown_name->text, name);
}
}
@@ -441,7 +441,7 @@ void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFCo
{
/* Find the matching GRF file */
const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, config->ident.md5sum);
- if (f == NULL) {
+ if (f == nullptr) {
/* Don't know the GRF, so mark game incompatible and the (possibly)
* already resolved name for this GRF (another server has sent the
* name of the GRF already */
@@ -521,7 +521,7 @@ static void NetworkUDPRemoveAdvertiseThread()
p.Send_uint16(_settings_client.network.server_port);
std::lock_guard<std::mutex> lock(_network_udp_mutex);
- if (_udp_master_socket != NULL) _udp_master_socket->SendPacket(&p, &out_addr, true);
+ if (_udp_master_socket != nullptr) _udp_master_socket->SendPacket(&p, &out_addr, true);
}
/**
@@ -533,7 +533,7 @@ void NetworkUDPRemoveAdvertise(bool blocking)
/* Check if we are advertising */
if (!_networking || !_network_server || !_network_udp_server) return;
- if (blocking || !StartNewThread(NULL, "ottd:udp-advert", &NetworkUDPRemoveAdvertiseThread)) {
+ if (blocking || !StartNewThread(nullptr, "ottd:udp-advert", &NetworkUDPRemoveAdvertiseThread)) {
NetworkUDPRemoveAdvertiseThread();
}
}
@@ -573,7 +573,7 @@ static void NetworkUDPAdvertiseThread()
p.Send_uint64(_session_key);
std::lock_guard<std::mutex> lock(_network_udp_mutex);
- if (_udp_master_socket != NULL) _udp_master_socket->SendPacket(&p, &out_addr, true);
+ if (_udp_master_socket != nullptr) _udp_master_socket->SendPacket(&p, &out_addr, true);
}
/**
@@ -614,7 +614,7 @@ void NetworkUDPAdvertise()
if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
if (_next_retry < _last_advertisement) _next_retry = UINT32_MAX;
- if (!StartNewThread(NULL, "ottd:udp-advert", &NetworkUDPAdvertiseThread)) {
+ if (!StartNewThread(nullptr, "ottd:udp-advert", &NetworkUDPAdvertiseThread)) {
NetworkUDPAdvertiseThread();
}
}
@@ -623,10 +623,10 @@ void NetworkUDPAdvertise()
void NetworkUDPInitialize()
{
/* If not closed, then do it. */
- if (_udp_server_socket != NULL) NetworkUDPClose();
+ if (_udp_server_socket != nullptr) NetworkUDPClose();
DEBUG(net, 1, "[udp] initializing listeners");
- assert(_udp_client_socket == NULL && _udp_server_socket == NULL && _udp_master_socket == NULL);
+ assert(_udp_client_socket == nullptr && _udp_server_socket == nullptr && _udp_master_socket == nullptr);
std::lock_guard<std::mutex> lock(_network_udp_mutex);
@@ -654,9 +654,9 @@ void NetworkUDPClose()
delete _udp_client_socket;
delete _udp_server_socket;
delete _udp_master_socket;
- _udp_client_socket = NULL;
- _udp_server_socket = NULL;
- _udp_master_socket = NULL;
+ _udp_client_socket = nullptr;
+ _udp_server_socket = nullptr;
+ _udp_master_socket = nullptr;
_network_udp_server = false;
_network_udp_broadcast = 0;