OpenTTD
|
Network functions used by other parts of OpenTTD. More...
#include "core/address.h"
#include "network_type.h"
#include "../console_type.h"
#include "../gfx_type.h"
#include "../openttd.h"
#include "../company_type.h"
Go to the source code of this file.
Functions | |
byte | NetworkSpectatorCount () |
void | NetworkUpdateClientName () |
Send the server our name. | |
bool | NetworkCompanyHasClients (CompanyID company) |
Check whether a particular company has clients. | |
const char * | NetworkChangeCompanyPassword (CompanyID company_id, const char *password) |
Change the company password of a given company. | |
void | NetworkReboot () |
void | NetworkDisconnect (bool blocking=false, bool close_admins=true) |
We want to disconnect from the host/clients. | |
void | NetworkGameLoop () |
void | NetworkBackgroundLoop () |
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer. | |
void | ParseConnectionString (const char **company, const char **port, char *connection_string) |
Converts a string to ip/port/company Format: IP:port::company. | |
void | NetworkStartDebugLog (NetworkAddress address) |
void | NetworkPopulateCompanyStats (NetworkCompanyStats *stats) |
Populate the company stats. | |
void | NetworkUpdateClientInfo (ClientID client_id) |
Send updated client info of a particular client. | |
void | NetworkClientsToSpectators (CompanyID cid) |
Move the clients of a company to the spectators. | |
void | NetworkClientConnectGame (NetworkAddress address, CompanyID join_as, const char *join_server_password=NULL, const char *join_company_password=NULL) |
void | NetworkClientRequestMove (CompanyID company, const char *pass="") |
Notify the server of this client wanting to be moved to another company. | |
void | NetworkClientSendRcon (const char *password, const char *command) |
Send a remote console command. | |
void | NetworkClientSendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data=0) |
Send a chat message. | |
bool | NetworkClientPreferTeamChat (const NetworkClientInfo *cio) |
Tell whether the client has team members where he/she can chat to. | |
bool | NetworkCompanyIsPassworded (CompanyID company_id) |
Check if the company we want to join requires a password. | |
bool | NetworkMaxCompaniesReached () |
Check if max_companies has been reached on the server (local check only). | |
bool | NetworkMaxSpectatorsReached () |
Check if max_spectatos has been reached on the server (local check only). | |
void | NetworkPrintClients () |
Print all the clients to the console. | |
void | NetworkHandlePauseChange (PauseMode prev_mode, PauseMode changed_mode) |
Handle the pause mode change so we send the right messages to the chat. | |
void | NetworkServerDailyLoop () |
Daily "callback". | |
void | NetworkServerMonthlyLoop () |
Monthly "callback". | |
void | NetworkServerYearlyLoop () |
Yearly "callback". | |
void | NetworkServerSendConfigUpdate () |
Send Config Update. | |
void | NetworkServerShowStatusToConsole () |
Show the status message of all clients on the console. | |
bool | NetworkServerStart () |
void | NetworkServerNewCompany (const Company *company, NetworkClientInfo *ci) |
Perform all the server specific administration of a new company. | |
bool | NetworkServerChangeClientName (ClientID client_id, const char *new_name) |
Change the client name of the given client. | |
void | NetworkServerDoMove (ClientID client_id, CompanyID company_id) |
Handle the tid-bits of moving a client from one company to another. | |
void | NetworkServerSendRcon (ClientID client_id, TextColour colour_code, const char *string) |
Send an rcon reply to the client. | |
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. | |
void | NetworkServerKickClient (ClientID client_id) |
Kick a single client. | |
uint | NetworkServerKickOrBanIP (ClientID client_id, bool ban) |
Ban, or kick, everyone joined from the given client's IP. | |
uint | NetworkServerKickOrBanIP (const char *ip, bool ban) |
Kick or ban someone based on an IP address. | |
void | NetworkInitChatMessage () |
Initialize all buffers of the chat visualisation. | |
void CDECL | NetworkAddChatMessage (TextColour colour, uint duration, const char *message,...) WARN_FORMAT(3 |
void CDECL void | NetworkUndrawChatMessage () |
Hide the chatbox. | |
void | NetworkChatMessageLoop () |
Check if a message is expired. | |
void | NetworkAfterNewGRFScan () |
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new NewGRFs. |
Variables | |
NetworkServerGameInfo | _network_game_info |
Uncomment the following define to enable command replaying. | |
NetworkCompanyState * | _network_company_states |
Statistics about some companies. | |
ClientID | _network_own_client_id |
Our client identifier. | |
ClientID | _redirect_console_to_client |
If not invalid, redirect the console output to a client. | |
bool | _network_need_advertise |
Whether we need to advertise. | |
uint8 | _network_reconnect |
Reconnect timeout. | |
StringList | _network_bind_list |
The addresses to bind on. | |
StringList | _network_host_list |
The servers we know. | |
StringList | _network_ban_list |
The banned clients. |
Network functions used by other parts of OpenTTD.
Definition in file network_func.h.
void NetworkBackgroundLoop | ( | ) |
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
For example stuff needed for finding servers or downloading content.
Definition at line 856 of file network.cpp.
References _network_content_client, TCPConnecter::CheckCallbacks(), NetworkHTTPSocketHandler::HTTPReceive(), NetworkBackgroundUDPLoop(), and ClientNetworkContentSocketHandler::SendReceive().
const char* NetworkChangeCompanyPassword | ( | CompanyID | company_id, |
const char * | password | ||
) |
Change the company password of a given company.
company_id | ID of the company the password should be changed for. |
password | The unhashed password we like to set ('*' or '' resets the password) |
Definition at line 174 of file network.cpp.
References NetworkClientSetCompanyPassword(), and NetworkServerSetCompanyPassword().
Referenced by CmdCompanyCtrl().
void NetworkChatMessageLoop | ( | ) |
Check if a message is expired.
Definition at line 180 of file network_chat_gui.cpp.
References _realtime_tick, MAX_CHAT_MESSAGES, ChatMessage::message, and ChatMessage::remove_time.
bool NetworkClientPreferTeamChat | ( | const NetworkClientInfo * | cio | ) |
Tell whether the client has team members where he/she can chat to.
cio | client to check members of. |
Definition at line 1270 of file network_client.cpp.
References _settings_client, NetworkClientInfo::client_playas, FOR_ALL_CLIENT_INFOS, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and GUISettings::prefer_teamchat.
Referenced by MainWindow::OnHotkey().
void NetworkClientRequestMove | ( | CompanyID | company_id, |
const char * | pass | ||
) |
Notify the server of this client wanting to be moved to another company.
company_id | id of the company the client wishes to be moved to. |
pass | the password, is only checked on the server end if a password is needed. |
Definition at line 1195 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendMove().
Referenced by MenuClickCompany(), CompanyWindow::OnClick(), and CompanyWindow::OnQueryTextFinished().
void NetworkClientSendChat | ( | NetworkAction | action, |
DestType | type, | ||
int | dest, | ||
const char * | msg, | ||
int64 | data | ||
) |
Send a chat message.
action | The action associated with the message. |
type | The destination type. |
dest | The destination index, be it a company index or client id. |
msg | The actual message. |
data | Arbitrary extra data. |
Definition at line 1251 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendChat().
void NetworkClientSendRcon | ( | const char * | password, |
const char * | command | ||
) |
Send a remote console command.
password | The password. |
command | The command to execute. |
Definition at line 1184 of file network_client.cpp.
References ClientNetworkGameSocketHandler::SendRCon().
void NetworkClientsToSpectators | ( | CompanyID | cid | ) |
Move the clients of a company to the spectators.
cid | The company to move the clients of. |
Definition at line 1204 of file network_client.cpp.
References _current_company, _local_company, CC_DEFAULT, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, FOR_ALL_CLIENT_INFOS, Backup< T >::Restore(), and SetLocalCompany().
Referenced by ChangeOwnershipOfCompanyItems().
bool NetworkCompanyHasClients | ( | CompanyID | company | ) |
Check whether a particular company has clients.
company | The company to check. |
Definition at line 2128 of file network_server.cpp.
References NetworkClientInfo::client_playas, and FOR_ALL_CLIENT_INFOS.
bool NetworkCompanyIsPassworded | ( | CompanyID | company_id | ) |
Check if the company we want to join requires a password.
company_id | id of the company we want to check the 'passworded' flag for. |
Definition at line 225 of file network.cpp.
References HasBit().
Referenced by CompanyWindow::DrawWidget(), NetworkServerUpdateCompanyPassworded(), CompanyWindow::OnClick(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), and ServerNetworkAdminSocketHandler::SendCompanyUpdate().
void NetworkDisconnect | ( | bool | blocking, |
bool | close_admins | ||
) |
We want to disconnect from the host/clients.
blocking | whether to wait till everything has been closed. |
close_admins | Whether the admin sockets need to be closed as well. |
Definition at line 798 of file network.cpp.
References _settings_client, DeleteWindowById(), FOR_ALL_ACTIVE_ADMIN_SOCKETS, FOR_ALL_CLIENT_SOCKETS, ClientSettings::network, NetworkClose(), NetworkUDPInitialize(), NetworkUDPRemoveAdvertise(), NetworkTCPSocketHandler::SendPackets(), ServerNetworkAdminSocketHandler::SendShutdown(), NetworkSettings::server_advertise, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
Referenced by NetworkShutDown(), NetworkJoinStatusWindow::OnClick(), NetworkJoinStatusWindow::OnQueryTextFinished(), and SafeLoad().
Handle the pause mode change so we send the right messages to the chat.
prev_mode | The previous pause mode. |
changed_mode | The pause mode that got changed. |
Definition at line 348 of file network.cpp.
References _pause_mode, CC_DEFAULT, DRAW_STRING_BUFFER, lastof, PM_PAUSED_ACTIVE_CLIENTS, PM_PAUSED_GAME_SCRIPT, PM_PAUSED_JOIN, PM_PAUSED_NORMAL, PM_UNPAUSED, and SetDParam().
Referenced by CmdPause().
void NetworkInitChatMessage | ( | ) |
Initialize all buffers of the chat visualisation.
Definition at line 118 of file network_chat_gui.cpp.
References _settings_client, ClientSettings::gui, MAX_CHAT_MESSAGES, ChatMessage::message, GUISettings::network_chat_box_height, GUISettings::network_chat_box_width_pct, NetworkReInitChatBoxSize(), and ReallocT().
Referenced by OnNewYear().
bool NetworkMaxCompaniesReached | ( | ) |
Check if max_companies has been reached on the server (local check only).
Definition at line 1287 of file network_client.cpp.
References _network_server, _network_server_max_companies, _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkSettings::max_companies, and ClientSettings::network.
Referenced by PopupMainCompanyToolbMenu().
bool NetworkMaxSpectatorsReached | ( | ) |
Check if max_spectatos has been reached on the server (local check only).
Definition at line 1296 of file network_client.cpp.
References _network_server, _network_server_max_spectators, _settings_client, NetworkSettings::max_spectators, and ClientSettings::network.
Referenced by PopupMainCompanyToolbMenu().
void NetworkPopulateCompanyStats | ( | NetworkCompanyStats * | stats | ) |
Populate the company stats.
stats | the stats to update |
Definition at line 1563 of file network_server.cpp.
References FACIL_AIRPORT, FACIL_BUS_STOP, FACIL_DOCK, FACIL_TRAIN, FACIL_TRUCK_STOP, BaseStation::facilities, FOR_ALL_VEHICLES, SpecializedVehicle< RoadVehicle, Type >::From(), RoadVehicle::IsBus(), Vehicle::IsPrimaryVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MAX_COMPANIES, NetworkCompanyStats::num_station, NetworkCompanyStats::num_vehicle, BaseStation::owner, Vehicle::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO(), ServerNetworkGameSocketHandler::SendCompanyInfo(), and ServerNetworkAdminSocketHandler::SendCompanyStats().
bool NetworkServerChangeClientName | ( | ClientID | client_id, |
const char * | new_name | ||
) |
Change the client name of the given client.
client_id | the client to change the name of |
new_name | the new name for the client |
Definition at line 1750 of file network_server.cpp.
References CC_DEFAULT, NetworkClientInfo::client_name, FOR_ALL_CLIENT_INFOS, NetworkClientInfo::GetByClientID(), lastof, NetworkUpdateClientInfo(), and strecpy().
void NetworkServerDailyLoop | ( | ) |
Daily "callback".
Called whenever the date changes.
Definition at line 1945 of file network_server.cpp.
References _date, ADMIN_FREQUENCY_DAILY, ADMIN_FREQUENCY_WEEKLY, and NetworkAdminUpdate().
Referenced by OnNewDay().
Handle the tid-bits of moving a client from one company to another.
client_id | id of the client we want to move. |
company_id | id of the company we want to move the client to. |
Definition at line 2030 of file network_server.cpp.
References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, DESTTYPE_BROADCAST, NetworkClientInfo::GetByClientID(), NetworkServerSendChat(), NetworkUpdateClientInfo(), and SetLocalCompany().
Referenced by MenuClickCompany(), CompanyWindow::OnClick(), and ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE().
void NetworkServerKickClient | ( | ClientID | client_id | ) |
Kick a single client.
client_id | The client to kick. |
Definition at line 2073 of file network_server.cpp.
References CLIENT_ID_SERVER.
Referenced by NetworkServerKickOrBanIP().
uint NetworkServerKickOrBanIP | ( | ClientID | client_id, |
bool | ban | ||
) |
Ban, or kick, everyone joined from the given client's IP.
client_id | The client to check for. |
ban | Whether to ban or kick. |
Definition at line 2084 of file network_server.cpp.
References NetworkServerKickOrBanIP().
Referenced by NetworkServerKickOrBanIP().
uint NetworkServerKickOrBanIP | ( | const char * | ip, |
bool | ban | ||
) |
Kick or ban someone based on an IP address.
ip | The IP address/range to ban/kick. |
ban | Whether to ban or just kick. |
Definition at line 2094 of file network_server.cpp.
References _network_ban_list, SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), CLIENT_ID_SERVER, SmallVector< T, S >::End(), FOR_ALL_CLIENT_SOCKETS, NetworkServerKickClient(), and stredup().
void NetworkServerMonthlyLoop | ( | ) |
Monthly "callback".
Called whenever the month changes.
Definition at line 1937 of file network_server.cpp.
References _cur_month, ADMIN_FREQUENCY_MONTHLY, ADMIN_FREQUENCY_QUARTERLY, NetworkAdminUpdate(), and NetworkAutoCleanCompanies().
Referenced by OnNewMonth().
void NetworkServerNewCompany | ( | const Company * | c, |
NetworkClientInfo * | ci | ||
) |
Perform all the server specific administration of a new company.
c | The newly created company; can't be NULL. |
ci | The client information of the client that made the company; can be NULL. |
Definition at line 2181 of file network_server.cpp.
References _network_company_states, _network_server, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, CMD_RENAME_PRESIDENT, DESTTYPE_BROADCAST, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, NetworkCompanyState::months_empty, NetworkAdminCompanyInfo(), NetworkSendCommand(), NetworkServerSendChat(), NetworkServerUpdateCompanyPassworded(), NetworkUpdateClientInfo(), and NetworkCompanyState::password.
Referenced by CmdCompanyCtrl().
void NetworkServerSendChat | ( | NetworkAction | action, |
DestType | desttype, | ||
int | dest, | ||
const char * | msg, | ||
ClientID | from_id, | ||
int64 | data, | ||
bool | from_admin | ||
) |
Send an actual chat message.
action | The action that's performed. |
desttype | The type of destination. |
dest | The actual destination index. |
msg | The actual message. |
from_id | The origin of the message. |
data | Arbitrary data. |
from_admin | Whether the origin is an admin or not. |
Definition at line 1268 of file network_server.cpp.
References _local_company, _settings_client, NetworkClientInfo::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, DEBUG, DESTTYPE_BROADCAST, DESTTYPE_CLIENT, DESTTYPE_TEAM, FOR_ALL_CLIENT_SOCKETS, NetworkClientInfo::GetByClientID(), GetDrawStringCompanyColour(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), lastof, ClientSettings::network, NETWORK_NAME_LENGTH, NetworkAdminChat(), NetworkSettings::server_admin_chat, and SetDParam().
Referenced by NetworkServerDoMove(), NetworkServerNewCompany(), ServerNetworkAdminSocketHandler::Receive_ADMIN_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and SendChat().
void NetworkServerSendRcon | ( | ClientID | client_id, |
TextColour | colour_code, | ||
const char * | string | ||
) |
Send an rcon reply to the client.
client_id | The identifier of the client. |
colour_code | The colour of the text. |
string | The actual reply. |
Definition at line 2064 of file network_server.cpp.
Referenced by IConsolePrint().
void NetworkServerShowStatusToConsole | ( | ) |
Show the status message of all clients on the console.
Definition at line 1961 of file network_server.cpp.
References CC_INFO, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, FOR_ALL_CLIENT_SOCKETS, IConsolePrintF(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and lengthof.
void NetworkServerYearlyLoop | ( | ) |
Yearly "callback".
Called whenever the year changes.
Definition at line 1930 of file network_server.cpp.
References ADMIN_FREQUENCY_ANUALLY, NetworkAdminUpdate(), and NetworkCheckRestartMap().
Referenced by OnNewYear().
void NetworkUpdateClientInfo | ( | ClientID | client_id | ) |
Send updated client info of a particular client.
client_id | The client to send it for. |
Definition at line 1602 of file network_server.cpp.
References _date, _date_fract, NetworkClientInfo::client_playas, DEBUG, FOR_ALL_CLIENT_SOCKETS, NetworkClientInfo::GetByClientID(), and NetworkAdminClientUpdate().
Referenced by CmdCompanyCtrl(), NetworkServerChangeClientName(), NetworkServerDoMove(), NetworkServerNewCompany(), NetworkUpdateClientName(), and ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME().
void ParseConnectionString | ( | const char ** | company, |
const char ** | port, | ||
char * | connection_string | ||
) |
Converts a string to ip/port/company Format: IP:port::company.
connection_string will be re-terminated to separate out the hostname, and company and port will be set to the company and port strings given by the user, inside the memory area originally occupied by connection_string.
Definition at line 474 of file network.cpp.
Referenced by NetworkHTTPSocketHandler::Connect(), AfterNewGRFScan::OnNewGRFsScanned(), and openttd_main().
NetworkServerGameInfo _network_game_info |
Uncomment the following define to enable command replaying.
See docs/desync.txt for details.
Definition at line 61 of file network.cpp.
Referenced by ServerNetworkGameSocketHandler::AllowConnection(), ServerNetworkGameSocketHandler::CloseConnection(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), ServerNetworkGameSocketHandler::SendWelcome(), and ServerNetworkAdminSocketHandler::SendWelcome().