Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
LogObserver Class Reference

Bridges the Observer hooks to the Logger. More...

#include <LogObserver.hpp>

+ Inheritance diagram for LogObserver:
+ Collaboration diagram for LogObserver:

Public Member Functions

 LogObserver (Logger &logger)
 
void onClientConnected (int connectionId) override
 A new client socket was accepted (assigned connectionId).
 
void onClientDisconnected (int connectionId) override
 A client socket closed or errored.
 
void onLineReceived (int connectionId, const std::string &line) override
 One complete '
'-terminated line arrived from the client.
 
void onLineSent (int connectionId, const std::string &line) override
 One line was queued to be sent to the client.
 
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 onPlayerMoved (int playerId, int nx, int ny, Orientation newOrientation) override
 Player changed tile and/or facing. -> ppo.
 
void onPlayerInventoryChanged (int playerId, int x, int y, Resources inventory) override
 Player's carried resources changed. -> pin.
 
void onPlayerRemoved (int playerId) override
 Player left (death or disconnect). -> pdi.
 
void onPlayerEjected (int playerId) override
 Player got pushed off its tile by an eject. -> pex.
 
void onBroadcast (int playerId, const std::string &message) override
 Player shouted a broadcast message. -> pbc.
 
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 onResourceDropped (int playerId, ResourceType resourceType, int tileX, int tileY, Resources resources) override
 Player dropped a resource onto the tile. -> pdr (+ bct/pin)
 
void onEggLaid (int eggId, int playerId, int x, int y) override
 A player laid an egg via Fork. -> enw.
 
void onInitialEggSpawned (int eggId, const std::string &teamName, int x, int y) override
 An initial team egg placed at game start (custom). -> sse.
 
void onEggHatched (int eggId) override
 An egg hatched into a connectable slot. -> ebo.
 
void onEggDied (int eggId) override
 An egg was destroyed (e.g. crushed by an eject). -> edi.
 
void onIncantationStart (int x, int y, int level, const std::vector< int > &participantIds) override
 Incantation began on a tile. participantIds = players involved. -> pic.
 
void onIncantationEnd (int x, int y, bool success) override
 Incantation finished, success = leveled up or not. -> pie.
 
void onPlayerLevelUp (int playerId, int newLevel) override
 Player reached a new level. -> plv.
 
void onGameEnd (const std::string &winningTeam) override
 A team won (6 players at max level). -> seg.
 
void onTileChanged (int x, int y, Resources resources) override
 A tile's resource contents changed (e.g. respawn). -> bct.
 
- Public Member Functions inherited from IWorldObserver
virtual ~IWorldObserver ()=default
 
- Public Member Functions inherited from INetworkObserver
virtual ~INetworkObserver ()=default
 

Private Attributes

Logger_logger
 

Detailed Description

Bridges the Observer hooks to the Logger.

Registered on both World (IWorldObserver) and ClientManager (INetworkObserver), so every world mutation and every raw protocol line is logged automatically, without scattering log calls across the game logic.

Raw I/O is logged at Debug; world events at Info.

Definition at line 19 of file LogObserver.hpp.

Constructor & Destructor Documentation

◆ LogObserver()

LogObserver::LogObserver ( Logger logger)
explicit

Definition at line 27 of file LogObserver.cpp.

Member Function Documentation

◆ onBroadcast()

void LogObserver::onBroadcast ( int  playerId,
const std::string &  message 
)
overridevirtual

Player shouted a broadcast message. -> pbc.

Implements IWorldObserver.

Definition at line 80 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

◆ onClientConnected()

void LogObserver::onClientConnected ( int  connectionId)
overridevirtual

A new client socket was accepted (assigned connectionId).

Implements INetworkObserver.

Definition at line 29 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onClientDisconnected()

void LogObserver::onClientDisconnected ( int  connectionId)
overridevirtual

A client socket closed or errored.

Implements INetworkObserver.

Definition at line 34 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onEggDied()

void LogObserver::onEggDied ( int  eggId)
overridevirtual

An egg was destroyed (e.g. crushed by an eject). -> edi.

Implements IWorldObserver.

Definition at line 120 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onEggHatched()

void LogObserver::onEggHatched ( int  eggId)
overridevirtual

An egg hatched into a connectable slot. -> ebo.

Implements IWorldObserver.

Definition at line 115 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onEggLaid()

void LogObserver::onEggLaid ( int  eggId,
int  playerId,
int  x,
int  y 
)
overridevirtual

A player laid an egg via Fork. -> enw.

Implements IWorldObserver.

Definition at line 103 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onGameEnd()

void LogObserver::onGameEnd ( const std::string &  winningTeam)
overridevirtual

A team won (6 players at max level). -> seg.

Implements IWorldObserver.

Definition at line 145 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onIncantationEnd()

void LogObserver::onIncantationEnd ( int  x,
int  y,
bool  success 
)
overridevirtual

Incantation finished, success = leveled up or not. -> pie.

Implements IWorldObserver.

Definition at line 133 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onIncantationStart()

void LogObserver::onIncantationStart ( int  x,
int  y,
int  level,
const std::vector< int > &  participantIds 
)
overridevirtual

Incantation began on a tile. participantIds = players involved. -> pic.

Implements IWorldObserver.

Definition at line 125 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onInitialEggSpawned()

void LogObserver::onInitialEggSpawned ( int  eggId,
const std::string &  teamName,
int  x,
int  y 
)
overridevirtual

An initial team egg placed at game start (custom). -> sse.

Implements IWorldObserver.

Definition at line 109 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onLineReceived()

void LogObserver::onLineReceived ( int  connectionId,
const std::string &  line 
)
overridevirtual

One complete '
'-terminated line arrived from the client.

Implements INetworkObserver.

Definition at line 39 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

◆ onLineSent()

void LogObserver::onLineSent ( int  connectionId,
const std::string &  line 
)
overridevirtual

One line was queued to be sent to the client.

Implements INetworkObserver.

Definition at line 44 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

◆ onPlayerAdded()

void LogObserver::onPlayerAdded ( int  playerId,
int  x,
int  y,
Orientation  orientation,
int  level,
const std::string &  teamName 
)
overridevirtual

Player spawned (egg hatched or initial connection). -> pnw.

Implements IWorldObserver.

Definition at line 49 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onPlayerEjected()

void LogObserver::onPlayerEjected ( int  playerId)
overridevirtual

Player got pushed off its tile by an eject. -> pex.

Implements IWorldObserver.

Definition at line 75 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onPlayerInventoryChanged()

void LogObserver::onPlayerInventoryChanged ( int  playerId,
int  x,
int  y,
Resources  inventory 
)
overridevirtual

Player's carried resources changed. -> pin.

Implements IWorldObserver.

Definition at line 63 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

◆ onPlayerLevelUp()

void LogObserver::onPlayerLevelUp ( int  playerId,
int  newLevel 
)
overridevirtual

Player reached a new level. -> plv.

Implements IWorldObserver.

Definition at line 139 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onPlayerMoved()

void LogObserver::onPlayerMoved ( int  playerId,
int  nx,
int  ny,
Orientation  newOrientation 
)
overridevirtual

Player changed tile and/or facing. -> ppo.

Implements IWorldObserver.

Definition at line 57 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

◆ onPlayerRemoved()

void LogObserver::onPlayerRemoved ( int  playerId)
overridevirtual

Player left (death or disconnect). -> pdi.

Implements IWorldObserver.

Definition at line 70 of file LogObserver.cpp.

References _logger, and Logger::info().

+ Here is the call graph for this function:

◆ onResourceDropped()

void LogObserver::onResourceDropped ( int  playerId,
ResourceType  resourceType,
int  tileX,
int  tileY,
Resources  resources 
)
overridevirtual

Player dropped a resource onto the tile. -> pdr (+ bct/pin)

Implements IWorldObserver.

Definition at line 94 of file LogObserver.cpp.

References _logger, Logger::debug(), and Resources::get_name().

+ Here is the call graph for this function:

◆ onResourceTaken()

void LogObserver::onResourceTaken ( int  playerId,
ResourceType  resourceType,
int  tileX,
int  tileY,
Resources  resources 
)
overridevirtual

Player picked a resource up off the tile. -> pgt (+ bct/pin)

Implements IWorldObserver.

Definition at line 85 of file LogObserver.cpp.

References _logger, Logger::debug(), and Resources::get_name().

+ Here is the call graph for this function:

◆ onTileChanged()

void LogObserver::onTileChanged ( int  x,
int  y,
Resources  resources 
)
overridevirtual

A tile's resource contents changed (e.g. respawn). -> bct.

Implements IWorldObserver.

Definition at line 150 of file LogObserver.cpp.

References _logger, and Logger::debug().

+ Here is the call graph for this function:

Member Data Documentation

◆ _logger


The documentation for this class was generated from the following files: