Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions

# ServerNetworkAdminSocketHandler Class Reference

Class for handling the server side of the game connection. More...

`#include <network_admin.h>`

Inheritance diagram for ServerNetworkAdminSocketHandler:

## Public Member Functions
| ServerNetworkAdminSocketHandler (SOCKET s)
| Create a new socket for the server side of the admin network.
| ~ServerNetworkAdminSocketHandler ()
| Clear everything related to this admin.
NetworkRecvStatus | SendError (NetworkErrorCode error)
| Send an error to the admin.
NetworkRecvStatus | SendWelcome ()
| Send a welcome message to the admin.
NetworkRecvStatus | SendNewGame ()
| Tell the admin we started a new game.
NetworkRecvStatus | SendShutdown ()
| Tell the admin we're shutting down.
NetworkRecvStatus | SendDate ()
| Tell the admin the date.
NetworkRecvStatus | SendClientJoin (ClientID client_id)
| Tell the admin that a client joined.
NetworkRecvStatus | SendClientInfo (const NetworkClientSocket *cs, const NetworkClientInfo *ci)
| Send an initial set of data from some client's information.
NetworkRecvStatus | SendClientUpdate (const NetworkClientInfo *ci)
| Send an update for some client's information.
NetworkRecvStatus | SendClientQuit (ClientID client_id)
| Tell the admin that a client quit.
NetworkRecvStatus | SendClientError (ClientID client_id, NetworkErrorCode error)
| Tell the admin that a client made an error.
NetworkRecvStatus | SendCompanyNew (CompanyID company_id)
| Tell the admin that a new company was founded.
NetworkRecvStatus | SendCompanyInfo (const Company *c)
| Send the admin some information about a company.
NetworkRecvStatus | SendCompanyUpdate (const Company *c)
| Send an update about a company.
NetworkRecvStatus | SendCompanyRemove (CompanyID company_id, AdminCompanyRemoveReason bcrr)
| Tell the admin that a company got removed.
NetworkRecvStatus | SendCompanyEconomy ()
| Send economic information of all companies.
NetworkRecvStatus | SendCompanyStats ()
| Send statistics about the companies.
NetworkRecvStatus | SendChat (NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
| Send a chat message.
NetworkRecvStatus | SendRcon (uint16 colour, const char *command)
| Send the reply of an rcon command.
NetworkRecvStatus | SendConsole (const char *origin, const char *command)
| Send console output of other clients.
NetworkRecvStatus | SendGameScript (const char *json)
| Send GameScript JSON output.
NetworkRecvStatus | SendCmdNames ()
| Send the names of the commands.
NetworkRecvStatus | SendCmdLogging (ClientID client_id, const CommandPacket *cp)
| Send a command for logging purposes.
NetworkRecvStatus | SendRconEnd (const char *command)
| Send a notification indicating the rcon command has completed.
## Static Public Member Functions
static void | Send ()
| Send the packets for the server sockets.
static void | AcceptConnection (SOCKET s, const NetworkAddress &address)
| Handle the acception of a connection.
static bool | AllowConnection ()
| Whether a connection is allowed or not at this moment.
static void | WelcomeAll ()
| Send a Welcome packet to all connected admins.
static const char * | GetName ()
| Get the name used by the listener.
## Data Fields
AdminUpdateFrequency | update_frequency [ADMIN_UPDATE_END]
| Admin requested update intervals.
uint32 | realtime_connect
| Time of connection.
NetworkAddress | address
| Address of the admin.
## Protected Member Functions
virtual NetworkRecvStatus | Receive_ADMIN_JOIN (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_QUIT (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_UPDATE_FREQUENCY (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_POLL (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_CHAT (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_RCON (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_GAMESCRIPT (Packet *p)
virtual NetworkRecvStatus | Receive_ADMIN_PING (Packet *p)
NetworkRecvStatus | SendProtocol ()
| Send the protocol version to the admin.
NetworkRecvStatus | SendPong (uint32 d1)
| Send ping-reply (pong) to admin.

## Detailed Description

Class for handling the server side of the game connection.

Definition at line 29 of file network_admin.h.

## Constructor & Destructor Documentation

ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler | ( | SOCKET | s | ) |

Create a new socket for the server side of the admin network.

Parameters:

  | s | The socket to connect with.

Definition at line 65 of file network_admin.cpp.

References _network_admins_connected, _realtime_tick, realtime_connect, and NetworkAdminSocketHandler::status.

Referenced by AcceptConnection().

## Member Function Documentation

void ServerNetworkAdminSocketHandler::AcceptConnection | ( | SOCKET | s,
|  | const NetworkAddress & | address |
| ) |  |  | `[static]`

Handle the acception of a connection.

Parameters:

  | s | The socket of the new connection.
  | address | The address of the peer.

Definition at line 117 of file network_admin.cpp.

References address, and ServerNetworkAdminSocketHandler().

bool ServerNetworkAdminSocketHandler::AllowConnection | ( |  | ) | `[static]`

Whether a connection is allowed or not at this moment.

Returns:
  Whether the connection is allowed.

Definition at line 86 of file network_admin.cpp.

References _network_admins_connected, _settings_client, NetworkSettings::admin_password, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkadminsocket_pool >::CanAllocateItem(), MAX_ADMINS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, ClientSettings::network, and StrEmpty().

static const char* ServerNetworkAdminSocketHandler::GetName | ( |  | ) | `[inline, static]`

Get the name used by the listener.

Returns:
  the name to show in debug logs and the like.

Definition at line 85 of file network_admin.h.

void ServerNetworkAdminSocketHandler::Send | ( |  | ) | `[static]`

Send the packets for the server sockets.

Definition at line 97 of file network_admin.cpp.

References _realtime_tick, ADMIN_AUTHORISATION_TIMEOUT, ADMIN_STATUS_INACTIVE, NetworkAdminSocketHandler::CloseConnection(), DEBUG, FOR_ALL_ADMIN_SOCKETS, realtime_connect, NetworkTCPSocketHandler::SendPackets(), NetworkAdminSocketHandler::status, and NetworkTCPSocketHandler::writable.

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat | ( | NetworkAction | action,
|  | DestType | desttype,
|  | ClientID | client_id,
|  | const char * | msg,
|  | int64 | data |
| ) |  |  |

Send a chat message.

Parameters:

  | action | The action associated with the message.
  | desttype | The destination type.
  | client_id | The origin of the chat message.
  | msg | The actual message.
  | data | Arbitrary extra data.

Definition at line 474 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CHAT, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint64(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminChat().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientError | ( | ClientID | client_id,
|  | NetworkErrorCode | error |
| ) |  |  |

Tell the admin that a client made an error.

Parameters:

  | client_id | The client that made the error.
  | error | The error that was made.

Definition at line 290 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_ERROR, Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminClientError().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo | ( | const NetworkClientSocket * | cs,
|  | const NetworkClientInfo * | ci |
| ) |  |  |

Send an initial set of data from some client's information.

Parameters:

  | cs | The socket of the client.
  | ci | The information about the client.

Definition at line 234 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_INFO, NetworkClientInfo::client_id, NetworkClientInfo::client_lang, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, NetworkClientInfo::join_date, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminClientInfo().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientJoin | ( | ClientID | client_id | ) |

Tell the admin that a client joined.

Parameters:

  | client_id | The client that joined.

Definition at line 219 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_JOIN, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminClientInfo().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientQuit | ( | ClientID | client_id | ) |

Tell the admin that a client quit.

Parameters:

  | client_id | The client that quit.

Definition at line 275 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_QUIT, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminClientQuit().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientUpdate | ( | const NetworkClientInfo * | ci | ) |

Send an update for some client's information.

Parameters:

  | ci | The information about a client.

Definition at line 258 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CLIENT_UPDATE, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminClientUpdate().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdLogging | ( | ClientID | client_id,
|  | const CommandPacket * | cp |
| ) |  |  |

Send a command for logging purposes.

Parameters:

  | client_id | The client executing the command.
  | cp | The command that would be executed.

Definition at line 646 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CMD_LOGGING, CommandContainer::cmd, CMD_ID_MASK, CommandPacket::company, CommandPacket::frame, CommandContainer::p1, CommandContainer::p2, Packet::Send_string(), Packet::Send_uint16(), Packet::Send_uint32(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), CommandContainer::text, and CommandContainer::tile.

Referenced by NetworkAdminCmdLogging().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames | ( |  | ) |

Send the names of the commands.

Definition at line 612 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CMD_NAMES, GetCommandName(), Packet::Send_bool(), SEND_MTU, Packet::Send_string(), Packet::Send_uint16(), NetworkTCPSocketHandler::SendPacket(), and Packet::size.

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy | ( |  | ) |

Send economic information of all companies.

Definition at line 402 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_ECONOMY, CompanyEconomyEntry::company_value, CompanyProperties::cur_economy, CompanyProperties::current_loan, CompanyEconomyEntry::delivered_cargo, CargoArray::GetSum(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, lengthof, min(), CompanyProperties::money, CompanyProperties::old_economy, CompanyEconomyEntry::performance_history, Packet::Send_uint16(), Packet::Send_uint64(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), and CompanyProperties::yearly_expenses.

Referenced by NetworkAdminUpdate().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo | ( | const Company * | c | ) |

Send the admin some information about a company.

Parameters:

  | c | The company to send the information about.

Definition at line 319 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_INFO, CeilDiv(), CompanyProperties::colour, CompanyProperties::inaugurated_year, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, CompanyProperties::is_ai, lastof, lengthof, CompanyProperties::months_of_bankruptcy, NETWORK_COMPANY_NAME_LENGTH, NetworkCompanyIsPassworded(), Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), SetDParam(), and CompanyProperties::share_owners.

Referenced by NetworkAdminCompanyInfo().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyNew | ( | CompanyID | company_id | ) |

Tell the admin that a new company was founded.

Parameters:

  | company_id | The company that was founded.

Definition at line 305 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_NEW, Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminCompanyInfo().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyRemove | ( | CompanyID | company_id,
|  | AdminCompanyRemoveReason | acrr |
| ) |  |  |

Tell the admin that a company got removed.

Parameters:

  | company_id | The company that got removed.
  | acrr | The reason for removal, e.g. bankruptcy or merger.

Definition at line 389 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_REMOVE, Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminCompanyRemove().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats | ( |  | ) |

Send statistics about the companies.

Definition at line 437 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_STATS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, NetworkPopulateCompanyStats(), NetworkCompanyStats::num_station, NetworkCompanyStats::num_vehicle, Packet::Send_uint16(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminUpdate().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate | ( | const Company * | c | ) |

Send an update about a company.

Parameters:

  | c | The company to send the update of.

Definition at line 355 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_COMPANY_UPDATE, CeilDiv(), CompanyProperties::colour, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, lastof, lengthof, CompanyProperties::months_of_bankruptcy, NETWORK_COMPANY_NAME_LENGTH, NetworkCompanyIsPassworded(), Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), SetDParam(), and CompanyProperties::share_owners.

Referenced by NetworkAdminCompanyUpdate().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole | ( | const char * | origin,
|  | const char * | string |
| ) |  |  |

Send console output of other clients.

Parameters:

  | origin | The origin of the string.
  | string | The string that's put on the console.

Definition at line 564 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_CONSOLE, SEND_MTU, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminConsole().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate | ( |  | ) |

Tell the admin the date.

Definition at line 205 of file network_admin.cpp.

References _date, ADMIN_PACKET_SERVER_DATE, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminUpdate().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendError | ( | NetworkErrorCode | error | ) |

Send an error to the admin.

Parameters:

  | error | The error to send.

Definition at line 131 of file network_admin.cpp.

References NetworkAdminSocketHandler::admin_name, ADMIN_PACKET_SERVER_ERROR, NetworkAdminSocketHandler::admin_version, NetworkAdminSocketHandler::CloseConnection(), DEBUG, GetNetworkErrorMsg(), lastof, Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript | ( | const char * | json | ) |

Send GameScript JSON output.

Parameters:

  | json | The JSON string.

Definition at line 585 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_GAMESCRIPT, NETWORK_GAMESCRIPT_JSON_LENGTH, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkAdminGameScript().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendNewGame | ( |  | ) |

Tell the admin we started a new game.

Definition at line 189 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_NEWGAME, and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendProtocol | ( |  | ) | `[protected]`

Send the protocol version to the admin.

Definition at line 148 of file network_admin.cpp.

References _admin_update_type_frequencies, ADMIN_PACKET_SERVER_PROTOCOL, NETWORK_GAME_ADMIN_VERSION, Packet::Send_bool(), Packet::Send_uint16(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), and SendWelcome().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon | ( | uint16 | colour,
|  | const char * | result |
| ) |  |  |

Send the reply of an rcon command.

Parameters:

  | colour | The colour of the text.
  | result | The result of the command.

Definition at line 507 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_RCON, Packet::Send_string(), Packet::Send_uint16(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd | ( | const char * | command | ) |

Send a notification indicating the rcon command has completed.

Parameters:

  | command | The original command sent.

Definition at line 492 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_RCON_END, Packet::Send_string(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendShutdown | ( |  | ) |

Tell the admin we're shutting down.

Definition at line 197 of file network_admin.cpp.

References ADMIN_PACKET_SERVER_SHUTDOWN, and NetworkTCPSocketHandler::SendPacket().

Referenced by NetworkDisconnect().

NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome | ( |  | ) |

Send a welcome message to the admin.

Definition at line 168 of file network_admin.cpp.

References _network_dedicated, _network_game_info, _settings_client, _settings_game, ADMIN_PACKET_SERVER_WELCOME, ConvertYMDToDate(), GameSettings::game_creation, GameCreationSettings::generation_seed, GameCreationSettings::landscape, NetworkServerGameInfo::map_name, MapSizeX(), MapSizeY(), ClientSettings::network, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint16(), Packet::Send_uint32(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), NetworkSettings::server_name, and GameCreationSettings::starting_year.

Referenced by SendProtocol(), and WelcomeAll().

The documentation for this class was generated from the following files:

- src/network/network_admin.h
- src/network/network_admin.cpp