minor cleanups, server-side deck storage code is working again
This commit is contained in:
parent
eabe3511cb
commit
d4aaf9fff5
19 changed files with 85 additions and 70 deletions
|
@ -90,10 +90,10 @@ HEADERS += src/abstractcounter.h \
|
|||
../common/color.h \
|
||||
../common/serializable_item.h \
|
||||
../common/decklist.h \
|
||||
../common/protocol.h \
|
||||
../common/rng_abstract.h \
|
||||
../common/rng_sfmt.h \
|
||||
../common/server.h \
|
||||
../common/server_response_containers.h \
|
||||
../common/server_arrow.h \
|
||||
../common/server_card.h \
|
||||
../common/server_cardzone.h \
|
||||
|
@ -174,11 +174,11 @@ SOURCES += src/abstractcounter.cpp \
|
|||
../common/get_pb_extension.cpp \
|
||||
../common/serializable_item.cpp \
|
||||
../common/decklist.cpp \
|
||||
../common/protocol.cpp \
|
||||
../common/rng_abstract.cpp \
|
||||
../common/rng_sfmt.cpp \
|
||||
../common/sfmt/SFMT.c \
|
||||
../common/server.cpp \
|
||||
../common/server_response_containers.cpp \
|
||||
../common/server_card.cpp \
|
||||
../common/server_cardzone.cpp \
|
||||
../common/server_room.cpp \
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "abstractclient.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include "pending_command.h"
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/server_message.pb.h"
|
||||
#include "pb/event_server_identification.pb.h"
|
||||
#include "pb/event_server_message.pb.h"
|
||||
#include "pb/event_server_shutdown.pb.h"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "localclient.h"
|
||||
#include "localserverinterface.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include "pb/session_commands.pb.h"
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include <QTimer>
|
||||
#include "remoteclient.h"
|
||||
#include "protocol.h"
|
||||
|
||||
#include "pending_command.h"
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/session_commands.pb.h"
|
||||
#include "pb/response_login.pb.h"
|
||||
#include "pb/server_message.pb.h"
|
||||
#include "pb/event_server_identification.pb.h"
|
||||
|
||||
static const unsigned int protocolVersion = 13;
|
||||
|
||||
RemoteClient::RemoteClient(QObject *parent)
|
||||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), messageLength(0)
|
||||
|
@ -41,8 +44,13 @@ void RemoteClient::slotConnected()
|
|||
setStatus(StatusAwaitingWelcome);
|
||||
}
|
||||
|
||||
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification & /*event*/)
|
||||
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
|
||||
{
|
||||
if (event.protocol_version() != protocolVersion) {
|
||||
emit protocolVersionMismatch(protocolVersion, event.protocol_version());
|
||||
setStatus(StatusDisconnected);
|
||||
return;
|
||||
}
|
||||
setStatus(StatusLoggingIn);
|
||||
|
||||
Command_Login cmdLogin;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <QInputDialog>
|
||||
#include "tab_server.h"
|
||||
#include "abstractclient.h"
|
||||
#include "protocol.h"
|
||||
#include "userlist.h"
|
||||
#include "userinfobox.h"
|
||||
#include <QDebug>
|
||||
|
|
|
@ -31,8 +31,8 @@ TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_clien
|
|||
connect(client, SIGNAL(userLeftEventReceived(const Event_UserLeft &)), this, SLOT(processUserLeftEvent(const Event_UserLeft &)));
|
||||
connect(client, SIGNAL(buddyListReceived(const QList<ServerInfo_User> &)), this, SLOT(buddyListReceived(const QList<ServerInfo_User> &)));
|
||||
connect(client, SIGNAL(ignoreListReceived(const QList<ServerInfo_User> &)), this, SLOT(ignoreListReceived(const QList<ServerInfo_User> &)));
|
||||
connect(client, SIGNAL(addToListEventReceived(const Event_AddToList *)), this, SLOT(processAddToListEvent(const Event_AddToList &)));
|
||||
connect(client, SIGNAL(removeFromListEventReceived(const Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(const Event_RemoveFromList &)));
|
||||
connect(client, SIGNAL(addToListEventReceived(const Event_AddToList &)), this, SLOT(processAddToListEvent(const Event_AddToList &)));
|
||||
connect(client, SIGNAL(removeFromListEventReceived(const Event_RemoveFromList &)), this, SLOT(processRemoveFromListEvent(const Event_RemoveFromList &)));
|
||||
|
||||
PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers());
|
||||
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(processListUsersResponse(const Response &)));
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
[Dolphin]
|
||||
Timestamp=2011,12,31,17,13,2
|
||||
Timestamp=2012,1,1,23,11,32
|
||||
Version=2
|
||||
|
||||
[Settings]
|
||||
ShowDotFiles=true
|
||||
|
|
|
@ -15,7 +15,7 @@ message ServerInfo_User {
|
|||
optional uint32 user_level = 2;
|
||||
optional string address = 3;
|
||||
optional string real_name = 4;
|
||||
optional Gender gender = 5;
|
||||
optional Gender gender = 5 [default = GenderUnknown];
|
||||
optional string country = 6;
|
||||
optional bytes avatar_bmp = 7;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "pb/event_set_active_phase.pb.h"
|
||||
#include "pb/serverinfo_playerping.pb.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include "protocol.h"
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include "server_player.h"
|
||||
#include "protocol.h"
|
||||
#include "server_response_containers.h"
|
||||
#include "pb/response.pb.h"
|
||||
#include "pb/serverinfo_player.pb.h"
|
||||
#include "pb/serverinfo_game.pb.h"
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "server_cardzone.h"
|
||||
#include "server_game.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "protocol.h"
|
||||
#include "decklist.h"
|
||||
#include "pb/response.pb.h"
|
||||
#include "pb/command_move_card.pb.h"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <QDebug>
|
||||
#include "rng_abstract.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "protocol.h"
|
||||
#include "server_room.h"
|
||||
#include "server_card.h"
|
||||
#include "server_arrow.h"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include "server.h"
|
||||
#include "protocol.h"
|
||||
#include "pb/response.pb.h"
|
||||
#include "pb/server_message.pb.h"
|
||||
|
||||
|
@ -13,6 +12,7 @@ class Server_Card;
|
|||
class ServerInfo_User;
|
||||
class Server_Room;
|
||||
class QTimer;
|
||||
class DeckList;
|
||||
|
||||
class Message;
|
||||
class ServerMessage;
|
||||
|
@ -21,6 +21,8 @@ class Response;
|
|||
class SessionEvent;
|
||||
class GameEventContainer;
|
||||
class RoomEvent;
|
||||
class GameEventStorage;
|
||||
class ResponseContainer;
|
||||
|
||||
class CommandContainer;
|
||||
class Command_Ping;
|
||||
|
|
|
@ -16,8 +16,6 @@ class DeckList;
|
|||
class GameEvent;
|
||||
class GameEventContainer;
|
||||
class GameEventContext;
|
||||
#include <QDebug>
|
||||
static const int protocolVersion = 13;
|
||||
|
||||
class GameEventStorageItem {
|
||||
public:
|
|
@ -24,10 +24,10 @@ HEADERS += src/main.h \
|
|||
../common/color.h \
|
||||
../common/serializable_item.h \
|
||||
../common/decklist.h \
|
||||
../common/protocol.h \
|
||||
../common/rng_abstract.h \
|
||||
../common/rng_sfmt.h \
|
||||
../common/server.h \
|
||||
../common/server_response_containers.h \
|
||||
../common/server_arrow.h \
|
||||
../common/server_card.h \
|
||||
../common/server_cardzone.h \
|
||||
|
@ -47,11 +47,11 @@ SOURCES += src/main.cpp \
|
|||
src/passwordhasher.cpp \
|
||||
../common/serializable_item.cpp \
|
||||
../common/decklist.cpp \
|
||||
../common/protocol.cpp \
|
||||
../common/rng_abstract.cpp \
|
||||
../common/rng_sfmt.cpp \
|
||||
../common/sfmt/SFMT.c \
|
||||
../common/server.cpp \
|
||||
../common/server_response_containers.cpp \
|
||||
../common/server_card.cpp \
|
||||
../common/server_cardzone.cpp \
|
||||
../common/server_room.cpp \
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "server_room.h"
|
||||
#include "serversocketinterface.h"
|
||||
#include "serversocketthread.h"
|
||||
#include "protocol.h"
|
||||
#include "server_logger.h"
|
||||
#include "main.h"
|
||||
#include "passwordhasher.h"
|
||||
|
@ -298,36 +297,38 @@ bool Servatrice::isInIgnoreList(const QString &whoseList, const QString &who)
|
|||
|
||||
ServerInfo_User Servatrice::evalUserQueryResult(const QSqlQuery &query, bool complete)
|
||||
{
|
||||
QString name = query.value(0).toString();
|
||||
int is_admin = query.value(1).toInt();
|
||||
QString realName = query.value(2).toString();
|
||||
QString genderStr = query.value(3).toString();
|
||||
QString country = query.value(4).toString();
|
||||
QByteArray avatarBmp;
|
||||
if (complete)
|
||||
avatarBmp = query.value(5).toByteArray();
|
||||
ServerInfo_User result;
|
||||
|
||||
ServerInfo_User::Gender gender;
|
||||
result.set_name(query.value(0).toString().toStdString());
|
||||
|
||||
const QString country = query.value(4).toString();
|
||||
if (!country.isEmpty())
|
||||
result.set_country(country.toStdString());
|
||||
|
||||
if (complete) {
|
||||
const QByteArray avatarBmp = query.value(5).toByteArray();
|
||||
if (avatarBmp.size())
|
||||
result.set_avatar_bmp(avatarBmp.data(), avatarBmp.size());
|
||||
}
|
||||
|
||||
const QString genderStr = query.value(3).toString();
|
||||
if (genderStr == "m")
|
||||
gender = ServerInfo_User::Male;
|
||||
result.set_gender(ServerInfo_User::Male);
|
||||
else if (genderStr == "f")
|
||||
gender = ServerInfo_User::Female;
|
||||
else
|
||||
gender = ServerInfo_User::GenderUnknown;
|
||||
result.set_gender(ServerInfo_User::Female);
|
||||
|
||||
const int is_admin = query.value(1).toInt();
|
||||
int userLevel = ServerInfo_User::IsUser | ServerInfo_User::IsRegistered;
|
||||
if (is_admin == 1)
|
||||
userLevel |= ServerInfo_User::IsAdmin | ServerInfo_User::IsModerator;
|
||||
else if (is_admin == 2)
|
||||
userLevel |= ServerInfo_User::IsModerator;
|
||||
|
||||
ServerInfo_User result;
|
||||
result.set_name(name.toStdString());
|
||||
result.set_user_level(userLevel);
|
||||
result.set_real_name(realName.toStdString());
|
||||
result.set_gender(gender);
|
||||
result.set_country(country.toStdString());
|
||||
result.set_avatar_bmp(avatarBmp.data(), avatarBmp.size());
|
||||
|
||||
const QString realName = query.value(2).toString();
|
||||
if (!realName.isEmpty())
|
||||
result.set_real_name(realName.toStdString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
#include <QDebug>
|
||||
#include "serversocketinterface.h"
|
||||
#include "servatrice.h"
|
||||
#include "protocol.h"
|
||||
#include "decklist.h"
|
||||
#include "server_player.h"
|
||||
#include "main.h"
|
||||
#include "server_logger.h"
|
||||
|
||||
#include "server_response_containers.h"
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/command_deck_upload.pb.h"
|
||||
#include "pb/command_deck_download.pb.h"
|
||||
|
@ -40,12 +39,17 @@
|
|||
#include "pb/event_server_identification.pb.h"
|
||||
#include "pb/event_add_to_list.pb.h"
|
||||
#include "pb/event_remove_from_list.pb.h"
|
||||
#include "pb/response_deck_list.pb.h"
|
||||
#include "pb/response_deck_download.pb.h"
|
||||
#include "pb/response_deck_upload.pb.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "pb/serverinfo_deckstorage.pb.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
static const int protocolVersion = 13;
|
||||
|
||||
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
|
||||
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), messageInProgress(false)
|
||||
{
|
||||
|
@ -260,38 +264,44 @@ int ServerSocketInterface::getDeckPathId(const QString &path)
|
|||
{
|
||||
return getDeckPathId(0, path.split("/"));
|
||||
}
|
||||
/*
|
||||
bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
||||
|
||||
bool ServerSocketInterface::deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder)
|
||||
{
|
||||
QMutexLocker locker(&servatrice->dbMutex);
|
||||
QSqlQuery query;
|
||||
query.prepare("select id, name from " + servatrice->getDbPrefix() + "_decklist_folders where id_parent = :id_parent and user = :user");
|
||||
query.bindValue(":id_parent", folder->getId());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":id_parent", folderId);
|
||||
query.bindValue(":user", QString::fromStdString(userInfo->name()));
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return false;
|
||||
|
||||
while (query.next()) {
|
||||
DeckList_Directory *newFolder = new DeckList_Directory(query.value(1).toString(), query.value(0).toInt());
|
||||
folder->appendItem(newFolder);
|
||||
if (!deckListHelper(newFolder))
|
||||
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
|
||||
newItem->set_id(query.value(0).toInt());
|
||||
newItem->set_name(query.value(1).toString().toStdString());
|
||||
|
||||
if (!deckListHelper(newItem->id(), newItem->mutable_folder()))
|
||||
return false;
|
||||
}
|
||||
|
||||
query.prepare("select id, name, upload_time from " + servatrice->getDbPrefix() + "_decklist_files where id_folder = :id_folder and user = :user");
|
||||
query.bindValue(":id_folder", folder->getId());
|
||||
query.bindValue(":user", userInfo->getName());
|
||||
query.bindValue(":id_folder", folderId);
|
||||
query.bindValue(":user", QString::fromStdString(userInfo->name()));
|
||||
if (!servatrice->execSqlQuery(query))
|
||||
return false;
|
||||
|
||||
while (query.next()) {
|
||||
DeckList_File *newFile = new DeckList_File(query.value(1).toString(), query.value(0).toInt(), query.value(2).toDateTime());
|
||||
folder->appendItem(newFile);
|
||||
ServerInfo_DeckStorage_TreeItem *newItem = folder->add_items();
|
||||
newItem->set_id(query.value(0).toInt());
|
||||
newItem->set_name(query.value(1).toString().toStdString());
|
||||
|
||||
ServerInfo_DeckStorage_File *newFile = newItem->mutable_file();
|
||||
newFile->set_creation_time(query.value(2).toDateTime().toMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
// CHECK AUTHENTICATION!
|
||||
// Also check for every function that data belonging to other users cannot be accessed.
|
||||
|
||||
|
@ -302,17 +312,14 @@ Response::ResponseCode ServerSocketInterface::cmdDeckList(const Command_DeckList
|
|||
|
||||
servatrice->checkSql();
|
||||
|
||||
/* DeckList_Directory *root = new DeckList_Directory(QString());
|
||||
QSqlQuery query;
|
||||
if (!deckListHelper(root))
|
||||
Response_DeckList *re = new Response_DeckList;
|
||||
ServerInfo_DeckStorage_Folder *root = re->mutable_root();
|
||||
|
||||
if (!deckListHelper(0, root))
|
||||
return Response::RespContextError;
|
||||
|
||||
ProtocolResponse *resp = new Response_DeckList(-1, RespOk, root);
|
||||
if (getCompressionSupport())
|
||||
resp->setCompressed(true);
|
||||
bla->setResponse(resp);
|
||||
*/
|
||||
return Response::RespNothing;
|
||||
rc.setResponseExtension(re);
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
Response::ResponseCode ServerSocketInterface::cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer & /*rc*/)
|
||||
|
@ -426,8 +433,14 @@ Response::ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUp
|
|||
query.bindValue(":content", deckStr);
|
||||
servatrice->execSqlQuery(query);
|
||||
|
||||
// bla->setResponse(new Response_DeckUpload(-1, RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
|
||||
return Response::RespNothing;
|
||||
Response_DeckUpload *re = new Response_DeckUpload;
|
||||
ServerInfo_DeckStorage_TreeItem *fileInfo = re->mutable_new_file();
|
||||
fileInfo->set_id(query.lastInsertId().toInt());
|
||||
fileInfo->set_name(deckName.toStdString());
|
||||
fileInfo->mutable_file()->set_creation_time(QDateTime::currentMSecsSinceEpoch());
|
||||
rc.setResponseExtension(re);
|
||||
|
||||
return Response::RespOk;
|
||||
}
|
||||
|
||||
DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
class QTcpSocket;
|
||||
class Servatrice;
|
||||
class DeckList;
|
||||
class ServerInfo_DeckStorage_Folder;
|
||||
|
||||
class ServerSocketInterface : public Server_ProtocolHandler
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ private:
|
|||
Response::ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, ResponseContainer &rc);
|
||||
int getDeckPathId(int basePathId, QStringList path);
|
||||
int getDeckPathId(const QString &path);
|
||||
// bool deckListHelper(DeckList_Directory *folder);
|
||||
bool deckListHelper(int folderId, ServerInfo_DeckStorage_Folder *folder);
|
||||
Response::ResponseCode cmdDeckList(const Command_DeckList &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc);
|
||||
void deckDelDirHelper(int basePathId);
|
||||
|
|
Loading…
Reference in a new issue