Tabs to spaces.
This commit is contained in:
parent
1217689ed6
commit
4e8ba699d2
38 changed files with 4510 additions and 4510 deletions
|
@ -10,26 +10,26 @@
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
inline QColor convertColorToQColor(const color &c)
|
inline QColor convertColorToQColor(const color &c)
|
||||||
{
|
{
|
||||||
return QColor(c.r(), c.g(), c.b());
|
return QColor(c.r(), c.g(), c.b());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline color convertQColorToColor(const QColor &c)
|
inline color convertQColorToColor(const QColor &c)
|
||||||
{
|
{
|
||||||
color result;
|
color result;
|
||||||
result.set_r(c.red());
|
result.set_r(c.red());
|
||||||
result.set_g(c.green());
|
result.set_g(c.green());
|
||||||
result.set_b(c.blue());
|
result.set_b(c.blue());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline color makeColor(int r, int g, int b)
|
inline color makeColor(int r, int g, int b)
|
||||||
{
|
{
|
||||||
color result;
|
color result;
|
||||||
result.set_r(r);
|
result.set_r(r);
|
||||||
result.set_g(g);
|
result.set_g(g);
|
||||||
result.set_b(b);
|
result.set_b(b);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,152 +23,152 @@ class InnerDecklistNode;
|
||||||
|
|
||||||
class SideboardPlan {
|
class SideboardPlan {
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
QList<MoveCard_ToZone> moveList;
|
QList<MoveCard_ToZone> moveList;
|
||||||
public:
|
public:
|
||||||
SideboardPlan(const QString &_name = QString(), const QList<MoveCard_ToZone> &_moveList = QList<MoveCard_ToZone>());
|
SideboardPlan(const QString &_name = QString(), const QList<MoveCard_ToZone> &_moveList = QList<MoveCard_ToZone>());
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void write(QXmlStreamWriter *xml);
|
void write(QXmlStreamWriter *xml);
|
||||||
|
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
const QList<MoveCard_ToZone> &getMoveList() const { return moveList; }
|
const QList<MoveCard_ToZone> &getMoveList() const { return moveList; }
|
||||||
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
|
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DeckSortMethod { ByNumber, ByName, ByPrice };
|
enum DeckSortMethod { ByNumber, ByName, ByPrice };
|
||||||
|
|
||||||
class AbstractDecklistNode {
|
class AbstractDecklistNode {
|
||||||
protected:
|
protected:
|
||||||
InnerDecklistNode *parent;
|
InnerDecklistNode *parent;
|
||||||
DeckSortMethod sortMethod;
|
DeckSortMethod sortMethod;
|
||||||
public:
|
public:
|
||||||
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
||||||
virtual ~AbstractDecklistNode() { }
|
virtual ~AbstractDecklistNode() { }
|
||||||
virtual void setSortMethod(DeckSortMethod method) { sortMethod = method; }
|
virtual void setSortMethod(DeckSortMethod method) { sortMethod = method; }
|
||||||
virtual QString getName() const = 0;
|
virtual QString getName() const = 0;
|
||||||
InnerDecklistNode *getParent() const { return parent; }
|
InnerDecklistNode *getParent() const { return parent; }
|
||||||
int depth() const;
|
int depth() const;
|
||||||
virtual int height() const = 0;
|
virtual int height() const = 0;
|
||||||
virtual bool compare(AbstractDecklistNode *other) const = 0;
|
virtual bool compare(AbstractDecklistNode *other) const = 0;
|
||||||
|
|
||||||
virtual bool readElement(QXmlStreamReader *xml) = 0;
|
virtual bool readElement(QXmlStreamReader *xml) = 0;
|
||||||
virtual void writeElement(QXmlStreamWriter *xml) = 0;
|
virtual void writeElement(QXmlStreamWriter *xml) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InnerDecklistNode : public AbstractDecklistNode, public QList<AbstractDecklistNode *> {
|
class InnerDecklistNode : public AbstractDecklistNode, public QList<AbstractDecklistNode *> {
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
class compareFunctor;
|
class compareFunctor;
|
||||||
public:
|
public:
|
||||||
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
|
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
|
||||||
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
|
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
|
||||||
virtual ~InnerDecklistNode();
|
virtual ~InnerDecklistNode();
|
||||||
void setSortMethod(DeckSortMethod method);
|
void setSortMethod(DeckSortMethod method);
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
void setName(const QString &_name) { name = _name; }
|
void setName(const QString &_name) { name = _name; }
|
||||||
static QString visibleNameFromName(const QString &_name);
|
static QString visibleNameFromName(const QString &_name);
|
||||||
virtual QString getVisibleName() const;
|
virtual QString getVisibleName() const;
|
||||||
void clearTree();
|
void clearTree();
|
||||||
AbstractDecklistNode *findChild(const QString &name);
|
AbstractDecklistNode *findChild(const QString &name);
|
||||||
int height() const;
|
int height() const;
|
||||||
int recursiveCount(bool countTotalCards = false) const;
|
int recursiveCount(bool countTotalCards = false) const;
|
||||||
float recursivePrice(bool countTotalCards = false) const;
|
float recursivePrice(bool countTotalCards = false) const;
|
||||||
bool compare(AbstractDecklistNode *other) const;
|
bool compare(AbstractDecklistNode *other) const;
|
||||||
bool compareNumber(AbstractDecklistNode *other) const;
|
bool compareNumber(AbstractDecklistNode *other) const;
|
||||||
bool compareName(AbstractDecklistNode *other) const;
|
bool compareName(AbstractDecklistNode *other) const;
|
||||||
bool comparePrice(AbstractDecklistNode *other) const;
|
bool comparePrice(AbstractDecklistNode *other) const;
|
||||||
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
|
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractDecklistCardNode : public AbstractDecklistNode {
|
class AbstractDecklistCardNode : public AbstractDecklistNode {
|
||||||
public:
|
public:
|
||||||
AbstractDecklistCardNode(InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent) { }
|
AbstractDecklistCardNode(InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent) { }
|
||||||
virtual int getNumber() const = 0;
|
virtual int getNumber() const = 0;
|
||||||
virtual void setNumber(int _number) = 0;
|
virtual void setNumber(int _number) = 0;
|
||||||
virtual QString getName() const = 0;
|
virtual QString getName() const = 0;
|
||||||
virtual void setName(const QString &_name) = 0;
|
virtual void setName(const QString &_name) = 0;
|
||||||
virtual float getPrice() const = 0;
|
virtual float getPrice() const = 0;
|
||||||
virtual void setPrice(const float _price) = 0;
|
virtual void setPrice(const float _price) = 0;
|
||||||
float getTotalPrice() const { return getNumber() * getPrice(); }
|
float getTotalPrice() const { return getNumber() * getPrice(); }
|
||||||
int height() const { return 0; }
|
int height() const { return 0; }
|
||||||
bool compare(AbstractDecklistNode *other) const;
|
bool compare(AbstractDecklistNode *other) const;
|
||||||
bool compareNumber(AbstractDecklistNode *other) const;
|
bool compareNumber(AbstractDecklistNode *other) const;
|
||||||
bool compareName(AbstractDecklistNode *other) const;
|
bool compareName(AbstractDecklistNode *other) const;
|
||||||
bool compareTotalPrice(AbstractDecklistNode *other) const;
|
bool compareTotalPrice(AbstractDecklistNode *other) const;
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DecklistCardNode : public AbstractDecklistCardNode {
|
class DecklistCardNode : public AbstractDecklistCardNode {
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
int number;
|
int number;
|
||||||
float price;
|
float price;
|
||||||
public:
|
public:
|
||||||
DecklistCardNode(const QString &_name = QString(), int _number = 1, float _price = 0, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(_price) { }
|
DecklistCardNode(const QString &_name = QString(), int _number = 1, float _price = 0, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(_price) { }
|
||||||
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(0) { }
|
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(0) { }
|
||||||
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
|
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
|
||||||
int getNumber() const { return number; }
|
int getNumber() const { return number; }
|
||||||
void setNumber(int _number) { number = _number; }
|
void setNumber(int _number) { number = _number; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
void setName(const QString &_name) { name = _name; }
|
void setName(const QString &_name) { name = _name; }
|
||||||
float getPrice() const { return price; }
|
float getPrice() const { return price; }
|
||||||
void setPrice(const float _price) { price = _price; }
|
void setPrice(const float _price) { price = _price; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckList : public QObject {
|
class DeckList : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString name, comments;
|
QString name, comments;
|
||||||
QString deckHash;
|
QString deckHash;
|
||||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
||||||
signals:
|
signals:
|
||||||
void deckHashChanged();
|
void deckHashChanged();
|
||||||
public slots:
|
public slots:
|
||||||
void setName(const QString &_name = QString()) { name = _name; }
|
void setName(const QString &_name = QString()) { name = _name; }
|
||||||
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
||||||
public:
|
public:
|
||||||
DeckList();
|
DeckList();
|
||||||
DeckList(const DeckList &other);
|
DeckList(const DeckList &other);
|
||||||
DeckList(const QString &nativeString);
|
DeckList(const QString &nativeString);
|
||||||
~DeckList();
|
~DeckList();
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
QString getComments() const { return comments; }
|
QString getComments() const { return comments; }
|
||||||
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
||||||
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
||||||
const QMap<QString, SideboardPlan *> &getSideboardPlans() const { return sideboardPlans; }
|
const QMap<QString, SideboardPlan *> &getSideboardPlans() const { return sideboardPlans; }
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void write(QXmlStreamWriter *xml);
|
void write(QXmlStreamWriter *xml);
|
||||||
bool loadFromXml(QXmlStreamReader *xml);
|
bool loadFromXml(QXmlStreamReader *xml);
|
||||||
bool loadFromString_Native(const QString &nativeString);
|
bool loadFromString_Native(const QString &nativeString);
|
||||||
QString writeToString_Native();
|
QString writeToString_Native();
|
||||||
bool loadFromFile_Native(QIODevice *device);
|
bool loadFromFile_Native(QIODevice *device);
|
||||||
bool saveToFile_Native(QIODevice *device);
|
bool saveToFile_Native(QIODevice *device);
|
||||||
bool loadFromStream_Plain(QTextStream &stream);
|
bool loadFromStream_Plain(QTextStream &stream);
|
||||||
bool loadFromFile_Plain(QIODevice *device);
|
bool loadFromFile_Plain(QIODevice *device);
|
||||||
bool saveToStream_Plain(QTextStream &stream);
|
bool saveToStream_Plain(QTextStream &stream);
|
||||||
bool saveToFile_Plain(QIODevice *device);
|
bool saveToFile_Plain(QIODevice *device);
|
||||||
QString writeToString_Plain();
|
QString writeToString_Plain();
|
||||||
|
|
||||||
void cleanList();
|
void cleanList();
|
||||||
bool isEmpty() const { return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty(); }
|
bool isEmpty() const { return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty(); }
|
||||||
QStringList getCardList() const;
|
QStringList getCardList() const;
|
||||||
|
|
||||||
int getSideboardSize() const;
|
int getSideboardSize() const;
|
||||||
|
|
||||||
QString getDeckHash() const { return deckHash; }
|
QString getDeckHash() const { return deckHash; }
|
||||||
void updateDeckHash();
|
void updateDeckHash();
|
||||||
|
|
||||||
InnerDecklistNode *getRoot() const { return root; }
|
InnerDecklistNode *getRoot() const { return root; }
|
||||||
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
||||||
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = 0);
|
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
int getPbExtension(const ::google::protobuf::Message &message)
|
int getPbExtension(const ::google::protobuf::Message &message)
|
||||||
{
|
{
|
||||||
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
|
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
|
||||||
message.GetReflection()->ListFields(message, &fieldList);
|
message.GetReflection()->ListFields(message, &fieldList);
|
||||||
for (unsigned int j = 0; j < fieldList.size(); ++j)
|
for (unsigned int j = 0; j < fieldList.size(); ++j)
|
||||||
if (fieldList[j]->is_extension())
|
if (fieldList[j]->is_extension())
|
||||||
return fieldList[j]->number();
|
return fieldList[j]->number();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#define GET_PB_EXTENSION_H
|
#define GET_PB_EXTENSION_H
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace protobuf {
|
namespace protobuf {
|
||||||
class Message;
|
class Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPbExtension(const ::google::protobuf::Message &message);
|
int getPbExtension(const ::google::protobuf::Message &message);
|
||||||
|
|
|
@ -4,27 +4,27 @@
|
||||||
|
|
||||||
QVector<int> RNG_Abstract::makeNumbersVector(int n, int min, int max)
|
QVector<int> RNG_Abstract::makeNumbersVector(int n, int min, int max)
|
||||||
{
|
{
|
||||||
const int bins = max - min + 1;
|
const int bins = max - min + 1;
|
||||||
QVector<int> result(bins);
|
QVector<int> result(bins);
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
int number = rand(min, max);
|
int number = rand(min, max);
|
||||||
if ((number < min) || (number > max))
|
if ((number < min) || (number > max))
|
||||||
qDebug() << "rand(" << min << "," << max << ") returned " << number;
|
qDebug() << "rand(" << min << "," << max << ") returned " << number;
|
||||||
else
|
else
|
||||||
result[number - min]++;
|
result[number - min]++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
double RNG_Abstract::testRandom(const QVector<int> &numbers) const
|
double RNG_Abstract::testRandom(const QVector<int> &numbers) const
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int i = 0; i < numbers.size(); ++i)
|
for (int i = 0; i < numbers.size(); ++i)
|
||||||
n += numbers[i];
|
n += numbers[i];
|
||||||
double expected = (double) n / (double) numbers.size();
|
double expected = (double) n / (double) numbers.size();
|
||||||
double chisq = 0;
|
double chisq = 0;
|
||||||
for (int i = 0; i < numbers.size(); ++i)
|
for (int i = 0; i < numbers.size(); ++i)
|
||||||
chisq += ((double) numbers[i] - expected) * ((double) numbers[i] - expected) / expected;
|
chisq += ((double) numbers[i] - expected) * ((double) numbers[i] - expected) / expected;
|
||||||
|
|
||||||
return chisq;
|
return chisq;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
class RNG_Abstract : public QObject {
|
class RNG_Abstract : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RNG_Abstract(QObject *parent = 0) : QObject(parent) { }
|
RNG_Abstract(QObject *parent = 0) : QObject(parent) { }
|
||||||
virtual unsigned int rand(int min, int max) = 0;
|
virtual unsigned int rand(int min, int max) = 0;
|
||||||
QVector<int> makeNumbersVector(int n, int min, int max);
|
QVector<int> makeNumbersVector(int n, int min, int max);
|
||||||
double testRandom(const QVector<int> &numbers) const;
|
double testRandom(const QVector<int> &numbers) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern RNG_Abstract *rng;
|
extern RNG_Abstract *rng;
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RNG_SFMT::RNG_SFMT(QObject *parent)
|
RNG_SFMT::RNG_SFMT(QObject *parent)
|
||||||
: RNG_Abstract(parent)
|
: RNG_Abstract(parent)
|
||||||
{
|
{
|
||||||
// initialize the random number generator with a 32bit integer seed (timestamp)
|
// initialize the random number generator with a 32bit integer seed (timestamp)
|
||||||
sfmt_init_gen_rand(&sfmt, QDateTime::currentDateTime().toTime_t());
|
sfmt_init_gen_rand(&sfmt, QDateTime::currentDateTime().toTime_t());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,11 +32,11 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
||||||
* There has been no use for negative random numbers with rand() though, so it's treated as error.
|
* There has been no use for negative random numbers with rand() though, so it's treated as error.
|
||||||
*/
|
*/
|
||||||
if(min < 0) {
|
if(min < 0) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
QString("Invalid bounds for RNG: Got min " +
|
QString("Invalid bounds for RNG: Got min " +
|
||||||
QString::number(min) + " < 0!\n").toStdString());
|
QString::number(min) + " < 0!\n").toStdString());
|
||||||
// at this point, the method exits. No return value is needed, because
|
// at this point, the method exits. No return value is needed, because
|
||||||
// basically the exception itself is returned.
|
// basically the exception itself is returned.
|
||||||
}
|
}
|
||||||
|
|
||||||
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
|
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
|
||||||
|
@ -99,38 +99,38 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
||||||
*/
|
*/
|
||||||
unsigned int RNG_SFMT::cdf(unsigned int min, unsigned int max)
|
unsigned int RNG_SFMT::cdf(unsigned int min, unsigned int max)
|
||||||
{
|
{
|
||||||
// This all makes no sense if min > max, which should never happen.
|
// This all makes no sense if min > max, which should never happen.
|
||||||
if(min > max) {
|
if(min > max) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
||||||
QString::number(min) + ", max = " +
|
QString::number(min) + ", max = " +
|
||||||
QString::number(max)).toStdString());
|
QString::number(max)).toStdString());
|
||||||
// at this point, the method exits. No return value is needed, because
|
// at this point, the method exits. No return value is needed, because
|
||||||
// basically the exception itself is returned.
|
// basically the exception itself is returned.
|
||||||
}
|
}
|
||||||
|
|
||||||
// First compute the diameter (aka size, length) of the [min, max] interval
|
// First compute the diameter (aka size, length) of the [min, max] interval
|
||||||
const unsigned int diameter = max - min + 1;
|
const unsigned int diameter = max - min + 1;
|
||||||
|
|
||||||
// Compute how many buckets (each in size of the diameter) will fit into the
|
// Compute how many buckets (each in size of the diameter) will fit into the
|
||||||
// universe.
|
// universe.
|
||||||
// If the division has a remainder, the result is floored automatically.
|
// If the division has a remainder, the result is floored automatically.
|
||||||
const uint64_t buckets = UINT64_MAX / diameter;
|
const uint64_t buckets = UINT64_MAX / diameter;
|
||||||
|
|
||||||
// Compute the last valid random number. All numbers beyond have to be ignored.
|
// Compute the last valid random number. All numbers beyond have to be ignored.
|
||||||
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
|
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
|
||||||
const uint64_t limit = diameter * buckets;
|
const uint64_t limit = diameter * buckets;
|
||||||
|
|
||||||
uint64_t rand;
|
uint64_t rand;
|
||||||
// To make the random number generation thread-safe, a mutex is created around
|
// To make the random number generation thread-safe, a mutex is created around
|
||||||
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
|
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
do {
|
do {
|
||||||
rand = sfmt_genrand_uint64(&sfmt);
|
rand = sfmt_genrand_uint64(&sfmt);
|
||||||
} while (rand >= limit);
|
} while (rand >= limit);
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|
||||||
// Now determine the bucket containing the SFMT() random number and after adding
|
// Now determine the bucket containing the SFMT() random number and after adding
|
||||||
// the lower bound, a random number from [min, max] can be returned.
|
// the lower bound, a random number from [min, max] can be returned.
|
||||||
return (unsigned int) (rand / buckets + min);
|
return (unsigned int) (rand / buckets + min);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RNG_SFMT : public RNG_Abstract {
|
class RNG_SFMT : public RNG_Abstract {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
sfmt_t sfmt;
|
sfmt_t sfmt;
|
||||||
// The discrete cumulative distribution function for the RNG
|
// The discrete cumulative distribution function for the RNG
|
||||||
unsigned int cdf(unsigned int min, unsigned int max);
|
unsigned int cdf(unsigned int min, unsigned int max);
|
||||||
public:
|
public:
|
||||||
RNG_SFMT(QObject *parent = 0);
|
RNG_SFMT(QObject *parent = 0);
|
||||||
unsigned int rand(int min, int max);
|
unsigned int rand(int min, int max);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,18 +36,18 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Server::Server(bool _threaded, QObject *parent)
|
Server::Server(bool _threaded, QObject *parent)
|
||||||
: QObject(parent), threaded(_threaded), nextLocalGameId(0)
|
: QObject(parent), threaded(_threaded), nextLocalGameId(0)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<ServerInfo_Game>("ServerInfo_Game");
|
qRegisterMetaType<ServerInfo_Game>("ServerInfo_Game");
|
||||||
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");
|
qRegisterMetaType<ServerInfo_Room>("ServerInfo_Room");
|
||||||
qRegisterMetaType<ServerInfo_User>("ServerInfo_User");
|
qRegisterMetaType<ServerInfo_User>("ServerInfo_User");
|
||||||
qRegisterMetaType<CommandContainer>("CommandContainer");
|
qRegisterMetaType<CommandContainer>("CommandContainer");
|
||||||
qRegisterMetaType<Response>("Response");
|
qRegisterMetaType<Response>("Response");
|
||||||
qRegisterMetaType<GameEventContainer>("GameEventContainer");
|
qRegisterMetaType<GameEventContainer>("GameEventContainer");
|
||||||
qRegisterMetaType<IslMessage>("IslMessage");
|
qRegisterMetaType<IslMessage>("IslMessage");
|
||||||
qRegisterMetaType<Command_JoinGame>("Command_JoinGame");
|
qRegisterMetaType<Command_JoinGame>("Command_JoinGame");
|
||||||
|
|
||||||
connect(this, SIGNAL(sigSendIslMessage(IslMessage, int)), this, SLOT(doSendIslMessage(IslMessage, int)), Qt::QueuedConnection);
|
connect(this, SIGNAL(sigSendIslMessage(IslMessage, int)), this, SLOT(doSendIslMessage(IslMessage, int)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
|
@ -56,532 +56,532 @@ Server::~Server()
|
||||||
|
|
||||||
void Server::prepareDestroy()
|
void Server::prepareDestroy()
|
||||||
{
|
{
|
||||||
// dirty :(
|
// dirty :(
|
||||||
if (threaded) {
|
if (threaded) {
|
||||||
clientsLock.lockForRead();
|
clientsLock.lockForRead();
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection);
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
class SleeperThread : public QThread
|
class SleeperThread : public QThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void msleep(unsigned long msecs) { QThread::usleep(msecs); }
|
static void msleep(unsigned long msecs) { QThread::usleep(msecs); }
|
||||||
};
|
};
|
||||||
|
|
||||||
do {
|
do {
|
||||||
SleeperThread::msleep(10);
|
SleeperThread::msleep(10);
|
||||||
clientsLock.lockForRead();
|
clientsLock.lockForRead();
|
||||||
if (clients.isEmpty())
|
if (clients.isEmpty())
|
||||||
done = true;
|
done = true;
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
} while (!done);
|
} while (!done);
|
||||||
} else {
|
} else {
|
||||||
// no locking is needed in unthreaded mode
|
// no locking is needed in unthreaded mode
|
||||||
while (!clients.isEmpty())
|
while (!clients.isEmpty())
|
||||||
clients.first()->prepareDestroy();
|
clients.first()->prepareDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
roomsLock.lockForWrite();
|
roomsLock.lockForWrite();
|
||||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||||
while (roomIterator.hasNext())
|
while (roomIterator.hasNext())
|
||||||
delete roomIterator.next().value();
|
delete roomIterator.next().value();
|
||||||
rooms.clear();
|
rooms.clear();
|
||||||
roomsLock.unlock();
|
roomsLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::setDatabaseInterface(Server_DatabaseInterface *_databaseInterface)
|
void Server::setDatabaseInterface(Server_DatabaseInterface *_databaseInterface)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(endSession(qint64)), _databaseInterface, SLOT(endSession(qint64)));
|
connect(this, SIGNAL(endSession(qint64)), _databaseInterface, SLOT(endSession(qint64)));
|
||||||
databaseInterfaces.insert(QThread::currentThread(), _databaseInterface);
|
databaseInterfaces.insert(QThread::currentThread(), _databaseInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_DatabaseInterface *Server::getDatabaseInterface() const
|
Server_DatabaseInterface *Server::getDatabaseInterface() const
|
||||||
{
|
{
|
||||||
return databaseInterfaces.value(QThread::currentThread());
|
return databaseInterfaces.value(QThread::currentThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr, int &secondsLeft)
|
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr, int &secondsLeft)
|
||||||
{
|
{
|
||||||
if (name.size() > 35)
|
if (name.size() > 35)
|
||||||
name = name.left(35);
|
name = name.left(35);
|
||||||
|
|
||||||
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
||||||
|
|
||||||
QWriteLocker locker(&clientsLock);
|
QWriteLocker locker(&clientsLock);
|
||||||
|
|
||||||
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, reasonStr, secondsLeft);
|
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, reasonStr, secondsLeft);
|
||||||
if ((authState == NotLoggedIn) || (authState == UserIsBanned || authState == UsernameInvalid))
|
if ((authState == NotLoggedIn) || (authState == UserIsBanned || authState == UsernameInvalid))
|
||||||
return authState;
|
return authState;
|
||||||
|
|
||||||
ServerInfo_User data = databaseInterface->getUserData(name, true);
|
ServerInfo_User data = databaseInterface->getUserData(name, true);
|
||||||
data.set_address(session->getAddress().toStdString());
|
data.set_address(session->getAddress().toStdString());
|
||||||
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
name = QString::fromStdString(data.name()); // Compensate for case indifference
|
||||||
|
|
||||||
databaseInterface->lockSessionTables();
|
databaseInterface->lockSessionTables();
|
||||||
|
|
||||||
if (authState == PasswordRight) {
|
if (authState == PasswordRight) {
|
||||||
if (users.contains(name) || databaseInterface->userSessionExists(name)) {
|
if (users.contains(name) || databaseInterface->userSessionExists(name)) {
|
||||||
qDebug("Login denied: would overwrite old session");
|
qDebug("Login denied: would overwrite old session");
|
||||||
databaseInterface->unlockSessionTables();
|
databaseInterface->unlockSessionTables();
|
||||||
return WouldOverwriteOldSession;
|
return WouldOverwriteOldSession;
|
||||||
}
|
}
|
||||||
} else if (authState == UnknownUser) {
|
} else if (authState == UnknownUser) {
|
||||||
// Change user name so that no two users have the same names,
|
// Change user name so that no two users have the same names,
|
||||||
// don't interfere with registered user names though.
|
// don't interfere with registered user names though.
|
||||||
QString tempName = name;
|
QString tempName = name;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||||
tempName = name + "_" + QString::number(++i);
|
tempName = name + "_" + QString::number(++i);
|
||||||
name = tempName;
|
name = tempName;
|
||||||
data.set_name(name.toStdString());
|
data.set_name(name.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
users.insert(name, session);
|
users.insert(name, session);
|
||||||
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
||||||
|
|
||||||
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
|
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
|
||||||
databaseInterface->unlockSessionTables();
|
databaseInterface->unlockSessionTables();
|
||||||
|
|
||||||
usersBySessionId.insert(data.session_id(), session);
|
usersBySessionId.insert(data.session_id(), session);
|
||||||
|
|
||||||
qDebug() << "session id:" << data.session_id();
|
qDebug() << "session id:" << data.session_id();
|
||||||
session->setUserInfo(data);
|
session->setUserInfo(data);
|
||||||
|
|
||||||
Event_UserJoined event;
|
Event_UserJoined event;
|
||||||
event.mutable_user_info()->CopyFrom(session->copyUserInfo(false));
|
event.mutable_user_info()->CopyFrom(session->copyUserInfo(false));
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsUserListChanges())
|
if (clients[i]->getAcceptsUserListChanges())
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
delete se;
|
delete se;
|
||||||
|
|
||||||
event.mutable_user_info()->CopyFrom(session->copyUserInfo(true, true, true));
|
event.mutable_user_info()->CopyFrom(session->copyUserInfo(true, true, true));
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
sendIsl_SessionEvent(*se);
|
sendIsl_SessionEvent(*se);
|
||||||
delete se;
|
delete se;
|
||||||
|
|
||||||
return authState;
|
return authState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId)
|
void Server::addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId)
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&persistentPlayersLock);
|
QWriteLocker locker(&persistentPlayersLock);
|
||||||
persistentPlayers.insert(userName, PlayerReference(roomId, gameId, playerId));
|
persistentPlayers.insert(userName, PlayerReference(roomId, gameId, playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId)
|
void Server::removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId)
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&persistentPlayersLock);
|
QWriteLocker locker(&persistentPlayersLock);
|
||||||
persistentPlayers.remove(userName, PlayerReference(roomId, gameId, playerId));
|
persistentPlayers.remove(userName, PlayerReference(roomId, gameId, playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<PlayerReference> Server::getPersistentPlayerReferences(const QString &userName) const
|
QList<PlayerReference> Server::getPersistentPlayerReferences(const QString &userName) const
|
||||||
{
|
{
|
||||||
QReadLocker locker(&persistentPlayersLock);
|
QReadLocker locker(&persistentPlayersLock);
|
||||||
return persistentPlayers.values(userName);
|
return persistentPlayers.values(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_AbstractUserInterface *Server::findUser(const QString &userName) const
|
Server_AbstractUserInterface *Server::findUser(const QString &userName) const
|
||||||
{
|
{
|
||||||
// Call this only with clientsLock set.
|
// Call this only with clientsLock set.
|
||||||
|
|
||||||
Server_AbstractUserInterface *userHandler = users.value(userName);
|
Server_AbstractUserInterface *userHandler = users.value(userName);
|
||||||
if (userHandler)
|
if (userHandler)
|
||||||
return userHandler;
|
return userHandler;
|
||||||
else
|
else
|
||||||
return externalUsers.value(userName);
|
return externalUsers.value(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::addClient(Server_ProtocolHandler *client)
|
void Server::addClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&clientsLock);
|
QWriteLocker locker(&clientsLock);
|
||||||
clients << client;
|
clients << client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::removeClient(Server_ProtocolHandler *client)
|
void Server::removeClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&clientsLock);
|
QWriteLocker locker(&clientsLock);
|
||||||
clients.removeAt(clients.indexOf(client));
|
clients.removeAt(clients.indexOf(client));
|
||||||
ServerInfo_User *data = client->getUserInfo();
|
ServerInfo_User *data = client->getUserInfo();
|
||||||
if (data) {
|
if (data) {
|
||||||
Event_UserLeft event;
|
Event_UserLeft event;
|
||||||
event.set_name(data->name());
|
event.set_name(data->name());
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsUserListChanges())
|
if (clients[i]->getAcceptsUserListChanges())
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
sendIsl_SessionEvent(*se);
|
sendIsl_SessionEvent(*se);
|
||||||
delete se;
|
delete se;
|
||||||
|
|
||||||
users.remove(QString::fromStdString(data->name()));
|
users.remove(QString::fromStdString(data->name()));
|
||||||
qDebug() << "Server::removeClient: name=" << QString::fromStdString(data->name());
|
qDebug() << "Server::removeClient: name=" << QString::fromStdString(data->name());
|
||||||
|
|
||||||
if (data->has_session_id()) {
|
if (data->has_session_id()) {
|
||||||
const qint64 sessionId = data->session_id();
|
const qint64 sessionId = data->session_id();
|
||||||
usersBySessionId.remove(sessionId);
|
usersBySessionId.remove(sessionId);
|
||||||
emit endSession(sessionId);
|
emit endSession(sessionId);
|
||||||
qDebug() << "closed session id:" << sessionId;
|
qDebug() << "closed session id:" << sessionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left";
|
qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalUserJoined(const ServerInfo_User &userInfo)
|
void Server::externalUserJoined(const ServerInfo_User &userInfo)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
clientsLock.lockForWrite();
|
clientsLock.lockForWrite();
|
||||||
|
|
||||||
Server_RemoteUserInterface *newUser = new Server_RemoteUserInterface(this, ServerInfo_User_Container(userInfo));
|
Server_RemoteUserInterface *newUser = new Server_RemoteUserInterface(this, ServerInfo_User_Container(userInfo));
|
||||||
externalUsers.insert(QString::fromStdString(userInfo.name()), newUser);
|
externalUsers.insert(QString::fromStdString(userInfo.name()), newUser);
|
||||||
externalUsersBySessionId.insert(userInfo.session_id(), newUser);
|
externalUsersBySessionId.insert(userInfo.session_id(), newUser);
|
||||||
|
|
||||||
Event_UserJoined event;
|
Event_UserJoined event;
|
||||||
event.mutable_user_info()->CopyFrom(userInfo);
|
event.mutable_user_info()->CopyFrom(userInfo);
|
||||||
|
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsUserListChanges())
|
if (clients[i]->getAcceptsUserListChanges())
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
delete se;
|
delete se;
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
|
|
||||||
ResponseContainer rc(-1);
|
ResponseContainer rc(-1);
|
||||||
newUser->joinPersistentGames(rc);
|
newUser->joinPersistentGames(rc);
|
||||||
newUser->sendResponseContainer(rc, Response::RespNothing);
|
newUser->sendResponseContainer(rc, Response::RespNothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalUserLeft(const QString &userName)
|
void Server::externalUserLeft(const QString &userName)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
clientsLock.lockForWrite();
|
clientsLock.lockForWrite();
|
||||||
Server_AbstractUserInterface *user = externalUsers.take(userName);
|
Server_AbstractUserInterface *user = externalUsers.take(userName);
|
||||||
externalUsersBySessionId.remove(user->getUserInfo()->session_id());
|
externalUsersBySessionId.remove(user->getUserInfo()->session_id());
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
|
|
||||||
QMap<int, QPair<int, int> > userGames(user->getGames());
|
QMap<int, QPair<int, int> > userGames(user->getGames());
|
||||||
QMapIterator<int, QPair<int, int> > userGamesIterator(userGames);
|
QMapIterator<int, QPair<int, int> > userGamesIterator(userGames);
|
||||||
roomsLock.lockForRead();
|
roomsLock.lockForRead();
|
||||||
while (userGamesIterator.hasNext()) {
|
while (userGamesIterator.hasNext()) {
|
||||||
userGamesIterator.next();
|
userGamesIterator.next();
|
||||||
Server_Room *room = rooms.value(userGamesIterator.value().first);
|
Server_Room *room = rooms.value(userGamesIterator.value().first);
|
||||||
if (!room)
|
if (!room)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||||
Server_Game *game = room->getGames().value(userGamesIterator.key());
|
Server_Game *game = room->getGames().value(userGamesIterator.key());
|
||||||
if (!game)
|
if (!game)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QMutexLocker gameLocker(&game->gameMutex);
|
QMutexLocker gameLocker(&game->gameMutex);
|
||||||
Server_Player *player = game->getPlayers().value(userGamesIterator.value().second);
|
Server_Player *player = game->getPlayers().value(userGamesIterator.value().second);
|
||||||
if (!player)
|
if (!player)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
player->disconnectClient();
|
player->disconnectClient();
|
||||||
}
|
}
|
||||||
roomsLock.unlock();
|
roomsLock.unlock();
|
||||||
|
|
||||||
delete user;
|
delete user;
|
||||||
|
|
||||||
Event_UserLeft event;
|
Event_UserLeft event;
|
||||||
event.set_name(userName.toStdString());
|
event.set_name(userName.toStdString());
|
||||||
|
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
clientsLock.lockForRead();
|
clientsLock.lockForRead();
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsUserListChanges())
|
if (clients[i]->getAcceptsUserListChanges())
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
delete se;
|
delete se;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo)
|
void Server::externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
QReadLocker locker(&roomsLock);
|
QReadLocker locker(&roomsLock);
|
||||||
|
|
||||||
Server_Room *room = rooms.value(roomId);
|
Server_Room *room = rooms.value(roomId);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalRoomUserJoined: room id=" << roomId << "not found";
|
qDebug() << "externalRoomUserJoined: room id=" << roomId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
room->addExternalUser(userInfo);
|
room->addExternalUser(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalRoomUserLeft(int roomId, const QString &userName)
|
void Server::externalRoomUserLeft(int roomId, const QString &userName)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
QReadLocker locker(&roomsLock);
|
QReadLocker locker(&roomsLock);
|
||||||
|
|
||||||
Server_Room *room = rooms.value(roomId);
|
Server_Room *room = rooms.value(roomId);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalRoomUserLeft: room id=" << roomId << "not found";
|
qDebug() << "externalRoomUserLeft: room id=" << roomId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
room->removeExternalUser(userName);
|
room->removeExternalUser(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalRoomSay(int roomId, const QString &userName, const QString &message)
|
void Server::externalRoomSay(int roomId, const QString &userName, const QString &message)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
QReadLocker locker(&roomsLock);
|
QReadLocker locker(&roomsLock);
|
||||||
|
|
||||||
Server_Room *room = rooms.value(roomId);
|
Server_Room *room = rooms.value(roomId);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalRoomSay: room id=" << roomId << "not found";
|
qDebug() << "externalRoomSay: room id=" << roomId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
room->say(userName, message, false);
|
room->say(userName, message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo)
|
void Server::externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
QReadLocker locker(&roomsLock);
|
QReadLocker locker(&roomsLock);
|
||||||
|
|
||||||
Server_Room *room = rooms.value(roomId);
|
Server_Room *room = rooms.value(roomId);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalRoomGameListChanged: room id=" << roomId << "not found";
|
qDebug() << "externalRoomGameListChanged: room id=" << roomId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
room->updateExternalGameList(gameInfo);
|
room->updateExternalGameList(gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId)
|
void Server::externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
QReadLocker roomsLocker(&roomsLock);
|
QReadLocker roomsLocker(&roomsLock);
|
||||||
QReadLocker clientsLocker(&clientsLock);
|
QReadLocker clientsLocker(&clientsLock);
|
||||||
|
|
||||||
Server_Room *room = rooms.value(roomId);
|
Server_Room *room = rooms.value(roomId);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalJoinGameCommandReceived: room id=" << roomId << "not found";
|
qDebug() << "externalJoinGameCommandReceived: room id=" << roomId << "not found";
|
||||||
throw Response::RespNotInRoom;
|
throw Response::RespNotInRoom;
|
||||||
}
|
}
|
||||||
Server_AbstractUserInterface *userInterface = externalUsersBySessionId.value(sessionId);
|
Server_AbstractUserInterface *userInterface = externalUsersBySessionId.value(sessionId);
|
||||||
if (!userInterface) {
|
if (!userInterface) {
|
||||||
qDebug() << "externalJoinGameCommandReceived: session id=" << sessionId << "not found";
|
qDebug() << "externalJoinGameCommandReceived: session id=" << sessionId << "not found";
|
||||||
throw Response::RespNotInRoom;
|
throw Response::RespNotInRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseContainer responseContainer(cmdId);
|
ResponseContainer responseContainer(cmdId);
|
||||||
Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface);
|
Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface);
|
||||||
userInterface->sendResponseContainer(responseContainer, responseCode);
|
userInterface->sendResponseContainer(responseContainer, responseCode);
|
||||||
} catch (Response::ResponseCode code) {
|
} catch (Response::ResponseCode code) {
|
||||||
Response response;
|
Response response;
|
||||||
response.set_cmd_id(cmdId);
|
response.set_cmd_id(cmdId);
|
||||||
response.set_response_code(code);
|
response.set_response_code(code);
|
||||||
|
|
||||||
sendIsl_Response(response, serverId, sessionId);
|
sendIsl_Response(response, serverId, sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId)
|
void Server::externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResponseContainer responseContainer(cont.cmd_id());
|
ResponseContainer responseContainer(cont.cmd_id());
|
||||||
Response::ResponseCode finalResponseCode = Response::RespOk;
|
Response::ResponseCode finalResponseCode = Response::RespOk;
|
||||||
|
|
||||||
QReadLocker roomsLocker(&roomsLock);
|
QReadLocker roomsLocker(&roomsLock);
|
||||||
Server_Room *room = rooms.value(cont.room_id());
|
Server_Room *room = rooms.value(cont.room_id());
|
||||||
if (!room) {
|
if (!room) {
|
||||||
qDebug() << "externalGameCommandContainerReceived: room id=" << cont.room_id() << "not found";
|
qDebug() << "externalGameCommandContainerReceived: room id=" << cont.room_id() << "not found";
|
||||||
throw Response::RespNotInRoom;
|
throw Response::RespNotInRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||||
Server_Game *game = room->getGames().value(cont.game_id());
|
Server_Game *game = room->getGames().value(cont.game_id());
|
||||||
if (!game) {
|
if (!game) {
|
||||||
qDebug() << "externalGameCommandContainerReceived: game id=" << cont.game_id() << "not found";
|
qDebug() << "externalGameCommandContainerReceived: game id=" << cont.game_id() << "not found";
|
||||||
throw Response::RespNotInRoom;
|
throw Response::RespNotInRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker gameLocker(&game->gameMutex);
|
QMutexLocker gameLocker(&game->gameMutex);
|
||||||
Server_Player *player = game->getPlayers().value(playerId);
|
Server_Player *player = game->getPlayers().value(playerId);
|
||||||
if (!player) {
|
if (!player) {
|
||||||
qDebug() << "externalGameCommandContainerReceived: player id=" << playerId << "not found";
|
qDebug() << "externalGameCommandContainerReceived: player id=" << playerId << "not found";
|
||||||
throw Response::RespNotInRoom;
|
throw Response::RespNotInRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEventStorage ges;
|
GameEventStorage ges;
|
||||||
for (int i = cont.game_command_size() - 1; i >= 0; --i) {
|
for (int i = cont.game_command_size() - 1; i >= 0; --i) {
|
||||||
const GameCommand &sc = cont.game_command(i);
|
const GameCommand &sc = cont.game_command(i);
|
||||||
qDebug() << "[ISL]" << QString::fromStdString(sc.ShortDebugString());
|
qDebug() << "[ISL]" << QString::fromStdString(sc.ShortDebugString());
|
||||||
|
|
||||||
Response::ResponseCode resp = player->processGameCommand(sc, responseContainer, ges);
|
Response::ResponseCode resp = player->processGameCommand(sc, responseContainer, ges);
|
||||||
|
|
||||||
if (resp != Response::RespOk)
|
if (resp != Response::RespOk)
|
||||||
finalResponseCode = resp;
|
finalResponseCode = resp;
|
||||||
}
|
}
|
||||||
ges.sendToGame(game);
|
ges.sendToGame(game);
|
||||||
|
|
||||||
if (finalResponseCode != Response::RespNothing) {
|
if (finalResponseCode != Response::RespNothing) {
|
||||||
player->playerMutex.lock();
|
player->playerMutex.lock();
|
||||||
player->getUserInterface()->sendResponseContainer(responseContainer, finalResponseCode);
|
player->getUserInterface()->sendResponseContainer(responseContainer, finalResponseCode);
|
||||||
player->playerMutex.unlock();
|
player->playerMutex.unlock();
|
||||||
}
|
}
|
||||||
} catch (Response::ResponseCode code) {
|
} catch (Response::ResponseCode code) {
|
||||||
Response response;
|
Response response;
|
||||||
response.set_cmd_id(cont.cmd_id());
|
response.set_cmd_id(cont.cmd_id());
|
||||||
response.set_response_code(code);
|
response.set_response_code(code);
|
||||||
|
|
||||||
sendIsl_Response(response, serverId, sessionId);
|
sendIsl_Response(response, serverId, sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId)
|
void Server::externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
QReadLocker usersLocker(&clientsLock);
|
QReadLocker usersLocker(&clientsLock);
|
||||||
|
|
||||||
Server_ProtocolHandler *client = usersBySessionId.value(sessionId);
|
Server_ProtocolHandler *client = usersBySessionId.value(sessionId);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
qDebug() << "externalGameEventContainerReceived: session" << sessionId << "not found";
|
qDebug() << "externalGameEventContainerReceived: session" << sessionId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client->sendProtocolItem(cont);
|
client->sendProtocolItem(cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::externalResponseReceived(const Response &resp, qint64 sessionId)
|
void Server::externalResponseReceived(const Response &resp, qint64 sessionId)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
QReadLocker usersLocker(&clientsLock);
|
QReadLocker usersLocker(&clientsLock);
|
||||||
|
|
||||||
Server_ProtocolHandler *client = usersBySessionId.value(sessionId);
|
Server_ProtocolHandler *client = usersBySessionId.value(sessionId);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
qDebug() << "externalResponseReceived: session" << sessionId << "not found";
|
qDebug() << "externalResponseReceived: session" << sessionId << "not found";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client->sendProtocolItem(resp);
|
client->sendProtocolItem(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl)
|
void Server::broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl)
|
||||||
{
|
{
|
||||||
// This function is always called from the main thread via signal/slot.
|
// This function is always called from the main thread via signal/slot.
|
||||||
|
|
||||||
Event_ListRooms event;
|
Event_ListRooms event;
|
||||||
event.add_room_list()->CopyFrom(roomInfo);
|
event.add_room_list()->CopyFrom(roomInfo);
|
||||||
|
|
||||||
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
|
|
||||||
clientsLock.lockForRead();
|
clientsLock.lockForRead();
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
if (clients[i]->getAcceptsRoomListChanges())
|
if (clients[i]->getAcceptsRoomListChanges())
|
||||||
clients[i]->sendProtocolItem(*se);
|
clients[i]->sendProtocolItem(*se);
|
||||||
clientsLock.unlock();
|
clientsLock.unlock();
|
||||||
|
|
||||||
if (sendToIsl)
|
if (sendToIsl)
|
||||||
sendIsl_SessionEvent(*se);
|
sendIsl_SessionEvent(*se);
|
||||||
|
|
||||||
delete se;
|
delete se;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::addRoom(Server_Room *newRoom)
|
void Server::addRoom(Server_Room *newRoom)
|
||||||
{
|
{
|
||||||
QWriteLocker locker(&roomsLock);
|
QWriteLocker locker(&roomsLock);
|
||||||
qDebug() << "Adding room: ID=" << newRoom->getId() << "name=" << newRoom->getName();
|
qDebug() << "Adding room: ID=" << newRoom->getId() << "name=" << newRoom->getName();
|
||||||
rooms.insert(newRoom->getId(), newRoom);
|
rooms.insert(newRoom->getId(), newRoom);
|
||||||
connect(newRoom, SIGNAL(roomInfoChanged(ServerInfo_Room)), this, SLOT(broadcastRoomUpdate(const ServerInfo_Room &)), Qt::QueuedConnection);
|
connect(newRoom, SIGNAL(roomInfoChanged(ServerInfo_Room)), this, SLOT(broadcastRoomUpdate(const ServerInfo_Room &)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::getUsersCount() const
|
int Server::getUsersCount() const
|
||||||
{
|
{
|
||||||
QReadLocker locker(&clientsLock);
|
QReadLocker locker(&clientsLock);
|
||||||
return users.size();
|
return users.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::getGamesCount() const
|
int Server::getGamesCount() const
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
QReadLocker locker(&roomsLock);
|
QReadLocker locker(&roomsLock);
|
||||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||||
while (roomIterator.hasNext()) {
|
while (roomIterator.hasNext()) {
|
||||||
Server_Room *room = roomIterator.next().value();
|
Server_Room *room = roomIterator.next().value();
|
||||||
QReadLocker roomLocker(&room->gamesLock);
|
QReadLocker roomLocker(&room->gamesLock);
|
||||||
result += room->getGames().size();
|
result += room->getGames().size();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_Response(const Response &item, int serverId, qint64 sessionId)
|
void Server::sendIsl_Response(const Response &item, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::RESPONSE);
|
msg.set_message_type(IslMessage::RESPONSE);
|
||||||
if (sessionId != -1)
|
if (sessionId != -1)
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
msg.mutable_response()->CopyFrom(item);
|
msg.mutable_response()->CopyFrom(item);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_SessionEvent(const SessionEvent &item, int serverId, qint64 sessionId)
|
void Server::sendIsl_SessionEvent(const SessionEvent &item, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::SESSION_EVENT);
|
msg.set_message_type(IslMessage::SESSION_EVENT);
|
||||||
if (sessionId != -1)
|
if (sessionId != -1)
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
msg.mutable_session_event()->CopyFrom(item);
|
msg.mutable_session_event()->CopyFrom(item);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_GameEventContainer(const GameEventContainer &item, int serverId, qint64 sessionId)
|
void Server::sendIsl_GameEventContainer(const GameEventContainer &item, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::GAME_EVENT_CONTAINER);
|
msg.set_message_type(IslMessage::GAME_EVENT_CONTAINER);
|
||||||
if (sessionId != -1)
|
if (sessionId != -1)
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
msg.mutable_game_event_container()->CopyFrom(item);
|
msg.mutable_game_event_container()->CopyFrom(item);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_RoomEvent(const RoomEvent &item, int serverId, qint64 sessionId)
|
void Server::sendIsl_RoomEvent(const RoomEvent &item, int serverId, qint64 sessionId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::ROOM_EVENT);
|
msg.set_message_type(IslMessage::ROOM_EVENT);
|
||||||
if (sessionId != -1)
|
if (sessionId != -1)
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
msg.mutable_room_event()->CopyFrom(item);
|
msg.mutable_room_event()->CopyFrom(item);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId)
|
void Server::sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::GAME_COMMAND_CONTAINER);
|
msg.set_message_type(IslMessage::GAME_COMMAND_CONTAINER);
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
msg.set_player_id(playerId);
|
msg.set_player_id(playerId);
|
||||||
|
|
||||||
CommandContainer *cont = msg.mutable_game_command();
|
CommandContainer *cont = msg.mutable_game_command();
|
||||||
cont->CopyFrom(item);
|
cont->CopyFrom(item);
|
||||||
cont->set_room_id(roomId);
|
cont->set_room_id(roomId);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId)
|
void Server::sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId)
|
||||||
{
|
{
|
||||||
IslMessage msg;
|
IslMessage msg;
|
||||||
msg.set_message_type(IslMessage::ROOM_COMMAND_CONTAINER);
|
msg.set_message_type(IslMessage::ROOM_COMMAND_CONTAINER);
|
||||||
msg.set_session_id(sessionId);
|
msg.set_session_id(sessionId);
|
||||||
|
|
||||||
CommandContainer *cont = msg.mutable_room_command();
|
CommandContainer *cont = msg.mutable_room_command();
|
||||||
cont->CopyFrom(item);
|
cont->CopyFrom(item);
|
||||||
cont->set_room_id(roomId);
|
cont->set_room_id(roomId);
|
||||||
|
|
||||||
emit sigSendIslMessage(msg, serverId);
|
emit sigSendIslMessage(msg, serverId);
|
||||||
}
|
}
|
||||||
|
|
152
common/server.h
152
common/server.h
|
@ -31,87 +31,87 @@ enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2,
|
||||||
|
|
||||||
class Server : public QObject
|
class Server : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void pingClockTimeout();
|
void pingClockTimeout();
|
||||||
void sigSendIslMessage(const IslMessage &message, int serverId);
|
void sigSendIslMessage(const IslMessage &message, int serverId);
|
||||||
void endSession(qint64 sessionId);
|
void endSession(qint64 sessionId);
|
||||||
private slots:
|
private slots:
|
||||||
void broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl = false);
|
void broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl = false);
|
||||||
public:
|
public:
|
||||||
mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock
|
mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock
|
||||||
Server(bool _threaded, QObject *parent = 0);
|
Server(bool _threaded, QObject *parent = 0);
|
||||||
~Server();
|
~Server();
|
||||||
void setThreaded(bool _threaded) { threaded = _threaded; }
|
void setThreaded(bool _threaded) { threaded = _threaded; }
|
||||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
|
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
|
||||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||||
|
|
||||||
Server_AbstractUserInterface *findUser(const QString &userName) const;
|
Server_AbstractUserInterface *findUser(const QString &userName) const;
|
||||||
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
||||||
const QMap<qint64, Server_ProtocolHandler *> &getUsersBySessionId() const { return usersBySessionId; }
|
const QMap<qint64, Server_ProtocolHandler *> &getUsersBySessionId() const { return usersBySessionId; }
|
||||||
void addClient(Server_ProtocolHandler *player);
|
void addClient(Server_ProtocolHandler *player);
|
||||||
void removeClient(Server_ProtocolHandler *player);
|
void removeClient(Server_ProtocolHandler *player);
|
||||||
virtual QString getLoginMessage() const { return QString(); }
|
virtual QString getLoginMessage() const { return QString(); }
|
||||||
|
|
||||||
virtual bool getGameShouldPing() const { return false; }
|
virtual bool getGameShouldPing() const { return false; }
|
||||||
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
||||||
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||||
virtual int getMessageCountingInterval() const { return 0; }
|
virtual int getMessageCountingInterval() const { return 0; }
|
||||||
virtual int getMaxMessageCountPerInterval() const { return 0; }
|
virtual int getMaxMessageCountPerInterval() const { return 0; }
|
||||||
virtual int getMaxMessageSizePerInterval() const { return 0; }
|
virtual int getMaxMessageSizePerInterval() const { return 0; }
|
||||||
virtual int getMaxGamesPerUser() const { return 0; }
|
virtual int getMaxGamesPerUser() const { return 0; }
|
||||||
virtual bool getThreaded() const { return false; }
|
virtual bool getThreaded() const { return false; }
|
||||||
|
|
||||||
Server_DatabaseInterface *getDatabaseInterface() const;
|
Server_DatabaseInterface *getDatabaseInterface() const;
|
||||||
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
|
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
|
||||||
|
|
||||||
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
||||||
void sendIsl_SessionEvent(const SessionEvent &item, int serverId = -1, qint64 sessionId = -1);
|
void sendIsl_SessionEvent(const SessionEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||||
void sendIsl_GameEventContainer(const GameEventContainer &item, int serverId = -1, qint64 sessionId = -1);
|
void sendIsl_GameEventContainer(const GameEventContainer &item, int serverId = -1, qint64 sessionId = -1);
|
||||||
void sendIsl_RoomEvent(const RoomEvent &item, int serverId = -1, qint64 sessionId = -1);
|
void sendIsl_RoomEvent(const RoomEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||||
void sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId);
|
void sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId);
|
||||||
void sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId);
|
void sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId);
|
||||||
|
|
||||||
void addExternalUser(const ServerInfo_User &userInfo);
|
void addExternalUser(const ServerInfo_User &userInfo);
|
||||||
void removeExternalUser(const QString &userName);
|
void removeExternalUser(const QString &userName);
|
||||||
const QMap<QString, Server_AbstractUserInterface *> &getExternalUsers() const { return externalUsers; }
|
const QMap<QString, Server_AbstractUserInterface *> &getExternalUsers() const { return externalUsers; }
|
||||||
|
|
||||||
void addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
void addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||||
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||||
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
||||||
private:
|
private:
|
||||||
bool threaded;
|
bool threaded;
|
||||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||||
mutable QReadWriteLock persistentPlayersLock;
|
mutable QReadWriteLock persistentPlayersLock;
|
||||||
int nextLocalGameId;
|
int nextLocalGameId;
|
||||||
QMutex nextLocalGameIdMutex;
|
QMutex nextLocalGameIdMutex;
|
||||||
protected slots:
|
protected slots:
|
||||||
void externalUserJoined(const ServerInfo_User &userInfo);
|
void externalUserJoined(const ServerInfo_User &userInfo);
|
||||||
void externalUserLeft(const QString &userName);
|
void externalUserLeft(const QString &userName);
|
||||||
void externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo);
|
void externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo);
|
||||||
void externalRoomUserLeft(int roomId, const QString &userName);
|
void externalRoomUserLeft(int roomId, const QString &userName);
|
||||||
void externalRoomSay(int roomId, const QString &userName, const QString &message);
|
void externalRoomSay(int roomId, const QString &userName, const QString &message);
|
||||||
void externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo);
|
void externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo);
|
||||||
void externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId);
|
void externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId);
|
||||||
void externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId);
|
void externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId);
|
||||||
void externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId);
|
void externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId);
|
||||||
void externalResponseReceived(const Response &resp, qint64 sessionId);
|
void externalResponseReceived(const Response &resp, qint64 sessionId);
|
||||||
|
|
||||||
virtual void doSendIslMessage(const IslMessage &msg, int serverId) { }
|
virtual void doSendIslMessage(const IslMessage &msg, int serverId) { }
|
||||||
protected:
|
protected:
|
||||||
void prepareDestroy();
|
void prepareDestroy();
|
||||||
void setDatabaseInterface(Server_DatabaseInterface *_databaseInterface);
|
void setDatabaseInterface(Server_DatabaseInterface *_databaseInterface);
|
||||||
QList<Server_ProtocolHandler *> clients;
|
QList<Server_ProtocolHandler *> clients;
|
||||||
QMap<qint64, Server_ProtocolHandler *> usersBySessionId;
|
QMap<qint64, Server_ProtocolHandler *> usersBySessionId;
|
||||||
QMap<QString, Server_ProtocolHandler *> users;
|
QMap<QString, Server_ProtocolHandler *> users;
|
||||||
QMap<qint64, Server_AbstractUserInterface *> externalUsersBySessionId;
|
QMap<qint64, Server_AbstractUserInterface *> externalUsersBySessionId;
|
||||||
QMap<QString, Server_AbstractUserInterface *> externalUsers;
|
QMap<QString, Server_AbstractUserInterface *> externalUsers;
|
||||||
QMap<int, Server_Room *> rooms;
|
QMap<int, Server_Room *> rooms;
|
||||||
QMap<QThread *, Server_DatabaseInterface *> databaseInterfaces;
|
QMap<QThread *, Server_DatabaseInterface *> databaseInterfaces;
|
||||||
|
|
||||||
int getUsersCount() const;
|
int getUsersCount() const;
|
||||||
int getGamesCount() const;
|
int getGamesCount() const;
|
||||||
void addRoom(Server_Room *newRoom);
|
void addRoom(Server_Room *newRoom);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,82 +15,82 @@
|
||||||
|
|
||||||
void Server_AbstractUserInterface::sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item)
|
void Server_AbstractUserInterface::sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ServerMessage::RESPONSE: sendProtocolItem(static_cast<const Response &>(item)); break;
|
case ServerMessage::RESPONSE: sendProtocolItem(static_cast<const Response &>(item)); break;
|
||||||
case ServerMessage::SESSION_EVENT: sendProtocolItem(static_cast<const SessionEvent &>(item)); break;
|
case ServerMessage::SESSION_EVENT: sendProtocolItem(static_cast<const SessionEvent &>(item)); break;
|
||||||
case ServerMessage::GAME_EVENT_CONTAINER: sendProtocolItem(static_cast<const GameEventContainer &>(item)); break;
|
case ServerMessage::GAME_EVENT_CONTAINER: sendProtocolItem(static_cast<const GameEventContainer &>(item)); break;
|
||||||
case ServerMessage::ROOM_EVENT: sendProtocolItem(static_cast<const RoomEvent &>(item)); break;
|
case ServerMessage::ROOM_EVENT: sendProtocolItem(static_cast<const RoomEvent &>(item)); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionEvent *Server_AbstractUserInterface::prepareSessionEvent(const ::google::protobuf::Message &sessionEvent)
|
SessionEvent *Server_AbstractUserInterface::prepareSessionEvent(const ::google::protobuf::Message &sessionEvent)
|
||||||
{
|
{
|
||||||
SessionEvent *event = new SessionEvent;
|
SessionEvent *event = new SessionEvent;
|
||||||
event->GetReflection()->MutableMessage(event, sessionEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(sessionEvent);
|
event->GetReflection()->MutableMessage(event, sessionEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(sessionEvent);
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_AbstractUserInterface::sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode)
|
void Server_AbstractUserInterface::sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode)
|
||||||
{
|
{
|
||||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &preResponseQueue = responseContainer.getPreResponseQueue();
|
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &preResponseQueue = responseContainer.getPreResponseQueue();
|
||||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||||
sendProtocolItemByType(preResponseQueue[i].first, *preResponseQueue[i].second);
|
sendProtocolItemByType(preResponseQueue[i].first, *preResponseQueue[i].second);
|
||||||
|
|
||||||
if (responseCode != Response::RespNothing) {
|
if (responseCode != Response::RespNothing) {
|
||||||
Response response;
|
Response response;
|
||||||
response.set_cmd_id(responseContainer.getCmdId());
|
response.set_cmd_id(responseContainer.getCmdId());
|
||||||
response.set_response_code(responseCode);
|
response.set_response_code(responseCode);
|
||||||
::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
||||||
if (responseExtension)
|
if (responseExtension)
|
||||||
response.GetReflection()->MutableMessage(&response, responseExtension->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*responseExtension);
|
response.GetReflection()->MutableMessage(&response, responseExtension->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*responseExtension);
|
||||||
sendProtocolItem(response);
|
sendProtocolItem(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &postResponseQueue = responseContainer.getPostResponseQueue();
|
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &postResponseQueue = responseContainer.getPostResponseQueue();
|
||||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||||
sendProtocolItemByType(postResponseQueue[i].first, *postResponseQueue[i].second);
|
sendProtocolItemByType(postResponseQueue[i].first, *postResponseQueue[i].second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_AbstractUserInterface::playerRemovedFromGame(Server_Game *game)
|
void Server_AbstractUserInterface::playerRemovedFromGame(Server_Game *game)
|
||||||
{
|
{
|
||||||
qDebug() << "Server_AbstractUserInterface::playerRemovedFromGame(): gameId =" << game->getGameId();
|
qDebug() << "Server_AbstractUserInterface::playerRemovedFromGame(): gameId =" << game->getGameId();
|
||||||
|
|
||||||
QMutexLocker locker(&gameListMutex);
|
QMutexLocker locker(&gameListMutex);
|
||||||
games.remove(game->getGameId());
|
games.remove(game->getGameId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_AbstractUserInterface::playerAddedToGame(int gameId, int roomId, int playerId)
|
void Server_AbstractUserInterface::playerAddedToGame(int gameId, int roomId, int playerId)
|
||||||
{
|
{
|
||||||
qDebug() << "Server_AbstractUserInterface::playerAddedToGame(): gameId =" << gameId;
|
qDebug() << "Server_AbstractUserInterface::playerAddedToGame(): gameId =" << gameId;
|
||||||
|
|
||||||
QMutexLocker locker(&gameListMutex);
|
QMutexLocker locker(&gameListMutex);
|
||||||
games.insert(gameId, QPair<int, int>(roomId, playerId));
|
games.insert(gameId, QPair<int, int>(roomId, playerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_AbstractUserInterface::joinPersistentGames(ResponseContainer &rc)
|
void Server_AbstractUserInterface::joinPersistentGames(ResponseContainer &rc)
|
||||||
{
|
{
|
||||||
QList<PlayerReference> gamesToJoin = server->getPersistentPlayerReferences(QString::fromStdString(userInfo->name()));
|
QList<PlayerReference> gamesToJoin = server->getPersistentPlayerReferences(QString::fromStdString(userInfo->name()));
|
||||||
|
|
||||||
server->roomsLock.lockForRead();
|
server->roomsLock.lockForRead();
|
||||||
for (int i = 0; i < gamesToJoin.size(); ++i) {
|
for (int i = 0; i < gamesToJoin.size(); ++i) {
|
||||||
const PlayerReference &pr = gamesToJoin.at(i);
|
const PlayerReference &pr = gamesToJoin.at(i);
|
||||||
|
|
||||||
Server_Room *room = server->getRooms().value(pr.getRoomId());
|
Server_Room *room = server->getRooms().value(pr.getRoomId());
|
||||||
if (!room)
|
if (!room)
|
||||||
continue;
|
continue;
|
||||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||||
|
|
||||||
Server_Game *game = room->getGames().value(pr.getGameId());
|
Server_Game *game = room->getGames().value(pr.getGameId());
|
||||||
if (!game)
|
if (!game)
|
||||||
continue;
|
continue;
|
||||||
QMutexLocker gameLocker(&game->gameMutex);
|
QMutexLocker gameLocker(&game->gameMutex);
|
||||||
|
|
||||||
Server_Player *player = game->getPlayers().value(pr.getPlayerId());
|
Server_Player *player = game->getPlayers().value(pr.getPlayerId());
|
||||||
|
|
||||||
player->setUserInterface(this);
|
player->setUserInterface(this);
|
||||||
playerAddedToGame(game->getGameId(), room->getId(), player->getPlayerId());
|
playerAddedToGame(game->getGameId(), room->getId(), player->getPlayerId());
|
||||||
|
|
||||||
game->createGameJoinedEvent(player, rc, true);
|
game->createGameJoinedEvent(player, rc, true);
|
||||||
}
|
}
|
||||||
server->roomsLock.unlock();
|
server->roomsLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,31 +18,31 @@ class Server_Game;
|
||||||
|
|
||||||
class Server_AbstractUserInterface : public ServerInfo_User_Container {
|
class Server_AbstractUserInterface : public ServerInfo_User_Container {
|
||||||
private:
|
private:
|
||||||
mutable QMutex gameListMutex;
|
mutable QMutex gameListMutex;
|
||||||
QMap<int, QPair<int, int> > games; // gameId -> (roomId, playerId)
|
QMap<int, QPair<int, int> > games; // gameId -> (roomId, playerId)
|
||||||
protected:
|
protected:
|
||||||
Server *server;
|
Server *server;
|
||||||
public:
|
public:
|
||||||
Server_AbstractUserInterface(Server *_server) : server(_server) { }
|
Server_AbstractUserInterface(Server *_server) : server(_server) { }
|
||||||
Server_AbstractUserInterface(Server *_server, const ServerInfo_User_Container &other) : ServerInfo_User_Container(other), server(_server) { }
|
Server_AbstractUserInterface(Server *_server, const ServerInfo_User_Container &other) : ServerInfo_User_Container(other), server(_server) { }
|
||||||
virtual ~Server_AbstractUserInterface() { }
|
virtual ~Server_AbstractUserInterface() { }
|
||||||
|
|
||||||
virtual int getLastCommandTime() const = 0;
|
virtual int getLastCommandTime() const = 0;
|
||||||
|
|
||||||
void playerRemovedFromGame(Server_Game *game);
|
void playerRemovedFromGame(Server_Game *game);
|
||||||
void playerAddedToGame(int gameId, int roomId, int playerId);
|
void playerAddedToGame(int gameId, int roomId, int playerId);
|
||||||
void joinPersistentGames(ResponseContainer &rc);
|
void joinPersistentGames(ResponseContainer &rc);
|
||||||
|
|
||||||
QMap<int, QPair<int, int> > getGames() const { QMutexLocker locker(&gameListMutex); return games; }
|
QMap<int, QPair<int, int> > getGames() const { QMutexLocker locker(&gameListMutex); return games; }
|
||||||
|
|
||||||
virtual void sendProtocolItem(const Response &item) = 0;
|
virtual void sendProtocolItem(const Response &item) = 0;
|
||||||
virtual void sendProtocolItem(const SessionEvent &item) = 0;
|
virtual void sendProtocolItem(const SessionEvent &item) = 0;
|
||||||
virtual void sendProtocolItem(const GameEventContainer &item) = 0;
|
virtual void sendProtocolItem(const GameEventContainer &item) = 0;
|
||||||
virtual void sendProtocolItem(const RoomEvent &item) = 0;
|
virtual void sendProtocolItem(const RoomEvent &item) = 0;
|
||||||
void sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item);
|
void sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item);
|
||||||
|
|
||||||
static SessionEvent *prepareSessionEvent(const ::google::protobuf::Message &sessionEvent);
|
static SessionEvent *prepareSessionEvent(const ::google::protobuf::Message &sessionEvent);
|
||||||
void sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode);
|
void sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,17 +14,17 @@ Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget
|
||||||
|
|
||||||
void Server_Arrow::getInfo(ServerInfo_Arrow *info)
|
void Server_Arrow::getInfo(ServerInfo_Arrow *info)
|
||||||
{
|
{
|
||||||
info->set_id(id);
|
info->set_id(id);
|
||||||
info->set_start_player_id(startCard->getZone()->getPlayer()->getPlayerId());
|
info->set_start_player_id(startCard->getZone()->getPlayer()->getPlayerId());
|
||||||
info->set_start_zone(startCard->getZone()->getName().toStdString());
|
info->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||||
info->set_start_card_id(startCard->getId());
|
info->set_start_card_id(startCard->getId());
|
||||||
info->mutable_arrow_color()->CopyFrom(arrowColor);
|
info->mutable_arrow_color()->CopyFrom(arrowColor);
|
||||||
|
|
||||||
Server_Card *targetCard = qobject_cast<Server_Card *>(targetItem);
|
Server_Card *targetCard = qobject_cast<Server_Card *>(targetItem);
|
||||||
if (targetCard) {
|
if (targetCard) {
|
||||||
info->set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerId());
|
info->set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerId());
|
||||||
info->set_target_zone(targetCard->getZone()->getName().toStdString());
|
info->set_target_zone(targetCard->getZone()->getName().toStdString());
|
||||||
info->set_target_card_id(targetCard->getId());
|
info->set_target_card_id(targetCard->getId());
|
||||||
} else
|
} else
|
||||||
info->set_target_player_id(static_cast<Server_Player *>(targetItem)->getPlayerId());
|
info->set_target_player_id(static_cast<Server_Player *>(targetItem)->getPlayerId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,18 @@ class ServerInfo_Arrow;
|
||||||
|
|
||||||
class Server_Arrow {
|
class Server_Arrow {
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
Server_Card *startCard;
|
Server_Card *startCard;
|
||||||
Server_ArrowTarget *targetItem;
|
Server_ArrowTarget *targetItem;
|
||||||
color arrowColor;
|
color arrowColor;
|
||||||
public:
|
public:
|
||||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
|
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
Server_Card *getStartCard() const { return startCard; }
|
Server_Card *getStartCard() const { return startCard; }
|
||||||
Server_ArrowTarget *getTargetItem() const { return targetItem; }
|
Server_ArrowTarget *getTargetItem() const { return targetItem; }
|
||||||
const color &getColor() const { return arrowColor; }
|
const color &getColor() const { return arrowColor; }
|
||||||
|
|
||||||
void getInfo(ServerInfo_Arrow *info);
|
void getInfo(ServerInfo_Arrow *info);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
#include "server_arrowtarget.h"
|
#include "server_arrowtarget.h"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class Server_ArrowTarget : public QObject {
|
class Server_ArrowTarget : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,138 +23,138 @@
|
||||||
#include "pb/serverinfo_card.pb.h"
|
#include "pb/serverinfo_card.pb.h"
|
||||||
|
|
||||||
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||||
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_Card::~Server_Card()
|
Server_Card::~Server_Card()
|
||||||
{
|
{
|
||||||
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
||||||
while (!attachedCards.isEmpty())
|
while (!attachedCards.isEmpty())
|
||||||
attachedCards.first()->setParentCard(0);
|
attachedCards.first()->setParentCard(0);
|
||||||
|
|
||||||
if (parentCard)
|
if (parentCard)
|
||||||
parentCard->removeAttachedCard(this);
|
parentCard->removeAttachedCard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Card::resetState()
|
void Server_Card::resetState()
|
||||||
{
|
{
|
||||||
counters.clear();
|
counters.clear();
|
||||||
setTapped(false);
|
setTapped(false);
|
||||||
setAttacking(false);
|
setAttacking(false);
|
||||||
power = -1;
|
power = -1;
|
||||||
toughness = -1;
|
toughness = -1;
|
||||||
setAnnotation(QString());
|
setAnnotation(QString());
|
||||||
setDoesntUntap(false);
|
setDoesntUntap(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
|
QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
|
||||||
{
|
{
|
||||||
switch (attribute) {
|
switch (attribute) {
|
||||||
case AttrTapped: {
|
case AttrTapped: {
|
||||||
bool value = avalue == "1";
|
bool value = avalue == "1";
|
||||||
if (!(!value && allCards && doesntUntap))
|
if (!(!value && allCards && doesntUntap))
|
||||||
setTapped(value);
|
setTapped(value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AttrAttacking: setAttacking(avalue == "1"); break;
|
case AttrAttacking: setAttacking(avalue == "1"); break;
|
||||||
case AttrFaceDown: setFaceDown(avalue == "1"); break;
|
case AttrFaceDown: setFaceDown(avalue == "1"); break;
|
||||||
case AttrColor: setColor(avalue); break;
|
case AttrColor: setColor(avalue); break;
|
||||||
case AttrPT: setPT(avalue); return getPT();
|
case AttrPT: setPT(avalue); return getPT();
|
||||||
case AttrAnnotation: setAnnotation(avalue); break;
|
case AttrAnnotation: setAnnotation(avalue); break;
|
||||||
case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break;
|
case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break;
|
||||||
}
|
}
|
||||||
return avalue;
|
return avalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Card::setCounter(int id, int value)
|
void Server_Card::setCounter(int id, int value)
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
counters.insert(id, value);
|
counters.insert(id, value);
|
||||||
else
|
else
|
||||||
counters.remove(id);
|
counters.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Card::setPT(const QString &_pt)
|
void Server_Card::setPT(const QString &_pt)
|
||||||
{
|
{
|
||||||
if (_pt.isEmpty()) {
|
if (_pt.isEmpty()) {
|
||||||
power = 0;
|
power = 0;
|
||||||
toughness = -1;
|
toughness = -1;
|
||||||
} else {
|
} else {
|
||||||
int sep = _pt.indexOf('/');
|
int sep = _pt.indexOf('/');
|
||||||
QString p1 = _pt.left(sep);
|
QString p1 = _pt.left(sep);
|
||||||
QString p2 = _pt.mid(sep + 1);
|
QString p2 = _pt.mid(sep + 1);
|
||||||
if (p1.isEmpty() || p2.isEmpty())
|
if (p1.isEmpty() || p2.isEmpty())
|
||||||
return;
|
return;
|
||||||
if ((p1[0] == '+') || (p2[0] == '+')) {
|
if ((p1[0] == '+') || (p2[0] == '+')) {
|
||||||
if (power < 0)
|
if (power < 0)
|
||||||
power = 0;
|
power = 0;
|
||||||
if (toughness < 0)
|
if (toughness < 0)
|
||||||
toughness = 0;
|
toughness = 0;
|
||||||
}
|
}
|
||||||
if (p1[0] == '+')
|
if (p1[0] == '+')
|
||||||
power += p1.mid(1).toInt();
|
power += p1.mid(1).toInt();
|
||||||
else
|
else
|
||||||
power = p1.toInt();
|
power = p1.toInt();
|
||||||
if (p2[0] == '+')
|
if (p2[0] == '+')
|
||||||
toughness += p2.mid(1).toInt();
|
toughness += p2.mid(1).toInt();
|
||||||
else
|
else
|
||||||
toughness = p2.toInt();
|
toughness = p2.toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Server_Card::getPT() const
|
QString Server_Card::getPT() const
|
||||||
{
|
{
|
||||||
if (toughness < 0)
|
if (toughness < 0)
|
||||||
return QString("");
|
return QString("");
|
||||||
return QString::number(power) + "/" + QString::number(toughness);
|
return QString::number(power) + "/" + QString::number(toughness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Card::setParentCard(Server_Card *_parentCard)
|
void Server_Card::setParentCard(Server_Card *_parentCard)
|
||||||
{
|
{
|
||||||
if (parentCard)
|
if (parentCard)
|
||||||
parentCard->removeAttachedCard(this);
|
parentCard->removeAttachedCard(this);
|
||||||
parentCard = _parentCard;
|
parentCard = _parentCard;
|
||||||
if (parentCard)
|
if (parentCard)
|
||||||
parentCard->addAttachedCard(this);
|
parentCard->addAttachedCard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Card::getInfo(ServerInfo_Card *info)
|
void Server_Card::getInfo(ServerInfo_Card *info)
|
||||||
{
|
{
|
||||||
QString displayedName = facedown ? QString() : name;
|
QString displayedName = facedown ? QString() : name;
|
||||||
|
|
||||||
info->set_id(id);
|
info->set_id(id);
|
||||||
info->set_name(displayedName.toStdString());
|
info->set_name(displayedName.toStdString());
|
||||||
info->set_x(coord_x);
|
info->set_x(coord_x);
|
||||||
info->set_y(coord_y);
|
info->set_y(coord_y);
|
||||||
if (facedown)
|
if (facedown)
|
||||||
info->set_face_down(true);
|
info->set_face_down(true);
|
||||||
info->set_tapped(tapped);
|
info->set_tapped(tapped);
|
||||||
if (attacking)
|
if (attacking)
|
||||||
info->set_attacking(true);
|
info->set_attacking(true);
|
||||||
if (!color.isEmpty())
|
if (!color.isEmpty())
|
||||||
info->set_color(color.toStdString());
|
info->set_color(color.toStdString());
|
||||||
const QString ptStr = getPT();
|
const QString ptStr = getPT();
|
||||||
if (!ptStr.isEmpty())
|
if (!ptStr.isEmpty())
|
||||||
info->set_pt(ptStr.toStdString());
|
info->set_pt(ptStr.toStdString());
|
||||||
if (!annotation.isEmpty())
|
if (!annotation.isEmpty())
|
||||||
info->set_annotation(annotation.toStdString());
|
info->set_annotation(annotation.toStdString());
|
||||||
if (destroyOnZoneChange)
|
if (destroyOnZoneChange)
|
||||||
info->set_destroy_on_zone_change(true);
|
info->set_destroy_on_zone_change(true);
|
||||||
if (doesntUntap)
|
if (doesntUntap)
|
||||||
info->set_doesnt_untap(true);
|
info->set_doesnt_untap(true);
|
||||||
|
|
||||||
QMapIterator<int, int> cardCounterIterator(counters);
|
QMapIterator<int, int> cardCounterIterator(counters);
|
||||||
while (cardCounterIterator.hasNext()) {
|
while (cardCounterIterator.hasNext()) {
|
||||||
cardCounterIterator.next();
|
cardCounterIterator.next();
|
||||||
ServerInfo_CardCounter *counterInfo = info->add_counter_list();
|
ServerInfo_CardCounter *counterInfo = info->add_counter_list();
|
||||||
counterInfo->set_id(cardCounterIterator.key());
|
counterInfo->set_id(cardCounterIterator.key());
|
||||||
counterInfo->set_value(cardCounterIterator.value());
|
counterInfo->set_value(cardCounterIterator.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentCard) {
|
if (parentCard) {
|
||||||
info->set_attach_player_id(parentCard->getZone()->getPlayer()->getPlayerId());
|
info->set_attach_player_id(parentCard->getZone()->getPlayer()->getPlayerId());
|
||||||
info->set_attach_zone(parentCard->getZone()->getName().toStdString());
|
info->set_attach_zone(parentCard->getZone()->getName().toStdString());
|
||||||
info->set_attach_card_id(parentCard->getId());
|
info->set_attach_card_id(parentCard->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,68 +29,68 @@ class Server_CardZone;
|
||||||
class ServerInfo_Card;
|
class ServerInfo_Card;
|
||||||
|
|
||||||
class Server_Card : public Server_ArrowTarget {
|
class Server_Card : public Server_ArrowTarget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Server_CardZone *zone;
|
Server_CardZone *zone;
|
||||||
int id;
|
int id;
|
||||||
int coord_x, coord_y;
|
int coord_x, coord_y;
|
||||||
QString name;
|
QString name;
|
||||||
QMap<int, int> counters;
|
QMap<int, int> counters;
|
||||||
bool tapped;
|
bool tapped;
|
||||||
bool attacking;
|
bool attacking;
|
||||||
bool facedown;
|
bool facedown;
|
||||||
QString color;
|
QString color;
|
||||||
int power, toughness;
|
int power, toughness;
|
||||||
QString annotation;
|
QString annotation;
|
||||||
bool destroyOnZoneChange;
|
bool destroyOnZoneChange;
|
||||||
bool doesntUntap;
|
bool doesntUntap;
|
||||||
|
|
||||||
Server_Card *parentCard;
|
Server_Card *parentCard;
|
||||||
QList<Server_Card *> attachedCards;
|
QList<Server_Card *> attachedCards;
|
||||||
public:
|
public:
|
||||||
Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = 0);
|
Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = 0);
|
||||||
~Server_Card();
|
~Server_Card();
|
||||||
|
|
||||||
Server_CardZone *getZone() const { return zone; }
|
Server_CardZone *getZone() const { return zone; }
|
||||||
void setZone(Server_CardZone *_zone) { zone = _zone; }
|
void setZone(Server_CardZone *_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; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
const QMap<int, int> &getCounters() const { return counters; }
|
const QMap<int, int> &getCounters() const { return counters; }
|
||||||
int getCounter(int id) const { return counters.value(id, 0); }
|
int getCounter(int id) const { return counters.value(id, 0); }
|
||||||
bool getTapped() const { return tapped; }
|
bool getTapped() const { return tapped; }
|
||||||
bool getAttacking() const { return attacking; }
|
bool getAttacking() const { return attacking; }
|
||||||
bool getFaceDown() const { return facedown; }
|
bool getFaceDown() const { return facedown; }
|
||||||
QString getColor() const { return color; }
|
QString getColor() const { return color; }
|
||||||
QString getPT() const;
|
QString getPT() const;
|
||||||
QString getAnnotation() const { return annotation; }
|
QString getAnnotation() const { return annotation; }
|
||||||
bool getDoesntUntap() const { return doesntUntap; }
|
bool getDoesntUntap() const { return doesntUntap; }
|
||||||
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
||||||
Server_Card *getParentCard() const { return parentCard; }
|
Server_Card *getParentCard() const { return parentCard; }
|
||||||
const QList<Server_Card *> &getAttachedCards() const { return attachedCards; }
|
const QList<Server_Card *> &getAttachedCards() const { return attachedCards; }
|
||||||
|
|
||||||
void setId(int _id) { id = _id; }
|
void setId(int _id) { id = _id; }
|
||||||
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
|
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
|
||||||
void setName(const QString &_name) { name = _name; }
|
void setName(const QString &_name) { name = _name; }
|
||||||
void setCounter(int id, int value);
|
void setCounter(int id, int value);
|
||||||
void setTapped(bool _tapped) { tapped = _tapped; }
|
void setTapped(bool _tapped) { tapped = _tapped; }
|
||||||
void setAttacking(bool _attacking) { attacking = _attacking; }
|
void setAttacking(bool _attacking) { attacking = _attacking; }
|
||||||
void setFaceDown(bool _facedown) { facedown = _facedown; }
|
void setFaceDown(bool _facedown) { facedown = _facedown; }
|
||||||
void setColor(const QString &_color) { color = _color; }
|
void setColor(const QString &_color) { color = _color; }
|
||||||
void setPT(const QString &_pt);
|
void setPT(const QString &_pt);
|
||||||
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
|
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
|
||||||
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
||||||
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
|
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
|
||||||
void setParentCard(Server_Card *_parentCard);
|
void setParentCard(Server_Card *_parentCard);
|
||||||
void addAttachedCard(Server_Card *card) { attachedCards.append(card); }
|
void addAttachedCard(Server_Card *card) { attachedCards.append(card); }
|
||||||
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
||||||
|
|
||||||
void resetState();
|
void resetState();
|
||||||
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
||||||
|
|
||||||
void getInfo(ServerInfo_Card *info);
|
void getInfo(ServerInfo_Card *info);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,48 +33,48 @@ class GameEventStorage;
|
||||||
|
|
||||||
class Server_CardZone {
|
class Server_CardZone {
|
||||||
private:
|
private:
|
||||||
Server_Player *player;
|
Server_Player *player;
|
||||||
QString name;
|
QString name;
|
||||||
bool has_coords;
|
bool has_coords;
|
||||||
ServerInfo_Zone::ZoneType type;
|
ServerInfo_Zone::ZoneType type;
|
||||||
int cardsBeingLookedAt;
|
int cardsBeingLookedAt;
|
||||||
QSet<int> playersWithWritePermission;
|
QSet<int> playersWithWritePermission;
|
||||||
bool alwaysRevealTopCard;
|
bool alwaysRevealTopCard;
|
||||||
QList<Server_Card *> cards;
|
QList<Server_Card *> cards;
|
||||||
QMap<int, QMap<int, Server_Card *> > coordinateMap; // y -> (x -> card)
|
QMap<int, QMap<int, Server_Card *> > coordinateMap; // y -> (x -> card)
|
||||||
QMap<int, QMultiMap<QString, int> > freePilesMap; // y -> (cardName -> x)
|
QMap<int, QMultiMap<QString, int> > freePilesMap; // y -> (cardName -> x)
|
||||||
QMap<int, int> freeSpaceMap; // y -> x
|
QMap<int, int> freeSpaceMap; // y -> x
|
||||||
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
|
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
|
||||||
void insertCardIntoCoordMap(Server_Card *card, int x, int y);
|
void insertCardIntoCoordMap(Server_Card *card, int x, int y);
|
||||||
public:
|
public:
|
||||||
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
|
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
|
||||||
~Server_CardZone();
|
~Server_CardZone();
|
||||||
|
|
||||||
const QList<Server_Card *> &getCards() const { return cards; }
|
const QList<Server_Card *> &getCards() const { return cards; }
|
||||||
int removeCard(Server_Card *card);
|
int removeCard(Server_Card *card);
|
||||||
Server_Card *getCard(int id, int *position = NULL, bool remove = false);
|
Server_Card *getCard(int id, int *position = NULL, bool remove = false);
|
||||||
|
|
||||||
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
||||||
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
||||||
bool hasCoords() const { return has_coords; }
|
bool hasCoords() const { return has_coords; }
|
||||||
ServerInfo_Zone::ZoneType getType() const { return type; }
|
ServerInfo_Zone::ZoneType getType() const { return type; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
Server_Player *getPlayer() const { return player; }
|
Server_Player *getPlayer() const { return player; }
|
||||||
void getInfo(ServerInfo_Zone *info, Server_Player *playerWhosAsking, bool omniscient);
|
void getInfo(ServerInfo_Zone *info, Server_Player *playerWhosAsking, bool omniscient);
|
||||||
|
|
||||||
int getFreeGridColumn(int x, int y, const QString &cardName) const;
|
int getFreeGridColumn(int x, int y, const QString &cardName) const;
|
||||||
bool isColumnEmpty(int x, int y) const;
|
bool isColumnEmpty(int x, int y) const;
|
||||||
bool isColumnStacked(int x, int y) const;
|
bool isColumnStacked(int x, int y) const;
|
||||||
void fixFreeSpaces(GameEventStorage &ges);
|
void fixFreeSpaces(GameEventStorage &ges);
|
||||||
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
|
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
|
||||||
void insertCard(Server_Card *card, int x, int y);
|
void insertCard(Server_Card *card, int x, int y);
|
||||||
void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
|
void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
|
||||||
void shuffle();
|
void shuffle();
|
||||||
void clear();
|
void clear();
|
||||||
void addWritePermission(int playerId);
|
void addWritePermission(int playerId);
|
||||||
const QSet<int> &getPlayersWithWritePermission() const { return playersWithWritePermission; }
|
const QSet<int> &getPlayersWithWritePermission() const { return playersWithWritePermission; }
|
||||||
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
||||||
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,9 +12,9 @@ Server_Counter::Server_Counter(int _id, const QString &_name, const color &_coun
|
||||||
|
|
||||||
void Server_Counter::getInfo(ServerInfo_Counter *info)
|
void Server_Counter::getInfo(ServerInfo_Counter *info)
|
||||||
{
|
{
|
||||||
info->set_id(id);
|
info->set_id(id);
|
||||||
info->set_name(name.toStdString());
|
info->set_name(name.toStdString());
|
||||||
info->mutable_counter_color()->CopyFrom(counterColor);
|
info->mutable_counter_color()->CopyFrom(counterColor);
|
||||||
info->set_radius(radius);
|
info->set_radius(radius);
|
||||||
info->set_count(count);
|
info->set_count(count);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,22 +27,22 @@ class ServerInfo_Counter;
|
||||||
|
|
||||||
class Server_Counter {
|
class Server_Counter {
|
||||||
protected:
|
protected:
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
color counterColor;
|
color counterColor;
|
||||||
int radius;
|
int radius;
|
||||||
int count;
|
int count;
|
||||||
public:
|
public:
|
||||||
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
|
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
|
||||||
~Server_Counter() { }
|
~Server_Counter() { }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
const color &getColor() const { return counterColor; }
|
const color &getColor() const { return counterColor; }
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getCount() const { return count; }
|
int getCount() const { return count; }
|
||||||
void setCount(int _count) { count = _count; }
|
void setCount(int _count) { count = _count; }
|
||||||
|
|
||||||
void getInfo(ServerInfo_Counter *info);
|
void getInfo(ServerInfo_Counter *info);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,32 +6,32 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
class Server_DatabaseInterface : public QObject {
|
class Server_DatabaseInterface : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Server_DatabaseInterface(QObject *parent = 0)
|
Server_DatabaseInterface(QObject *parent = 0)
|
||||||
: QObject(parent) { }
|
: QObject(parent) { }
|
||||||
|
|
||||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
|
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
|
||||||
virtual bool userExists(const QString &user) { return false; }
|
virtual bool userExists(const QString &user) { return false; }
|
||||||
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||||
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||||
virtual bool isInBuddyList(const QString &whoseList, const QString &who) { return false; }
|
virtual bool isInBuddyList(const QString &whoseList, const QString &who) { return false; }
|
||||||
virtual bool isInIgnoreList(const QString &whoseList, const QString &who) { return false; }
|
virtual bool isInIgnoreList(const QString &whoseList, const QString &who) { return false; }
|
||||||
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
||||||
virtual void storeGameInformation(const QString &roomName, const QStringList &roomGameTypes, const ServerInfo_Game &gameInfo, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replayList) { }
|
virtual void storeGameInformation(const QString &roomName, const QStringList &roomGameTypes, const ServerInfo_Game &gameInfo, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replayList) { }
|
||||||
virtual DeckList *getDeckFromDatabase(int deckId, int userId) { return 0; }
|
virtual DeckList *getDeckFromDatabase(int deckId, int userId) { return 0; }
|
||||||
|
|
||||||
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
||||||
public slots:
|
public slots:
|
||||||
virtual void endSession(qint64 sessionId) { }
|
virtual void endSession(qint64 sessionId) { }
|
||||||
public:
|
public:
|
||||||
virtual int getNextGameId() = 0;
|
virtual int getNextGameId() = 0;
|
||||||
virtual int getNextReplayId() = 0;
|
virtual int getNextReplayId() = 0;
|
||||||
|
|
||||||
virtual void clearSessionTables() { }
|
virtual void clearSessionTables() { }
|
||||||
virtual void lockSessionTables() { }
|
virtual void lockSessionTables() { }
|
||||||
virtual void unlockSessionTables() { }
|
virtual void unlockSessionTables() { }
|
||||||
virtual bool userSessionExists(const QString &userName) { return false; }
|
virtual bool userSessionExists(const QString &userName) { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -42,86 +42,86 @@ class Server_AbstractUserInterface;
|
||||||
class Event_GameStateChanged;
|
class Event_GameStateChanged;
|
||||||
|
|
||||||
class Server_Game : public QObject {
|
class Server_Game : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
Server_Room *room;
|
Server_Room *room;
|
||||||
int nextPlayerId;
|
int nextPlayerId;
|
||||||
int hostId;
|
int hostId;
|
||||||
ServerInfo_User *creatorInfo;
|
ServerInfo_User *creatorInfo;
|
||||||
QMap<int, Server_Player *> players;
|
QMap<int, Server_Player *> players;
|
||||||
QSet<QString> allPlayersEver, allSpectatorsEver;
|
QSet<QString> allPlayersEver, allSpectatorsEver;
|
||||||
bool gameStarted;
|
bool gameStarted;
|
||||||
bool gameClosed;
|
bool gameClosed;
|
||||||
int gameId;
|
int gameId;
|
||||||
QString description;
|
QString description;
|
||||||
QString password;
|
QString password;
|
||||||
int maxPlayers;
|
int maxPlayers;
|
||||||
QList<int> gameTypes;
|
QList<int> gameTypes;
|
||||||
int activePlayer, activePhase;
|
int activePlayer, activePhase;
|
||||||
bool onlyBuddies, onlyRegistered;
|
bool onlyBuddies, onlyRegistered;
|
||||||
bool spectatorsAllowed;
|
bool spectatorsAllowed;
|
||||||
bool spectatorsNeedPassword;
|
bool spectatorsNeedPassword;
|
||||||
bool spectatorsCanTalk;
|
bool spectatorsCanTalk;
|
||||||
bool spectatorsSeeEverything;
|
bool spectatorsSeeEverything;
|
||||||
int inactivityCounter;
|
int inactivityCounter;
|
||||||
int startTimeOfThisGame, secondsElapsed;
|
int startTimeOfThisGame, secondsElapsed;
|
||||||
bool firstGameStarted;
|
bool firstGameStarted;
|
||||||
QDateTime startTime;
|
QDateTime startTime;
|
||||||
QTimer *pingClock;
|
QTimer *pingClock;
|
||||||
QList<GameReplay *> replayList;
|
QList<GameReplay *> replayList;
|
||||||
GameReplay *currentReplay;
|
GameReplay *currentReplay;
|
||||||
|
|
||||||
void createGameStateChangedEvent(Event_GameStateChanged *event, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
void createGameStateChangedEvent(Event_GameStateChanged *event, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||||
void sendGameStateToPlayers();
|
void sendGameStateToPlayers();
|
||||||
void storeGameInformation();
|
void storeGameInformation();
|
||||||
signals:
|
signals:
|
||||||
void sigStartGameIfReady();
|
void sigStartGameIfReady();
|
||||||
void gameInfoChanged(ServerInfo_Game gameInfo);
|
void gameInfoChanged(ServerInfo_Game gameInfo);
|
||||||
private slots:
|
private slots:
|
||||||
void pingClockTimeout();
|
void pingClockTimeout();
|
||||||
void doStartGameIfReady();
|
void doStartGameIfReady();
|
||||||
public:
|
public:
|
||||||
mutable QMutex gameMutex;
|
mutable QMutex gameMutex;
|
||||||
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
||||||
~Server_Game();
|
~Server_Game();
|
||||||
Server_Room *getRoom() const { return room; }
|
Server_Room *getRoom() const { return room; }
|
||||||
void getInfo(ServerInfo_Game &result) const;
|
void getInfo(ServerInfo_Game &result) const;
|
||||||
int getHostId() const { return hostId; }
|
int getHostId() const { return hostId; }
|
||||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||||
bool getGameStarted() const { return gameStarted; }
|
bool getGameStarted() const { return gameStarted; }
|
||||||
int getPlayerCount() const;
|
int getPlayerCount() const;
|
||||||
int getSpectatorCount() const;
|
int getSpectatorCount() const;
|
||||||
const QMap<int, Server_Player *> &getPlayers() const { return players; }
|
const QMap<int, Server_Player *> &getPlayers() const { return players; }
|
||||||
int getGameId() const { return gameId; }
|
int getGameId() const { return gameId; }
|
||||||
QString getDescription() const { return description; }
|
QString getDescription() const { return description; }
|
||||||
QString getPassword() const { return password; }
|
QString getPassword() const { return password; }
|
||||||
int getMaxPlayers() const { return maxPlayers; }
|
int getMaxPlayers() const { return maxPlayers; }
|
||||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||||
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
||||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||||
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
||||||
Response::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;
|
bool containsUser(const QString &userName) const;
|
||||||
void addPlayer(Server_AbstractUserInterface *userInterface, ResponseContainer &rc, bool spectator, bool broadcastUpdate = true);
|
void addPlayer(Server_AbstractUserInterface *userInterface, ResponseContainer &rc, bool spectator, bool broadcastUpdate = true);
|
||||||
void removePlayer(Server_Player *player);
|
void removePlayer(Server_Player *player);
|
||||||
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_Player *player);
|
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_Player *player);
|
||||||
void unattachCards(GameEventStorage &ges, Server_Player *player);
|
void unattachCards(GameEventStorage &ges, Server_Player *player);
|
||||||
bool kickPlayer(int playerId);
|
bool kickPlayer(int playerId);
|
||||||
void startGameIfReady();
|
void startGameIfReady();
|
||||||
void stopGameIfFinished();
|
void stopGameIfFinished();
|
||||||
int getActivePlayer() const { return activePlayer; }
|
int getActivePlayer() const { return activePlayer; }
|
||||||
int getActivePhase() const { return activePhase; }
|
int getActivePhase() const { return activePhase; }
|
||||||
void setActivePlayer(int _activePlayer);
|
void setActivePlayer(int _activePlayer);
|
||||||
void setActivePhase(int _activePhase);
|
void setActivePhase(int _activePhase);
|
||||||
void nextTurn();
|
void nextTurn();
|
||||||
int getSecondsElapsed() const { return secondsElapsed; }
|
int getSecondsElapsed() const { return secondsElapsed; }
|
||||||
|
|
||||||
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);
|
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);
|
||||||
|
|
||||||
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
|
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
|
||||||
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
|
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
|
||||||
|
|
||||||
void sendGameEventContainer(GameEventContainer *cont, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int privatePlayerId = -1);
|
void sendGameEventContainer(GameEventContainer *cont, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int privatePlayerId = -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -62,104 +62,104 @@ class Command_SetSideboardLock;
|
||||||
class Command_ChangeZoneProperties;
|
class Command_ChangeZoneProperties;
|
||||||
|
|
||||||
class Server_Player : public Server_ArrowTarget, public ServerInfo_User_Container {
|
class Server_Player : public Server_ArrowTarget, public ServerInfo_User_Container {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
class MoveCardCompareFunctor;
|
class MoveCardCompareFunctor;
|
||||||
Server_Game *game;
|
Server_Game *game;
|
||||||
Server_AbstractUserInterface *userInterface;
|
Server_AbstractUserInterface *userInterface;
|
||||||
DeckList *deck;
|
DeckList *deck;
|
||||||
QMap<QString, Server_CardZone *> zones;
|
QMap<QString, Server_CardZone *> zones;
|
||||||
QMap<int, Server_Counter *> counters;
|
QMap<int, Server_Counter *> counters;
|
||||||
QMap<int, Server_Arrow *> arrows;
|
QMap<int, Server_Arrow *> arrows;
|
||||||
QList<int> lastDrawList;
|
QList<int> lastDrawList;
|
||||||
int pingTime;
|
int pingTime;
|
||||||
int playerId;
|
int playerId;
|
||||||
bool spectator;
|
bool spectator;
|
||||||
int initialCards;
|
int initialCards;
|
||||||
int nextCardId;
|
int nextCardId;
|
||||||
bool readyStart;
|
bool readyStart;
|
||||||
bool conceded;
|
bool conceded;
|
||||||
bool sideboardLocked;
|
bool sideboardLocked;
|
||||||
public:
|
public:
|
||||||
mutable QMutex playerMutex;
|
mutable QMutex playerMutex;
|
||||||
Server_Player(Server_Game *_game, int _playerId, const ServerInfo_User &_userInfo, bool _spectator, Server_AbstractUserInterface *_handler);
|
Server_Player(Server_Game *_game, int _playerId, const ServerInfo_User &_userInfo, bool _spectator, Server_AbstractUserInterface *_handler);
|
||||||
~Server_Player();
|
~Server_Player();
|
||||||
void prepareDestroy();
|
void prepareDestroy();
|
||||||
Server_AbstractUserInterface *getUserInterface() const { return userInterface; }
|
Server_AbstractUserInterface *getUserInterface() const { return userInterface; }
|
||||||
void setUserInterface(Server_AbstractUserInterface *_userInterface);
|
void setUserInterface(Server_AbstractUserInterface *_userInterface);
|
||||||
void disconnectClient();
|
void disconnectClient();
|
||||||
|
|
||||||
void setPlayerId(int _id) { playerId = _id; }
|
void setPlayerId(int _id) { playerId = _id; }
|
||||||
bool getReadyStart() const { return readyStart; }
|
bool getReadyStart() const { return readyStart; }
|
||||||
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
||||||
int getPlayerId() const { return playerId; }
|
int getPlayerId() const { return playerId; }
|
||||||
bool getSpectator() const { return spectator; }
|
bool getSpectator() const { return spectator; }
|
||||||
bool getConceded() const { return conceded; }
|
bool getConceded() const { return conceded; }
|
||||||
void setConceded(bool _conceded) { conceded = _conceded; }
|
void setConceded(bool _conceded) { conceded = _conceded; }
|
||||||
DeckList *getDeck() const { return deck; }
|
DeckList *getDeck() const { return deck; }
|
||||||
Server_Game *getGame() const { return game; }
|
Server_Game *getGame() const { return game; }
|
||||||
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
||||||
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
||||||
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
||||||
|
|
||||||
int getPingTime() const { return pingTime; }
|
int getPingTime() const { return pingTime; }
|
||||||
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
||||||
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||||
|
|
||||||
int newCardId();
|
int newCardId();
|
||||||
int newCounterId() const;
|
int newCounterId() const;
|
||||||
int newArrowId() const;
|
int newArrowId() const;
|
||||||
|
|
||||||
void addZone(Server_CardZone *zone);
|
void addZone(Server_CardZone *zone);
|
||||||
void addArrow(Server_Arrow *arrow);
|
void addArrow(Server_Arrow *arrow);
|
||||||
bool deleteArrow(int arrowId);
|
bool deleteArrow(int arrowId);
|
||||||
void addCounter(Server_Counter *counter);
|
void addCounter(Server_Counter *counter);
|
||||||
|
|
||||||
void clearZones();
|
void clearZones();
|
||||||
void setupZones();
|
void setupZones();
|
||||||
|
|
||||||
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
|
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
|
||||||
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);
|
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);
|
void unattachCard(GameEventStorage &ges, Server_Card *card);
|
||||||
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, CardAttribute attribute, const QString &attrValue);
|
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, CardAttribute attribute, const QString &attrValue);
|
||||||
|
|
||||||
Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
Response::ResponseCode cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
|
|
||||||
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
|
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
|
||||||
void sendGameEvent(const GameEventContainer &event);
|
void sendGameEvent(const GameEventContainer &event);
|
||||||
|
|
||||||
void getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
void getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
|
|
||||||
class PlayerReference {
|
class PlayerReference {
|
||||||
private:
|
private:
|
||||||
int roomId;
|
int roomId;
|
||||||
int gameId;
|
int gameId;
|
||||||
int playerId;
|
int playerId;
|
||||||
public:
|
public:
|
||||||
PlayerReference(int _roomId, int _gameId, int _playerId) : roomId(_roomId), gameId(_gameId), playerId(_playerId) { }
|
PlayerReference(int _roomId, int _gameId, int _playerId) : roomId(_roomId), gameId(_gameId), playerId(_playerId) { }
|
||||||
int getRoomId() const { return roomId; }
|
int getRoomId() const { return roomId; }
|
||||||
int getGameId() const { return gameId; }
|
int getGameId() const { return gameId; }
|
||||||
int getPlayerId() const { return playerId; }
|
int getPlayerId() const { return playerId; }
|
||||||
bool operator==(const PlayerReference &other) { return ((roomId == other.roomId) && (gameId == other.gameId) && (playerId == other.playerId)); }
|
bool operator==(const PlayerReference &other) { return ((roomId == other.roomId) && (gameId == other.gameId) && (playerId == other.playerId)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -40,64 +40,64 @@ class Command_CreateGame;
|
||||||
class Command_JoinGame;
|
class Command_JoinGame;
|
||||||
|
|
||||||
class Server_ProtocolHandler : public QObject, public Server_AbstractUserInterface {
|
class Server_ProtocolHandler : public QObject, public Server_AbstractUserInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
QMap<int, Server_Room *> rooms;
|
QMap<int, Server_Room *> rooms;
|
||||||
|
|
||||||
bool deleted;
|
bool deleted;
|
||||||
Server_DatabaseInterface *databaseInterface;
|
Server_DatabaseInterface *databaseInterface;
|
||||||
AuthenticationResult authState;
|
AuthenticationResult authState;
|
||||||
bool acceptsUserListChanges;
|
bool acceptsUserListChanges;
|
||||||
bool acceptsRoomListChanges;
|
bool acceptsRoomListChanges;
|
||||||
virtual void logDebugMessage(const QString &message) { }
|
virtual void logDebugMessage(const QString &message) { }
|
||||||
private:
|
private:
|
||||||
QList<int> messageSizeOverTime, messageCountOverTime;
|
QList<int> messageSizeOverTime, messageCountOverTime;
|
||||||
int timeRunning, lastDataReceived;
|
int timeRunning, lastDataReceived;
|
||||||
QTimer *pingClock;
|
QTimer *pingClock;
|
||||||
|
|
||||||
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
|
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
|
||||||
|
|
||||||
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdListRooms(const Command_ListRooms &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdListRooms(const Command_ListRooms &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc);
|
Response::ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdListUsers(const Command_ListUsers &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 cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdRoomSay(const Command_RoomSay &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 cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||||
Response::ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc);
|
Response::ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||||
|
|
||||||
Response::ResponseCode processSessionCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
Response::ResponseCode processSessionCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||||
virtual Response::ResponseCode processExtendedSessionCommand(int cmdType, const SessionCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
virtual Response::ResponseCode processExtendedSessionCommand(int cmdType, const SessionCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||||
Response::ResponseCode processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
Response::ResponseCode processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||||
Response::ResponseCode processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
Response::ResponseCode processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||||
Response::ResponseCode processModeratorCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
Response::ResponseCode processModeratorCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||||
virtual Response::ResponseCode processExtendedModeratorCommand(int cmdType, const ModeratorCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
virtual Response::ResponseCode processExtendedModeratorCommand(int cmdType, const ModeratorCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||||
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||||
virtual Response::ResponseCode processExtendedAdminCommand(int cmdType, const AdminCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
virtual Response::ResponseCode processExtendedAdminCommand(int cmdType, const AdminCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||||
private slots:
|
private slots:
|
||||||
void pingClockTimeout();
|
void pingClockTimeout();
|
||||||
public slots:
|
public slots:
|
||||||
void prepareDestroy();
|
void prepareDestroy();
|
||||||
public:
|
public:
|
||||||
Server_ProtocolHandler(Server *_server, Server_DatabaseInterface *_databaseInterface, QObject *parent = 0);
|
Server_ProtocolHandler(Server *_server, Server_DatabaseInterface *_databaseInterface, QObject *parent = 0);
|
||||||
~Server_ProtocolHandler();
|
~Server_ProtocolHandler();
|
||||||
|
|
||||||
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
||||||
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
|
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
|
||||||
virtual QString getAddress() const = 0;
|
virtual QString getAddress() const = 0;
|
||||||
Server_DatabaseInterface *getDatabaseInterface() const { return databaseInterface; }
|
Server_DatabaseInterface *getDatabaseInterface() const { return databaseInterface; }
|
||||||
|
|
||||||
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
|
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
|
||||||
void processCommandContainer(const CommandContainer &cont);
|
void processCommandContainer(const CommandContainer &cont);
|
||||||
|
|
||||||
void sendProtocolItem(const Response &item);
|
void sendProtocolItem(const Response &item);
|
||||||
void sendProtocolItem(const SessionEvent &item);
|
void sendProtocolItem(const SessionEvent &item);
|
||||||
void sendProtocolItem(const GameEventContainer &item);
|
void sendProtocolItem(const GameEventContainer &item);
|
||||||
void sendProtocolItem(const RoomEvent &item);
|
void sendProtocolItem(const RoomEvent &item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,20 +4,20 @@
|
||||||
|
|
||||||
void Server_RemoteUserInterface::sendProtocolItem(const Response &item)
|
void Server_RemoteUserInterface::sendProtocolItem(const Response &item)
|
||||||
{
|
{
|
||||||
server->sendIsl_Response(item, userInfo->server_id(), userInfo->session_id());
|
server->sendIsl_Response(item, userInfo->server_id(), userInfo->session_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_RemoteUserInterface::sendProtocolItem(const SessionEvent &item)
|
void Server_RemoteUserInterface::sendProtocolItem(const SessionEvent &item)
|
||||||
{
|
{
|
||||||
server->sendIsl_SessionEvent(item, userInfo->server_id(), userInfo->session_id());
|
server->sendIsl_SessionEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_RemoteUserInterface::sendProtocolItem(const GameEventContainer &item)
|
void Server_RemoteUserInterface::sendProtocolItem(const GameEventContainer &item)
|
||||||
{
|
{
|
||||||
server->sendIsl_GameEventContainer(item, userInfo->server_id(), userInfo->session_id());
|
server->sendIsl_GameEventContainer(item, userInfo->server_id(), userInfo->session_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_RemoteUserInterface::sendProtocolItem(const RoomEvent &item)
|
void Server_RemoteUserInterface::sendProtocolItem(const RoomEvent &item)
|
||||||
{
|
{
|
||||||
server->sendIsl_RoomEvent(item, userInfo->server_id(), userInfo->session_id());
|
server->sendIsl_RoomEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
|
|
||||||
class Server_RemoteUserInterface : public Server_AbstractUserInterface {
|
class Server_RemoteUserInterface : public Server_AbstractUserInterface {
|
||||||
public:
|
public:
|
||||||
Server_RemoteUserInterface(Server *_server, const ServerInfo_User_Container &_userInfoContainer) : Server_AbstractUserInterface(_server, _userInfoContainer) { }
|
Server_RemoteUserInterface(Server *_server, const ServerInfo_User_Container &_userInfoContainer) : Server_AbstractUserInterface(_server, _userInfoContainer) { }
|
||||||
|
|
||||||
int getLastCommandTime() const { return 0; }
|
int getLastCommandTime() const { return 0; }
|
||||||
|
|
||||||
void sendProtocolItem(const Response &item);
|
void sendProtocolItem(const Response &item);
|
||||||
void sendProtocolItem(const SessionEvent &item);
|
void sendProtocolItem(const SessionEvent &item);
|
||||||
void sendProtocolItem(const GameEventContainer &item);
|
void sendProtocolItem(const GameEventContainer &item);
|
||||||
void sendProtocolItem(const RoomEvent &item);
|
void sendProtocolItem(const RoomEvent &item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,64 +3,64 @@
|
||||||
#include "server_game.h"
|
#include "server_game.h"
|
||||||
|
|
||||||
GameEventStorageItem::GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients)
|
GameEventStorageItem::GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients)
|
||||||
: event(new GameEvent), recipients(_recipients)
|
: event(new GameEvent), recipients(_recipients)
|
||||||
{
|
{
|
||||||
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
||||||
event->set_player_id(_playerId);
|
event->set_player_id(_playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEventStorageItem::~GameEventStorageItem()
|
GameEventStorageItem::~GameEventStorageItem()
|
||||||
{
|
{
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEventStorage::GameEventStorage()
|
GameEventStorage::GameEventStorage()
|
||||||
: gameEventContext(0)
|
: gameEventContext(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GameEventStorage::~GameEventStorage()
|
GameEventStorage::~GameEventStorage()
|
||||||
{
|
{
|
||||||
delete gameEventContext;
|
delete gameEventContext;
|
||||||
for (int i = 0; i < gameEventList.size(); ++i)
|
for (int i = 0; i < gameEventList.size(); ++i)
|
||||||
delete gameEventList[i];
|
delete gameEventList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventStorage::setGameEventContext(const ::google::protobuf::Message &_gameEventContext)
|
void GameEventStorage::setGameEventContext(const ::google::protobuf::Message &_gameEventContext)
|
||||||
{
|
{
|
||||||
delete gameEventContext;
|
delete gameEventContext;
|
||||||
gameEventContext = new GameEventContext;
|
gameEventContext = new GameEventContext;
|
||||||
gameEventContext->GetReflection()->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_gameEventContext);
|
gameEventContext->GetReflection()->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_gameEventContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventStorage::enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients, int _privatePlayerId)
|
void GameEventStorage::enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients, int _privatePlayerId)
|
||||||
{
|
{
|
||||||
gameEventList.append(new GameEventStorageItem(event, playerId, recipients));
|
gameEventList.append(new GameEventStorageItem(event, playerId, recipients));
|
||||||
if (_privatePlayerId != -1)
|
if (_privatePlayerId != -1)
|
||||||
privatePlayerId = _privatePlayerId;
|
privatePlayerId = _privatePlayerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventStorage::sendToGame(Server_Game *game)
|
void GameEventStorage::sendToGame(Server_Game *game)
|
||||||
{
|
{
|
||||||
if (gameEventList.isEmpty())
|
if (gameEventList.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GameEventContainer *contPrivate = new GameEventContainer;
|
GameEventContainer *contPrivate = new GameEventContainer;
|
||||||
GameEventContainer *contOthers = new GameEventContainer;
|
GameEventContainer *contOthers = new GameEventContainer;
|
||||||
for (int i = 0; i < gameEventList.size(); ++i) {
|
for (int i = 0; i < gameEventList.size(); ++i) {
|
||||||
const GameEvent &event = gameEventList[i]->getGameEvent();
|
const GameEvent &event = gameEventList[i]->getGameEvent();
|
||||||
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
|
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
|
||||||
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
||||||
contPrivate->add_event_list()->CopyFrom(event);
|
contPrivate->add_event_list()->CopyFrom(event);
|
||||||
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
||||||
contOthers->add_event_list()->CopyFrom(event);
|
contOthers->add_event_list()->CopyFrom(event);
|
||||||
}
|
}
|
||||||
if (gameEventContext) {
|
if (gameEventContext) {
|
||||||
contPrivate->mutable_context()->CopyFrom(*gameEventContext);
|
contPrivate->mutable_context()->CopyFrom(*gameEventContext);
|
||||||
contOthers->mutable_context()->CopyFrom(*gameEventContext);
|
contOthers->mutable_context()->CopyFrom(*gameEventContext);
|
||||||
}
|
}
|
||||||
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, privatePlayerId);
|
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, privatePlayerId);
|
||||||
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, privatePlayerId);
|
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, privatePlayerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseContainer::ResponseContainer(int _cmdId)
|
ResponseContainer::ResponseContainer(int _cmdId)
|
||||||
|
@ -70,9 +70,9 @@ ResponseContainer::ResponseContainer(int _cmdId)
|
||||||
|
|
||||||
ResponseContainer::~ResponseContainer()
|
ResponseContainer::~ResponseContainer()
|
||||||
{
|
{
|
||||||
delete responseExtension;
|
delete responseExtension;
|
||||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||||
delete preResponseQueue[i].second;
|
delete preResponseQueue[i].second;
|
||||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||||
delete postResponseQueue[i].second;
|
delete postResponseQueue[i].second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,54 +9,54 @@ class Server_Game;
|
||||||
|
|
||||||
class GameEventStorageItem {
|
class GameEventStorageItem {
|
||||||
public:
|
public:
|
||||||
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
||||||
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
||||||
private:
|
private:
|
||||||
GameEvent *event;
|
GameEvent *event;
|
||||||
EventRecipients recipients;
|
EventRecipients recipients;
|
||||||
public:
|
public:
|
||||||
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
|
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
|
||||||
~GameEventStorageItem();
|
~GameEventStorageItem();
|
||||||
|
|
||||||
const GameEvent &getGameEvent() const { return *event; }
|
const GameEvent &getGameEvent() const { return *event; }
|
||||||
EventRecipients getRecipients() const { return recipients; }
|
EventRecipients getRecipients() const { return recipients; }
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
|
||||||
|
|
||||||
class GameEventStorage {
|
class GameEventStorage {
|
||||||
private:
|
private:
|
||||||
::google::protobuf::Message *gameEventContext;
|
::google::protobuf::Message *gameEventContext;
|
||||||
QList<GameEventStorageItem *> gameEventList;
|
QList<GameEventStorageItem *> gameEventList;
|
||||||
int privatePlayerId;
|
int privatePlayerId;
|
||||||
public:
|
public:
|
||||||
GameEventStorage();
|
GameEventStorage();
|
||||||
~GameEventStorage();
|
~GameEventStorage();
|
||||||
|
|
||||||
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
|
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
|
||||||
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
||||||
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
|
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
|
||||||
int getPrivatePlayerId() const { return privatePlayerId; }
|
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||||
|
|
||||||
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1);
|
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1);
|
||||||
void sendToGame(Server_Game *game);
|
void sendToGame(Server_Game *game);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResponseContainer {
|
class ResponseContainer {
|
||||||
private:
|
private:
|
||||||
int cmdId;
|
int cmdId;
|
||||||
::google::protobuf::Message *responseExtension;
|
::google::protobuf::Message *responseExtension;
|
||||||
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > preResponseQueue, postResponseQueue;
|
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > preResponseQueue, postResponseQueue;
|
||||||
public:
|
public:
|
||||||
ResponseContainer(int _cmdId);
|
ResponseContainer(int _cmdId);
|
||||||
~ResponseContainer();
|
~ResponseContainer();
|
||||||
|
|
||||||
int getCmdId() const { return cmdId; }
|
int getCmdId() const { return cmdId; }
|
||||||
void setResponseExtension(::google::protobuf::Message *_responseExtension) { responseExtension = _responseExtension; }
|
void setResponseExtension(::google::protobuf::Message *_responseExtension) { responseExtension = _responseExtension; }
|
||||||
::google::protobuf::Message *getResponseExtension() const { return responseExtension; }
|
::google::protobuf::Message *getResponseExtension() const { return responseExtension; }
|
||||||
void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { preResponseQueue.append(qMakePair(type, item)); }
|
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)); }
|
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 *> > &getPreResponseQueue() const { return preResponseQueue; }
|
||||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPostResponseQueue() const { return postResponseQueue; }
|
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPostResponseQueue() const { return postResponseQueue; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,326 +13,326 @@
|
||||||
#include <google/protobuf/descriptor.h>
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_Room::~Server_Room()
|
Server_Room::~Server_Room()
|
||||||
{
|
{
|
||||||
qDebug("Server_Room destructor");
|
qDebug("Server_Room destructor");
|
||||||
|
|
||||||
gamesLock.lockForWrite();
|
gamesLock.lockForWrite();
|
||||||
const QList<Server_Game *> gameList = games.values();
|
const QList<Server_Game *> gameList = games.values();
|
||||||
for (int i = 0; i < gameList.size(); ++i)
|
for (int i = 0; i < gameList.size(); ++i)
|
||||||
delete gameList[i];
|
delete gameList[i];
|
||||||
games.clear();
|
games.clear();
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
|
|
||||||
usersLock.lockForWrite();
|
usersLock.lockForWrite();
|
||||||
users.clear();
|
users.clear();
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
Server *Server_Room::getServer() const
|
Server *Server_Room::getServer() const
|
||||||
{
|
{
|
||||||
return static_cast<Server *>(parent());
|
return static_cast<Server *>(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool includeExternalData) const
|
const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool includeExternalData) const
|
||||||
{
|
{
|
||||||
result.set_room_id(id);
|
result.set_room_id(id);
|
||||||
|
|
||||||
result.set_name(name.toStdString());
|
result.set_name(name.toStdString());
|
||||||
result.set_description(description.toStdString());
|
result.set_description(description.toStdString());
|
||||||
result.set_auto_join(autoJoin);
|
result.set_auto_join(autoJoin);
|
||||||
|
|
||||||
gamesLock.lockForRead();
|
gamesLock.lockForRead();
|
||||||
result.set_game_count(games.size() + externalGames.size());
|
result.set_game_count(games.size() + externalGames.size());
|
||||||
if (complete) {
|
if (complete) {
|
||||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||||
while (gameIterator.hasNext())
|
while (gameIterator.hasNext())
|
||||||
gameIterator.next().value()->getInfo(*result.add_game_list());
|
gameIterator.next().value()->getInfo(*result.add_game_list());
|
||||||
if (includeExternalData) {
|
if (includeExternalData) {
|
||||||
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
|
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
|
||||||
while (externalGameIterator.hasNext())
|
while (externalGameIterator.hasNext())
|
||||||
result.add_game_list()->CopyFrom(externalGameIterator.next().value());
|
result.add_game_list()->CopyFrom(externalGameIterator.next().value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
|
|
||||||
usersLock.lockForRead();
|
usersLock.lockForRead();
|
||||||
result.set_player_count(users.size() + externalUsers.size());
|
result.set_player_count(users.size() + externalUsers.size());
|
||||||
if (complete) {
|
if (complete) {
|
||||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||||
while (userIterator.hasNext())
|
while (userIterator.hasNext())
|
||||||
result.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
result.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
||||||
if (includeExternalData) {
|
if (includeExternalData) {
|
||||||
QMapIterator<QString, ServerInfo_User_Container> externalUserIterator(externalUsers);
|
QMapIterator<QString, ServerInfo_User_Container> externalUserIterator(externalUsers);
|
||||||
while (externalUserIterator.hasNext())
|
while (externalUserIterator.hasNext())
|
||||||
result.add_user_list()->CopyFrom(externalUserIterator.next().value().copyUserInfo(false));
|
result.add_user_list()->CopyFrom(externalUserIterator.next().value().copyUserInfo(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
if (complete || showGameTypes)
|
if (complete || showGameTypes)
|
||||||
for (int i = 0; i < gameTypes.size(); ++i) {
|
for (int i = 0; i < gameTypes.size(); ++i) {
|
||||||
ServerInfo_GameType *gameTypeInfo = result.add_gametype_list();
|
ServerInfo_GameType *gameTypeInfo = result.add_gametype_list();
|
||||||
gameTypeInfo->set_game_type_id(i);
|
gameTypeInfo->set_game_type_id(i);
|
||||||
gameTypeInfo->set_description(gameTypes[i].toStdString());
|
gameTypeInfo->set_description(gameTypes[i].toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomEvent *Server_Room::prepareRoomEvent(const ::google::protobuf::Message &roomEvent)
|
RoomEvent *Server_Room::prepareRoomEvent(const ::google::protobuf::Message &roomEvent)
|
||||||
{
|
{
|
||||||
RoomEvent *event = new RoomEvent;
|
RoomEvent *event = new RoomEvent;
|
||||||
event->set_room_id(id);
|
event->set_room_id(id);
|
||||||
event->GetReflection()->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(roomEvent);
|
event->GetReflection()->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(roomEvent);
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::addClient(Server_ProtocolHandler *client)
|
void Server_Room::addClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
Event_JoinRoom event;
|
Event_JoinRoom event;
|
||||||
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
||||||
sendRoomEvent(prepareRoomEvent(event));
|
sendRoomEvent(prepareRoomEvent(event));
|
||||||
|
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
|
|
||||||
usersLock.lockForWrite();
|
usersLock.lockForWrite();
|
||||||
users.insert(QString::fromStdString(client->getUserInfo()->name()), client);
|
users.insert(QString::fromStdString(client->getUserInfo()->name()), client);
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
// XXX This can be removed during the next client update.
|
// XXX This can be removed during the next client update.
|
||||||
gamesLock.lockForRead();
|
gamesLock.lockForRead();
|
||||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
usersLock.lockForWrite();
|
usersLock.lockForWrite();
|
||||||
users.remove(QString::fromStdString(client->getUserInfo()->name()));
|
users.remove(QString::fromStdString(client->getUserInfo()->name()));
|
||||||
|
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
Event_LeaveRoom event;
|
Event_LeaveRoom event;
|
||||||
event.set_name(client->getUserInfo()->name());
|
event.set_name(client->getUserInfo()->name());
|
||||||
sendRoomEvent(prepareRoomEvent(event));
|
sendRoomEvent(prepareRoomEvent(event));
|
||||||
|
|
||||||
// XXX This can be removed during the next client update.
|
// XXX This can be removed during the next client update.
|
||||||
gamesLock.lockForRead();
|
gamesLock.lockForRead();
|
||||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
||||||
{
|
{
|
||||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||||
ServerInfo_User_Container userInfoContainer(userInfo);
|
ServerInfo_User_Container userInfoContainer(userInfo);
|
||||||
Event_JoinRoom event;
|
Event_JoinRoom event;
|
||||||
event.mutable_user_info()->CopyFrom(userInfoContainer.copyUserInfo(false));
|
event.mutable_user_info()->CopyFrom(userInfoContainer.copyUserInfo(false));
|
||||||
sendRoomEvent(prepareRoomEvent(event), false);
|
sendRoomEvent(prepareRoomEvent(event), false);
|
||||||
|
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
|
|
||||||
usersLock.lockForWrite();
|
usersLock.lockForWrite();
|
||||||
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeExternalUser(const QString &name)
|
void Server_Room::removeExternalUser(const QString &name)
|
||||||
{
|
{
|
||||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
|
|
||||||
usersLock.lockForWrite();
|
usersLock.lockForWrite();
|
||||||
if (externalUsers.contains(name))
|
if (externalUsers.contains(name))
|
||||||
externalUsers.remove(name);
|
externalUsers.remove(name);
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
Event_LeaveRoom event;
|
Event_LeaveRoom event;
|
||||||
event.set_name(name.toStdString());
|
event.set_name(name.toStdString());
|
||||||
sendRoomEvent(prepareRoomEvent(event), false);
|
sendRoomEvent(prepareRoomEvent(event), false);
|
||||||
|
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
||||||
{
|
{
|
||||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
|
|
||||||
gamesLock.lockForWrite();
|
gamesLock.lockForWrite();
|
||||||
if (!gameInfo.has_player_count() && externalGames.contains(gameInfo.game_id()))
|
if (!gameInfo.has_player_count() && externalGames.contains(gameInfo.game_id()))
|
||||||
externalGames.remove(gameInfo.game_id());
|
externalGames.remove(gameInfo.game_id());
|
||||||
else
|
else
|
||||||
externalGames.insert(gameInfo.game_id(), gameInfo);
|
externalGames.insert(gameInfo.game_id(), gameInfo);
|
||||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
|
|
||||||
broadcastGameListUpdate(gameInfo, false);
|
broadcastGameListUpdate(gameInfo, false);
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
|
Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
|
||||||
{
|
{
|
||||||
// This function is called from the Server thread and from the S_PH thread.
|
// This function is called from the Server thread and from the S_PH thread.
|
||||||
// server->roomsMutex is always locked.
|
// server->roomsMutex is always locked.
|
||||||
|
|
||||||
QReadLocker roomGamesLocker(&gamesLock);
|
QReadLocker roomGamesLocker(&gamesLock);
|
||||||
Server_Game *g = games.value(cmd.game_id());
|
Server_Game *g = games.value(cmd.game_id());
|
||||||
if (!g) {
|
if (!g) {
|
||||||
if (externalGames.contains(cmd.game_id())) {
|
if (externalGames.contains(cmd.game_id())) {
|
||||||
CommandContainer cont;
|
CommandContainer cont;
|
||||||
cont.set_cmd_id(rc.getCmdId());
|
cont.set_cmd_id(rc.getCmdId());
|
||||||
RoomCommand *roomCommand = cont.add_room_command();
|
RoomCommand *roomCommand = cont.add_room_command();
|
||||||
roomCommand->GetReflection()->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
|
roomCommand->GetReflection()->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
|
||||||
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(), userInterface->getUserInfo()->session_id(), id);
|
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(), userInterface->getUserInfo()->session_id(), id);
|
||||||
|
|
||||||
return Response::RespNothing;
|
return Response::RespNothing;
|
||||||
} else
|
} else
|
||||||
return Response::RespNameNotFound;
|
return Response::RespNameNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker gameLocker(&g->gameMutex);
|
QMutexLocker gameLocker(&g->gameMutex);
|
||||||
|
|
||||||
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions());
|
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions());
|
||||||
if (result == Response::RespOk)
|
if (result == Response::RespOk)
|
||||||
g->addPlayer(userInterface, rc, cmd.spectator());
|
g->addPlayer(userInterface, rc, cmd.spectator());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
||||||
{
|
{
|
||||||
Event_RoomSay event;
|
Event_RoomSay event;
|
||||||
event.set_name(userName.toStdString());
|
event.set_name(userName.toStdString());
|
||||||
event.set_message(s.toStdString());
|
event.set_message(s.toStdString());
|
||||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
||||||
{
|
{
|
||||||
usersLock.lockForRead();
|
usersLock.lockForRead();
|
||||||
{
|
{
|
||||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||||
while (userIterator.hasNext())
|
while (userIterator.hasNext())
|
||||||
userIterator.next().value()->sendProtocolItem(*event);
|
userIterator.next().value()->sendProtocolItem(*event);
|
||||||
}
|
}
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
if (sendToIsl)
|
if (sendToIsl)
|
||||||
static_cast<Server *>(parent())->sendIsl_RoomEvent(*event);
|
static_cast<Server *>(parent())->sendIsl_RoomEvent(*event);
|
||||||
|
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl)
|
void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl)
|
||||||
{
|
{
|
||||||
Event_ListGames event;
|
Event_ListGames event;
|
||||||
event.add_game_list()->CopyFrom(gameInfo);
|
event.add_game_list()->CopyFrom(gameInfo);
|
||||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::addGame(Server_Game *game)
|
void Server_Room::addGame(Server_Game *game)
|
||||||
{
|
{
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
|
|
||||||
gamesLock.lockForWrite();
|
gamesLock.lockForWrite();
|
||||||
connect(game, SIGNAL(gameInfoChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)));
|
connect(game, SIGNAL(gameInfoChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)));
|
||||||
|
|
||||||
game->gameMutex.lock();
|
game->gameMutex.lock();
|
||||||
games.insert(game->getGameId(), game);
|
games.insert(game->getGameId(), game);
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
game->getInfo(gameInfo);
|
game->getInfo(gameInfo);
|
||||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||||
game->gameMutex.unlock();
|
game->gameMutex.unlock();
|
||||||
gamesLock.unlock();
|
gamesLock.unlock();
|
||||||
|
|
||||||
// XXX This can be removed during the next client update.
|
// XXX This can be removed during the next client update.
|
||||||
usersLock.lockForRead();
|
usersLock.lockForRead();
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
emit gameListChanged(gameInfo);
|
emit gameListChanged(gameInfo);
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeGame(Server_Game *game)
|
void Server_Room::removeGame(Server_Game *game)
|
||||||
{
|
{
|
||||||
// No need to lock gamesLock or gameMutex. This method is only
|
// No need to lock gamesLock or gameMutex. This method is only
|
||||||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||||
|
|
||||||
disconnect(game, 0, this, 0);
|
disconnect(game, 0, this, 0);
|
||||||
|
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
game->getInfo(gameInfo);
|
game->getInfo(gameInfo);
|
||||||
emit gameListChanged(gameInfo);
|
emit gameListChanged(gameInfo);
|
||||||
|
|
||||||
games.remove(game->getGameId());
|
games.remove(game->getGameId());
|
||||||
|
|
||||||
ServerInfo_Room roomInfo;
|
ServerInfo_Room roomInfo;
|
||||||
roomInfo.set_room_id(id);
|
roomInfo.set_room_id(id);
|
||||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||||
|
|
||||||
// XXX This can be removed during the next client update.
|
// XXX This can be removed during the next client update.
|
||||||
usersLock.lockForRead();
|
usersLock.lockForRead();
|
||||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
emit roomInfoChanged(roomInfo);
|
emit roomInfoChanged(roomInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||||
{
|
{
|
||||||
QReadLocker locker(&gamesLock);
|
QReadLocker locker(&gamesLock);
|
||||||
|
|
||||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
while (gamesIterator.hasNext())
|
while (gamesIterator.hasNext())
|
||||||
if (gamesIterator.next().value()->getCreatorInfo()->name() == userName.toStdString())
|
if (gamesIterator.next().value()->getCreatorInfo()->name() == userName.toStdString())
|
||||||
++result;
|
++result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) const
|
QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) const
|
||||||
{
|
{
|
||||||
QReadLocker locker(&gamesLock);
|
QReadLocker locker(&gamesLock);
|
||||||
|
|
||||||
QList<ServerInfo_Game> result;
|
QList<ServerInfo_Game> result;
|
||||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||||
while (gamesIterator.hasNext()) {
|
while (gamesIterator.hasNext()) {
|
||||||
Server_Game *game = gamesIterator.next().value();
|
Server_Game *game = gamesIterator.next().value();
|
||||||
if (game->containsUser(userName)) {
|
if (game->containsUser(userName)) {
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
game->getInfo(gameInfo);
|
game->getInfo(gameInfo);
|
||||||
result.append(gameInfo);
|
result.append(gameInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,58 +24,58 @@ class ResponseContainer;
|
||||||
class Server_AbstractUserInterface;
|
class Server_AbstractUserInterface;
|
||||||
|
|
||||||
class Server_Room : public QObject {
|
class Server_Room : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void roomInfoChanged(const ServerInfo_Room &roomInfo);
|
void roomInfoChanged(const ServerInfo_Room &roomInfo);
|
||||||
void gameListChanged(const ServerInfo_Game &gameInfo);
|
void gameListChanged(const ServerInfo_Game &gameInfo);
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
bool autoJoin;
|
bool autoJoin;
|
||||||
QString joinMessage;
|
QString joinMessage;
|
||||||
QStringList gameTypes;
|
QStringList gameTypes;
|
||||||
QMap<int, Server_Game *> games;
|
QMap<int, Server_Game *> games;
|
||||||
QMap<int, ServerInfo_Game> externalGames;
|
QMap<int, ServerInfo_Game> externalGames;
|
||||||
QMap<QString, Server_ProtocolHandler *> users;
|
QMap<QString, Server_ProtocolHandler *> users;
|
||||||
QMap<QString, ServerInfo_User_Container> externalUsers;
|
QMap<QString, ServerInfo_User_Container> externalUsers;
|
||||||
private slots:
|
private slots:
|
||||||
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
|
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
|
||||||
public:
|
public:
|
||||||
mutable QReadWriteLock usersLock;
|
mutable QReadWriteLock usersLock;
|
||||||
mutable QReadWriteLock gamesLock;
|
mutable QReadWriteLock gamesLock;
|
||||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||||
~Server_Room();
|
~Server_Room();
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
QString getDescription() const { return description; }
|
QString getDescription() const { return description; }
|
||||||
bool getAutoJoin() const { return autoJoin; }
|
bool getAutoJoin() const { return autoJoin; }
|
||||||
QString getJoinMessage() const { return joinMessage; }
|
QString getJoinMessage() const { return joinMessage; }
|
||||||
const QStringList &getGameTypes() const { return gameTypes; }
|
const QStringList &getGameTypes() const { return gameTypes; }
|
||||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||||
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
||||||
Server *getServer() const;
|
Server *getServer() const;
|
||||||
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
|
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
|
||||||
int getGamesCreatedByUser(const QString &name) 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 addClient(Server_ProtocolHandler *client);
|
||||||
void removeClient(Server_ProtocolHandler *client);
|
void removeClient(Server_ProtocolHandler *client);
|
||||||
|
|
||||||
void addExternalUser(const ServerInfo_User &userInfo);
|
void addExternalUser(const ServerInfo_User &userInfo);
|
||||||
void removeExternalUser(const QString &name);
|
void removeExternalUser(const QString &name);
|
||||||
const QMap<QString, ServerInfo_User_Container> &getExternalUsers() const { return externalUsers; }
|
const QMap<QString, ServerInfo_User_Container> &getExternalUsers() const { return externalUsers; }
|
||||||
void updateExternalGameList(const ServerInfo_Game &gameInfo);
|
void updateExternalGameList(const ServerInfo_Game &gameInfo);
|
||||||
|
|
||||||
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface);
|
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface);
|
||||||
|
|
||||||
void say(const QString &userName, const QString &s, bool sendToIsl = true);
|
void say(const QString &userName, const QString &s, bool sendToIsl = true);
|
||||||
|
|
||||||
void addGame(Server_Game *game);
|
void addGame(Server_Game *game);
|
||||||
void removeGame(Server_Game *game);
|
void removeGame(Server_Game *game);
|
||||||
|
|
||||||
void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
|
void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
|
||||||
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
|
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,46 +7,46 @@ ServerInfo_User_Container::ServerInfo_User_Container(ServerInfo_User *_userInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User &_userInfo)
|
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User &_userInfo)
|
||||||
: userInfo(new ServerInfo_User(_userInfo))
|
: userInfo(new ServerInfo_User(_userInfo))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User_Container &other)
|
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User_Container &other)
|
||||||
{
|
{
|
||||||
if (other.userInfo)
|
if (other.userInfo)
|
||||||
userInfo = new ServerInfo_User(*other.userInfo);
|
userInfo = new ServerInfo_User(*other.userInfo);
|
||||||
else
|
else
|
||||||
userInfo = 0;
|
userInfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User_Container::~ServerInfo_User_Container()
|
ServerInfo_User_Container::~ServerInfo_User_Container()
|
||||||
{
|
{
|
||||||
delete userInfo;
|
delete userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerInfo_User_Container::setUserInfo(const ServerInfo_User &_userInfo)
|
void ServerInfo_User_Container::setUserInfo(const ServerInfo_User &_userInfo)
|
||||||
{
|
{
|
||||||
userInfo = new ServerInfo_User(_userInfo);
|
userInfo = new ServerInfo_User(_userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User &ServerInfo_User_Container::copyUserInfo(ServerInfo_User &result, bool complete, bool internalInfo, bool sessionInfo) const
|
ServerInfo_User &ServerInfo_User_Container::copyUserInfo(ServerInfo_User &result, bool complete, bool internalInfo, bool sessionInfo) const
|
||||||
{
|
{
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
result.CopyFrom(*userInfo);
|
result.CopyFrom(*userInfo);
|
||||||
if (!sessionInfo) {
|
if (!sessionInfo) {
|
||||||
result.clear_session_id();
|
result.clear_session_id();
|
||||||
result.clear_address();
|
result.clear_address();
|
||||||
}
|
}
|
||||||
if (!internalInfo)
|
if (!internalInfo)
|
||||||
result.clear_id();
|
result.clear_id();
|
||||||
if (!complete)
|
if (!complete)
|
||||||
result.clear_avatar_bmp();
|
result.clear_avatar_bmp();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_User ServerInfo_User_Container::copyUserInfo(bool complete, bool internalInfo, bool sessionInfo) const
|
ServerInfo_User ServerInfo_User_Container::copyUserInfo(bool complete, bool internalInfo, bool sessionInfo) const
|
||||||
{
|
{
|
||||||
ServerInfo_User result;
|
ServerInfo_User result;
|
||||||
return copyUserInfo(result, complete, internalInfo, sessionInfo);
|
return copyUserInfo(result, complete, internalInfo, sessionInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,16 @@ class ServerInfo_User;
|
||||||
|
|
||||||
class ServerInfo_User_Container {
|
class ServerInfo_User_Container {
|
||||||
protected:
|
protected:
|
||||||
ServerInfo_User *userInfo;
|
ServerInfo_User *userInfo;
|
||||||
public:
|
public:
|
||||||
ServerInfo_User_Container(ServerInfo_User *_userInfo = 0);
|
ServerInfo_User_Container(ServerInfo_User *_userInfo = 0);
|
||||||
ServerInfo_User_Container(const ServerInfo_User &_userInfo);
|
ServerInfo_User_Container(const ServerInfo_User &_userInfo);
|
||||||
ServerInfo_User_Container(const ServerInfo_User_Container &other);
|
ServerInfo_User_Container(const ServerInfo_User_Container &other);
|
||||||
virtual ~ServerInfo_User_Container();
|
virtual ~ServerInfo_User_Container();
|
||||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||||
void setUserInfo(const ServerInfo_User &_userInfo);
|
void setUserInfo(const ServerInfo_User &_userInfo);
|
||||||
ServerInfo_User ©UserInfo(ServerInfo_User &result, bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
ServerInfo_User ©UserInfo(ServerInfo_User &result, bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||||
ServerInfo_User copyUserInfo(bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
ServerInfo_User copyUserInfo(bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue