mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
new files
This commit is contained in:
parent
7921b5f82d
commit
58e803c3e7
10 changed files with 452 additions and 0 deletions
70
cockatrice/src/abstractclient.cpp
Normal file
70
cockatrice/src/abstractclient.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include "abstractclient.h"
|
||||
#include "protocol.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
AbstractClient::AbstractClient(QObject *parent)
|
||||
: QObject(parent), status(StatusDisconnected)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractClient::~AbstractClient()
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractClient::processProtocolItem(ProtocolItem *item)
|
||||
{
|
||||
ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item);
|
||||
if (response) {
|
||||
CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0);
|
||||
if (!cmdCont)
|
||||
return;
|
||||
|
||||
pendingCommands.remove(cmdCont->getCmdId());
|
||||
cmdCont->processResponse(response);
|
||||
delete response;
|
||||
delete cmdCont;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GenericEvent *genericEvent = qobject_cast<GenericEvent *>(item);
|
||||
if (genericEvent) {
|
||||
switch (genericEvent->getItemId()) {
|
||||
case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break;
|
||||
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break;
|
||||
case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break;
|
||||
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
|
||||
}
|
||||
delete genericEvent;
|
||||
return;
|
||||
}
|
||||
|
||||
GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item);
|
||||
if (gameEventContainer) {
|
||||
emit gameEventContainerReceived(gameEventContainer);
|
||||
delete gameEventContainer;
|
||||
return;
|
||||
}
|
||||
|
||||
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
|
||||
if (chatEvent) {
|
||||
emit chatEventReceived(chatEvent);
|
||||
delete chatEvent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractClient::setStatus(const ClientStatus _status)
|
||||
{
|
||||
if (_status != status) {
|
||||
status = _status;
|
||||
emit statusChanged(_status);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractClient::sendCommand(Command *cmd)
|
||||
{
|
||||
sendCommandContainer(new CommandContainer(QList<Command *>() << cmd));
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue