Merge branch 'master' into jgrpp

Replace build and refit, and group collapse implementations
Fix template creation build and refit

# Conflicts:
#	Makefile.bundle.in
#	config.lib
#	src/animated_tile.cpp
#	src/blitter/32bpp_anim.hpp
#	src/blitter/32bpp_base.hpp
#	src/blitter/8bpp_base.hpp
#	src/blitter/null.hpp
#	src/build_vehicle_gui.cpp
#	src/command.cpp
#	src/command_func.h
#	src/console_gui.cpp
#	src/core/smallstack_type.hpp
#	src/date.cpp
#	src/debug.cpp
#	src/genworld_gui.cpp
#	src/ground_vehicle.hpp
#	src/group_gui.cpp
#	src/lang/korean.txt
#	src/linkgraph/linkgraph_gui.h
#	src/main_gui.cpp
#	src/misc_gui.cpp
#	src/network/core/game.h
#	src/network/core/packet.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_content.cpp
#	src/network/network_type.h
#	src/network/network_udp.cpp
#	src/newgrf_house.h
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/os/unix/crashlog_unix.cpp
#	src/os/windows/crashlog_win.cpp
#	src/osk_gui.cpp
#	src/pathfinder/opf/opf_ship.cpp
#	src/rail_cmd.cpp
#	src/rail_gui.cpp
#	src/saveload/saveload.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/smallmap_gui.h
#	src/station_base.h
#	src/station_cmd.cpp
#	src/table/gameopt_settings.ini
#	src/table/newgrf_debug_data.h
#	src/table/settings.ini
#	src/timetable_gui.cpp
#	src/toolbar_gui.cpp
#	src/train_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/vehiclelist.cpp
#	src/viewport.cpp
#	src/widgets/dropdown.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2019-03-27 18:12:04 +00:00
422 changed files with 4697 additions and 6619 deletions

View File

@@ -11,8 +11,6 @@
#include "../../stdafx.h"
#ifdef ENABLE_NETWORK
#include "address.h"
#include "../../debug.h"
@@ -433,5 +431,3 @@ void NetworkAddress::Listen(int socktype, SocketList *sockets)
default: return "unsupported";
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,11 +17,9 @@
#include "../../string_func.h"
#include "../../core/smallmap_type.hpp"
#ifdef ENABLE_NETWORK
class NetworkAddress;
typedef SmallVector<NetworkAddress, 4> NetworkAddressList; ///< Type for a list of addresses.
typedef SmallMap<NetworkAddress, SOCKET, 4> SocketList; ///< Type for a mapping between address and socket.
typedef std::vector<NetworkAddress> NetworkAddressList; ///< Type for a list of addresses.
typedef SmallMap<NetworkAddress, SOCKET> SocketList; ///< Type for a mapping between address and socket.
/**
* Wrapper for (un)resolved network addresses; there's no reason to transform
@@ -192,5 +190,4 @@ public:
static const char *AddressFamilyAsString(int family);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_ADDRESS_H */

View File

@@ -11,8 +11,6 @@
* @file core.cpp Functions used to initialize/shut down the core network
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "os_abstraction.h"
@@ -80,5 +78,3 @@ void NetworkSocketHandler::ReceiveGRFIdentifier(Packet *p, GRFIdentifier *grf)
grf->md5sum[j] = p->Recv_uint8();
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "../../newgrf_config.h"
#include "config.h"
#ifdef ENABLE_NETWORK
bool NetworkCoreInitialize();
void NetworkCoreShutdown();
@@ -80,6 +78,4 @@ public:
void SendCompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len = NETWORK_COMPANY_NAME_LENGTH);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_CORE_H */

View File

@@ -19,8 +19,6 @@
#include "../../newgrf_config.h"
#include "../../date_type.h"
#ifdef ENABLE_NETWORK
/**
* The game information that is not generated on-the-fly and has to
* be sent to the clients.
@@ -57,6 +55,4 @@ struct NetworkGameInfo : NetworkServerGameInfo {
byte map_set; ///< Graphical set
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_GAME_H */

View File

@@ -9,8 +9,6 @@
/** @file host.cpp Functions related to getting host specific data (IPs). */
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "address.h"
@@ -78,7 +76,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // BE
memset(&address, 0, sizeof(address));
((sockaddr_in*)&address)->sin_addr.s_addr = htonl(ip | ~netmask);
NetworkAddress addr(address, sizeof(sockaddr));
if (!broadcast->Contains(addr)) *broadcast->Append() = addr;
if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr);
}
if (read < 0) {
break;
@@ -102,7 +100,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE
if (ifa->ifa_broadaddr->sa_family != AF_INET) continue;
NetworkAddress addr(ifa->ifa_broadaddr, sizeof(sockaddr));
if (!broadcast->Contains(addr)) *broadcast->Append() = addr;
if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr);
}
freeifaddrs(ifap);
}
@@ -138,7 +136,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi
memcpy(&address, &ifo[j].iiAddress.Address, sizeof(sockaddr));
((sockaddr_in*)&address)->sin_addr.s_addr = ifo[j].iiAddress.AddressIn.sin_addr.s_addr | ~ifo[j].iiNetmask.AddressIn.sin_addr.s_addr;
NetworkAddress addr(address, sizeof(sockaddr));
if (!broadcast->Contains(addr)) *broadcast->Append() = addr;
if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr);
}
free(ifo);
@@ -176,7 +174,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // !G
(r.ifr_flags & IFF_BROADCAST) &&
ioctl(sock, SIOCGIFBRDADDR, &r) != -1) {
NetworkAddress addr(&r.ifr_broadaddr, sizeof(sockaddr));
if (!broadcast->Contains(addr)) *broadcast->Append() = addr;
if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) *broadcast->Append() = addr;
}
}
@@ -202,10 +200,8 @@ void NetworkFindBroadcastIPs(NetworkAddressList *broadcast)
/* Now display to the debug all the detected ips */
DEBUG(net, 3, "Detected broadcast addresses:");
int i = 0;
for (NetworkAddress *addr = broadcast->Begin(); addr != broadcast->End(); addr++) {
addr->SetPort(NETWORK_DEFAULT_PORT);
DEBUG(net, 3, "%d) %s", i++, addr->GetHostname());
for (NetworkAddress &addr : *broadcast) {
addr.SetPort(NETWORK_DEFAULT_PORT);
DEBUG(net, 3, "%d) %s", i++, addr.GetHostname());
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -18,8 +18,6 @@
/* Include standard stuff per OS */
#ifdef ENABLE_NETWORK
/* Windows stuff */
#if defined(_WIN32)
#include <errno.h>
@@ -185,6 +183,4 @@ static inline bool SetNoDelay(SOCKET d)
assert_compile(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
assert_compile(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_OS_ABSTRACTION_H */

View File

@@ -11,8 +11,6 @@
* @file packet.cpp Basic functions to create, fill and read packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../string_func.h"
#include "../../command_type.h"
@@ -373,5 +371,3 @@ void Packet::Recv_binary(std::string &buffer, size_t size)
buffer.assign((const char *) &this->buffer[this->pos], size);
this->pos += (PacketSize) size;
}
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "../../string_type.h"
#include <string>
#ifdef ENABLE_NETWORK
typedef uint16 PacketSize; ///< Size of the whole packet.
typedef uint8 PacketType; ///< Identifier for the packet
@@ -94,6 +92,4 @@ public:
void Recv_binary(std::string &buffer, size_t size);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_PACKET_H */

View File

@@ -11,8 +11,6 @@
* @file tcp.cpp Basic functions to receive and send TCP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
@@ -238,5 +236,3 @@ bool NetworkTCPSocketHandler::CanSendReceive()
this->writable = !!FD_ISSET(this->sock, &write_fd);
return FD_ISSET(this->sock, &read_fd) != 0;
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "address.h"
#include "packet.h"
#ifdef ENABLE_NETWORK
/** The states of sending the packets. */
enum SendPacketsState {
SPS_CLOSED, ///< The connection got closed.
@@ -42,7 +40,7 @@ public:
*/
bool IsConnected() const { return this->sock != INVALID_SOCKET; }
virtual NetworkRecvStatus CloseConnection(bool error = true);
NetworkRecvStatus CloseConnection(bool error = true) override;
virtual void SendPacket(Packet *packet);
SendPacketsState SendPackets(bool closing_down = false);
@@ -99,6 +97,4 @@ public:
static void KillAll();
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_admin.cpp Basic functions to receive and send TCP packets to and from the admin network.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../network_internal.h"
@@ -172,5 +170,3 @@ NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_NAMES(Packet *p)
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_CMD_LOGGING(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_CMD_LOGGING); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_RCON_END(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_RCON_END); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_SERVER_PONG(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_SERVER_PONG); }
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "../network_type.h"
#include "../../core/pool_type.hpp"
#ifdef ENABLE_NETWORK
/**
* Enum with types of TCP packets specific to the admin network.
* This protocol may only be extended to ensure stability.
@@ -483,7 +481,7 @@ protected:
NetworkRecvStatus HandlePacket(Packet *p);
public:
NetworkRecvStatus CloseConnection(bool error = true);
NetworkRecvStatus CloseConnection(bool error = true) override;
NetworkAdminSocketHandler(SOCKET s);
~NetworkAdminSocketHandler();
@@ -500,6 +498,4 @@ public:
}
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_ADMIN_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_connect.cpp Basic functions to create connections without blocking.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../thread/thread.h"
@@ -21,7 +19,7 @@
#include "../../safeguards.h"
/** List of connections that are currently being created */
static SmallVector<TCPConnecter *, 1> _tcp_connecters;
static std::vector<TCPConnecter *> _tcp_connecters;
/**
* Create a new connecter for the given address
@@ -34,7 +32,7 @@ TCPConnecter::TCPConnecter(const NetworkAddress &address) :
sock(INVALID_SOCKET),
address(address)
{
*_tcp_connecters.Append() = this;
_tcp_connecters.push_back(this);
if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread, "ottd:tcp")) {
this->Connect();
}
@@ -68,22 +66,22 @@ void TCPConnecter::Connect()
*/
/* static */ void TCPConnecter::CheckCallbacks()
{
for (TCPConnecter **iter = _tcp_connecters.Begin(); iter < _tcp_connecters.End(); /* nothing */) {
for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) {
TCPConnecter *cur = *iter;
if ((cur->connected || cur->aborted) && cur->killed) {
_tcp_connecters.Erase(iter);
iter = _tcp_connecters.erase(iter);
if (cur->sock != INVALID_SOCKET) closesocket(cur->sock);
delete cur;
continue;
}
if (cur->connected) {
_tcp_connecters.Erase(iter);
iter = _tcp_connecters.erase(iter);
cur->OnConnect(cur->sock);
delete cur;
continue;
}
if (cur->aborted) {
_tcp_connecters.Erase(iter);
iter = _tcp_connecters.erase(iter);
cur->OnFailure();
delete cur;
continue;
@@ -95,7 +93,5 @@ void TCPConnecter::Connect()
/** Kill all connection attempts. */
/* static */ void TCPConnecter::KillAll()
{
for (TCPConnecter **iter = _tcp_connecters.Begin(); iter != _tcp_connecters.End(); iter++) (*iter)->killed = true;
for (TCPConnecter *conn : _tcp_connecters) conn->killed = true;
}
#endif /* ENABLE_NETWORK */

View File

@@ -11,8 +11,6 @@
* @file tcp_content.cpp Basic functions to receive and send Content packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#ifndef OPENTTD_MSU
#include "../../textfile_gui.h"
@@ -266,5 +264,3 @@ Subdirectory GetContentInfoSubDir(ContentType type)
}
}
#endif /* OPENTTD_MSU */
#endif /* ENABLE_NETWORK */

View File

@@ -19,8 +19,6 @@
#include "packet.h"
#include "../../debug.h"
#ifdef ENABLE_NETWORK
/** The values in the enum are important; they are used as database 'keys' */
enum ContentType {
CONTENT_TYPE_BEGIN = 1, ///< Helper to mark the begin of the types
@@ -100,7 +98,7 @@ struct ContentInfo {
class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
protected:
NetworkAddress client_addr; ///< The address we're connected to.
virtual void Close();
void Close() override;
bool ReceiveInvalidPacket(PacketContentType type);
@@ -213,6 +211,4 @@ public:
Subdirectory GetContentInfoSubDir(ContentType type);
#endif /* OPENTTD_MSU */
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_CONTENT_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_game.cpp Basic functions to receive and send TCP packets for game purposes.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../network.h"
@@ -199,5 +197,3 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE(Packet *p) { ret
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_MOVE); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMPANY_UPDATE); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CONFIG_UPDATE); }
#endif /* ENABLE_NETWORK */

View File

@@ -20,8 +20,6 @@
#include "../../core/pool_type.hpp"
#include <memory>
#ifdef ENABLE_NETWORK
/**
* Enum with all types of TCP packets.
* For the exact meaning, look at #NetworkGameSocketHandler.
@@ -528,7 +526,7 @@ public:
CommandQueue incoming_queue; ///< The command-queue awaiting handling
uint last_packet; ///< Time we received the last frame.
NetworkRecvStatus CloseConnection(bool error = true);
NetworkRecvStatus CloseConnection(bool error = true) override;
/**
* Close the network connection due to the given status.
@@ -562,6 +560,4 @@ public:
void SendCommand(Packet *p, const CommandPacket *cp);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_GAME_H */

View File

@@ -11,8 +11,6 @@
* @file tcp_http.cpp Basic functions to receive and send HTTP TCP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../debug.h"
#include "../../rev.h"
@@ -23,7 +21,7 @@
#include "../../safeguards.h"
/** List of open HTTP connections. */
static SmallVector<NetworkHTTPSocketHandler *, 1> _http_connections;
static std::vector<NetworkHTTPSocketHandler *> _http_connections;
/**
* Start the querying
@@ -65,7 +63,7 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s,
return;
}
*_http_connections.Append() = this;
_http_connections.push_back(this);
}
/** Free whatever needs to be freed. */
@@ -299,21 +297,21 @@ int NetworkHTTPSocketHandler::Receive()
/* static */ void NetworkHTTPSocketHandler::HTTPReceive()
{
/* No connections, just bail out. */
if (_http_connections.Length() == 0) return;
if (_http_connections.size() == 0) return;
fd_set read_fd;
struct timeval tv;
FD_ZERO(&read_fd);
for (NetworkHTTPSocketHandler **iter = _http_connections.Begin(); iter < _http_connections.End(); iter++) {
FD_SET((*iter)->sock, &read_fd);
for (NetworkHTTPSocketHandler *handler : _http_connections) {
FD_SET(handler->sock, &read_fd);
}
tv.tv_sec = tv.tv_usec = 0; // don't block at all.
int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
if (n == -1) return;
for (NetworkHTTPSocketHandler **iter = _http_connections.Begin(); iter < _http_connections.End(); /* nothing */) {
for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) {
NetworkHTTPSocketHandler *cur = *iter;
if (FD_ISSET(cur->sock, &read_fd)) {
@@ -323,7 +321,7 @@ int NetworkHTTPSocketHandler::Receive()
if (ret <= 0) {
/* Then... the connection can be closed */
cur->CloseConnection();
_http_connections.Erase(iter);
iter = _http_connections.erase(iter);
delete cur;
continue;
}
@@ -331,5 +329,3 @@ int NetworkHTTPSocketHandler::Receive()
iter++;
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -16,8 +16,6 @@
#include "tcp.h"
#ifdef ENABLE_NETWORK
/** Callback for when the HTTP handler has something to tell us. */
struct HTTPCallback {
/**
@@ -62,7 +60,7 @@ public:
return this->sock != INVALID_SOCKET;
}
virtual NetworkRecvStatus CloseConnection(bool error = true);
NetworkRecvStatus CloseConnection(bool error = true) override;
NetworkHTTPSocketHandler(SOCKET sock, HTTPCallback *callback,
const char *host, const char *url, const char *data, int depth);
@@ -108,13 +106,13 @@ public:
free(this->url);
}
virtual void OnFailure()
void OnFailure() override
{
this->callback->OnFailure();
free(this->data);
}
virtual void OnConnect(SOCKET s)
void OnConnect(SOCKET s) override
{
new NetworkHTTPSocketHandler(s, this->callback, this->address.GetHostname(), this->url, this->data, this->depth);
/* We've relinquished control of data now. */
@@ -122,6 +120,4 @@ public:
}
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_HTTP_H */

View File

@@ -20,8 +20,6 @@
#include "../../debug.h"
#include "table/strings.h"
#ifdef ENABLE_NETWORK
/**
* Template for TCP listeners.
* @param Tsocket The class we create sockets for.
@@ -56,13 +54,13 @@ public:
/* Check if the client is banned */
bool banned = false;
for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++) {
banned = address.IsInNetmask(*iter);
for (char *entry : _network_ban_list) {
banned = address.IsInNetmask(entry);
if (banned) {
Packet p(Tban_packet);
p.PrepareToSend();
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), *iter);
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry);
if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
@@ -113,16 +111,16 @@ public:
}
/* take care of listener port */
for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
FD_SET(s->second, &read_fd);
for (auto &s : sockets) {
FD_SET(s.second, &read_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;
/* accept clients.. */
for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
if (FD_ISSET(s->second, &read_fd)) AcceptClient(s->second);
for (auto &s : sockets) {
if (FD_ISSET(s.second, &read_fd)) AcceptClient(s.second);
}
/* read stuff from clients */
@@ -142,16 +140,16 @@ public:
*/
static bool Listen(uint16 port)
{
assert(sockets.Length() == 0);
assert(sockets.size() == 0);
NetworkAddressList addresses;
GetBindAddresses(&addresses, port);
for (NetworkAddress *address = addresses.Begin(); address != addresses.End(); address++) {
address->Listen(SOCK_STREAM, &sockets);
for (NetworkAddress &address : addresses) {
address.Listen(SOCK_STREAM, &sockets);
}
if (sockets.Length() == 0) {
if (sockets.size() == 0) {
DEBUG(net, 0, "[server] could not start network: could not create listening socket");
NetworkError(STR_NETWORK_ERROR_SERVER_START);
return false;
@@ -163,16 +161,14 @@ public:
/** Close the sockets we're listening on. */
static void CloseListeners()
{
for (SocketList::iterator s = sockets.Begin(); s != sockets.End(); s++) {
closesocket(s->second);
for (auto &s : sockets) {
closesocket(s.second);
}
sockets.Clear();
sockets.clear();
DEBUG(net, 1, "[%s] closed listeners", Tsocket::GetName());
}
};
template <class Tsocket, PacketType Tfull_packet, PacketType Tban_packet> SocketList TCPListenHandler<Tsocket, Tfull_packet, Tban_packet>::sockets;
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_LISTEN_H */

View File

@@ -11,8 +11,6 @@
* @file core/udp.cpp Basic functions to receive and send UDP packets.
*/
#ifdef ENABLE_NETWORK
#include "../../stdafx.h"
#include "../../date_func.h"
#include "../../debug.h"
@@ -31,15 +29,15 @@ extern const uint8 _out_of_band_grf_md5[16];
NetworkUDPSocketHandler::NetworkUDPSocketHandler(NetworkAddressList *bind)
{
if (bind != NULL) {
for (NetworkAddress *addr = bind->Begin(); addr != bind->End(); addr++) {
*this->bind.Append() = *addr;
for (NetworkAddress &addr : *bind) {
this->bind.push_back(addr);
}
} else {
/* As hostname NULL and port 0/NULL don't go well when
* resolving it we need to add an address for each of
* the address families we support. */
*this->bind.Append() = NetworkAddress(NULL, 0, AF_INET);
*this->bind.Append() = NetworkAddress(NULL, 0, AF_INET6);
this->bind.emplace_back(nullptr, 0, AF_INET);
this->bind.emplace_back(nullptr, 0, AF_INET6);
}
this->fragment_token = ((uint64) InteractiveRandom()) | (((uint64) InteractiveRandom()) << 32);
@@ -55,11 +53,11 @@ bool NetworkUDPSocketHandler::Listen()
/* Make sure socket is closed */
this->Close();
for (NetworkAddress *addr = this->bind.Begin(); addr != this->bind.End(); addr++) {
addr->Listen(SOCK_DGRAM, &this->sockets);
for (NetworkAddress &addr : this->bind) {
addr.Listen(SOCK_DGRAM, &this->sockets);
}
return this->sockets.Length() != 0;
return this->sockets.size() != 0;
}
/**
@@ -67,10 +65,10 @@ bool NetworkUDPSocketHandler::Listen()
*/
void NetworkUDPSocketHandler::Close()
{
for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
closesocket(s->second);
for (auto &s : this->sockets) {
closesocket(s.second);
}
this->sockets.Clear();
this->sockets.clear();
}
NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection(bool error)
@@ -88,7 +86,7 @@ NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection(bool error)
*/
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast)
{
if (this->sockets.Length() == 0) this->Listen();
if (this->sockets.size() == 0) this->Listen();
if (p->size > SEND_MTU) {
p->PrepareToSend();
@@ -117,26 +115,26 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
return;
}
for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
for (auto &s : this->sockets) {
/* Make a local copy because if we resolve it we cannot
* easily unresolve it so we can resolve it later again. */
NetworkAddress send(*recv);
/* Not the same type */
if (!send.IsFamily(s->first.GetAddress()->ss_family)) continue;
if (!send.IsFamily(s.first.GetAddress()->ss_family)) continue;
p->PrepareToSend();
if (broadcast) {
/* Enable broadcast */
unsigned long val = 1;
if (setsockopt(s->second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
if (setsockopt(s.second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
DEBUG(net, 1, "[udp] setting broadcast failed with: %i", GET_LAST_ERROR());
}
}
/* Send the buffer */
int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
int res = sendto(s.second, (const char*)p->buffer, p->size, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString());
/* Check for any errors, but ignore it otherwise */
@@ -151,7 +149,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
*/
void NetworkUDPSocketHandler::ReceivePackets()
{
for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
for (auto &s : this->sockets) {
for (int i = 0; i < 1000; i++) { // Do not infinitely loop when DoSing with UDP
struct sockaddr_storage client_addr;
memset(&client_addr, 0, sizeof(client_addr));
@@ -160,8 +158,8 @@ void NetworkUDPSocketHandler::ReceivePackets()
socklen_t client_len = sizeof(client_addr);
/* Try to receive anything */
SetNonBlocking(s->second); // Some OSes seem to lose the non-blocking status of the socket
int nbytes = recvfrom(s->second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
SetNonBlocking(s.second); // Some OSes seem to lose the non-blocking status of the socket
int nbytes = recvfrom(s.second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
/* Did we get the bytes for the base header of the packet? */
if (nbytes <= 0) break; // No data, i.e. no packet
@@ -569,5 +567,3 @@ void NetworkUDPSocketHandler::Receive_SERVER_UNREGISTER(Packet *p, NetworkAddres
void NetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_GET_NEWGRFS, client_addr); }
void NetworkUDPSocketHandler::Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_NEWGRFS, client_addr); }
void NetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_MASTER_SESSION_KEY, client_addr); }
#endif /* ENABLE_NETWORK */

View File

@@ -22,8 +22,6 @@
#include <string>
#include <time.h>
#ifdef ENABLE_NETWORK
/** Enum with all types of UDP packets. The order MUST not be changed **/
enum PacketUDPType {
PACKET_UDP_CLIENT_FIND_SERVER, ///< Queries a game server for game information
@@ -71,7 +69,7 @@ protected:
};
std::vector<FragmentSet> fragments;
NetworkRecvStatus CloseConnection(bool error = true);
NetworkRecvStatus CloseConnection(bool error = true) override;
void ReceiveInvalidPacket(PacketUDPType, NetworkAddress *client_addr);
@@ -258,7 +256,7 @@ public:
virtual ~NetworkUDPSocketHandler() { this->Close(); }
bool Listen();
void Close();
void Close() override;
void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false);
void ReceivePackets();
@@ -269,6 +267,4 @@ public:
void ReceiveNetworkGameInfoExtended(Packet *p, NetworkGameInfo *info);
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_UDP_H */

View File

@@ -11,8 +11,6 @@
#include "../stdafx.h"
#ifdef ENABLE_NETWORK
#include "../strings_func.h"
#include "../command_func.h"
#include "../date_func.h"
@@ -597,12 +595,12 @@ class TCPQueryConnecter : TCPConnecter {
public:
TCPQueryConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
virtual void OnFailure()
void OnFailure() override
{
NetworkDisconnect();
}
virtual void OnConnect(SOCKET s)
void OnConnect(SOCKET s) override
{
_networking = true;
new ClientNetworkGameSocketHandler(s);
@@ -653,13 +651,13 @@ void NetworkAddServer(const char *b)
*/
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
{
for (char **iter = _network_bind_list.Begin(); iter != _network_bind_list.End(); iter++) {
*addresses->Append() = NetworkAddress(*iter, port);
for (char *iter : _network_bind_list) {
addresses->emplace_back(iter, port);
}
/* No address, so bind to everything. */
if (addresses->Length() == 0) {
*addresses->Append() = NetworkAddress("", port);
if (addresses->size() == 0) {
addresses->emplace_back("", port);
}
}
@@ -671,7 +669,7 @@ void NetworkRebuildHostList()
_network_host_list.Clear();
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
if (item->manually) *_network_host_list.Append() = stredup(item->address.GetAddressAsString(false));
if (item->manually) _network_host_list.push_back(stredup(item->address.GetAddressAsString(false)));
}
}
@@ -680,12 +678,12 @@ class TCPClientConnecter : TCPConnecter {
public:
TCPClientConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
virtual void OnFailure()
void OnFailure() override
{
NetworkError(STR_NETWORK_ERROR_NOCONNECTION);
}
virtual void OnConnect(SOCKET s)
void OnConnect(SOCKET s) override
{
_networking = true;
new ClientNetworkGameSocketHandler(s);
@@ -1132,5 +1130,3 @@ bool IsNetworkCompatibleVersion(const char *other, bool extended)
{
return strncmp(_openttd_revision, other, (extended ? NETWORK_LONG_REVISION_LENGTH : NETWORK_REVISION_LENGTH) - 1) == 0;
}
#endif /* ENABLE_NETWORK */

View File

@@ -12,9 +12,6 @@
#ifndef NETWORK_H
#define NETWORK_H
#ifdef ENABLE_NETWORK
void NetworkStartUp();
void NetworkShutDown();
void NetworkDrawChatMessage();
@@ -26,19 +23,4 @@ extern bool _network_available; ///< is network mode available?
extern bool _network_dedicated; ///< are we a dedicated server?
extern bool _is_network_server; ///< Does this client wants to be a network-server?
#else /* ENABLE_NETWORK */
/* Network function stubs when networking is disabled */
static inline void NetworkStartUp() {}
static inline void NetworkShutDown() {}
static inline void NetworkDrawChatMessage() {}
static inline bool HasClients() { return false; }
#define _networking 0
#define _network_server 0
#define _network_available 0
#define _network_dedicated 0
#define _is_network_server 0
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_H */

View File

@@ -9,8 +9,6 @@
/** @file network_admin.cpp Server part of the admin network protocol. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../strings_func.h"
#include "../date_func.h"
@@ -1045,5 +1043,3 @@ void NetworkAdminUpdate(AdminUpdateFrequency freq)
}
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -12,8 +12,6 @@
#ifndef NETWORK_ADMIN_H
#define NETWORK_ADMIN_H
#ifdef ENABLE_NETWORK
#include "network_internal.h"
#include "core/tcp_listen.h"
#include "core/tcp_admin.h"
@@ -28,14 +26,14 @@ extern NetworkAdminSocketPool _networkadminsocket_pool;
/** Class for handling the server side of the game connection. */
class ServerNetworkAdminSocketHandler : public NetworkAdminSocketPool::PoolItem<&_networkadminsocket_pool>, public NetworkAdminSocketHandler, public TCPListenHandler<ServerNetworkAdminSocketHandler, ADMIN_PACKET_SERVER_FULL, ADMIN_PACKET_SERVER_BANNED> {
protected:
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p);
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p);
NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_POLL(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_RCON(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p) override;
NetworkRecvStatus Receive_ADMIN_PING(Packet *p) override;
NetworkRecvStatus SendProtocol();
NetworkRecvStatus SendPong(uint32 d1);
@@ -124,5 +122,4 @@ void NetworkAdminConsole(const char *origin, const char *string);
void NetworkAdminGameScript(const char *json);
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp);
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_ADMIN_H */

View File

@@ -12,8 +12,6 @@
#ifndef NETWORK_BASE_H
#define NETWORK_BASE_H
#ifdef ENABLE_NETWORK
#include "network_type.h"
#include "core/address.h"
#include "../core/pool_type.hpp"
@@ -54,5 +52,4 @@ struct NetworkClientInfo : NetworkClientInfoPool::PoolItem<&_networkclientinfo_p
*/
#define FOR_ALL_CLIENT_INFOS(var) FOR_ALL_CLIENT_INFOS_FROM(var, 0)
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_BASE_H */

View File

@@ -11,8 +11,6 @@
#include <stdarg.h> /* va_list */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../strings_func.h"
#include "../blitter/factory.hpp"
@@ -324,7 +322,7 @@ struct NetworkChatWindow : public Window {
InvalidateWindowData(WC_NEWS_WINDOW, 0, 0);
}
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
void FindWindowPlacementAndResize(int def_width, int def_height) override
{
Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
}
@@ -462,13 +460,13 @@ struct NetworkChatWindow : public Window {
free(pre_buf);
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
Point pt = { 0, _screen.height - sm_height - FindWindowById(WC_STATUS_BAR, 0)->height };
return pt;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_NC_DESTINATION) return;
@@ -481,7 +479,7 @@ struct NetworkChatWindow : public Window {
*size = maxdim(*size, d);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_NC_DESTINATION) return;
@@ -491,7 +489,7 @@ struct NetworkChatWindow : public Window {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->dest_string, TC_BLACK, SA_RIGHT);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_NC_SENDBUTTON: /* Send */
@@ -504,7 +502,7 @@ struct NetworkChatWindow : public Window {
}
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
EventState state = ES_NOT_HANDLED;
if (keycode == WKC_TAB) {
@@ -514,7 +512,7 @@ struct NetworkChatWindow : public Window {
return state;
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
_chat_tab_completion_active = false;
}
@@ -524,7 +522,7 @@ struct NetworkChatWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (data == this->dest) delete this;
}
@@ -564,5 +562,3 @@ void ShowNetworkChatQueryWindow(DestType type, int dest)
DeleteWindowByClass(WC_SEND_NETWORK_MSG);
new NetworkChatWindow(&_chat_window_desc, type, dest);
}
#endif /* ENABLE_NETWORK */

View File

@@ -9,8 +9,6 @@
/** @file network_client.cpp Client part of the network protocol. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "network_gui.h"
#include "../saveload/saveload.h"
@@ -44,7 +42,7 @@
struct PacketReader : LoadFilter {
static const size_t CHUNK = 32 * 1024; ///< 32 KiB chunks of memory.
AutoFreeSmallVector<byte *, 16> blocks; ///< Buffer with blocks of allocated memory.
AutoFreeSmallVector<byte *> blocks; ///< Buffer with blocks of allocated memory.
byte *buf; ///< Buffer we're going to write to/read from.
byte *bufe; ///< End of the buffer we write to/read from.
byte **block; ///< The block we're reading from/writing to.
@@ -80,14 +78,14 @@ struct PacketReader : LoadFilter {
/* Allocate a new chunk and add the remaining data. */
pbuf += to_write;
to_write = in_packet - to_write;
this->buf = *this->blocks.Append() = CallocT<byte>(CHUNK);
this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
this->bufe = this->buf + CHUNK;
memcpy(this->buf, pbuf, to_write);
this->buf += to_write;
}
/* virtual */ size_t Read(byte *rbuf, size_t size)
size_t Read(byte *rbuf, size_t size) override
{
/* Limit the amount to read to whatever we still have. */
size_t ret_size = size = min(this->written_bytes - this->read_bytes, size);
@@ -109,11 +107,11 @@ struct PacketReader : LoadFilter {
return ret_size;
}
/* virtual */ void Reset()
void Reset() override
{
this->read_bytes = 0;
this->block = this->blocks.Begin();
this->block = this->blocks.data();
this->buf = *this->block++;
this->bufe = this->buf + CHUNK;
}
@@ -1328,5 +1326,3 @@ bool NetworkMaxSpectatorsReached()
{
return NetworkSpectatorCount() >= (_network_server ? _settings_client.network.max_spectators : _network_server_max_spectators);
}
#endif /* ENABLE_NETWORK */

View File

@@ -12,8 +12,6 @@
#ifndef NETWORK_CLIENT_H
#define NETWORK_CLIENT_H
#ifdef ENABLE_NETWORK
#include "network_internal.h"
/** Class for handling the client side of the game connection. */
@@ -44,33 +42,33 @@ protected:
friend void NetworkClose(bool close_admins);
static ClientNetworkGameSocketHandler *my_client; ///< This is us!
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override;
static NetworkRecvStatus SendNewGRFsOk();
static NetworkRecvStatus SendGetMap();
@@ -80,7 +78,7 @@ public:
ClientNetworkGameSocketHandler(SOCKET s);
~ClientNetworkGameSocketHandler();
NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
void ClientError(NetworkRecvStatus res);
static NetworkRecvStatus SendCompanyInformationQuery();
@@ -118,6 +116,4 @@ extern CompanyID _network_join_as;
extern const char *_network_join_server_password;
extern const char *_network_join_company_password;
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CLIENT_H */

View File

@@ -9,8 +9,6 @@
/** @file network_command.cpp Command handling over network connections. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "network_admin.h"
#include "network_client.h"
@@ -373,5 +371,3 @@ void NetworkGameSocketHandler::SendCommand(Packet *p, const CommandPacket *cp)
}
p->Send_uint8 (callback);
}
#endif /* ENABLE_NETWORK */

View File

@@ -9,8 +9,6 @@
/** @file network_content.cpp Content sending/receiving part of the network protocol. */
#if defined(ENABLE_NETWORK)
#include "../stdafx.h"
#include "../rev.h"
#include "../ai/ai.hpp"
@@ -139,8 +137,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
if (ci->state == ContentInfo::UNSELECTED && ci->filesize == 0) ci->state = ContentInfo::DOES_NOT_EXIST;
/* Do we already have a stub for this? */
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ici = *iter;
for (ContentInfo *ici : this->infos) {
if (ici->type == ci->type && ici->unique_id == ci->unique_id &&
memcmp(ci->md5sum, ici->md5sum, sizeof(ci->md5sum)) == 0) {
/* Preserve the name if possible */
@@ -167,11 +164,11 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
return true;
}
*this->infos.Append() = ci;
this->infos.push_back(ci);
/* Incoming data means that we might need to reconsider dependencies */
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
this->CheckDependencyState(*iter);
for (ContentInfo *ici : this->infos) {
this->CheckDependencyState(ici);
}
this->OnReceiveContentInfo(ci);
@@ -253,13 +250,12 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
uint offset = 0;
while (cv->Length() > offset) {
while (cv->size() > offset) {
Packet *p = new Packet(send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID);
const uint to_send = min<uint>(cv->Length() - offset, max_per_packet);
const uint to_send = min<uint>(cv->size() - offset, max_per_packet);
p->Send_uint8(to_send);
for (uint i = 0; i < to_send; i++) {
const ContentInfo *ci = (*cv)[offset + i];
for (const ContentInfo *ci : *cv) {
p->Send_uint8((byte)ci->type);
p->Send_uint32(ci->unique_id);
if (!send_md5sum) continue;
@@ -274,11 +270,9 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
offset += to_send;
}
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : *cv) {
bool found = false;
for (ContentIterator iter2 = this->infos.Begin(); iter2 != this->infos.End(); iter2++) {
ContentInfo *ci2 = *iter2;
for (ContentInfo *ci2 : this->infos) {
if (ci->type == ci2->type && ci->unique_id == ci2->unique_id &&
(!send_md5sum || memcmp(ci->md5sum, ci2->md5sum, sizeof(ci->md5sum)) == 0)) {
found = true;
@@ -286,7 +280,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
}
}
if (!found) {
*this->infos.Append() = ci;
this->infos.push_back(ci);
} else {
delete ci;
}
@@ -304,15 +298,14 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
bytes = 0;
ContentIDList content;
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : this->infos) {
if (!ci->IsSelected() || ci->state == ContentInfo::ALREADY_HERE) continue;
*content.Append() = ci->id;
content.push_back(ci->id);
bytes += ci->filesize;
}
files = content.Length();
files = content.size();
/* If there's nothing to download, do nothing. */
if (files == 0) return;
@@ -330,7 +323,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContent(uint &files, uin
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const ContentIDList &content)
{
uint count = content.Length();
uint count = content.size();
/* Allocate memory for the whole request.
* Requests are "id\nid\n..." (as strings), so assume the maximum ID,
@@ -341,8 +334,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
const char *lastof = content_request + bytes - 1;
char *p = content_request;
for (const ContentID *id = content.Begin(); id != content.End(); id++) {
p += seprintf(p, lastof, "%d\n", *id);
for (const ContentID &id : content) {
p += seprintf(p, lastof, "%d\n", id);
}
this->http_response_index = -1;
@@ -358,8 +351,8 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(const Conten
*/
void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const ContentIDList &content)
{
uint count = content.Length();
const ContentID *content_ids = content.Begin();
uint count = content.size();
const ContentID *content_ids = content.data();
this->Connect();
while (count > 0) {
@@ -563,7 +556,8 @@ void ClientNetworkContentSocketHandler::OnFailure()
uint files, bytes;
this->DownloadSelectedContent(files, bytes, true);
this->http_response.Reset();
this->http_response.clear();
this->http_response.shrink_to_fit();
this->http_response_index = -2;
if (this->curFile != NULL) {
@@ -586,11 +580,11 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
if (this->http_response_index == -1) {
if (data != NULL) {
/* Append the rest of the response. */
memcpy(this->http_response.Append((uint)length), data, length);
memcpy(grow(this->http_response, (uint)length), data, length);
return;
} else {
/* Make sure the response is properly terminated. */
*this->http_response.Append() = '\0';
this->http_response.push_back('\0');
/* And prepare for receiving the rest of the data. */
this->http_response_index = 0;
@@ -615,7 +609,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
this->AfterDownload();
}
if ((uint)this->http_response_index >= this->http_response.Length()) {
if ((uint)this->http_response_index >= this->http_response.size()) {
/* It's not a real failure, but if there's
* nothing more to download it helps with
* cleaning up the stuff we allocated. */
@@ -633,7 +627,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
#define check_and_terminate(p) { check_not_null(p); *(p) = '\0'; }
for (;;) {
char *str = this->http_response.Begin() + this->http_response_index;
char *str = this->http_response.data() + this->http_response_index;
char *p = strchr(str, '\n');
check_and_terminate(p);
@@ -661,7 +655,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l
str = p + 1;
/* Is it a fallback URL? If so, just continue with the next one. */
if (strncmp(str, "ottd", 4) == 0) {
if ((uint)this->http_response_index >= this->http_response.Length()) {
if ((uint)this->http_response_index >= this->http_response.size()) {
/* Have we gone through all lines? */
this->OnFailure();
return;
@@ -720,7 +714,7 @@ ClientNetworkContentSocketHandler::~ClientNetworkContentSocketHandler()
delete this->curInfo;
if (this->curFile != NULL) fclose(this->curFile);
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
for (ContentInfo *ci : this->infos) delete ci;
}
/** Connect to the content server. */
@@ -732,13 +726,13 @@ public:
*/
NetworkContentConnecter(const NetworkAddress &address) : TCPConnecter(address) {}
virtual void OnFailure()
void OnFailure() override
{
_network_content_client.isConnecting = false;
_network_content_client.OnConnect(false);
}
virtual void OnConnect(SOCKET s)
void OnConnect(SOCKET s) override
{
assert(_network_content_client.sock == INVALID_SOCKET);
_network_content_client.isConnecting = false;
@@ -801,10 +795,9 @@ void ClientNetworkContentSocketHandler::SendReceive()
void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
{
/* When we tried to download it already, don't try again */
if (this->requested.Contains(cid)) return;
if (std::find(this->requested.begin(), this->requested.end(), cid) != this->requested.end()) return;
*this->requested.Append() = cid;
assert(this->requested.Contains(cid));
this->requested.push_back(cid);
this->RequestContentList(1, &cid);
}
@@ -815,8 +808,7 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
*/
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->id == cid) return ci;
}
return NULL;
@@ -852,8 +844,7 @@ void ClientNetworkContentSocketHandler::Unselect(ContentID cid)
/** Select everything we can select */
void ClientNetworkContentSocketHandler::SelectAll()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -864,8 +855,7 @@ void ClientNetworkContentSocketHandler::SelectAll()
/** Select everything that's an update for something we've got */
void ClientNetworkContentSocketHandler::SelectUpgrade()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->state == ContentInfo::UNSELECTED && ci->upgrade) {
ci->state = ContentInfo::SELECTED;
this->CheckDependencyState(ci);
@@ -876,8 +866,7 @@ void ClientNetworkContentSocketHandler::SelectUpgrade()
/** Unselect everything that we've not downloaded so far. */
void ClientNetworkContentSocketHandler::UnselectAll()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
ContentInfo *ci = *iter;
for (ContentInfo *ci : this->infos) {
if (ci->IsSelected() && ci->state != ContentInfo::ALREADY_HERE) ci->state = ContentInfo::UNSELECTED;
}
}
@@ -907,13 +896,12 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
*/
void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const
{
for (ConstContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo * const &ci : this->infos) {
if (ci == child) continue;
for (uint i = 0; i < ci->dependency_count; i++) {
if (ci->dependencies[i] == child->id) {
*parents.Append() = ci;
parents.push_back(ci);
break;
}
}
@@ -927,18 +915,18 @@ void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVect
*/
void ClientNetworkContentSocketHandler::ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const
{
*tree.Append() = child;
tree.push_back(child);
/* First find all direct parents. We can't use the "normal" iterator as
* we are including stuff into the vector and as such the vector's data
* store can be reallocated (and thus move), which means out iterating
* pointer gets invalid. So fall back to the indices. */
for (uint i = 0; i < tree.Length(); i++) {
for (uint i = 0; i < tree.size(); i++) {
ConstContentVector parents;
this->ReverseLookupDependency(parents, tree[i]);
for (ConstContentIterator piter = parents.Begin(); piter != parents.End(); piter++) {
tree.Include(*piter);
for (const ContentInfo *ci : parents) {
include(tree, ci);
}
}
}
@@ -973,8 +961,7 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* we automatically selected them. */
ConstContentVector parents;
this->ReverseLookupDependency(parents, ci);
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
const ContentInfo *c = *iter;
for (const ContentInfo *c : parents) {
if (!c->IsSelected()) continue;
this->Unselect(c->id);
@@ -989,15 +976,15 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
if (c->state != ContentInfo::AUTOSELECTED) continue;
/* Only unselect when WE are the only parent. */
parents.Clear();
parents.clear();
this->ReverseLookupDependency(parents, c);
/* First check whether anything depends on us */
int sel_count = 0;
bool force_selection = false;
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
if ((*iter)->IsSelected()) sel_count++;
if ((*iter)->state == ContentInfo::SELECTED) force_selection = true;
for (const ContentInfo *ci : parents) {
if (ci->IsSelected()) sel_count++;
if (ci->state == ContentInfo::SELECTED) force_selection = true;
}
if (sel_count == 0) {
/* Nothing depends on us */
@@ -1008,12 +995,12 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
if (force_selection) continue;
/* "Flood" search to find all items in the dependency graph*/
parents.Clear();
parents.clear();
this->ReverseLookupTreeDependency(parents, c);
/* Is there anything that is "force" selected?, if so... we're done. */
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
if ((*iter)->state != ContentInfo::SELECTED) continue;
for (const ContentInfo *ci : parents) {
if (ci->state != ContentInfo::SELECTED) continue;
force_selection = true;
break;
@@ -1026,12 +1013,11 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
* After that's done run over them once again to test their children
* to unselect. Don't do it immediately because it'll do exactly what
* we're doing now. */
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
const ContentInfo *c = *iter;
for (const ContentInfo *c : parents) {
if (c->state == ContentInfo::AUTOSELECTED) this->Unselect(c->id);
}
for (ConstContentIterator iter = parents.Begin(); iter != parents.End(); iter++) {
this->CheckDependencyState(this->GetContent((*iter)->id));
for (const ContentInfo *c : parents) {
this->CheckDependencyState(this->GetContent(c->id));
}
}
}
@@ -1039,47 +1025,47 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci)
/** Clear all downloaded content information. */
void ClientNetworkContentSocketHandler::Clear()
{
for (ContentIterator iter = this->infos.Begin(); iter != this->infos.End(); iter++) delete *iter;
for (ContentInfo *c : this->infos) delete c;
this->infos.Clear();
this->requested.Clear();
this->infos.clear();
this->requested.clear();
}
/*** CALLBACK ***/
void ClientNetworkContentSocketHandler::OnConnect(bool success)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnConnect(success);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDisconnect()
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDisconnect();
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo *ci)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnReceiveContentInfo(ci);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes)
{
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadProgress(ci, bytes);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
@@ -1090,11 +1076,9 @@ void ClientNetworkContentSocketHandler::OnDownloadComplete(ContentID cid)
ci->state = ContentInfo::ALREADY_HERE;
}
for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) {
for (auto iter = this->callbacks.begin(); iter != this->callbacks.end(); /* nothing */) {
ContentCallback *cb = *iter;
cb->OnDownloadComplete(cid);
if (iter != this->callbacks.End() && *iter == cb) iter++;
if (iter != this->callbacks.end() && *iter == cb) iter++;
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -15,12 +15,10 @@
#include "core/tcp_content.h"
#include "core/tcp_http.h"
#if defined(ENABLE_NETWORK)
/** Vector with content info */
typedef SmallVector<ContentInfo *, 16> ContentVector;
typedef std::vector<ContentInfo *> ContentVector;
/** Vector with constant content info */
typedef SmallVector<const ContentInfo *, 16> ConstContentVector;
typedef std::vector<const ContentInfo *> ConstContentVector;
/** Iterator for the content vector */
typedef ContentInfo **ContentIterator;
@@ -68,12 +66,12 @@ struct ContentCallback {
*/
class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, ContentCallback, HTTPCallback {
protected:
typedef SmallVector<ContentID, 4> ContentIDList; ///< List of content IDs to (possibly) select.
SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
ContentIDList requested; ///< ContentIDs we already requested (so we don't do it again)
ContentVector infos; ///< All content info we received
SmallVector<char, 1024> http_response; ///< The HTTP response to the requests we've been doing
int http_response_index; ///< Where we are, in the response, with handling it
typedef std::vector<ContentID> ContentIDList; ///< List of content IDs to (possibly) select.
std::vector<ContentCallback *> callbacks; ///< Callbacks to notify "the world"
ContentIDList requested; ///< ContentIDs we already requested (so we don't do it again)
ContentVector infos; ///< All content info we received
std::vector<char> http_response; ///< The HTTP response to the requests we've been doing
int http_response_index; ///< Where we are, in the response, with handling it
FILE *curFile; ///< Currently downloaded file
ContentInfo *curInfo; ///< Information about the currently downloaded file
@@ -82,20 +80,20 @@ protected:
friend class NetworkContentConnecter;
virtual bool Receive_SERVER_INFO(Packet *p);
virtual bool Receive_SERVER_CONTENT(Packet *p);
bool Receive_SERVER_INFO(Packet *p) override;
bool Receive_SERVER_CONTENT(Packet *p) override;
ContentInfo *GetContent(ContentID cid);
void DownloadContentInfo(ContentID cid);
void OnConnect(bool success);
void OnDisconnect();
void OnReceiveContentInfo(const ContentInfo *ci);
void OnDownloadProgress(const ContentInfo *ci, int bytes);
void OnDownloadComplete(ContentID cid);
void OnConnect(bool success) override;
void OnDisconnect() override;
void OnReceiveContentInfo(const ContentInfo *ci) override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override;
void OnDownloadComplete(ContentID cid) override;
void OnFailure();
void OnReceiveData(const char *data, size_t length);
void OnFailure() override;
void OnReceiveData(const char *data, size_t length) override;
bool BeforeDownload();
void AfterDownload();
@@ -111,7 +109,7 @@ public:
void Connect();
void SendReceive();
void Close();
void Close() override;
void RequestContentList(ContentType type);
void RequestContentList(uint count, const ContentID *content_ids);
@@ -131,20 +129,20 @@ public:
void CheckDependencyState(ContentInfo *ci);
/** Get the number of content items we know locally. */
uint Length() const { return this->infos.Length(); }
uint Length() const { return this->infos.size(); }
/** Get the begin of the content inf iterator. */
ConstContentIterator Begin() const { return this->infos.Begin(); }
ConstContentIterator Begin() const { return this->infos.data(); }
/** Get the nth position of the content inf iterator. */
ConstContentIterator Get(uint32 index) const { return this->infos.Get(index); }
ConstContentIterator Get(uint32 index) const { return this->infos.data() + index; }
/** Get the end of the content inf iterator. */
ConstContentIterator End() const { return this->infos.End(); }
ConstContentIterator End() const { return this->Begin() + this->Length(); }
void Clear();
/** Add a callback to this class */
void AddCallback(ContentCallback *cb) { this->callbacks.Include(cb); }
void AddCallback(ContentCallback *cb) { include(this->callbacks, cb); }
/** Remove a callback */
void RemoveCallback(ContentCallback *cb) { this->callbacks.Erase(this->callbacks.Find(cb)); }
void RemoveCallback(ContentCallback *cb) { this->callbacks.erase(std::find(this->callbacks.begin(), this->callbacks.end(), cb)); }
};
extern ClientNetworkContentSocketHandler _network_content_client;
@@ -153,8 +151,4 @@ void ShowNetworkContentListWindow(ContentVector *cv = NULL, ContentType type1 =
void ShowMissingContentWindow(const struct GRFConfig *list);
#else
static inline void ShowNetworkContentListWindow() {}
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CONTENT_H */

View File

@@ -9,7 +9,6 @@
/** @file network_content_gui.cpp Implementation of the Network Content related GUIs. */
#if defined(ENABLE_NETWORK)
#include "../stdafx.h"
#include "../strings_func.h"
#include "../gfx_func.h"
@@ -65,7 +64,7 @@ struct ContentTextfileWindow : public TextfileWindow {
}
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, this->GetTypeString());
@@ -116,7 +115,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
_network_content_client.RemoveCallback(this);
}
/* virtual */ void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
void BaseNetworkContentDownloadStatusWindow::DrawWidget(const Rect &r, int widget) const
{
if (widget != WID_NCDS_BACKGROUND) return;
@@ -145,7 +144,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
DrawStringMultiLine(r.left + 2, r.right - 2, y, y + FONT_HEIGHT_NORMAL * 2, str, TC_FROMSTRING, SA_CENTER);
}
/* virtual */ void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInfo *ci, int bytes)
{
if (ci->id != this->cur_id) {
strecpy(this->name, ci->filename, lastof(this->name));
@@ -161,7 +160,7 @@ BaseNetworkContentDownloadStatusWindow::~BaseNetworkContentDownloadStatusWindow(
/** Window for showing the download status of content */
struct NetworkContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
private:
SmallVector<ContentType, 4> receivedTypes; ///< Types we received so we can update their cache
std::vector<ContentType> receivedTypes; ///< Types we received so we can update their cache
public:
/**
@@ -177,8 +176,8 @@ public:
~NetworkContentDownloadStatusWindow()
{
TarScanner::Mode mode = TarScanner::NONE;
for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
switch (*iter) {
for (auto ctype : this->receivedTypes) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
/* AI::Rescan calls the scanner. */
@@ -211,8 +210,8 @@ public:
TarScanner::DoScan(mode);
/* Tell all the backends about what we've downloaded */
for (ContentType *iter = this->receivedTypes.Begin(); iter != this->receivedTypes.End(); iter++) {
switch (*iter) {
for (auto ctype : this->receivedTypes) {
switch (ctype) {
case CONTENT_TYPE_AI:
case CONTENT_TYPE_AI_LIBRARY:
AI::Rescan();
@@ -258,7 +257,7 @@ public:
InvalidateWindowData(WC_NETWORK_WINDOW, WN_NETWORK_WINDOW_CONTENT_LIST, 2);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget == WID_NCDS_CANCELOK) {
if (this->downloaded_bytes != this->total_bytes) {
@@ -272,10 +271,10 @@ public:
}
}
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
{
BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(ci, bytes);
this->receivedTypes.Include(ci->type);
include(this->receivedTypes, ci->type);
/* When downloading is finished change cancel in ok */
if (this->downloaded_bytes == this->total_bytes) {
@@ -334,8 +333,7 @@ class NetworkContentListWindow : public Window, ContentCallback {
pos = strecpy(pos, "do=searchgrfid&q=", last);
bool first = true;
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : this->content) {
if (ci->state != ContentInfo::DOES_NOT_EXIST) continue;
if (!first) pos = strecpy(pos, ",", last);
@@ -386,23 +384,23 @@ class NetworkContentListWindow : public Window, ContentCallback {
if (!this->content.NeedRebuild()) return;
/* Create temporary array of games to use for listing */
this->content.Clear();
this->content.clear();
bool all_available = true;
for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
if ((*iter)->state == ContentInfo::DOES_NOT_EXIST) all_available = false;
*this->content.Append() = *iter;
this->content.push_back(*iter);
}
this->SetWidgetDisabledState(WID_NCL_SEARCH_EXTERNAL, this->auto_select && all_available);
this->FilterContentList();
this->content.Compact();
this->content.shrink_to_fit();
this->content.RebuildDone();
this->SortContentList();
this->vscroll->SetCount(this->content.Length()); // Update the scrollbar
this->vscroll->SetCount(this->content.size()); // Update the scrollbar
this->ScrollToSelected();
}
@@ -436,12 +434,8 @@ class NetworkContentListWindow : public Window, ContentCallback {
{
if (!this->content.Sort()) return;
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
if (*iter == this->selected) {
this->list_pos = iter - this->content.Begin();
break;
}
}
int idx = find_index(this->content, this->selected);
if (idx >= 0) this->list_pos = idx;
}
/** Filter content by tags/name */
@@ -479,11 +473,10 @@ class NetworkContentListWindow : public Window, ContentCallback {
if (!changed) return;
/* update list position */
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
if (*iter == this->selected) {
this->list_pos = iter - this->content.Begin();
return;
}
int idx = find_index(this->content, this->selected);
if (idx >= 0) {
this->list_pos = idx;
return;
}
/* previously selected item not in list anymore */
@@ -563,7 +556,7 @@ public:
_network_content_client.RemoveCallback(this);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
@@ -591,7 +584,7 @@ public:
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NCL_FILTER_CAPT:
@@ -608,7 +601,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
const SortButtonState arrow = this->content.IsDescSortOrder() ? SBS_DOWN : SBS_UP;
@@ -641,8 +634,13 @@ public:
int sprite_y_offset = WD_MATRIX_TOP + (line_height - this->checkbox_size.height) / 2 - 1;
int text_y_offset = WD_MATRIX_TOP + (line_height - FONT_HEIGHT_NORMAL) / 2;
uint y = r.top;
int cnt = 0;
for (ConstContentIterator iter = this->content.Get(this->vscroll->GetPosition()); iter != this->content.End() && cnt < this->vscroll->GetCapacity(); iter++, cnt++) {
auto iter = this->content.begin() + this->vscroll->GetPosition();
auto end = iter + this->vscroll->GetCapacity();
if (end > this->content.end())
end = this->content.end();
for (/**/; iter != end; iter++) {
const ContentInfo *ci = *iter;
if (ci == this->selected) GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->resize.step_height - 1, PC_GREY);
@@ -767,8 +765,7 @@ public:
char buf[DRAW_STRING_BUFFER] = "";
char *p = buf;
for (ConstContentIterator iter = tree.Begin(); iter != tree.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : tree) {
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name);
@@ -780,7 +777,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
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;
@@ -792,9 +789,9 @@ public:
switch (widget) {
case WID_NCL_MATRIX: {
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NCL_MATRIX);
if (id_v >= this->content.Length()) return; // click out of bounds
if (id_v >= this->content.size()) return; // click out of bounds
this->selected = *this->content.Get(id_v);
this->selected = this->content[id_v];
this->list_pos = id_v;
const NWidgetBase *checkbox = this->GetWidget<NWidgetBase>(WID_NCL_CHECKBOX);
@@ -816,7 +813,7 @@ public:
case WID_NCL_NAME:
if (this->content.SortType() == widget - WID_NCL_CHECKBOX) {
this->content.ToggleSortOrder();
if (this->content.Length() > 0) this->list_pos = this->content.Length() - this->list_pos - 1;
if (this->content.size() > 0) this->list_pos = this->content.size() - this->list_pos - 1;
} else {
this->content.SetSortType(widget - WID_NCL_CHECKBOX);
this->content.ForceResort();
@@ -866,7 +863,7 @@ public:
}
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
switch (keycode) {
case WKC_UP:
@@ -875,7 +872,7 @@ public:
break;
case WKC_DOWN:
/* scroll down by one */
if (this->list_pos < (int)this->content.Length() - 1) this->list_pos++;
if (this->list_pos < (int)this->content.size() - 1) this->list_pos++;
break;
case WKC_PAGEUP:
/* scroll up a page */
@@ -883,7 +880,7 @@ public:
break;
case WKC_PAGEDOWN:
/* scroll down a page */
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.Length() - 1);
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->content.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
@@ -891,7 +888,7 @@ public:
break;
case WKC_END:
/* jump to end */
this->list_pos = this->content.Length() - 1;
this->list_pos = this->content.size() - 1;
break;
case WKC_SPACE:
@@ -915,7 +912,7 @@ public:
return ES_NOT_HANDLED;
}
if (this->content.Length() == 0) {
if (this->content.size() == 0) {
this->list_pos = 0; // above stuff may result in "-1".
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
@@ -924,7 +921,7 @@ public:
return ES_HANDLED;
}
this->selected = *this->content.Get(this->list_pos);
this->selected = this->content[this->list_pos];
if (this->UpdateFilterState()) {
this->content.ForceRebuild();
@@ -938,7 +935,7 @@ public:
return ES_HANDLED;
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_NCL_FILTER) {
this->filter_data.string_filter.SetFilterTerm(this->filter_editbox.text.buf);
@@ -948,25 +945,25 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_NCL_MATRIX);
}
virtual void OnReceiveContentInfo(const ContentInfo *rci)
void OnReceiveContentInfo(const ContentInfo *rci) override
{
if (this->auto_select && !rci->IsSelected()) _network_content_client.ToggleSelectedState(rci);
this->content.ForceRebuild();
this->InvalidateData();
}
virtual void OnDownloadComplete(ContentID cid)
void OnDownloadComplete(ContentID cid) override
{
this->content.ForceResort();
this->InvalidateData();
}
virtual void OnConnect(bool success)
void OnConnect(bool success) override
{
if (!success) {
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR);
@@ -982,7 +979,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
if (this->content.NeedRebuild()) this->BuildContentList();
@@ -991,8 +988,7 @@ public:
this->filesize_sum = 0;
bool show_select_all = false;
bool show_select_upgrade = false;
for (ConstContentIterator iter = this->content.Begin(); iter != this->content.End(); iter++) {
const ContentInfo *ci = *iter;
for (const ContentInfo *ci : this->content) {
switch (ci->state) {
case ContentInfo::SELECTED:
case ContentInfo::AUTOSELECTED:
@@ -1164,9 +1160,7 @@ void ShowNetworkContentListWindow(ContentVector *cv, ContentType type1, ContentT
ShowErrorMessage(STR_CONTENT_NO_ZLIB, STR_CONTENT_NO_ZLIB_SUB, WL_ERROR);
/* Connection failed... clean up the mess */
if (cv != NULL) {
for (ContentIterator iter = cv->Begin(); iter != cv->End(); iter++) delete *iter;
for (ContentInfo *ci : *cv) delete ci;
}
#endif /* WITH_ZLIB */
}
#endif /* ENABLE_NETWORK */

View File

@@ -39,8 +39,8 @@ public:
*/
~BaseNetworkContentDownloadStatusWindow();
virtual void DrawWidget(const Rect &r, int widget) const;
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes);
void DrawWidget(const Rect &r, int widget) const override;
void OnDownloadProgress(const ContentInfo *ci, int bytes) override;
};
void BuildContentTypeStringList();

View File

@@ -26,8 +26,6 @@
#include "../openttd.h"
#include "../company_type.h"
#ifdef ENABLE_NETWORK
extern NetworkServerGameInfo _network_game_info;
extern NetworkCompanyState *_network_company_states;
@@ -90,5 +88,4 @@ void NetworkChatMessageLoop();
void NetworkAfterNewGRFScan();
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_FUNC_H */

View File

@@ -12,8 +12,6 @@
* Also, it handles the request to a server for data about the server
*/
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../debug.h"
#include "../window_func.h"
@@ -206,5 +204,3 @@ void NetworkAfterNewGRFScan()
InvalidateWindowClassesData(WC_NETWORK_WINDOW);
}
#endif /* ENABLE_NETWORK */

View File

@@ -9,7 +9,6 @@
/** @file network_gui.cpp Implementation of the Network related GUIs. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../strings_func.h"
#include "../date_func.h"
@@ -120,7 +119,7 @@ public:
*lastof(this->visible) = true;
}
void SetupSmallestSize(Window *w, bool init_array)
void SetupSmallestSize(Window *w, bool init_array) override
{
/* Oh yeah, we ought to be findable! */
w->nested_array[WID_NG_HEADER] = this;
@@ -146,7 +145,7 @@ public:
this->smallest_x = this->head->smallest_x + this->tail->smallest_x; // First and last are always shown, rest not
}
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
{
assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
@@ -186,7 +185,7 @@ public:
}
}
/* virtual */ void Draw(const Window *w)
void Draw(const Window *w) override
{
int i = 0;
for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
@@ -196,7 +195,7 @@ public:
}
}
/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y)
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;
@@ -253,10 +252,10 @@ protected:
if (!this->servers.NeedRebuild()) return;
/* Create temporary array of games to use for listing */
this->servers.Clear();
this->servers.clear();
for (NetworkGameList *ngl = _network_game_list; ngl != NULL; ngl = ngl->next) {
*this->servers.Append() = ngl;
this->servers.push_back(ngl);
}
/* Apply the filter condition immediately, if a search string has been provided. */
@@ -270,9 +269,9 @@ protected:
this->servers.SetFilterState(false);
}
this->servers.Compact();
this->servers.shrink_to_fit();
this->servers.RebuildDone();
this->vscroll->SetCount(this->servers.Length());
this->vscroll->SetCount(this->servers.size());
/* Sort the list of network games as requested. */
this->servers.Sort();
@@ -357,7 +356,7 @@ protected:
void UpdateListPos()
{
this->list_pos = SLP_INVALID;
for (uint i = 0; i != this->servers.Length(); i++) {
for (uint i = 0; i != this->servers.size(); i++) {
if (this->servers[i] == this->server) {
this->list_pos = i;
break;
@@ -497,7 +496,7 @@ public:
this->last_sorting = this->servers.GetListing();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_NG_CONN_BTN:
@@ -506,7 +505,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NG_CONN_BTN:
@@ -561,13 +560,13 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NG_MATRIX: {
uint16 y = r.top;
const int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.Length());
const int max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), (int)this->servers.size());
for (int i = this->vscroll->GetPosition(); i < max; ++i) {
const NetworkGameList *ngl = this->servers[i];
@@ -598,7 +597,7 @@ public:
}
virtual void OnPaint()
void OnPaint() override
{
if (this->servers.NeedRebuild()) {
this->BuildGUINetworkGameList();
@@ -694,7 +693,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_NG_CANCEL: // Cancel button
@@ -713,7 +712,7 @@ public:
case WID_NG_INFO: // Connectivity (green dot)
if (this->servers.SortType() == widget - WID_NG_NAME) {
this->servers.ToggleSortOrder();
if (this->list_pos != SLP_INVALID) this->list_pos = this->servers.Length() - this->list_pos - 1;
if (this->list_pos != SLP_INVALID) this->list_pos = this->servers.size() - this->list_pos - 1;
} else {
this->servers.SetSortType(widget - WID_NG_NAME);
this->servers.ForceResort();
@@ -725,7 +724,7 @@ 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.Length()) ? this->servers[id_v] : NULL;
this->server = (id_v < this->servers.size()) ? this->servers[id_v] : NULL;
this->list_pos = (server == NULL) ? SLP_INVALID : id_v;
this->SetDirty();
@@ -791,7 +790,7 @@ public:
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_NG_CONN_BTN:
@@ -810,19 +809,19 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
this->servers.ForceRebuild();
this->SetDirty();
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
EventState state = ES_NOT_HANDLED;
/* handle up, down, pageup, pagedown, home and end */
if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
if (this->servers.Length() == 0) return ES_HANDLED;
if (this->servers.size() == 0) return ES_HANDLED;
switch (keycode) {
case WKC_UP:
/* scroll up by one */
@@ -832,7 +831,7 @@ public:
case WKC_DOWN:
/* scroll down by one */
if (this->list_pos == SLP_INVALID) return ES_HANDLED;
if (this->list_pos < this->servers.Length() - 1) this->list_pos++;
if (this->list_pos < this->servers.size() - 1) this->list_pos++;
break;
case WKC_PAGEUP:
/* scroll up a page */
@@ -842,7 +841,7 @@ public:
case WKC_PAGEDOWN:
/* scroll down a page */
if (this->list_pos == SLP_INVALID) return ES_HANDLED;
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.Length() - 1);
this->list_pos = min(this->list_pos + this->vscroll->GetCapacity(), (int)this->servers.size() - 1);
break;
case WKC_HOME:
/* jump to beginning */
@@ -850,7 +849,7 @@ public:
break;
case WKC_END:
/* jump to end */
this->list_pos = this->servers.Length() - 1;
this->list_pos = this->servers.size() - 1;
break;
default: NOT_REACHED();
}
@@ -877,7 +876,7 @@ public:
return state;
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
switch (wid) {
case WID_NG_FILTER: {
@@ -899,17 +898,17 @@ public:
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (!StrEmpty(str)) NetworkAddServer(str);
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_NG_MATRIX);
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
if (!this->requery_timer.Elapsed(delta_ms)) return;
this->requery_timer.SetInterval(MILLISECONDS_PER_TICK);
@@ -1048,8 +1047,8 @@ void ShowNetworkGameWindow()
if (first) {
first = false;
/* Add all servers from the config file to our list. */
for (char **iter = _network_host_list.Begin(); iter != _network_host_list.End(); iter++) {
NetworkAddServer(*iter);
for (char *iter : _network_host_list) {
NetworkAddServer(iter);
}
}
@@ -1070,7 +1069,7 @@ struct NetworkStartServerWindow : public Window {
this->SetFocusedWidget(WID_NSS_GAMENAME);
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_NSS_CONNTYPE_BTN:
@@ -1095,7 +1094,7 @@ struct NetworkStartServerWindow : public Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NSS_CONNTYPE_BTN:
@@ -1106,7 +1105,7 @@ struct NetworkStartServerWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NSS_SETPWD:
@@ -1115,7 +1114,7 @@ struct NetworkStartServerWindow : public Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_NSS_CANCEL: // Cancel button
@@ -1211,7 +1210,7 @@ struct NetworkStartServerWindow : public Window {
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_NSS_CONNTYPE_BTN:
@@ -1227,14 +1226,14 @@ struct NetworkStartServerWindow : public Window {
this->SetDirty();
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_NSS_GAMENAME) {
strecpy(_settings_client.network.server_name, this->name_editbox.text.buf, lastof(_settings_client.network.server_name));
}
}
virtual void OnTimeout()
void OnTimeout() override
{
static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WID_NSS_SPECTATORS_BTND, WID_NSS_SPECTATORS_BTNU, WIDGET_LIST_END};
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
@@ -1245,7 +1244,7 @@ struct NetworkStartServerWindow : public Window {
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
@@ -1387,7 +1386,7 @@ struct NetworkLobbyWindow : public Window {
return COMPANY_FIRST;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_NL_HEADER:
@@ -1405,7 +1404,7 @@ struct NetworkLobbyWindow : public Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_NL_TEXT:
@@ -1414,7 +1413,7 @@ struct NetworkLobbyWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_NL_DETAILS:
@@ -1427,7 +1426,7 @@ struct NetworkLobbyWindow : public Window {
}
}
virtual void OnPaint()
void OnPaint() override
{
const NetworkGameInfo *gi = &this->server->info;
@@ -1549,7 +1548,7 @@ struct NetworkLobbyWindow : public Window {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_PLAYERS); // players
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_NL_CANCEL: // Cancel button
@@ -1588,7 +1587,7 @@ struct NetworkLobbyWindow : public Window {
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_NL_MATRIX);
}
@@ -1725,7 +1724,7 @@ struct NetworkClientListPopupWindow : Window {
uint sel_index;
ClientID client_id;
Point desired_location;
SmallVector<ClientListAction, 2> actions; ///< Actions to execute
std::vector<ClientListAction> actions; ///< Actions to execute
/**
* Add an action to the list of actions to execute.
@@ -1734,9 +1733,7 @@ struct NetworkClientListPopupWindow : Window {
*/
inline void AddAction(StringID name, ClientList_Action_Proc *proc)
{
ClientListAction *action = this->actions.Append();
action->name = name;
action->proc = proc;
this->actions.push_back({name, proc});
}
NetworkClientListPopupWindow(WindowDesc *desc, int x, int y, ClientID client_id) :
@@ -1767,30 +1764,30 @@ struct NetworkClientListPopupWindow : Window {
CLRBITS(this->flags, WF_WHITE_BORDER);
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
return this->desired_location;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
Dimension d = *size;
for (const ClientListAction *action = this->actions.Begin(); action != this->actions.End(); action++) {
d = maxdim(GetStringBoundingBox(action->name), d);
for (const ClientListAction &action : this->actions) {
d = maxdim(GetStringBoundingBox(action.name), d);
}
d.height *= this->actions.Length();
d.height *= this->actions.size();
d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
*size = d;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
/* Draw the actions */
int sel = this->sel_index;
int y = r.top + WD_FRAMERECT_TOP;
for (const ClientListAction *action = this->actions.Begin(); action != this->actions.End(); action++, y += FONT_HEIGHT_NORMAL) {
for (const ClientListAction &action : this->actions) {
TextColour colour;
if (sel-- == 0) { // Selected item, highlight it
GfxFillRect(r.left + 1, y, r.right - 1, y + FONT_HEIGHT_NORMAL - 1, PC_BLACK);
@@ -1799,22 +1796,23 @@ struct NetworkClientListPopupWindow : Window {
colour = TC_BLACK;
}
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, action->name, colour);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, action.name, colour);
y += FONT_HEIGHT_NORMAL;
}
}
virtual void OnMouseLoop()
void OnMouseLoop() override
{
/* We selected an action */
uint index = (_cursor.pos.y - this->top - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL;
if (_left_button_down) {
if (index == this->sel_index || index >= this->actions.Length()) return;
if (index == this->sel_index || index >= this->actions.size()) return;
this->sel_index = index;
this->SetDirty();
} else {
if (index < this->actions.Length() && _cursor.pos.y >= this->top) {
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);
}
@@ -1894,7 +1892,7 @@ struct NetworkClientListWindow : Window {
return true;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_CL_PANEL) return;
@@ -1911,7 +1909,7 @@ struct NetworkClientListWindow : Window {
size->width = WD_FRAMERECT_LEFT + this->server_client_width + this->icon_size.width + WD_FRAMERECT_LEFT + width + WD_FRAMERECT_RIGHT;
}
virtual void OnPaint()
void OnPaint() override
{
/* Check if we need to reset the height */
if (!this->CheckClientListHeight()) return;
@@ -1919,7 +1917,7 @@ struct NetworkClientListWindow : Window {
this->DrawWidgets();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_CL_PANEL) return;
@@ -1965,7 +1963,7 @@ struct NetworkClientListWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
/* Show the popup with option */
if (this->selected_item != -1) {
@@ -1981,7 +1979,7 @@ struct NetworkClientListWindow : Window {
}
}
virtual void OnMouseOver(Point pt, int widget)
void OnMouseOver(Point pt, int widget) override
{
/* -1 means we left the current window */
if (pt.y == -1) {
@@ -2025,7 +2023,7 @@ struct NetworkJoinStatusWindow : Window {
this->InitNested(WN_NETWORK_STATUS_WINDOW_JOIN);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_NJS_BACKGROUND) return;
@@ -2059,7 +2057,7 @@ struct NetworkJoinStatusWindow : Window {
DrawFrameRect(r.left + 20, r.top + 5, (int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_NJS_BACKGROUND) return;
@@ -2085,7 +2083,7 @@ struct NetworkJoinStatusWindow : Window {
size->width = width + WD_FRAMERECT_LEFT + WD_FRAMERECT_BOTTOM + 10;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget == WID_NJS_CANCELOK) { // Disconnect button
NetworkDisconnect();
@@ -2094,7 +2092,7 @@ struct NetworkJoinStatusWindow : Window {
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (StrEmpty(str)) {
NetworkDisconnect();
@@ -2174,7 +2172,7 @@ struct NetworkCompanyPasswordWindow : public Window {
NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_NCP_OK:
@@ -2230,5 +2228,3 @@ void ShowNetworkCompanyPasswordWindow(Window *parent)
new NetworkCompanyPasswordWindow(&_network_company_password_window_desc, parent);
}
#endif /* ENABLE_NETWORK */

View File

@@ -17,8 +17,6 @@
#include "../window_type.h"
#include "network_type.h"
#ifdef ENABLE_NETWORK
void ShowNetworkNeedPassword(NetworkPasswordType npt);
void ShowNetworkGiveMoneyWindow(CompanyID company);
void ShowNetworkChatQueryWindow(DestType type, int dest);
@@ -42,14 +40,4 @@ struct NetworkCompanyInfo : NetworkCompanyStats {
NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company);
#else /* ENABLE_NETWORK */
/* Network function stubs when networking is disabled */
static inline void ShowNetworkChatQueryWindow(byte desttype, int dest) {}
static inline void ShowClientList() {}
static inline void ShowNetworkGameWindow() {}
static inline void ShowNetworkCompanyPasswordWindow(Window *parent) {}
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_GUI_H */

View File

@@ -17,8 +17,6 @@
#include "../command_type.h"
#ifdef ENABLE_NETWORK
#ifdef RANDOM_DEBUG
/**
* If this line is enable, every frame will have a sync test
@@ -171,5 +169,4 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkFindName(char *new_name, const char *last);
const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed);
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_INTERNAL_H */

View File

@@ -9,8 +9,6 @@
/** @file network_server.cpp Server part of the network protocol. */
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../strings_func.h"
#include "../date_func.h"
@@ -165,7 +163,7 @@ struct PacketWriter : SaveFilter {
this->current = NULL;
}
/* virtual */ void Write(byte *buf, size_t size)
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);
@@ -192,7 +190,7 @@ struct PacketWriter : SaveFilter {
this->total_size += size;
}
/* virtual */ void Finish()
void Finish() override
{
/* We want to abort the saving when the socket is closed. */
if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
@@ -2104,13 +2102,13 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
/* Add address to ban-list */
if (ban) {
bool contains = false;
for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++) {
if (strcmp(*iter, ip) == 0) {
for (char *iter : _network_ban_list) {
if (strcmp(iter, ip) == 0) {
contains = true;
break;
}
}
if (!contains) *_network_ban_list.Append() = stredup(ip);
if (!contains) _network_ban_list.push_back(stredup(ip));
}
uint n = 0;
@@ -2213,5 +2211,3 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);
}
}
#endif /* ENABLE_NETWORK */

View File

@@ -12,8 +12,6 @@
#ifndef NETWORK_SERVER_H
#define NETWORK_SERVER_H
#ifdef ENABLE_NETWORK
#include "network_internal.h"
#include "core/tcp_listen.h"
#include "../thread/thread.h"
@@ -28,22 +26,22 @@ extern NetworkClientSocketPool _networkclientsocket_pool;
/** Class for handling the server side of the game connection. */
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
protected:
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_ACK(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p);
virtual NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p);
NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_COMPANY_INFO(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_ACK(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_RCON(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;
NetworkRecvStatus SendCompanyInfo();
NetworkRecvStatus SendNewGRFCheck();
@@ -81,8 +79,8 @@ public:
ServerNetworkGameSocketHandler(SOCKET s);
~ServerNetworkGameSocketHandler();
virtual Packet *ReceivePacket();
NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
virtual Packet *ReceivePacket() override;
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
void GetClientName(char *client_name, const char *last) const;
NetworkRecvStatus SendMap();
@@ -138,12 +136,4 @@ void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded)
*/
#define FOR_ALL_CLIENT_SOCKETS(var) FOR_ALL_CLIENT_SOCKETS_FROM(var, 0)
#else /* ENABLE_NETWORK */
/* Network function stubs when networking is disabled */
static inline void NetworkServerMonthlyLoop() {}
static inline void NetworkServerYearlyLoop() {}
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_SERVER_H */

View File

@@ -14,8 +14,6 @@
#include "core/game.h"
#ifdef ENABLE_NETWORK
/** How many clients can we have */
static const uint MAX_CLIENTS = 255;
@@ -149,5 +147,4 @@ struct NetworkTextMessageData {
}
};
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_TYPE_H */

View File

@@ -14,8 +14,6 @@
* communication before the game is being joined.
*/
#ifdef ENABLE_NETWORK
#include "../stdafx.h"
#include "../date_func.h"
#include "../map_func.h"
@@ -133,8 +131,8 @@ void NetworkUDPQueryServer(NetworkAddress address, bool manually)
/** Helper class for connecting to the master server. */
class MasterNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
protected:
virtual void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr);
virtual void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr);
void Receive_MASTER_ACK_REGISTER(Packet *p, NetworkAddress *client_addr) override;
void Receive_MASTER_SESSION_KEY(Packet *p, NetworkAddress *client_addr) override;
public:
/**
* Create the socket.
@@ -164,9 +162,9 @@ void MasterNetworkUDPSocketHandler::Receive_MASTER_SESSION_KEY(Packet *p, Networ
/** Helper class for handling all server side communication. */
class ServerNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
protected:
virtual void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr);
virtual void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr);
virtual void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr);
void Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr) override;
void Receive_CLIENT_DETAIL_INFO(Packet *p, NetworkAddress *client_addr) override;
void Receive_CLIENT_GET_NEWGRFS(Packet *p, NetworkAddress *client_addr) override;
void Reply_CLIENT_FIND_SERVER_extended(Packet *p, NetworkAddress *client_addr, NetworkGameInfo *ngi);
public:
/**
@@ -386,11 +384,11 @@ class ClientNetworkUDPSocketHandler : public NetworkUDPSocketHandler {
private:
void Receive_SERVER_RESPONSE_Common(Packet *p, NetworkAddress *client_addr, bool extended);
protected:
virtual void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr);
virtual void Receive_EX_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr);
virtual void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr);
virtual void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr);
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config);
void Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr) override;
void Receive_EX_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr) override;
void Receive_MASTER_RESPONSE_LIST(Packet *p, NetworkAddress *client_addr) override;
void Receive_SERVER_NEWGRFS(Packet *p, NetworkAddress *client_addr) override;
void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) override;
public:
virtual ~ClientNetworkUDPSocketHandler() {}
};
@@ -579,12 +577,12 @@ void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFCo
/** Broadcast to all ips */
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
{
for (NetworkAddress *addr = _broadcast_list.Begin(); addr != _broadcast_list.End(); addr++) {
for (NetworkAddress &addr : _broadcast_list) {
Packet p = PrepareUdpClientFindServerPacket();
DEBUG(net, 4, "[udp] broadcasting to %s", addr->GetHostname());
DEBUG(net, 4, "[udp] broadcasting to %s", addr.GetHostname());
socket->SendPacket(&p, addr, true, true);
socket->SendPacket(&p, &addr, true, true);
}
}
@@ -752,7 +750,7 @@ void NetworkUDPInitialize()
GetBindAddresses(&server, _settings_client.network.server_port);
_udp_server_socket = new ServerNetworkUDPSocketHandler(&server);
server.Clear();
server.clear();
GetBindAddresses(&server, 0);
_udp_master_socket = new MasterNetworkUDPSocketHandler(&server);
@@ -796,5 +794,3 @@ void NetworkBackgroundUDPLoop()
_network_udp_mutex->EndCritical();
}
#endif /* ENABLE_NETWORK */

View File

@@ -12,8 +12,6 @@
#ifndef NETWORK_UDP_H
#define NETWORK_UDP_H
#ifdef ENABLE_NETWORK
#include "core/address.h"
void NetworkUDPInitialize();
@@ -25,6 +23,4 @@ void NetworkUDPRemoveAdvertise(bool blocking);
void NetworkUDPClose();
void NetworkBackgroundUDPLoop();
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_UDP_H */