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

Handles the first exchange with a new socket. More...

#include <HandshakeHandler.hpp>

+ Collaboration diagram for HandshakeHandler:

Public Member Functions

 HandshakeHandler (ClientManager &clients, World &world, GuiNotifier &notifier, const ServerConfig &config, const GameClock &clock, PromotedCallback onPromoted)
 
void onNewConnection (int connectionId)
 New socket: send the "WELCOME" greeting.
 
void onLine (int connectionId, const std::string &line)
 The client's reply (its team name).
 

Private Member Functions

void _promoteToGui (int connectionId)
 
void _promoteToAi (int connectionId, const std::string &teamName)
 
void _reject (int connectionId)
 

Private Attributes

ClientManager_clients
 
World_world
 
GuiNotifier_notifier
 
const ServerConfig_config
 
const GameClock_clock
 
PromotedCallback _onPromoted
 

Detailed Description

Handles the first exchange with a new socket.

On connect the server sends "WELCOME". The client replies with a team name: "GRAPHIC" becomes a GUI, any other name joins that team as an AI (if a slot is free), anything else is rejected. Once accepted, the connection is promoted to its real type and onPromoted is fired.

Definition at line 22 of file HandshakeHandler.hpp.

Constructor & Destructor Documentation

◆ HandshakeHandler()

HandshakeHandler::HandshakeHandler ( ClientManager clients,
World world,
GuiNotifier notifier,
const ServerConfig config,
const GameClock clock,
PromotedCallback  onPromoted 
)

Definition at line 9 of file HandshakeHandler.cpp.

Member Function Documentation

◆ _promoteToAi()

void HandshakeHandler::_promoteToAi ( int  connectionId,
const std::string &  teamName 
)
private

Definition at line 74 of file HandshakeHandler.cpp.

References _clients, _config, _onPromoted, _reject(), _world, World::addPlayer(), AI, ClientManager::getConnection(), ServerConfig::height, World::popEggForTeam(), ClientManager::send(), Connection::setPlayerId(), Connection::setType(), World::teamEggCount(), and ServerConfig::width.

Referenced by onLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _promoteToGui()

void HandshakeHandler::_promoteToGui ( int  connectionId)
private

Definition at line 49 of file HandshakeHandler.cpp.

References _clients, _clock, _config, _notifier, _world, GuiNotifier::addGui(), World::at(), Serializer::bct(), Serializer::enw(), GameClock::freq(), ClientManager::getConnection(), World::getEggs(), World::getPlayers(), GUI, ServerConfig::height, Serializer::msz(), Serializer::pnw(), Tile::resources, GuiNotifier::send(), Connection::setType(), Serializer::sgt(), Serializer::sse(), ServerConfig::teamNames, Serializer::tna(), and ServerConfig::width.

Referenced by onLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _reject()

void HandshakeHandler::_reject ( int  connectionId)
private

Definition at line 100 of file HandshakeHandler.cpp.

References _clients, ClientManager::disconnect(), and ClientManager::send().

Referenced by _promoteToAi(), and onLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onLine()

void HandshakeHandler::onLine ( int  connectionId,
const std::string &  line 
)

The client's reply (its team name).

Definition at line 26 of file HandshakeHandler.cpp.

References _config, _promoteToAi(), _promoteToGui(), _reject(), _world, World::isGameEnded(), World::teamEggCount(), and ServerConfig::teamNames.

Referenced by CommandDispatcher::dispatch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onNewConnection()

void HandshakeHandler::onNewConnection ( int  connectionId)

New socket: send the "WELCOME" greeting.

Definition at line 21 of file HandshakeHandler.cpp.

References _clients, and ClientManager::send().

Referenced by CommandDispatcher::onNewConnection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _clients

ClientManager& HandshakeHandler::_clients
private

Definition at line 38 of file HandshakeHandler.hpp.

Referenced by _promoteToAi(), _promoteToGui(), _reject(), and onNewConnection().

◆ _clock

const GameClock& HandshakeHandler::_clock
private

Definition at line 42 of file HandshakeHandler.hpp.

Referenced by _promoteToGui().

◆ _config

const ServerConfig& HandshakeHandler::_config
private

Definition at line 41 of file HandshakeHandler.hpp.

Referenced by _promoteToAi(), _promoteToGui(), and onLine().

◆ _notifier

GuiNotifier& HandshakeHandler::_notifier
private

Definition at line 40 of file HandshakeHandler.hpp.

Referenced by _promoteToGui().

◆ _onPromoted

PromotedCallback HandshakeHandler::_onPromoted
private

Definition at line 43 of file HandshakeHandler.hpp.

Referenced by _promoteToAi().

◆ _world

World& HandshakeHandler::_world
private

Definition at line 39 of file HandshakeHandler.hpp.

Referenced by _promoteToAi(), _promoteToGui(), and onLine().


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