game events
This commit is contained in:
parent
bd2855cb95
commit
1d6923f2a2
11 changed files with 64 additions and 762 deletions
|
@ -9,7 +9,6 @@ QHash<QString, ServerEventType> ServerEventData::eventHash;
|
|||
ServerEventData::ServerEventData(const QString &line)
|
||||
{
|
||||
if (eventHash.isEmpty()) {
|
||||
eventHash.insert("player_id", eventPlayerId);
|
||||
eventHash.insert("say", eventSay);
|
||||
eventHash.insert("join", eventJoin);
|
||||
eventHash.insert("leave", eventLeave);
|
||||
|
@ -187,19 +186,7 @@ void Client::readLine()
|
|||
// prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone}
|
||||
if ((prefix == "private") || (prefix == "public")) {
|
||||
ServerEventData event(line);
|
||||
if (event.getEventType() == eventPlayerId) {
|
||||
QStringList data = event.getEventData();
|
||||
if (data.size() != 2) {
|
||||
// XXX
|
||||
}
|
||||
bool ok;
|
||||
int id = data[0].toInt(&ok);
|
||||
if (!ok) {
|
||||
// XXX
|
||||
}
|
||||
emit playerIdReceived(id, data[1]);
|
||||
} else
|
||||
emit gameEvent(event);
|
||||
emit gameEvent(event);
|
||||
} else if (prefix == "chat") {
|
||||
emit chatEvent(ChatEventData(line));
|
||||
} else if (prefix == "resp") {
|
||||
|
|
|
@ -31,7 +31,6 @@ enum ServerResponse {
|
|||
|
||||
enum ServerEventType {
|
||||
eventInvalid,
|
||||
eventPlayerId,
|
||||
eventSay,
|
||||
eventJoin,
|
||||
eventLeave,
|
||||
|
|
|
@ -365,8 +365,7 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
case eventSetCardAttr:
|
||||
case eventAddCounter:
|
||||
case eventSetCounter:
|
||||
case eventDelCounter:
|
||||
case eventPlayerId: {
|
||||
case eventDelCounter: {
|
||||
p->gameEvent(msg);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ DEPENDPATH += .
|
|||
INCLUDEPATH += .
|
||||
|
||||
# Input
|
||||
HEADERS += protocol.h widget.h protocol_commands.h
|
||||
SOURCES += main.cpp protocol.cpp widget.cpp protocol_commands.cpp
|
||||
HEADERS += protocol.h widget.h protocol_items.h
|
||||
SOURCES += main.cpp protocol.cpp widget.cpp protocol_items.cpp
|
||||
|
||||
CONFIG += qt debug
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <QXmlStreamWriter>
|
||||
#include <QDebug>
|
||||
#include "protocol.h"
|
||||
#include "protocol_commands.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
QHash<QString, ProtocolItem::NewItemFunction> ProtocolItem::itemNameHash;
|
||||
|
||||
|
@ -114,3 +114,23 @@ void ProtocolResponse::initializeHash()
|
|||
responseHash.insert("wrong_password", RespWrongPassword);
|
||||
responseHash.insert("spectators_not_allowed", RespSpectatorsNotAllowed);
|
||||
}
|
||||
|
||||
void GameEvent::extractParameters()
|
||||
{
|
||||
bool ok;
|
||||
gameId = parameters["game_id"].toInt(&ok);
|
||||
if (!ok)
|
||||
gameId = -1;
|
||||
isPublic = parameters["is_public"].toInt();
|
||||
playerId = parameters["player_id"].toInt(&ok);
|
||||
if (!ok)
|
||||
playerId = -1;
|
||||
}
|
||||
|
||||
GameEvent::GameEvent(const QString &_eventName, int _gameId, bool _isPublic, int _playerId)
|
||||
: ProtocolItem(_eventName), gameId(_gameId), isPublic(_isPublic), playerId(_playerId)
|
||||
{
|
||||
setParameter("game_id", gameId);
|
||||
setParameter("is_public", isPublic);
|
||||
setParameter("player_id", playerId);
|
||||
}
|
||||
|
|
|
@ -99,4 +99,17 @@ public:
|
|||
static ProtocolItem *newItem() { return new ProtocolResponse; }
|
||||
};
|
||||
|
||||
class GameEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int gameId;
|
||||
bool isPublic;
|
||||
int playerId;
|
||||
protected:
|
||||
QString getItemType() const { return "game_event"; }
|
||||
void extractParameters();
|
||||
public:
|
||||
GameEvent(const QString &_eventName, int _gameId, bool _isPublic, int _playerId);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,340 +0,0 @@
|
|||
#include "protocol.h"
|
||||
#include "protocol_commands.h"
|
||||
|
||||
Command_Ping::Command_Ping()
|
||||
: Command("ping")
|
||||
{
|
||||
}
|
||||
Command_Login::Command_Login(const QString &_username, const QString &_password)
|
||||
: Command("login"), username(_username), password(_password)
|
||||
{
|
||||
setParameter("username", username);
|
||||
setParameter("password", password);
|
||||
}
|
||||
void Command_Login::extractParameters()
|
||||
{
|
||||
Command::extractParameters();
|
||||
username = parameters["username"];
|
||||
password = parameters["password"];
|
||||
}
|
||||
Command_ChatListChannels::Command_ChatListChannels()
|
||||
: Command("chat_list_channels")
|
||||
{
|
||||
}
|
||||
Command_ChatJoinChannel::Command_ChatJoinChannel(const QString &_channel)
|
||||
: Command("chat_join_channel"), channel(_channel)
|
||||
{
|
||||
setParameter("channel", channel);
|
||||
}
|
||||
void Command_ChatJoinChannel::extractParameters()
|
||||
{
|
||||
Command::extractParameters();
|
||||
channel = parameters["channel"];
|
||||
}
|
||||
Command_ChatLeaveChannel::Command_ChatLeaveChannel(const QString &_channel)
|
||||
: ChatCommand("chat_leave_channel", _channel)
|
||||
{
|
||||
}
|
||||
Command_ChatSay::Command_ChatSay(const QString &_channel, const QString &_message)
|
||||
: ChatCommand("chat_say", _channel), message(_message)
|
||||
{
|
||||
setParameter("message", message);
|
||||
}
|
||||
void Command_ChatSay::extractParameters()
|
||||
{
|
||||
ChatCommand::extractParameters();
|
||||
message = parameters["message"];
|
||||
}
|
||||
Command_ListGames::Command_ListGames()
|
||||
: Command("list_games")
|
||||
{
|
||||
}
|
||||
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed)
|
||||
: Command("create_game"), description(_description), password(_password), maxPlayers(_maxPlayers), spectatorsAllowed(_spectatorsAllowed)
|
||||
{
|
||||
setParameter("description", description);
|
||||
setParameter("password", password);
|
||||
setParameter("max_players", maxPlayers);
|
||||
setParameter("spectators_allowed", spectatorsAllowed);
|
||||
}
|
||||
void Command_CreateGame::extractParameters()
|
||||
{
|
||||
Command::extractParameters();
|
||||
description = parameters["description"];
|
||||
password = parameters["password"];
|
||||
maxPlayers = parameters["max_players"].toInt();
|
||||
spectatorsAllowed = (parameters["spectators_allowed"] == "1");
|
||||
}
|
||||
Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator)
|
||||
: Command("join_game"), gameId(_gameId), password(_password), spectator(_spectator)
|
||||
{
|
||||
setParameter("game_id", gameId);
|
||||
setParameter("password", password);
|
||||
setParameter("spectator", spectator);
|
||||
}
|
||||
void Command_JoinGame::extractParameters()
|
||||
{
|
||||
Command::extractParameters();
|
||||
gameId = parameters["game_id"].toInt();
|
||||
password = parameters["password"];
|
||||
spectator = (parameters["spectator"] == "1");
|
||||
}
|
||||
Command_LeaveGame::Command_LeaveGame(int _gameId)
|
||||
: GameCommand("leave_game", _gameId)
|
||||
{
|
||||
}
|
||||
Command_Say::Command_Say(int _gameId, const QString &_message)
|
||||
: GameCommand("say", _gameId), message(_message)
|
||||
{
|
||||
setParameter("message", message);
|
||||
}
|
||||
void Command_Say::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
message = parameters["message"];
|
||||
}
|
||||
Command_Shuffle::Command_Shuffle(int _gameId)
|
||||
: GameCommand("shuffle", _gameId)
|
||||
{
|
||||
}
|
||||
Command_RollDie::Command_RollDie(int _gameId, int _sides)
|
||||
: GameCommand("roll_die", _gameId), sides(_sides)
|
||||
{
|
||||
setParameter("sides", sides);
|
||||
}
|
||||
void Command_RollDie::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
sides = parameters["sides"].toInt();
|
||||
}
|
||||
Command_DrawCards::Command_DrawCards(int _gameId, int _number)
|
||||
: GameCommand("draw_cards", _gameId), number(_number)
|
||||
{
|
||||
setParameter("number", number);
|
||||
}
|
||||
void Command_DrawCards::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
number = parameters["number"].toInt();
|
||||
}
|
||||
Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown)
|
||||
: GameCommand("move_card", _gameId), startZone(_startZone), cardId(_cardId), targetZone(_targetZone), x(_x), y(_y), faceDown(_faceDown)
|
||||
{
|
||||
setParameter("start_zone", startZone);
|
||||
setParameter("card_id", cardId);
|
||||
setParameter("target_zone", targetZone);
|
||||
setParameter("x", x);
|
||||
setParameter("y", y);
|
||||
setParameter("face_down", faceDown);
|
||||
}
|
||||
void Command_MoveCard::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
startZone = parameters["start_zone"];
|
||||
cardId = parameters["card_id"].toInt();
|
||||
targetZone = parameters["target_zone"];
|
||||
x = parameters["x"].toInt();
|
||||
y = parameters["y"].toInt();
|
||||
faceDown = (parameters["face_down"] == "1");
|
||||
}
|
||||
Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_name, const QString &_pt, int _x, int _y)
|
||||
: GameCommand("create_token", _gameId), zone(_zone), name(_name), pt(_pt), x(_x), y(_y)
|
||||
{
|
||||
setParameter("zone", zone);
|
||||
setParameter("name", name);
|
||||
setParameter("pt", pt);
|
||||
setParameter("x", x);
|
||||
setParameter("y", y);
|
||||
}
|
||||
void Command_CreateToken::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
zone = parameters["zone"];
|
||||
name = parameters["name"];
|
||||
pt = parameters["pt"];
|
||||
x = parameters["x"].toInt();
|
||||
y = parameters["y"].toInt();
|
||||
}
|
||||
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetPlayerZone, int _targetCardId, int _color)
|
||||
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetPlayerZone(_targetPlayerZone), targetCardId(_targetCardId), color(_color)
|
||||
{
|
||||
setParameter("start_player_id", startPlayerId);
|
||||
setParameter("start_zone", startZone);
|
||||
setParameter("start_card_id", startCardId);
|
||||
setParameter("target_player_id", targetPlayerId);
|
||||
setParameter("target_player_zone", targetPlayerZone);
|
||||
setParameter("target_card_id", targetCardId);
|
||||
setParameter("color", color);
|
||||
}
|
||||
void Command_CreateArrow::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
startPlayerId = parameters["start_player_id"].toInt();
|
||||
startZone = parameters["start_zone"];
|
||||
startCardId = parameters["start_card_id"].toInt();
|
||||
targetPlayerId = parameters["target_player_id"].toInt();
|
||||
targetPlayerZone = parameters["target_player_zone"];
|
||||
targetCardId = parameters["target_card_id"].toInt();
|
||||
color = parameters["color"].toInt();
|
||||
}
|
||||
Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId)
|
||||
: GameCommand("delete_arrow", _gameId), arrowId(_arrowId)
|
||||
{
|
||||
setParameter("arrow_id", arrowId);
|
||||
}
|
||||
void Command_DeleteArrow::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
arrowId = parameters["arrow_id"].toInt();
|
||||
}
|
||||
Command_SetCardAttr::Command_SetCardAttr(int _gameId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue)
|
||||
: GameCommand("set_card_attr", _gameId), zone(_zone), cardId(_cardId), attrName(_attrName), attrValue(_attrValue)
|
||||
{
|
||||
setParameter("zone", zone);
|
||||
setParameter("card_id", cardId);
|
||||
setParameter("attr_name", attrName);
|
||||
setParameter("attr_value", attrValue);
|
||||
}
|
||||
void Command_SetCardAttr::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
zone = parameters["zone"];
|
||||
cardId = parameters["card_id"].toInt();
|
||||
attrName = parameters["attr_name"];
|
||||
attrValue = parameters["attr_value"];
|
||||
}
|
||||
Command_ReadyStart::Command_ReadyStart(int _gameId)
|
||||
: GameCommand("ready_start", _gameId)
|
||||
{
|
||||
}
|
||||
Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta)
|
||||
: GameCommand("inc_counter", _gameId), counterId(_counterId), delta(_delta)
|
||||
{
|
||||
setParameter("counter_id", counterId);
|
||||
setParameter("delta", delta);
|
||||
}
|
||||
void Command_IncCounter::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
counterId = parameters["counter_id"].toInt();
|
||||
delta = parameters["delta"].toInt();
|
||||
}
|
||||
Command_AddCounter::Command_AddCounter(int _gameId, const QString &_counterName, int _color, int _radius, int _value)
|
||||
: GameCommand("add_counter", _gameId), counterName(_counterName), color(_color), radius(_radius), value(_value)
|
||||
{
|
||||
setParameter("counter_name", counterName);
|
||||
setParameter("color", color);
|
||||
setParameter("radius", radius);
|
||||
setParameter("value", value);
|
||||
}
|
||||
void Command_AddCounter::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
counterName = parameters["counter_name"];
|
||||
color = parameters["color"].toInt();
|
||||
radius = parameters["radius"].toInt();
|
||||
value = parameters["value"].toInt();
|
||||
}
|
||||
Command_SetCounter::Command_SetCounter(int _gameId, int _counterId, int _value)
|
||||
: GameCommand("set_counter", _gameId), counterId(_counterId), value(_value)
|
||||
{
|
||||
setParameter("counter_id", counterId);
|
||||
setParameter("value", value);
|
||||
}
|
||||
void Command_SetCounter::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
counterId = parameters["counter_id"].toInt();
|
||||
value = parameters["value"].toInt();
|
||||
}
|
||||
Command_DelCounter::Command_DelCounter(int _gameId, int _counterId)
|
||||
: GameCommand("del_counter", _gameId), counterId(_counterId)
|
||||
{
|
||||
setParameter("counter_id", counterId);
|
||||
}
|
||||
void Command_DelCounter::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
counterId = parameters["counter_id"].toInt();
|
||||
}
|
||||
Command_NextTurn::Command_NextTurn(int _gameId)
|
||||
: GameCommand("next_turn", _gameId)
|
||||
{
|
||||
}
|
||||
Command_SetActivePhase::Command_SetActivePhase(int _gameId, int _phase)
|
||||
: GameCommand("set_active_phase", _gameId), phase(_phase)
|
||||
{
|
||||
setParameter("phase", phase);
|
||||
}
|
||||
void Command_SetActivePhase::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
phase = parameters["phase"].toInt();
|
||||
}
|
||||
Command_DumpZone::Command_DumpZone(int _gameId, int _playerId, const QString &_zoneName, int _numberCards)
|
||||
: GameCommand("dump_zone", _gameId), playerId(_playerId), zoneName(_zoneName), numberCards(_numberCards)
|
||||
{
|
||||
setParameter("player_id", playerId);
|
||||
setParameter("zone_name", zoneName);
|
||||
setParameter("number_cards", numberCards);
|
||||
}
|
||||
void Command_DumpZone::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
playerId = parameters["player_id"].toInt();
|
||||
zoneName = parameters["zone_name"];
|
||||
numberCards = parameters["number_cards"].toInt();
|
||||
}
|
||||
Command_StopDumpZone::Command_StopDumpZone(int _gameId, int _playerId, const QString &_zoneName)
|
||||
: GameCommand("stop_dump_zone", _gameId), playerId(_playerId), zoneName(_zoneName)
|
||||
{
|
||||
setParameter("player_id", playerId);
|
||||
setParameter("zone_name", zoneName);
|
||||
}
|
||||
void Command_StopDumpZone::extractParameters()
|
||||
{
|
||||
GameCommand::extractParameters();
|
||||
playerId = parameters["player_id"].toInt();
|
||||
zoneName = parameters["zone_name"];
|
||||
}
|
||||
Command_DumpAll::Command_DumpAll(int _gameId)
|
||||
: GameCommand("dump_all", _gameId)
|
||||
{
|
||||
}
|
||||
Command_SubmitDeck::Command_SubmitDeck(int _gameId)
|
||||
: GameCommand("submit_deck", _gameId)
|
||||
{
|
||||
}
|
||||
void ProtocolItem::initializeHashAuto()
|
||||
{
|
||||
itemNameHash.insert("cmdping", Command_Ping::newItem);
|
||||
itemNameHash.insert("cmdlogin", Command_Login::newItem);
|
||||
itemNameHash.insert("cmdchat_list_channels", Command_ChatListChannels::newItem);
|
||||
itemNameHash.insert("cmdchat_join_channel", Command_ChatJoinChannel::newItem);
|
||||
itemNameHash.insert("cmdchat_leave_channel", Command_ChatLeaveChannel::newItem);
|
||||
itemNameHash.insert("cmdchat_say", Command_ChatSay::newItem);
|
||||
itemNameHash.insert("cmdlist_games", Command_ListGames::newItem);
|
||||
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
|
||||
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
|
||||
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
|
||||
itemNameHash.insert("cmdsay", Command_Say::newItem);
|
||||
itemNameHash.insert("cmdshuffle", Command_Shuffle::newItem);
|
||||
itemNameHash.insert("cmdroll_die", Command_RollDie::newItem);
|
||||
itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem);
|
||||
itemNameHash.insert("cmdmove_card", Command_MoveCard::newItem);
|
||||
itemNameHash.insert("cmdcreate_token", Command_CreateToken::newItem);
|
||||
itemNameHash.insert("cmdcreate_arrow", Command_CreateArrow::newItem);
|
||||
itemNameHash.insert("cmddelete_arrow", Command_DeleteArrow::newItem);
|
||||
itemNameHash.insert("cmdset_card_attr", Command_SetCardAttr::newItem);
|
||||
itemNameHash.insert("cmdready_start", Command_ReadyStart::newItem);
|
||||
itemNameHash.insert("cmdinc_counter", Command_IncCounter::newItem);
|
||||
itemNameHash.insert("cmdadd_counter", Command_AddCounter::newItem);
|
||||
itemNameHash.insert("cmdset_counter", Command_SetCounter::newItem);
|
||||
itemNameHash.insert("cmddel_counter", Command_DelCounter::newItem);
|
||||
itemNameHash.insert("cmdnext_turn", Command_NextTurn::newItem);
|
||||
itemNameHash.insert("cmdset_active_phase", Command_SetActivePhase::newItem);
|
||||
itemNameHash.insert("cmddump_zone", Command_DumpZone::newItem);
|
||||
itemNameHash.insert("cmdstop_dump_zone", Command_StopDumpZone::newItem);
|
||||
itemNameHash.insert("cmddump_all", Command_DumpAll::newItem);
|
||||
itemNameHash.insert("cmdsubmit_deck", Command_SubmitDeck::newItem);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
0:ping
|
||||
0:login:s,username:s,password
|
||||
0:chat_list_channels
|
||||
0:chat_join_channel:s,channel
|
||||
1:chat_leave_channel
|
||||
1:chat_say:s,message
|
||||
0:list_games
|
||||
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed
|
||||
0:join_game:i,game_id:s,password:b,spectator
|
||||
2:leave_game
|
||||
2:say:s,message
|
||||
2:shuffle
|
||||
2:roll_die:i,sides
|
||||
2:draw_cards:i,number
|
||||
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
|
||||
2:create_token:s,zone:s,name:s,pt:i,x:i,y
|
||||
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_player_zone:i,target_card_id:i,color
|
||||
2:delete_arrow:i,arrow_id
|
||||
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||
2:ready_start
|
||||
2:inc_counter:i,counter_id:i,delta
|
||||
2:add_counter:s,counter_name:i,color:i,radius:i,value
|
||||
2:set_counter:i,counter_id:i,value
|
||||
2:del_counter:i,counter_id
|
||||
2:next_turn
|
||||
2:set_active_phase:i,phase
|
||||
2:dump_zone:i,player_id:s,zone_name:i,number_cards
|
||||
2:stop_dump_zone:i,player_id:s,zone_name
|
||||
2:dump_all
|
||||
2:submit_deck
|
|
@ -1,361 +0,0 @@
|
|||
#ifndef PROTOCOL_COMMANDS_H
|
||||
#define PROTOCOL_COMMANDS_H
|
||||
|
||||
#include "protocol.h"
|
||||
|
||||
class Command_Ping : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_Ping();
|
||||
static ProtocolItem *newItem() { return new Command_Ping; }
|
||||
};
|
||||
class Command_Login : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString username;
|
||||
QString password;
|
||||
public:
|
||||
Command_Login(const QString &_username = QString(), const QString &_password = QString());
|
||||
QString getUsername() const { return username; }
|
||||
QString getPassword() const { return password; }
|
||||
static ProtocolItem *newItem() { return new Command_Login; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_ChatListChannels : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_ChatListChannels();
|
||||
static ProtocolItem *newItem() { return new Command_ChatListChannels; }
|
||||
};
|
||||
class Command_ChatJoinChannel : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString channel;
|
||||
public:
|
||||
Command_ChatJoinChannel(const QString &_channel = QString());
|
||||
QString getChannel() const { return channel; }
|
||||
static ProtocolItem *newItem() { return new Command_ChatJoinChannel; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_ChatLeaveChannel : public ChatCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_ChatLeaveChannel(const QString &_channel = QString());
|
||||
static ProtocolItem *newItem() { return new Command_ChatLeaveChannel; }
|
||||
};
|
||||
class Command_ChatSay : public ChatCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString message;
|
||||
public:
|
||||
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString());
|
||||
QString getMessage() const { return message; }
|
||||
static ProtocolItem *newItem() { return new Command_ChatSay; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_ListGames : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_ListGames();
|
||||
static ProtocolItem *newItem() { return new Command_ListGames; }
|
||||
};
|
||||
class Command_CreateGame : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers;
|
||||
bool spectatorsAllowed;
|
||||
public:
|
||||
Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false);
|
||||
QString getDescription() const { return description; }
|
||||
QString getPassword() const { return password; }
|
||||
int getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
static ProtocolItem *newItem() { return new Command_CreateGame; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_JoinGame : public Command {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int gameId;
|
||||
QString password;
|
||||
bool spectator;
|
||||
public:
|
||||
Command_JoinGame(int _gameId = -1, const QString &_password = QString(), bool _spectator = false);
|
||||
int getGameId() const { return gameId; }
|
||||
QString getPassword() const { return password; }
|
||||
bool getSpectator() const { return spectator; }
|
||||
static ProtocolItem *newItem() { return new Command_JoinGame; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_LeaveGame : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_LeaveGame(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_LeaveGame; }
|
||||
};
|
||||
class Command_Say : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString message;
|
||||
public:
|
||||
Command_Say(int _gameId = -1, const QString &_message = QString());
|
||||
QString getMessage() const { return message; }
|
||||
static ProtocolItem *newItem() { return new Command_Say; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_Shuffle : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_Shuffle(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_Shuffle; }
|
||||
};
|
||||
class Command_RollDie : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int sides;
|
||||
public:
|
||||
Command_RollDie(int _gameId = -1, int _sides = -1);
|
||||
int getSides() const { return sides; }
|
||||
static ProtocolItem *newItem() { return new Command_RollDie; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_DrawCards : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int number;
|
||||
public:
|
||||
Command_DrawCards(int _gameId = -1, int _number = -1);
|
||||
int getNumber() const { return number; }
|
||||
static ProtocolItem *newItem() { return new Command_DrawCards; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_MoveCard : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString startZone;
|
||||
int cardId;
|
||||
QString targetZone;
|
||||
int x;
|
||||
int y;
|
||||
bool faceDown;
|
||||
public:
|
||||
Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false);
|
||||
QString getStartZone() const { return startZone; }
|
||||
int getCardId() const { return cardId; }
|
||||
QString getTargetZone() const { return targetZone; }
|
||||
int getX() const { return x; }
|
||||
int getY() const { return y; }
|
||||
bool getFaceDown() const { return faceDown; }
|
||||
static ProtocolItem *newItem() { return new Command_MoveCard; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_CreateToken : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString zone;
|
||||
QString name;
|
||||
QString pt;
|
||||
int x;
|
||||
int y;
|
||||
public:
|
||||
Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_name = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1);
|
||||
QString getZone() const { return zone; }
|
||||
QString getName() const { return name; }
|
||||
QString getPt() const { return pt; }
|
||||
int getX() const { return x; }
|
||||
int getY() const { return y; }
|
||||
static ProtocolItem *newItem() { return new Command_CreateToken; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_CreateArrow : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int startPlayerId;
|
||||
QString startZone;
|
||||
int startCardId;
|
||||
int targetPlayerId;
|
||||
QString targetPlayerZone;
|
||||
int targetCardId;
|
||||
int color;
|
||||
public:
|
||||
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetPlayerZone = QString(), int _targetCardId = -1, int _color = -1);
|
||||
int getStartPlayerId() const { return startPlayerId; }
|
||||
QString getStartZone() const { return startZone; }
|
||||
int getStartCardId() const { return startCardId; }
|
||||
int getTargetPlayerId() const { return targetPlayerId; }
|
||||
QString getTargetPlayerZone() const { return targetPlayerZone; }
|
||||
int getTargetCardId() const { return targetCardId; }
|
||||
int getColor() const { return color; }
|
||||
static ProtocolItem *newItem() { return new Command_CreateArrow; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_DeleteArrow : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int arrowId;
|
||||
public:
|
||||
Command_DeleteArrow(int _gameId = -1, int _arrowId = -1);
|
||||
int getArrowId() const { return arrowId; }
|
||||
static ProtocolItem *newItem() { return new Command_DeleteArrow; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_SetCardAttr : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString zone;
|
||||
int cardId;
|
||||
QString attrName;
|
||||
QString attrValue;
|
||||
public:
|
||||
Command_SetCardAttr(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString());
|
||||
QString getZone() const { return zone; }
|
||||
int getCardId() const { return cardId; }
|
||||
QString getAttrName() const { return attrName; }
|
||||
QString getAttrValue() const { return attrValue; }
|
||||
static ProtocolItem *newItem() { return new Command_SetCardAttr; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_ReadyStart : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_ReadyStart(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_ReadyStart; }
|
||||
};
|
||||
class Command_IncCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int counterId;
|
||||
int delta;
|
||||
public:
|
||||
Command_IncCounter(int _gameId = -1, int _counterId = -1, int _delta = -1);
|
||||
int getCounterId() const { return counterId; }
|
||||
int getDelta() const { return delta; }
|
||||
static ProtocolItem *newItem() { return new Command_IncCounter; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_AddCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString counterName;
|
||||
int color;
|
||||
int radius;
|
||||
int value;
|
||||
public:
|
||||
Command_AddCounter(int _gameId = -1, const QString &_counterName = QString(), int _color = -1, int _radius = -1, int _value = -1);
|
||||
QString getCounterName() const { return counterName; }
|
||||
int getColor() const { return color; }
|
||||
int getRadius() const { return radius; }
|
||||
int getValue() const { return value; }
|
||||
static ProtocolItem *newItem() { return new Command_AddCounter; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_SetCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int counterId;
|
||||
int value;
|
||||
public:
|
||||
Command_SetCounter(int _gameId = -1, int _counterId = -1, int _value = -1);
|
||||
int getCounterId() const { return counterId; }
|
||||
int getValue() const { return value; }
|
||||
static ProtocolItem *newItem() { return new Command_SetCounter; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_DelCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int counterId;
|
||||
public:
|
||||
Command_DelCounter(int _gameId = -1, int _counterId = -1);
|
||||
int getCounterId() const { return counterId; }
|
||||
static ProtocolItem *newItem() { return new Command_DelCounter; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_NextTurn : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_NextTurn(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_NextTurn; }
|
||||
};
|
||||
class Command_SetActivePhase : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int phase;
|
||||
public:
|
||||
Command_SetActivePhase(int _gameId = -1, int _phase = -1);
|
||||
int getPhase() const { return phase; }
|
||||
static ProtocolItem *newItem() { return new Command_SetActivePhase; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_DumpZone : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int playerId;
|
||||
QString zoneName;
|
||||
int numberCards;
|
||||
public:
|
||||
Command_DumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString(), int _numberCards = -1);
|
||||
int getPlayerId() const { return playerId; }
|
||||
QString getZoneName() const { return zoneName; }
|
||||
int getNumberCards() const { return numberCards; }
|
||||
static ProtocolItem *newItem() { return new Command_DumpZone; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_StopDumpZone : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
int playerId;
|
||||
QString zoneName;
|
||||
public:
|
||||
Command_StopDumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString());
|
||||
int getPlayerId() const { return playerId; }
|
||||
QString getZoneName() const { return zoneName; }
|
||||
static ProtocolItem *newItem() { return new Command_StopDumpZone; }
|
||||
protected:
|
||||
void extractParameters();
|
||||
};
|
||||
class Command_DumpAll : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_DumpAll(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_DumpAll; }
|
||||
};
|
||||
class Command_SubmitDeck : public GameCommand {
|
||||
Q_OBJECT
|
||||
private:
|
||||
public:
|
||||
Command_SubmitDeck(int _gameId = -1);
|
||||
static ProtocolItem *newItem() { return new Command_SubmitDeck; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
$initializeHash = '';
|
||||
|
||||
open(headerfile, ">protocol_commands.h");
|
||||
print headerfile "#ifndef PROTOCOL_COMMANDS_H\n"
|
||||
. "#define PROTOCOL_COMMANDS_H\n\n"
|
||||
open(headerfile, ">protocol_items.h");
|
||||
print headerfile "#ifndef PROTOCOL_ITEMS_H\n"
|
||||
. "#define PROTOCOL_ITEMS_H\n\n"
|
||||
. "#include \"protocol.h\"\n\n";
|
||||
|
||||
open(cppfile, ">protocol_commands.cpp");
|
||||
open(cppfile, ">protocol_items.cpp");
|
||||
print cppfile "#include \"protocol.h\"\n"
|
||||
. "#include \"protocol_commands.h\"\n\n";
|
||||
. "#include \"protocol_items.h\"\n\n";
|
||||
|
||||
open(file, "protocol_commands.dat");
|
||||
open(file, "protocol_items.dat");
|
||||
while (<file>) {
|
||||
s/\s+$//;
|
||||
@line = split(/:/);
|
||||
|
@ -20,23 +20,35 @@ while (<file>) {
|
|||
($name2 = $name1) =~ s/_(.)/\U$1\E/g;
|
||||
$name2 =~ s/^(.)/\U$1\E/;
|
||||
if ($type == 0) {
|
||||
$type = 'cmd';
|
||||
$namePrefix = 'Command';
|
||||
$baseClass = 'Command';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\")";
|
||||
$constructorParamsH = "";
|
||||
$constructorParamsCpp = "";
|
||||
} elsif ($type == 1) {
|
||||
$type = 'cmd';
|
||||
$namePrefix = 'Command';
|
||||
$baseClass = 'ChatCommand';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _channel)";
|
||||
$constructorParamsH = "const QString &_channel = QString()";
|
||||
$constructorParamsCpp = "const QString &_channel";
|
||||
} else {
|
||||
} elsif ($type == 2) {
|
||||
$type = 'cmd';
|
||||
$namePrefix = 'Command';
|
||||
$baseClass = 'GameCommand';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _gameId)";
|
||||
$constructorParamsH = "int _gameId = -1";
|
||||
$constructorParamsCpp = "int _gameId";
|
||||
} elsif ($type == 3) {
|
||||
$type = 'game_event';
|
||||
$namePrefix = 'Event';
|
||||
$baseClass = 'GameEvent';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _gameId, _isPublic, _playerId)";
|
||||
$constructorParamsH = "int _gameId = -1, bool _isPublic = false, int _playerId = -1";
|
||||
$constructorParamsCpp = "int _gameId, bool _isPublic, int _playerId";
|
||||
}
|
||||
|
||||
$className = 'Command_' . $name2;
|
||||
$className = $namePrefix . '_' . $name2;
|
||||
print headerfile "class $className : public $baseClass {\n"
|
||||
. "\tQ_OBJECT\n"
|
||||
. "private:\n";
|
||||
|
@ -93,7 +105,7 @@ while (<file>) {
|
|||
. $paramStr5
|
||||
. "}\n";
|
||||
}
|
||||
$initializeHash .= "\titemNameHash.insert(\"cmd$name1\", $className" . "::newItem);\n";
|
||||
$initializeHash .= "\titemNameHash.insert(\"$type$name1\", $className" . "::newItem);\n";
|
||||
}
|
||||
close(file);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <QDebug>
|
||||
#include "widget.h"
|
||||
#include "protocol.h"
|
||||
#include "protocol_commands.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
Widget::Widget()
|
||||
: QMainWindow()
|
||||
|
@ -49,6 +49,9 @@ void Widget::startClicked()
|
|||
|
||||
ProtocolResponse *test4 = new ProtocolResponse(123, ProtocolResponse::RespContextError);
|
||||
test4->write(xmlWriter);
|
||||
|
||||
GameEvent *test5 = new Event_RollDie(1234, true, 1, 20, 13);
|
||||
test5->write(xmlWriter);
|
||||
}
|
||||
|
||||
bool Widget::readCurrentCommand()
|
||||
|
|
Loading…
Reference in a new issue