Files

39 lines
1.6 KiB
C++

#pragma once
#include "gateway/legacy_stream.hpp"
#include "gateway/source_account_key.h"
#include <string_view>
#include <memory>
#include <string>
namespace gateway {
class LegacyLogin;
class LegacySession;
// Socket-free legitimate world handshake, created only from a verified SRP
// account. The transport owns I/O; no key or POSIX descriptor is exported.
class WorldAuthentication {
friend class LegacyLogin;
friend class LegacySession;
std::string username_;
Bytes key_,addons_;
uint32_t build_;
uint16_t port_;
std::unique_ptr<LegacyPacketStream> stream_;
bool accepted_=false,failed_=false;
WorldAuthentication(const std::string&,const Bytes&,Bytes,uint32_t,uint16_t);
public:
~WorldAuthentication();
WorldAuthentication(const WorldAuthentication&)=delete;
WorldAuthentication& operator=(const WorldAuthentication&)=delete;
uint16_t port() const {return port_;}
uint32_t internal_source_account() const {return accepted()?gw_source_account_key(username_.data(),username_.size()):0;}
bool accepted() const {return accepted_ && !failed_;}
std::string_view account_name() const {return accepted()?std::string_view(username_):std::string_view{};}
// Plain server challenge -> legitimate CMSG_AUTH_SESSION; starts header
// encryption exactly once. All later incoming frames use stream().
Bytes begin(const LegacyPacket&);
// Validate a genuinely received decoded auth response. Other packets are
// still dispatched by the caller; this does not invent an auth success.
void accept(const LegacyPacket&);
LegacyPacketStream& stream();
};
}