OpenTTD Source  14.0-beta3
network_gui.cpp File Reference
#include "../stdafx.h"
#include "../strings_func.h"
#include "../fios.h"
#include "network_client.h"
#include "network_gui.h"
#include "network_gamelist.h"
#include "network.h"
#include "network_base.h"
#include "network_content.h"
#include "network_server.h"
#include "network_coordinator.h"
#include "network_survey.h"
#include "../gui.h"
#include "network_udp.h"
#include "../window_func.h"
#include "../gfx_func.h"
#include "../widgets/dropdown_type.h"
#include "../widgets/dropdown_func.h"
#include "../querystring_gui.h"
#include "../sortlist_type.h"
#include "../company_func.h"
#include "../command_func.h"
#include "../core/geometry_func.hpp"
#include "../genworld.h"
#include "../map_type.h"
#include "../zoom_func.h"
#include "../sprite.h"
#include "../settings_internal.h"
#include "../company_cmd.h"
#include "../timer/timer.h"
#include "../timer/timer_window.h"
#include "../timer/timer_game_calendar.h"
#include "../textfile_gui.h"
#include "../widgets/network_widget.h"
#include "table/strings.h"
#include "../table/sprites.h"
#include "../stringfilter_type.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

class  NWidgetServerListHeader
 Full blown container to make it behave exactly as we want :) More...
 
class  NetworkGameWindow
 
struct  NetworkStartServerWindow
 
class  ButtonCommon
 Button shown for either a company or client in the client-list. More...
 
class  Button< T >
 Template version of Button, with callback support. More...
 
struct  NetworkClientListWindow
 Main handle for clientlist. More...
 
struct  NetworkJoinStatusWindow
 
struct  NetworkCompanyPasswordWindow
 
struct  NetworkAskRelayWindow
 Window used for asking the user if he is okay using a relay server. More...
 
struct  NetworkAskSurveyWindow
 Window used for asking if the user wants to participate in the automated survey. More...
 
struct  SurveyResultTextfileWindow
 Window for displaying the textfile of a survey result. More...
 

Typedefs

typedef GUIList< NetworkGameList *, std::nullptr_t, StringFilter & > GUIGameServerList
 
typedef int ServerListPosition
 
using CompanyButton = Button< CompanyID >
 
using ClientButton = Button< ClientID >
 

Enumerations

enum  DropDownAdmin { DD_CLIENT_ADMIN_KICK, DD_CLIENT_ADMIN_BAN, DD_COMPANY_ADMIN_RESET, DD_COMPANY_ADMIN_UNLOCK }
 The possibly entries in a DropDown for an admin. More...
 

Functions

static void ShowNetworkStartServerWindow ()
 
void UpdateNetworkGameWindow ()
 Update the network new window because a new server is found on the network.
 
static DropDownList BuildVisibilityDropDownList ()
 
static std::unique_ptr< NWidgetBaseMakeResizableHeader ()
 
void ShowNetworkGameWindow ()
 
void DrawCompanyIcon (CompanyID cid, int x, int y)
 Draw the icon of a company. More...
 
static void AdminClientKickCallback (Window *, bool confirmed)
 Callback function for admin command to kick client. More...
 
static void AdminClientBanCallback (Window *, bool confirmed)
 Callback function for admin command to ban client. More...
 
static void AdminCompanyResetCallback (Window *, bool confirmed)
 Callback function for admin command to reset company. More...
 
static void AdminCompanyUnlockCallback (Window *, bool confirmed)
 Callback function for admin command to unlock company. More...
 
void ShowClientList ()
 
void ShowJoinStatusWindow ()
 
void ShowNetworkNeedPassword (NetworkPasswordType npt)
 
void ShowNetworkCompanyPasswordWindow (Window *parent)
 
void ShowNetworkAskRelay (const std::string &server_connection_string, const std::string &relay_connection_string, const std::string &token)
 Show a modal confirmation window with "no" / "yes, once" / "yes, always" buttons. More...
 
void ShowNetworkAskSurvey ()
 Show a modal confirmation window with "no" / "preview" / "yes" buttons.
 
void ShowSurveyResultTextfileWindow ()
 

Variables

static ClientID _admin_client_id = INVALID_CLIENT_ID
 For what client a confirmation window is open.
 
static CompanyID _admin_company_id = INVALID_COMPANY
 For what company a confirmation window is open.
 
static const ServerListPosition SLP_INVALID = -1
 
static constexpr NWidgetPart _nested_network_game_widgets []
 
static WindowDesc _network_game_window_desc (__FILE__, __LINE__, WDP_CENTER, "list_servers", 1000, 730, WC_NETWORK_WINDOW, WC_NONE, 0, std::begin(_nested_network_game_widgets), std::end(_nested_network_game_widgets))
 
static constexpr NWidgetPart _nested_network_start_server_window_widgets []
 
static WindowDesc _network_start_server_window_desc (__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_NETWORK_WINDOW, WC_NONE, 0, std::begin(_nested_network_start_server_window_widgets), std::end(_nested_network_start_server_window_widgets))
 
static constexpr NWidgetPart _nested_client_list_widgets []
 
static WindowDesc _client_list_desc (__FILE__, __LINE__, WDP_AUTO, "list_clients", 220, 300, WC_CLIENT_LIST, WC_NONE, 0, std::begin(_nested_client_list_widgets), std::end(_nested_client_list_widgets))
 
NetworkJoinStatus _network_join_status
 The status of joining.
 
uint8_t _network_join_waiting
 The number of clients waiting in front of us.
 
uint32_t _network_join_bytes
 The number of bytes we already downloaded.
 
uint32_t _network_join_bytes_total
 The total number of bytes to download.
 
static constexpr NWidgetPart _nested_network_join_status_window_widgets []
 
static WindowDesc _network_join_status_window_desc (__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WDF_MODAL, std::begin(_nested_network_join_status_window_widgets), std::end(_nested_network_join_status_window_widgets))
 
static constexpr NWidgetPart _nested_network_company_password_window_widgets []
 
static WindowDesc _network_company_password_window_desc (__FILE__, __LINE__, WDP_AUTO, nullptr, 0, 0, WC_COMPANY_PASSWORD_WINDOW, WC_NONE, 0, std::begin(_nested_network_company_password_window_widgets), std::end(_nested_network_company_password_window_widgets))
 
static constexpr NWidgetPart _nested_network_ask_relay_widgets []
 
static WindowDesc _network_ask_relay_desc (__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_NETWORK_ASK_RELAY, WC_NONE, WDF_MODAL, std::begin(_nested_network_ask_relay_widgets), std::end(_nested_network_ask_relay_widgets))
 
static constexpr NWidgetPart _nested_network_ask_survey_widgets []
 
static WindowDesc _network_ask_survey_desc (__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_NETWORK_ASK_SURVEY, WC_NONE, WDF_MODAL, std::begin(_nested_network_ask_survey_widgets), std::end(_nested_network_ask_survey_widgets))
 

Detailed Description

Implementation of the Network related GUIs.

Definition in file network_gui.cpp.

Enumeration Type Documentation

◆ DropDownAdmin

The possibly entries in a DropDown for an admin.

Client and companies are mixed; they just have to be unique.

Definition at line 1316 of file network_gui.cpp.

Function Documentation

◆ AdminClientBanCallback()

static void AdminClientBanCallback ( Window ,
bool  confirmed 
)
static

Callback function for admin command to ban client.

Parameters
confirmedIff the user pressed Yes.

Definition at line 1336 of file network_gui.cpp.

References _admin_client_id, and NetworkServerKickOrBanIP().

◆ AdminClientKickCallback()

static void AdminClientKickCallback ( Window ,
bool  confirmed 
)
static

Callback function for admin command to kick client.

Parameters
confirmedIff the user pressed Yes.

Definition at line 1327 of file network_gui.cpp.

References _admin_client_id, and NetworkServerKickClient().

◆ AdminCompanyResetCallback()

static void AdminCompanyResetCallback ( Window ,
bool  confirmed 
)
static

Callback function for admin command to reset company.

Parameters
confirmedIff the user pressed Yes.

Definition at line 1345 of file network_gui.cpp.

References _admin_company_id, CCA_DELETE, CRR_MANUAL, INVALID_CLIENT_ID, and NetworkCompanyHasClients().

◆ AdminCompanyUnlockCallback()

static void AdminCompanyUnlockCallback ( Window ,
bool  confirmed 
)
static

Callback function for admin command to unlock company.

Parameters
confirmedIff the user pressed Yes.

Definition at line 1357 of file network_gui.cpp.

References _admin_company_id, and NetworkServerSetCompanyPassword().

◆ DrawCompanyIcon()

void DrawCompanyIcon ( CompanyID  c,
int  x,
int  y 
)

Draw the icon of a company.

Parameters
cCompany that needs its icon drawn.
xHorizontal coordinate of the icon.
yVertical coordinate of the icon.

Definition at line 158 of file company_cmd.cpp.

Referenced by TownAuthorityWindow::DrawRatings().

◆ ShowNetworkAskRelay()

void ShowNetworkAskRelay ( const std::string &  server_connection_string,
const std::string &  relay_connection_string,
const std::string &  token 
)

Show a modal confirmation window with "no" / "yes, once" / "yes, always" buttons.

Parameters
server_connection_stringThe game server we want to connect to.
relay_connection_stringThe relay server we want to connect to.
tokenThe token for this connection.

Definition at line 2471 of file network_gui.cpp.

References CloseWindowByClass(), GetMainWindow(), NRWCD_HANDLED, and WC_NETWORK_ASK_RELAY.

Variable Documentation

◆ _nested_network_ask_relay_widgets

constexpr NWidgetPart _nested_network_ask_relay_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_RED),
NWidget(WWT_CAPTION, COLOUR_RED, WID_NAR_CAPTION), SetDataTip(STR_NETWORK_ASK_RELAY_CAPTION, STR_NULL),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ONCE), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ONCE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NAR_YES_ALWAYS), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_RELAY_YES_ALWAYS, STR_NULL),
}

Definition at line 2441 of file network_gui.cpp.

◆ _nested_network_ask_survey_widgets

constexpr NWidgetPart _nested_network_ask_survey_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_NAS_CAPTION), SetDataTip(STR_NETWORK_ASK_SURVEY_CAPTION, STR_NULL),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_PREVIEW), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_PREVIEW, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NAS_LINK), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_LINK, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_NO, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NAS_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_NETWORK_ASK_SURVEY_YES, STR_NULL),
}

Definition at line 2536 of file network_gui.cpp.

◆ _nested_network_company_password_window_widgets

constexpr NWidgetPart _nested_network_company_password_window_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_COMPANY_PASSWORD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_TEXT, COLOUR_GREY, WID_NCP_LABEL), SetDataTip(STR_COMPANY_VIEW_PASSWORD, STR_NULL),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_NCP_PASSWORD), SetFill(1, 0), SetMinimalSize(194, 12), SetDataTip(STR_COMPANY_VIEW_SET_PASSWORD, STR_NULL),
SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK),
}

Definition at line 2324 of file network_gui.cpp.

◆ _nested_network_join_status_window_widgets

constexpr NWidgetPart _nested_network_join_status_window_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_CONNECTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NJS_PROGRESS_BAR), SetFill(1, 0),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NJS_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(350, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NJS_CANCELOK), SetMinimalSize(101, 12), SetDataTip(STR_NETWORK_CONNECTION_DISCONNECT, STR_NULL), SetFill(1, 0),
}

Definition at line 2216 of file network_gui.cpp.

SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
WID_NCP_LABEL
@ WID_NCP_LABEL
Label in front of the password field.
Definition: network_widget.h:103
WID_NCP_CANCEL
@ WID_NCP_CANCEL
Close the window without changing anything.
Definition: network_widget.h:107
WID_NAS_NO
@ WID_NAS_NO
"No" button.
Definition: network_widget.h:126
WID_NAS_PREVIEW
@ WID_NAS_PREVIEW
"Preview" button.
Definition: network_widget.h:124
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
WID_NCP_PASSWORD
@ WID_NCP_PASSWORD
Input field for the password.
Definition: network_widget.h:104
WID_NAS_YES
@ WID_NAS_YES
"Yes" button.
Definition: network_widget.h:127
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition: widget_type.h:1130
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
WID_NAR_NO
@ WID_NAR_NO
"No" button.
Definition: network_widget.h:115
WID_NJS_CANCELOK
@ WID_NJS_CANCELOK
Cancel / OK button.
Definition: network_widget.h:97
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
WID_NCP_BACKGROUND
@ WID_NCP_BACKGROUND
Background of the window.
Definition: network_widget.h:102
WID_NAR_TEXT
@ WID_NAR_TEXT
Text in the window.
Definition: network_widget.h:114
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1188
WID_NAS_CAPTION
@ WID_NAS_CAPTION
Caption of the window.
Definition: network_widget.h:122
WID_NCP_WARNING
@ WID_NCP_WARNING
Warning text about password security.
Definition: network_widget.h:106
WID_NAR_YES_ONCE
@ WID_NAR_YES_ONCE
"Yes, once" button.
Definition: network_widget.h:116
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
WID_NAR_CAPTION
@ WID_NAR_CAPTION
Caption of the window.
Definition: network_widget.h:113
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1220
WID_NAS_TEXT
@ WID_NAS_TEXT
Text in the window.
Definition: network_widget.h:123
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WID_NCP_SAVE_AS_DEFAULT_PASSWORD
@ WID_NCP_SAVE_AS_DEFAULT_PASSWORD
Toggle 'button' for saving the current password as default password.
Definition: network_widget.h:105
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
WID_NAS_LINK
@ WID_NAS_LINK
"Details & Privacy" button.
Definition: network_widget.h:125
WID_NJS_PROGRESS_TEXT
@ WID_NJS_PROGRESS_TEXT
Text explaining what is happening.
Definition: network_widget.h:96
WID_NCP_OK
@ WID_NCP_OK
Safe the password etc.
Definition: network_widget.h:108
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
WID_NJS_PROGRESS_BAR
@ WID_NJS_PROGRESS_BAR
Simple progress bar.
Definition: network_widget.h:95
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
WID_NAR_YES_ALWAYS
@ WID_NAR_YES_ALWAYS
"Yes, always" button.
Definition: network_widget.h:117