# network_func.h File Reference

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 ()
bool | NetworkCompanyHasClients (CompanyID company)
const char * | NetworkChangeCompanyPassword (const char *)
| Sets/resets company password.
void | NetworkReboot ()
void | NetworkDisconnect (bool blocking=false)
| We want to disconnect from the host/clients.
void | NetworkGameLoop ()
void | NetworkUDPGameLoop ()
void | NetworkUDPCloseAll ()
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)
void | NetworkClientsToSpectators (CompanyID cid)
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)
void | NetworkClientSendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data=0)
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 | NetworkServerMonthlyLoop ()
void | NetworkServerYearlyLoop ()
void | NetworkServerSendConfigUpdate ()
| Send Config Update.
void | NetworkServerShowStatusToConsole ()
bool | NetworkServerStart ()
void | NetworkServerUpdateCompanyPassworded (CompanyID company_id, bool passworded)
bool | NetworkServerChangeClientName (ClientID client_id, const char *new_name)
| Change the client name of the given client.
NetworkClientInfo * | NetworkFindClientInfoFromIndex (ClientIndex index)
| Return the CI given it's raw index.
NetworkClientInfo * | NetworkFindClientInfoFromClientID (ClientID client_id)
| Return the CI given it's client-identifier.
NetworkClientInfo * | NetworkFindClientInfoFromIP (const char *ip)
| Return the CI for a given IP.
const char * | GetClientIP (NetworkClientInfo *ci)
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, ConsoleColour colour_code, const char *string)
void | NetworkServerSendError (ClientID client_id, NetworkErrorCode error)
void | NetworkServerSendChat (NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data=0)
void | NetworkServerKickClient (ClientID client_id)
uint | NetworkServerKickOrBanIP (const char *ip, bool ban)
void | NetworkInitChatMessage ()
void CDECL | NetworkAddChatMessage (TextColour colour, uint8 duration, const char *message,...) WARN_FORMAT(3
void CDECL void | NetworkUndrawChatMessage ()
| Hide the chatbox.
void | NetworkChatMessageDailyLoop ()
| Check if a message is expired every day.
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
NetworkCompanyState * | _network_company_states
ClientID | _network_own_client_id
ClientID | _redirect_console_to_client
bool | _network_need_advertise
uint32 | _network_last_advertise_frame
uint8 | _network_reconnect
StringList | _network_bind_list
StringList | _network_host_list
StringList | _network_ban_list

## Detailed Description

Network functions used by other parts of OpenTTD.

Definition in file network_func.h.

## Function Documentation

const char* NetworkChangeCompanyPassword | ( | const char * | password | ) |

Sets/resets company password.

Parameters:

  | password | new password, "" or "*" resets password

Returns:
  new password

Definition at line 1096 of file network_client.cpp.

References _network_server, and HashCurrentCompanyPassword().

Referenced by CmdCompanyCtrl().

bool NetworkClientPreferTeamChat | ( | const NetworkClientInfo * | cio | ) |

Tell whether the client has team members where he/she can chat to.

Parameters:

  | cio | client to check members of.

Returns:
  true if there is at least one team member.

Definition at line 1078 of file network_client.cpp.

References _settings_client, NetworkClientInfo::client_playas, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and GUISettings::prefer_teamchat.

Referenced by MainWindow::OnKeyPress().

void NetworkClientRequestMove | ( | CompanyID | company_id,
|  | const char * | pass |
| ) |  |  |

Notify the server of this client wanting to be moved to another company.

Parameters:

  | 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.

Returns:
  void

Definition at line 1025 of file network_client.cpp.

Referenced by CompanyWindow::OnClick(), and CompanyWindow::OnQueryTextFinished().

bool NetworkCompanyIsPassworded | ( | CompanyID | company_id | ) |

Check if the company we want to join requires a password.

Parameters:

  | company_id | id of the company we want to check the 'passworded' flag for.

Returns:
  true if the company requires a password.

Definition at line 206 of file network.cpp.

References HasBit().

Referenced by CompanyWindow::DrawWidget(), and CompanyWindow::OnClick().

void NetworkDisconnect | ( | bool | blocking | ) |

We want to disconnect from the host/clients.

Parameters:

  | blocking | whether to wait till everything has been closed

Definition at line 928 of file network.cpp.

References _settings_client, DeleteWindowById(), ClientSettings::network, NetworkUDPRemoveAdvertise(), NetworkTCPSocketHandler::Send_Packets(), and NetworkSettings::server_advertise.

Referenced by NetworkShutDown(), NetworkJoinStatusWindow::OnClick(), TCPQueryConnecter::OnFailure(), NetworkJoinStatusWindow::OnQueryTextFinished(), and SafeSaveOrLoad().

NetworkClientInfo* NetworkFindClientInfoFromClientID | ( | ClientID | client_id | ) |

Return the CI given it's client-identifier.

Parameters:

  | client_id | the ClientID to search for

Returns:
  return a pointer to the corresponding NetworkClientInfo struct or NULL when not found

Definition at line 127 of file network.cpp.

References NetworkClientInfo::client_id.

Referenced by CmdCompanyCtrl(), NetworkChatWindow::DrawWidget(), NetworkServerChangeClientName(), NetworkServerDoMove(), MainWindow::OnKeyPress(), and NetworkChatWindow::UpdateWidgetSize().

NetworkClientInfo* NetworkFindClientInfoFromIndex | ( | ClientIndex | index | ) |

Return the CI given it's raw index.

Parameters:

  | index | the index to search for

Returns:
  return a pointer to the corresponding NetworkClientInfo struct

Definition at line 117 of file network.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::GetIfValid().

NetworkClientInfo* NetworkFindClientInfoFromIP | ( | const char * | ip | ) |

Return the CI for a given IP.

Parameters:

  | ip | IP of the client we are looking for. This must be in string-format

Returns:
  return a pointer to the corresponding NetworkClientInfo struct or NULL when not found

Definition at line 143 of file network.cpp.

References NetworkClientInfo::client_address, and NetworkAddress::GetAddressLength().

void NetworkHandlePauseChange | ( | PauseMode | prev_mode,
|  | PauseMode | changed_mode |
| ) |  |  |

Handle the pause mode change so we send the right messages to the chat.

Parameters:

  | prev_mode | The previous pause mode.
  | changed_mode | The pause mode that got changed.

Definition at line 366 of file network.cpp.

References _pause_mode, lastof, PM_PAUSED_ACTIVE_CLIENTS, PM_PAUSED_JOIN, PM_PAUSED_NORMAL, PM_UNPAUSED, and SetDParam().

Referenced by CmdPause().

bool NetworkMaxCompaniesReached | ( |  | ) |

Check if max_companies has been reached on the server (local check only).

Returns:
  true if the max value has been reached or exceeded, false otherwise.

Definition at line 1113 of file network_client.cpp.

References _network_server, _network_server_max_companies, _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, 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).

Returns:
  true if the max value has been reached or exceeded, false otherwise.

Definition at line 1122 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.

Parameters:

  | stats | the stats to update

Definition at line 1393 of file network_server.cpp.

References FACIL_AIRPORT, FACIL_BUS_STOP, FACIL_DOCK, FACIL_TRAIN, FACIL_TRUCK_STOP, BaseStation::facilities, SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), RoadVehicle::IsBus(), Vehicle::IsPrimaryVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MAX_COMPANIES, NetworkCompanyStats::num_station, NetworkCompanyStats::num_vehicle, BaseStation::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

bool NetworkServerChangeClientName | ( | ClientID | client_id,
|  | const char * | new_name |
| ) |  |  |

Change the client name of the given client.

Parameters:

  | client_id | the client to change the name of
  | new_name | the new name for the client

Returns:
  true iff the name was changed

Definition at line 1571 of file network_server.cpp.

References NetworkClientInfo::client_name, lastof, NetworkFindClientInfoFromClientID(), and strecpy().

void NetworkServerDoMove | ( | ClientID | client_id,
|  | CompanyID | company_id |
| ) |  |  |

Handle the tid-bits of moving a client from one company to another.

Parameters:

  | client_id | id of the client we want to move.
  | company_id | id of the company we want to move the client to.

Returns:
  void

Definition at line 1770 of file network_server.cpp.

References _network_dedicated, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, DESTTYPE_BROADCAST, NetworkFindClientInfoFromClientID(), NetworkFindClientStateFromClientID(), and SetLocalCompany().

Referenced by CompanyWindow::OnClick().

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 seperate 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 485 of file network.cpp.

Referenced by NetworkHTTPSocketHandler::Connect().