Replays split up, one for each subgame

This commit is contained in:
Max-Wilhelm Bruker 2012-03-02 20:45:04 +01:00
parent 4dc712286f
commit 8481e61e8f
15 changed files with 278 additions and 119 deletions

View file

@ -126,6 +126,7 @@ SET(PROTO_FILES
serverinfo_playerproperties.proto
serverinfo_player.proto
serverinfo_replay.proto
serverinfo_replay_match.proto
serverinfo_room.proto
serverinfo_user.proto
serverinfo_zone.proto

View file

@ -4,5 +4,5 @@ message Command_ReplayDownload {
extend SessionCommand {
optional Command_ReplayDownload ext = 1101;
}
optional sint32 game_id = 1 [default = -1];
optional sint32 replay_id = 1 [default = -1];
}

View file

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

View file

@ -1,9 +1,9 @@
import "response.proto";
import "serverinfo_replay.proto";
import "serverinfo_replay_match.proto";
message Response_ReplayList {
extend Response {
optional Response_ReplayList ext = 1100;
}
repeated ServerInfo_Replay replay_list = 1;
repeated ServerInfo_ReplayMatch match_list = 1;
}

View file

@ -1,9 +1,5 @@
message ServerInfo_Replay {
optional sint32 game_id = 1 [default = -1];
optional string room_name = 2;
optional uint32 time_started = 3;
optional uint32 length = 4;
optional string game_name = 5;
optional string replay_name = 6;
repeated string player_names = 7;
optional sint32 replay_id = 1 [default = -1];
optional string replay_name = 2;
optional uint32 duration = 3;
}

View file

@ -48,7 +48,7 @@ public:
virtual bool isInBuddyList(const QString &whoseList, const QString &who) { return false; }
virtual bool isInIgnoreList(const QString &whoseList, const QString &who) { return false; }
virtual void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const GameReplay &replay) { }
virtual void storeGameInformation(int secondsElapsed, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replays) { }
protected:
void prepareDestroy();
QList<Server_ProtocolHandler *> clients;

View file

@ -45,14 +45,15 @@
#include <QDebug>
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *_room)
: 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), secondsElapsed(0), startTime(QDateTime::currentDateTime()), gameMutex(QMutex::Recursive)
: 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)
{
replay = new GameReplay;
currentReplay = new GameReplay;
connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection);
addPlayer(_creator, false, false);
replay->mutable_game_info()->CopyFrom(getInfo());
currentReplay->mutable_game_info()->CopyFrom(getInfo());
if (room->getServer()->getGameShouldPing()) {
pingClock = new QTimer(this);
@ -80,8 +81,12 @@ Server_Game::~Server_Game()
gameMutex.unlock();
room->roomMutex.unlock();
room->getServer()->storeGameInformation(secondsElapsed, allPlayersEver, allSpectatorsEver, *replay);
delete replay;
currentReplay->set_duration_seconds(secondsElapsed - startTimeOfThisGame);
replayList.append(currentReplay);
room->getServer()->storeGameInformation(secondsElapsed, allPlayersEver, allSpectatorsEver, replayList);
for (int i = 0; i < replayList.size(); ++i)
delete replayList[i];
qDebug() << "Server_Game destructor: gameId=" << gameId;
}
@ -176,9 +181,9 @@ void Server_Game::sendGameStateToPlayers()
omniscientEvent.add_player_list()->CopyFrom(omniscientGameStateIterator.next());
GameEventContainer *replayCont = prepareGameEvent(omniscientEvent, -1);
replayCont->set_seconds_elapsed(secondsElapsed);
replayCont->set_seconds_elapsed(secondsElapsed - startTimeOfThisGame);
replayCont->clear_game_id();
replay->add_event_list()->CopyFrom(*replayCont);
currentReplay->add_event_list()->CopyFrom(*replayCont);
delete replayCont;
// If spectators are not omniscient, we need an additional getGameState call, otherwise we can use the data we used for the replay.
@ -237,6 +242,27 @@ void Server_Game::doStartGameIfReady()
player->setReadyStart(false);
}
if (firstGameStarted) {
currentReplay->set_duration_seconds(secondsElapsed - startTimeOfThisGame);
replayList.append(currentReplay);
currentReplay = new GameReplay;
currentReplay->mutable_game_info()->CopyFrom(getInfo());
Event_GameStateChanged omniscientEvent;
QListIterator<ServerInfo_Player> omniscientGameStateIterator(getGameState(0, true, true));
while (omniscientGameStateIterator.hasNext())
omniscientEvent.add_player_list()->CopyFrom(omniscientGameStateIterator.next());
GameEventContainer *replayCont = prepareGameEvent(omniscientEvent, -1);
replayCont->set_seconds_elapsed(0);
replayCont->clear_game_id();
currentReplay->add_event_list()->CopyFrom(*replayCont);
delete replayCont;
startTimeOfThisGame = secondsElapsed;
} else
firstGameStarted = true;
sendGameStateToPlayers();
activePlayer = -1;
@ -624,9 +650,9 @@ void Server_Game::sendGameEventContainer(GameEventContainer *cont, GameEventStor
p->sendGameEvent(*cont);
}
if (recipients.testFlag(GameEventStorageItem::SendToPrivate)) {
cont->set_seconds_elapsed(secondsElapsed);
cont->set_seconds_elapsed(secondsElapsed - startTimeOfThisGame);
cont->clear_game_id();
replay->add_event_list()->CopyFrom(*cont);
currentReplay->add_event_list()->CopyFrom(*cont);
}
delete cont;

View file

@ -59,10 +59,12 @@ private:
bool spectatorsCanTalk;
bool spectatorsSeeEverything;
int inactivityCounter;
int secondsElapsed;
int startTimeOfThisGame, secondsElapsed;
bool firstGameStarted;
QDateTime startTime;
QTimer *pingClock;
GameReplay *replay;
QList<GameReplay *> replayList;
GameReplay *currentReplay;
signals:
void sigStartGameIfReady();
private slots: