* Add a new item to the linked gamelist. If the IP and Port match * return the existing item instead of adding it again * @param connection_string the address of the to-be added item * @return a point to the newly added or already existing item */
| 28 | * @return a point to the newly added or already existing item |
| 29 | */ |
| 30 | NetworkGame *NetworkGameListAddItem(std::string_view connection_string) |
| 31 | { |
| 32 | /* Parse the connection string to ensure the default port is there. */ |
| 33 | const std::string resolved_connection_string = ServerAddress::Parse(connection_string, NETWORK_DEFAULT_PORT).connection_string; |
| 34 | |
| 35 | /* Check if it's already added. */ |
| 36 | auto it = std::ranges::find(_network_game_list, resolved_connection_string, &NetworkGame::connection_string); |
| 37 | if (it != std::end(_network_game_list)) return it->get(); |
| 38 | |
| 39 | auto &item = _network_game_list.emplace_back(std::make_unique<NetworkGame>(resolved_connection_string)); |
| 40 | item->info.gamescript_version = -1; |
| 41 | item->version = _network_game_list_version; |
| 42 | |
| 43 | UpdateNetworkGameWindow(); |
| 44 | |
| 45 | return item.get(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Remove an item from the gamelist linked list |
no test coverage detected