|
Zappy Server
C++ game server: world, rules, scheduler, network
|
Owns every client socket and runs the poll() loop. More...
#include <ClientManager.hpp>
Collaboration diagram for ClientManager:Public Member Functions | |
| ClientManager (Listener &listener) | |
| PollResult | poll (int timeoutMs) |
Run one poll cycle (blocks up to timeoutMs); returns this cycle's events. | |
| void | send (int connectionId, const std::string &msg) |
Queue msg to be sent to a client (flushed during poll()). | |
| void | disconnect (int connectionId) |
| Close a client and drop its connection. | |
| Connection & | getConnection (int connectionId) |
| Access the underlying Connection (e.g. to set its type/playerId). | |
| void | addNetworkObserver (INetworkObserver *observer) |
| Subscribe an observer to connect/disconnect/line events. | |
Private Member Functions | |
| void | _acceptNew (PollResult &result) |
| void | _handleEvents (const pollfd &pfd, PollResult &result) |
| void | _rebuildPollFds () |
Private Attributes | |
| Listener & | _listener |
| std::unordered_map< int, Connection > | _connections |
| std::unordered_map< int, int > | _fdToId |
| std::vector< pollfd > | _pollFds |
| int | _nextId = 0 |
| std::vector< INetworkObserver * > | _observers |
Owns every client socket and runs the poll() loop.
One poll() call watches all sockets at once: it accepts new clients, reads the ready ones, splits incoming bytes into '
' lines, and flushes pending writes. Clients are addressed by a stable id, not the raw fd. Observers are told about all traffic.
Definition at line 30 of file ClientManager.hpp.
|
explicit |
Definition at line 9 of file ClientManager.cpp.
|
private |
Definition at line 38 of file ClientManager.cpp.
References _connections, _listener, _nextId, _observers, Listener::accept(), and PollResult::newConnections.
Referenced by poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 49 of file ClientManager.cpp.
References _connections, _fdToId, _observers, PollResult::disconnectedIds, PollResult::lines, and n().
Referenced by poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 11 of file ClientManager.cpp.
References _connections, _fdToId, _listener, _pollFds, Listener::fd(), and id().
Referenced by poll().
Here is the call graph for this function:
Here is the caller graph for this function:| void ClientManager::addNetworkObserver | ( | INetworkObserver * | observer | ) |
Subscribe an observer to connect/disconnect/line events.
Definition at line 100 of file ClientManager.cpp.
References _observers.
Referenced by Server::Server().
Here is the caller graph for this function:| void ClientManager::disconnect | ( | int | connectionId | ) |
Close a client and drop its connection.
Definition at line 83 of file ClientManager.cpp.
References _connections, and _observers.
Referenced by Server::_handleGameOver(), HandshakeHandler::_reject(), and Server::run().
Here is the caller graph for this function:| Connection & ClientManager::getConnection | ( | int | connectionId | ) |
Access the underlying Connection (e.g. to set its type/playerId).
Definition at line 92 of file ClientManager.cpp.
References _connections.
Referenced by CommandDispatcher::_handleBroadcast(), CommandDispatcher::_handleConnectNbr(), CommandDispatcher::_handleEject(), CommandDispatcher::_handleFork(), CommandDispatcher::_handleForward(), CommandDispatcher::_handleIncantation(), CommandDispatcher::_handleInventory(), CommandDispatcher::_handleLeft(), CommandDispatcher::_handleLook(), CommandDispatcher::_handleRight(), CommandDispatcher::_handleSet(), CommandDispatcher::_handleTake(), HandshakeHandler::_promoteToAi(), HandshakeHandler::_promoteToGui(), CommandDispatcher::dispatch(), and CommandDispatcher::onDisconnect().
Here is the caller graph for this function:| PollResult ClientManager::poll | ( | int | timeoutMs | ) |
Run one poll cycle (blocks up to timeoutMs); returns this cycle's events.
Definition at line 23 of file ClientManager.cpp.
References _acceptNew(), _handleEvents(), _pollFds, _rebuildPollFds(), and poll().
Referenced by poll(), and Server::run().
Here is the call graph for this function:
Here is the caller graph for this function:| void ClientManager::send | ( | int | connectionId, |
| const std::string & | msg | ||
| ) |
Queue msg to be sent to a client (flushed during poll()).
Definition at line 76 of file ClientManager.cpp.
References _connections, and _observers.
Referenced by CommandDispatcher::_dispatchAi(), CommandDispatcher::_dispatchGui(), CommandDispatcher::_handleBct(), CommandDispatcher::_handleBroadcast(), CommandDispatcher::_handleConnectNbr(), CommandDispatcher::_handleEject(), CommandDispatcher::_handleFork(), CommandDispatcher::_handleForward(), CommandDispatcher::_handleIncantation(), CommandDispatcher::_handleInventory(), CommandDispatcher::_handleLeft(), CommandDispatcher::_handleLook(), CommandDispatcher::_handleMct(), CommandDispatcher::_handleMsz(), CommandDispatcher::_handlePin(), CommandDispatcher::_handlePlv(), CommandDispatcher::_handlePpo(), CommandDispatcher::_handleRight(), CommandDispatcher::_handleSet(), CommandDispatcher::_handleSgt(), CommandDispatcher::_handleStu(), CommandDispatcher::_handleTake(), CommandDispatcher::_handleTna(), HandshakeHandler::_promoteToAi(), HandshakeHandler::_reject(), GuiNotifier::broadcast(), HandshakeHandler::onNewConnection(), and GuiNotifier::send().
Here is the caller graph for this function:
|
private |
Definition at line 52 of file ClientManager.hpp.
Referenced by _acceptNew(), _handleEvents(), _rebuildPollFds(), disconnect(), getConnection(), and send().
|
private |
Definition at line 53 of file ClientManager.hpp.
Referenced by _handleEvents(), and _rebuildPollFds().
|
private |
Definition at line 51 of file ClientManager.hpp.
Referenced by _acceptNew(), and _rebuildPollFds().
|
private |
Definition at line 55 of file ClientManager.hpp.
Referenced by _acceptNew().
|
private |
Definition at line 56 of file ClientManager.hpp.
Referenced by _acceptNew(), _handleEvents(), addNetworkObserver(), disconnect(), and send().
|
private |
Definition at line 54 of file ClientManager.hpp.
Referenced by _rebuildPollFds(), and poll().