Changeset View
Standalone View
source/network/NetClient.h
/* Copyright (C) 2022 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0!A.D. | * This file is part of 0!A.D. | ||||
* | * | ||||
* 0!A.D. is free software: you can redistribute it and/or modify | * 0!A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0!A.D. is distributed in the hope that it will be useful, | * 0!A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | public: | ||||
* Set connection data to the remote networked server. | * Set connection data to the remote networked server. | ||||
* @param address IP address or host name to connect to | * @param address IP address or host name to connect to | ||||
*/ | */ | ||||
void SetupServerData(CStr address, u16 port, bool stun); | void SetupServerData(CStr address, u16 port, bool stun); | ||||
/** | /** | ||||
* Set up a connection to the remote networked server. | * Set up a connection to the remote networked server. | ||||
* Must call SetupServerData first. | * Must call SetupServerData first. | ||||
* @param enetClient Pointer to an existing Enet Client. If a `nullptr` is | |||||
phosit: Why should enetClient be an `std::optional`? | |||||
Not Done Inline ActionsBecause it's optional. :P The CCs recommend not using default arguments, because they can hide intent. But having a pointer that needs to be explicitly nullptr in some valid cases is a bit weird, and can make the code harder to parse. if it's std::optional, it's explicated that this an optional arg. That's my logic anyways. wraitii: Because it's optional. :P
The CCs recommend not using default arguments, because they can hide… | |||||
Not Done Inline ActionsIf you need a non-null pointer you should use a reference. Why are the CC so weird could somebody add explenations to every of them. :) phosit: If you need a non-null pointer you should use a reference.
I think explicitly annotating "it is… | |||||
Not Done Inline ActionsI agree that using std::optional is a bit strange for pointers. I'd prefer to clean CC to have a rule something like: an argument as a pointer might be nullptr if not said otherwise, use references when an argument can't be nullptr and a pointer isn't needed. Refs: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f60-prefer-t-over-t-when-no-argument-is-a-valid-option vladislavbelov: I agree that using `std::optional` is a bit strange for pointers. I'd prefer to clean CC to… | |||||
* passed, a new client will be createed. | |||||
* @return true on success, false on connection failure | * @return true on success, false on connection failure | ||||
*/ | */ | ||||
bool SetupConnection(ENetHost* enetClient); | bool SetupConnection(ENetHost* enetClient); | ||||
/** | /** | ||||
* Request connection information over the lobby. | * Request connection information over the lobby. | ||||
*/ | */ | ||||
void SetupConnectionViaLobby(); | void SetupConnectionViaLobby(); | ||||
/** | /** | ||||
* Connect to the remote networked server using lobby. | * Connect to the remote networked server using the lobby. | ||||
* Push netstatus messages on failure. | * Push netstatus messages on failure. | ||||
* @param localNetwork - if true, assume we are trying to connect on the local network. | * @param localNetwork - if true, assume we are trying to connect on the local network. | ||||
* @return true on success, false on connection failure | * @return true on success, false on connection failure | ||||
*/ | */ | ||||
bool TryToConnect(const CStr& hostJID, bool localNetwork); | bool TryToConnectViaLobby(const CStr& hostJID, bool localNetwork); | ||||
/** | /** | ||||
* Destroy the connection to the server. | * Destroy the connection to the server. | ||||
* This client probably cannot be used again. | * This client probably cannot be used again. | ||||
*/ | */ | ||||
void DestroyConnection(); | void DestroyConnection(); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines |
Why should enetClient be an std::optional?