mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [Network] Use new/delete instead of calloc/free for NetworkGameList
parent
dc05917287
commit
dcef3209a6
|
@ -57,7 +57,7 @@ static void NetworkGameListHandleDelayedInsert()
|
||||||
if (item->manually) NetworkRebuildHostList();
|
if (item->manually) NetworkRebuildHostList();
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
}
|
}
|
||||||
free(ins_item);
|
delete ins_item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,9 +80,7 @@ NetworkGameList *NetworkGameListAddItem(const std::string &connection_string)
|
||||||
prev_item = item;
|
prev_item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = CallocT<NetworkGameList>(1);
|
item = new NetworkGameList(resolved_connection_string);
|
||||||
item->next = nullptr;
|
|
||||||
item->connection_string = resolved_connection_string;
|
|
||||||
|
|
||||||
if (prev_item == nullptr) {
|
if (prev_item == nullptr) {
|
||||||
_network_game_list = item;
|
_network_game_list = item;
|
||||||
|
@ -112,8 +110,7 @@ void NetworkGameListRemoveItem(NetworkGameList *remove)
|
||||||
|
|
||||||
/* Remove GRFConfig information */
|
/* Remove GRFConfig information */
|
||||||
ClearGRFConfigList(&remove->info.grfconfig);
|
ClearGRFConfigList(&remove->info.grfconfig);
|
||||||
free(remove);
|
delete remove;
|
||||||
remove = nullptr;
|
|
||||||
|
|
||||||
DEBUG(net, 4, "[gamelist] removed server from list");
|
DEBUG(net, 4, "[gamelist] removed server from list");
|
||||||
NetworkRebuildHostList();
|
NetworkRebuildHostList();
|
||||||
|
|
|
@ -16,12 +16,17 @@
|
||||||
|
|
||||||
/** Structure with information shown in the game list (GUI) */
|
/** Structure with information shown in the game list (GUI) */
|
||||||
struct NetworkGameList {
|
struct NetworkGameList {
|
||||||
NetworkGameInfo info; ///< The game information of this server
|
NetworkGameList(const std::string &connection_string, bool manually = false) :
|
||||||
std::string connection_string; ///< Address of the server
|
connection_string(connection_string), manually(manually)
|
||||||
bool online; ///< False if the server did not respond (default status)
|
{
|
||||||
bool manually; ///< True if the server was added manually
|
}
|
||||||
uint8 retries; ///< Number of retries (to stop requerying)
|
|
||||||
NetworkGameList *next; ///< Next pointer to make a linked game list
|
NetworkGameInfo info = {}; ///< The game information of this server
|
||||||
|
std::string connection_string; ///< Address of the server
|
||||||
|
bool online = false; ///< False if the server did not respond (default status)
|
||||||
|
bool manually = false; ///< True if the server was added manually
|
||||||
|
uint8 retries = 0; ///< Number of retries (to stop requerying)
|
||||||
|
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Game list of this client */
|
/** Game list of this client */
|
||||||
|
|
|
@ -90,10 +90,8 @@ static UDPSocket _udp_master("Master"); ///< udp master socket
|
||||||
static void DoNetworkUDPQueryServer(const std::string &connection_string, bool needs_mutex, bool manually)
|
static void DoNetworkUDPQueryServer(const std::string &connection_string, bool needs_mutex, bool manually)
|
||||||
{
|
{
|
||||||
/* Clear item in gamelist */
|
/* Clear item in gamelist */
|
||||||
NetworkGameList *item = CallocT<NetworkGameList>(1);
|
NetworkGameList *item = new NetworkGameList(connection_string, manually);
|
||||||
strecpy(item->info.server_name, connection_string.c_str(), lastof(item->info.server_name));
|
strecpy(item->info.server_name, connection_string.c_str(), lastof(item->info.server_name));
|
||||||
item->connection_string = connection_string;
|
|
||||||
item->manually = manually;
|
|
||||||
NetworkGameListAddItemDelayed(item);
|
NetworkGameListAddItemDelayed(item);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(_udp_client.mutex, std::defer_lock);
|
std::unique_lock<std::mutex> lock(_udp_client.mutex, std::defer_lock);
|
||||||
|
|
Loading…
Reference in New Issue