Skip to content

Commit

Permalink
Implemented GET_NETWORK_ADDRESS
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmit799 committed Jan 18, 2024
1 parent 42067dd commit 16220bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/clientagent/client_participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ void ClientParticipant::HandleDatagram(const std::shared_ptr<Datagram> &dg) {
_sessionObjects.erase(doId);
break;
}
case CLIENTAGENT_GET_TLVS_RESP: {
// TODO.
break;
}
case CLIENTAGENT_GET_NETWORK_ADDRESS: {
// TODO.
auto resp = std::make_shared<Datagram>(sender, _channel, CLIENTAGENT_GET_NETWORK_ADDRESS_RESP);
resp->AddUint32(dgi.GetUint32()); // Context.
resp->AddString(GetRemoteAddress().ip);
resp->AddUint16(GetRemoteAddress().port);
resp->AddString(GetLocalAddress().ip);
resp->AddUint16(GetLocalAddress().port);
PublishDatagram(resp);
break;
}
case STATESERVER_OBJECT_SET_FIELD: {
Expand Down
13 changes: 12 additions & 1 deletion src/net/network_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NetworkClient::NetworkClient(const std::shared_ptr<uvw::tcp_handle> &socket)
_socket->keep_alive(true, uvw::tcp_handle::time{60});

_remoteAddress = _socket->peer();
_localAddress = _socket->sock();

// Setup event listeners.
_socket->on<uvw::error_event>(
Expand Down Expand Up @@ -59,7 +60,17 @@ bool NetworkClient::Disconnected() const { return _disconnected; }
* Returns this clients remote address.
* @return
*/
uvw::socket_address NetworkClient::GetRemoteAddress() { return _remoteAddress; }
uvw::socket_address NetworkClient::GetRemoteAddress() const {
return _remoteAddress;
}

/**
* Returns this clients local address.
* @return
*/
uvw::socket_address NetworkClient::GetLocalAddress() const {
return _localAddress;
}

void NetworkClient::Shutdown() {
if (_disconnected) {
Expand Down
4 changes: 3 additions & 1 deletion src/net/network_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class NetworkClient {
~NetworkClient();

[[nodiscard]] bool Disconnected() const;
uvw::socket_address GetRemoteAddress();
[[nodiscard]] uvw::socket_address GetRemoteAddress() const;
[[nodiscard]] uvw::socket_address GetLocalAddress() const;

void Shutdown();

Expand All @@ -34,6 +35,7 @@ class NetworkClient {

std::shared_ptr<uvw::tcp_handle> _socket;
uvw::socket_address _remoteAddress;
uvw::socket_address _localAddress;
std::vector<uint8_t> _data_buf;

bool _isWriting = false;
Expand Down

0 comments on commit 16220bc

Please sign in to comment.