diff options
| author | alpine <[email protected]> | 2020-06-16 13:35:02 +0200 |
|---|---|---|
| committer | alpine <[email protected]> | 2020-06-16 13:35:02 +0200 |
| commit | 4a1762e5a6cdf995bd4ff959c17dbdef5189adea (patch) | |
| tree | 5cbd5c3bf899ce639493064005463fe0cf82a8a6 /client/src | |
| parent | Finished session/user id generation. (diff) | |
| download | loader-4a1762e5a6cdf995bd4ff959c17dbdef5189adea.tar.xz loader-4a1762e5a6cdf995bd4ff959c17dbdef5189adea.zip | |
Renamed uid to session id.
Diffstat (limited to 'client/src')
| -rw-r--r-- | client/src/client/client.cpp | 8 | ||||
| -rw-r--r-- | client/src/client/client.h | 4 | ||||
| -rw-r--r-- | client/src/client/packet.h | 22 | ||||
| -rw-r--r-- | client/src/main.cpp | 2 |
4 files changed, 18 insertions, 18 deletions
diff --git a/client/src/client/client.cpp b/client/src/client/client.cpp index 9688543..9c290ff 100644 --- a/client/src/client/client.cpp +++ b/client/src/client/client.cpp @@ -39,11 +39,11 @@ bool tcp::client::start(const std::string_view server_ip, const uint16_t port) { return true; } -bool tcp::client::set_uid() { - m_uid.resize(tcp::uid_len); +bool tcp::client::set_session() { + m_session_id.resize(tcp::session_id_len); - int ret = read(&m_uid[0], tcp::uid_len); - if(ret != tcp::uid_len) return false; + int ret = read(&m_session_id[0], tcp::session_id_len); + if(ret != tcp::session_id_len) return false; return true; } diff --git a/client/src/client/client.h b/client/src/client/client.h index 992cae6..3092c20 100644 --- a/client/src/client/client.h +++ b/client/src/client/client.h @@ -14,7 +14,7 @@ class client { SSL *m_server_ssl; SSL_CTX *m_ssl_ctx; - std::string m_uid; + std::string m_session_id; public: event<packet_t &> receive_event; @@ -33,7 +33,7 @@ class client { int read_stream(std::vector<char> &out); int stream(std::vector<char> &data); - bool set_uid(); + bool set_session(); int get_socket() { return m_socket; } bool is_active() { return m_state == client_state::active; } diff --git a/client/src/client/packet.h b/client/src/client/packet.h index 7ac8857..d60eae7 100644 --- a/client/src/client/packet.h +++ b/client/src/client/packet.h @@ -1,36 +1,36 @@ #pragma once namespace tcp { -constexpr size_t uid_len = 10; +constexpr size_t session_id_len = 10; enum packet_type : int { write = 0, read }; struct packet_t { std::string message; char action; - std::string uid; + std::string session_id; packet_t() {} - packet_t(const std::string msg, const packet_type &type, std::string userid = "") { + packet_t(const std::string_view msg, const packet_type &type, std::string_view session = "") { if (type == read) { - if (msg.size() < uid_len) { - io::logger->error("client packet message invalid!"); + if (msg.size() < session_id_len) { + io::logger->error("packet message invalid!"); return; } - uid = msg.substr(0, uid_len); + session_id = msg.substr(0, session_id_len); - action = msg[uid_len]; - message = msg.substr(uid_len); + action = msg[session_id_len]; + message = msg.substr(session_id_len); } else { - uid = userid; + session_id = session; - message = fmt::format("{}{}", uid, msg); + message = fmt::format("{}{}", session_id, msg); } } operator bool() const { - return !message.empty() && !uid.empty(); + return !message.empty() && !session_id.empty(); } }; }; // namespace tcp diff --git a/client/src/main.cpp b/client/src/main.cpp index a9fecec..7177511 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) { tcp::client client; if (client.start("127.0.0.1", 6666)) { - if(!client.set_uid()) { + if(!client.set_session()) { io::logger->error("failed to set session id."); return 0; } |