Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: Use member initalisers #11304

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/network/core/tcp_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static std::vector<std::unique_ptr<NetworkGameSocketHandler>> _deferred_deletion
* Create a new socket for the game connection.
* @param s The socket to connect with.
*/
NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(nullptr), client_id(INVALID_CLIENT_ID),
NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s, ClientID client_id) : info(nullptr), client_id(client_id),
last_frame(_frame_counter), last_frame_server(_frame_counter)
{
this->sock = s;
Expand Down
2 changes: 1 addition & 1 deletion src/network/core/tcp_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class NetworkGameSocketHandler : public NetworkTCPSocketHandler {

NetworkRecvStatus HandlePacket(Packet *p);

NetworkGameSocketHandler(SOCKET s);
NetworkGameSocketHandler(SOCKET s, ClientID client_id = INVALID_CLIENT_ID);
public:
ClientID client_id; ///< Client identifier
uint32 last_frame; ///< Last frame we have executed
Expand Down
3 changes: 1 addition & 2 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,7 @@ NetworkAddress ParseConnectionString(const std::string &connection_string, uint1
/* Register the login */
_network_clients_connected++;

ServerNetworkGameSocketHandler *cs = new ServerNetworkGameSocketHandler(s);
cs->client_address = address; // Save the IP of the client
new ServerNetworkGameSocketHandler(s, address);

InvalidateWindowData(WC_CLIENT_LIST, 0);
}
Expand Down
6 changes: 1 addition & 5 deletions src/network/network_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,8 @@ struct PacketWriter : SaveFilter {
* Create a new socket for the server side of the game connection.
* @param s The socket to connect with.
*/
ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : NetworkGameSocketHandler(s)
ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s, NetworkAddress client_address) : NetworkGameSocketHandler(s, _network_client_id++), status(STATUS_INACTIVE), receive_limit(_settings_client.network.bytes_per_frame_burst), client_address(client_address)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, two years later, same comment: please don't do a ++ in a ctor initializer like this. That is going to be overlooked and will bite us in the ass :) ctor member initializer should be without side-effects. Side-effects go in the body.

{
this->status = STATUS_INACTIVE;
this->client_id = _network_client_id++;
this->receive_limit = _settings_client.network.bytes_per_frame_burst;

/* The Socket and Info pools need to be the same in size. After all,
* each Socket will be associated with at most one Info object. As
* such if the Socket was allocated the Info object can as well. */
Expand Down
2 changes: 1 addition & 1 deletion src/network/network_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<
struct PacketWriter *savegame; ///< Writer used to write the savegame.
NetworkAddress client_address; ///< IP-address of the client (so they can be banned)

ServerNetworkGameSocketHandler(SOCKET s);
ServerNetworkGameSocketHandler(SOCKET s, NetworkAddress client_address);
~ServerNetworkGameSocketHandler();

virtual Packet *ReceivePacket() override;
Expand Down