Fixed messages not showing up in QT client from the android client
Android client requires double authentication ;at the moment. After loggin in type LOGIN:USERNAME:PASSWORD in chat to finish the login. Android can send messages after 2nd login.
This commit is contained in:
parent
7bf93623bf
commit
e86abb53d6
@ -468,8 +468,22 @@ private slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_socket_read() {
|
void on_socket_read() {
|
||||||
while (socket->canReadLine()) {
|
// Read all available data
|
||||||
QString message = QString::fromUtf8(socket->readLine()).trimmed();
|
QByteArray data = socket->readAll();
|
||||||
|
if (data.isEmpty()) return;
|
||||||
|
|
||||||
|
// Append to buffer
|
||||||
|
m_read_buffer.append(data);
|
||||||
|
|
||||||
|
// Process complete lines
|
||||||
|
while (true) {
|
||||||
|
int newline_pos = m_read_buffer.indexOf('\n');
|
||||||
|
if (newline_pos == -1) break; // No complete line yet
|
||||||
|
|
||||||
|
QString message = QString::fromUtf8(m_read_buffer.left(newline_pos)).trimmed();
|
||||||
|
m_read_buffer.remove(0, newline_pos + 1);
|
||||||
|
|
||||||
|
if (message.isEmpty()) continue; // Skip empty lines
|
||||||
|
|
||||||
// Handle authentication response
|
// Handle authentication response
|
||||||
if (message.startsWith("LOGIN_SUCCESS:")) {
|
if (message.startsWith("LOGIN_SUCCESS:")) {
|
||||||
@ -499,7 +513,7 @@ private slots:
|
|||||||
// Placeholder for future video frame implementation
|
// Placeholder for future video frame implementation
|
||||||
} else {
|
} else {
|
||||||
// Regular chat message
|
// Regular chat message
|
||||||
chat_display->append("[Server] " + message);
|
chat_display->append(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -601,6 +615,7 @@ private:
|
|||||||
|
|
||||||
// Connection
|
// Connection
|
||||||
QSslSocket *socket;
|
QSslSocket *socket;
|
||||||
|
QByteArray m_read_buffer;
|
||||||
QColor bg_color;
|
QColor bg_color;
|
||||||
QColor text_color;
|
QColor text_color;
|
||||||
|
|
||||||
|
|||||||
@ -71,15 +71,9 @@ bool load_certificates(const char *cert_file, const char *key_file) {
|
|||||||
|
|
||||||
void broadcast_message(const std::string &message, SSL *sender) {
|
void broadcast_message(const std::string &message, SSL *sender) {
|
||||||
std::lock_guard<std::mutex> lock(clients_mutex);
|
std::lock_guard<std::mutex> lock(clients_mutex);
|
||||||
std::cout << "Broadcasting to " << client_sockets.size() << " clients (excluding sender): " << message;
|
|
||||||
for (SSL *client : client_sockets) {
|
for (SSL *client : client_sockets) {
|
||||||
if (client != sender) {
|
if (client != sender) {
|
||||||
int bytes_written = SSL_write(client, message.c_str(), message.length());
|
SSL_write(client, message.c_str(), message.length());
|
||||||
if (bytes_written <= 0) {
|
|
||||||
std::cerr << "Failed to write to client: " << SSL_get_error(client, bytes_written) << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout << " -> Sent " << bytes_written << " bytes to client" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user