|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../strings_func.h"
12 #include "core/network_game_info.h"
17 #include "../console_func.h"
18 #include "../company_base.h"
19 #include "../command_func.h"
20 #include "../saveload/saveload.h"
21 #include "../saveload/saveload_filter.h"
22 #include "../station_base.h"
23 #include "../genworld.h"
24 #include "../company_func.h"
25 #include "../company_gui.h"
26 #include "../company_cmd.h"
27 #include "../roadveh.h"
28 #include "../order_backup.h"
29 #include "../core/pool_func.hpp"
30 #include "../core/random_func.hpp"
31 #include "../company_cmd.h"
33 #include "../timer/timer.h"
34 #include "../timer/timer_game_calendar.h"
35 #include "../timer/timer_game_economy.h"
36 #include "../timer/timer_game_realtime.h"
38 #include <condition_variable>
40 #include "../safeguards.h"
66 std::deque<std::unique_ptr<Packet>>
packets;
81 std::unique_lock<std::mutex>
lock(this->mutex);
83 if (this->cs !=
nullptr) this->exit_sig.wait(
lock);
87 Debug(net, 0,
"Destruct!");
88 this->packets.clear();
89 this->current =
nullptr;
104 std::unique_lock<std::mutex>
lock(this->mutex);
108 this->exit_sig.notify_all();
126 if (this->packets.empty())
return false;
128 std::lock_guard<std::mutex>
lock(this->mutex);
130 while (!this->packets.empty()) {
132 socket->
SendPacket(std::move(this->packets.front()));
133 this->packets.pop_front();
135 if (last_packet)
return true;
141 void Write(
byte *buf,
size_t size)
override
144 if (this->cs ==
nullptr)
SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
148 std::lock_guard<std::mutex>
lock(this->mutex);
150 byte *bufe = buf + size;
151 while (buf != bufe) {
152 size_t written = this->current->Send_bytes(buf, bufe);
155 if (!this->current->CanWriteToPacket(1)) {
156 this->packets.push_back(std::move(this->current));
161 this->total_size += size;
167 if (this->cs ==
nullptr)
SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
169 std::lock_guard<std::mutex>
lock(this->mutex);
172 if (this->current !=
nullptr) this->packets.push_back(std::move(this->current));
179 p->Send_uint32((uint32_t)this->total_size);
180 this->packets.push_front(std::move(p));
242 if (this->IsPendingDeletion() || this->
sock == INVALID_SOCKET)
return status;
248 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, client_name,
"", STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
251 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
253 new_cs->SendErrorQuit(this->
client_id, NETWORK_ERROR_CONNECTION_LOST);
265 this->CheckNextClientToSendMap(
this);
278 this->DeferDeletion();
304 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
345 SerializeNetworkGameInfo(*p, GetCurrentNetworkServerGameInfo());
359 Debug(net, 9,
"client[{}] SendError(): error={}", this->
client_id, error);
363 p->Send_uint8(error);
364 if (!reason.empty()) p->Send_string(reason);
373 Debug(net, 1,
"'{}' made an error and has been disconnected: {}", client_name,
GetString(strid));
375 if (error == NETWORK_ERROR_KICKED && !reason.empty()) {
376 NetworkTextMessage(NETWORK_ACTION_KICKED,
CC_DEFAULT,
false, client_name, reason, strid);
378 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, client_name,
"", strid);
381 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
385 if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || error == NETWORK_ERROR_WRONG_REVISION) {
386 error = NETWORK_ERROR_ILLEGAL_PACKET;
388 new_cs->SendErrorQuit(this->
client_id, error);
414 p->Send_uint8 (grf_count);
431 Debug(net, 9,
"client[{}] SendNeedGamePassword()", this->
client_id);
454 Debug(net, 9,
"client[{}] SendNeedCompanyPassword()", this->
client_id);
459 Debug(net, 9,
"client[{}] status = AUTH_COMPANY", this->
client_id);
493 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
510 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
512 if (new_cs->GetInfo()->join_date < this->GetInfo()->join_date || (new_cs->GetInfo()->join_date == this->GetInfo()->join_date && new_cs->client_id < this->client_id)) waiting++;
516 p->Send_uint8(waiting);
521 void ServerNetworkGameSocketHandler::CheckNextClientToSendMap(NetworkClientSocket *ignore_cs)
523 Debug(net, 9,
"client[{}] CheckNextClientToSendMap()", this->
client_id);
526 NetworkClientSocket *best =
nullptr;
527 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
528 if (ignore_cs == new_cs)
continue;
531 if (best ==
nullptr || best->GetInfo()->join_date > new_cs->GetInfo()->join_date || (best->GetInfo()->join_date == new_cs->GetInfo()->join_date && best->client_id > new_cs->client_id)) {
538 if (best !=
nullptr) {
544 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
555 return this->
SendError(NETWORK_ERROR_NOT_AUTHORIZED);
559 Debug(net, 9,
"client[{}] SendMap(): first_packet", this->
client_id);
562 this->
savegame = std::make_shared<PacketWriter>(
this);
583 Debug(net, 9,
"client[{}] SendMap(): last_packet", this->
client_id);
594 this->CheckNextClientToSendMap();
606 Debug(net, 9,
"client[{}] SendJoin(): client_id={}", this->client_id,
client_id);
622 #ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
624 #ifdef NETWORK_SEND_DOUBLE_SEED
625 p->Send_uint32(_sync_seed_2);
631 this->
last_token = InteractiveRandomRange(UINT8_MAX - 1) + 1;
648 #ifdef NETWORK_SEND_DOUBLE_SEED
649 p->Send_uint32(_sync_seed_2);
666 p->Send_uint32(cp.
frame);
683 Debug(net, 9,
"client[{}] SendChat(): action={}, client_id={}, self_send={}", this->client_id, action,
client_id, self_send);
689 p->Send_uint8 (action);
691 p->Send_bool (self_send);
693 p->Send_uint64(data);
708 Debug(net, 9,
"client[{}] SendExternalChat(): source={}", this->
client_id, source);
714 p->Send_string(source);
715 p->Send_uint16(colour);
716 p->Send_string(user);
730 Debug(net, 9,
"client[{}] SendErrorQuit(): client_id={}, errorno={}", this->client_id,
client_id, errorno);
735 p->Send_uint8 (errorno);
747 Debug(net, 9,
"client[{}] SendQuit(): client_id={}", this->client_id,
client_id);
788 p->Send_uint16(colour);
789 p->Send_string(command);
801 Debug(net, 9,
"client[{}] SendMove(): client_id={}", this->client_id,
client_id);
806 p->Send_uint8(company_id);
843 Debug(net, 9,
"client[{}] Receive_CLIENT_GAME_INFO()", this->
client_id);
852 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
855 Debug(net, 9,
"client[{}] Receive_CLIENT_NEWGRFS_CHECKED()", this->
client_id);
864 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
869 return this->
SendError(NETWORK_ERROR_FULL);
875 Debug(net, 9,
"client[{}] Receive_CLIENT_JOIN(): client_revision={}, newgrf_version={}", this->
client_id, client_revision, newgrf_version);
878 if (!IsNetworkCompatibleVersion(client_revision) || _openttd_newgrf_version != newgrf_version) {
880 return this->
SendError(NETWORK_ERROR_WRONG_REVISION);
892 return this->
SendError(NETWORK_ERROR_FULL);
899 return this->
SendError(NETWORK_ERROR_COMPANY_MISMATCH);
908 return this->
SendError(NETWORK_ERROR_INVALID_CLIENT_NAME);
913 return this->
SendError(NETWORK_ERROR_NAME_IN_USE);
927 Debug(net, 9,
"client[{}] status = NEWGRFS_CHECK", this->
client_id);
941 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
944 Debug(net, 9,
"client[{}] Receive_CLIENT_GAME_PASSWORD()", this->
client_id);
952 return this->
SendError(NETWORK_ERROR_WRONG_PASSWORD);
961 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
964 Debug(net, 9,
"client[{}] Receive_CLIENT_COMPANY_PASSWORD()", this->
client_id);
975 return this->
SendError(NETWORK_ERROR_WRONG_PASSWORD);
985 if (this->status < STATUS_AUTHORIZED || this->
HasClientQuit()) {
986 return this->
SendError(NETWORK_ERROR_NOT_AUTHORIZED);
989 Debug(net, 9,
"client[{}] Receive_CLIENT_GETMAP()", this->
client_id);
992 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
1009 Debug(net, 9,
"client[{}] Receive_CLIENT_MAP_OK()", this->
client_id);
1013 NetworkTextMessage(NETWORK_ACTION_JOIN,
CC_DEFAULT,
false, client_name,
"", this->
client_id);
1020 Debug(net, 9,
"client[{}] status = PRE_ACTIVE", this->
client_id);
1031 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
1033 new_cs->SendClientInfo(this->
GetInfo());
1048 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1059 if (this->status < STATUS_DONE_MAP || this->
HasClientQuit()) {
1060 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1064 return this->
SendError(NETWORK_ERROR_TOO_MANY_COMMANDS);
1067 Debug(net, 9,
"client[{}] Receive_CLIENT_COMMAND()", this->
client_id);
1076 if (err !=
nullptr) {
1078 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1084 return this->
SendError(NETWORK_ERROR_KICKED);
1089 return this->
SendError(NETWORK_ERROR_KICKED);
1101 return this->
SendError(NETWORK_ERROR_COMPANY_MISMATCH);
1106 return this->
SendError(NETWORK_ERROR_CHEATER);
1128 Debug(net, 9,
"client[{}] Receive_CLIENT_ERROR(): errorno={}", this->
client_id, errorno);
1131 if (this->status < STATUS_DONE_MAP || this->
HasClientQuit()) {
1138 Debug(net, 1,
"'{}' reported an error and is closing its connection: {}", client_name,
GetString(strid));
1140 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, client_name,
"", strid);
1142 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
1144 new_cs->SendErrorQuit(this->
client_id, errorno);
1156 if (this->status < STATUS_DONE_MAP || this->
HasClientQuit()) {
1160 Debug(net, 9,
"client[{}] Receive_CLIENT_QUIT()", this->
client_id);
1164 NetworkTextMessage(NETWORK_ACTION_LEAVE,
CC_DEFAULT,
false, client_name,
"", STR_NETWORK_MESSAGE_CLIENT_LEAVING);
1166 for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
1181 return this->
SendError(NETWORK_ERROR_NOT_AUTHORIZED);
1186 Debug(net, 9,
"client[{}] Receive_CLIENT_ACK(): frame={}", this->
client_id, frame);
1246 if (ci !=
nullptr) {
1255 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1256 if (cs->client_id == (
ClientID)dest) {
1257 cs->SendChat(action, from_id,
false, msg, data);
1268 if (ci !=
nullptr && ci_to !=
nullptr) {
1272 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1273 if (cs->client_id == from_id) {
1274 cs->SendChat(action, (
ClientID)dest,
true, msg, data);
1283 bool show_local =
true;
1286 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1289 cs->SendChat(action, from_id,
false, msg, data);
1290 if (cs->client_id == from_id) show_local =
false;
1302 if (ci !=
nullptr && ci_own !=
nullptr && ci_own->
client_playas == dest) {
1309 if (ci_to ==
nullptr)
break;
1312 if (ci !=
nullptr && show_local) {
1319 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1320 if (cs->client_id == from_id) {
1321 cs->SendChat(action, ci_to->
client_id,
true, msg, data);
1329 Debug(net, 1,
"Received unknown chat destination type {}; doing broadcast instead", desttype);
1333 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1334 cs->SendChat(action, from_id,
false, msg, data);
1340 if (ci !=
nullptr) {
1356 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1357 cs->SendExternalChat(source, colour, user, msg);
1359 NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour,
false, user, msg, 0, source);
1366 return this->
SendError(NETWORK_ERROR_NOT_AUTHORIZED);
1373 Debug(net, 9,
"client[{}] Receive_CLIENT_CHAT(): action={}, desttype={}, dest={}", this->
client_id, action, desttype, dest);
1380 case NETWORK_ACTION_CHAT:
1381 case NETWORK_ACTION_CHAT_CLIENT:
1382 case NETWORK_ACTION_CHAT_COMPANY:
1387 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1396 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1399 Debug(net, 9,
"client[{}] Receive_CLIENT_SET_PASSWORD()", this->
client_id);
1412 return this->
SendError(NETWORK_ERROR_NOT_EXPECTED);
1415 Debug(net, 9,
"client[{}] Receive_CLIENT_SET_NAME()", this->
client_id);
1424 if (ci !=
nullptr) {
1429 return this->
SendError(NETWORK_ERROR_INVALID_CLIENT_NAME);
1448 Debug(net, 9,
"client[{}] Receive_CLIENT_RCON()", this->
client_id);
1454 Debug(net, 1,
"[rcon] Wrong password from client-id {}", this->
client_id);
1458 Debug(net, 3,
"[rcon] Client-id {} executed: {}", this->
client_id, command);
1472 Debug(net, 9,
"client[{}] Receive_CLIENT_MOVE(): company_id={}", this->
client_id, company_id);
1484 Debug(net, 2,
"Wrong password from client-id #{} for company #{}", this->
client_id, company_id + 1);
1507 case VEH_TRAIN: type = NETWORK_VEH_TRAIN;
break;
1510 case VEH_SHIP: type = NETWORK_VEH_SHIP;
break;
1538 if (ci ==
nullptr)
return;
1542 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1544 cs->SendClientInfo(ci);
1559 CompanyMask has_clients = 0;
1560 CompanyMask has_vehicles = 0;
1571 assert(ci !=
nullptr);
1577 if (std::any_of(std::begin(c->group_all), std::end(c->group_all), [](
const GroupStatistics &gs) { return gs.num_vehicle != 0; }))
SetBit(has_vehicles, c->index);
1584 if (c->is_ai)
continue;
1586 if (!
HasBit(has_clients, c->index)) {
1624 bool is_name_unique =
false;
1625 std::string original_name = name;
1627 for (uint number = 1; !is_name_unique && number <=
MAX_CLIENTS; number++) {
1628 is_name_unique =
true;
1630 if (ci->client_name == name) {
1632 is_name_unique =
false;
1638 if (ci !=
nullptr) {
1639 if (ci->
client_name == name) is_name_unique =
false;
1642 if (!is_name_unique) {
1644 name = original_name +
" #" + std::to_string(number);
1652 return is_name_unique;
1665 if (ci->client_name.compare(new_name) == 0)
return false;
1669 if (ci ==
nullptr)
return false;
1689 if (already_hashed) {
1704 for (
auto &cp : cs->outgoing_queue) cs->SendCommand(cp);
1705 cs->outgoing_queue.clear();
1714 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
1715 bool send_sync =
false;
1718 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
1727 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1734 uint lag = NetworkCalculateLag(cs);
1735 switch (cs->status) {
1736 case NetworkClientSocket::STATUS_ACTIVE:
1740 if (cs->last_packet + std::chrono::milliseconds(lag *
MILLISECONDS_PER_TICK) > std::chrono::steady_clock::now()) {
1742 IConsolePrint(
CC_WARNING,
"Client #{} (IP: {}) is dropped because the client's game state is more than {} ticks behind.", cs->client_id, cs->GetClientIP(), lag);
1745 IConsolePrint(
CC_WARNING,
"Client #{} (IP: {}) is dropped because the client did not respond for more than {} ticks.", cs->client_id, cs->GetClientIP(), lag);
1747 cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
1756 if (lag > (uint)
Ticks::DAY_TICKS && cs->lag_test == 0 && cs->last_packet + std::chrono::seconds(2) > std::chrono::steady_clock::now()) {
1763 IConsolePrint(
CC_WARNING,
"Client #{} (IP: {}) is dropped because it fails to send valid acks.", cs->client_id, cs->GetClientIP());
1764 cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
1769 case NetworkClientSocket::STATUS_INACTIVE:
1770 case NetworkClientSocket::STATUS_NEWGRFS_CHECK:
1771 case NetworkClientSocket::STATUS_AUTHORIZED:
1776 cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
1781 case NetworkClientSocket::STATUS_MAP_WAIT:
1785 if (std::chrono::steady_clock::now() > cs->last_packet + std::chrono::seconds(2)) {
1792 cs->last_packet = std::chrono::steady_clock::now();
1796 case NetworkClientSocket::STATUS_MAP:
1800 cs->SendError(NETWORK_ERROR_TIMEOUT_MAP);
1805 case NetworkClientSocket::STATUS_DONE_MAP:
1806 case NetworkClientSocket::STATUS_PRE_ACTIVE:
1810 cs->SendError(NETWORK_ERROR_TIMEOUT_JOIN);
1815 case NetworkClientSocket::STATUS_AUTH_GAME:
1816 case NetworkClientSocket::STATUS_AUTH_COMPANY:
1820 cs->SendError(NETWORK_ERROR_TIMEOUT_PASSWORD);
1825 case NetworkClientSocket::STATUS_END:
1830 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) {
1835 if (send_frame) cs->SendFrame();
1837 #ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
1839 if (send_sync) cs->SendSync();
1960 static const char *
const stat_str[] = {
1963 "authorizing (server password)",
1964 "authorizing (company password)",
1972 static_assert(
lengthof(stat_str) == NetworkClientSocket::STATUS_END);
1974 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1976 if (ci ==
nullptr)
continue;
1977 uint lag = NetworkCalculateLag(cs);
1980 status = (cs->status < (ptrdiff_t)
lengthof(stat_str) ? stat_str[cs->status] :
"unknown");
1993 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
1994 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) cs->SendConfigUpdate();
2016 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
2017 if (cs->status >= NetworkClientSocket::STATUS_PRE_ACTIVE) cs->SendCompanyUpdate();
2035 assert(ci !=
nullptr);
2045 NetworkClientSocket *cs = NetworkClientSocket::GetByClientID(client_id);
2047 if (cs->status < NetworkClientSocket::STATUS_AUTHORIZED)
return;
2048 cs->SendMove(client_id, company_id);
2068 NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code,
string);
2079 NetworkClientSocket::GetByClientID(client_id)->SendError(NETWORK_ERROR_KICKED, reason);
2103 bool contains =
false;
2120 for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
2123 if (cs->client_address.IsInNetmask(ip)) {
2140 if (ci->client_playas == company)
return true;
2156 return fmt::format(
"Client #{}", this->
client_id);
2170 ci->client_id ==
CLIENT_ID_SERVER ?
"server" : NetworkClientSocket::GetByClientID(ci->client_id)->GetClientIP());
2187 assert(c !=
nullptr);
2195 if (ci !=
nullptr) {
2205 if (ci !=
nullptr) {
@ VEH_AIRCRAFT
Aircraft vehicle type.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
Ban, or kick, everyone joined from the given client's IP.
uint64_t Recv_uint64()
Read a 64 bits integer from the packet.
const char * ReceiveCommand(Packet &p, CommandPacket &cp)
Receives a command from the network.
uint16_t num_station[NETWORK_VEH_END]
How many stations are there of this type?
Simple calculated statistics of a company.
static const TextColour CC_INFO
Colour for information lines.
static IntervalTimer< TimerGameEconomy > _network_quarterly({TimerGameEconomy::QUARTER, TimerGameEconomy::Priority::NONE}, [](auto) { if(!_network_server) return;NetworkAutoCleanCompanies();NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);})
Quarterly "callback".
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
@ PACKET_SERVER_MAP_DONE
Server tells it has just sent the last bits of the map to the client.
@ NETWORK_RECV_STATUS_CLIENT_QUIT
The connection is lost gracefully. Other clients are already informed of this leaving client.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
@ FT_SCENARIO
old or new scenario
@ PACKET_SERVER_QUIT
A server tells that a client has quit.
@ PACKET_SERVER_RCON
Response of the executed command on the server.
void NetworkServerSendConfigUpdate()
Send Config Update.
void NetworkAdminUpdate(AdminUpdateFrequency freq)
Send (push) updates to the admin network as they have registered for these updates.
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.
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
NetworkRecvStatus SendCommand(const CommandPacket &cp)
Send a command to the client to execute.
uint16_t max_commands_in_queue
how many commands may there be in the incoming queue before dropping the connection?
@ SM_LOAD_GAME
Load game, Play Scenario.
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data, bool from_admin)
Send chat to the admin network (if they did opt in for the respective update).
TimerGameCalendar::Year restart_game_year
year the server restarts
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
@ UNPAUSED
Only run when not paused.
void NetworkServerShowStatusToConsole()
Show the status message of all clients on the console.
std::string client_name
Name of the client.
@ PACKET_SERVER_FULL
The server is full and has no place for you.
ServerNetworkGameSocketHandler * cs
Socket we are associated with.
uint16_t months_empty
How many months the company is empty.
NetworkRecvStatus SendGameInfo()
Send the client information about the server.
uint32_t frame
the frame in which this packet is executed
std::mutex lock
synchronization for playback status fields
CompanyID client_playas
As which company is this client playing (CompanyID)
uint16_t max_password_time
maximum amount of time, in game ticks, a client may take to enter the password
@ FACIL_TRUCK_STOP
Station with truck stops.
@ STATUS_PRE_ACTIVE
The client is catching up the delayed frames.
NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet &p) override
Gives the client a new name: string New name of the client.
CommandFlags GetCommandFlags(Commands cmd)
This function mask the parameter with CMD_ID_MASK and returns the flags which belongs to the given co...
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint16_t sync_freq
how often do we check whether we are still in-sync
bool _network_server
network-server is active
@ PACKET_SERVER_MOVE
Server tells everyone that someone is moved to another company.
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
NetworkAction
Actions that can be used for NetworkTextMessage.
@ CMD_COMPANY_CTRL
used in multiplayer to create a new companies etc.
@ SPS_CLOSED
The connection got closed.
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
@ WC_CLIENT_LIST
Client list; Window numbers:
An interval timer will fire every interval, and will continue to fire until it is deleted.
Tindex index
Index of this pool item.
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
NetworkRecvStatus Receive_CLIENT_COMMAND(Packet &p) override
The client has done a command and wants us to handle it.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet &p) override
Send a password to the server to authorize: uint8_t Password type (see NetworkPasswordType).
void ChangeNetworkRestartTime(bool reset)
Reset the automatic network restart time interval.
NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet &p) override
Send a password to the server to authorize uint8_t Password type (see NetworkPasswordType).
static void NetworkAutoCleanCompanies()
Check if the server has autoclean_companies activated Two things happen: 1) If a company is not prote...
@ ADMIN_FREQUENCY_DAILY
The admin gets information about this on a daily basis.
void NetworkPrintClients()
Print all the clients to the console.
static void NetworkCheckRestartMapYear()
Check if we want to restart the map based on the year.
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
SOCKET sock
The socket currently connected to.
size_t receive_limit
Amount of bytes that we can receive at this moment.
void Write(byte *buf, size_t size) override
Write a given number of bytes into the savegame.
static const uint MAX_CLIENTS
How many clients can we have.
static const char * GetName()
Get the name used by the listener.
@ PACKET_SERVER_NEWGAME
The server is preparing to start a new game.
@ PACKET_SERVER_SHUTDOWN
The server is shutting down.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static DateFract date_fract
Fractional part of the day.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
uint8_t autoclean_protected
remove the password from passworded companies after this many months
ClientSettings _settings_client
The current settings for this game.
@ STATUS_MAP
The client is downloading the map.
static bool IsValidHumanID(size_t index)
Is this company a valid company, not controlled by a NoAI program?
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
Sync our local command queue to the command queue of the given socket.
@ ADMIN_FREQUENCY_MONTHLY
The admin gets information about this on a monthly basis.
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
@ PACKET_SERVER_CLIENT_INFO
Server sends you information about a client.
@ WC_COMPANY
Company view; Window numbers:
std::map< SOCKET, NetworkAddress > SocketList
Type for a mapping between address and socket.
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
@ PACKET_SERVER_CHECK_NEWGRFS
Server sends NewGRF IDs and MD5 checksums for the client to check.
static IntervalTimer< TimerGameEconomy > _economy_network_daily({TimerGameEconomy::DAY, TimerGameEconomy::Priority::NONE}, [](auto) { if(!_network_server) return;NetworkAdminUpdate(ADMIN_FREQUENCY_DAILY);})
Daily "callback".
@ PACKET_SERVER_FRAME
Server tells the client what frame it is in, and thus to where the client may progress.
@ VEH_ROAD
Road vehicle type.
ClientID _redirect_console_to_client
If not invalid, redirect the console output to a client.
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
Owner
Enum for all companies/owners.
Base socket handler for all TCP sockets.
@ PACKET_SERVER_SYNC
Server tells the client what the random state should be.
void NetworkAdminClientQuit(ClientID client_id)
Notify the admin network that a client quit (if they have opt in for the respective update).
Defines the traits of a command.
uint16_t max_download_time
maximum amount of time, in game ticks, a client may take to download the map
static const TextColour CC_DEFAULT
Default colour of the console.
static void NetworkReplaceCommandClientId(CommandPacket &cp, ClientID client_id)
Insert a client ID into the command data in a command packet.
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string)
Send an rcon reply to the client.
std::deque< std::unique_ptr< Packet > > packets
Packet queue of the savegame; send these "slowly" to the client. Cannot be a std::queue as we want to...
@ STATUS_ACTIVE
The client is active within in the game.
void NetworkServer_Tick(bool send_frame)
This is called every tick if this is a _network_server.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void NetworkAdminClientInfo(const NetworkClientSocket *cs, bool new_client)
Notify the admin network of a new client (if they did opt in for the respective update).
GameCreationSettings game_creation
settings used during the creation of a game (map)
@ PACKET_SERVER_BANNED
The server has banned you.
void Finish() override
Prepare everything to finish writing the savegame.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static void ResetUser(uint32_t user)
Reset an user's OrderBackup if needed.
std::string Recv_string(size_t length, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads characters (bytes) from the packet until it finds a '\0', or reaches a maximum of length charac...
NetworkRecvStatus Receive_CLIENT_GETMAP(Packet &p) override
Request the map from the server.
uint16_t max_join_time
maximum amount of time, in game ticks, a client may take to sync up during joining
bool NetworkMakeClientNameUnique(std::string &name)
Check whether a name is unique, and otherwise try to make it unique.
uint32_t _sync_seed_1
Seed to compare during sync checks.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet &p) override
Set the password for the clients current company: string The password.
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
@ ADMIN_FREQUENCY_QUARTERLY
The admin gets information about this on a quarterly basis.
NetworkRecvStatus Receive_CLIENT_JOIN(Packet &p) override
Try to join the server: string OpenTTD revision (norev000 if no revision).
CompanyID company
company that is executing the command
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
@ FACIL_BUS_STOP
Station with bus stops.
Statistics and caches on the vehicles in a group.
NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet &p) override
Request game information.
static IntervalTimer< TimerGameEconomy > _economy_network_yearly({TimerGameEconomy::YEAR, TimerGameEconomy::Priority::NONE}, [](auto) { if(!_network_server) return;NetworkAdminUpdate(ADMIN_FREQUENCY_ANUALLY);})
Economy yearly "callback".
static IntervalTimer< TimerGameCalendar > _calendar_network_yearly({ TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE }, [](auto) { if(!_network_server) return;NetworkCheckRestartMapYear();})
Calendar yearly "callback".
std::string GetClientName() const
Get the name of the client, if the user did not send it yet, Client ID is used.
Template for TCP listeners.
~ServerNetworkGameSocketHandler()
Clear everything related to this client.
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
Send a chat message from external source.
std::unique_ptr< Packet > ReceivePacket() override
Receives a packet for the given client.
@ COMPANY_NEW_COMPANY
The client wants a new company.
bool server_admin_chat
allow private chat for the server to be distributed to the admin network
@ STATUS_INACTIVE
The client is not connected nor active.
bool TransferToNetworkQueue(ServerNetworkGameSocketHandler *socket)
Transfer all packets from here to the network's queue while holding the lock on our mutex.
static void Send()
Send the packets for the server sockets.
@ PACKET_SERVER_CHAT
Server distributing the message of a client (or itself).
@ CLIENT_ID_FIRST
The first client ID.
Writing a savegame directly to a number of packets.
@ PACKET_SERVER_GAME_INFO
Information about the server.
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded)
Tell that a particular company is (not) passworded.
Everything we need to know about a command to be able to execute it.
@ PACKET_SERVER_COMPANY_UPDATE
Information (password) of a company changed.
NetworkRecvStatus SendSync()
Request the client to sync.
Information about GRF, used in the game and (part of it) in savegames.
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64_t data)
Send a chat message.
NetworkRecvStatus SendConfigUpdate()
Send an update about the max company/spectator counts.
@ SM_NEWGAME
New Game --> 'Random game'.
uint32_t Recv_uint32()
Read a 32 bits integer from the packet.
@ PACKET_SERVER_ERROR
Server sending an error message to the client.
static void NetworkHandleCommandQueue(NetworkClientSocket *cs)
Handle the command-queue of a socket.
uint16_t num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
@ NETWORK_RECV_STATUS_SERVER_ERROR
The server told us we made an error.
void IConsoleCmdExec(const std::string &command_string, const uint recurse_count)
Execute a given command passed to us.
NetworkRecvStatus Receive_CLIENT_MOVE(Packet &p) override
Request the server to move this client into another company: uint8_t ID of the company the client wan...
NetworkRecvStatus Receive_CLIENT_RCON(Packet &p) override
Send an RCon command to the server: string RCon password.
uint32_t _last_sync_frame
Used in the server to store the last time a sync packet was sent to clients.
NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id)
Tell that a client moved to another company.
NetworkRecvStatus Receive_CLIENT_ERROR(Packet &p) override
The client made an error and is quitting the game.
NetworkRecvStatus SendJoin(ClientID client_id)
Tell that a client joined.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
NetworkRecvStatus SendFrame()
Tell the client that they may run to a particular frame.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ CMD_CLIENT_ID
set p2 with the ClientID of the sending client.
size_t total_size
Total size of the compressed savegame.
NetworkRecvStatus Receive_CLIENT_ACK(Packet &p) override
Tell the server we are done with this frame: uint32_t Current frame counter of the client.
std::string password
The password for the company.
uint16_t max_lag_time
maximum amount of time, in game ticks, a client may be lagging behind the server
NetworkCompanyState * _network_company_states
Statistics about some companies.
NetworkRecvStatus SendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
Send a chat message from external source.
NetworkRecvStatus SendCompanyUpdate()
Send an update about the company password states.
NetworkRecvStatus SendWelcome()
Send the client a welcome message with some basic information.
static ClientID _network_client_id
The identifier counter for new clients (is never decreased)
static void NetworkRestartMap()
Helper function to restart the map.
bool my_cmd
did the command originate from "me"
NetworkRecvStatus SendError(NetworkErrorCode error, const std::string &reason={})
Send an error to the client, and close its connection.
static const size_t TCP_MTU
Number of bytes we can pack in a single TCP packet.
ClientStatus status
Status of this client.
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
@ FACIL_DOCK
Station with a dock.
uint16_t bytes_per_frame_burst
how many bytes may, over a short period, be received?
bool _network_dedicated
are we a dedicated server?
Internal entity of a packet.
@ FT_SAVEGAME
old or new savegame
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci)
Send the client information about a client.
@ ADMIN_FREQUENCY_ANUALLY
The admin gets information about this on a yearly basis.
@ PACKET_SERVER_WAIT
Server tells the client there are some people waiting for the map as well.
static const uint NETWORK_REVISION_LENGTH
The maximum length of the revision, in bytes including '\0'.
@ PACKET_SERVER_MAP_SIZE
Server tells the client what the (compressed) size of the map is.
@ STATUS_DONE_MAP
The client has downloaded the map.
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
NetworkRecvStatus SendQuit(ClientID client_id)
Tell the client another client quit.
ClientID client_id
Client identifier (same as ClientState->client_id)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
uint32_t last_token_frame
The last frame we received the right token.
@ PACKET_SERVER_NEED_GAME_PASSWORD
Server requests the (hashed) game password.
static const uint32_t GENERATE_NEW_SEED
Create a new random seed.
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const std::string &msg, ClientID from_id, int64_t data, bool from_admin)
Send an actual chat message.
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
std::string server_name
name of the server
NetworkRecvStatus SendErrorQuit(ClientID client_id, NetworkErrorCode errorno)
Tell the client another client quit with an error.
void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
@ CCA_NEW
Create a new company.
Class for handling the server side of the game connection.
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
std::string rcon_password
password for rconsole (server side)
SwitchMode _switch_mode
The next mainloop command.
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet &p) override
Tell the server that we have the required GRFs.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
@ PACKET_SERVER_MAP_DATA
Server sends bits of the map to the client.
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
uint32_t last_frame_server
Last frame the server has executed.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const std::string & GetClientIP()
Get the IP address/hostname of the connected client.
uint8_t flags
NOSAVE: GCF_Flags, bitset.
Base class for all pools.
SaveOrLoadResult SaveWithFilter(std::shared_ptr< SaveFilter > writer, bool threaded)
Save the game using a (writer) filter.
std::unique_ptr< Packet > current
The packet we're currently writing to.
uint32_t generation_seed
noise seed for world generation
ClientID
'Unique' identifier to be given to clients
static size_t GetNumItems()
Returns number of valid items in the pool.
NetworkRecvStatus SendNewGame()
Tell the client we're starting a new game.
@ FACIL_TRAIN
Station with train station.
~PacketWriter()
Make sure everything is cleaned up.
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ PACKET_SERVER_EXTERNAL_CHAT
Server distributing the message from external source.
Interface for filtering a savegame till it is written.
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
uint32_t _frame_counter
The current frame.
DestType
Destination of our chat messages.
CommandDataBuffer data
command parameters.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
@ COMPANY_SPECTATOR
The client is spectating.
uint32_t last_frame
Last frame we have executed.
NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet &p) override
Tell the server that we are done receiving/loading the map.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
byte _network_clients_connected
The amount of clients connected.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
@ STATUS_NEWGRFS_CHECK
The client is checking NewGRFs.
static bool AllowConnection()
Whether an connection is allowed or not at this moment.
@ PACKET_SERVER_COMMAND
Server distributes a command to (all) the clients.
@ PACKET_SERVER_MAP_BEGIN
Server tells the client that it is beginning to send the map.
uint8_t max_clients
maximum amount of clients
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
std::string server_password
password for joining this server
uint8_t max_companies
maximum amount of companies
const std::string & GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
Kick a single client.
std::shared_ptr< struct PacketWriter > savegame
Writer used to write the savegame.
NetworkRecvStatus SendMap()
This sends the map to the client.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ FT_HEIGHTMAP
heightmap file
CompanyCtrlAction
The action to do with CMD_COMPANY_CTRL.
@ INVALID_CLIENT_ID
Client is not part of anything.
@ PACKET_SERVER_CONFIG_UPDATE
Some network configuration important to the client changed.
NetworkRecvStatus SendNewGRFCheck()
Send the check for the NewGRFs.
virtual std::unique_ptr< Packet > ReceivePacket()
Receives a packet for the given client.
@ STATUS_AUTH_COMPANY
The client is authorizing with company password.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
NetworkRecvStatus SendNeedGamePassword()
Request the game password.
CommandQueue incoming_queue
The command-queue awaiting handling.
ClientID client_id
Client identifier.
GRFConfig * _grfconfig
First item in list of current GRF set up.
PacketWriter(ServerNetworkGameSocketHandler *cs)
Create the packet writer.
@ CRR_AUTOCLEAN
The company is removed due to autoclean.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
Change the client name of the given client.
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
Notify the admin network of a client update (if they did opt in for the respective update).
void SendCommand(Packet &p, const CommandPacket &cp)
Sends a command over the network.
uint16_t bytes_per_frame
how many bytes may, over a long period, be received per frame?
#define lengthof(x)
Return the length of an fixed size array.
StringList _network_ban_list
The banned clients.
NetworkSettings network
settings related to the network
std::mutex mutex
Mutex for making threaded saving safe.
uint16_t restart_hours
number of hours to run the server before automatic restart
NetworkRecvStatus Receive_CLIENT_CHAT(Packet &p) override
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
void SlError(StringID string, const std::string &extra_msg)
Error handler.
ServerNetworkGameSocketHandler(SOCKET s)
Create a new socket for the server side of the game connection.
bool IsBus() const
Check whether a roadvehicle is a bus.
NetworkAddress client_address
IP-address of the client (so they can be banned)
@ PACKET_SERVER_ERROR_QUIT
A server tells that a client has hit an error and did quit.
static IntervalTimer< TimerGameRealtime > _network_restart_map_timer({std::chrono::hours::zero(), TimerGameRealtime::UNPAUSED}, [](auto) { if(!_network_server) return;if(_settings_client.network.restart_hours==0) return;Debug(net, 3, "Auto-restarting map: {} hours played", _settings_client.network.restart_hours);NetworkRestartMap();})
Timer to restart a network server automatically based on real-time hours played.
@ PACKET_SERVER_JOIN
Tells clients that a new client has joined.
uint8_t autoclean_novehicles
remove companies with no vehicles after this many months
void Destroy()
Begin the destruction of this packet writer.
std::string GenerateCompanyPasswordHash(const std::string &password, const std::string &password_server_id, uint32_t password_game_seed)
Hash the given password using server ID and game seed.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
@ ADMIN_FREQUENCY_WEEKLY
The admin gets information about this on a weekly basis.
void NetworkServerUpdateGameInfo()
Update the server's NetworkServerGameInfo due to changes in settings.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
NetworkRecvStatus SendShutdown()
Tell the client we're shutting down.
@ VEH_TRAIN
Train vehicle type.
uint8_t autoclean_unprotected
remove passwordless companies after this many months
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static IntervalTimer< TimerGameEconomy > _network_weekly({TimerGameEconomy::WEEK, TimerGameEconomy::Priority::NONE}, [](auto) { if(!_network_server) return;NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);})
Economy weekly "callback".
NetworkRecvStatus SendRConResult(uint16_t colour, const std::string &command)
Send the result of a console action.
uint16_t max_init_time
maximum amount of time, in game ticks, a client may take to initiate joining
@ FACIL_AIRPORT
Station with an airport.
@ CMD_SERVER
the command can only be initiated by the server
@ CMD_SPECTATOR
the command may be initiated by a spectator
byte last_token
The last random token we did send to verify the client is listening.
std::condition_variable exit_sig
Signal for threaded destruction of this packet writer.
byte clients_on
Current count of clients on server.
NetworkRecvStatus Receive_CLIENT_QUIT(Packet &p) override
The client is quitting the game.
static const TextColour CC_WARNING
Colour for warning lines.
@ CCA_DELETE
Delete a company.
static const uint MAX_CLIENT_SLOTS
The number of slots; must be at least 1 more than MAX_CLIENTS.
void NetworkServerSetCompanyPassword(CompanyID company_id, const std::string &password, bool already_hashed)
Set/Reset a company password on the server end.
@ VEH_SHIP
Ship vehicle type.
NetworkRecvStatus SendNeedCompanyPassword()
Request the company password.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
@ SL_OK
completed successfully
@ CLIENT_ID_SERVER
Servers always have this ID.
NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket")
Make very sure the preconditions given in network_type.h are actually followed.
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
Notify the admin network of company details.
NetworkErrorCode
The error codes we send around in the protocols.
Container for all information known about a client.
bool NetworkIsValidClientName(const std::string_view client_name)
Check whether the given client name is deemed valid for use in network games.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
uint32_t _frame_counter_max
To where we may go with our clients.
static IntervalTimer< TimerGameEconomy > _network_monthly({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::NONE}, [](auto) { if(!_network_server) return;NetworkAutoCleanCompanies();NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY);})
Economy monthly "callback".
TimerGameEconomy::Date join_date
Gamedate the client has joined.
@ STATUS_AUTH_GAME
The client is authorizing with game (server) password.
bool NetworkCompanyHasClients(CompanyID company)
Check whether a particular company has clients.
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
void NetworkAdminClientError(ClientID client_id, NetworkErrorCode error_code)
Notify the admin network of a client error (if they have opt in for the respective update).
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
@ PACKET_SERVER_NEED_COMPANY_PASSWORD
Server requests the (hashed) company password.
NetworkRecvStatus SendWait()
Tell the client that its put in a waiting queue.
bool autoclean_companies
automatically remove companies that are not in use
std::string network_id
network ID for servers
@ STATUS_AUTHORIZED
The client is authorized.
static Year year
Current year, starting at 0.
@ PACKET_SERVER_WELCOME
Server welcomes you and gives you your ClientID.
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
Commands cmd
command being executed.
static Date date
Current date in days (day counter).
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.