Skip to content

Commit

Permalink
libshell: Implemented the game state packet
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 10, 2013
1 parent 31f3f7c commit 003823d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doomsday/libshell/include/de/shell/doomsdayinfo.h
Expand Up @@ -45,6 +45,8 @@ class DoomsdayInfo
*/
static QList<GameMode> allGameModes();

static String titleForGameMode(String const &mode);

static NativePath defaultServerRuntimeFolder();
};

Expand Down
15 changes: 15 additions & 0 deletions doomsday/libshell/include/de/shell/protocol.h
Expand Up @@ -120,6 +120,21 @@ class LIBSHELL_PUBLIC Protocol : public de::Protocol
RecordPacket *newConsoleLexicon(Lexicon const &lexicon);

Lexicon lexicon(Packet const &consoleLexiconPacket);

/**
* Constructs a packet that describes the current gameplay state.
*
* @param mode Game mode (e.g., doom2).
* @param rules Name of the game rules (e.g., Deathmatch).
* @param mapId Identifier of the map (e.g., E1M3).
* @param mapTitle Title of the map (from mapinfo/defs).
*
* @return Packet. Caller gets ownership.
*/
RecordPacket *newGameState(String const &mode,
String const &rules,
String const &mapId,
String const &mapTitle);
};

} // namespace shell
Expand Down
10 changes: 10 additions & 0 deletions doomsday/libshell/src/doomsdayinfo.cpp
Expand Up @@ -65,6 +65,16 @@ QList<DoomsdayInfo::GameMode> DoomsdayInfo::allGameModes()
return modes;
}

String DoomsdayInfo::titleForGameMode(String const &mode)
{
for(int i = 0; gameModes[i].name; ++i)
{
if(gameModes[i].mode == mode)
return gameModes[i].name;
}
return mode;
}

NativePath DoomsdayInfo::defaultServerRuntimeFolder()
{
#ifdef MACOSX
Expand Down
15 changes: 15 additions & 0 deletions doomsday/libshell/src/protocol.cpp
Expand Up @@ -28,6 +28,7 @@ namespace shell {

static String const PT_COMMAND = "shell.command";
static String const PT_LEXICON = "shell.lexicon";
static String const PT_GAME_STATE = "shell.game.state";

// LogEntryPacket ------------------------------------------------------------

Expand Down Expand Up @@ -114,6 +115,8 @@ Protocol::PacketType Protocol::recognize(Packet const *packet)
return Command;
else if(rec->name() == PT_LEXICON)
return ConsoleLexicon;
else if(rec->name() == PT_GAME_STATE)
return GameState;
}
return Unknown;
}
Expand Down Expand Up @@ -163,5 +166,17 @@ Lexicon Protocol::lexicon(Packet const &consoleLexiconPacket)
return lexicon;
}

RecordPacket *Protocol::newGameState(String const &mode, String const &rules,
String const &mapId, String const &mapTitle)
{
RecordPacket *gs = new RecordPacket(PT_GAME_STATE);
Record &r = gs->record();
r.addText("mode", mode);
r.addText("rules", rules);
r.addText("mapId", mapId);
r.addText("mapTitle", mapTitle);
return gs;
}

} // namespace shell
} // namespace de

0 comments on commit 003823d

Please sign in to comment.