14 #include "../stdafx.h" 15 #include "../strings_func.h" 16 #include "../date_func.h" 20 #include "../command_func.h" 21 #include "../company_base.h" 22 #include "../console_func.h" 23 #include "../core/pool_func.hpp" 24 #include "../map_func.h" 26 #include "../game/game.hpp" 28 #include "../safeguards.h" 142 GetString(str, strid,
lastof(str));
144 DEBUG(net, 1,
"[admin] the admin '%s' (%s) made an error and has been disconnected. Reason: '%s'", this->
admin_name, this->
admin_version, str);
244 p->
Send_string(cs == NULL ?
"" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
327 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
330 GetString(manager_name, STR_PRESIDENT_NAME,
lastof(manager_name));
363 GetString(company_name, STR_COMPANY_NAME,
lastof(company_name));
366 GetString(manager_name, STR_PRESIDENT_NAME,
lastof(manager_name));
407 FOR_ALL_COMPANIES(company) {
425 for (uint i = 0; i < 2; i++) {
448 FOR_ALL_COMPANIES(company) {
454 for (uint i = 0; i < NETWORK_VEH_END; i++) {
458 for (uint i = 0; i < NETWORK_VEH_END; i++) {
618 for (uint i = 0; i <
CMD_END; i++) {
680 return this->
SendError(NETWORK_ERROR_WRONG_PASSWORD);
688 return this->
SendError(NETWORK_ERROR_ILLEGAL_PACKET);
714 return this->
SendError(NETWORK_ERROR_ILLEGAL_PACKET);
737 const NetworkClientSocket *cs;
738 if (d1 == UINT32_MAX) {
747 cs = NetworkClientSocket::GetByClientID((
ClientID)d1);
756 if (d1 == UINT32_MAX) {
757 FOR_ALL_COMPANIES(company) {
784 return this->
SendError(NETWORK_ERROR_ILLEGAL_PACKET);
802 case NETWORK_ACTION_CHAT:
803 case NETWORK_ACTION_CHAT_CLIENT:
804 case NETWORK_ACTION_CHAT_COMPANY:
805 case NETWORK_ACTION_SERVER_MESSAGE:
811 return this->
SendError(NETWORK_ERROR_ILLEGAL_PACKET);
889 if (company == NULL) {
890 DEBUG(net, 1,
"[admin] Empty company given for update");
911 if (company == NULL)
return;
940 if (from_admin)
return;
945 as->
SendChat(action, desttype, client_id, msg, data);
1042 default: NOT_REACHED();
char admin_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the admin.
The admin would like to have console messages.
static const byte NETWORK_GAME_ADMIN_VERSION
What version of the admin network do we use?
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
static uint MapSizeX()
Get the size of the map along the X.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
const char * GetCommandName(uint32 cmd)
static uint MapSizeY()
Get the size of the map along the Y.
#define FOR_ALL_ACTIVE_ADMIN_SOCKETS(var)
Iterate over all the active sockets.
Container for all information known about a client.
NetworkRecvStatus SendClientUpdate(const NetworkClientInfo *ci)
Send an update for some client's information.
uint32 _realtime_tick
The real time in the game.
Internal entity of a packet.
The server replies to a ping request from the admin.
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
byte landscape
the landscape we're currently in
static void WelcomeAll()
Send a Welcome packet to all connected admins.
The admin would like to have chat messages.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
The server gives the admin information from the GameScript in JSON.
char server_name[NETWORK_NAME_LENGTH]
name of the server
static Titem * Get(size_t index)
Returns Titem with given index.
int32 performance_history
Company score (scale 0-1000)
The server tells the admin its going to start a new game.
void NetworkAdminGameScript(const char *json)
Send GameScript JSON to the admin network (if they did opt in for the respective update).
void Send_string(const char *data)
Sends a string over the network.
Year inaugurated_year
Year of starting the company.
The server tells the admin its shutting down.
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
Populate the company stats.
NetworkErrorCode
The error codes we send around in the protocols.
The server received a chat message and relays it.
The server tells the admin that a new company has started.
The server tells the admin its protocol version.
ClientID client_id
Client identifier (same as ClientState->client_id)
The admin would like a list of all DoCommand names.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
NetworkRecvStatus SendWelcome()
Send a welcome message to the admin.
The server tells the admin that a client quit.
static void Send()
Send the packets for the server sockets.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Tindex index
Index of this pool item.
byte months_of_bankruptcy
Number of months that the company is unable to pay its debts.
static const AdminIndex INVALID_ADMIN_ID
An invalid admin marker.
The server tells the admin an error has occurred.
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
#define lastof(x)
Get the last element of an fixed size array.
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the acception of a connection.
Updates about the information of clients.
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
char admin_version[NETWORK_REVISION_LENGTH]
Version string of the admin.
Base core network types and some helper functions to access them.
AdminIndex _redirect_console_to_admin
Redirection of the (remote) console to the admin.
uint32 realtime_connect
Time of connection.
The admin gets information about this on a daily basis.
virtual NetworkRecvStatus Receive_ADMIN_UPDATE_FREQUENCY(Packet *p)
Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): uint16 Upda...
char text[32 *MAX_CHAR_LENGTH]
possible text sent for name changes etc, in bytes including '\0'.
The server tells the admin what the current game date is.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
The admin would like to have DoCommand information.
AdminUpdateFrequency
Update frequencies an admin can register.
NetworkRecvStatus SendConsole(const char *origin, const char *command)
Send console output of other clients.
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Servers always have this ID.
The admin gets information about this on a monthly basis.
bool _network_dedicated
are we a dedicated server?
NetworkRecvStatus SendCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Tell the admin that a company got removed.
The server gives the admin some statistics about a company.
uint16 num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
static const size_t MAX_SIZE
Make template parameter accessible from outside.
void NetworkAdminClientQuit(ClientID client_id)
Notify the admin network that a client quit (if they have opt in for the respective update)...
void NetworkAdminConsole(const char *origin, const char *string)
Send console to the admin network (if they did opt in for the respective update). ...
void NetworkAdminCmdLogging(const NetworkClientSocket *owner, const CommandPacket *cp)
Distribute CommandPacket details over the admin network for logging purposes.
void NetworkAdminUpdate(AdminUpdateFrequency freq)
Send (push) updates to the admin network as they have registered for these updates.
NetworkSettings network
settings related to the network
NetworkRecvStatus SendDate()
Tell the admin the date.
CompanyID client_playas
As which company is this client playing (CompanyID)
static const uint NETWORK_RCONCOMMAND_LENGTH
The maximum length of a rconsole command, in bytes including '\0'.
AdminStatus status
Status of this admin.
void Send_uint64(uint64 data)
Package a 64 bits integer in the packet.
The server's reply to a remove console command.
virtual NetworkRecvStatus Receive_ADMIN_JOIN(Packet *p)
Join the admin network: string Password the server is expecting for this network. ...
NetworkRecvStatus SendCompanyEconomy()
Send economic information of all companies.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
Name of the client.
Updates about the statistics of companies.
Server part of the network protocol.
The server gives the admin an information update on a client.
NetworkRecvStatus SendRcon(uint16 colour, const char *command)
Send the reply of an rcon command.
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
Updates about the economy of companies.
NetworkRecvStatus SendClientInfo(const NetworkClientSocket *cs, const NetworkClientInfo *ci)
Send an initial set of data from some client's information.
The admin is not connected nor active.
AdminUpdateFrequency update_frequency[ADMIN_UPDATE_END]
Admin requested update intervals.
NetworkRecvStatus SendClientQuit(ClientID client_id)
Tell the admin that a client quit.
bool writable
Can we write to this socket?
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)...
virtual NetworkRecvStatus Receive_ADMIN_CHAT(Packet *p)
Send chat as the server: uint8 Action such as NETWORK_ACTION_CHAT_CLIENT (see NetworkAction).
virtual NetworkRecvStatus Receive_ADMIN_GAMESCRIPT(Packet *p)
Send a JSON string to the current active GameScript.
Money current_loan
Amount of money borrowed from the bank.
void IConsoleCmdExec(const char *cmdstr)
Execute a given command passed to us.
~ServerNetworkAdminSocketHandler()
Clear everything related to this admin.
ClientID _network_own_client_id
Our client identifier.
ClientSettings _settings_client
The current settings for this game.
NetworkRecvStatus SendRconEnd(const char *command)
Send a notification indicating the rcon command has completed.
virtual NetworkRecvStatus Receive_ADMIN_POLL(Packet *p)
Poll the server for certain updates, an invalid poll (e.g.
NetworkRecvStatus SendClientJoin(ClientID client_id)
Tell the admin that a client joined.
The admin gets information about this on a quarterly basis.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
The admin would like to have gamescript messages.
NetworkRecvStatus SendNewGame()
Tell the admin we started a new game.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
virtual NetworkRecvStatus Receive_ADMIN_RCON(Packet *p)
Execute a command on the servers console: string Command to be executed.
NetworkRecvStatus SendCmdNames()
Send the names of the commands.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
The server indicates that the remote console command has completed.
NetworkRecvStatus SendCompanyUpdate(const Company *c)
Send an update about a company.
static const uint NETWORK_CHAT_LENGTH
The maximum length of a chat message, in bytes including '\0'.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Money money
Money owned by the company.
Updates about the date of the game.
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data, bool from_admin)
Send chat to the admin network (if they did opt in for the respective update).
PacketSize size
The size of the whole packet for received packets.
NetworkRecvStatus SendCompanyInfo(const Company *c)
Send the admin some information about a company.
CompanyID company
company that is executing the command
byte _network_admins_connected
The amount of admins connected.
#define lengthof(x)
Return the length of an fixed size array.
NetworkServerGameInfo _network_game_info
Information about our game.
virtual NetworkRecvStatus Receive_ADMIN_QUIT(Packet *p)
Notification to the server that this admin is quitting.
static T min(const T a, const T b)
Returns the minimum of two values.
static bool AllowConnection()
Whether a connection is allowed or not at this moment.
The server tells the admin that a company was removed.
static const AdminIndex MAX_ADMINS
Maximum number of allowed admins.
The server sends out the names of the DoCommands to the admins.
#define FOR_ALL_CLIENT_SOCKETS(var)
Iterate over all the sockets.
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).
uint32 frame
the frame in which this packet is executed
uint32 StringID
Numeric value that represents a string, independent of the selected language.
The server tells the admin that a client caused an error.
Maximum number of companies.
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string)
Pass the rcon reply to the admin.
The server gives the admin the data that got printed to its console.
uint8 AdminIndex
Indices into the admin tables.
static const uint NETWORK_GAMESCRIPT_JSON_LENGTH
The maximum length of a gamescript json string, in bytes including '\0'. Must not be longer than SEND...
Date join_date
Gamedate the client has joined.
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
Base class for all pools.
NetworkRecvStatus SendError(NetworkErrorCode error)
Send an error to the admin.
#define DEBUG(name, level,...)
Output a line of debugging information.
The server gives the admin an information update on a company.
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
assert_compile(lengthof(_admin_update_type_frequencies)==ADMIN_UPDATE_END)
Sanity check.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
NetworkRecvStatus SendProtocol()
Send the protocol version to the admin.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0, bool from_admin=false)
Send an actual chat message.
uint32 generation_seed
noise seed for world generation
NetworkRecvStatus SendClientError(ClientID client_id, NetworkErrorCode error)
Tell the admin that a client made an error.
The admin gets information about this on a yearly basis.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static const AdminUpdateFrequency _admin_update_type_frequencies[]
Frequencies, which may be registered for a certain update type.
Must ALWAYS be on the end of this list!! (period)
The server tells the admin that a client has joined.
OwnerByte share_owners[4]
Owners of the 4 shares of the company. INVALID_OWNER if nobody has bought them yet.
The admin gets information about this on a weekly basis.
byte colour
Company colour.
CargoArray delivered_cargo
The amount of delivered cargo.
NetworkRecvStatus SendGameScript(const char *json)
Send GameScript JSON output.
ClientID
'Unique' identifier to be given to clients
static const uint NETWORK_COMPANY_NAME_LENGTH
The maximum length of the company name, in bytes including '\0'.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
ServerNetworkAdminSocketHandler(SOCKET s)
Create a new socket for the server side of the admin network.
uint16 num_station[NETWORK_VEH_END]
How many stations are there of this type?
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Class for handling the server side of the game connection.
Must ALWAYS be on the end of this list!! (period)
void NetworkAdminCompanyInfo(const Company *company, bool new_company)
Notify the admin network of company details.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
The server gives the admin information about a client.
static const uint16 SEND_MTU
Number of bytes we can pack in a single packet.
char admin_password[NETWORK_PASSWORD_LENGTH]
password for the admin network
Main socket handler for admin related connections.
NetworkRecvStatus SendCompanyStats()
Send statistics about the companies.
TileIndex tile
tile command being executed on.
The server welcomes the admin to a game.
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
Send a chat message.
Everything we need to know about a command to be able to execute it.
Money yearly_expenses[3][EXPENSES_END]
Expenses of the company for the last three years, in every #Expenses category.
NetworkRecvStatus SendShutdown()
Tell the admin we're shutting down.
The admin gets information about this when it changes.
virtual void SendPacket(Packet *packet)
This function puts the packet in the send-queue and it is send as soon as possible.
Simple calculated statistics of a company.
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) ...
void NetworkAdminClientUpdate(const NetworkClientInfo *ci)
Notify the admin network of a client update (if they did opt in for the respective update)...
The server gives the admin copies of incoming command packets.
GameCreationSettings game_creation
settings used during the creation of a game (map)
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
#define FOR_ALL_ADMIN_SOCKETS(var)
Iterate over all the sockets.
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
Owner
Enum for all companies/owners.
void Send_bool(bool data)
Package a boolean in the packet.
Money company_value
The value of the company.
NetworkRecvStatus SendCmdLogging(ClientID client_id, const CommandPacket *cp)
Send a command for logging purposes.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
NetworkAdminSocketPool _networkadminsocket_pool("NetworkAdminSocket")
The pool with sockets/clients.
Updates about the generic information of companies.
The server gives the admin some economy related company information.
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
virtual NetworkRecvStatus Receive_ADMIN_PING(Packet *p)
Ping the server, requiring the server to reply with a pong packet.
Date _date
Current date in days (day counter)
NetworkRecvStatus SendCompanyNew(CompanyID company_id)
Tell the admin that a new company was founded.
AdminUpdateType
Update types an admin can register a frequency for.
Year starting_year
starting date
uint32 cmd
command being executed.
NetworkRecvStatus CloseConnection(bool error=true)
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
DestType
Destination of our chat messages.
byte client_lang
The language of the client.
static const int ADMIN_AUTHORISATION_TIMEOUT
The timeout for authorisation of the client.
NetworkAction
Actions that can be used for NetworkTextMessage.
NetworkRecvStatus SendPong(uint32 d1)
Send ping-reply (pong) to admin.
const T GetSum() const
Get the sum of all cargo amounts.
NetworkAddress address
Address of the admin.
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
Server part of the admin network protocol.
The server gives the admin information about a company.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.