Füge erweitertes Logging für Raumverwaltung im SSLServer hinzu
- Ergänze Debug-Ausgaben in der Methode `handleWebSocketMessage`, um verfügbare Räume und den Status der Benutzeranmeldung zu protokollieren. - Füge Logging in der Methode `createRooms` hinzu, um den Prozess der Raumerstellung aus der Konfiguration zu verfolgen. - Implementiere zusätzliche Ausgaben in der Methode `reloadRooms`, um die Anzahl der geladenen Räume aus der Datenbank zu dokumentieren und Fehlerfälle zu behandeln.
This commit is contained in:
@@ -278,10 +278,21 @@ void SSLServer::handleWebSocketMessage(struct lws *wsi, const std::string& messa
|
|||||||
|
|
||||||
// Try to add user to room
|
// Try to add user to room
|
||||||
bool added = false;
|
bool added = false;
|
||||||
|
|
||||||
|
// Debug: List all available rooms
|
||||||
|
std::cout << "[YourChat] Available rooms: ";
|
||||||
|
for (const auto &roomObj: _rooms) {
|
||||||
|
std::cout << "'" << roomObj->name() << "' ";
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << "[YourChat] Looking for room: '" << room << "'" << std::endl;
|
||||||
|
|
||||||
for (auto &roomObj: _rooms) {
|
for (auto &roomObj: _rooms) {
|
||||||
if (roomObj->name() == room) {
|
if (roomObj->name() == room) {
|
||||||
|
std::cout << "[YourChat] Found room '" << room << "', attempting to add user..." << std::endl;
|
||||||
// Add user to room (ChatUser will be created by addUser)
|
// Add user to room (ChatUser will be created by addUser)
|
||||||
if (roomObj->addUser(name, color, password, lws_get_socket_fd(wsi))) {
|
if (roomObj->addUser(name, color, password, lws_get_socket_fd(wsi))) {
|
||||||
|
std::cout << "[YourChat] Successfully added user '" << name << "' to room '" << room << "'" << std::endl;
|
||||||
// Find the created ChatUser
|
// Find the created ChatUser
|
||||||
auto chatUser = roomObj->findUserByName(name);
|
auto chatUser = roomObj->findUserByName(name);
|
||||||
if (chatUser) {
|
if (chatUser) {
|
||||||
@@ -289,6 +300,8 @@ void SSLServer::handleWebSocketMessage(struct lws *wsi, const std::string& messa
|
|||||||
}
|
}
|
||||||
added = true;
|
added = true;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
std::cout << "[YourChat] Failed to add user '" << name << "' to room '" << room << "'" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,14 +428,20 @@ void SSLServer::createRooms() {
|
|||||||
// Load rooms from database or config
|
// Load rooms from database or config
|
||||||
Json::Value roomList = _config->group("rooms");
|
Json::Value roomList = _config->group("rooms");
|
||||||
|
|
||||||
|
std::cout << "[YourChat] createRooms() called" << std::endl;
|
||||||
|
std::cout << "[YourChat] Config rooms size: " << roomList.size() << std::endl;
|
||||||
|
|
||||||
if (roomList.isArray() && roomList.size() > 0) {
|
if (roomList.isArray() && roomList.size() > 0) {
|
||||||
|
std::cout << "[YourChat] Loading rooms from config..." << std::endl;
|
||||||
for (const auto& room : roomList) {
|
for (const auto& room : roomList) {
|
||||||
|
std::cout << "[YourChat] Config room: " << room << std::endl;
|
||||||
// Create room objects using the same logic as the main server
|
// Create room objects using the same logic as the main server
|
||||||
auto newRoom = std::make_shared<ChatRoom>(nullptr, room); // parent will be set later
|
auto newRoom = std::make_shared<ChatRoom>(nullptr, room); // parent will be set later
|
||||||
_rooms.push_back(newRoom);
|
_rooms.push_back(newRoom);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create default room if no rooms configured
|
// Create default room if no rooms configured
|
||||||
|
std::cout << "[YourChat] No config rooms found, creating default room..." << std::endl;
|
||||||
Json::Value defaultRoom;
|
Json::Value defaultRoom;
|
||||||
defaultRoom["name"] = "Halle";
|
defaultRoom["name"] = "Halle";
|
||||||
defaultRoom["password"] = "";
|
defaultRoom["password"] = "";
|
||||||
@@ -433,6 +452,11 @@ void SSLServer::createRooms() {
|
|||||||
_rooms.push_back(newRoom);
|
_rooms.push_back(newRoom);
|
||||||
std::cout << "[YourChat] Created default room 'Halle'" << std::endl;
|
std::cout << "[YourChat] Created default room 'Halle'" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "[YourChat] Total rooms created: " << _rooms.size() << std::endl;
|
||||||
|
for (const auto& room : _rooms) {
|
||||||
|
std::cout << "[YourChat] Room: '" << room->name() << "'" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSLServer::reloadRooms() {
|
void SSLServer::reloadRooms() {
|
||||||
@@ -444,13 +468,21 @@ void SSLServer::reloadRooms() {
|
|||||||
// Try to load rooms from database first
|
// Try to load rooms from database first
|
||||||
try {
|
try {
|
||||||
Json::Value dbRooms = _database->getRooms();
|
Json::Value dbRooms = _database->getRooms();
|
||||||
|
std::cout << "[YourChat] Database returned " << dbRooms.size() << " rooms" << std::endl;
|
||||||
|
|
||||||
if (dbRooms.isArray() && dbRooms.size() > 0) {
|
if (dbRooms.isArray() && dbRooms.size() > 0) {
|
||||||
for (const auto& room : dbRooms) {
|
for (const auto& room : dbRooms) {
|
||||||
|
std::cout << "[YourChat] Database room: " << room << std::endl;
|
||||||
auto newRoom = std::make_shared<ChatRoom>(nullptr, room);
|
auto newRoom = std::make_shared<ChatRoom>(nullptr, room);
|
||||||
_rooms.push_back(newRoom);
|
_rooms.push_back(newRoom);
|
||||||
}
|
}
|
||||||
std::cout << "[YourChat] Loaded " << _rooms.size() << " rooms from database" << std::endl;
|
std::cout << "[YourChat] Loaded " << _rooms.size() << " rooms from database" << std::endl;
|
||||||
|
for (const auto& room : _rooms) {
|
||||||
|
std::cout << "[YourChat] Loaded room: '" << room->name() << "'" << std::endl;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
std::cout << "[YourChat] No rooms found in database, falling back to config/default" << std::endl;
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "[YourChat] Failed to load rooms from database: " << e.what() << std::endl;
|
std::cerr << "[YourChat] Failed to load rooms from database: " << e.what() << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user