mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-13 17:44:48 -07:00
Connect/disconnect and join game/room intents.
Took 3 hours 14 minutes
This commit is contained in:
parent
ea6d9366a3
commit
d174a2941f
26 changed files with 512 additions and 3 deletions
63
cockatrice/src/interface/intents/intent_join_server_game.h
Normal file
63
cockatrice/src/interface/intents/intent_join_server_game.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef COCKATRICE_INTENT_JOIN_SERVER_GAME_H
|
||||
#define COCKATRICE_INTENT_JOIN_SERVER_GAME_H
|
||||
|
||||
#include "../widgets/server/game_selector.h"
|
||||
#include "../widgets/tabs/tab_room.h"
|
||||
#include "../widgets/tabs/tab_server.h"
|
||||
#include "../widgets/tabs/tab_supervisor.h"
|
||||
#include "contexts/context_join_game.h"
|
||||
#include "contexts/context_join_room.h"
|
||||
#include "intent.h"
|
||||
#include "intent_join_server_room.h"
|
||||
#include "remote_client.h"
|
||||
|
||||
class IntentJoinServerGame : public Intent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IntentJoinServerGame(TabSupervisor *_tabSupervisor, RemoteClient *_remoteClient, ContextJoinGame *_context)
|
||||
: Intent(), tabSupervisor(_tabSupervisor), remoteClient(_remoteClient), context(_context)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool checkPrecondition() const override
|
||||
{
|
||||
if (remoteClient->getStatus() != ClientStatus::StatusLoggedIn) {
|
||||
return false;
|
||||
}
|
||||
if (remoteClient->peerName() != context->roomContext.serverContext.hostname) {
|
||||
return false;
|
||||
}
|
||||
if (QString::number(remoteClient->peerPort()) != context->roomContext.serverContext.port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tabSupervisor->getRoomTabs()[context->roomContext.roomId]) {
|
||||
qWarning() << "No room tab";
|
||||
return false;
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onPreconditionSatisfied() override
|
||||
{
|
||||
qWarning() << "All lights green, joining game";
|
||||
TabRoom *room = tabSupervisor->getRoomTabs()[context->roomContext.roomId];
|
||||
room->getGameSelector()->joinGameById(context->gameId);
|
||||
}
|
||||
|
||||
void onPreconditionNotSatisfied() override
|
||||
{
|
||||
runDependency(new IntentJoinServerRoom(tabSupervisor, remoteClient, &context->roomContext));
|
||||
}
|
||||
|
||||
private:
|
||||
TabSupervisor *tabSupervisor;
|
||||
RemoteClient *remoteClient;
|
||||
ContextJoinGame *context;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_INTENT_JOIN_SERVER_GAME_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue