tell logged in clients about new replays

This commit is contained in:
Max-Wilhelm Bruker 2012-03-03 18:10:16 +01:00
parent 2487476fcc
commit a876a0bf5f
14 changed files with 95 additions and 11 deletions

View file

@ -78,6 +78,7 @@ SET(PROTO_FILES
event_move_card.proto
event_player_properties_changed.proto
event_remove_from_list.proto
event_replay_added.proto
event_reveal_cards.proto
event_roll_die.proto
event_room_say.proto

View file

@ -0,0 +1,9 @@
import "session_event.proto";
import "serverinfo_replay_match.proto";
message Event_ReplayAdded {
extend SessionEvent {
optional Event_ReplayAdded ext = 1100;
}
optional ServerInfo_ReplayMatch match_info = 1;
}

View file

@ -2,7 +2,8 @@ import "serverinfo_game.proto";
import "game_event_container.proto";
message GameReplay {
optional ServerInfo_Game game_info = 1;
repeated GameEventContainer event_list = 2;
optional uint32 duration_seconds = 3;
optional uint64 replay_id = 1;
optional ServerInfo_Game game_info = 2;
repeated GameEventContainer event_list = 3;
optional uint32 duration_seconds = 4;
}

View file

@ -11,6 +11,7 @@ message SessionEvent {
USER_JOINED = 1007;
USER_LEFT = 1008;
GAME_JOINED = 1009;
REPLAY_ADDED = 1100;
}
extensions 100 to max;
}

View file

@ -29,7 +29,7 @@
#include <QDebug>
Server::Server(QObject *parent)
: QObject(parent), serverMutex(QMutex::Recursive), nextGameId(0)
: QObject(parent), serverMutex(QMutex::Recursive), nextGameId(0), nextReplayId(0)
{
}

View file

@ -28,6 +28,7 @@ public:
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason);
const QMap<int, Server_Room *> &getRooms() { return rooms; }
int getNextGameId() { return nextGameId++; }
int getNextReplayId() { return nextReplayId++; }
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
void addClient(Server_ProtocolHandler *player);
@ -62,7 +63,7 @@ protected:
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
int getUsersCount() const;
int getGamesCount() const;
int nextGameId;
int nextGameId, nextReplayId;
void addRoom(Server_Room *newRoom);
};

View file

@ -48,6 +48,7 @@ Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QS
: QObject(), room(_room), hostId(0), creatorInfo(new ServerInfo_User(_creator->copyUserInfo(false))), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), onlyBuddies(_onlyBuddies), onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), startTimeOfThisGame(0), secondsElapsed(0), firstGameStarted(false), startTime(QDateTime::currentDateTime()), gameMutex(QMutex::Recursive)
{
currentReplay = new GameReplay;
currentReplay->set_replay_id(room->getServer()->getNextReplayId());
connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection);
@ -246,6 +247,7 @@ void Server_Game::doStartGameIfReady()
currentReplay->set_duration_seconds(secondsElapsed - startTimeOfThisGame);
replayList.append(currentReplay);
currentReplay = new GameReplay;
currentReplay->set_replay_id(room->getServer()->getNextReplayId());
currentReplay->mutable_game_info()->CopyFrom(getInfo());
Event_GameStateChanged omniscientEvent;