OpenTTD Source 20250205-master-gfd85ab1e2c
network_gamelist.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
13#include "../stdafx.h"
14#include "../debug.h"
15#include "../window_func.h"
16#include "network_internal.h"
17#include "network_udp.h"
18#include "network_gamelist.h"
19#include <atomic>
20
21#include "../safeguards.h"
22
25
32NetworkGameList *NetworkGameListAddItem(const std::string &connection_string)
33{
34 NetworkGameList *item, *prev_item;
35
36 /* Parse the connection string to ensure the default port is there. */
37 const std::string resolved_connection_string = ServerAddress::Parse(connection_string, NETWORK_DEFAULT_PORT).connection_string;
38
39 prev_item = nullptr;
40 for (item = _network_game_list; item != nullptr; item = item->next) {
41 if (item->connection_string == resolved_connection_string) return item;
42 prev_item = item;
43 }
44
45 item = new NetworkGameList(resolved_connection_string);
46 item->info.gamescript_version = -1;
48
49 if (prev_item == nullptr) {
50 _network_game_list = item;
51 } else {
52 prev_item->next = item;
53 }
54
56
57 return item;
58}
59
65{
66 NetworkGameList *prev_item = nullptr;
67 for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
68 if (remove == item) {
69 if (prev_item == nullptr) {
70 _network_game_list = remove->next;
71 } else {
72 prev_item->next = remove->next;
73 }
74
75 delete remove;
76
77 NetworkRebuildHostList();
79 return;
80 }
81 prev_item = item;
82 }
83}
84
91{
93
94 for (NetworkGameList *item = _network_game_list; item != nullptr;) {
95 if (!item->manually && item->version < _network_game_list_version) {
96 NetworkGameList *remove = item;
97 item = item->next;
98 *prev_item = item;
99
100 delete remove;
101 } else {
102 prev_item = &item->next;
103 item = item->next;
104 }
105 }
106
108}
109
115{
116 for (NetworkGameList *item = _network_game_list; item != nullptr; item = item->next) {
117 /* Reset compatibility state */
118 item->info.compatible = item->info.version_compatible;
119
120 for (auto &c : item->info.grfconfig) {
121 assert(c->flags.Test(GRFConfigFlag::Copy));
122
123 const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
124 if (f == nullptr) {
125 /* Don't know the GRF (anymore), so mark game incompatible. */
126 c->status = GCS_NOT_FOUND;
127
128 /* If we miss a file, we're obviously incompatible. */
129 item->info.compatible = false;
130 } else {
131 c->filename = f->filename;
132 c->name = f->name;
133 c->info = f->info;
134 c->status = GCS_UNKNOWN;
135 }
136 }
137 }
138
140}
std::string connection_string
The connection string for this ServerAddress.
Definition address.h:210
static ServerAddress Parse(const std::string &connection_string, uint16_t default_port, CompanyID *company_id=nullptr)
Convert a string containing either "hostname", "hostname:port" or invite code to a ServerAddress,...
Definition address.cpp:450
static const uint16_t NETWORK_DEFAULT_PORT
The default port of the game server (TCP & UDP)
Definition config.h:25
void NetworkGameListRemoveExpired()
Remove all servers that have not recently been updated.
void NetworkGameListRemoveItem(NetworkGameList *remove)
Remove an item from the gamelist linked list.
int _network_game_list_version
Current version of all items in the list.
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
NetworkGameList * NetworkGameListAddItem(const std::string &connection_string)
Add a new item to the linked gamelist.
NetworkGameList * _network_game_list
Game list of this client.
Handling of the list of games.
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Variables and function used internally.
Sending and receiving UDP messages.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
@ GCS_UNKNOWN
The status of this grf file is unknown.
@ Copy
The data is copied from a grf in _all_grfs.
@ FGCM_EXACT
Only find Grfs matching md5sum.
Information about GRF, used in the game and (part of it) in savegames.
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
std::string filename
Filename - either with or without full path.
Structure with information shown in the game list (GUI)
int version
Used to see which servers are no longer available on the Game Coordinator and can be removed.
std::string connection_string
Address of the server.
NetworkGameList * next
Next pointer to make a linked game list.
NetworkGameInfo info
The game information of this server.
int gamescript_version
Version of the gamescript.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3234
@ WC_NETWORK_WINDOW
Network window; Window numbers: