mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-21 23:00:24 -08:00
more ServerNetwork code
This commit is contained in:
@@ -34,8 +34,6 @@ SET(common_HEADERS
|
|||||||
FIND_PACKAGE(Qt4 REQUIRED)
|
FIND_PACKAGE(Qt4 REQUIRED)
|
||||||
FIND_PACKAGE(Protobuf REQUIRED)
|
FIND_PACKAGE(Protobuf REQUIRED)
|
||||||
|
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
|
||||||
|
|
||||||
QT4_WRAP_CPP(common_HEADERS_MOC ${common_HEADERS})
|
QT4_WRAP_CPP(common_HEADERS_MOC ${common_HEADERS})
|
||||||
INCLUDE(${QT_USE_FILE})
|
INCLUDE(${QT_USE_FILE})
|
||||||
INCLUDE_DIRECTORIES(pb)
|
INCLUDE_DIRECTORIES(pb)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ SET(PROTO_FILES
|
|||||||
event_reveal_cards.proto
|
event_reveal_cards.proto
|
||||||
event_roll_die.proto
|
event_roll_die.proto
|
||||||
event_room_say.proto
|
event_room_say.proto
|
||||||
|
event_server_complete_list.proto
|
||||||
event_server_identification.proto
|
event_server_identification.proto
|
||||||
event_server_message.proto
|
event_server_message.proto
|
||||||
event_server_shutdown.proto
|
event_server_shutdown.proto
|
||||||
@@ -132,6 +133,7 @@ SET(PROTO_FILES
|
|||||||
serverinfo_room.proto
|
serverinfo_room.proto
|
||||||
serverinfo_user.proto
|
serverinfo_user.proto
|
||||||
serverinfo_zone.proto
|
serverinfo_zone.proto
|
||||||
|
servernetwork_message.proto
|
||||||
server_message.proto
|
server_message.proto
|
||||||
session_commands.proto
|
session_commands.proto
|
||||||
session_event.proto
|
session_event.proto
|
||||||
|
|||||||
12
common/pb/event_server_complete_list.proto
Normal file
12
common/pb/event_server_complete_list.proto
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import "session_event.proto";
|
||||||
|
import "serverinfo_user.proto";
|
||||||
|
import "serverinfo_room.proto";
|
||||||
|
|
||||||
|
message Event_ServerCompleteList {
|
||||||
|
extend SessionEvent {
|
||||||
|
optional Event_ServerCompleteList ext = 600;
|
||||||
|
}
|
||||||
|
optional uint32 server_id = 1;
|
||||||
|
repeated ServerInfo_User user_list = 2;
|
||||||
|
repeated ServerInfo_Room room_list = 3;
|
||||||
|
}
|
||||||
24
common/pb/servernetwork_message.proto
Normal file
24
common/pb/servernetwork_message.proto
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import "response.proto";
|
||||||
|
import "session_event.proto";
|
||||||
|
import "commands.proto";
|
||||||
|
import "game_event_container.proto";
|
||||||
|
import "room_event.proto";
|
||||||
|
|
||||||
|
message ServerNetworkMessage {
|
||||||
|
enum MessageType {
|
||||||
|
RESPONSE = 0;
|
||||||
|
SESSION_EVENT = 1;
|
||||||
|
GAME_COMMAND_CONTAINER = 2;
|
||||||
|
GAME_EVENT_CONTAINER = 3;
|
||||||
|
ROOM_EVENT = 4;
|
||||||
|
}
|
||||||
|
optional MessageType message_type = 1;
|
||||||
|
|
||||||
|
optional sint32 game_id = 10;
|
||||||
|
|
||||||
|
optional Response response = 100;
|
||||||
|
optional SessionEvent session_event = 101;
|
||||||
|
optional CommandContainer game_command = 102;
|
||||||
|
optional GameEventContainer game_event_container = 103;
|
||||||
|
optional RoomEvent room_event = 104;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
message SessionEvent {
|
message SessionEvent {
|
||||||
enum SessionEventType {
|
enum SessionEventType {
|
||||||
SERVER_IDENTIFICATION = 500;
|
SERVER_IDENTIFICATION = 500;
|
||||||
|
SERVER_COMPLETE_LIST = 600;
|
||||||
SERVER_MESSAGE = 1000;
|
SERVER_MESSAGE = 1000;
|
||||||
SERVER_SHUTDOWN = 1001;
|
SERVER_SHUTDOWN = 1001;
|
||||||
CONNECTION_CLOSED = 1002;
|
CONNECTION_CLOSED = 1002;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||||||
QMutexLocker locker(&serverMutex);
|
QMutexLocker locker(&serverMutex);
|
||||||
if (name.size() > 35)
|
if (name.size() > 35)
|
||||||
name = name.left(35);
|
name = name.left(35);
|
||||||
|
|
||||||
AuthenticationResult authState = checkUserPassword(session, name, password, reasonStr);
|
AuthenticationResult authState = checkUserPassword(session, name, password, reasonStr);
|
||||||
if ((authState == NotLoggedIn) || (authState == UserIsBanned))
|
if ((authState == NotLoggedIn) || (authState == UserIsBanned))
|
||||||
return authState;
|
return authState;
|
||||||
@@ -62,8 +63,10 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||||||
data.set_address(session->getAddress().toStdString());
|
data.set_address(session->getAddress().toStdString());
|
||||||
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
||||||
|
|
||||||
|
lockSessionTables();
|
||||||
|
|
||||||
if (authState == PasswordRight) {
|
if (authState == PasswordRight) {
|
||||||
if (users.contains(name)) {
|
if (users.contains(name) || userSessionExists(name)) {
|
||||||
qDebug("Login denied: would overwrite old session");
|
qDebug("Login denied: would overwrite old session");
|
||||||
return WouldOverwriteOldSession;
|
return WouldOverwriteOldSession;
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||||||
// don't interfere with registered user names though.
|
// don't interfere with registered user names though.
|
||||||
QString tempName = name;
|
QString tempName = name;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (users.contains(tempName) || userExists(tempName))
|
while (users.contains(tempName) || userExists(tempName) || userSessionExists(tempName))
|
||||||
tempName = name + "_" + QString::number(++i);
|
tempName = name + "_" + QString::number(++i);
|
||||||
name = tempName;
|
name = tempName;
|
||||||
data.set_name(name.toStdString());
|
data.set_name(name.toStdString());
|
||||||
@@ -83,7 +86,9 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||||||
users.insert(name, session);
|
users.insert(name, session);
|
||||||
qDebug() << "Server::loginUser: name=" << name;
|
qDebug() << "Server::loginUser: name=" << name;
|
||||||
|
|
||||||
session->setSessionId(startSession(name, session->getAddress()));
|
session->setSessionId(startSession(name, session->getAddress()));
|
||||||
|
unlockSessionTables();
|
||||||
|
|
||||||
qDebug() << "session id:" << session->getSessionId();
|
qDebug() << "session id:" << session->getSessionId();
|
||||||
|
|
||||||
Event_UserJoined event;
|
Event_UserJoined event;
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ protected:
|
|||||||
int getGamesCount() const;
|
int getGamesCount() const;
|
||||||
int nextGameId, nextReplayId;
|
int nextGameId, nextReplayId;
|
||||||
void addRoom(Server_Room *newRoom);
|
void addRoom(Server_Room *newRoom);
|
||||||
|
|
||||||
|
virtual void clearSessionTables() { }
|
||||||
|
virtual void lockSessionTables() { }
|
||||||
|
virtual void unlockSessionTables() { }
|
||||||
|
virtual bool userSessionExists(const QString &userName) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -270,6 +270,7 @@ void Server_Game::doStartGameIfReady()
|
|||||||
activePlayer = -1;
|
activePlayer = -1;
|
||||||
nextTurn();
|
nextTurn();
|
||||||
|
|
||||||
|
locker.unlock();
|
||||||
room->broadcastGameListUpdate(this);
|
room->broadcastGameListUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -577,6 +577,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message
|
|||||||
if (authState == NotLoggedIn)
|
if (authState == NotLoggedIn)
|
||||||
return Response::RespLoginNeeded;
|
return Response::RespLoginNeeded;
|
||||||
|
|
||||||
|
server->serverMutex.lock();
|
||||||
QString receiver = QString::fromStdString(cmd.user_name());
|
QString receiver = QString::fromStdString(cmd.user_name());
|
||||||
Server_ProtocolHandler *userHandler = server->getUsers().value(receiver);
|
Server_ProtocolHandler *userHandler = server->getUsers().value(receiver);
|
||||||
if (!userHandler)
|
if (!userHandler)
|
||||||
@@ -592,6 +593,8 @@ Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message
|
|||||||
SessionEvent *se = prepareSessionEvent(event);
|
SessionEvent *se = prepareSessionEvent(event);
|
||||||
userHandler->sendProtocolItem(*se);
|
userHandler->sendProtocolItem(*se);
|
||||||
rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, se);
|
rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, se);
|
||||||
|
server->serverMutex.unlock();
|
||||||
|
|
||||||
return Response::RespOk;
|
return Response::RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,10 +634,12 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetU
|
|||||||
if (userName.isEmpty())
|
if (userName.isEmpty())
|
||||||
re->mutable_user_info()->CopyFrom(*userInfo);
|
re->mutable_user_info()->CopyFrom(*userInfo);
|
||||||
else {
|
else {
|
||||||
|
server->serverMutex.lock();
|
||||||
Server_ProtocolHandler *handler = server->getUsers().value(userName);
|
Server_ProtocolHandler *handler = server->getUsers().value(userName);
|
||||||
if (!handler)
|
if (!handler)
|
||||||
return Response::RespNameNotFound;
|
return Response::RespNameNotFound;
|
||||||
re->mutable_user_info()->CopyFrom(handler->copyUserInfo(true, userInfo->user_level() & ServerInfo_User::IsModerator));
|
re->mutable_user_info()->CopyFrom(handler->copyUserInfo(true, userInfo->user_level() & ServerInfo_User::IsModerator));
|
||||||
|
server->serverMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.setResponseExtension(re);
|
rc.setResponseExtension(re);
|
||||||
@@ -690,9 +695,11 @@ Response::ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUs
|
|||||||
return Response::RespLoginNeeded;
|
return Response::RespLoginNeeded;
|
||||||
|
|
||||||
Response_ListUsers *re = new Response_ListUsers;
|
Response_ListUsers *re = new Response_ListUsers;
|
||||||
|
server->serverMutex.lock();
|
||||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator = server->getUsers();
|
QMapIterator<QString, Server_ProtocolHandler *> userIterator = server->getUsers();
|
||||||
while (userIterator.hasNext())
|
while (userIterator.hasNext())
|
||||||
re->add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
re->add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
||||||
|
server->serverMutex.unlock();
|
||||||
|
|
||||||
acceptsUserListChanges = true;
|
acceptsUserListChanges = true;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Server_Room::~Server_Room()
|
|||||||
delete gameList[i];
|
delete gameList[i];
|
||||||
games.clear();
|
games.clear();
|
||||||
|
|
||||||
clear();
|
userList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Server *Server_Room::getServer() const
|
Server *Server_Room::getServer() const
|
||||||
@@ -39,7 +39,7 @@ ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool upd
|
|||||||
ServerInfo_Room result;
|
ServerInfo_Room result;
|
||||||
result.set_room_id(id);
|
result.set_room_id(id);
|
||||||
result.set_game_count(games.size());
|
result.set_game_count(games.size());
|
||||||
result.set_player_count(size());
|
result.set_player_count(userList.size());
|
||||||
|
|
||||||
if (!updating) {
|
if (!updating) {
|
||||||
result.set_name(name.toStdString());
|
result.set_name(name.toStdString());
|
||||||
@@ -52,8 +52,8 @@ ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool upd
|
|||||||
while (gameIterator.hasNext())
|
while (gameIterator.hasNext())
|
||||||
result.add_game_list()->CopyFrom(gameIterator.next().value()->getInfo());
|
result.add_game_list()->CopyFrom(gameIterator.next().value()->getInfo());
|
||||||
|
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < userList.size(); ++i)
|
||||||
result.add_user_list()->CopyFrom(at(i)->copyUserInfo(false));
|
result.add_user_list()->CopyFrom(userList[i]->copyUserInfo(false));
|
||||||
}
|
}
|
||||||
if (complete || showGameTypes)
|
if (complete || showGameTypes)
|
||||||
for (int i = 0; i < gameTypes.size(); ++i) {
|
for (int i = 0; i < gameTypes.size(); ++i) {
|
||||||
@@ -75,21 +75,22 @@ RoomEvent *Server_Room::prepareRoomEvent(const ::google::protobuf::Message &room
|
|||||||
|
|
||||||
void Server_Room::addClient(Server_ProtocolHandler *client)
|
void Server_Room::addClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&roomMutex);
|
|
||||||
|
|
||||||
Event_JoinRoom event;
|
Event_JoinRoom event;
|
||||||
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
||||||
sendRoomEvent(prepareRoomEvent(event));
|
sendRoomEvent(prepareRoomEvent(event));
|
||||||
|
|
||||||
append(client);
|
roomMutex.lock();
|
||||||
|
userList.append(client);
|
||||||
|
roomMutex.unlock();
|
||||||
|
|
||||||
emit roomInfoChanged();
|
emit roomInfoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&roomMutex);
|
roomMutex.lock();
|
||||||
|
userList.removeAt(userList.indexOf(client));
|
||||||
removeAt(indexOf(client));
|
roomMutex.unlock();
|
||||||
|
|
||||||
Event_LeaveRoom event;
|
Event_LeaveRoom event;
|
||||||
event.set_name(client->getUserInfo()->name());
|
event.set_name(client->getUserInfo()->name());
|
||||||
@@ -110,8 +111,8 @@ void Server_Room::sendRoomEvent(RoomEvent *event)
|
|||||||
{
|
{
|
||||||
QMutexLocker locker(&roomMutex);
|
QMutexLocker locker(&roomMutex);
|
||||||
|
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < userList.size(); ++i)
|
||||||
at(i)->sendProtocolItem(*event);
|
userList[i]->sendProtocolItem(*event);
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class ServerInfo_Game;
|
|||||||
class Server_Game;
|
class Server_Game;
|
||||||
class Server;
|
class Server;
|
||||||
|
|
||||||
class Server_Room : public QObject, public QList<Server_ProtocolHandler *> {
|
class Server_Room : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void roomInfoChanged();
|
void roomInfoChanged();
|
||||||
@@ -28,6 +28,7 @@ private:
|
|||||||
QString joinMessage;
|
QString joinMessage;
|
||||||
QStringList gameTypes;
|
QStringList gameTypes;
|
||||||
QMap<int, Server_Game *> games;
|
QMap<int, Server_Game *> games;
|
||||||
|
QList<Server_ProtocolHandler *> userList;
|
||||||
public:
|
public:
|
||||||
mutable QMutex roomMutex;
|
mutable QMutex roomMutex;
|
||||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ SET(servatrice_SOURCES
|
|||||||
src/server_logger.cpp
|
src/server_logger.cpp
|
||||||
src/serversocketinterface.cpp
|
src/serversocketinterface.cpp
|
||||||
src/serversocketthread.cpp
|
src/serversocketthread.cpp
|
||||||
|
src/networkserverinterface.cpp
|
||||||
|
src/networkserverthread.cpp
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
||||||
)
|
)
|
||||||
SET(servatrice_HEADERS
|
SET(servatrice_HEADERS
|
||||||
@@ -16,6 +18,8 @@ SET(servatrice_HEADERS
|
|||||||
src/server_logger.h
|
src/server_logger.h
|
||||||
src/serversocketinterface.h
|
src/serversocketinterface.h
|
||||||
src/serversocketthread.h
|
src/serversocketthread.h
|
||||||
|
src/networkserverinterface.h
|
||||||
|
src/networkserverthread.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(QT_DONTUSE_QTGUI)
|
SET(QT_DONTUSE_QTGUI)
|
||||||
|
|||||||
122
servatrice/src/networkserverinterface.cpp
Normal file
122
servatrice/src/networkserverinterface.cpp
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
#include "networkserverinterface.h"
|
||||||
|
#include <QSslSocket>
|
||||||
|
#include "server_logger.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "server_protocolhandler.h"
|
||||||
|
#include "server_room.h"
|
||||||
|
|
||||||
|
#include "pb/servernetwork_message.pb.h"
|
||||||
|
#include "pb/event_server_complete_list.pb.h"
|
||||||
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
|
NetworkServerInterface::NetworkServerInterface(Servatrice *_server, QSslSocket *_socket)
|
||||||
|
: QObject(), server(_server), socket(_socket), messageInProgress(false)
|
||||||
|
{
|
||||||
|
connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
|
||||||
|
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||||
|
connect(this, SIGNAL(outputBufferChanged()), this, SLOT(flushOutputBuffer()), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
Event_ServerCompleteList event;
|
||||||
|
event.set_server_id(server->getServerId());
|
||||||
|
|
||||||
|
server->serverMutex.lock();
|
||||||
|
QMapIterator<QString, Server_ProtocolHandler *> userIterator(server->getUsers());
|
||||||
|
while (userIterator.hasNext())
|
||||||
|
event.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(true, true));
|
||||||
|
|
||||||
|
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
||||||
|
while (roomIterator.hasNext()) {
|
||||||
|
Server_Room *room = roomIterator.next().value();
|
||||||
|
room->roomMutex.lock();
|
||||||
|
event.add_room_list()->CopyFrom(room->getInfo(true, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerNetworkMessage message;
|
||||||
|
message.set_message_type(ServerNetworkMessage::SESSION_EVENT);
|
||||||
|
SessionEvent *sessionEvent = message.mutable_session_event();
|
||||||
|
sessionEvent->GetReflection()->MutableMessage(sessionEvent, event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(event);
|
||||||
|
transmitMessage(message);
|
||||||
|
|
||||||
|
server->addNetworkServerInterface(this);
|
||||||
|
|
||||||
|
roomIterator.toFront();
|
||||||
|
while (roomIterator.hasNext())
|
||||||
|
roomIterator.next().value()->roomMutex.unlock();
|
||||||
|
server->serverMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkServerInterface::~NetworkServerInterface()
|
||||||
|
{
|
||||||
|
logger->logMessage("[SN] session ended", this);
|
||||||
|
|
||||||
|
flushOutputBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerInterface::flushOutputBuffer()
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&outputBufferMutex);
|
||||||
|
if (outputBuffer.isEmpty())
|
||||||
|
return;
|
||||||
|
server->incTxBytes(outputBuffer.size());
|
||||||
|
socket->write(outputBuffer);
|
||||||
|
socket->flush();
|
||||||
|
outputBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerInterface::readClient()
|
||||||
|
{
|
||||||
|
QByteArray data = socket->readAll();
|
||||||
|
server->incRxBytes(data.size());
|
||||||
|
inputBuffer.append(data);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (!messageInProgress) {
|
||||||
|
if (inputBuffer.size() >= 4) {
|
||||||
|
messageLength = (((quint32) (unsigned char) inputBuffer[0]) << 24)
|
||||||
|
+ (((quint32) (unsigned char) inputBuffer[1]) << 16)
|
||||||
|
+ (((quint32) (unsigned char) inputBuffer[2]) << 8)
|
||||||
|
+ ((quint32) (unsigned char) inputBuffer[3]);
|
||||||
|
inputBuffer.remove(0, 4);
|
||||||
|
messageInProgress = true;
|
||||||
|
} else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (inputBuffer.size() < messageLength)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ServerNetworkMessage newMessage;
|
||||||
|
newMessage.ParseFromArray(inputBuffer.data(), messageLength);
|
||||||
|
inputBuffer.remove(0, messageLength);
|
||||||
|
messageInProgress = false;
|
||||||
|
|
||||||
|
processMessage(newMessage);
|
||||||
|
} while (!inputBuffer.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerInterface::catchSocketError(QAbstractSocket::SocketError socketError)
|
||||||
|
{
|
||||||
|
qDebug() << "Socket error:" << socketError;
|
||||||
|
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerInterface::transmitMessage(const ServerNetworkMessage &item)
|
||||||
|
{
|
||||||
|
QByteArray buf;
|
||||||
|
unsigned int size = item.ByteSize();
|
||||||
|
buf.resize(size + 4);
|
||||||
|
item.SerializeToArray(buf.data() + 4, size);
|
||||||
|
buf.data()[3] = (unsigned char) size;
|
||||||
|
buf.data()[2] = (unsigned char) (size >> 8);
|
||||||
|
buf.data()[1] = (unsigned char) (size >> 16);
|
||||||
|
buf.data()[0] = (unsigned char) (size >> 24);
|
||||||
|
|
||||||
|
QMutexLocker locker(&outputBufferMutex);
|
||||||
|
outputBuffer.append(buf);
|
||||||
|
emit outputBufferChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerInterface::processMessage(const ServerNetworkMessage &item)
|
||||||
|
{
|
||||||
|
}
|
||||||
35
servatrice/src/networkserverinterface.h
Normal file
35
servatrice/src/networkserverinterface.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef NETWORKSERVERINTERFACE_H
|
||||||
|
#define NETWORKSERVERINTERFACE_H
|
||||||
|
|
||||||
|
#include "servatrice.h"
|
||||||
|
|
||||||
|
class Servatrice;
|
||||||
|
class QSslSocket;
|
||||||
|
class ServerNetworkMessage;
|
||||||
|
|
||||||
|
class NetworkServerInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void readClient();
|
||||||
|
void catchSocketError(QAbstractSocket::SocketError socketError);
|
||||||
|
void flushOutputBuffer();
|
||||||
|
signals:
|
||||||
|
void outputBufferChanged();
|
||||||
|
private:
|
||||||
|
QMutex outputBufferMutex;
|
||||||
|
Servatrice *server;
|
||||||
|
QSslSocket *socket;
|
||||||
|
|
||||||
|
QByteArray inputBuffer, outputBuffer;
|
||||||
|
bool messageInProgress;
|
||||||
|
int messageLength;
|
||||||
|
|
||||||
|
void processMessage(const ServerNetworkMessage &item);
|
||||||
|
public:
|
||||||
|
NetworkServerInterface(Servatrice *_server, QSslSocket *_socket);
|
||||||
|
~NetworkServerInterface();
|
||||||
|
|
||||||
|
void transmitMessage(const ServerNetworkMessage &item);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
60
servatrice/src/networkserverthread.cpp
Normal file
60
servatrice/src/networkserverthread.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "networkserverthread.h"
|
||||||
|
#include "networkserverinterface.h"
|
||||||
|
#include "server_logger.h"
|
||||||
|
#include "servatrice.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include <QSslSocket>
|
||||||
|
|
||||||
|
NetworkServerThread::NetworkServerThread(int _socketDescriptor, Servatrice *_server, const QSslCertificate &_cert, const QSslKey &_privateKey, QObject *parent)
|
||||||
|
: QThread(parent), server(_server), socketDescriptor(_socketDescriptor), cert(_cert), privateKey(_privateKey)
|
||||||
|
{
|
||||||
|
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkServerThread::~NetworkServerThread()
|
||||||
|
{
|
||||||
|
quit();
|
||||||
|
wait();
|
||||||
|
|
||||||
|
delete socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkServerThread::run()
|
||||||
|
{
|
||||||
|
socket = new QSslSocket;
|
||||||
|
socket->setSocketDescriptor(socketDescriptor);
|
||||||
|
socket->setLocalCertificate(cert);
|
||||||
|
socket->setPrivateKey(privateKey);
|
||||||
|
|
||||||
|
logger->logMessage(QString("[SN] incoming connection: %1").arg(socket->peerAddress().toString()));
|
||||||
|
|
||||||
|
QList<ServerProperties> serverList = server->getServerList();
|
||||||
|
int listIndex = -1;
|
||||||
|
for (int i = 0; i < serverList.size(); ++i)
|
||||||
|
if (serverList[i].address == socket->peerAddress()) {
|
||||||
|
listIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (listIndex == -1) {
|
||||||
|
logger->logMessage(QString("[SN] address %1 unknown, terminating connection").arg(socket->peerAddress().toString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket->startServerEncryption();
|
||||||
|
if (!socket->waitForEncrypted(5000)) {
|
||||||
|
logger->logMessage(QString("[SN] SSL handshake timeout, terminating connection"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serverList[listIndex].cert == socket->peerCertificate())
|
||||||
|
logger->logMessage(QString("[SN] Peer authenticated as " + serverList[listIndex].hostname));
|
||||||
|
else {
|
||||||
|
logger->logMessage(QString("[SN] Authentication failed, terminating connection"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface = new NetworkServerInterface(server, socket);
|
||||||
|
connect(interface, SIGNAL(destroyed()), this, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
exec();
|
||||||
|
}
|
||||||
28
servatrice/src/networkserverthread.h
Normal file
28
servatrice/src/networkserverthread.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef NETWORKSERVERTHREAD_H
|
||||||
|
#define NETWORKSERVERTHREAD_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QSslCertificate>
|
||||||
|
#include <QSslKey>
|
||||||
|
|
||||||
|
class Servatrice;
|
||||||
|
class NetworkServerInterface;
|
||||||
|
class QSslSocket;
|
||||||
|
|
||||||
|
class NetworkServerThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
Servatrice *server;
|
||||||
|
NetworkServerInterface *interface;
|
||||||
|
QSslCertificate cert;
|
||||||
|
QSslKey privateKey;
|
||||||
|
int socketDescriptor;
|
||||||
|
QSslSocket *socket;
|
||||||
|
public:
|
||||||
|
NetworkServerThread(int _socketDescriptor, Servatrice *_server, const QSslCertificate &_cert, const QSslKey &_privateKey, QObject *parent = 0);
|
||||||
|
~NetworkServerThread();
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -21,11 +21,11 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QSslSocket>
|
|
||||||
#include "servatrice.h"
|
#include "servatrice.h"
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
#include "serversocketinterface.h"
|
#include "serversocketinterface.h"
|
||||||
#include "serversocketthread.h"
|
#include "serversocketthread.h"
|
||||||
|
#include "networkserverthread.h"
|
||||||
#include "server_logger.h"
|
#include "server_logger.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "passwordhasher.h"
|
#include "passwordhasher.h"
|
||||||
@@ -50,13 +50,8 @@ void Servatrice_GameServer::incomingConnection(int socketDescriptor)
|
|||||||
|
|
||||||
void Servatrice_NetworkServer::incomingConnection(int socketDescriptor)
|
void Servatrice_NetworkServer::incomingConnection(int socketDescriptor)
|
||||||
{
|
{
|
||||||
QSslSocket *socket = new QSslSocket;
|
NetworkServerThread *thread = new NetworkServerThread(socketDescriptor, server, cert, privateKey);
|
||||||
socket->setLocalCertificate(cert);
|
thread->start();
|
||||||
socket->setPrivateKey(privateKey);
|
|
||||||
socket->setSocketDescriptor(socketDescriptor);
|
|
||||||
socket->startServerEncryption();
|
|
||||||
// SocketInterface *ssi = new ServerSocketInterface(server, socket);
|
|
||||||
// logger->logMessage(QString("Incoming server network connection: %1").arg(socket->peerAddress().toString()), ssi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
||||||
@@ -100,11 +95,13 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
|||||||
if (databaseType != DatabaseNone)
|
if (databaseType != DatabaseNone)
|
||||||
openDatabase();
|
openDatabase();
|
||||||
|
|
||||||
|
updateServerList();
|
||||||
|
clearSessionTables();
|
||||||
|
|
||||||
try { if (settings->value("servernetwork/active", 0).toInt()) {
|
try { if (settings->value("servernetwork/active", 0).toInt()) {
|
||||||
qDebug() << "Connecting to server network.";
|
qDebug() << "Connecting to server network.";
|
||||||
const QString certFileName = settings->value("servernetwork/ssl_cert").toString();
|
const QString certFileName = settings->value("servernetwork/ssl_cert").toString();
|
||||||
const QString keyFileName = settings->value("servernetwork/ssl_key").toString();
|
const QString keyFileName = settings->value("servernetwork/ssl_key").toString();
|
||||||
const QString passphrase = settings->value("servernetwork/ssl_passphrase").toString();
|
|
||||||
qDebug() << "Loading certificate...";
|
qDebug() << "Loading certificate...";
|
||||||
QFile certFile(certFileName);
|
QFile certFile(certFileName);
|
||||||
if (!certFile.open(QIODevice::ReadOnly))
|
if (!certFile.open(QIODevice::ReadOnly))
|
||||||
@@ -116,7 +113,7 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent)
|
|||||||
QFile keyFile(keyFileName);
|
QFile keyFile(keyFileName);
|
||||||
if (!keyFile.open(QIODevice::ReadOnly))
|
if (!keyFile.open(QIODevice::ReadOnly))
|
||||||
throw QString("Error opening private key file: %1").arg(keyFileName);
|
throw QString("Error opening private key file: %1").arg(keyFileName);
|
||||||
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, passphrase.toAscii());
|
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||||
if (key.isNull())
|
if (key.isNull())
|
||||||
throw QString("Invalid private key.");
|
throw QString("Invalid private key.");
|
||||||
|
|
||||||
@@ -235,6 +232,34 @@ bool Servatrice::execSqlQuery(QSqlQuery &query)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Servatrice::updateServerList()
|
||||||
|
{
|
||||||
|
qDebug() << "Updating server list...";
|
||||||
|
|
||||||
|
serverListMutex.lock();
|
||||||
|
serverList.clear();
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
|
||||||
|
execSqlQuery(query);
|
||||||
|
while (query.next()) {
|
||||||
|
ServerProperties prop(query.value(0).toInt(), QSslCertificate(query.value(1).toString().toAscii()), query.value(2).toString(), QHostAddress(query.value(3).toString()), query.value(4).toInt(), query.value(5).toInt());
|
||||||
|
serverList.append(prop);
|
||||||
|
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
serverListMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ServerProperties> Servatrice::getServerList() const
|
||||||
|
{
|
||||||
|
serverListMutex.lock();
|
||||||
|
QList<ServerProperties> result = serverList;
|
||||||
|
serverListMutex.unlock();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
AuthenticationResult Servatrice::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr)
|
AuthenticationResult Servatrice::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&dbMutex);
|
QMutexLocker locker(&dbMutex);
|
||||||
@@ -461,6 +486,37 @@ QList<ServerSocketInterface *> Servatrice::getUsersWithAddressAsList(const QHost
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Servatrice::clearSessionTables()
|
||||||
|
{
|
||||||
|
lockSessionTables();
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("update " + dbPrefix + "_sessions set end_time=now() where end_time is null and id_server = :id_server");
|
||||||
|
query.bindValue(":id_server", serverId);
|
||||||
|
query.exec();
|
||||||
|
unlockSessionTables();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Servatrice::lockSessionTables()
|
||||||
|
{
|
||||||
|
QSqlQuery("lock tables " + dbPrefix + "_sessions write, " + dbPrefix + "_users read").exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Servatrice::unlockSessionTables()
|
||||||
|
{
|
||||||
|
QSqlQuery("unlock tables").exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Servatrice::userSessionExists(const QString &userName)
|
||||||
|
{
|
||||||
|
// Call only after lockSessionTables().
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("select 1 from " + dbPrefix + "_sessions where user_name = :user_name and end_time is null");
|
||||||
|
query.bindValue(":user_name", userName);
|
||||||
|
query.exec();
|
||||||
|
return query.next();
|
||||||
|
}
|
||||||
|
|
||||||
int Servatrice::startSession(const QString &userName, const QString &address)
|
int Servatrice::startSession(const QString &userName, const QString &address)
|
||||||
{
|
{
|
||||||
if (authenticationMethod == AuthenticationNone)
|
if (authenticationMethod == AuthenticationNone)
|
||||||
@@ -489,9 +545,11 @@ void Servatrice::endSession(int sessionId)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
query.exec("lock tables " + dbPrefix + "_sessions read");
|
||||||
query.prepare("update " + dbPrefix + "_sessions set end_time=NOW() where id = :id_session");
|
query.prepare("update " + dbPrefix + "_sessions set end_time=NOW() where id = :id_session");
|
||||||
query.bindValue(":id_session", sessionId);
|
query.bindValue(":id_session", sessionId);
|
||||||
execSqlQuery(query);
|
execSqlQuery(query);
|
||||||
|
query.exec("unlock tables");
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, ServerInfo_User> Servatrice::getBuddyList(const QString &name)
|
QMap<QString, ServerInfo_User> Servatrice::getBuddyList(const QString &name)
|
||||||
@@ -751,3 +809,14 @@ void Servatrice::shutdownTimeout()
|
|||||||
if (!shutdownMinutes)
|
if (!shutdownMinutes)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Servatrice::addNetworkServerInterface(NetworkServerInterface *interface)
|
||||||
|
{
|
||||||
|
networkServerInterfaces.append(interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Servatrice::removeNetworkServerInterface(NetworkServerInterface *interface)
|
||||||
|
{
|
||||||
|
// XXX we probably need to delete everything that belonged to it...
|
||||||
|
networkServerInterfaces.removeAt(networkServerInterfaces.indexOf(interface));
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QSslCertificate>
|
#include <QSslCertificate>
|
||||||
#include <QSslKey>
|
#include <QSslKey>
|
||||||
|
#include <QHostAddress>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
class QSqlDatabase;
|
class QSqlDatabase;
|
||||||
@@ -34,6 +35,7 @@ class QTimer;
|
|||||||
class GameReplay;
|
class GameReplay;
|
||||||
class Servatrice;
|
class Servatrice;
|
||||||
class ServerSocketInterface;
|
class ServerSocketInterface;
|
||||||
|
class NetworkServerInterface;
|
||||||
|
|
||||||
class Servatrice_GameServer : public QTcpServer {
|
class Servatrice_GameServer : public QTcpServer {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -60,6 +62,19 @@ protected:
|
|||||||
void incomingConnection(int socketDescriptor);
|
void incomingConnection(int socketDescriptor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ServerProperties {
|
||||||
|
public:
|
||||||
|
int id;
|
||||||
|
QSslCertificate cert;
|
||||||
|
QString hostname;
|
||||||
|
QHostAddress address;
|
||||||
|
int gamePort;
|
||||||
|
int controlPort;
|
||||||
|
|
||||||
|
ServerProperties(int _id, const QSslCertificate &_cert, const QString &_hostname, const QHostAddress &_address, int _gamePort, int _controlPort)
|
||||||
|
: id(_id), cert(_cert), hostname(_hostname), address(_address), gamePort(_gamePort), controlPort(_controlPort) { }
|
||||||
|
};
|
||||||
|
|
||||||
class Servatrice : public Server
|
class Servatrice : public Server
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -85,6 +100,7 @@ public:
|
|||||||
int getMaxGamesPerUser() const { return maxGamesPerUser; }
|
int getMaxGamesPerUser() const { return maxGamesPerUser; }
|
||||||
bool getThreaded() const { return threaded; }
|
bool getThreaded() const { return threaded; }
|
||||||
QString getDbPrefix() const { return dbPrefix; }
|
QString getDbPrefix() const { return dbPrefix; }
|
||||||
|
int getServerId() const { return serverId; }
|
||||||
void updateLoginMessage();
|
void updateLoginMessage();
|
||||||
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
ServerInfo_User getUserData(const QString &name, bool withId = false);
|
||||||
int getUsersWithAddress(const QHostAddress &address) const;
|
int getUsersWithAddress(const QHostAddress &address) const;
|
||||||
@@ -98,11 +114,21 @@ public:
|
|||||||
void incRxBytes(quint64 num);
|
void incRxBytes(quint64 num);
|
||||||
int getUserIdInDB(const QString &name);
|
int getUserIdInDB(const QString &name);
|
||||||
void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays);
|
void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays);
|
||||||
|
|
||||||
|
void addNetworkServerInterface(NetworkServerInterface *interface);
|
||||||
|
void removeNetworkServerInterface(NetworkServerInterface *interface);
|
||||||
|
|
||||||
|
QList<ServerProperties> getServerList() const;
|
||||||
protected:
|
protected:
|
||||||
int startSession(const QString &userName, const QString &address);
|
int startSession(const QString &userName, const QString &address);
|
||||||
void endSession(int sessionId);
|
void endSession(int sessionId);
|
||||||
bool userExists(const QString &user);
|
bool userExists(const QString &user);
|
||||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr);
|
AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr);
|
||||||
|
|
||||||
|
void clearSessionTables();
|
||||||
|
void lockSessionTables();
|
||||||
|
void unlockSessionTables();
|
||||||
|
bool userSessionExists(const QString &userName);
|
||||||
private:
|
private:
|
||||||
enum AuthenticationMethod { AuthenticationNone, AuthenticationSql };
|
enum AuthenticationMethod { AuthenticationNone, AuthenticationSql };
|
||||||
enum DatabaseType { DatabaseNone, DatabaseMySql };
|
enum DatabaseType { DatabaseNone, DatabaseMySql };
|
||||||
@@ -127,6 +153,12 @@ private:
|
|||||||
QString shutdownReason;
|
QString shutdownReason;
|
||||||
int shutdownMinutes;
|
int shutdownMinutes;
|
||||||
QTimer *shutdownTimer;
|
QTimer *shutdownTimer;
|
||||||
|
|
||||||
|
mutable QMutex serverListMutex;
|
||||||
|
QList<ServerProperties> serverList;
|
||||||
|
void updateServerList();
|
||||||
|
|
||||||
|
QList<NetworkServerInterface *> networkServerInterfaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,16 +31,16 @@ ServerLogger::~ServerLogger()
|
|||||||
flushBuffer();
|
flushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLogger::logMessage(QString message, Server_ProtocolHandler *ssi)
|
void ServerLogger::logMessage(QString message, void *caller)
|
||||||
{
|
{
|
||||||
if (!logFile)
|
if (!logFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bufferMutex.lock();
|
bufferMutex.lock();
|
||||||
QString ssiString;
|
QString callerString;
|
||||||
if (ssi)
|
if (caller)
|
||||||
ssiString = QString::number((qulonglong) ssi, 16) + " ";
|
callerString = QString::number((qulonglong) caller, 16) + " ";
|
||||||
buffer.append(QDateTime::currentDateTime().toString() + " " + QString::number((qulonglong) QThread::currentThread(), 16) + " " + ssiString + message);
|
buffer.append(QDateTime::currentDateTime().toString() + " " + QString::number((qulonglong) QThread::currentThread(), 16) + " " + callerString + message);
|
||||||
bufferMutex.unlock();
|
bufferMutex.unlock();
|
||||||
|
|
||||||
emit sigFlushBuffer();
|
emit sigFlushBuffer();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
~ServerLogger();
|
~ServerLogger();
|
||||||
static void hupSignalHandler(int unused);
|
static void hupSignalHandler(int unused);
|
||||||
public slots:
|
public slots:
|
||||||
void logMessage(QString message, Server_ProtocolHandler *ssi = 0);
|
void logMessage(QString message, void *caller = 0);
|
||||||
private slots:
|
private slots:
|
||||||
void handleSigHup();
|
void handleSigHup();
|
||||||
void flushBuffer();
|
void flushBuffer();
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_s
|
|||||||
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
connect(socket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||||
connect(this, SIGNAL(outputBufferChanged()), this, SLOT(flushOutputBuffer()), Qt::QueuedConnection);
|
connect(this, SIGNAL(outputBufferChanged()), this, SLOT(flushOutputBuffer()), Qt::QueuedConnection);
|
||||||
connect(this, SIGNAL(logDebugMessage(const QString &, Server_ProtocolHandler *)), logger, SLOT(logMessage(QString, Server_ProtocolHandler *)));
|
|
||||||
|
|
||||||
Event_ServerIdentification identEvent;
|
Event_ServerIdentification identEvent;
|
||||||
identEvent.set_server_name(servatrice->getServerName().toStdString());
|
identEvent.set_server_name(servatrice->getServerName().toStdString());
|
||||||
|
|||||||
Reference in New Issue
Block a user