|
Zappy Server
C++ game server: world, rules, scheduler, network
|
Sends each client line to the right handler. More...
#include <CommandDispatcher.hpp>
Collaboration diagram for CommandDispatcher:Public Member Functions | |
| CommandDispatcher (ClientManager &clients, World &world, GuiNotifier ¬ifier, const ServerConfig &config, Scheduler &scheduler) | |
| void | onNewConnection (int connectionId) |
| New socket connected: start its handshake. | |
| void | dispatch (int connectionId, const std::string &line) |
| Route one line from a client. | |
| void | onDisconnect (int connectionId) |
| Socket dropped: clean up its queue and player. | |
| std::vector< int > | drainPendingDisconnects () |
| Take the list of ids the server should disconnect this cycle. | |
| std::chrono::microseconds | gameElapsed () const |
Wall-clock time since server start (single source for stu and the win banner). | |
| double | gameTicks () const |
| Total game ticks elapsed (freq integrated over time). For the win banner. | |
| std::optional< GameClock::Stamp > | teamJoin (const std::string &team) const |
When team's first player joined, or nullopt if it never did. | |
Private Member Functions | |
| void | _dispatchAi (int connectionId, const std::string &line) |
| void | _dispatchGui (int connectionId, const std::string &line) |
| void | _executeNext (int connectionId) |
| Run the next queued AI command (or go idle if none left). | |
| void | _onAiJoined (int connectionId, int playerId) |
| Fired on AI promotion: stamp team join, then start its food timer. | |
| void | _startStarvationTimer (int connectionId, int playerId) |
| void | _handleMsz (int connectionId) |
| void | _handleBct (int connectionId, int x, int y) |
| void | _handleMct (int connectionId) |
| void | _handleTna (int connectionId) |
| void | _handlePpo (int connectionId, int playerId) |
| void | _handlePlv (int connectionId, int playerId) |
| void | _handlePin (int connectionId, int playerId) |
| void | _handleSgt (int connectionId) |
| void | _handleSst (int freq) |
| void | _handleStu (int connectionId) |
| void | _handleForward (int connectionId) |
| void | _handleRight (int connectionId) |
| void | _handleLeft (int connectionId) |
| void | _handleLook (int connectionId) |
| void | _handleInventory (int connectionId) |
| void | _handleBroadcast (int connectionId, const std::string &msg) |
| void | _handleFork (int connectionId) |
| void | _handleEject (int connectionId) |
| void | _handleTake (int connectionId, ResourceType resource) |
| void | _handleSet (int connectionId, ResourceType resource) |
| void | _handleIncantation (int connectionId) |
| void | _handleConnectNbr (int connectionId) |
Private Attributes | |
| ClientManager & | _clients |
| World & | _world |
| GuiNotifier & | _notifier |
| Scheduler & | _scheduler |
| const ServerConfig & | _config |
| GameClock | _clock |
| HandshakeHandler | _handshakeHandler |
| std::unordered_map< int, std::deque< Ai::Command > > | _queues |
| std::unordered_map< int, bool > | _hasActive |
| std::vector< int > | _pendingDisconnects |
Static Private Attributes | |
| static constexpr int | STARVATION_INTERVAL_MS = 126000 |
| one food is consumed every 126 time units (1 unit = 1/freq seconds) | |
Sends each client line to the right handler.
GUI lines are answered right away. AI lines get queued (max 10) and run one at a time, each taking some time units before the next starts. Also handles the handshake for new sockets and the food/starvation timer per player.
Definition at line 25 of file CommandDispatcher.hpp.
| CommandDispatcher::CommandDispatcher | ( | ClientManager & | clients, |
| World & | world, | ||
| GuiNotifier & | notifier, | ||
| const ServerConfig & | config, | ||
| Scheduler & | scheduler | ||
| ) |
Definition at line 10 of file CommandDispatcher.cpp.
References _onAiJoined().
Here is the call graph for this function:
|
private |
Definition at line 94 of file CommandDispatcher.cpp.
References _clients, _executeNext(), _hasActive, _queues, _world, World::isGameEnded(), AiParser::parse(), and ClientManager::send().
Referenced by dispatch().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 70 of file CommandDispatcher.cpp.
References _clients, _handleBct(), _handleMct(), _handleMsz(), _handlePin(), _handlePlv(), _handlePpo(), _handleSgt(), _handleSst(), _handleStu(), _handleTna(), GuiParser::parse(), and ClientManager::send().
Referenced by dispatch().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Run the next queued AI command (or go idle if none left).
Definition at line 111 of file CommandDispatcher.cpp.
References _handleBroadcast(), _handleConnectNbr(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleRight(), _handleSet(), _handleTake(), _hasActive, and _queues.
Referenced by _dispatchAi(), _handleBroadcast(), _handleConnectNbr(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleRight(), _handleSet(), and _handleTake().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 13 of file GuiHandlers.cpp.
References _clients, _world, World::at(), Serializer::bct(), Tile::resources, and ClientManager::send().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 183 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, broadcastDirection(), GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), World::getPlayers(), World::height(), World::playerBroadcast(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), and World::width().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 140 of file CommandDispatcher.cpp.
References _clients, _executeNext(), _world, ClientManager::getConnection(), World::getPlayer(), World::getPlayers(), Connection::playerId(), ClientManager::send(), and World::teamEggCount().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 224 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, broadcastDirection(), World::ejectPlayers(), GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), World::height(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), and World::width().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 207 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, World::addEgg(), GameClock::freq(), ClientManager::getConnection(), Connection::playerId(), Scheduler::schedule(), and ClientManager::send().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 51 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), World::movePlayer(), Connection::playerId(), Scheduler::schedule(), and ClientManager::send().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 295 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, Player::connectionId, World::finalizeIncantation(), GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), World::getPlayers(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), World::startIncantation(), and Player::x.
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 157 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), Connection::playerId(), Scheduler::schedule(), and ClientManager::send().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 105 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), turnLeft(), and World::turnPlayer().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 123 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _lookForwardRight(), _scheduler, _tileContent(), _world, World::at(), GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), Connection::playerId(), Scheduler::schedule(), and ClientManager::send().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 18 of file GuiHandlers.cpp.
References _clients, _world, World::at(), Serializer::bct(), World::height(), Tile::resources, ClientManager::send(), and World::width().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 8 of file GuiHandlers.cpp.
References _clients, _world, World::height(), Serializer::msz(), ClientManager::send(), and World::width().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 50 of file GuiHandlers.cpp.
References _clients, _world, World::getPlayer(), Serializer::pin(), and ClientManager::send().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 40 of file GuiHandlers.cpp.
References _clients, _world, World::getPlayer(), Serializer::plv(), and ClientManager::send().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 30 of file GuiHandlers.cpp.
References _clients, _world, World::getPlayer(), Serializer::ppo(), and ClientManager::send().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 86 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), World::getPlayer(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), World::turnPlayer(), and turnRight().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 275 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), and World::setResource().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 60 of file GuiHandlers.cpp.
References _clients, _clock, GameClock::freq(), ClientManager::send(), and Serializer::sgt().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 75 of file GuiHandlers.cpp.
References _clock, _notifier, _scheduler, GuiNotifier::broadcast(), GameClock::freq(), Scheduler::rescale(), GameClock::setFreq(), and Serializer::sst().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 65 of file GuiHandlers.cpp.
References _clients, _clock, gameElapsed(), ClientManager::send(), Serializer::stu(), and GameClock::ticks().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 256 of file AiHandlers.cpp.
References _clients, _clock, _executeNext(), _scheduler, _world, GameClock::freq(), ClientManager::getConnection(), Connection::playerId(), Scheduler::schedule(), ClientManager::send(), and World::takeResource().
Referenced by _executeNext().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 25 of file GuiHandlers.cpp.
References _clients, _config, ClientManager::send(), ServerConfig::teamNames, and Serializer::tna().
Referenced by _dispatchGui().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Fired on AI promotion: stamp team join, then start its food timer.
Definition at line 33 of file CommandDispatcher.cpp.
References _clock, _startStarvationTimer(), _world, World::getPlayer(), World::getPlayers(), GameClock::recordJoin(), and Player::teamName.
Referenced by CommandDispatcher().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 151 of file CommandDispatcher.cpp.
References _clock, _scheduler, GameClock::freq(), Scheduler::schedule(), and STARVATION_INTERVAL_MS.
Referenced by _onAiJoined().
Here is the call graph for this function:
Here is the caller graph for this function:| void CommandDispatcher::dispatch | ( | int | connectionId, |
| const std::string & | line | ||
| ) |
Route one line from a client.
Definition at line 44 of file CommandDispatcher.cpp.
References _clients, _dispatchAi(), _dispatchGui(), _handshakeHandler, AI, ClientManager::getConnection(), GUI, HandshakeHandler::onLine(), and PENDING.
Referenced by Server::run().
Here is the call graph for this function:
Here is the caller graph for this function:| std::vector< int > CommandDispatcher::drainPendingDisconnects | ( | ) |
Take the list of ids the server should disconnect this cycle.
Definition at line 166 of file CommandDispatcher.cpp.
References _pendingDisconnects.
Referenced by Server::run().
Here is the caller graph for this function:| std::chrono::microseconds CommandDispatcher::gameElapsed | ( | ) | const |
Wall-clock time since server start (single source for stu and the win banner).
Definition at line 24 of file CommandDispatcher.cpp.
References _clock, and GameClock::elapsed().
Referenced by Server::_handleGameOver(), and _handleStu().
Here is the call graph for this function:
Here is the caller graph for this function:| double CommandDispatcher::gameTicks | ( | ) | const |
Total game ticks elapsed (freq integrated over time). For the win banner.
Definition at line 26 of file CommandDispatcher.cpp.
References _clock, and GameClock::ticks().
Referenced by Server::_handleGameOver().
Here is the call graph for this function:
Here is the caller graph for this function:| void CommandDispatcher::onDisconnect | ( | int | connectionId | ) |
Socket dropped: clean up its queue and player.
Definition at line 55 of file CommandDispatcher.cpp.
References _clients, _hasActive, _notifier, _queues, _world, AI, ClientManager::getConnection(), World::getPlayers(), GUI, GuiNotifier::removeGui(), and World::removePlayer().
Referenced by Server::run().
Here is the call graph for this function:
Here is the caller graph for this function:| void CommandDispatcher::onNewConnection | ( | int | connectionId | ) |
New socket connected: start its handshake.
Definition at line 39 of file CommandDispatcher.cpp.
References _handshakeHandler, and HandshakeHandler::onNewConnection().
Referenced by Server::run().
Here is the call graph for this function:
Here is the caller graph for this function:| std::optional< GameClock::Stamp > CommandDispatcher::teamJoin | ( | const std::string & | team | ) | const |
When team's first player joined, or nullopt if it never did.
Definition at line 28 of file CommandDispatcher.cpp.
References _clock, and GameClock::joinOf().
Referenced by Server::_handleGameOver().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 85 of file CommandDispatcher.hpp.
Referenced by _dispatchAi(), _dispatchGui(), _handleBct(), _handleBroadcast(), _handleConnectNbr(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleMct(), _handleMsz(), _handlePin(), _handlePlv(), _handlePpo(), _handleRight(), _handleSet(), _handleSgt(), _handleStu(), _handleTake(), _handleTna(), dispatch(), and onDisconnect().
|
private |
Definition at line 90 of file CommandDispatcher.hpp.
Referenced by _handleBroadcast(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleRight(), _handleSet(), _handleSgt(), _handleSst(), _handleStu(), _handleTake(), _onAiJoined(), _startStarvationTimer(), gameElapsed(), gameTicks(), and teamJoin().
|
private |
Definition at line 89 of file CommandDispatcher.hpp.
Referenced by _handleTna().
|
private |
Definition at line 91 of file CommandDispatcher.hpp.
Referenced by dispatch(), and onNewConnection().
|
private |
Definition at line 94 of file CommandDispatcher.hpp.
Referenced by _dispatchAi(), _executeNext(), and onDisconnect().
|
private |
Definition at line 87 of file CommandDispatcher.hpp.
Referenced by _handleSst(), and onDisconnect().
|
private |
Definition at line 95 of file CommandDispatcher.hpp.
Referenced by drainPendingDisconnects().
|
private |
Definition at line 93 of file CommandDispatcher.hpp.
Referenced by _dispatchAi(), _executeNext(), and onDisconnect().
|
private |
Definition at line 88 of file CommandDispatcher.hpp.
Referenced by _handleBroadcast(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleRight(), _handleSet(), _handleSst(), _handleTake(), and _startStarvationTimer().
|
private |
Definition at line 86 of file CommandDispatcher.hpp.
Referenced by _dispatchAi(), _handleBct(), _handleBroadcast(), _handleConnectNbr(), _handleEject(), _handleFork(), _handleForward(), _handleIncantation(), _handleInventory(), _handleLeft(), _handleLook(), _handleMct(), _handleMsz(), _handlePin(), _handlePlv(), _handlePpo(), _handleRight(), _handleSet(), _handleTake(), _onAiJoined(), and onDisconnect().
|
staticconstexprprivate |
one food is consumed every 126 time units (1 unit = 1/freq seconds)
Definition at line 57 of file CommandDispatcher.hpp.
Referenced by _startStarvationTimer().