diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-11 19:09:47 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:44:59 +0800 |
| commit | e702fc9cdbe9808a8cc7a60bf3c414f874d81d02 (patch) | |
| tree | f44b7db3600671e21a9ac07cce4e7a6f6239082f /src/session.cpp | |
| parent | b3fc81f22c0f00636611ef36e70138607635c2ff (diff) | |
session: get/use IP and port on connect
Diffstat (limited to 'src/session.cpp')
| -rw-r--r-- | src/session.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/session.cpp b/src/session.cpp index b3994ee..64dbda1 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,16 +1,23 @@ #include "session.hpp" #include "chatManager.hpp" #include "log.hpp" +#include "server.hpp" #include "sessionManager.hpp" #include <cerrno> #include <cstring> #include <sys/socket.h> +#include <arpa/inet.h> + +CSession::CSession() : m_addrLen(sizeof(m_addr)) { + m_sockfd = Hyprutils::OS::CFileDescriptor{accept(g_pServer->getSocket()->get(), reinterpret_cast<sockaddr *>(&m_addr), &m_addrLen)}; // if this is in the init list, it will run before m_addrLen, so it won't work :/ -CSession::CSession(Hyprutils::OS::CFileDescriptor sockfd) - : m_sockfd(std::move(sockfd)) { if (!m_sockfd.isValid()) throw std::runtime_error("session: Failed to create socket"); + inet_ntop(AF_INET, &m_addr.sin_addr, m_ip, INET_ADDRSTRLEN); + m_port = ntohs(m_addr.sin_port); + log(TRACE, "session({}): connected on port {}", m_ip, m_port); + log(TRACE, "session: initialized"); } @@ -82,8 +89,7 @@ CSession::SRecvData CSession::read(const std::string &msg) { void CSession::run() { onConnect(); registerSession() ? recvLoop() : - // TODO: get ip and print the ip also - log(LOG, "User exited without even registering"); + log(LOG, "Client {} exited without even registering", m_ip); g_pSessionManager->removeSession(self); } |
