mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 20:43:54 -07:00
room stuff and minor fixes
This commit is contained in:
parent
80277ff573
commit
78d81ae65a
19 changed files with 159 additions and 99 deletions
|
|
@ -44,6 +44,7 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
|
||||
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
|
||||
registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
|
||||
registerSerializableItem("resplogin", Response_Login::newItem);
|
||||
|
||||
registerSerializableItem("room_eventlist_games", Event_ListGames::newItem);
|
||||
registerSerializableItem("room_eventjoin_room", Event_JoinRoom::newItem);
|
||||
|
|
@ -281,6 +282,14 @@ Response_DumpZone::Response_DumpZone(int _cmdId, ResponseCode _responseCode, Ser
|
|||
insertItem(_zone);
|
||||
}
|
||||
|
||||
Response_Login::Response_Login(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_userInfo)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "login")
|
||||
{
|
||||
if (!_userInfo)
|
||||
_userInfo = new ServerInfo_User;
|
||||
insertItem(_userInfo);
|
||||
}
|
||||
|
||||
GameEvent::GameEvent(const QString &_eventName, int _playerId)
|
||||
: ProtocolItem("game_event", _eventName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ enum ItemId {
|
|||
ItemId_Response_DeckUpload = ItemId_Other + 304,
|
||||
ItemId_Response_DumpZone = ItemId_Other + 305,
|
||||
ItemId_Response_JoinRoom = ItemId_Other + 306,
|
||||
ItemId_Response_Login = ItemId_Other + 307,
|
||||
ItemId_Invalid = ItemId_Other + 1000
|
||||
};
|
||||
|
||||
|
|
@ -268,6 +269,15 @@ public:
|
|||
ServerInfo_Zone *getZone() const { return static_cast<ServerInfo_Zone *>(itemMap.value("zone")); }
|
||||
};
|
||||
|
||||
class Response_Login : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_Login(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Response_Login; }
|
||||
static SerializableItem *newItem() { return new Response_Login; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
// --------------
|
||||
// --- EVENTS ---
|
||||
// --------------
|
||||
|
|
|
|||
|
|
@ -108,6 +108,11 @@ void Server::broadcastRoomUpdate()
|
|||
delete event;
|
||||
}
|
||||
|
||||
void Server::gameCreated(Server_Game *game)
|
||||
{
|
||||
games.insert(game->getGameId(), game);
|
||||
}
|
||||
|
||||
void Server::gameClosing(int gameId)
|
||||
{
|
||||
qDebug("Server::gameClosing");
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class Server : public QObject
|
|||
signals:
|
||||
void pingClockTimeout();
|
||||
private slots:
|
||||
void gameCreated(Server_Game *game);
|
||||
void gameClosing(int gameId);
|
||||
void broadcastRoomUpdate();
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
|||
// so it will not receive the game update event.
|
||||
server->removeClient(this);
|
||||
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
roomIterator.next().value()->removeClient(this);
|
||||
|
||||
QMapIterator<int, QPair<Server_Game *, Server_Player *> > gameIterator(games);
|
||||
while (gameIterator.hasNext()) {
|
||||
gameIterator.next();
|
||||
|
|
@ -37,10 +41,6 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
|||
p->setProtocolHandler(0);
|
||||
}
|
||||
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
roomIterator.next().value()->removeClient(this);
|
||||
|
||||
delete userInfo;
|
||||
}
|
||||
|
||||
|
|
@ -234,8 +234,9 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RespOk;
|
||||
|
||||
cont->setResponse(new Response_Login(cont->getCmdId(), RespOk, new ServerInfo_User(userInfo, true)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandContainer *cont)
|
||||
|
|
@ -302,6 +303,8 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC
|
|||
r->addClient(this);
|
||||
rooms.insert(r->getId(), r);
|
||||
|
||||
enqueueProtocolItem(new Event_RoomSay(r->getId(), QString(), r->getJoinMessage()));
|
||||
|
||||
cont->setResponse(new Response_JoinRoom(cont->getCmdId(), RespOk, r->getInfo(true)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
|||
{
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_User *> userList;
|
||||
qDebug() << "getInfo: complete=" << complete;
|
||||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
|
|
@ -79,6 +78,7 @@ Server_Game *Server_Room::createGame(const QString &description, const QString &
|
|||
broadcastGameListUpdate(newGame);
|
||||
|
||||
emit gameCreated(newGame);
|
||||
emit roomInfoChanged();
|
||||
|
||||
return newGame;
|
||||
}
|
||||
|
|
@ -90,4 +90,5 @@ void Server_Room::removeGame()
|
|||
games.remove(game->getGameId());
|
||||
|
||||
emit gameClosing(game->getGameId());
|
||||
emit roomInfoChanged();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public:
|
|||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
Server *getServer() const;
|
||||
ServerInfo_Room *getInfo(bool complete) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue