TODO: implement handshake
| 27 | |
| 28 | // TODO: implement handshake |
| 29 | bool Connection::Reconnect() |
| 30 | { |
| 31 | if (!m_socket) |
| 32 | return false; |
| 33 | |
| 34 | m_socket->Close(); |
| 35 | |
| 36 | if (!m_socket->Open(m_host, m_port)) |
| 37 | return false; |
| 38 | |
| 39 | // TODO: generate unique client id here. |
| 40 | std::string clientId = "TODO"; |
| 41 | auto packet = Protocol::CreateAuthPacket(clientId); |
| 42 | if (!m_socket->Write(packet.data(), static_cast<uint32_t>(packet.size()))) |
| 43 | return false; |
| 44 | |
| 45 | std::string check(std::begin(Protocol::kFail), std::end(Protocol::kFail)); |
| 46 | bool const isSuccess = m_socket->Read(reinterpret_cast<uint8_t *>(&check[0]), static_cast<uint32_t>(check.size())); |
| 47 | if (!isSuccess || check != std::string(std::begin(Protocol::kOk), std::end(Protocol::kOk))) |
| 48 | return false; |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | void Connection::Shutdown() |
| 54 | { |