10 #include "../stdafx.h"
11 #include "core/network_game_info.h"
16 #include "table/strings.h"
18 #include "../safeguards.h"
25 assert(this->
sock != INVALID_SOCKET);
44 std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->
last_packet;
47 if (lag > std::chrono::seconds(5)) {
84 Debug(net, 9,
"Query::SendGameInfo()");
92 Debug(net, 9,
"Query::Receive_SERVER_FULL()");
105 Debug(net, 9,
"Query::Receive_SERVER_BANNED()");
118 Debug(net, 9,
"Query::Receive_SERVER_GAME_INFO()");
125 DeserializeNetworkGameInfo(p, item->
info);
127 CheckGameCompatibility(item->
info);
141 Debug(net, 9,
"Query::Receive_SERVER_ERROR(): error={}", error);
145 if (error == NETWORK_ERROR_NOT_EXPECTED) {
167 if (!(*it)->Receive()) {
169 }
else if (!(*it)->CheckConnection()) {
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
SOCKET sock
The socket currently connected to.
virtual void SendPacket(std::unique_ptr< Packet > &&packet)
This function puts the packet in the send-queue and it is send as soon as possible.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
bool CanSendReceive()
Check whether this socket can send or receive something.
static std::vector< std::unique_ptr< QueryNetworkGameSocketHandler > > queries
Pending queries.
void Send()
Send the packets of this socket handler.
NetworkRecvStatus Receive_SERVER_FULL(Packet &p) override
Notification that the server is full.
std::string connection_string
Address we are connected to.
static void SendReceive()
Check if any query needs to send or receive.
NetworkRecvStatus Receive_SERVER_ERROR(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
NetworkRecvStatus Receive_SERVER_BANNED(Packet &p) override
Notification that the client trying to join is banned.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p) override
Sends information about the game.
NetworkRecvStatus SendGameInfo()
Query the server for server information.
bool CheckConnection()
Check the connection's state, i.e.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
@ NETWORK_RECV_STATUS_CLOSE_QUERY
Done querying the server.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
@ NETWORK_RECV_STATUS_CONNECTION_LOST
The connection is lost unexpectedly.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
NetworkGameList * NetworkGameListAddItem(const std::string &connection_string)
Add a new item to the linked gamelist.
Handling of the list of games.
@ NGLS_ONLINE
Server is online.
@ NGLS_FULL
Server is full and cannot be queried.
@ NGLS_TOO_OLD
Server is too old to query.
@ NGLS_OFFLINE
Server is offline (or cannot be queried).
@ NGLS_BANNED
You are banned from this server.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Query part of the network protocol.
NetworkErrorCode
The error codes we send around in the protocols.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Structure with information shown in the game list (GUI)
bool refreshing
Whether this server is being queried.
NetworkGameListStatus status
Stats of the server.
NetworkGameInfo info
The game information of this server.
GRFConfig * grfconfig
List of NewGRF files used.
Internal entity of a packet.
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
@ PACKET_CLIENT_GAME_INFO
Request information about the server.