events
This commit is contained in:
parent
29bf3d3774
commit
8b3723b871
16 changed files with 274 additions and 77 deletions
|
@ -15,25 +15,19 @@ bool ProtocolItem::read(QXmlStreamReader *xml)
|
||||||
{
|
{
|
||||||
while (!xml->atEnd()) {
|
while (!xml->atEnd()) {
|
||||||
xml->readNext();
|
xml->readNext();
|
||||||
if (xml->isStartElement()) {
|
if (readElement(xml))
|
||||||
qDebug() << "startElement: " << xml->name().toString();
|
continue;
|
||||||
} else if (xml->isEndElement()) {
|
if (xml->isEndElement()) {
|
||||||
qDebug() << "endElement: " << xml->name().toString();
|
|
||||||
if (xml->name() == getItemType()) {
|
if (xml->name() == getItemType()) {
|
||||||
extractParameters();
|
extractParameters();
|
||||||
qDebug() << "FERTIG";
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
QString tagName = xml->name().toString();
|
QString tagName = xml->name().toString();
|
||||||
if (!parameters.contains(tagName))
|
if (parameters.contains(tagName))
|
||||||
qDebug() << "unrecognized attribute";
|
|
||||||
else
|
|
||||||
parameters[tagName] = currentElementText;
|
parameters[tagName] = currentElementText;
|
||||||
}
|
}
|
||||||
} else if (xml->isCharacters() && !xml->isWhitespace()) {
|
} else if (xml->isCharacters() && !xml->isWhitespace())
|
||||||
currentElementText = xml->text().toString();
|
currentElementText = xml->text().toString();
|
||||||
qDebug() << "text: " << currentElementText;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +44,8 @@ void ProtocolItem::write(QXmlStreamWriter *xml)
|
||||||
xml->writeTextElement(i.key(), i.value());
|
xml->writeTextElement(i.key(), i.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeElement(xml);
|
||||||
|
|
||||||
xml->writeEndElement();
|
xml->writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +147,49 @@ ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel)
|
||||||
{
|
{
|
||||||
setParameter("channel", channel);
|
setParameter("channel", channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Event_ChatListChannels::readElement(QXmlStreamReader *xml)
|
||||||
|
{
|
||||||
|
if (xml->isStartElement() && (xml->name() == "channel")) {
|
||||||
|
channelList.append(ChannelInfo(
|
||||||
|
xml->attributes().value("name").toString(),
|
||||||
|
xml->attributes().value("description").toString(),
|
||||||
|
xml->attributes().value("player_count").toString().toInt(),
|
||||||
|
xml->attributes().value("auto_join").toString().toInt()
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Event_ChatListChannels::writeElement(QXmlStreamWriter *xml)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < channelList.size(); ++i) {
|
||||||
|
xml->writeStartElement("channel");
|
||||||
|
xml->writeAttribute("name", channelList[i].getName());
|
||||||
|
xml->writeAttribute("description", channelList[i].getDescription());
|
||||||
|
xml->writeAttribute("player_count", QString::number(channelList[i].getPlayerCount()));
|
||||||
|
xml->writeAttribute("auto_join", channelList[i].getAutoJoin() ? "1" : "0");
|
||||||
|
xml->writeEndElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Event_ChatListPlayers::readElement(QXmlStreamReader *xml)
|
||||||
|
{
|
||||||
|
if (xml->isStartElement() && ((xml->name() == "player"))) {
|
||||||
|
playerList.append(PlayerInfo(
|
||||||
|
xml->attributes().value("name").toString()
|
||||||
|
));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Event_ChatListPlayers::writeElement(QXmlStreamWriter *xml)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < playerList.size(); ++i) {
|
||||||
|
xml->writeStartElement("player");
|
||||||
|
xml->writeAttribute("name", playerList[i].getName());
|
||||||
|
xml->writeEndElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -12,20 +12,29 @@ class QXmlStreamReader;
|
||||||
class QXmlStreamWriter;
|
class QXmlStreamWriter;
|
||||||
class QXmlStreamAttributes;
|
class QXmlStreamAttributes;
|
||||||
|
|
||||||
|
enum ItemId {
|
||||||
|
ItemId_Event_ChatListChannels = ItemId_Other + 1,
|
||||||
|
ItemId_Event_ChatListPlayers = ItemId_Other + 2,
|
||||||
|
};
|
||||||
|
|
||||||
class ProtocolItem : public QObject {
|
class ProtocolItem : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QString currentElementText;
|
||||||
protected:
|
protected:
|
||||||
typedef ProtocolItem *(*NewItemFunction)();
|
typedef ProtocolItem *(*NewItemFunction)();
|
||||||
static QHash<QString, NewItemFunction> itemNameHash;
|
static QHash<QString, NewItemFunction> itemNameHash;
|
||||||
|
|
||||||
QString itemName;
|
QString itemName;
|
||||||
QMap<QString, QString> parameters;
|
QMap<QString, QString> parameters;
|
||||||
QString currentElementText;
|
|
||||||
void setParameter(const QString &name, const QString &value) { parameters[name] = value; }
|
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, bool value) { parameters[name] = (value ? "1" : "0"); }
|
||||||
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
|
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
|
||||||
virtual void extractParameters() { };
|
virtual void extractParameters() { }
|
||||||
virtual QString getItemType() const = 0;
|
virtual QString getItemType() const = 0;
|
||||||
|
|
||||||
|
virtual bool readElement(QXmlStreamReader * /*xml*/) { return false; }
|
||||||
|
virtual void writeElement(QXmlStreamWriter * /*xml*/) { }
|
||||||
private:
|
private:
|
||||||
static void initializeHashAuto();
|
static void initializeHashAuto();
|
||||||
public:
|
public:
|
||||||
|
@ -34,8 +43,8 @@ public:
|
||||||
ProtocolItem(const QString &_itemName);
|
ProtocolItem(const QString &_itemName);
|
||||||
static void initializeHash();
|
static void initializeHash();
|
||||||
static ProtocolItem *getNewItem(const QString &name);
|
static ProtocolItem *getNewItem(const QString &name);
|
||||||
virtual bool read(QXmlStreamReader *xml);
|
bool read(QXmlStreamReader *xml);
|
||||||
virtual void write(QXmlStreamWriter *xml);
|
void write(QXmlStreamWriter *xml);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Command : public ProtocolItem {
|
class Command : public ProtocolItem {
|
||||||
|
@ -143,4 +152,62 @@ public:
|
||||||
ChatEvent(const QString &_eventName, const QString &_channel);
|
ChatEvent(const QString &_eventName, const QString &_channel);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Event_ChatListChannels : public GenericEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
class ChannelInfo {
|
||||||
|
private:
|
||||||
|
QString name;
|
||||||
|
QString description;
|
||||||
|
int playerCount;
|
||||||
|
bool autoJoin;
|
||||||
|
public:
|
||||||
|
ChannelInfo(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
|
||||||
|
: name(_name), description(_description), playerCount(_playerCount), autoJoin(_autoJoin) { }
|
||||||
|
QString getName() const { return name; }
|
||||||
|
QString getDescription() const { return description; }
|
||||||
|
int getPlayerCount() const { return playerCount; }
|
||||||
|
bool getAutoJoin() const { return autoJoin; }
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
QList<ChannelInfo> channelList;
|
||||||
|
public:
|
||||||
|
Event_ChatListChannels() : GenericEvent("chat_list_channels") { }
|
||||||
|
int getItemId() const { return ItemId_Event_ChatListChannels; }
|
||||||
|
void addChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
|
||||||
|
{
|
||||||
|
channelList.append(ChannelInfo(_name, _description, _playerCount, _autoJoin));
|
||||||
|
}
|
||||||
|
const QList<ChannelInfo> &getChannelList() const { return channelList; }
|
||||||
|
|
||||||
|
bool readElement(QXmlStreamReader *xml);
|
||||||
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
|
};
|
||||||
|
|
||||||
|
class Event_ChatListPlayers : public ChatEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
class PlayerInfo {
|
||||||
|
private:
|
||||||
|
QString name;
|
||||||
|
public:
|
||||||
|
PlayerInfo(const QString &_name)
|
||||||
|
: name(_name) { }
|
||||||
|
QString getName() const { return name; }
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
QList<PlayerInfo> playerList;
|
||||||
|
public:
|
||||||
|
Event_ChatListPlayers(const QString &_channel) : ChatEvent("chat_list_players", _channel) { }
|
||||||
|
int getItemId() const { return ItemId_Event_ChatListPlayers; }
|
||||||
|
void addPlayer(const QString &_name)
|
||||||
|
{
|
||||||
|
playerList.append(PlayerInfo(_name));
|
||||||
|
}
|
||||||
|
const QList<PlayerInfo> &getPlayerList() const { return playerList; }
|
||||||
|
|
||||||
|
bool readElement(QXmlStreamReader *xml);
|
||||||
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,6 +50,9 @@ ItemId_Event_SetActivePlayer = 1048,
|
||||||
ItemId_Event_SetActivePhase = 1049,
|
ItemId_Event_SetActivePhase = 1049,
|
||||||
ItemId_Event_DumpZone = 1050,
|
ItemId_Event_DumpZone = 1050,
|
||||||
ItemId_Event_StopDumpZone = 1051,
|
ItemId_Event_StopDumpZone = 1051,
|
||||||
ItemId_Event_Welcome = 1052,
|
ItemId_Event_ChatServerMessage = 1052,
|
||||||
ItemId_Other = 1053
|
ItemId_Event_ChatJoinChannel = 1053,
|
||||||
|
ItemId_Event_ChatLeaveChannel = 1054,
|
||||||
|
ItemId_Event_ChatSay = 1055,
|
||||||
|
ItemId_Other = 1056
|
||||||
};
|
};
|
||||||
|
|
|
@ -551,14 +551,46 @@ void Event_StopDumpZone::extractParameters()
|
||||||
zoneOwnerId = parameters["zone_owner_id"].toInt();
|
zoneOwnerId = parameters["zone_owner_id"].toInt();
|
||||||
zone = parameters["zone"];
|
zone = parameters["zone"];
|
||||||
}
|
}
|
||||||
Event_Welcome::Event_Welcome(const QString &_message)
|
Event_ChatServerMessage::Event_ChatServerMessage(const QString &_channel, const QString &_message)
|
||||||
: GenericEvent("welcome"), message(_message)
|
: ChatEvent("chat_server_message", _channel), message(_message)
|
||||||
{
|
{
|
||||||
setParameter("message", message);
|
setParameter("message", message);
|
||||||
}
|
}
|
||||||
void Event_Welcome::extractParameters()
|
void Event_ChatServerMessage::extractParameters()
|
||||||
{
|
{
|
||||||
GenericEvent::extractParameters();
|
ChatEvent::extractParameters();
|
||||||
|
message = parameters["message"];
|
||||||
|
}
|
||||||
|
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
|
||||||
|
: ChatEvent("chat_join_channel", _channel), playerName(_playerName)
|
||||||
|
{
|
||||||
|
setParameter("player_name", playerName);
|
||||||
|
}
|
||||||
|
void Event_ChatJoinChannel::extractParameters()
|
||||||
|
{
|
||||||
|
ChatEvent::extractParameters();
|
||||||
|
playerName = parameters["player_name"];
|
||||||
|
}
|
||||||
|
Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName)
|
||||||
|
: ChatEvent("chat_leave_channel", _channel), playerName(_playerName)
|
||||||
|
{
|
||||||
|
setParameter("player_name", playerName);
|
||||||
|
}
|
||||||
|
void Event_ChatLeaveChannel::extractParameters()
|
||||||
|
{
|
||||||
|
ChatEvent::extractParameters();
|
||||||
|
playerName = parameters["player_name"];
|
||||||
|
}
|
||||||
|
Event_ChatSay::Event_ChatSay(const QString &_channel, const QString &_playerName, const QString &_message)
|
||||||
|
: ChatEvent("chat_say", _channel), playerName(_playerName), message(_message)
|
||||||
|
{
|
||||||
|
setParameter("player_name", playerName);
|
||||||
|
setParameter("message", message);
|
||||||
|
}
|
||||||
|
void Event_ChatSay::extractParameters()
|
||||||
|
{
|
||||||
|
ChatEvent::extractParameters();
|
||||||
|
playerName = parameters["player_name"];
|
||||||
message = parameters["message"];
|
message = parameters["message"];
|
||||||
}
|
}
|
||||||
void ProtocolItem::initializeHashAuto()
|
void ProtocolItem::initializeHashAuto()
|
||||||
|
@ -614,5 +646,8 @@ void ProtocolItem::initializeHashAuto()
|
||||||
itemNameHash.insert("game_eventset_active_phase", Event_SetActivePhase::newItem);
|
itemNameHash.insert("game_eventset_active_phase", Event_SetActivePhase::newItem);
|
||||||
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
||||||
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
||||||
itemNameHash.insert("generic_eventwelcome", Event_Welcome::newItem);
|
itemNameHash.insert("chat_eventchat_server_message", Event_ChatServerMessage::newItem);
|
||||||
|
itemNameHash.insert("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
|
||||||
|
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
|
||||||
|
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,4 +49,7 @@
|
||||||
3:set_active_phase:i,phase
|
3:set_active_phase:i,phase
|
||||||
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
||||||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||||
4:welcome:s,message
|
5:chat_server_message:s,message
|
||||||
|
5:chat_join_channel:s,player_name
|
||||||
|
5:chat_leave_channel:s,player_name
|
||||||
|
5:chat_say:s,player_name:s,message
|
|
@ -685,15 +685,53 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
class Event_Welcome : public GenericEvent {
|
class Event_ChatServerMessage : public ChatEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString message;
|
QString message;
|
||||||
public:
|
public:
|
||||||
Event_Welcome(const QString &_message = QString());
|
Event_ChatServerMessage(const QString &_channel = QString(), const QString &_message = QString());
|
||||||
QString getMessage() const { return message; }
|
QString getMessage() const { return message; }
|
||||||
static ProtocolItem *newItem() { return new Event_Welcome; }
|
static ProtocolItem *newItem() { return new Event_ChatServerMessage; }
|
||||||
int getItemId() const { return ItemId_Event_Welcome; }
|
int getItemId() const { return ItemId_Event_ChatServerMessage; }
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
};
|
||||||
|
class Event_ChatJoinChannel : public ChatEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QString playerName;
|
||||||
|
public:
|
||||||
|
Event_ChatJoinChannel(const QString &_channel = QString(), const QString &_playerName = QString());
|
||||||
|
QString getPlayerName() const { return playerName; }
|
||||||
|
static ProtocolItem *newItem() { return new Event_ChatJoinChannel; }
|
||||||
|
int getItemId() const { return ItemId_Event_ChatJoinChannel; }
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
};
|
||||||
|
class Event_ChatLeaveChannel : public ChatEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QString playerName;
|
||||||
|
public:
|
||||||
|
Event_ChatLeaveChannel(const QString &_channel = QString(), const QString &_playerName = QString());
|
||||||
|
QString getPlayerName() const { return playerName; }
|
||||||
|
static ProtocolItem *newItem() { return new Event_ChatLeaveChannel; }
|
||||||
|
int getItemId() const { return ItemId_Event_ChatLeaveChannel; }
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
};
|
||||||
|
class Event_ChatSay : public ChatEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QString playerName;
|
||||||
|
QString message;
|
||||||
|
public:
|
||||||
|
Event_ChatSay(const QString &_channel = QString(), const QString &_playerName = QString(), const QString &_message = QString());
|
||||||
|
QString getPlayerName() const { return playerName; }
|
||||||
|
QString getMessage() const { return message; }
|
||||||
|
static ProtocolItem *newItem() { return new Event_ChatSay; }
|
||||||
|
int getItemId() const { return ItemId_Event_ChatSay; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,6 +59,13 @@ while (<file>) {
|
||||||
$parentConstructorCall = "$baseClass(\"$name1\")";
|
$parentConstructorCall = "$baseClass(\"$name1\")";
|
||||||
$constructorParamsH = "";
|
$constructorParamsH = "";
|
||||||
$constructorParamsCpp = "";
|
$constructorParamsCpp = "";
|
||||||
|
} elsif ($type == 5) {
|
||||||
|
$type = 'chat_event';
|
||||||
|
$namePrefix = 'Event';
|
||||||
|
$baseClass = 'ChatEvent';
|
||||||
|
$parentConstructorCall = "$baseClass(\"$name1\", _channel)";
|
||||||
|
$constructorParamsH = "const QString &_channel = QString()";
|
||||||
|
$constructorParamsCpp = "const QString &_channel";
|
||||||
}
|
}
|
||||||
$className = $namePrefix . '_' . $name2;
|
$className = $namePrefix . '_' . $name2;
|
||||||
$itemEnum .= "ItemId_$className = " . ++$itemId . ",\n";
|
$itemEnum .= "ItemId_$className = " . ++$itemId . ",\n";
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
void addClient(Server_ProtocolHandler *player);
|
void addClient(Server_ProtocolHandler *player);
|
||||||
void removeClient(Server_ProtocolHandler *player);
|
void removeClient(Server_ProtocolHandler *player);
|
||||||
virtual QStringList getLoginMessage() const = 0;
|
virtual QString getLoginMessage() const = 0;
|
||||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, const QString &playerName);
|
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, const QString &playerName);
|
||||||
private:
|
private:
|
||||||
QMap<int, Server_Game *> games;
|
QMap<int, Server_Game *> games;
|
||||||
|
|
|
@ -1,46 +1,41 @@
|
||||||
#include "server_chatchannel.h"
|
#include "server_chatchannel.h"
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
|
|
||||||
Server_ChatChannel::Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QStringList &_joinMessage)
|
Server_ChatChannel::Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage)
|
||||||
: name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
|
: name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_ChatChannel::addClient(Server_ProtocolHandler *client)
|
void Server_ChatChannel::addClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
/* QString str = QString("chat|join_channel|%1|%2").arg(name).arg(player->getPlayerName());
|
sendChatEvent(new Event_ChatJoinChannel(name, client->getPlayerName()));
|
||||||
for (int i = 0; i < size(); ++i)
|
append(client);
|
||||||
at(i)->msg(str);
|
|
||||||
|
|
||||||
append(player);
|
|
||||||
|
|
||||||
|
Event_ChatListPlayers *eventCLP = new Event_ChatListPlayers(name);
|
||||||
for (int i = 0; i < size(); ++i)
|
for (int i = 0; i < size(); ++i)
|
||||||
player->msg(QString("chat|list_players|%1|%2").arg(name).arg(at(i)->getPlayerName()));
|
eventCLP->addPlayer(at(i)->getPlayerName());
|
||||||
for (int i = 0; i < joinMessage.size(); ++i)
|
client->enqueueProtocolItem(eventCLP);
|
||||||
player->msg(QString("chat|server_message|%1|%2").arg(name).arg(joinMessage[i]));
|
|
||||||
|
client->enqueueProtocolItem(new Event_ChatServerMessage(name, joinMessage));
|
||||||
|
|
||||||
emit channelInfoChanged();
|
emit channelInfoChanged();
|
||||||
*/}
|
}
|
||||||
|
|
||||||
void Server_ChatChannel::removeClient(Server_ProtocolHandler *client)
|
void Server_ChatChannel::removeClient(Server_ProtocolHandler *client)
|
||||||
{
|
{
|
||||||
/* QString str = QString("chat|leave_channel|%1|%2").arg(name).arg(player->getPlayerName());
|
removeAt(indexOf(client));
|
||||||
|
sendChatEvent(new Event_ChatLeaveChannel(name, client->getPlayerName()));
|
||||||
removeAt(indexOf(player));
|
|
||||||
for (int i = 0; i < size(); ++i)
|
|
||||||
at(i)->msg(str);
|
|
||||||
|
|
||||||
emit channelInfoChanged();
|
emit channelInfoChanged();
|
||||||
*/}
|
}
|
||||||
|
|
||||||
void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
|
void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
|
||||||
{
|
{
|
||||||
/* QString str = QString("chat|say|%1|%2|%3").arg(name).arg(player->getPlayerName()).arg(s);
|
sendChatEvent(new Event_ChatSay(name, client->getPlayerName(), s));
|
||||||
for (int i = 0; i < size(); ++i)
|
}
|
||||||
at(i)->msg(str);
|
|
||||||
*/}
|
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
|
||||||
|
{
|
||||||
QString Server_ChatChannel::getChannelListLine() const
|
for (int i = 0; i < size(); ++i)
|
||||||
{
|
at(i)->sendProtocolItem(event, false);
|
||||||
// return QString("chat|list_channels|%1|%2|%3|%4").arg(name).arg(description).arg(size()).arg(autoJoin ? 1 : 0);
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
class Server_ProtocolHandler;
|
class Server_ProtocolHandler;
|
||||||
|
class ChatEvent;
|
||||||
|
|
||||||
class Server_ChatChannel : public QObject, public QList<Server_ProtocolHandler *> {
|
class Server_ChatChannel : public QObject, public QList<Server_ProtocolHandler *> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -15,16 +16,17 @@ private:
|
||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
bool autoJoin;
|
bool autoJoin;
|
||||||
QStringList joinMessage;
|
QString joinMessage;
|
||||||
public:
|
public:
|
||||||
Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QStringList &_joinMessage);
|
Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage);
|
||||||
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; }
|
||||||
void addClient(Server_ProtocolHandler *client);
|
void addClient(Server_ProtocolHandler *client);
|
||||||
void removeClient(Server_ProtocolHandler *client);
|
void removeClient(Server_ProtocolHandler *client);
|
||||||
void say(Server_ProtocolHandler *client, const QString &s);
|
void say(Server_ProtocolHandler *client, const QString &s);
|
||||||
QString getChannelListLine() const;
|
|
||||||
|
void sendChatEvent(ChatEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -85,6 +85,14 @@ void Server_ProtocolHandler::processCommand(Command *command)
|
||||||
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
|
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
|
||||||
|
|
||||||
delete command;
|
delete command;
|
||||||
|
|
||||||
|
while (!itemQueue.isEmpty())
|
||||||
|
sendProtocolItem(itemQueue.takeFirst());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server_ProtocolHandler::enqueueProtocolItem(ProtocolItem *item)
|
||||||
|
{
|
||||||
|
itemQueue << item;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId) const
|
QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId) const
|
||||||
|
@ -106,23 +114,19 @@ ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *c
|
||||||
return ProtocolResponse::RespWrongPassword;
|
return ProtocolResponse::RespWrongPassword;
|
||||||
playerName = cmd->getUsername();
|
playerName = cmd->getUsername();
|
||||||
|
|
||||||
/*
|
enqueueProtocolItem(new Event_ChatServerMessage(QString(), server->getLoginMessage()));
|
||||||
Mit enqueueProtocolItem() lösen!
|
|
||||||
|
|
||||||
QStringList loginMessage = server->getLoginMessage();
|
|
||||||
for (int i = 0; i < loginMessage.size(); ++i)
|
|
||||||
msg("chat|server_message||" + loginMessage[i]);
|
|
||||||
*/
|
|
||||||
return ProtocolResponse::RespOk;
|
return ProtocolResponse::RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels *cmd)
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels *cmd)
|
||||||
{
|
{
|
||||||
|
Event_ChatListChannels *event = new Event_ChatListChannels;
|
||||||
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
|
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
|
||||||
while (channelIterator.hasNext()) {
|
while (channelIterator.hasNext()) {
|
||||||
Server_ChatChannel *c = channelIterator.next().value();
|
Server_ChatChannel *c = channelIterator.next().value();
|
||||||
// msg(c->getChannelListLine());
|
event->addChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin());
|
||||||
}
|
}
|
||||||
|
sendProtocolItem(event);
|
||||||
|
|
||||||
acceptsChatChannelListChanges = true;
|
acceptsChatChannelListChanges = true;
|
||||||
return ProtocolResponse::RespOk;
|
return ProtocolResponse::RespOk;
|
||||||
|
|
|
@ -24,6 +24,8 @@ private:
|
||||||
bool acceptsGameListChanges;
|
bool acceptsGameListChanges;
|
||||||
bool acceptsChatChannelListChanges;
|
bool acceptsChatChannelListChanges;
|
||||||
|
|
||||||
|
QList<ProtocolItem *> itemQueue;
|
||||||
|
|
||||||
ProtocolResponse::ResponseCode cmdPing(Command_Ping *cmd);
|
ProtocolResponse::ResponseCode cmdPing(Command_Ping *cmd);
|
||||||
ProtocolResponse::ResponseCode cmdLogin(Command_Login *cmd);
|
ProtocolResponse::ResponseCode cmdLogin(Command_Login *cmd);
|
||||||
ProtocolResponse::ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
|
ProtocolResponse::ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
|
||||||
|
@ -54,9 +56,6 @@ private:
|
||||||
ProtocolResponse::ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
ProtocolResponse::ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||||
ProtocolResponse::ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
|
ProtocolResponse::ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
|
||||||
ProtocolResponse::ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
|
ProtocolResponse::ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
|
||||||
QList<ProtocolItem *> itemQueue;
|
|
||||||
void enqueueProtocolItem(ProtocolItem *item);
|
|
||||||
public:
|
public:
|
||||||
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
||||||
~Server_ProtocolHandler();
|
~Server_ProtocolHandler();
|
||||||
|
@ -66,7 +65,8 @@ public:
|
||||||
const QString &getPlayerName() const { return playerName; }
|
const QString &getPlayerName() const { return playerName; }
|
||||||
|
|
||||||
void processCommand(Command *command);
|
void processCommand(Command *command);
|
||||||
virtual void sendProtocolItem(ProtocolItem *item) = 0;
|
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||||
|
void enqueueProtocolItem(ProtocolItem *item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,13 +46,13 @@ Servatrice::Servatrice(QObject *parent)
|
||||||
settings->value("name").toString(),
|
settings->value("name").toString(),
|
||||||
settings->value("description").toString(),
|
settings->value("description").toString(),
|
||||||
settings->value("autojoin").toBool(),
|
settings->value("autojoin").toBool(),
|
||||||
settings->value("joinmessage").toStringList()
|
settings->value("joinmessage").toString()
|
||||||
);
|
);
|
||||||
addChatChannel(newChannel);
|
addChatChannel(newChannel);
|
||||||
}
|
}
|
||||||
settings->endArray();
|
settings->endArray();
|
||||||
|
|
||||||
loginMessage = settings->value("messages/login").toStringList();
|
loginMessage = settings->value("messages/login").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Servatrice::~Servatrice()
|
Servatrice::~Servatrice()
|
||||||
|
@ -121,4 +121,4 @@ AuthenticationResult Servatrice::checkUserPassword(const QString &user, const QS
|
||||||
return UnknownUser;
|
return UnknownUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString Servatrice::versionString = "Servatrice 0.20091030";
|
const QString Servatrice::versionString = "Servatrice 0.20091103";
|
||||||
|
|
|
@ -37,10 +37,10 @@ public:
|
||||||
~Servatrice();
|
~Servatrice();
|
||||||
bool openDatabase();
|
bool openDatabase();
|
||||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||||
QStringList getLoginMessage() const { return loginMessage; }
|
QString getLoginMessage() const { return loginMessage; }
|
||||||
private:
|
private:
|
||||||
QTcpServer *tcpServer;
|
QTcpServer *tcpServer;
|
||||||
QStringList loginMessage;
|
QString loginMessage;
|
||||||
QSettings *settings;
|
QSettings *settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ ServerSocketInterface::ServerSocketInterface(Server *_server, QTcpSocket *_socke
|
||||||
xmlWriter->writeStartElement("cockatrice_server_stream");
|
xmlWriter->writeStartElement("cockatrice_server_stream");
|
||||||
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
|
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
|
||||||
|
|
||||||
sendProtocolItem(new Event_Welcome(Servatrice::versionString));
|
sendProtocolItem(new Event_ChatServerMessage(QString(), Servatrice::versionString));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerSocketInterface::~ServerSocketInterface()
|
ServerSocketInterface::~ServerSocketInterface()
|
||||||
|
@ -104,8 +104,9 @@ void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socket
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSocketInterface::sendProtocolItem(ProtocolItem *item)
|
void ServerSocketInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem)
|
||||||
{
|
{
|
||||||
item->write(xmlWriter);
|
item->write(xmlWriter);
|
||||||
delete item;
|
if (deleteItem)
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent = 0);
|
ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent = 0);
|
||||||
~ServerSocketInterface();
|
~ServerSocketInterface();
|
||||||
|
|
||||||
void sendProtocolItem(ProtocolItem *item);
|
void sendProtocolItem(ProtocolItem *item, bool deleteItem = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue