10Client::Client(
const std::string &playerName,
const std::string &host, uint16_t port,
bool isSpectator)
11 : _playerName(playerName),
16 _isSpectator(isSpectator) {}
18Client::Client(
const std::string &playerName,
const std::string &username,
const std::string &password,
19 const std::string &host, uint16_t port)
20 : _playerName(playerName),
25 _isSpectator(false) {}
43 LOG_INFO(
"Initializing R-Type client...");
47 LOG_ERROR(
"Failed to initialize networking");
63 LOG_ERROR(
"Failed to initialize GameLoop");
69 LOG_INFO(
"Initialization complete!");
82 LOG_INFO(
"[Client] Server changed to ", host,
":", port);
93 LOG_ERROR(
"Failed to initiate connection");
98 LOG_INFO(
"Waiting for connection...");
99 bool connected =
false;
100 for (
int i = 0; i < 50 && !connected; ++i) {
103 std::this_thread::sleep_for(std::chrono::milliseconds(100));
114 LOG_INFO(
"Sending authentication request...");
121 LOG_ERROR(
"Failed to send connect request");
126 LOG_INFO(
"Waiting for server response...");
127 bool authenticated =
false;
128 for (
int i = 0; i < 30 && !authenticated; ++i) {
134 std::this_thread::sleep_for(std::chrono::milliseconds(100));
140 authenticated =
true;
151 LOG_ERROR(
"Cannot run: not initialized");
155 LOG_INFO(
"Starting R-Type client...");
156 LOG_INFO(
"========================================");
159 LOG_INFO(
"Waiting for server selection...");
160 LOG_INFO(
"========================================");
166 const std::string &serverInfo =
event.getData();
167 size_t colonPos = serverInfo.find(
':');
168 if (colonPos != std::string::npos) {
169 std::string ip = serverInfo.substr(0, colonPos);
170 uint16_t port =
static_cast<uint16_t
>(std::stoi(serverInfo.substr(colonPos + 1)));
172 LOG_INFO(
"[Client] Connecting to ", ip,
":", port,
"...");
176 std::thread([
this]() {
178 LOG_ERROR(
"[Client] Connection failed!");
182 LOG_INFO(
"[Client] ✓ Connected successfully!");
bool initializeNetworking()
Initialize the networking subsystem.
void deinitializeNetworking()
Cleanup the networking subsystem.
bool initialize()
Initialize client systems.
void SetServer(const std::string &host, uint16_t port)
Set server address and port.
std::unique_ptr< Replicator > _replicator
~Client()
Destructor - clean shutdown.
bool connectToServer()
Connect to server.
void stop()
Stop the client.
Client(const std::string &playerName, const std::string &host, uint16_t port, bool isSpectator=false)
Constructor.
std::unique_ptr< GameLoop > _gameLoop
bool Connect()
Connect to the configured server.
void SetCredentials(const std::string &username, const std::string &password)
Update credentials for next connection attempt.
void run()
Run the client (Start Game Loop directly)
std::unique_ptr< EventBus > _eventBus