Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Oct 11, 2023
1 parent c8f7233 commit 23061ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/server/network/connection/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void Connection::close(bool force) {
ConnectionManager::getInstance().releaseConnection(shared_from_this());

std::lock_guard<std::recursive_mutex> lockClass(connectionLock);
ip = 0;
if (connectionState == CONNECTION_STATE_CLOSED) {
return;
}
Expand Down Expand Up @@ -325,16 +326,17 @@ void Connection::internalWorker() {
}

uint32_t Connection::getIP() {
if (ip != 1) {
return ip;
}

std::lock_guard<std::recursive_mutex> lockClass(connectionLock);

// IP-address is expressed in network byte order
std::error_code error;
const asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(error);
if (error) {
return 0;
}

return htonl(endpoint.address().to_v4().to_ulong());
ip = error ? 0 : htonl(endpoint.address().to_v4().to_ulong());
return ip;
}

void Connection::internalSend(const OutputMessage_ptr &outputMessage) {
Expand Down
1 change: 1 addition & 0 deletions src/server/network/connection/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Connection : public std::enable_shared_from_this<Connection> {

time_t timeConnected;
uint32_t packetsSent = 0;
uint32_t ip = 1;

std::underlying_type_t<ConnectionState_t> connectionState = CONNECTION_STATE_OPEN;
bool receivedFirst = false;
Expand Down

0 comments on commit 23061ae

Please sign in to comment.