10 #include "../stdafx.h" 11 #include "../strings_func.h" 12 #include "../date_func.h" 22 #include "../window_func.h" 23 #include "../gfx_func.h" 24 #include "../widgets/dropdown_func.h" 25 #include "../querystring_gui.h" 26 #include "../sortlist_type.h" 27 #include "../company_func.h" 28 #include "../core/geometry_func.hpp" 29 #include "../genworld.h" 30 #include "../map_type.h" 31 #include "../guitimer_func.h" 33 #include "../widgets/network_widget.h" 35 #include "table/strings.h" 36 #include "../table/sprites.h" 38 #include "../stringfilter_type.h" 40 #include "../safeguards.h" 43 static void ShowNetworkStartServerWindow();
50 STR_NETWORK_START_SERVER_UNADVERTISED,
51 STR_NETWORK_START_SERVER_ADVERTISED,
59 STR_NETWORK_SERVER_LIST_ADVERTISED_NO,
60 STR_NETWORK_SERVER_LIST_ADVERTISED_YES,
64 static std::vector<StringID> _language_dropdown;
66 void SortNetworkLanguages()
69 if (_language_dropdown.empty()) {
70 for (
int i = 0; i < NETLANG_COUNT; i++) _language_dropdown.emplace_back(STR_NETWORK_LANG_ANY + i);
75 std::sort(_language_dropdown.begin() + 1, _language_dropdown.end() - 1, StringIDSorter);
88 typedef uint16 ServerListPosition;
89 static const ServerListPosition SLP_INVALID = 0xFFFF;
114 this->visible[0] =
true;
115 *
lastof(this->visible) =
true;
130 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
131 child_wid->SetupSmallestSize(w, init_array);
132 this->
smallest_y =
max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
136 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
137 child_wid->current_x = child_wid->smallest_x;
156 for (uint i = 1; i <
lengthof(this->visible) - 1; i++) {
157 if (given_width > MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER + child_wid->
smallest_x && this->visible[i - 1]) {
158 this->visible[i] =
true;
161 this->visible[i] =
false;
163 child_wid = child_wid->
next;
171 uint i = rtl ?
lengthof(this->visible) - 1 : 0;
172 child_wid = rtl ? this->
tail : this->
head;
173 while (child_wid !=
nullptr) {
174 if (this->visible[i]) {
179 child_wid = rtl ? child_wid->
prev : child_wid->
next;
187 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
188 if (!this->visible[i++])
continue;
199 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
200 if (!this->visible[i++])
continue;
202 if (nwid !=
nullptr)
return nwid;
251 this->servers.clear();
254 this->servers.push_back(ngl);
268 this->servers.shrink_to_fit();
270 this->vscroll->
SetCount((
int)this->servers.size());
273 this->servers.
Sort();
274 this->UpdateListPos();
295 if (r == 0)
return NGameNameSorter(a, b);
307 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
314 return (r != 0) ? r < 0 : NGameClientSorter(a, b);
321 return (r != 0) ? r < 0: NGameDateSorter(a, b);
340 if (r == 0)
return NGameClientSorter(a, b);
348 if (this->servers.
Sort()) this->UpdateListPos();
354 this->list_pos = SLP_INVALID;
355 for (uint i = 0; i != this->servers.size(); i++) {
356 if (this->servers[i] == this->server) {
365 assert(item !=
nullptr);
366 assert((*item) !=
nullptr);
369 sf.
AddLine((*item)->info.server_name);
385 if (highlight)
GfxFillRect(nwi_name->
pos_x + 1, y + 1, nwi_info->pos_x + nwi_info->current_x - 2, y + this->resize.step_height - 2,
PC_GREY);
389 int icon_y_offset = (this->resize.step_height -
GetSpriteSize(SPR_BLOT).height) / 2;
429 SetDParam(0, ymd_cur.year - ymd_start.year);
453 if (this->list_pos == SLP_INVALID)
return;
460 this->list_pos = SLP_INVALID;
461 this->server =
nullptr;
463 this->lock_offset = 5;
464 this->blot_offset = this->lock_offset + 3 +
GetSpriteSize(SPR_LOCK).width;
465 this->flag_offset = this->blot_offset + 2 +
GetSpriteSize(SPR_BLOT).width;
467 this->CreateNestedTree();
479 this->server = this->last_joined;
492 this->last_sorting = this->servers.
GetListing();
509 size->width += padding.width;
510 size->height += padding.height;
515 size->height = 10 * resize->height;
523 size->width = NWidgetScrollbar::GetVerticalDimension().width;
569 this->DrawServerLine(ngl, y, ngl == this->server);
570 y += this->resize.step_height;
577 if (this->last_joined !=
nullptr) this->DrawServerLine(this->last_joined, r.top, this->last_joined == this->server);
581 this->DrawDetails(r);
599 this->BuildGUINetworkGameList();
602 this->SortNetworkGameList();
609 this->SetWidgetDisabledState(
WID_NG_JOIN, sel ==
nullptr ||
621 void DrawDetails(
const Rect &r)
const 629 if (sel ==
nullptr) {
631 }
else if (!sel->
online) {
641 uint16 y = r.top + detail_height + 4;
711 if (this->list_pos != SLP_INVALID) this->list_pos = (ServerListPosition)this->servers.size() - this->list_pos - 1;
715 this->SortNetworkGameList();
717 this->ScrollToSelectedServer();
723 this->server = (id_v < this->servers.size()) ? this->servers[id_v] :
nullptr;
724 this->list_pos = (server ==
nullptr) ? SLP_INVALID : id_v;
733 if (this->last_joined !=
nullptr) {
734 this->server = this->last_joined;
737 this->UpdateListPos();
738 this->ScrollToSelectedServer();
758 STR_NETWORK_SERVER_LIST_ENTER_IP,
764 ShowNetworkStartServerWindow();
768 if (this->server !=
nullptr) {
819 if (keycode == WKC_UP || keycode == WKC_DOWN || keycode == WKC_PAGEUP || keycode == WKC_PAGEDOWN || keycode == WKC_HOME || keycode == WKC_END) {
820 if (this->servers.size() == 0)
return ES_HANDLED;
824 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
825 if (this->list_pos > 0) this->list_pos--;
829 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
830 if (this->list_pos < this->servers.size() - 1) this->list_pos++;
834 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
835 this->list_pos = (this->list_pos < this->vscroll->
GetCapacity()) ? 0 : this->list_pos - this->vscroll->
GetCapacity();
839 if (this->list_pos == SLP_INVALID)
return ES_HANDLED;
840 this->list_pos =
min(this->list_pos + this->vscroll->
GetCapacity(), (int)this->servers.size() - 1);
848 this->list_pos = (ServerListPosition)this->servers.size() - 1;
850 default: NOT_REACHED();
853 this->server = this->servers[this->list_pos];
856 this->ScrollToSelectedServer();
863 if (this->server !=
nullptr) {
864 if (keycode == WKC_DELETE) {
866 if (this->server == this->last_joined) this->last_joined =
nullptr;
867 this->server =
nullptr;
868 this->list_pos = SLP_INVALID;
880 this->BuildGUINetworkGameList();
881 this->ScrollToSelectedServer();
888 if (!
StrEmpty(this->name_editbox.text.
buf) && this->name_editbox.text.buf[0] !=
' ') {
899 if (!
StrEmpty(str)) NetworkAddServer(str);
909 if (!this->requery_timer.
Elapsed(delta_ms))
return;
916 Listing NetworkGameWindow::last_sorting = {
false, 5};
930 static NWidgetBase *MakeResizableHeader(
int *biggest_index)
932 *biggest_index = max<int>(*biggest_index,
WID_NG_INFO);
936 static const NWidgetPart _nested_network_game_widgets[] = {
951 SetDataTip(STR_BLACK_STRING, STR_NETWORK_SERVER_LIST_ADVERTISED_TOOLTIP),
957 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
972 SetDataTip(0x0, STR_NETWORK_SERVER_LIST_CLICK_TO_SELECT_LAST),
983 SetDataTip(STR_NETWORK_SERVER_LIST_PLAYER_NAME_OSKTITLE, STR_NETWORK_SERVER_LIST_ENTER_NAME_TOOLTIP),
1033 _nested_network_game_widgets,
lengthof(_nested_network_game_widgets)
1036 void ShowNetworkGameWindow()
1038 static bool first =
true;
1047 NetworkAddServer(iter.c_str());
1098 size->width += padding.width;
1099 size->height += padding.height;
1117 ShowNetworkGameWindow();
1134 if (!(this->flags &
WF_TIMEOUT) || this->timeout_timer <= 1) {
1135 this->HandleButtonClick(widget);
1138 default: NOT_REACHED();
1173 for (uint i = 0; i < _language_dropdown.size() - 1; i++) {
1235 for (
const int *widget = raise_widgets; *widget !=
WIDGET_LIST_END; widget++) {
1236 if (this->IsWidgetLowered(*widget)) {
1237 this->RaiseWidget(*widget);
1238 this->SetWidgetDirty(*widget);
1245 if (str ==
nullptr)
return;
1250 int32 value = atoi(str);
1251 this->SetWidgetDirty(this->widget_id);
1252 switch (this->widget_id) {
1253 default: NOT_REACHED();
1264 static const NWidgetPart _nested_network_start_server_window_widgets[] = {
1344 static WindowDesc _network_start_server_window_desc(
1348 _nested_network_start_server_window_widgets,
lengthof(_nested_network_start_server_window_widgets)
1351 static void ShowNetworkStartServerWindow()
1368 this->CreateNestedTree();
1373 CompanyID NetworkLobbyFindCompanyIndex(byte pos)
const 1377 if (!
StrEmpty(this->company_info[i].company_name)) {
1378 if (pos-- == 0)
return i;
1394 size->height = 10 * resize->height;
1416 this->DrawDetails(r);
1439 this->DrawWidgets();
1449 int lock_width = lock_size.width;
1453 int profit_width = lock_size.width;
1456 uint text_left = left + (rtl ? lock_width + profit_width + 4 : 0);
1457 uint text_right = right - (rtl ? 0 : lock_width + profit_width + 4);
1458 uint profit_left = rtl ? left : right - profit_width;
1459 uint lock_left = rtl ? left + profit_width + 2 : right - profit_width - lock_width - 2;
1465 byte company = NetworkLobbyFindCompanyIndex(pos);
1466 bool income =
false;
1467 if (this->company == company) {
1471 DrawString(text_left, text_right, y, this->company_info[company].company_name, TC_BLACK);
1472 if (this->company_info[company].use_password != 0)
DrawSprite(SPR_LOCK, PAL_NONE, lock_left, y + lock_y_offset);
1475 if (this->company_info[company].income >= 0) income =
true;
1476 DrawSprite(income ? SPR_PROFIT_LOT : SPR_PROFIT_NEGATIVE, PAL_NONE, profit_left, y + profit_y_offset);
1479 y += this->resize.step_height;
1484 void DrawDetails(
const Rect &r)
const 1493 int y = r.top + detail_height + 4;
1503 SetDParamStr(0, this->company_info[this->company].company_name);
1507 SetDParam(0, this->company_info[this->company].inaugurated_year);
1511 SetDParam(0, this->company_info[this->company].company_value);
1515 SetDParam(0, this->company_info[this->company].money);
1519 SetDParam(0, this->company_info[this->company].income);
1523 SetDParam(0, this->company_info[this->company].performance);
1527 SetDParam(0, this->company_info[this->company].num_vehicle[NETWORK_VEH_TRAIN]);
1528 SetDParam(1, this->company_info[this->company].num_vehicle[NETWORK_VEH_LORRY]);
1529 SetDParam(2, this->company_info[this->company].num_vehicle[NETWORK_VEH_BUS]);
1530 SetDParam(3, this->company_info[this->company].num_vehicle[NETWORK_VEH_SHIP]);
1531 SetDParam(4, this->company_info[this->company].num_vehicle[NETWORK_VEH_PLANE]);
1535 SetDParam(0, this->company_info[this->company].num_station[NETWORK_VEH_TRAIN]);
1536 SetDParam(1, this->company_info[this->company].num_station[NETWORK_VEH_LORRY]);
1537 SetDParam(2, this->company_info[this->company].num_station[NETWORK_VEH_BUS]);
1538 SetDParam(3, this->company_info[this->company].num_station[NETWORK_VEH_SHIP]);
1539 SetDParam(4, this->company_info[this->company].num_station[NETWORK_VEH_PLANE]);
1543 SetDParamStr(0, this->company_info[this->company].clients);
1551 ShowNetworkGameWindow();
1581 memset(this->company_info, 0,
sizeof(this->company_info));
1592 static const NWidgetPart _nested_network_lobby_window_widgets[] = {
1598 NWidget(
WWT_TEXT, COLOUR_LIGHT_BLUE,
WID_NL_TEXT),
SetDataTip(STR_NETWORK_GAME_LOBBY_PREPARE_TO_JOIN, STR_NULL),
SetResize(1, 0),
SetPadding(10, 10, 0, 10),
1603 NWidget(
WWT_PANEL, COLOUR_WHITE,
WID_NL_HEADER),
SetMinimalSize(146, 0),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
1604 NWidget(
WWT_MATRIX, COLOUR_LIGHT_BLUE,
WID_NL_MATRIX),
SetMinimalSize(146, 0),
SetResize(1, 1),
SetFill(1, 1),
SetMatrixDataTip(1, 0, STR_NETWORK_GAME_LOBBY_COMPANY_LIST_TOOLTIP),
SetScrollbar(
WID_NL_SCROLLBAR),
1609 NWidget(
WWT_PANEL, COLOUR_LIGHT_BLUE,
WID_NL_DETAILS),
SetMinimalSize(232, 0),
SetResize(1, 1),
SetFill(1, 1),
EndContainer(),
1631 static WindowDesc _network_lobby_window_desc(
1635 _nested_network_lobby_window_widgets,
lengthof(_nested_network_lobby_window_widgets)
1661 return (lobby !=
nullptr && company <
MAX_COMPANIES) ? &lobby->company_info[company] :
nullptr;
1676 static const NWidgetPart _nested_client_list_popup_widgets[] = {
1684 _nested_client_list_popup_widgets,
lengthof(_nested_client_list_popup_widgets)
1728 Point desired_location;
1738 this->actions.push_back({name, proc});
1743 sel_index(0), client_id(client_id)
1745 this->desired_location.x = x;
1746 this->desired_location.y = y;
1751 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT, &ClientList_SpeakToClient);
1755 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, &ClientList_SpeakToCompany);
1757 this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, &ClientList_SpeakToAll);
1762 this->AddAction(STR_NETWORK_CLIENTLIST_GIVE_MONEY, &ClientList_GiveMoney);
1768 this->AddAction(STR_NETWORK_CLIENTLIST_KICK, &ClientList_Kick);
1769 this->AddAction(STR_NETWORK_CLIENTLIST_BAN, &ClientList_Ban);
1772 this->InitNested(client_id);
1778 return this->desired_location;
1788 d.height *= (uint)this->actions.size();
1797 int sel = this->sel_index;
1819 if (index == this->sel_index || index >= this->actions.size())
return;
1821 this->sel_index = index;
1824 if (index < this->actions.size() && _cursor.
pos.y >= this->top) {
1826 if (ci !=
nullptr) this->actions[index].proc(ci);
1846 static const NWidgetPart _nested_client_list_widgets[] = {
1859 _nested_client_list_widgets,
lengthof(_nested_client_list_widgets)
1868 uint server_client_width;
1877 this->InitNested(window_number);
1892 num *= this->line_height;
1922 if (!this->CheckClientListHeight())
return;
1924 this->DrawWidgets();
1932 int icon_offset = (this->line_height - icon_size.height) / 2;
1938 uint type_icon_width = this->server_client_width + this->icon_size.width +
WD_FRAMERECT_LEFT;
1941 uint type_left = rtl ? right - this->server_client_width : left;
1942 uint type_right = rtl ? right : left + this->server_client_width - 1;
1943 uint icon_left = rtl ? right - type_icon_width +
WD_FRAMERECT_LEFT : left + this->server_client_width;
1944 uint name_left = rtl ? left : left + type_icon_width;
1945 uint name_right = rtl ? right - type_icon_width : right;
1950 if (this->selected_item == i++) {
1958 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_SERVER, colour);
1960 DrawString(type_left, type_right, y + text_offset, STR_NETWORK_CLIENT, colour);
1966 DrawString(name_left, name_right, y + text_offset, ci->client_name, colour);
1975 if (this->selected_item != -1) {
1976 int client_no = this->selected_item;
1978 if (client_no == 0) {
1991 this->selected_item = -1;
2004 if (item == this->selected_item)
return;
2005 this->selected_item = item;
2012 void ShowClientList()
2014 AllocateWindowDescFront<NetworkClientListWindow>(&_client_list_desc, 0);
2036 DrawString(r.left + 2, r.right - 2, r.top + 20, STR_NETWORK_CONNECTING_1 + _network_join_status, TC_FROMSTRING,
SA_HOR_CENTER);
2037 switch (_network_join_status) {
2038 case NETWORK_JOIN_STATUS_CONNECTING:
case NETWORK_JOIN_STATUS_AUTHORIZING:
2039 case NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO:
2042 case NETWORK_JOIN_STATUS_WAITING:
2047 case NETWORK_JOIN_STATUS_DOWNLOADING:
2049 SetDParam(1, _network_join_bytes_total);
2050 DrawString(r.left + 2, r.right - 2, r.top + 20 +
FONT_HEIGHT_NORMAL, _network_join_bytes_total == 0 ? STR_NETWORK_CONNECTING_DOWNLOADING_1 : STR_NETWORK_CONNECTING_DOWNLOADING_2, TC_FROMSTRING,
SA_HOR_CENTER);
2051 if (_network_join_bytes_total == 0) {
2058 progress = 15 + _network_join_bytes * (100 - 15) / _network_join_bytes_total;
2062 DrawFrameRect(r.left + 20, r.top + 5, (
int)((this->width - 20) * progress / 100), r.top + 15, COLOUR_MAUVE, FR_NONE);
2073 for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) {
2096 ShowNetworkGameWindow();
2104 ShowNetworkGameWindow();
2108 switch (this->password_type) {
2111 default: NOT_REACHED();
2116 static const NWidgetPart _nested_network_join_status_window_widgets[] = {
2129 static WindowDesc _network_join_status_window_desc(
2133 _nested_network_join_status_window_widgets,
lengthof(_nested_network_join_status_window_widgets)
2136 void ShowJoinStatusWindow()
2145 if (w ==
nullptr)
return;
2146 w->password_type = npt;
2150 default: NOT_REACHED();
2163 this->InitNested(0);
2164 this->UpdateWarningStringSize();
2166 this->parent = parent;
2173 void UpdateWarningStringSize()
2175 assert(this->nested_root->smallest_x > 0);
2177 this->warning_size.height =
GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width);
2186 *size = this->warning_size;
2196 STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING,
SA_CENTER);
2227 static const NWidgetPart _nested_network_company_password_window_widgets[] = {
2241 SetDataTip(STR_COMPANY_PASSWORD_MAKE_DEFAULT, STR_COMPANY_PASSWORD_MAKE_DEFAULT_TOOLTIP),
2252 static WindowDesc _network_company_password_window_desc(
2256 _nested_network_company_password_window_widgets,
lengthof(_nested_network_company_password_window_widgets)
2259 void ShowNetworkCompanyPasswordWindow(
Window *parent)
EventState
State of handling an event.
Date start_date
When the game started.
static const uint NETWORK_CLIENT_NAME_LENGTH
The maximum length of a client's name, in bytes including '\0'.
Owner
Enum for all companies/owners.
byte spectators_max
Max spectators allowed on server.
static bool NGameClientSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the amount of clients online on a server.
uint16 map_height
Map height.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Send message/notice to all clients (All)
Main handle for clientlist.
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
Ban, or kick, everyone joined from the given client's IP.
void RebuildDone()
Notify the sortlist that the rebuild is done.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
bool CheckClientListHeight()
Finds the amount of clients and set the height correct.
void OnPaint() override
The window must be repainted.
Container for all information known about a client.
Horizontally center the text.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
bool server_advertise
advertise the server to the masterserver
Point pos
logical mouse position
uint8 lan_internet
search on the LAN or internet for servers
void OnPaint() override
The window must be repainted.
uint16 last_port
port of the last joined server
High level window description.
int CompareTo(NetworkAddress &address)
Compare the address of this class with the address of another.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Client list; Window numbers:
EconomySettings economy
settings to change the economy
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
char server_name[NETWORK_NAME_LENGTH]
name of the server
static NetworkRecvStatus SendGamePassword(const char *password)
Set the game password as requested.
Switch to game intro menu.
NetworkGameList * next
Next pointer to make a linked game list.
GUIs related to networking.
void OnResize() override
Called after the window got resized.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
byte server_lang
Language of the server (we should make a nice table for this)
Offset at top to draw the frame rectangular area.
Normal amount of vertical space between two paragraphs of text.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
bool Elapsed(uint delta)
Test if a timer has elapsed.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
bool GetState() const
Get the matching state of the current item.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
ClientID client_id
Client identifier (same as ClientState->client_id)
Popup for the client list; Window numbers:
bool version_compatible
Can we connect to this server or not? (based on server_revision)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
NetworkJoinStatus _network_join_status
The status of joining.
The client wants a new company.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int ACTION_CLEAR
Clear editbox.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
NetworkGameList * last_joined
the last joined server
static const uint MAX_CLIENTS
How many clients can we have.
Sending and receiving UDP messages.
Client part of the network protocol.
QueryString filter_editbox
Editbox for filter on servers.
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
ServerListPosition list_pos
position of the selected server
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
bool give_money
allow giving other companies money
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
QueryString password_editbox
Password editbox.
Offset at top of a matrix cell.
uint16 map_width
Map width.
Send message/notice to only a certain client (Private)
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0...
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
#define lastof(x)
Get the last element of an fixed size array.
return success even when the text didn't change
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Base core network types and some helper functions to access them.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Structure with information shown in the game list (GUI)
#define CLRBITS(x, y)
Clears several bits in a variable.
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
Query a specific server.
ClientID
'Unique' identifier to be given to clients
static T max(const T a, const T b)
Returns the maximum of two values.
void SetListing(Listing l)
Import sort conditions.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
char server_name[NETWORK_NAME_LENGTH]
Server name.
bool NeedRebuild() const
Check if a rebuild is needed.
void SortNetworkGameList()
Sort the server list.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
bool _left_button_clicked
Is left mouse button clicked?
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
The password of the company.
void ForceRebuild()
Force that a rebuild is needed.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Data structure for an opened window.
The game information that is sent from the server to the clients.
bool _ctrl_pressed
Is Ctrl pressed?
static bool NGameNameSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by name.
byte companies_max
Max companies allowed on server.
void SetFilterTerm(const char *str)
Set the term to filter on.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
Bottom offset of the text of the frame.
byte widget_id
The widget that has the pop-up input menu.
void OnResize() override
Called after the window got resized.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
NetworkSettings network
settings related to the network
void BuildGUINetworkGameList()
(Re)build the GUI network game list (a.k.a.
bool _is_network_server
Does this client wants to be a network-server?
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
NetworkGameList * NetworkGameListAddItem(NetworkAddress address)
Add a new item to the linked gamelist.
CompanyID client_playas
As which company is this client playing (CompanyID)
byte companies_on
How many started companies do we have.
void NetworkUDPSearchGame()
Find all servers.
static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
Show the networklobbywindow with the selected server.
Offset at bottom of a matrix cell.
static NetworkRecvStatus SendCompanyPassword(const char *password)
Set the company password as requested.
void NetworkServerKickClient(ClientID client_id)
Kick a single client.
The client is spectating.
Listing GetListing() const
Export current sort conditions.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
uint8 max_spectators
maximum amount of spectators
byte clients_max
Max clients allowed on server.
Company information stored at the client side.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
bool _left_button_down
Is left mouse button pressed?
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
Draw a single server line.
Data stored about a string that can be modified in the GUI.
ClientID _network_own_client_id
Our client identifier.
ClientSettings _settings_client
The current settings for this game.
void NetworkUDPQueryMasterServer()
Request the the server-list from the master server.
Center both horizontally and vertically.
Data structure to convert between Date and triplet (year, month, and day).
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
bool use_password
Is this server passworded?
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
char connect_to_ip[NETWORK_HOSTNAME_LENGTH]
default for the "Add server" query
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
void OnPaint() override
The window must be repainted.
static const StringID _connection_types_dropdown[]
Advertisement options in the start server window.
void ShowGenerateLandscape()
Start with a normal game.
NetworkAddress address
The connection info of the game server.
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
byte clients_on
Current count of clients on server.
NetworkGameInfo info
The game information of this server.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
char server_revision[NETWORK_REVISION_LENGTH]
The version number the server is using (e.g.: 'r304' or 0.5.0)
NetworkGameList * _network_game_list
Game list of this client.
Offset at bottom to draw the frame rectangular area.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void NetworkGameListRequery()
Requeries the (game) servers we have not gotten a reply from.
Right offset of the text of the frame.
int lock_offset
Left offset for lock icon.
#define lengthof(x)
Return the length of an fixed size array.
static bool NGameDateSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by current date.
static T min(const T a, const T b)
Returns the minimum of two values.
uint8 server_lang
language of the server
Top offset of the text of the frame.
Left offset of the text of the frame.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
bool Sort(SortFunction *compare)
Sort the list.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
static const uint8 PC_BLACK
Black palette colour.
uint32 _network_join_bytes
The number of bytes we already downloaded.
static bool NGameYearsSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by the number of days the game is running.
NetworkGameList * server
Selected server.
The window is a modal child of some other window, meaning the parent is 'inactive'.
uint8 max_companies
maximum amount of companies
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
CompanyID company
Selected company.
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Network status window; Window numbers:
void AddLine(const char *str)
Pass another text line from the current item to the filter.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
StringList _network_host_list
The servers we know.
int blot_offset
Left offset for green/yellow/red compatibility icon.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
byte map_set
Graphical set.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static const StringID _lan_internet_types_dropdown[]
Advertisement options in the server list.
Date game_date
Current date.
static const uint8 PC_GREY
Grey palette colour.
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
void DrawCompanyIcon(CompanyID cid, int x, int y)
Draw the icon of a company.
The password of the game.
bool online
False if the server did not respond (default status)
char *const buf
buffer in which text is saved
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
char client_name[NETWORK_CLIENT_NAME_LENGTH]
name of the player (as client)
Both numeric and alphabetic and spaces and stuff.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
NetworkJoinStatus
Status of the clients during joining.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void SetFilterState(bool state)
Enable or disable the filter.
int flag_offset
Left offset for language flag icon.
GUITimer requery_timer
Timer for network requery.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Handling of the list of games.
First company, same as owner.
TextDirection _current_text_dir
Text direction of the currently selected language.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here...
static void PopupClientList(ClientID client_id, int x, int y)
Show the popup (action list)
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
bool CDECL FilterFunction(const T *, F)
Signature of filter function.
uint8 max_clients
maximum amount of clients
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Network window; Window numbers:
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Maximum number of companies.
static bool NGameMapSizeSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by map size.
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool _network_server
network-server is active
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension warning_size
How much space to use for the warning text.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Data structure describing how to show the list (what sort direction and criteria).
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint16 GetPort() const
Get the port.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
void NetworkDisconnect(bool blocking, bool close_admins)
We want to disconnect from the host/clients.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
uint32 _network_join_bytes_total
The total number of bytes to download.
Offset at right to draw the frame rectangular area.
char last_host[NETWORK_HOSTNAME_LENGTH]
IP address of the last joined server.
Company password query; Window numbers:
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
static const uint NETWORK_PASSWORD_LENGTH
The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH) ...
static bool NGameAllowedSorter(NetworkGameList *const &a, NetworkGameList *const &b)
Sort servers by joinability.
QueryString name_editbox
Client name editbox.
bool IsDescSortOrder() const
Check if the sort order is descending.
Servers always have this ID.
NetworkGameList * server
selected server
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
int32 WindowNumber
Number to differentiate different windows of the same class.
Specification of a rectangle with absolute coordinates of all edges.
NetworkPasswordType
The type of password we're asking for.
The passed event is handled.
void ScrollToSelectedServer()
Scroll the list up or down to the currently selected server.
Text is written right-to-left by default.
void ClientList_Action_Proc(const NetworkClientInfo *ci)
Prototype for ClientList actions.
QueryString name_editbox
Server name editbox.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it's client-identifier.
Find a place automatically.
GUIGameServerList servers
list with game servers.
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
uint8 _network_join_waiting
The number of clients waiting in front of us.
password entry box, show warning about password security
bool SortFunction(const T &, const T &)
Signature of sort function.
GRFConfig * grfconfig
List of NewGRF files used.
uint32 WChar
Type for wide characters, i.e.
Scrollbar * vscroll
vertical scrollbar of the list of servers
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Window white border counter bit mask.
Send message/notice to everyone playing the same company (Team)
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Dimensions (a width and height) of a rectangle in 2D.
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
void UpdateListPos()
Set this->list_pos to match this->server.
void GetAddressAsString(char *buffer, const char *last, bool with_family=true)
Get the address as a string, e.g.
byte spectators_on
How many spectators do we have?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
void ShowNetworkChatQueryWindow(DestType type, int dest)
Show the chat window.
void OnTimeout() override
Called when this window's timeout has been reached.
static const SpriteID SPR_FLAGS_BASE
Flags sprites (in same order as enum NetworkLanguage)
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
NetworkCompanyInfo * GetLobbyCompanyInfo(CompanyID company)
Get the company information of a given company to fill for the lobby.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
uint8 SortType() const
Get the sorttype of the list.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.