This commit is contained in:
Max-Wilhelm Bruker 2011-12-30 02:03:26 +01:00
parent ca9122b9fb
commit 10018280e5
20 changed files with 970 additions and 1178 deletions

View file

@ -0,0 +1,9 @@
import "game_event.proto";
import "serverinfo_arrow.proto";
message Event_CreateArrow {
extend GameEvent {
optional Event_CreateArrow ext = 2000;
}
optional ServerInfo_Arrow arrow_info = 1;
}

View file

@ -1,9 +0,0 @@
import "game_event.proto";
import "serverinfo_arrow.proto";
message Event_CreateArrows {
extend GameEvent {
optional Event_CreateArrows ext = 2000;
}
repeated ServerInfo_Arrow arrow_list = 1;
}

View file

@ -0,0 +1,9 @@
import "game_event.proto";
import "serverinfo_counter.proto";
message Event_CreateCounter {
extend GameEvent {
optional Event_CreateCounter ext = 2002;
}
optional ServerInfo_Counter counter_info = 1;
}

View file

@ -1,9 +0,0 @@
import "game_event.proto";
import "serverinfo_counter.proto";
message Event_CreateCounters {
extend GameEvent {
optional Event_CreateCounters ext = 2002;
}
repeated ServerInfo_Counter counter_list = 1;
}

View file

@ -10,9 +10,9 @@ message GameEvent {
PLAYER_PROPERTIES_CHANGED = 1007;
PING = 1008;
GAME_SAY = 1009;
CREATE_ARROWS = 2000;
CREATE_ARROW = 2000;
DELETE_ARROW = 2001;
CREATE_COUNTERS = 2002;
CREATE_COUNTER = 2002;
SET_COUNTER = 2003;
DEL_COUNTER = 2004;
DRAW_CARDS = 2005;

View file

@ -0,0 +1,8 @@
import "response.proto";
message Response_DeckDownload {
extend Response {
optional Response_DeckDownload ext = 1007;
}
optional string deck = 1;
}

View file

@ -10,8 +10,10 @@ message ServerMessage {
GAME_EVENT_CONTAINER = 2;
ROOM_EVENT = 3;
}
optional Response response = 1;
optional SessionEvent session_event = 2;
optional GameEventContainer game_event_container = 3;
optional RoomEvent room_event = 4;
optional MessageType message_type = 1;
optional Response response = 2;
optional SessionEvent session_event = 3;
optional GameEventContainer game_event_container = 4;
optional RoomEvent room_event = 5;
}

View file

@ -1,10 +1,10 @@
import "serverinfo_cardcounter.proto";
message ServerInfo_Card {
optional sint32 id = 1;
optional sint32 id = 1 [default = -1];
optional string name = 2;
optional sint32 x = 3;
optional sint32 y = 4;
optional sint32 x = 3 [default = -1];
optional sint32 y = 4 [default = -1];
optional bool face_down = 5;
optional bool tapped = 6;
optional bool attacking = 7;
@ -14,7 +14,7 @@ message ServerInfo_Card {
optional bool destroy_on_zone_change = 11;
optional bool doesnt_untap = 12;
repeated ServerInfo_CardCounter counter_list = 13;
optional sint32 attach_player_id = 14;
optional sint32 attach_player_id = 14 [default = -1];
optional string attach_zone = 15;
optional sint32 attach_card_id = 16;
optional sint32 attach_card_id = 16 [default = -1];
}

View file

@ -2,6 +2,15 @@ import "serverinfo_card.proto";
message ServerInfo_Zone {
enum ZoneType {
// PrivateZone: Contents of the zone are always visible to the owner,
// but not to anyone else.
// PublicZone: Contents of the zone are always visible to anyone.
// HiddenZone: Contents of the zone are never visible to anyone.
// However, the owner of the zone can issue a dump_zone command,
// setting beingLookedAt to true.
// Cards in a zone with the type HiddenZone are referenced by their
// list index, whereas cards in any other zone are referenced by their ids.
PrivateZone = 0;
PublicZone = 1;
HiddenZone = 2;

View file

@ -6,7 +6,11 @@
#include <QHash>
#include <QObject>
#include <QVariant>
#include "protocol_datastructures.h"
#include "serializable_item.h"
#include <QPair>
#include <google/protobuf/message.h>
#include "pb/server_message.pb.h"
class QXmlStreamReader;
class QXmlStreamWriter;
@ -22,11 +26,9 @@ class MoveCardToZone;
class ProtocolItem : public SerializableItem_Map {
Q_OBJECT
private:
static void initializeHashAuto();
bool receiverMayDelete;
public:
static const int protocolVersion = 13;
static void initializeHash();
virtual int getItemId() const = 0;
bool getReceiverMayDelete() const { return receiverMayDelete; }
void setReceiverMayDelete(bool _receiverMayDelete) { receiverMayDelete = _receiverMayDelete; }
@ -38,32 +40,49 @@ public:
// --- COMMANDS ---
// ----------------
class BlaContainer : public ProtocolItem {
Q_OBJECT
class GameEventStorage {
private:
ProtocolResponse *resp;
QList<ProtocolItem *> itemQueue;
GameEventContext *gameEventContext;
::google::protobuf::Message *gameEventContext;
GameEventContainer *gameEventQueuePublic;
GameEventContainer *gameEventQueueOmniscient;
GameEventContainer *gameEventQueuePrivate;
int privatePlayerId;
public:
BlaContainer();
int getItemId() const { return 102332456; }
GameEventStorage();
~GameEventStorage();
void setGameEventContext(::google::protobuf::Message *_gameEventContext) { gameEventContext = _gameEventContext; }
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
ProtocolResponse *getResponse() const { return resp; }
void setResponse(ProtocolResponse *_resp);
const QList<ProtocolItem *> &getItemQueue() const { return itemQueue; }
void enqueueItem(ProtocolItem *item) { itemQueue.append(item); }
GameEventContainer *getGameEventQueuePublic() const { return gameEventQueuePublic; }
void enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context = 0);
void enqueueGameEventPublic(const ::google::protobuf::Message &event, int playerId);
GameEventContainer *getGameEventQueueOmniscient() const { return gameEventQueueOmniscient; }
void enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context = 0);
void enqueueGameEventOmniscient(const ::google::protobuf::Message &event, int playerId);
GameEventContainer *getGameEventQueuePrivate() const { return gameEventQueuePrivate; }
void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0);
void enqueueGameEventPrivate(const ::google::protobuf::Message &event, int playerId);
// XXX - DRAN DENKEN, dass privatePlayerId gesetzt wird
int getPrivatePlayerId() const { return privatePlayerId; }
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId);
};
class ResponseContainer {
private:
::google::protobuf::Message *responseExtension;
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > preResponseQueue, postResponseQueue;
public:
ResponseContainer() : responseExtension(0) { }
~ResponseContainer() { /* XXX responseExtension und Inhalt beider Listen löschen */ }
void setResponseExtension(::google::protobuf::Message *_responseExtension) { responseExtension = _responseExtension; }
::google::protobuf::Message *getResponseExtension() const { return responseExtension; }
void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { preResponseQueue.append(qMakePair(type, item)); }
void enqueuePostResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { postResponseQueue.append(qMakePair(type, item)); }
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPreResponseQueue() const { return preResponseQueue; }
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPostResponseQueue() const { return postResponseQueue; }
};
/*
* XXX
*

View file

@ -1,283 +0,0 @@
#include "protocol_datastructures.h"
#include "decklist.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_address, const QString &_realName, Gender _gender, const QString &_country, const QByteArray &_avatarBmp)
: SerializableItem_Map("user")
{
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Int("userlevel", _userLevel));
insertItem(new SerializableItem_String("address", _address));
insertItem(new SerializableItem_String("real_name", _realName));
insertItem(new SerializableItem_Int("gender", _gender));
insertItem(new SerializableItem_String("country", _country));
insertItem(new SerializableItem_ByteArray("avatar_bmp", _avatarBmp));
}
ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete, bool moderatorInfo)
: SerializableItem_Map("user")
{
insertItem(new SerializableItem_String("name", other->getName()));
insertItem(new SerializableItem_Int("userlevel", other->getUserLevel()));
insertItem(new SerializableItem_String("address", moderatorInfo ? other->getAddress() : QString()));
insertItem(new SerializableItem_String("real_name", other->getRealName()));
insertItem(new SerializableItem_Int("gender", other->getGender()));
insertItem(new SerializableItem_String("country", other->getCountry()));
insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray()));
}
ServerInfo_UserList::ServerInfo_UserList(const QString &_itemType, const QList<ServerInfo_User *> &_userList)
: SerializableItem_Map(_itemType)
{
for (int i = 0; i < _userList.size(); ++i)
itemList.append(_userList[i]);
}
ServerInfo_Game::ServerInfo_Game(int _roomId, int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, bool _started, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
: SerializableItem_Map("game")
{
insertItem(new SerializableItem_Int("room_id", _roomId));
insertItem(new SerializableItem_Int("game_id", _gameId));
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_Bool("has_password", _hasPassword));
insertItem(new SerializableItem_Int("player_count", _playerCount));
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
insertItem(new SerializableItem_Bool("started", _started));
if (!_creatorInfo)
_creatorInfo = new ServerInfo_User;
insertItem(_creatorInfo);
insertItem(new SerializableItem_Bool("only_buddies", _onlyBuddies));
insertItem(new SerializableItem_Bool("only_registered", _onlyRegistered));
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
}
ServerInfo_GameType::ServerInfo_GameType(int _gameTypeId, const QString &_description)
: SerializableItem_Map("game_type")
{
insertItem(new SerializableItem_Int("game_type_id", _gameTypeId));
insertItem(new SerializableItem_String("description", _description));
}
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList, const QList<ServerInfo_GameType *> &_gameTypeList)
: SerializableItem_Map("room")
{
insertItem(new SerializableItem_Int("room_id", _roomId));
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_Int("game_count", _gameCount));
insertItem(new SerializableItem_Int("player_count", _playerCount));
insertItem(new SerializableItem_Bool("auto_join", _autoJoin));
gameList = _gameList;
for (int i = 0; i < _gameList.size(); ++i)
itemList.append(_gameList[i]);
userList = _userList;
for (int i = 0; i < _userList.size(); ++i)
itemList.append(_userList[i]);
gameTypeList = _gameTypeList;
for (int i = 0; i < _gameTypeList.size(); ++i)
itemList.append(_gameTypeList[i]);
}
void ServerInfo_Room::extractData()
{
for (int i = 0; i < itemList.size(); ++i) {
ServerInfo_User *user = dynamic_cast<ServerInfo_User *>(itemList[i]);
if (user) {
userList.append(user);
continue;
}
ServerInfo_Game *game = dynamic_cast<ServerInfo_Game *>(itemList[i]);
if (game) {
gameList.append(game);
continue;
}
ServerInfo_GameType *gameType = dynamic_cast<ServerInfo_GameType *>(itemList[i]);
if (gameType) {
gameTypeList.append(gameType);
continue;
}
}
}
ServerInfo_CardCounter::ServerInfo_CardCounter(int _id, int _value)
: SerializableItem_Map("card_counter")
{
insertItem(new SerializableItem_Int("id", _id));
insertItem(new SerializableItem_Int("value", _value));
}
ServerInfo_Card::ServerInfo_Card(int _id, const QString &_name, int _x, int _y, bool _faceDown, bool _tapped, bool _attacking, const QString &_color, const QString &_pt, const QString &_annotation, bool _destroyOnZoneChange, bool _doesntUntap, const QList<ServerInfo_CardCounter *> &_counters, int _attachPlayerId, const QString &_attachZone, int _attachCardId)
: SerializableItem_Map("card")
{
insertItem(new SerializableItem_Int("id", _id));
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Int("x", _x));
insertItem(new SerializableItem_Int("y", _y));
insertItem(new SerializableItem_Bool("facedown", _faceDown));
insertItem(new SerializableItem_Bool("tapped", _tapped));
insertItem(new SerializableItem_Bool("attacking", _attacking));
insertItem(new SerializableItem_String("color", _color));
insertItem(new SerializableItem_String("pt", _pt));
insertItem(new SerializableItem_String("annotation", _annotation));
insertItem(new SerializableItem_Bool("destroy_on_zone_change", _destroyOnZoneChange));
insertItem(new SerializableItem_Bool("doesnt_untap", _doesntUntap));
insertItem(new SerializableItem_Int("attach_player_id", _attachPlayerId));
insertItem(new SerializableItem_String("attach_zone", _attachZone));
insertItem(new SerializableItem_Int("attach_card_id", _attachCardId));
for (int i = 0; i < _counters.size(); ++i)
itemList.append(_counters[i]);
}
ServerInfo_Zone::ServerInfo_Zone(const QString &_name, ZoneType _type, bool _hasCoords, int _cardCount, const QList<ServerInfo_Card *> &_cardList)
: SerializableItem_Map("zone")
{
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_String("zone_type", typeToString(_type)));
insertItem(new SerializableItem_Bool("has_coords", _hasCoords));
insertItem(new SerializableItem_Int("card_count", _cardCount));
for (int i = 0; i < _cardList.size(); ++i)
itemList.append(_cardList[i]);
}
ZoneType ServerInfo_Zone::typeFromString(const QString &type) const
{
if (type == "private")
return PrivateZone;
else if (type == "hidden")
return HiddenZone;
return PublicZone;
}
QString ServerInfo_Zone::typeToString(ZoneType type) const
{
switch (type) {
case PrivateZone: return "private";
case HiddenZone: return "hidden";
default: return "public";
}
}
QList<ServerInfo_Card *> ServerInfo_Zone::getCardList() const
{
QList<ServerInfo_Card *> result;
for (int i = 0; i < itemList.size(); ++i) {
ServerInfo_Card *card = dynamic_cast<ServerInfo_Card *>(itemList[i]);
if (card)
result.append(card);
}
return result;
}
ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const Color &_color, int _radius, int _count)
: SerializableItem_Map("counter")
{
insertItem(new SerializableItem_Int("id", _id));
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Color("color", _color));
insertItem(new SerializableItem_Int("radius", _radius));
insertItem(new SerializableItem_Int("count", _count));
}
ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color)
: SerializableItem_Map("arrow")
{
insertItem(new SerializableItem_Int("id", _id));
insertItem(new SerializableItem_Int("start_player_id", _startPlayerId));
insertItem(new SerializableItem_String("start_zone", _startZone));
insertItem(new SerializableItem_Int("start_card_id", _startCardId));
insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId));
insertItem(new SerializableItem_String("target_zone", _targetZone));
insertItem(new SerializableItem_Int("target_card_id", _targetCardId));
insertItem(new SerializableItem_Color("color", _color));
}
ServerInfo_PlayerProperties::ServerInfo_PlayerProperties(int _playerId, ServerInfo_User *_userInfo, bool _spectator, bool _conceded, bool _readyStart, const QString &_deckHash)
: SerializableItem_Map("player_properties")
{
insertItem(new SerializableItem_Int("player_id", _playerId));
if (!_userInfo)
_userInfo = new ServerInfo_User;
insertItem(_userInfo);
insertItem(new SerializableItem_Bool("spectator", _spectator));
insertItem(new SerializableItem_Bool("conceded", _conceded));
insertItem(new SerializableItem_Bool("ready_start", _readyStart));
insertItem(new SerializableItem_String("deck_hash", _deckHash));
}
ServerInfo_Player::ServerInfo_Player(ServerInfo_PlayerProperties *_properties, DeckList *_deck, const QList<ServerInfo_Zone *> &_zoneList, const QList<ServerInfo_Counter *> &_counterList, const QList<ServerInfo_Arrow *> &_arrowList)
: SerializableItem_Map("player"), zoneList(_zoneList), counterList(_counterList), arrowList(_arrowList)
{
if (!_properties)
insertItem(new ServerInfo_PlayerProperties);
else
insertItem(_properties);
if (!_deck)
insertItem(new DeckList);
else
insertItem(new DeckList(_deck));
zoneList = _zoneList;
for (int i = 0; i < _zoneList.size(); ++i)
itemList.append(_zoneList[i]);
counterList = _counterList;
for (int i = 0; i < _counterList.size(); ++i)
itemList.append(_counterList[i]);
arrowList = _arrowList;
for (int i = 0; i < _arrowList.size(); ++i)
itemList.append(_arrowList[i]);
}
void ServerInfo_Player::extractData()
{
for (int i = 0; i < itemList.size(); ++i) {
ServerInfo_Zone *zone = dynamic_cast<ServerInfo_Zone *>(itemList[i]);
ServerInfo_Counter *counter = dynamic_cast<ServerInfo_Counter *>(itemList[i]);
ServerInfo_Arrow *arrow = dynamic_cast<ServerInfo_Arrow *>(itemList[i]);
if (zone)
zoneList.append(zone);
else if (counter)
counterList.append(counter);
else if (arrow)
arrowList.append(arrow);
}
}
DeckList *ServerInfo_Player::getDeck() const
{
return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
}
ServerInfo_PlayerPing::ServerInfo_PlayerPing(int _playerId, int _pingTime)
: SerializableItem_Map("player_ping")
{
insertItem(new SerializableItem_Int("player_id", _playerId));
insertItem(new SerializableItem_Int("ping_time", _pingTime));
}
DeckList_TreeItem::DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id)
: SerializableItem_Map(_itemType)
{
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Int("id", _id));
}
DeckList_File::DeckList_File(const QString &_name, int _id, QDateTime _uploadTime)
: DeckList_TreeItem("file", _name, _id)
{
insertItem(new SerializableItem_DateTime("upload_time", _uploadTime));
}
DeckList_Directory::DeckList_Directory(const QString &_name, int _id)
: DeckList_TreeItem("directory", _name, _id)
{
}

View file

@ -1,240 +0,0 @@
#ifndef PROTOCOL_DATASTRUCTURES_H
#define PROTOCOL_DATASTRUCTURES_H
#include <QString>
#include <QDateTime>
#include "serializable_item.h"
#include "color.h"
class DeckList;
enum ResponseCode { RespNothing, RespOk, RespNotInRoom, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespInIgnoreList, RespWouldOverwriteOldSession, RespChatFlood };
// PrivateZone: Contents of the zone are always visible to the owner,
// but not to anyone else.
// PublicZone: Contents of the zone are always visible to anyone.
// HiddenZone: Contents of the zone are never visible to anyone.
// However, the owner of the zone can issue a dump_zone command,
// setting beingLookedAt to true.
// Cards in a zone with the type HiddenZone are referenced by their
// list index, whereas cards in any other zone are referenced by their ids.
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
class GameTypeId : public SerializableItem_Int {
public:
GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { }
static SerializableItem *newItem() { return new GameTypeId; }
};
class ServerInfo_User : public SerializableItem_Map {
public:
enum UserLevelFlags {
IsNothing = 0x00,
IsUser = 0x01,
IsRegistered = 0x02,
IsModerator = 0x04,
IsAdmin = 0x08
};
enum Gender {
GenderUnknown = -1,
Male = 0,
Female = 1
};
ServerInfo_User(const QString &_name = QString(), int _userLevel = IsNothing, const QString &_address = QString(), const QString &_realName = QString(), Gender _gender = GenderUnknown, const QString &_country = QString(), const QByteArray &_avatarBmp = QByteArray());
ServerInfo_User(const ServerInfo_User *other, bool complete = true, bool moderatorInfo = false);
static SerializableItem *newItem() { return new ServerInfo_User; }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
void setName(const QString &_name) { static_cast<SerializableItem_String *>(itemMap.value("name"))->setData(_name); }
int getUserLevel() const { return static_cast<SerializableItem_Int *>(itemMap.value("userlevel"))->getData(); }
void setUserLevel(int _userLevel) { static_cast<SerializableItem_Int *>(itemMap.value("userlevel"))->setData(_userLevel); }
QString getAddress() const { return static_cast<SerializableItem_String *>(itemMap.value("address"))->getData(); }
void setAddress(const QString &_address) { static_cast<SerializableItem_String *>(itemMap.value("address"))->setData(_address); }
QString getRealName() const { return static_cast<SerializableItem_String *>(itemMap.value("real_name"))->getData(); }
Gender getGender() const { return static_cast<Gender>(static_cast<SerializableItem_Int *>(itemMap.value("gender"))->getData()); }
QString getCountry() const { return static_cast<SerializableItem_String *>(itemMap.value("country"))->getData(); }
QByteArray getAvatarBmp() const { return static_cast<SerializableItem_ByteArray *>(itemMap.value("avatar_bmp"))->getData(); }
};
class ServerInfo_UserList : public SerializableItem_Map {
public:
ServerInfo_UserList(const QString &_itemType, const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>());
QList<ServerInfo_User *> getUserList() const { return typecastItemList<ServerInfo_User *>(); }
};
class ServerInfo_Game : public SerializableItem_Map {
public:
ServerInfo_Game(int _roomId = -1, int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, bool _started = false, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
static SerializableItem *newItem() { return new ServerInfo_Game; }
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
bool getStarted() const { return static_cast<SerializableItem_Bool *>(itemMap.value("started"))->getData(); }
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
bool getOnlyBuddies() const { return static_cast<SerializableItem_Bool *>(itemMap.value("only_buddies"))->getData(); }
bool getOnlyRegistered() const { return static_cast<SerializableItem_Bool *>(itemMap.value("only_registered"))->getData(); }
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); }
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); }
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
};
class ServerInfo_GameType : public SerializableItem_Map {
public:
ServerInfo_GameType(int _gameTypeId = -1, const QString &_description = QString());
static SerializableItem *newItem() { return new ServerInfo_GameType; }
int getGameTypeId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_type_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
};
class ServerInfo_Room : public SerializableItem_Map {
private:
QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
protected:
void extractData();
public:
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>(), const QList<ServerInfo_GameType *> &_gameTypeList = QList<ServerInfo_GameType *>());
static SerializableItem *newItem() { return new ServerInfo_Room; }
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
int getGameCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_count"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
const QList<ServerInfo_Game *> &getGameList() const { return gameList; }
const QList<ServerInfo_User *> &getUserList() const { return userList; }
const QList<ServerInfo_GameType *> &getGameTypeList() const { return gameTypeList; }
};
class ServerInfo_CardCounter : public SerializableItem_Map {
public:
ServerInfo_CardCounter(int _id = -1, int _value = 0);
static SerializableItem *newItem() { return new ServerInfo_CardCounter; }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); }
};
class ServerInfo_Card : public SerializableItem_Map {
public:
ServerInfo_Card(int _id = -1, const QString &_name = QString(), int _x = -1, int _y = -1, bool _faceDown = false, bool _tapped = false, bool _attacking = false, const QString &_color = QString(), const QString &_pt = QString(), const QString &_annotation = QString(), bool _destroyOnZoneChange = false, bool _doesntUntap = false, const QList<ServerInfo_CardCounter *> &_counterList = QList<ServerInfo_CardCounter *>(), int attachPlayerId = -1, const QString &_attachZone = QString(), int attachCardId = -1);
static SerializableItem *newItem() { return new ServerInfo_Card; }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); }
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); }
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("facedown"))->getData(); }
bool getTapped() const { return static_cast<SerializableItem_Bool *>(itemMap.value("tapped"))->getData(); }
bool getAttacking() const { return static_cast<SerializableItem_Bool *>(itemMap.value("attacking"))->getData(); }
QString getColor() const { return static_cast<SerializableItem_String *>(itemMap.value("color"))->getData(); }
QString getPT() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); }
QString getAnnotation() const { return static_cast<SerializableItem_String *>(itemMap.value("annotation"))->getData(); }
bool getDestroyOnZoneChange() const { return static_cast<SerializableItem_Bool *>(itemMap.value("destroy_on_zone_change"))->getData(); }
bool getDoesntUntap() const { return static_cast<SerializableItem_Bool *>(itemMap.value("doesnt_untap"))->getData(); }
QList<ServerInfo_CardCounter *> getCounters() const { return typecastItemList<ServerInfo_CardCounter *>(); }
int getAttachPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("attach_player_id"))->getData(); }
QString getAttachZone() const { return static_cast<SerializableItem_String *>(itemMap.value("attach_zone"))->getData(); }
int getAttachCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("attach_card_id"))->getData(); }
};
class ServerInfo_Zone : public SerializableItem_Map {
private:
ZoneType typeFromString(const QString &type) const;
QString typeToString(ZoneType type) const;
public:
ServerInfo_Zone(const QString &_name = QString(), ZoneType _type = PrivateZone, bool _hasCoords = false, int _cardCount = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
static SerializableItem *newItem() { return new ServerInfo_Zone; }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
ZoneType getType() const { return typeFromString(static_cast<SerializableItem_String *>(itemMap.value("type"))->getData()); }
bool getHasCoords() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_coords"))->getData(); }
int getCardCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_count"))->getData(); }
QList<ServerInfo_Card *> getCardList() const;
};
class ServerInfo_Counter : public SerializableItem_Map {
public:
ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const Color &_color = Color(), int _radius = -1, int _count = -1);
static SerializableItem *newItem() { return new ServerInfo_Counter; }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); }
int getCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("count"))->getData(); }
};
class ServerInfo_Arrow : public SerializableItem_Map {
public:
ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color());
static SerializableItem *newItem() { return new ServerInfo_Arrow; }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
int getStartPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); }
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }
int getStartCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_card_id"))->getData(); }
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); }
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }
int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); }
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
};
class ServerInfo_PlayerProperties : public SerializableItem_Map {
public:
ServerInfo_PlayerProperties(int _playerId = -1, ServerInfo_User *_userInfo = 0, bool _spectator = false, bool _conceded = false, bool _readyStart = false, const QString &_deckHash = QString());
static SerializableItem *newItem() { return new ServerInfo_PlayerProperties; }
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); }
bool getConceded() const { return static_cast<SerializableItem_Bool *>(itemMap.value("conceded"))->getData(); }
bool getReadyStart() const { return static_cast<SerializableItem_Bool *>(itemMap.value("ready_start"))->getData(); }
QString getDeckHash() const { return static_cast<SerializableItem_String *>(itemMap.value("deck_hash"))->getData(); }
};
class ServerInfo_Player : public SerializableItem_Map {
private:
QList<ServerInfo_Zone *> zoneList;
QList<ServerInfo_Counter *> counterList;
QList<ServerInfo_Arrow *> arrowList;
protected:
void extractData();
public:
ServerInfo_Player(ServerInfo_PlayerProperties *_properties = 0, DeckList *_deck = 0, const QList<ServerInfo_Zone *> &_zoneList = QList<ServerInfo_Zone *>(), const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>(), const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
static SerializableItem *newItem() { return new ServerInfo_Player; }
ServerInfo_PlayerProperties *getProperties() const { return static_cast<ServerInfo_PlayerProperties *>(itemMap.value("player_properties")); }
DeckList *getDeck() const;
const QList<ServerInfo_Zone *> &getZoneList() const { return zoneList; }
const QList<ServerInfo_Counter *> &getCounterList() const { return counterList; }
const QList<ServerInfo_Arrow *> &getArrowList() const { return arrowList; }
};
class ServerInfo_PlayerPing : public SerializableItem_Map {
public:
ServerInfo_PlayerPing(int _playerId = -1, int _pingTime = -1);
static SerializableItem *newItem() { return new ServerInfo_PlayerPing; }
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
int getPingTime() const { return static_cast<SerializableItem_Int *>(itemMap.value("ping_time"))->getData(); }
};
class DeckList_TreeItem : public SerializableItem_Map {
public:
DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id);
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
};
class DeckList_File : public DeckList_TreeItem {
public:
DeckList_File(const QString &_name = QString(), int _id = -1, QDateTime _uploadTime = QDateTime());
static SerializableItem *newItem() { return new DeckList_File; }
QDateTime getUploadTime() const { return static_cast<SerializableItem_DateTime *>(itemMap.value("upload_time"))->getData(); }
};
class DeckList_Directory : public DeckList_TreeItem {
public:
DeckList_Directory(const QString &_name = QString(), int _id = 0);
static SerializableItem *newItem() { return new DeckList_Directory; }
QList<DeckList_TreeItem *> getTreeItems() const { return typecastItemList<DeckList_TreeItem *>(); }
};
#endif

View file

@ -22,22 +22,22 @@
#include <QList>
#include <QString>
#include "protocol_datastructures.h"
#include "pb/serverinfo_zone.pb.h"
class Server_Card;
class Server_Player;
class Server_Game;
class BlaContainer;
class GameEventStorage;
class Server_CardZone {
private:
Server_Player *player;
QString name;
bool has_coords;
ZoneType type;
ServerInfo_Zone::ZoneType type;
int cardsBeingLookedAt;
public:
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ZoneType _type);
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
~Server_CardZone();
int removeCard(Server_Card *card);
@ -46,15 +46,15 @@ public:
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
bool hasCoords() const { return has_coords; }
ZoneType getType() const { return type; }
ServerInfo_Zone::ZoneType getType() const { return type; }
QString getName() const { return name; }
Server_Player *getPlayer() const { return player; }
int getFreeGridColumn(int x, int y, const QString &cardName) const;
bool isColumnEmpty(int x, int y) const;
bool isColumnStacked(int x, int y) const;
void fixFreeSpaces(BlaContainer *bla);
void moveCard(BlaContainer *bla, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y);
void fixFreeSpaces(GameEventStorage &ges);
void moveCard(GameEventStorage &ges, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y);
QList<Server_Card *> cards;
void insertCard(Server_Card *card, int x, int y);
void shuffle();

View file

@ -26,8 +26,11 @@
#include <QMutex>
#include "server_player.h"
#include "protocol.h"
#include "pb/response.pb.h"
#include "pb/serverinfo_player.pb.h"
class QTimer;
class GameEventContainer;
class Server_Room;
class ServerInfo_User;
@ -78,7 +81,7 @@ public:
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions);
Response::ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions);
bool containsUser(const QString &userName) const;
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
void removePlayer(Server_Player *player);
@ -93,8 +96,13 @@ public:
void nextTurn();
void postConnectionStatusUpdate(Server_Player *player, bool connectionStatus);
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
void sendGameEvent(GameEvent *event, GameEventContext *context = 0, Server_Player *exclude = 0);
QList<ServerInfo_Player> getGameState(Server_Player *playerWhosAsking) const;
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId);
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, const GameEventContext &context);
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
// void sendGameEvent(GameEvent *event, GameEventContext *context = 0, Server_Player *exclude = 0);
void sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude = 0, bool excludeOmniscient = false);
void sendGameEventContainerOmniscient(GameEventContainer *cont, Server_Player *exclude = 0);
void sendGameEventToPlayer(Server_Player *player, GameEvent *event);

View file

@ -184,7 +184,7 @@ void Server_Player::clearZones()
lastDrawList.clear();
}
ServerInfo_PlayerProperties *Server_Player::getProperties()
ServerInfo_PlayerProperties Server_Player::getProperties()
{
QMutexLocker locker(&game->gameMutex);

View file

@ -6,7 +6,6 @@
#include <QList>
#include <QMap>
#include <QMutex>
#include "protocol_datastructures.h"
class DeckList;
class Server_Game;
@ -20,7 +19,7 @@ class ServerInfo_User;
class ServerInfo_PlayerProperties;
class CommandContainer;
class CardToMove;
class BlaContainer;
class GameEventStorage;
class Server_Player : public Server_ArrowTarget {
Q_OBJECT
@ -66,7 +65,7 @@ public:
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
ServerInfo_PlayerProperties *getProperties();
ServerInfo_PlayerProperties getProperties();
int newCardId();
int newCounterId() const;
@ -81,12 +80,12 @@ public:
void clearZones();
void setupZones();
ResponseCode drawCards(BlaContainer *bla, int number);
ResponseCode undoDraw(BlaContainer *bla);
ResponseCode moveCard(BlaContainer *bla, const QString &_startZone, const QList<const CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
ResponseCode moveCard(BlaContainer *bla, Server_CardZone *startzone, const QList<const CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
void unattachCard(BlaContainer *bla, Server_Card *card);
ResponseCode setCardAttrHelper(BlaContainer *bla, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
Response::ResponseCode undoDraw(GameEventStorage &ges);
Response::ResponseCode moveCard(GameEventStorage &ges, const QString &_startZone, const QList<const CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
Response::ResponseCode moveCard(GameEventStorage &ges, Server_CardZone *startzone, const QList<const CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
void unattachCard(GameEventStorage &ges, Server_Card *card);
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
};

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,8 @@
#include <QPair>
#include "server.h"
#include "protocol.h"
#include "protocol_items.h"
#include "pb/response.pb.h"
#include "pb/server_message.pb.h"
class Server_Player;
class Server_Card;
@ -13,6 +14,14 @@ class ServerInfo_User;
class Server_Room;
class QTimer;
class Message;
class ServerMessage;
class Response;
class SessionEvent;
class GameEventContainer;
class RoomEvent;
class CommandContainer;
class Command_Ping;
class Command_Login;
@ -90,72 +99,74 @@ protected:
virtual bool getCompressionSupport() const = 0;
int sessionId;
private:
QList<ProtocolItem *> itemQueue;
QString thisUserName;
QList<int> messageSizeOverTime, messageCountOverTime;
int timeRunning, lastDataReceived;
QTimer *pingClock;
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
virtual DeckList *getDeckFromDatabase(int deckId) = 0;
ResponseCode cmdPing(const Command_Ping &cmd);
ResponseCode cmdLogin(const Command_Login &cmd, BlaContainer *bla);
ResponseCode cmdMessage(const Command_Message &cmd, BlaContainer *bla);
virtual ResponseCode cmdAddToList(const Command_AddToList &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckList(const Command_DeckList &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckDel(const Command_DeckDel &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, BlaContainer *bla) = 0;
ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, BlaContainer *bla);
ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, BlaContainer *bla);
ResponseCode cmdListRooms(const Command_ListRooms &cmd, BlaContainer *bla);
ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, BlaContainer *bla);
ResponseCode cmdListUsers(const Command_ListUsers &cmd, BlaContainer *bla);
ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room);
ResponseCode cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room);
ResponseCode cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room);
ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room);
ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdConcede(const Command_Concede &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdGameSay(const Command_GameSay &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdShuffle(const Command_Shuffle &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdMulligan(const Command_Mulligan &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdRollDie(const Command_RollDie &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdDrawCards(const Command_DrawCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdMoveCard(const Command_MoveCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdFlipCard(const Command_FlipCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdAttachCard(const Command_AttachCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdCreateToken(const Command_CreateToken &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdIncCounter(const Command_IncCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdSetCounter(const Command_SetCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdDelCounter(const Command_DelCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdNextTurn(const Command_NextTurn &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdDumpZone(const Command_DumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
ResponseCode cmdRevealCards(const Command_RevealCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla);
virtual ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, BlaContainer *bla) = 0;
virtual ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, BlaContainer *bla) = 0;
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
virtual Response::ResponseCode cmdAddToList(const Command_AddToList &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckList(const Command_DeckList &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckDel(const Command_DeckDel &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, ResponseContainer &rc) = 0;
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
Response::ResponseCode cmdListRooms(const Command_ListRooms &cmd, ResponseContainer &rc);
Response::ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc);
Response::ResponseCode cmdListUsers(const Command_ListUsers &cmd, ResponseContainer &rc);
Response::ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room, ResponseContainer &rc);
Response::ResponseCode cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room, ResponseContainer &rc);
Response::ResponseCode cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room, ResponseContainer &rc);
Response::ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc);
Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdConcede(const Command_Concede &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, Server_Game *game, Server_Player *player, ResponseContainer &rc, GameEventStorage &ges);
virtual Response::ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, ResponseContainer &rc) = 0;
virtual Response::ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, ResponseContainer &rc) = 0;
ResponseCode processSessionCommandContainer(const CommandContainer &cont, BlaContainer *bla);
ResponseCode processRoomCommandContainer(const CommandContainer &cont, BlaContainer *bla);
ResponseCode processGameCommandContainer(const CommandContainer &cont, BlaContainer *bla);
ResponseCode processModeratorCommandContainer(const CommandContainer &cont, BlaContainer *bla);
ResponseCode processAdminCommandContainer(const CommandContainer &cont, BlaContainer *bla);
Response::ResponseCode processSessionCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
Response::ResponseCode processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
Response::ResponseCode processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
Response::ResponseCode processModeratorCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
private slots:
void pingClockTimeout();
public:
@ -168,6 +179,8 @@ public:
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
ServerInfo_User *getUserInfo() const { return userInfo; }
ServerInfo_User copyUserInfo(bool complete, bool moderatorInfo = false) const;
const QString &getUserName() const { return thisUserName; }
virtual QString getAddress() const = 0;
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
const QMap<QString, ServerInfo_User *> &getBuddyList() const { return buddyList; }
@ -177,8 +190,14 @@ public:
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
void processCommandContainer(const CommandContainer &cont);
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
void enqueueProtocolItem(ProtocolItem *item);
void sendProtocolItem(const Response &item);
void sendProtocolItem(const SessionEvent &item);
void sendProtocolItem(const GameEventContainer &item);
void sendProtocolItem(const RoomEvent &item);
void sendProtocolItem(ServerMessage::MessageType type, const ::google::protobuf::Message &item);
SessionEvent *prepareSessionEvent(const ::google::protobuf::Message &sessionEvent);
};
#endif

View file

@ -6,6 +6,7 @@
#include <QObject>
#include <QStringList>
#include <QMutex>
#include "pb/serverinfo_room.pb.h"
class Server_ProtocolHandler;
class RoomEvent;
@ -38,9 +39,9 @@ public:
QString getJoinMessage() const { return joinMessage; }
const QMap<int, Server_Game *> &getGames() const { return games; }
Server *getServer() const;
ServerInfo_Room *getInfo(bool complete, bool showGameTypes = false) const;
ServerInfo_Room getInfo(bool complete, bool showGameTypes = false) const;
int getGamesCreatedByUser(const QString &name) const;
QList<ServerInfo_Game *> getGamesOfUser(const QString &name) const;
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
void addClient(Server_ProtocolHandler *client);
void removeClient(Server_ProtocolHandler *client);
@ -50,6 +51,7 @@ public:
void removeGame(Server_Game *game);
void sendRoomEvent(RoomEvent *event);
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
};
#endif

View file

@ -24,7 +24,6 @@ HEADERS += src/main.h \
../common/serializable_item.h \
../common/decklist.h \
../common/protocol.h \
../common/protocol_datastructures.h \
../common/rng_abstract.h \
../common/rng_sfmt.h \
../common/server.h \
@ -48,7 +47,6 @@ SOURCES += src/main.cpp \
../common/serializable_item.cpp \
../common/decklist.cpp \
../common/protocol.cpp \
../common/protocol_datastructures.cpp \
../common/rng_abstract.cpp \
../common/rng_sfmt.cpp \
../common/sfmt/SFMT.c \