server keeps list of arrows
This commit is contained in:
parent
4bc76600e8
commit
961b42f734
7 changed files with 120 additions and 12 deletions
|
@ -17,6 +17,7 @@ QT -= gui
|
||||||
HEADERS += src/server.h src/servergame.h src/serversocket.h \
|
HEADERS += src/server.h src/servergame.h src/serversocket.h \
|
||||||
src/playerzone.h \
|
src/playerzone.h \
|
||||||
src/card.h \
|
src/card.h \
|
||||||
|
src/arrow.h \
|
||||||
src/version.h \
|
src/version.h \
|
||||||
src/counter.h \
|
src/counter.h \
|
||||||
src/abstractrng.h \
|
src/abstractrng.h \
|
||||||
|
|
18
servatrice/src/arrow.h
Normal file
18
servatrice/src/arrow.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef ARROW_H
|
||||||
|
#define ARROW_H
|
||||||
|
|
||||||
|
class Card;
|
||||||
|
|
||||||
|
class Arrow {
|
||||||
|
private:
|
||||||
|
Card *startCard, *targetCard;
|
||||||
|
int color;
|
||||||
|
public:
|
||||||
|
Arrow(Card *_startCard, Card *_targetCard, int _color)
|
||||||
|
: startCard(_startCard), targetCard(_targetCard), color(_color) { }
|
||||||
|
Card *getStartCard() const { return startCard; }
|
||||||
|
Card *getTargetCard() const { return targetCard; }
|
||||||
|
int getColor() const { return color; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,8 +22,11 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
class PlayerZone;
|
||||||
|
|
||||||
class Card {
|
class Card {
|
||||||
private:
|
private:
|
||||||
|
PlayerZone *zone;
|
||||||
int id;
|
int id;
|
||||||
int coord_x, coord_y;
|
int coord_x, coord_y;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -37,6 +40,9 @@ public:
|
||||||
Card(QString _name, int _id, int _coord_x, int _coord_y);
|
Card(QString _name, int _id, int _coord_x, int _coord_y);
|
||||||
~Card();
|
~Card();
|
||||||
|
|
||||||
|
PlayerZone *getZone() const { return zone; }
|
||||||
|
void setZone(PlayerZone *_zone) { zone = _zone; }
|
||||||
|
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
int getX() const { return coord_x; }
|
int getX() const { return coord_x; }
|
||||||
int getY() const { return coord_y; }
|
int getY() const { return coord_y; }
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "abstractrng.h"
|
#include "abstractrng.h"
|
||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
|
||||||
PlayerZone::PlayerZone(const QString &_name, bool _has_coords, ZoneType _type)
|
PlayerZone::PlayerZone(ServerSocket *_player, const QString &_name, bool _has_coords, ZoneType _type)
|
||||||
: name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0)
|
: player(_player), name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +48,10 @@ Card *PlayerZone::getCard(int id, bool remove, int *position)
|
||||||
while (CardIterator.hasNext()) {
|
while (CardIterator.hasNext()) {
|
||||||
Card *tmp = CardIterator.next();
|
Card *tmp = CardIterator.next();
|
||||||
if (tmp->getId() == id) {
|
if (tmp->getId() == id) {
|
||||||
if (remove)
|
if (remove) {
|
||||||
cards.removeAt(i);
|
cards.removeAt(i);
|
||||||
|
tmp->setZone(0);
|
||||||
|
}
|
||||||
if (position)
|
if (position)
|
||||||
*position = i;
|
*position = i;
|
||||||
return tmp;
|
return tmp;
|
||||||
|
@ -61,8 +63,10 @@ Card *PlayerZone::getCard(int id, bool remove, int *position)
|
||||||
if ((id >= cards.size()) || (id < 0))
|
if ((id >= cards.size()) || (id < 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
Card *tmp = cards[id];
|
Card *tmp = cards[id];
|
||||||
if (remove)
|
if (remove) {
|
||||||
cards.removeAt(id);
|
cards.removeAt(id);
|
||||||
|
tmp->setZone(0);
|
||||||
|
}
|
||||||
if (position)
|
if (position)
|
||||||
*position = id;
|
*position = id;
|
||||||
return tmp;
|
return tmp;
|
||||||
|
@ -78,6 +82,7 @@ void PlayerZone::insertCard(Card *card, int x, int y)
|
||||||
card->setCoords(0, 0);
|
card->setCoords(0, 0);
|
||||||
cards.insert(x, card);
|
cards.insert(x, card);
|
||||||
}
|
}
|
||||||
|
card->setZone(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerZone::clear()
|
void PlayerZone::clear()
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class Card;
|
class Card;
|
||||||
|
class ServerSocket;
|
||||||
class AbstractRNG;
|
class AbstractRNG;
|
||||||
|
|
||||||
class PlayerZone {
|
class PlayerZone {
|
||||||
|
@ -38,12 +39,13 @@ public:
|
||||||
// list index, whereas cards in any other zone are referenced by their ids.
|
// list index, whereas cards in any other zone are referenced by their ids.
|
||||||
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
||||||
private:
|
private:
|
||||||
|
ServerSocket *player;
|
||||||
QString name;
|
QString name;
|
||||||
bool has_coords;
|
bool has_coords;
|
||||||
ZoneType type;
|
ZoneType type;
|
||||||
int cardsBeingLookedAt;
|
int cardsBeingLookedAt;
|
||||||
public:
|
public:
|
||||||
PlayerZone(const QString &_name, bool _has_coords, ZoneType _type);
|
PlayerZone(ServerSocket *_player, const QString &_name, bool _has_coords, ZoneType _type);
|
||||||
~PlayerZone();
|
~PlayerZone();
|
||||||
|
|
||||||
Card *getCard(int id, bool remove, int *position = NULL);
|
Card *getCard(int id, bool remove, int *position = NULL);
|
||||||
|
@ -53,6 +55,7 @@ public:
|
||||||
bool hasCoords() const { return has_coords; }
|
bool hasCoords() const { return has_coords; }
|
||||||
ZoneType getType() const { return type; }
|
ZoneType getType() const { return type; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
|
ServerSocket *getPlayer() const { return player; }
|
||||||
|
|
||||||
QList<Card *> cards;
|
QList<Card *> cards;
|
||||||
void insertCard(Card *card, int x, int y);
|
void insertCard(Card *card, int x, int y);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "playerzone.h"
|
#include "playerzone.h"
|
||||||
#include "counter.h"
|
#include "counter.h"
|
||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
#include "arrow.h"
|
||||||
#include "abstractrng.h"
|
#include "abstractrng.h"
|
||||||
#include "chatchannel.h"
|
#include "chatchannel.h"
|
||||||
|
|
||||||
|
@ -89,7 +90,15 @@ ServerSocket::ServerSocket(Server *_server, QObject *parent)
|
||||||
<< QVariant::Int
|
<< QVariant::Int
|
||||||
<< QVariant::Int
|
<< QVariant::Int
|
||||||
<< QVariant::String
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
<< QVariant::Int, &ServerSocket::cmdCreateArrow));
|
<< QVariant::Int, &ServerSocket::cmdCreateArrow));
|
||||||
|
commandHash.insert("delete_arrow", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::Int
|
||||||
|
<< QVariant::String
|
||||||
|
<< QVariant::Int, &ServerSocket::cmdDeleteArrow));
|
||||||
commandHash.insert("set_card_attr", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
commandHash.insert("set_card_attr", CommandProperties(true, true, true, false, QList<QVariant::Type>()
|
||||||
<< QVariant::String
|
<< QVariant::String
|
||||||
<< QVariant::Int
|
<< QVariant::Int
|
||||||
|
@ -137,6 +146,7 @@ ServerSocket::ServerSocket(Server *_server, QObject *parent)
|
||||||
ServerSocket::~ServerSocket()
|
ServerSocket::~ServerSocket()
|
||||||
{
|
{
|
||||||
qDebug("ServerSocket destructor");
|
qDebug("ServerSocket destructor");
|
||||||
|
clearZones();
|
||||||
// The socket has to be removed from the server's list before it is removed from the game's list
|
// The socket has to be removed from the server's list before it is removed from the game's list
|
||||||
// so it will not receive the game update event.
|
// so it will not receive the game update event.
|
||||||
server->removePlayer(this);
|
server->removePlayer(this);
|
||||||
|
@ -183,14 +193,14 @@ void ServerSocket::setupZones()
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
// Create zones
|
// Create zones
|
||||||
PlayerZone *deck = new PlayerZone("deck", false, PlayerZone::HiddenZone);
|
PlayerZone *deck = new PlayerZone(this, "deck", false, PlayerZone::HiddenZone);
|
||||||
zones << deck;
|
zones << deck;
|
||||||
PlayerZone *sb = new PlayerZone("sb", false, PlayerZone::HiddenZone);
|
PlayerZone *sb = new PlayerZone(this, "sb", false, PlayerZone::HiddenZone);
|
||||||
zones << sb;
|
zones << sb;
|
||||||
zones << new PlayerZone("table", true, PlayerZone::PublicZone);
|
zones << new PlayerZone(this, "table", true, PlayerZone::PublicZone);
|
||||||
zones << new PlayerZone("hand", false, PlayerZone::PrivateZone);
|
zones << new PlayerZone(this, "hand", false, PlayerZone::PrivateZone);
|
||||||
zones << new PlayerZone("grave", false, PlayerZone::PublicZone);
|
zones << new PlayerZone(this, "grave", false, PlayerZone::PublicZone);
|
||||||
zones << new PlayerZone("rfg", false, PlayerZone::PublicZone);
|
zones << new PlayerZone(this, "rfg", false, PlayerZone::PublicZone);
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -222,6 +232,10 @@ void ServerSocket::clearZones()
|
||||||
while (counterIterator.hasNext())
|
while (counterIterator.hasNext())
|
||||||
delete counterIterator.next().value();
|
delete counterIterator.next().value();
|
||||||
counters.clear();
|
counters.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < arrows.size(); i++)
|
||||||
|
delete arrows.at(i);
|
||||||
|
arrows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSocket::leaveGame()
|
void ServerSocket::leaveGame()
|
||||||
|
@ -583,8 +597,47 @@ ReturnMessage::ReturnCode ServerSocket::cmdCreateArrow(const QList<QVariant> &pa
|
||||||
Card *targetCard = targetZone->getCard(params[5].toInt(), false);
|
Card *targetCard = targetZone->getCard(params[5].toInt(), false);
|
||||||
if (!startCard || !targetCard || (startCard == targetCard))
|
if (!startCard || !targetCard || (startCard == targetCard))
|
||||||
return ReturnMessage::ReturnContextError;
|
return ReturnMessage::ReturnContextError;
|
||||||
|
for (int i = 0; i < arrows.size(); ++i)
|
||||||
|
if ((arrows[i]->getStartCard() == startCard) && (arrows[i]->getTargetCard() == targetCard))
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
int color = params[6].toInt();
|
||||||
|
|
||||||
emit broadcastEvent(QString("create_arrow|%1|%2|%3|%4|%5|%6")
|
arrows.append(new Arrow(startCard, targetCard, color));
|
||||||
|
emit broadcastEvent(QString("create_arrow|%1|%2|%3|%4|%5|%6|%7")
|
||||||
|
.arg(startPlayer->getPlayerId())
|
||||||
|
.arg(startZone->getName())
|
||||||
|
.arg(startCard->getId())
|
||||||
|
.arg(targetPlayer->getPlayerId())
|
||||||
|
.arg(targetZone->getName())
|
||||||
|
.arg(targetCard->getId())
|
||||||
|
.arg(color), this
|
||||||
|
);
|
||||||
|
return ReturnMessage::ReturnOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnMessage::ReturnCode ServerSocket::cmdDeleteArrow(const QList<QVariant> ¶ms)
|
||||||
|
{
|
||||||
|
ServerSocket *startPlayer = game->getPlayer(params[0].toInt());
|
||||||
|
ServerSocket *targetPlayer = game->getPlayer(params[3].toInt());
|
||||||
|
if (!startPlayer || !targetPlayer)
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
PlayerZone *startZone = startPlayer->getZone(params[1].toString());
|
||||||
|
PlayerZone *targetZone = targetPlayer->getZone(params[4].toString());
|
||||||
|
if (!startZone || !targetZone)
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
Card *startCard = startZone->getCard(params[2].toInt(), false);
|
||||||
|
Card *targetCard = targetZone->getCard(params[5].toInt(), false);
|
||||||
|
|
||||||
|
Arrow *arrow = 0;
|
||||||
|
for (int i = 0; i < arrows.size(); ++i)
|
||||||
|
if ((arrows[i]->getStartCard() == startCard) && (arrows[i]->getTargetCard() == targetCard)) {
|
||||||
|
arrow = arrows.takeAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!arrow)
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
|
||||||
|
emit broadcastEvent(QString("delete_arrow|%1|%2|%3|%4|%5|%6")
|
||||||
.arg(startPlayer->getPlayerId())
|
.arg(startPlayer->getPlayerId())
|
||||||
.arg(startZone->getName())
|
.arg(startZone->getName())
|
||||||
.arg(startCard->getId())
|
.arg(startCard->getId())
|
||||||
|
@ -810,6 +863,22 @@ ReturnMessage::ReturnCode ServerSocket::cmdSetActivePhase(const QList<QVariant>
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ServerSocket::listArrowsHelper(ServerSocket *player)
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
const QList<Arrow *> &arrowList = player->getArrows();
|
||||||
|
for (int i = 0; i < arrowList.size(); ++i) {
|
||||||
|
Card *startCard = arrowList[i]->getStartCard();
|
||||||
|
Card *targetCard = arrowList[i]->getTargetCard();
|
||||||
|
PlayerZone *startZone = startCard->getZone();
|
||||||
|
PlayerZone *targetZone = targetCard->getZone();
|
||||||
|
ServerSocket *startPlayer = startZone->getPlayer();
|
||||||
|
ServerSocket *targetPlayer = targetZone->getPlayer();
|
||||||
|
result << QString("%1|%2|%3|%4|%5|%6|%7").arg(startPlayer->getPlayerName()).arg(startZone->getName()).arg(startCard->getId()).arg(targetPlayer->getPlayerName()).arg(targetZone->getName()).arg(targetCard->getId()).arg(arrowList[i]->getColor());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnMessage::ReturnCode ServerSocket::cmdDumpAll(const QList<QVariant> &/*params*/)
|
ReturnMessage::ReturnCode ServerSocket::cmdDumpAll(const QList<QVariant> &/*params*/)
|
||||||
{
|
{
|
||||||
remsg->sendList(listPlayersHelper(), "list_players");
|
remsg->sendList(listPlayersHelper(), "list_players");
|
||||||
|
@ -825,6 +894,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpAll(const QList<QVariant> &/*para
|
||||||
remsg->sendList(dumpZoneHelper(players[i], zones[j], -1), "dump_zone");
|
remsg->sendList(dumpZoneHelper(players[i], zones[j], -1), "dump_zone");
|
||||||
|
|
||||||
remsg->sendList(listCountersHelper(players[i]), "list_counters");
|
remsg->sendList(listCountersHelper(players[i]), "list_counters");
|
||||||
|
remsg->sendList(listArrowsHelper(players[i]), "list_arrows");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remsg->send(ReturnMessage::ReturnOk);
|
remsg->send(ReturnMessage::ReturnOk);
|
||||||
|
|
|
@ -30,6 +30,7 @@ class Server;
|
||||||
class ServerGame;
|
class ServerGame;
|
||||||
class PlayerZone;
|
class PlayerZone;
|
||||||
class Counter;
|
class Counter;
|
||||||
|
class Arrow;
|
||||||
|
|
||||||
enum PlayerStatusEnum { StatusNormal, StatusSubmitDeck, StatusReadyStart, StatusPlaying };
|
enum PlayerStatusEnum { StatusNormal, StatusSubmitDeck, StatusReadyStart, StatusPlaying };
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ private:
|
||||||
QStringList listZonesHelper(ServerSocket *player);
|
QStringList listZonesHelper(ServerSocket *player);
|
||||||
QStringList dumpZoneHelper(ServerSocket *player, PlayerZone *zone, int numberCards);
|
QStringList dumpZoneHelper(ServerSocket *player, PlayerZone *zone, int numberCards);
|
||||||
QStringList listCountersHelper(ServerSocket *player);
|
QStringList listCountersHelper(ServerSocket *player);
|
||||||
|
QStringList listArrowsHelper(ServerSocket *player);
|
||||||
|
|
||||||
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdLogin(const QList<QVariant> ¶ms);
|
||||||
|
@ -91,6 +93,7 @@ private:
|
||||||
ReturnMessage::ReturnCode cmdMoveCard(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdMoveCard(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdCreateToken(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdCreateToken(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdCreateArrow(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdCreateArrow(const QList<QVariant> ¶ms);
|
||||||
|
ReturnMessage::ReturnCode cmdDeleteArrow(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdSetCardAttr(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdSetCardAttr(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdIncCounter(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdIncCounter(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdAddCounter(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdAddCounter(const QList<QVariant> ¶ms);
|
||||||
|
@ -112,6 +115,7 @@ private:
|
||||||
QList<QString> SideboardList;
|
QList<QString> SideboardList;
|
||||||
QList<PlayerZone *> zones;
|
QList<PlayerZone *> zones;
|
||||||
QMap<int, Counter *> counters;
|
QMap<int, Counter *> counters;
|
||||||
|
QList<Arrow *> arrows;
|
||||||
int playerId;
|
int playerId;
|
||||||
QString playerName;
|
QString playerName;
|
||||||
bool spectator;
|
bool spectator;
|
||||||
|
@ -145,6 +149,7 @@ public:
|
||||||
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
||||||
const QList<PlayerZone *> &getZones() const { return zones; }
|
const QList<PlayerZone *> &getZones() const { return zones; }
|
||||||
const QMap<int, Counter *> &getCounters() const { return counters; }
|
const QMap<int, Counter *> &getCounters() const { return counters; }
|
||||||
|
const QList<Arrow *> &getArrows() const { return arrows; }
|
||||||
void setupZones();
|
void setupZones();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue