Merge: Codechange: Use null pointer literal instead of the NULL macro

This commit is contained in:
Jonathan G Rennison
2019-04-11 18:14:13 +01:00
585 changed files with 6604 additions and 6604 deletions

View File

@@ -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 &&

View File

@@ -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;

View File

@@ -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);

View File

@@ -25,10 +25,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>(SHRT_MAX);
@@ -54,8 +54,8 @@ Packet::~Packet()
void Packet::ResetState(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;
@@ -68,7 +68,7 @@ void Packet::ResetState(PacketType type)
*/
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);
@@ -155,7 +155,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 <= SHRT_MAX);
while ((this->buffer[this->size++] = *data++) != '\0') {}
@@ -167,7 +167,7 @@ void Packet::Send_string(const char *data)
*/
void Packet::Send_binary(const char *data, const size_t size)
{
assert(data != NULL);
assert(data != nullptr);
assert(size < MAX_CMD_TEXT_LENGTH);
memcpy(&this->buffer[this->size], data, size);
this->size += (PacketSize) size;
@@ -206,7 +206,7 @@ bool Packet::CanReadFromPacket(uint bytes_to_read, bool non_fatal)
*/
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;
}

View File

@@ -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;
}
@@ -193,22 +193,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;
@@ -231,7 +231,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;

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -131,14 +131,14 @@ 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.
void Append(CommandPacket *p, bool move);
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) { this->Append(&p, false); }
@@ -541,7 +541,7 @@ public:
*/
inline void SetInfo(NetworkClientInfo *info)
{
assert(info != NULL && this->info == NULL);
assert(info != nullptr && this->info == nullptr);
this->info = info;
}

View File

@@ -43,11 +43,11 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s,
redirect_depth(depth),
sock(s)
{
size_t bufferSize = strlen(url) + strlen(host) + strlen(_openttd_revision) + (data == NULL ? 0 : strlen(data)) + 128;
size_t bufferSize = strlen(url) + strlen(host) + strlen(_openttd_revision) + (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, _openttd_revision, (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, _openttd_revision);
@@ -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 */) {

View File

@@ -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;
}
};

View File

@@ -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) {

View File

@@ -28,12 +28,12 @@ extern const uint8 _out_of_band_grf_md5[16];
*/
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);
@@ -209,14 +209,14 @@ 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(min<uint>(count, NETWORK_MAX_GRF_COUNT)); // Send number of GRFs
/* Send actual GRF Identifications */
uint index = 0;
for (c = info->grfconfig; c != NULL; c = c->next) {
for (c = info->grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC)) {
if (index == NETWORK_MAX_GRF_COUNT - 1 && count > NETWORK_MAX_GRF_COUNT) {
/* Send fake GRF ID */
@@ -293,13 +293,13 @@ void NetworkUDPSocketHandler::SendNetworkGameInfoExtended(Packet *p, const Netwo
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_uint32(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);
}
@@ -489,7 +489,7 @@ void NetworkUDPSocketHandler::Receive_EX_MULTI(Packet *p, NetworkAddress *client
if (total == 0 || index >= total) return;
if (!p->CanReadFromPacket(payload_size)) return;
time_t cur_time = time(NULL);
time_t cur_time = time(nullptr);
auto add_to_fragment = [&](FragmentSet &fs) {
fs.fragments[index].assign((const char *) p->buffer + p->pos, payload_size);

View File

@@ -250,7 +250,7 @@ protected:
virtual void Receive_EX_MULTI(Packet *p, NetworkAddress *client_addr);
public:
NetworkUDPSocketHandler(NetworkAddressList *bind = NULL);
NetworkUDPSocketHandler(NetworkAddressList *bind = nullptr);
/** On destructing of this class, the socket needs to be closed */
virtual ~NetworkUDPSocketHandler() { this->Close(); }

View File

@@ -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()
@@ -397,7 +397,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;
}
@@ -560,7 +560,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);
}
@@ -573,7 +573,7 @@ void NetworkClose(bool close_admins)
NetworkFreeLocalCommandQueue();
free(_network_company_states);
_network_company_states = NULL;
_network_company_states = nullptr;
InitializeNetworkPools(close_admins);
}
@@ -627,8 +627,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;
@@ -638,7 +638,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);
}
@@ -668,7 +668,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));
}
}
@@ -907,15 +907,15 @@ void NetworkGameLoop()
static std::unique_ptr<CommandPacket> cp;
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.c_str(), cp->company, cp->binary_length);
if (cp != nullptr) {
NetworkSendCommand(cp->tile, cp->p1, cp->p2, cp->cmd & ~CMD_FLAGS_MASK, nullptr, cp->text.c_str(), cp->company, cp->binary_length);
DEBUG(net, 0, "injecting: date{%08x; %02x; %02x}; %02x; %06x; %08x; %08x; %08x; \"%s\" (%x) (%s)", _date, _date_fract, _tick_skip_counter, (int)_current_company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text.c_str(), cp->binary_length, GetCommandName(cp->cmd));
cp.reset();
}
@@ -931,16 +931,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;
}
@@ -972,7 +972,7 @@ void NetworkGameLoop()
cp->cmd = CMD_PAUSE;
cp->p1 = PM_PAUSED_NORMAL;
cp->p2 = 1;
cp->callback = NULL;
cp->callback = nullptr;
cp->binary_length = 0;
_ddc_fastforward = false;
} else if (strncmp(p, "sync: ", 6) == 0) {
@@ -992,10 +992,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) {

View File

@@ -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) {

View File

@@ -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.
@@ -362,7 +362,7 @@ struct NetworkChatWindow : public Window {
}
}
return NULL;
return nullptr;
}
/**
@@ -373,7 +373,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;
@@ -402,7 +402,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) {
@@ -545,7 +545,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)

View File

@@ -51,7 +51,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)
{
}
@@ -146,9 +146,9 @@ void ClientNetworkEmergencySave()
*/
ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler (SOCKET s)
: NetworkGameSocketHandler (s),
savegame (NULL), token (0), status (STATUS_INACTIVE)
savegame (nullptr), token (0), status (STATUS_INACTIVE)
{
assert(ClientNetworkGameSocketHandler::my_client == NULL);
assert(ClientNetworkGameSocketHandler::my_client == nullptr);
ClientNetworkGameSocketHandler::my_client = this;
}
@@ -156,7 +156,7 @@ ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler (SOCKET s)
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler()
{
assert(ClientNetworkGameSocketHandler::my_client == this);
ClientNetworkGameSocketHandler::my_client = NULL;
ClientNetworkGameSocketHandler::my_client = nullptr;
delete this->savegame;
}
@@ -307,7 +307,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;
@@ -326,9 +326,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);
@@ -539,7 +539,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;
}
@@ -548,7 +548,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)
{
@@ -582,7 +582,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();
@@ -625,7 +625,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);
@@ -721,7 +721,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);
@@ -807,7 +807,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();
@@ -825,7 +825,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);
@@ -836,7 +836,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);
@@ -850,7 +850,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);
@@ -863,12 +863,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;
@@ -894,7 +894,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, 0);
NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company, 0);
}
} else {
/* take control over an existing company */
@@ -959,7 +959,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;
}
@@ -974,7 +974,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();
@@ -984,7 +984,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
data.recv(p);
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) {
@@ -1017,7 +1017,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;
@@ -1030,8 +1030,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;
}
@@ -1047,8 +1047,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);
@@ -1067,7 +1067,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);
}
@@ -1137,7 +1137,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;
@@ -1261,7 +1261,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) {

View File

@@ -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,
@@ -69,8 +69,8 @@ void CommandQueue::Append(CommandPacket *p, bool move)
} else {
*add = *p;
}
add->next = NULL;
if (this->first == NULL) {
add->next = nullptr;
if (this->first == nullptr) {
this->first = add;
} else {
this->last->next = add;
@@ -89,15 +89,15 @@ std::unique_ptr<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--;
@@ -114,17 +114,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()
{
std::unique_ptr<CommandPacket> cp;
while ((cp = this->Pop()) != NULL) {}
while ((cp = this->Pop()) != nullptr) {}
assert(this->count == 0);
}
@@ -158,7 +158,7 @@ void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comman
c.binary_length = binary_length;
if (binary_length == 0) {
if (text != NULL) {
if (text != nullptr) {
c.text.assign(text);
} else {
c.text.clear();
@@ -198,7 +198,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(std::move(c));
@@ -215,7 +215,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;
@@ -262,13 +262,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);
}
@@ -288,7 +288,7 @@ static void DistributeQueue(CommandQueue *queue, const NetworkClientSocket *owne
#endif
std::unique_ptr<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.get());
}
@@ -298,7 +298,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;
@@ -311,7 +311,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)
{
@@ -337,7 +337,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;
}
/**
@@ -367,7 +367,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);
}

View File

@@ -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();
@@ -380,12 +380,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);
@@ -406,14 +406,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];
@@ -447,8 +447,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
@@ -458,7 +458,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;
@@ -479,7 +479,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;
}
@@ -500,14 +500,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);
@@ -526,7 +526,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));
@@ -560,25 +560,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;
@@ -591,7 +591,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. */
@@ -604,7 +604,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();
}
@@ -622,7 +622,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'; }
@@ -701,8 +701,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)
{
@@ -712,7 +712,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;
}
@@ -804,14 +804,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;
}
@@ -822,7 +822,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);
@@ -835,7 +835,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);
@@ -943,7 +943,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;
@@ -969,7 +969,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;
}
@@ -1074,7 +1074,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;
}

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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, NetworkTextMessageData data = NetworkTextMessageData());

View File

@@ -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. */

View File

@@ -131,13 +131,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;
}
@@ -174,7 +174,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;
@@ -188,7 +188,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);
@@ -197,15 +197,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;
}
/**
@@ -254,7 +254,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);
}
@@ -366,8 +366,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);
@@ -462,7 +462,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;
@@ -481,7 +481,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);
@@ -578,7 +578,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:
@@ -608,16 +608,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();
}
@@ -630,7 +630,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
@@ -724,8 +724,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 */
@@ -734,7 +734,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 */
@@ -769,7 +769,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);
@@ -777,15 +777,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;
}
}
@@ -864,11 +864,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;
}
}
@@ -1246,7 +1246,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));
@@ -1346,7 +1346,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)
@@ -1633,7 +1633,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)
@@ -1662,7 +1662,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
@@ -1681,7 +1681,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)
@@ -1814,7 +1814,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);
@@ -1829,7 +1829,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);
}
@@ -1975,7 +1975,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);
}
}
@@ -2122,7 +2122,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)
@@ -2137,7 +2137,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;
@@ -2216,7 +2216,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)

View File

@@ -149,8 +149,8 @@ bool IsNetworkCompatibleVersion(const char *version, bool extended = false);
* 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

View File

@@ -71,7 +71,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)
{
}
@@ -80,11 +80,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;
@@ -97,7 +97,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
@@ -107,7 +107,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();
@@ -128,7 +128,7 @@ struct PacketWriter : SaveFilter {
*/
bool HasPackets()
{
return this->packets != NULL;
return this->packets != nullptr;
}
/**
@@ -140,7 +140,7 @@ struct PacketWriter : SaveFilter {
Packet *p = this->packets;
this->packets = p->next;
p->next = NULL;
p->next = nullptr;
return p;
}
@@ -148,23 +148,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);
@@ -187,7 +187,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);
@@ -230,9 +230,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;
}
}
@@ -240,12 +240,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;
}
@@ -268,7 +268,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) {
@@ -365,7 +365,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]));
}
@@ -375,7 +375,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]));
}
@@ -438,7 +438,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) {
@@ -467,12 +467,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_uint32 (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);
}
@@ -611,7 +611,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 ;)) */
@@ -619,17 +619,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();
@@ -950,9 +950,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();
@@ -1036,7 +1036,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 */
@@ -1093,7 +1093,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);
}
@@ -1159,7 +1159,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) {
@@ -1171,7 +1171,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(Packet *p
if (errorno == NETWORK_ERROR_DESYNC) {
// have the server and all clients run some sanity checks
NetworkSendCommand(0, 0, 0, CMD_DESYNC_CHECK, NULL, NULL, _local_company, 0);
NetworkSendCommand(0, 0, 0, CMD_DESYNC_CHECK, nullptr, nullptr, _local_company, 0);
}
return this->CloseConnection(NETWORK_RECV_STATUS_CONN_LOST);
@@ -1191,7 +1191,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) {
@@ -1271,7 +1271,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) {
@@ -1293,7 +1293,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 {
@@ -1310,10 +1310,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
@@ -1327,17 +1327,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;
@@ -1367,7 +1367,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),
(desttype == DESTTYPE_BROADCAST_SS && from_id == CLIENT_ID_SERVER), ci->client_name, msg, data);
}
@@ -1440,7 +1440,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);
@@ -1603,7 +1603,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: date{%08x; %02x; %02x}; %02x; %04x", _date, _date_fract, _tick_skip_counter, (int)ci->client_playas, client_id);
@@ -1724,7 +1724,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
}
@@ -1755,7 +1755,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);
@@ -1790,7 +1790,7 @@ void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password,
static void NetworkHandleCommandQueue(NetworkClientSocket *cs)
{
std::unique_ptr<CommandPacket> cp;
while ((cp = cs->outgoing_queue.Pop()) != NULL) {
while ((cp = cs->outgoing_queue.Pop()) != nullptr) {
cs->SendCommand(cp.get());
}
}
@@ -1975,7 +1975,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;
@@ -2142,7 +2142,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);
@@ -2173,12 +2173,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;
@@ -2186,18 +2186,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, 0);
NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, nullptr, ci->client_name, c->index, 0);
}
/* 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);

View File

@@ -53,9 +53,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
static Packet PrepareUdpClientFindServerPacket()
{
@@ -86,7 +86,7 @@ static void DoNetworkUDPQueryServer(NetworkAddress &address, bool needs_mutex, b
if (needs_mutex) lock.lock();
/* Init the packet */
Packet p = PrepareUdpClientFindServerPacket();
if (_udp_client_socket != NULL) _udp_client_socket->SendPacket(&p, &address);
if (_udp_client_socket != nullptr) _udp_client_socket->SendPacket(&p, &address);
}
/**
@@ -96,7 +96,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);
}
}
@@ -330,7 +330,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, Networ
const GRFConfig *f;
/* Find the matching GRF file */
f = FindGRFConfig(info.ident.grfid, FGCM_EXACT, info.ident.md5sum);
if (f == NULL) continue; // The GRF is unknown to this server
if (f == nullptr) continue; // The GRF is unknown to this server
info.ident = f->ident;
info.name = f->GetName();
@@ -427,7 +427,7 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE_Common(Packet *p, Ne
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;
@@ -516,7 +516,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);
}
}
@@ -526,7 +526,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 */
@@ -606,7 +606,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);
}
/**
@@ -618,7 +618,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();
}
}
@@ -658,7 +658,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);
}
/**
@@ -699,7 +699,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();
}
}
@@ -708,10 +708,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);
@@ -739,9 +739,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;