18 : _network(network), _registry(registry) {};
27 std::ifstream inFile(
"logins.txt");
34 tempPacket >> payload;
35 username = std::string(payload.
username);
36 password = std::string(payload.
password);
39 log::info(
"Login attempt: session={} username='{}' password='{}'",
40 sessionId, username, password);
43 log::error(
"Failed to open logins.txt for reading");
45 return {
false, username, weaponKind};
49 std::string record = username +
":" + password;
51 while (std::getline(inFile, line)) {
53 log::info(
"Login successful for username '{}'", username);
55 return {
true, username, weaponKind};
58 log::warning(
"Login failed for username '{}'", username);
60 return {
false, username, weaponKind};
65 std::ofstream outFile(
"logins.txt", std::ios::app);
72 tempPacket >> payload;
73 username = std::string(payload.
username);
74 password = std::string(payload.
password);
76 log::info(
"Registration attempt: username='{}' password='{}'",
80 log::error(
"Failed to open logins.txt for writing");
82 return {
false, username};
85 if (username.find(
':') != std::string::npos || password.find(
':') != std::string::npos) {
86 log::warning(
"Registration failed: username or password contains invalid character ':'");
88 return {
false, username};
91 std::ifstream inFile(
"logins.txt");
93 while (std::getline(inFile, line)) {
94 size_t delimPos = line.find(
':');
95 if (delimPos != std::string::npos) {
96 std::string existingUsername = line.substr(0, delimPos);
97 if (existingUsername == username) {
98 log::warning(
"Registration failed: username '{}' already exists", username);
100 return {
false, username};
105 outFile << username <<
":" << password <<
"\n";
106 log::info(
"Registration successful for username '{}'", username);
108 return {
true, username};
116 std::strncpy(payload.username, username.c_str(),
sizeof(payload.username) - 1);
117 payload.username[
sizeof(payload.username) - 1] =
'\0';
118 responsePacket << payload;
127 std::strncpy(payload.username, username.c_str(),
sizeof(payload.username) - 1);
128 payload.username[
sizeof(payload.username) - 1] =
'\0';
129 responsePacket << payload;
Network packet with header and serializable body.
ServerNetwork & _network
Reference to the server network manager.
void sendRegisterResponse(uint32_t sessionId, bool success, const std::string &username)
Send a registration response to a client.
void sendLoginResponse(uint32_t sessionId, bool success, const std::string &username)
Send a login response to a client.
std::pair< bool, std::string > handleRegisterRequest(uint32_t sessionId, const net::Packet &packet)
Handle a registration request from a client.
void update(float dt) override
Update system logic for one frame.
std::tuple< bool, std::string, uint8_t > handleLoginRequest(uint32_t sessionId, const net::Packet &packet)
Handle a login request from a client.
AuthSystem(ServerNetwork &network, ecs::Registry ®istry)
Constructor for AuthSystem.
Implementation ASIO du serveur réseau (TCP + UDP)
void sendPacket(uint32_t sessionId, const net::Packet &packet, net::NetworkMode mode)
Send a packet to a specific session.
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
void info(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an informational message.
@ RegisterResponse
Incorrect password notification.
@ LoginResponse
Successful connection notification.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
char password[32]
Player password.
uint8_t weaponKind
Selected weapon kind.
char username[32]
Player username.
Login response data sent by server for LoginResponse Server OpCode.
uint8_t success
Login success flag.
Player registration data sended by client Client OpCode.
char password[32]
Player password.
char username[32]
Player username.
Registration response data sent by server for RegisterResponse Server OpCode.
uint8_t success
Registration success flag.