7 constexpr const char*
NET =
"NET";
8 constexpr const char*
WORLD =
"WORLD";
11 std::string
trim(
const std::string& s)
13 if (!s.empty() && s.back() ==
'\n')
return s.substr(0, s.size() - 1);
19 return "food=" + std::to_string(r.
food) +
" lin=" + std::to_string(r.
linemate) +
20 " der=" + std::to_string(r.
deraumere) +
" sib=" + std::to_string(r.
sibur) +
21 " men=" + std::to_string(r.
mendiane) +
" phi=" + std::to_string(r.
phiras) +
22 " thy=" + std::to_string(r.
thystame);
31 _logger.
info(NET,
"client connected (conn=" + std::to_string(connectionId) +
")");
36 _logger.
info(NET,
"client disconnected (conn=" + std::to_string(connectionId) +
")");
41 _logger.
debug(NET,
"<- conn=" + std::to_string(connectionId) +
" : " + trim(line));
46 _logger.
debug(NET,
"-> conn=" + std::to_string(connectionId) +
" : " + trim(line));
50 const std::string& teamName)
52 _logger.
info(WORLD,
"player #" + std::to_string(playerId) +
" added team=" + teamName +
53 " lvl=" + std::to_string(level) +
" at (" + std::to_string(x) +
"," +
54 std::to_string(y) +
")");
59 _logger.
debug(WORLD,
"player #" + std::to_string(playerId) +
" moved to (" +
60 std::to_string(nx) +
"," + std::to_string(ny) +
")");
65 _logger.
debug(WORLD,
"player #" + std::to_string(playerId) +
" inventory at (" +
66 std::to_string(x) +
"," + std::to_string(y) +
") [" +
67 resStr(inventory) +
"]");
72 _logger.
info(WORLD,
"player #" + std::to_string(playerId) +
" removed");
77 _logger.
info(WORLD,
"player #" + std::to_string(playerId) +
" ejected");
82 _logger.
debug(WORLD,
"player #" + std::to_string(playerId) +
" broadcast: " + message);
88 _logger.
debug(WORLD,
"player #" + std::to_string(playerId) +
" took " +
90 "," + std::to_string(tileY) +
") tile now [" + resStr(resources) +
97 _logger.
debug(WORLD,
"player #" + std::to_string(playerId) +
" dropped " +
99 "," + std::to_string(tileY) +
") tile now [" + resStr(resources) +
105 _logger.
info(WORLD,
"egg #" + std::to_string(eggId) +
" laid by #" + std::to_string(playerId) +
106 " at (" + std::to_string(x) +
"," + std::to_string(y) +
")");
111 _logger.
info(WORLD,
"initial egg #" + std::to_string(eggId) +
" for team " + teamName +
112 " at (" + std::to_string(x) +
"," + std::to_string(y) +
")");
117 _logger.
info(WORLD,
"egg #" + std::to_string(eggId) +
" hatched");
122 _logger.
info(WORLD,
"egg #" + std::to_string(eggId) +
" died");
126 const std::vector<int>& participantIds)
128 _logger.
info(WORLD,
"incantation start lvl=" + std::to_string(level) +
" at (" +
129 std::to_string(x) +
"," + std::to_string(y) +
130 ") participants=" + std::to_string(participantIds.size()));
135 _logger.
info(WORLD, std::string(
"incantation end ") + (success ?
"success" :
"fail") +
" at (" +
136 std::to_string(x) +
"," + std::to_string(y) +
")");
142 "player #" + std::to_string(playerId) +
" -> lvl " + std::to_string(newLevel));
147 _logger.
info(WORLD,
"game end, winner=" + winningTeam);
152 _logger.
debug(WORLD,
"tile (" + std::to_string(x) +
"," + std::to_string(y) +
") -> [" +
153 resStr(resources) +
"]");
ResourceType
Enumerate the different types of resources in the game.
void onGameEnd(const std::string &winningTeam) override
A team won (6 players at max level). -> seg.
void onPlayerInventoryChanged(int playerId, int x, int y, Resources inventory) override
Player's carried resources changed. -> pin.
void onResourceTaken(int playerId, ResourceType resourceType, int tileX, int tileY, Resources resources) override
Player picked a resource up off the tile. -> pgt (+ bct/pin)
void onPlayerEjected(int playerId) override
Player got pushed off its tile by an eject. -> pex.
void onLineSent(int connectionId, const std::string &line) override
One line was queued to be sent to the client.
void onEggLaid(int eggId, int playerId, int x, int y) override
A player laid an egg via Fork. -> enw.
void onClientConnected(int connectionId) override
A new client socket was accepted (assigned connectionId).
void onPlayerMoved(int playerId, int nx, int ny, Orientation newOrientation) override
Player changed tile and/or facing. -> ppo.
void onBroadcast(int playerId, const std::string &message) override
Player shouted a broadcast message. -> pbc.
void onClientDisconnected(int connectionId) override
A client socket closed or errored.
void onInitialEggSpawned(int eggId, const std::string &teamName, int x, int y) override
An initial team egg placed at game start (custom). -> sse.
LogObserver(Logger &logger)
void onIncantationStart(int x, int y, int level, const std::vector< int > &participantIds) override
Incantation began on a tile. participantIds = players involved. -> pic.
void onPlayerRemoved(int playerId) override
Player left (death or disconnect). -> pdi.
void onPlayerAdded(int playerId, int x, int y, Orientation orientation, int level, const std::string &teamName) override
Player spawned (egg hatched or initial connection). -> pnw.
void onTileChanged(int x, int y, Resources resources) override
A tile's resource contents changed (e.g. respawn). -> bct.
void onEggHatched(int eggId) override
An egg hatched into a connectable slot. -> ebo.
void onResourceDropped(int playerId, ResourceType resourceType, int tileX, int tileY, Resources resources) override
Player dropped a resource onto the tile. -> pdr (+ bct/pin)
void onEggDied(int eggId) override
An egg was destroyed (e.g. crushed by an eject). -> edi.
void onPlayerLevelUp(int playerId, int newLevel) override
Player reached a new level. -> plv.
void onIncantationEnd(int x, int y, bool success) override
Incantation finished, success = leveled up or not. -> pie.
void onLineReceived(int connectionId, const std::string &line) override
One complete ' '-terminated line arrived from the client.
Logging facade: formats [time] [LEVEL] [component] message, filters by level, and forwards to a singl...
void info(std::string_view component, std::string_view msg)
void debug(std::string_view component, std::string_view msg)
Represents the resources available in the game, including food and various minerals.
static std::string get_name(int index)
constexpr const char * NET
std::string trim(const std::string &s)
Strip a single trailing ' ' so protocol lines log on one row.
constexpr const char * WORLD
std::string resStr(const Resources &r)