MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / ReadValidation

Method ReadValidation

extensions/olcPGEX_Network.h:605–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603 }
604
605 void ReadValidation(olc::net::server_interface<T>* server = nullptr)
606 {
607 asio::async_read(m_socket, asio::buffer(&m_nHandshakeIn, sizeof(uint64_t)),
608 [this, server](std::error_code ec, std::size_t length)
609 {
610 if (!ec)
611 {
612 if (m_nOwnerType == owner::server)
613 {
614 // Connection is a server, so check response from client
615
616 // Compare sent data to actual solution
617 if (m_nHandshakeIn == m_nHandshakeCheck)
618 {
619 // Client has provided valid solution, so allow it to connect properly
620 std::cout << "Client Validated" << std::endl;
621 server->OnClientValidated(this->shared_from_this());
622
623 // Sit waiting to receive data now
624 ReadHeader();
625 }
626 else
627 {
628 // Client gave incorrect data, so disconnect
629 std::cout << "Client Disconnected (Fail Validation)" << std::endl;
630 m_socket.close();
631 }
632 }
633 else
634 {
635 // Connection is a client, so solve puzzle
636 m_nHandshakeOut = scramble(m_nHandshakeIn);
637
638 // Write the result
639 WriteValidation();
640 }
641 }
642 else
643 {
644 // Some biggerfailure occured
645 std::cout << "Client Disconnected (ReadValidation)" << std::endl;
646 m_socket.close();
647 }
648 });
649 }
650
651 // Once a full message is received, add it to the incoming queue
652 void AddToIncomingMessageQueue()

Callers

nothing calls this directly

Calls 1

OnClientValidatedMethod · 0.80

Tested by

no test coverage detected