Update to 12.0-RC1

This commit is contained in:
dP
2021-09-26 20:30:12 +03:00
parent c9765f712f
commit 4eb8b29dbf
173 changed files with 31125 additions and 9485 deletions

View File

@@ -22,6 +22,8 @@ add_files(
network_gui.cpp
network_gui.h
network_internal.h
network_query.cpp
network_query.h
network_server.cpp
network_server.h
network_stun.cpp

View File

@@ -53,6 +53,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
case ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY: return this->Receive_ADMIN_UPDATE_FREQUENCY(p);
case ADMIN_PACKET_ADMIN_POLL: return this->Receive_ADMIN_POLL(p);
case ADMIN_PACKET_ADMIN_CHAT: return this->Receive_ADMIN_CHAT(p);
case ADMIN_PACKET_ADMIN_EXTERNAL_CHAT: return this->Receive_ADMIN_EXTERNAL_CHAT(p);
case ADMIN_PACKET_ADMIN_RCON: return this->Receive_ADMIN_RCON(p);
case ADMIN_PACKET_ADMIN_GAMESCRIPT: return this->Receive_ADMIN_GAMESCRIPT(p);
case ADMIN_PACKET_ADMIN_PING: return this->Receive_ADMIN_PING(p);
@@ -132,6 +133,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *p) { ret
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENCY(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_POLL); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_CHAT); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_EXTERNAL_CHAT); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_RCON); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_GAMESCRIPT); }
NetworkRecvStatus NetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p) { return this->ReceiveInvalidPacket(ADMIN_PACKET_ADMIN_PING); }

View File

@@ -30,6 +30,7 @@ enum PacketAdminType {
ADMIN_PACKET_ADMIN_RCON, ///< The admin sends a remote console command.
ADMIN_PACKET_ADMIN_GAMESCRIPT, ///< The admin sends a JSON string for the GameScript.
ADMIN_PACKET_ADMIN_PING, ///< The admin sends a ping to the server, expecting a ping-reply (PONG) packet.
ADMIN_PACKET_ADMIN_EXTERNAL_CHAT, ///< The admin sends a chat message from external source.
ADMIN_PACKET_SERVER_FULL = 100, ///< The server tells the admin it cannot accept the admin.
ADMIN_PACKET_SERVER_BANNED, ///< The server tells the admin it is banned.
@@ -163,6 +164,17 @@ protected:
*/
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p);
/**
* Send chat from the external source:
* string Name of the source this message came from.
* uint16 TextColour to use for the message.
* string Name of the user who sent the messsage.
* string Message.
* @param p The packet that was just received.
* @return The state the network should have.
*/
virtual NetworkRecvStatus Receive_ADMIN_EXTERNAL_CHAT(Packet *p);
/**
* Execute a command on the servers console:
* string Command to be executed.

View File

@@ -205,9 +205,13 @@ void TCPConnecter::OnResolved(addrinfo *ai)
}
if (_debug_net_level >= 6) {
Debug(net, 6, "{} resolved in:", this->connection_string);
for (const auto &address : this->addresses) {
Debug(net, 6, "- {}", NetworkAddress(address->ai_addr, (int)address->ai_addrlen).GetAddressAsString());
if (this->addresses.size() == 0) {
Debug(net, 6, "{} did not resolve", this->connection_string);
} else {
Debug(net, 6, "{} resolved in:", this->connection_string);
for (const auto &address : this->addresses) {
Debug(net, 6, "- {}", NetworkAddress(address->ai_addr, (int)address->ai_addrlen).GetAddressAsString());
}
}
}

View File

@@ -26,7 +26,11 @@ protected:
/**
* Client requesting a list of content info:
* byte type
* uint32 openttd version
* uint32 openttd version (or 0xFFFFFFFF if using a list)
* Only if the above value is 0xFFFFFFFF:
* uint8 count
* string branch-name ("vanilla" for upstream OpenTTD)
* string release version (like "12.0")
* @param p The packet that was just received.
* @return True upon success, otherwise false.
*/

View File

@@ -94,6 +94,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
case PACKET_SERVER_COMMAND: return this->Receive_SERVER_COMMAND(p);
case PACKET_CLIENT_CHAT: return this->Receive_CLIENT_CHAT(p);
case PACKET_SERVER_CHAT: return this->Receive_SERVER_CHAT(p);
case PACKET_SERVER_EXTERNAL_CHAT: return this->Receive_SERVER_EXTERNAL_CHAT(p);
case PACKET_CLIENT_SET_PASSWORD: return this->Receive_CLIENT_SET_PASSWORD(p);
case PACKET_CLIENT_SET_NAME: return this->Receive_CLIENT_SET_NAME(p);
case PACKET_CLIENT_QUIT: return this->Receive_CLIENT_QUIT(p);
@@ -180,6 +181,7 @@ NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet *p) {
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_COMMAND); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_CHAT); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_CHAT); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_SERVER_EXTERNAL_CHAT); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_PASSWORD); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_SET_NAME); }
NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CLIENT_QUIT); }

View File

@@ -99,6 +99,7 @@ enum PacketGameType {
/* Human communication! */
PACKET_CLIENT_CHAT, ///< Client said something that should be distributed.
PACKET_SERVER_CHAT, ///< Server distributing the message of a client (or itself).
PACKET_SERVER_EXTERNAL_CHAT, ///< Server distributing the message from external source.
/* Remote console. */
PACKET_CLIENT_RCON, ///< Client asks the server to execute some command.
@@ -378,6 +379,16 @@ protected:
*/
virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
/**
* Sends a chat-packet for external source to the client:
* string Name of the source this message came from.
* uint16 TextColour to use for the message.
* string Name of the user who sent the messsage.
* string Message (max NETWORK_CHAT_LENGTH).
* @param p The packet that was just received.
*/
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet *p);
/**
* Set the password for the clients current company:
* string The password.

View File

@@ -14,6 +14,7 @@
#include "../date_func.h"
#include "network_admin.h"
#include "network_client.h"
#include "network_query.h"
#include "network_server.h"
#include "network_content.h"
#include "network_udp.h"
@@ -216,7 +217,7 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
/* This puts a text-message to the console, or in the future, the chat-box,
* (to keep it all a bit more general)
* If 'self_send' is true, this is the client who is sending the message */
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str, int64 data)
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str, int64 data, const std::string &data_str)
{
StringID strid;
switch (action) {
@@ -247,6 +248,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
case NETWORK_ACTION_CHAT_COMPANY: strid = self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY; break;
case NETWORK_ACTION_CHAT_CLIENT: strid = self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT; break;
case NETWORK_ACTION_KICKED: strid = STR_NETWORK_MESSAGE_KICKED; break;
case NETWORK_ACTION_EXTERNAL_CHAT: strid = STR_NETWORK_CHAT_EXTERNAL; break;
default: strid = STR_NETWORK_CHAT_ALL; break;
}
@@ -254,6 +256,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
SetDParamStr(0, name);
SetDParamStr(1, str);
SetDParam(2, data);
SetDParamStr(3, data_str);
/* All of these strings start with "***". These characters are interpreted as both left-to-right and
* right-to-left characters depending on the context. As the next text might be an user's name, the
@@ -264,7 +267,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", _date, _date_fract, message);
IConsolePrint(colour, message);
NetworkAddChatMessage((TextColour)colour, _settings_client.gui.network_chat_timeout, message);
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message);
}
/* Calculate the frame-lag of a client */
@@ -631,16 +634,14 @@ public:
void OnFailure() override
{
NetworkGameList *item = NetworkGameListAddItem(connection_string);
item->online = false;
item->status = NGLS_OFFLINE;
UpdateNetworkGameWindow();
}
void OnConnect(SOCKET s) override
{
_networking = true;
new ClientNetworkGameSocketHandler(s, this->connection_string);
MyClient::SendInformationQuery();
QueryNetworkGameSocketHandler::QueryServer(s, this->connection_string);
}
};
@@ -652,8 +653,6 @@ void NetworkQueryServer(const std::string &connection_string)
{
if (!_network_available) return;
NetworkInitialize();
new TCPQueryConnecter(connection_string);
}
@@ -1020,6 +1019,7 @@ void NetworkBackgroundLoop()
_network_coordinator_client.SendReceive();
TCPConnecter::CheckCallbacks();
NetworkHTTPSocketHandler::HTTPReceive();
QueryNetworkGameSocketHandler::SendReceive();
NetworkBackgroundUDPLoop();
}

View File

@@ -76,6 +76,11 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
_network_admins_connected--;
Debug(net, 3, "[admin] '{}' ({}) has disconnected", this->admin_name, this->admin_version);
if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID;
if (this->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) {
this->update_frequency[ADMIN_UPDATE_CONSOLE] = (AdminUpdateFrequency)0;
DebugReconsiderSendRemoteMessages();
}
}
/**
@@ -594,7 +599,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
/* Should COMPAT_MTU be exceeded, start a new packet
* (magic 5: 1 bool "more data" and one uint16 "command id", one
* byte for string '\0' termination and 1 bool "no more data" */
if (p->CanWriteToPacket(strlen(cmdname) + 5)) {
if (!p->CanWriteToPacket(strlen(cmdname) + 5)) {
p->Send_bool(false);
this->SendPacket(p);
@@ -688,6 +693,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_UPDATE_FREQUENC
this->update_frequency[type] = freq;
if (type == ADMIN_UPDATE_CONSOLE) DebugReconsiderSendRemoteMessages();
return NETWORK_RECV_STATUS_OKAY;
}
@@ -783,6 +790,25 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(Packet *p)
return NETWORK_RECV_STATUS_OKAY;
}
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(Packet *p)
{
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
std::string source = p->Recv_string(NETWORK_CHAT_LENGTH);
TextColour colour = (TextColour)p->Recv_uint16();
std::string user = p->Recv_string(NETWORK_CHAT_LENGTH);
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
if (!IsValidConsoleColour(colour)) {
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16)colour, source, user, msg, this->admin_name, this->admin_version);
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
}
NetworkServerSendExternalChat(source, colour, user, msg);
return NETWORK_RECV_STATUS_OKAY;
}
/*
* Useful wrapper functions
*/

View File

@@ -29,6 +29,7 @@ protected:
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_EXTERNAL_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;

View File

@@ -95,7 +95,7 @@ void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::st
ChatMessage *cmsg = &_chatmsg_list.emplace_front();
cmsg->message = message;
cmsg->colour = (colour & TC_IS_PALETTE_COLOUR) ? colour : TC_WHITE;
cmsg->colour = colour;
cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
_chatmessage_dirty_time = std::chrono::steady_clock::now();

View File

@@ -23,7 +23,6 @@
#include "../gfx_func.h"
#include "../error.h"
#include "../rev.h"
#include "core/game_info.h"
#include "network.h"
#include "network_base.h"
#include "network_client.h"
@@ -328,17 +327,6 @@ static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
* DEF_CLIENT_SEND_COMMAND has no parameters
************/
/**
* Query the server for server information.
*/
NetworkRecvStatus ClientNetworkGameSocketHandler::SendInformationQuery()
{
my_client->status = STATUS_GAME_INFO;
my_client->SendPacket(new Packet(PACKET_CLIENT_GAME_INFO));
return NETWORK_RECV_STATUS_OKAY;
}
/** Tell the server we would like to join. */
NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
{
@@ -557,26 +545,6 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *
return NETWORK_RECV_STATUS_SERVER_BANNED;
}
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p)
{
if (this->status != STATUS_GAME_INFO) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
/* Clear any existing GRFConfig chain. */
ClearGRFConfigList(&item->info.grfconfig);
/* Retrieve the NetworkGameInfo from the packet. */
DeserializeNetworkGameInfo(p, &item->info);
/* Check for compatability with the client. */
CheckGameCompatibility(item->info);
/* Ensure we consider the server online. */
item->online = true;
UpdateNetworkGameWindow();
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
/* This packet contains info about the client (playas and name)
* as client we save this in NetworkClientInfo, linked via 'client_id'
* which is always an unique number on a server. */
@@ -665,15 +633,6 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
/* If we query a server that is 1.11.1 or older, we get an
* NETWORK_ERROR_NOT_EXPECTED on requesting the game info. Show a special
* error popup in that case.
*/
if (error == NETWORK_ERROR_NOT_EXPECTED && this->status == STATUS_GAME_INFO) {
ShowErrorMessage(STR_NETWORK_ERROR_SERVER_TOO_OLD, INVALID_STRING_ID, WL_CRITICAL);
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
StringID err = STR_NETWORK_ERROR_LOSTCONNECTION;
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
/* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
@@ -1004,6 +963,22 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
return NETWORK_RECV_STATUS_OKAY;
}
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_EXTERNAL_CHAT(Packet *p)
{
if (this->status != STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
std::string source = p->Recv_string(NETWORK_CHAT_LENGTH);
TextColour colour = (TextColour)p->Recv_uint16();
std::string user = p->Recv_string(NETWORK_CHAT_LENGTH);
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
if (!IsValidConsoleColour(colour)) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
return NETWORK_RECV_STATUS_OKAY;
}
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(Packet *p)
{
if (this->status < STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;

View File

@@ -22,7 +22,6 @@ private:
/** Status of the connection with the server. */
enum ServerStatus {
STATUS_INACTIVE, ///< The client is not connected nor active.
STATUS_GAME_INFO, ///< We are trying to get the game information.
STATUS_JOIN, ///< We are trying to join a server.
STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs.
STATUS_AUTH_GAME, ///< Last action was requesting game (server) password.
@@ -44,7 +43,6 @@ protected:
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
NetworkRecvStatus Receive_SERVER_GAME_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;
@@ -59,6 +57,7 @@ protected:
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_EXTERNAL_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;
@@ -80,8 +79,6 @@ public:
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
void ClientError(NetworkRecvStatus res);
static NetworkRecvStatus SendInformationQuery();
static NetworkRecvStatus SendJoin();
static NetworkRecvStatus SendCommand(const CommandPacket *cp);
static NetworkRecvStatus SendError(NetworkErrorCode errorno);

View File

@@ -68,7 +68,11 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
uint dependency_count = p->Recv_uint8();
ci->dependencies.reserve(dependency_count);
for (uint i = 0; i < dependency_count; i++) ci->dependencies.push_back((ContentID)p->Recv_uint32());
for (uint i = 0; i < dependency_count; i++) {
ContentID dependency_cid = (ContentID)p->Recv_uint32();
ci->dependencies.push_back(dependency_cid);
this->reverse_dependency_map.insert({ dependency_cid, ci->id });
}
uint tag_count = p->Recv_uint8();
ci->tags.reserve(tag_count);
@@ -168,8 +172,10 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
this->infos.push_back(ci);
/* Incoming data means that we might need to reconsider dependencies */
for (ContentInfo *ici : this->infos) {
this->CheckDependencyState(ici);
ConstContentVector parents;
this->ReverseLookupTreeDependency(parents, ci);
for (const ContentInfo *ici : parents) {
this->CheckDependencyState(const_cast<ContentInfo *>(ici));
}
this->OnReceiveContentInfo(ci);
@@ -201,7 +207,20 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
Packet *p = new Packet(PACKET_CONTENT_CLIENT_INFO_LIST);
p->Send_uint8 ((byte)type);
p->Send_uint32(_openttd_newgrf_version);
p->Send_uint32(0xffffffff);
p->Send_uint8 (1);
p->Send_string("vanilla");
p->Send_string(_openttd_content_version);
/* Patchpacks can extend the list with one. In BaNaNaS metadata you can
* add a branch in the 'compatibility' list, to filter on this. If you want
* your patchpack to be mentioned in the BaNaNaS web-interface, create an
* issue on https://github.com/OpenTTD/bananas-api asking for this.
p->Send_string("patchpack"); // Or what-ever the name of your patchpack is.
p->Send_string(_openttd_content_version_patchpack);
*/
this->SendPacket(p);
}
@@ -833,7 +852,7 @@ void ClientNetworkContentSocketHandler::DownloadContentInfo(ContentID cid)
* @param cid the ContentID to search for
* @return the ContentInfo or nullptr if not found
*/
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid)
ContentInfo *ClientNetworkContentSocketHandler::GetContent(ContentID cid) const
{
for (ContentInfo *ci : this->infos) {
if (ci->id == cid) return ci;
@@ -923,15 +942,10 @@ void ClientNetworkContentSocketHandler::ToggleSelectedState(const ContentInfo *c
*/
void ClientNetworkContentSocketHandler::ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const
{
for (const ContentInfo *ci : this->infos) {
if (ci == child) continue;
auto range = this->reverse_dependency_map.equal_range(child->id);
for (auto &dependency : ci->dependencies) {
if (dependency == child->id) {
parents.push_back(ci);
break;
}
}
for (auto iter = range.first; iter != range.second; ++iter) {
parents.push_back(GetContent(iter->second));
}
}
@@ -1056,6 +1070,7 @@ void ClientNetworkContentSocketHandler::Clear()
this->infos.clear();
this->requested.clear();
this->reverse_dependency_map.clear();
}
/*** CALLBACK ***/

View File

@@ -12,6 +12,7 @@
#include "core/tcp_content.h"
#include "core/tcp_http.h"
#include <unordered_map>
/** Vector with content info */
typedef std::vector<ContentInfo *> ContentVector;
@@ -68,6 +69,7 @@ protected:
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::unordered_multimap<ContentID, ContentID> reverse_dependency_map; ///< Content reverse dependency map
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
@@ -81,7 +83,7 @@ protected:
bool Receive_SERVER_INFO(Packet *p) override;
bool Receive_SERVER_CONTENT(Packet *p) override;
ContentInfo *GetContent(ContentID cid);
ContentInfo *GetContent(ContentID cid) const;
void DownloadContentInfo(ContentID cid);
void OnConnect(bool success) override;

View File

@@ -152,7 +152,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(Packet *p)
/* Mark the server as offline. */
NetworkGameList *item = NetworkGameListAddItem(detail);
item->online = false;
item->status = NGLS_OFFLINE;
UpdateNetworkGameWindow();
return true;
@@ -257,7 +257,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet *p)
/* Check for compatability with the client. */
CheckGameCompatibility(item->info);
/* Mark server as online. */
item->online = true;
item->status = NGLS_ONLINE;
/* Mark the item as up-to-date. */
item->version = _network_game_list_version;
}
@@ -378,7 +378,6 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT(Packet *p)
this->game_connecter = nullptr;
}
Debug(misc, 0, "{}", ticket);
this->turn_handlers[token] = ClientNetworkTurnSocketHandler::Turn(token, tracking_number, ticket, connection_string);
if (!_network_server) {

View File

@@ -78,6 +78,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_na
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string);
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, ClientID from_id, int64 data = 0, bool from_admin = false);
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
void NetworkServerKickClient(ClientID client_id, const std::string &reason);
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason);

View File

@@ -43,6 +43,7 @@ NetworkGameList *NetworkGameListAddItem(const std::string &connection_string)
}
item = new NetworkGameList(resolved_connection_string);
item->info.gamescript_version = -1;
item->version = _network_game_list_version;
if (prev_item == nullptr) {

View File

@@ -14,17 +14,26 @@
#include "core/game_info.h"
#include "network_type.h"
/** The status a server can be in. */
enum NetworkGameListStatus {
NGLS_OFFLINE, ///< Server is offline (or cannot be queried).
NGLS_ONLINE, ///< Server is online.
NGLS_FULL, ///< Server is full and cannot be queried.
NGLS_BANNED, ///< You are banned from this server.
NGLS_TOO_OLD, ///< Server is too old to query.
};
/** Structure with information shown in the game list (GUI) */
struct NetworkGameList {
NetworkGameList(const std::string &connection_string) : connection_string(connection_string) {}
NetworkGameInfo info = {}; ///< The game information of this server
std::string connection_string; ///< Address of the server
bool online = false; ///< False if the server did not respond (default status)
bool manually = false; ///< True if the server was added manually
uint8 retries = 0; ///< Number of retries (to stop requerying)
int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed.
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list
NetworkGameInfo info = {}; ///< The game information of this server.
std::string connection_string; ///< Address of the server.
NetworkGameListStatus status = NGLS_OFFLINE; ///< Stats of the server.
bool manually = false; ///< True if the server was added manually.
uint8 retries = 0; ///< Number of retries (to stop requerying).
int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed.
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list.
};
extern NetworkGameList *_network_game_list;

View File

@@ -249,15 +249,21 @@ protected:
this->servers.clear();
bool found_current_server = false;
bool found_last_joined = false;
for (NetworkGameList *ngl = _network_game_list; ngl != nullptr; ngl = ngl->next) {
this->servers.push_back(ngl);
if (ngl == this->server) {
found_current_server = true;
}
if (ngl == this->last_joined) {
found_last_joined = true;
}
}
/* A refresh can cause the current server to be delete; so unselect. */
if (!found_last_joined) {
this->last_joined = nullptr;
}
if (!found_current_server) {
if (this->server == this->last_joined) this->last_joined = nullptr;
this->server = nullptr;
this->list_pos = SLP_INVALID;
}
@@ -401,7 +407,7 @@ protected:
DrawString(nwi_name->pos_x + WD_FRAMERECT_LEFT, nwi_name->pos_x + nwi_name->current_x - WD_FRAMERECT_RIGHT, y + text_y_offset, cur_item->info.server_name, TC_BLACK);
/* only draw details if the server is online */
if (cur_item->online) {
if (cur_item->status == NGLS_ONLINE) {
const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(WID_NG_HEADER);
if (nwi_header->IsWidgetVisible(WID_NG_CLIENTS)) {
@@ -603,13 +609,13 @@ public:
this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
/* 'Join' button disabling conditions */
this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
!sel->online || // Server offline
sel->status != NGLS_ONLINE || // Server offline
sel->info.clients_on >= sel->info.clients_max || // Server full
!sel->info.compatible); // Revision mismatch
/* 'NewGRF Settings' button invisible if no NewGRF is used */
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr);
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr);
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
#ifdef __EMSCRIPTEN__
this->SetWidgetDisabledState(WID_NG_SEARCH_INTERNET, true);
@@ -631,10 +637,20 @@ public:
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.top + detail_height - 1, PC_DARK_BLUE);
if (sel == nullptr) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);
} else if (!sel->online) {
} else if (sel->status != NGLS_ONLINE) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6 + 4 + FONT_HEIGHT_NORMAL, sel->info.server_name, TC_ORANGE, SA_HOR_CENTER); // game name
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, STR_NETWORK_SERVER_LIST_SERVER_OFFLINE, TC_FROMSTRING, SA_HOR_CENTER); // server offline
StringID message = INVALID_STRING_ID;
switch (sel->status) {
case NGLS_OFFLINE: message = STR_NETWORK_SERVER_LIST_SERVER_OFFLINE; break;
case NGLS_FULL: message = STR_NETWORK_SERVER_LIST_SERVER_FULL; break;
case NGLS_BANNED: message = STR_NETWORK_SERVER_LIST_SERVER_BANNED; break;
case NGLS_TOO_OLD: message = STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD; break;
/* Handled by the if-case above. */
case NGLS_ONLINE: NOT_REACHED();
}
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + detail_height + 4, message, TC_FROMSTRING, SA_HOR_CENTER); // server offline
} else { // show game info
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + 6, STR_NETWORK_SERVER_LIST_GAME_INFO, TC_FROMSTRING, SA_HOR_CENTER);

View File

@@ -119,7 +119,7 @@ void NetworkFreeLocalCommandQueue();
void NetworkSyncCommandQueue(NetworkClientSocket *cs);
void ShowNetworkError(StringID error_string);
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", int64 data = 0);
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const std::string &name, const std::string &str = "", int64 data = 0, const std::string &data_str = "");
uint NetworkCalculateLag(const NetworkClientSocket *cs);
StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkMakeClientNameUnique(std::string &new_name);

View File

@@ -0,0 +1,155 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file network_query.cpp Query part of the network protocol. */
#include "../stdafx.h"
#include "core/game_info.h"
#include "network_query.h"
#include "network_gamelist.h"
#include "../error.h"
#include "table/strings.h"
#include "../safeguards.h"
std::vector<std::unique_ptr<QueryNetworkGameSocketHandler>> QueryNetworkGameSocketHandler::queries = {};
NetworkRecvStatus QueryNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
{
assert(status != NETWORK_RECV_STATUS_OKAY);
assert(this->sock != INVALID_SOCKET);
return status;
}
/**
* Check the connection's state, i.e. is the connection still up?
*/
bool QueryNetworkGameSocketHandler::CheckConnection()
{
std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->last_packet;
/* If there was no response in 5 seconds, terminate the query. */
if (lag > std::chrono::seconds(5)) {
this->CloseConnection(NETWORK_RECV_STATUS_CONNECTION_LOST);
return false;
}
return true;
}
/**
* Check whether we received/can send some data from/to the server and
* when that's the case handle it appropriately.
* @return true when everything went okay.
*/
bool QueryNetworkGameSocketHandler::Receive()
{
if (this->CanSendReceive()) {
NetworkRecvStatus res = this->ReceivePackets();
if (res != NETWORK_RECV_STATUS_OKAY) {
this->CloseConnection(res);
return false;
}
}
return true;
}
/** Send the packets of this socket handler. */
void QueryNetworkGameSocketHandler::Send()
{
this->SendPackets();
}
/**
* Query the server for server information.
*/
NetworkRecvStatus QueryNetworkGameSocketHandler::SendGameInfo()
{
this->SendPacket(new Packet(PACKET_CLIENT_GAME_INFO));
return NETWORK_RECV_STATUS_OKAY;
}
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
{
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
item->status = NGLS_FULL;
UpdateNetworkGameWindow();
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p)
{
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
item->status = NGLS_BANNED;
UpdateNetworkGameWindow();
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet *p)
{
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
/* Clear any existing GRFConfig chain. */
ClearGRFConfigList(&item->info.grfconfig);
/* Retrieve the NetworkGameInfo from the packet. */
DeserializeNetworkGameInfo(p, &item->info);
/* Check for compatability with the client. */
CheckGameCompatibility(item->info);
/* Ensure we consider the server online. */
item->status = NGLS_ONLINE;
UpdateNetworkGameWindow();
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
{
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
if (error == NETWORK_ERROR_NOT_EXPECTED) {
/* If we query a server that is 1.11.1 or older, we get an
* NETWORK_ERROR_NOT_EXPECTED on requesting the game info. Show to the
* user this server is too old to query.
*/
item->status = NGLS_TOO_OLD;
} else {
item->status = NGLS_OFFLINE;
}
UpdateNetworkGameWindow();
return NETWORK_RECV_STATUS_CLOSE_QUERY;
}
/**
* Check if any query needs to send or receive.
*/
/* static */ void QueryNetworkGameSocketHandler::SendReceive()
{
for (auto it = QueryNetworkGameSocketHandler::queries.begin(); it != QueryNetworkGameSocketHandler::queries.end(); /* nothing */) {
if (!(*it)->Receive()) {
it = QueryNetworkGameSocketHandler::queries.erase(it);
} else if (!(*it)->CheckConnection()) {
it = QueryNetworkGameSocketHandler::queries.erase(it);
} else {
it++;
}
}
for (auto &query : QueryNetworkGameSocketHandler::queries) {
query->Send();
}
}

View File

@@ -0,0 +1,59 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file network_query.h Query part of the network protocol. */
#ifndef NETWORK_QUERY_H
#define NETWORK_QUERY_H
#include "network_internal.h"
/** Class for handling the client side of quering a game server. */
class QueryNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
private:
static std::vector<std::unique_ptr<QueryNetworkGameSocketHandler>> queries; ///< Pending queries.
std::string connection_string; ///< Address we are connected to.
protected:
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet *p) override;
NetworkRecvStatus SendGameInfo();
bool CheckConnection();
void Send();
bool Receive();
public:
/**
* Create a new socket for the client side of quering game server.
* @param s The socket to connect with.
* @param connection_string The connection string of the server.
*/
QueryNetworkGameSocketHandler(SOCKET s, const std::string &connection_string) : NetworkGameSocketHandler(s), connection_string(connection_string) {}
/**
* Start to query a server based on an open socket.
* @param s The socket to connect with.
* @param connection_string The connection string of the server.
*/
static void QueryServer(SOCKET s, const std::string &connection_string)
{
auto query = std::make_unique<QueryNetworkGameSocketHandler>(s, connection_string);
query->SendGameInfo();
QueryNetworkGameSocketHandler::queries.push_back(std::move(query));
}
static void SendReceive();
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
};
#endif /* NETWORK_QUERY_H */

View File

@@ -281,7 +281,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
}
NetworkAdminClientError(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
Debug(net, 3, "Closed client connection {}", this->client_id);
Debug(net, 3, "[{}] Client #{} closed connection", ServerNetworkGameSocketHandler::GetName(), this->client_id);
/* We just lost one client :( */
if (this->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
@@ -305,7 +305,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
{
extern byte _network_clients_connected;
bool accept = _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients;
bool accept = _network_clients_connected < MAX_CLIENTS;
/* We can't go over the MAX_CLIENTS limit here. However, the
* pool must have place for all clients and ourself. */
@@ -670,6 +670,28 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action,
return NETWORK_RECV_STATUS_OKAY;
}
/**
* Send a chat message from external source.
* @param source Name of the source this message came from.
* @param colour TextColour to use for the message.
* @param user Name of the user who sent the messsage.
* @param msg The actual message.
*/
NetworkRecvStatus ServerNetworkGameSocketHandler::SendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
{
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
Packet *p = new Packet(PACKET_SERVER_EXTERNAL_CHAT);
p->Send_string(source);
p->Send_uint16(colour);
p->Send_string(user);
p->Send_string(msg);
this->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
}
/**
* Tell the client another client quit with an error.
* @param client_id The client that quit.
@@ -805,6 +827,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
if (_network_game_info.clients_on >= _settings_client.network.max_clients) {
/* Turns out we are full. Inform the user about this. */
return this->SendError(NETWORK_ERROR_FULL);
}
std::string client_revision = p->Recv_string(NETWORK_REVISION_LENGTH);
uint32 newgrf_version = p->Recv_uint32();
@@ -943,6 +970,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet *
NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, "", this->client_id);
InvalidateWindowData(WC_CLIENT_LIST, 0);
Debug(net, 3, "[{}] Client #{} ({}) joined as {}", ServerNetworkGameSocketHandler::GetName(), this->client_id, this->GetClientIP(), client_name);
/* Mark the client as pre-active, and wait for an ACK
* so we know it is done loading and in sync with us */
this->status = STATUS_PRE_ACTIVE;
@@ -1255,12 +1284,27 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkClientInfo::GetByClientID(from_id);
if (ci != nullptr) {
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data, "");
}
break;
}
}
/**
* Send a chat message from external source.
* @param source Name of the source this message came from.
* @param colour TextColour to use for the message.
* @param user Name of the user who sent the messsage.
* @param msg The actual message.
*/
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
{
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
cs->SendExternalChat(source, colour, user, msg);
}
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
}
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
{
if (this->status < STATUS_PRE_ACTIVE) {

View File

@@ -93,6 +93,7 @@ public:
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
NetworkRecvStatus SendError(NetworkErrorCode error, const std::string &reason = {});
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64 data);
NetworkRecvStatus SendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg);
NetworkRecvStatus SendJoin(ClientID client_id);
NetworkRecvStatus SendFrame();
NetworkRecvStatus SendSync();

View File

@@ -100,9 +100,7 @@ NetworkRecvStatus ClientNetworkStunSocketHandler::CloseConnection(bool error)
{
NetworkStunSocketHandler::CloseConnection(error);
/* If our connecter is still pending, shut it down too. Otherwise the
* callback of the connecter can call into us, and our object is most
* likely about to be destroyed. */
/* Also make sure any pending connecter is killed ASAP. */
if (this->connecter != nullptr) {
this->connecter->Kill();
this->connecter = nullptr;
@@ -111,6 +109,14 @@ NetworkRecvStatus ClientNetworkStunSocketHandler::CloseConnection(bool error)
return NETWORK_RECV_STATUS_OKAY;
}
ClientNetworkStunSocketHandler::~ClientNetworkStunSocketHandler()
{
if (this->connecter != nullptr) {
this->connecter->Kill();
this->connecter = nullptr;
}
}
/**
* Check whether we received/can send some data from/to the STUN server and
* when that's the case handle it appropriately.

View File

@@ -24,6 +24,7 @@ public:
NetworkAddress local_addr; ///< Local addresses of the socket.
NetworkRecvStatus CloseConnection(bool error = true) override;
~ClientNetworkStunSocketHandler() override;
void SendReceive();
void Connect(const std::string &token, uint8 family);

View File

@@ -108,9 +108,7 @@ NetworkRecvStatus ClientNetworkTurnSocketHandler::CloseConnection(bool error)
{
NetworkTurnSocketHandler::CloseConnection(error);
/* If our connecter is still pending, shut it down too. Otherwise the
* callback of the connecter can call into us, and our object is most
* likely about to be destroyed. */
/* Also make sure any pending connecter is killed ASAP. */
if (this->connecter != nullptr) {
this->connecter->Kill();
this->connecter = nullptr;
@@ -119,6 +117,14 @@ NetworkRecvStatus ClientNetworkTurnSocketHandler::CloseConnection(bool error)
return NETWORK_RECV_STATUS_OKAY;
}
ClientNetworkTurnSocketHandler::~ClientNetworkTurnSocketHandler()
{
if (this->connecter != nullptr) {
this->connecter->Kill();
this->connecter = nullptr;
}
}
/**
* Check whether we received/can send some data from/to the TURN server and
* when that's the case handle it appropriately

View File

@@ -30,6 +30,7 @@ public:
ClientNetworkTurnSocketHandler(const std::string &token, uint8 tracking_number, const std::string &connection_string) : token(token), tracking_number(tracking_number), connection_string(connection_string) {}
NetworkRecvStatus CloseConnection(bool error = true) override;
~ClientNetworkTurnSocketHandler() override;
void SendReceive();
void Connect();

View File

@@ -109,6 +109,7 @@ enum NetworkAction {
NETWORK_ACTION_COMPANY_JOIN,
NETWORK_ACTION_COMPANY_NEW,
NETWORK_ACTION_KICKED,
NETWORK_ACTION_EXTERNAL_CHAT,
};
/**