mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
response codes
This commit is contained in:
parent
3461b60183
commit
bd2855cb95
7 changed files with 186 additions and 92 deletions
|
|
@ -9,28 +9,43 @@
|
|||
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
class QXmlStreamAttributes;
|
||||
|
||||
class Command : public QObject {
|
||||
class ProtocolItem : public QObject {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
typedef Command *(*NewCommandFunction)();
|
||||
static QHash<QString, NewCommandFunction> commandHash;
|
||||
typedef ProtocolItem *(*NewItemFunction)();
|
||||
static QHash<QString, NewItemFunction> itemNameHash;
|
||||
|
||||
QString cmdName;
|
||||
QString itemName;
|
||||
QMap<QString, QString> parameters;
|
||||
QString currentElementText;
|
||||
void setParameter(const QString &name, const QString &value) { parameters[name] = value; }
|
||||
void setParameter(const QString &name, bool value) { parameters[name] = (value ? "1" : "0"); }
|
||||
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
|
||||
virtual void extractParameters() { };
|
||||
virtual QString getItemType() const = 0;
|
||||
private:
|
||||
static void initializeHashAuto();
|
||||
public:
|
||||
Command(const QString &_cmdName);
|
||||
ProtocolItem(const QString &_itemName);
|
||||
static void initializeHash();
|
||||
static Command *getNewCommand(const QString &name);
|
||||
static ProtocolItem *getNewItem(const QString &name);
|
||||
virtual bool read(QXmlStreamReader &xml);
|
||||
virtual void write(QXmlStreamWriter &xml);
|
||||
};
|
||||
|
||||
class Command : public ProtocolItem {
|
||||
private:
|
||||
int cmdId;
|
||||
static int lastCmdId;
|
||||
protected:
|
||||
QString getItemType() const { return "cmd"; }
|
||||
void extractParameters();
|
||||
public:
|
||||
Command(const QString &_itemName, int _cmdId = -1);
|
||||
};
|
||||
|
||||
class ChatCommand : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
|
@ -67,4 +82,21 @@ public:
|
|||
int getGameId() const { return gameId; }
|
||||
};
|
||||
|
||||
class ProtocolResponse : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ResponseCode { RespOk, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
|
||||
private:
|
||||
int cmdId;
|
||||
ResponseCode responseCode;
|
||||
static QHash<QString, ResponseCode> responseHash;
|
||||
protected:
|
||||
QString getItemType() const { return "resp"; }
|
||||
void extractParameters();
|
||||
public:
|
||||
ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk);
|
||||
static void initializeHash();
|
||||
static ProtocolItem *newItem() { return new ProtocolResponse; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue