adchpp::ClientManager Class Reference

The ClientManager takes care of all protocol details, clients and so on. More...

#include <ClientManager.h>

Inheritance diagram for adchpp::ClientManager:
Inheritance graph
[legend]
Collaboration diagram for adchpp::ClientManager:
Collaboration graph
[legend]

List of all members.

Public Types

typedef EntityMap::iterator EntityIter
typedef std::unordered_map
< uint32_t, Entity * > 
EntityMap
typedef SignalTraits< void(Entity
&, const std::string &)> 
SignalBadLine
typedef SignalTraits< void(Entity &)> SignalConnected
typedef SignalTraits< void(Entity &)> SignalDisconnected
typedef SignalTraits< void(Entity
&, AdcCommand &, bool &)> 
SignalReceive
typedef SignalTraits< void(Entity
&, const AdcCommand &, bool &)> 
SignalSend
typedef SignalTraits< void(Entity
&, int)> 
SignalState

Public Member Functions

ADCHPP_DLL BotcreateBot (const Bot::SendHandler &handler)
bool dispatch (Entity &c, AdcCommand &cmd)
ADCHPP_DLL void enterIdentify (Entity &c, bool sendData) throw ()
 Enter IDENTIFY state.
ADCHPP_DLL bool enterNormal (Entity &c, bool sendData, bool sendOwnInf) throw ()
 Enter NORMAL state.
ADCHPP_DLL ByteVector enterVerify (Entity &c, bool sendData) throw ()
 Enter VERIFY state.
EntityMapgetEntities () throw ()
 Get a list of all currently connected clients.
ADCHPP_DLL EntitygetEntity (uint32_t aSid) throw ()
uint32_t getLoginTimeout ()
ADCHPP_DLL size_t getQueuedBytes () throw ()
ADCHPP_DLL uint32_t getSID (const CID &cid) const throw ()
ADCHPP_DLL uint32_t getSID (const std::string &nick) const throw ()
ADCHPP_DLL void regBot (Bot &bot)
ADCHPP_DLL void send (const AdcCommand &cmd) throw ()
 Send a command to according to its type.
ADCHPP_DLL void sendTo (const BufferPtr &buffer, uint32_t to)
 Send buffer to a single client regardless of type.
ADCHPP_DLL void sendToAll (const BufferPtr &buffer) throw ()
 Send a buffer to all connected entities.
void setLoginTimeout (uint32_t millis)
ADCHPP_DLL void setState (Entity &c, Entity::State newState) throw ()
 Update the state of c (this fires signalState as well).
SignalBadLine::SignalsignalBadLine ()
SignalConnected::SignalsignalConnected ()
SignalDisconnected::SignalsignalDisconnected ()
SignalReceive::SignalsignalReceive ()
SignalSend::SignalsignalSend ()
SignalState::SignalsignalState ()
ADCHPP_DLL bool verifyCID (Entity &c, AdcCommand &cmd) throw ()
 Verify that CID is correct and corresponds to PID.
ADCHPP_DLL bool verifyINF (Entity &c, AdcCommand &cmd) throw ()
 Do all INF verifications and update client data.
ADCHPP_DLL bool verifyIp (Client &c, AdcCommand &cmd) throw ()
 Verify that IP is correct and replace any zero addresses.
ADCHPP_DLL bool verifyNick (Entity &c, const AdcCommand &cmd) throw ()
 Verify nick on INF (check that its not a dupe etc.
ADCHPP_DLL bool verifyOverflow (Entity &c)
 Verify that there aren't too many sockets overflowing (indicates lack of bandwidth).
ADCHPP_DLL bool verifyPassword (Entity &c, const std::string &password, const ByteVector &salt, const std::string &suppliedHash)
 Verify password.
ADCHPP_DLL bool verifySUP (Entity &c, AdcCommand &cmd) throw ()
 Do all SUP verifications and update client data.

Static Public Member Functions

static void deleteInstance ()
static T * getInstance ()
static void newInstance ()

Private Types

typedef std::unordered_map
< CID, Entity * > 
CIDMap
typedef std::unordered_map
< std::string, Entity * > 
NickMap

Private Member Functions

void badState (Entity &c, const AdcCommand &cmd) throw ()
 ClientManager () throw ()
template<typename T >
bool handle (T, Entity &c, AdcCommand &cmd) throw ()
bool handle (AdcCommand::INF, Entity &c, AdcCommand &cmd) throw ()
bool handle (AdcCommand::SUP, Entity &c, AdcCommand &cmd) throw ()
bool handleDefault (Entity &c, AdcCommand &cmd) throw ()
void handleIncoming (const ManagedSocketPtr &sock) throw ()
uint32_t makeSID ()
void maybeSend (Entity &c, const AdcCommand &cmd)
void onBadLine (Client &, const std::string &) throw ()
void onConnected (Client &) throw ()
void onFailed (Client &, const boost::system::error_code &e) throw ()
void onReceive (Entity &, AdcCommand &) throw ()
void removeEntity (Entity &c) throw ()
void removeLogins (Entity &c) throw ()
virtual ~ClientManager () throw ()

Private Attributes

CIDMap cids
EntityMap entities
Hub hub
std::list< std::pair< Client
*, uint32_t > > 
logins
size_t loginTimeout
NickMap nicks
SignalBadLine::Signal signalBadLine_
SignalConnected::Signal signalConnected_
SignalDisconnected::Signal signalDisconnected_
SignalReceive::Signal signalReceive_
SignalSend::Signal signalSend_
SignalState::Signal signalState_
std::string strtmp

Static Private Attributes

static const std::string className = "ClientManager"
static ADCHPP_DLL ClientManagerinstance = 0

Friends

class Bot
class Client
class CommandHandler< ClientManager >
class Entity
class Singleton< ClientManager >

Detailed Description

The ClientManager takes care of all protocol details, clients and so on.

This is the very heart of ADCH++ together with SocketManager and ManagedSocket.

Definition at line 38 of file ClientManager.h.


Member Typedef Documentation

typedef std::unordered_map<CID, Entity*> adchpp::ClientManager::CIDMap [private]

Definition at line 167 of file ClientManager.h.

typedef EntityMap::iterator adchpp::ClientManager::EntityIter

Definition at line 42 of file ClientManager.h.

typedef std::unordered_map<uint32_t, Entity*> adchpp::ClientManager::EntityMap

Definition at line 41 of file ClientManager.h.

typedef std::unordered_map<std::string, Entity*> adchpp::ClientManager::NickMap [private]

Definition at line 165 of file ClientManager.h.

typedef SignalTraits<void (Entity&, const std::string&)> adchpp::ClientManager::SignalBadLine

Definition at line 142 of file ClientManager.h.

Definition at line 140 of file ClientManager.h.

Definition at line 145 of file ClientManager.h.

Definition at line 141 of file ClientManager.h.

Definition at line 143 of file ClientManager.h.

Definition at line 144 of file ClientManager.h.


Constructor & Destructor Documentation

adchpp::ClientManager::ClientManager (  )  throw () [private]

Definition at line 38 of file ClientManager.cpp.

References adchpp::Entity::addSupports(), adchpp::Singleton< T >::getInstance(), handleIncoming(), hub, and adchpp::AdcCommand::toFourCC().

Here is the call graph for this function:

adchpp::ClientManager::~ClientManager (  )  throw () [private, virtual]

Definition at line 45 of file ClientManager.cpp.


Member Function Documentation

void adchpp::ClientManager::badState ( Entity c,
const AdcCommand cmd 
) throw () [private]
Bot * adchpp::ClientManager::createBot ( const Bot::SendHandler handler  ) 
Returns:
A new Bot instance in STATE_IDENTIFY; set CID, nick etc and call regBot

Definition at line 49 of file ClientManager.cpp.

References Bot, and makeSID().

Here is the call graph for this function:

template<typename T>
static void adchpp::Singleton< T >::deleteInstance (  )  [inline, static, inherited]

Definition at line 49 of file Singleton.h.

bool adchpp::CommandHandler< ClientManager >::dispatch ( Entity c,
AdcCommand cmd 
) [inline, inherited]

Definition at line 206 of file AdcCommand.h.

References C, dcdebug, adchpp::AdcCommand::getCommand(), and adchpp::AdcCommand::toString().

Here is the call graph for this function:

void adchpp::ClientManager::enterIdentify ( Entity c,
bool  sendData 
) throw ()

Enter IDENTIFY state.

Call this if you stop the SUP command when in PROTOCOL state.

Parameters:
sendData Send ISUP & IINF.

Definition at line 434 of file ClientManager.cpp.

References c, dcassert, dcdebug, adchpp::AdcCommand::fromSID(), adchpp::Entity::getSID(), adchpp::Entity::getState(), adchpp::Client::send(), adchpp::Entity::STATE_IDENTIFY, and adchpp::Entity::STATE_PROTOCOL.

Referenced by regBot().

Here is the call graph for this function:

Here is the caller graph for this function:

bool adchpp::ClientManager::enterNormal ( Entity c,
bool  sendData,
bool  sendOwnInf 
) throw ()

Enter NORMAL state.

Call this if you stop an INF of a password-less client in IDENTIFY state or a PAS in VERIFY state.

Parameters:
sendData Send all data as mandated by the protocol, including list of connected clients.
sendOwnInf Set to true to broadcast the client's inf (i e when a plugin asks for password)
Returns:
false if the client was disconnected

Definition at line 465 of file ClientManager.cpp.

References c, dcassert, dcdebug, adchpp::AdcCommand::fromSID(), adchpp::Entity::getINF(), adchpp::Entity::getSID(), adchpp::Entity::getState(), adchpp::Client::send(), adchpp::Entity::STATE_IDENTIFY, adchpp::Entity::STATE_NORMAL, and adchpp::Entity::STATE_VERIFY.

Referenced by regBot().

Here is the call graph for this function:

Here is the caller graph for this function:

ByteVector adchpp::ClientManager::enterVerify ( Entity c,
bool  sendData 
) throw ()

Enter VERIFY state.

Call this if you stop an INF in the IDENTIFY state and want to check a password.

Parameters:
sendData Send GPA.
Returns:
The random data that was sent to the client (if sendData was true, undefined otherwise).

Definition at line 446 of file ClientManager.cpp.

References c, dcassert, dcdebug, adchpp::AdcCommand::fromSID(), adchpp::Entity::getSID(), adchpp::Entity::getState(), adchpp::Util::rand(), adchpp::Client::send(), adchpp::Entity::STATE_IDENTIFY, adchpp::Entity::STATE_VERIFY, and adchpp::Encoder::toBase32().

Here is the call graph for this function:

EntityMap& adchpp::ClientManager::getEntities (  )  throw () [inline]

Get a list of all currently connected clients.

(Don't change it, it's non-const so that you'll be able to get non-const clients out of it...)!!!)

Definition at line 60 of file ClientManager.h.

References entities.

Entity * adchpp::ClientManager::getEntity ( uint32_t  aSid  )  throw ()
Returns:
The entity associated with a certain SID, NULL if not found

Definition at line 519 of file ClientManager.cpp.

References dcdebug, adchpp::AdcCommand::HUB_SID, and adchpp::AdcCommand::INVALID_SID.

template<typename T>
static T* adchpp::Singleton< T >::getInstance (  )  [inline, static, inherited]

Definition at line 37 of file Singleton.h.

Referenced by ClientManager(), adchpp::Bot::die(), and adchpp::Entity::inject().

Here is the caller graph for this function:

uint32_t adchpp::ClientManager::getLoginTimeout (  )  [inline]

Definition at line 155 of file ClientManager.h.

References loginTimeout.

size_t adchpp::ClientManager::getQueuedBytes (  )  throw ()

Definition at line 110 of file ClientManager.cpp.

References entities.

uint32_t adchpp::ClientManager::getSID ( const CID cid  )  const throw ()
Returns:
SID of entity or 0 if not found

Definition at line 538 of file ClientManager.cpp.

uint32_t adchpp::ClientManager::getSID ( const std::string &  nick  )  const throw ()
Returns:
SID of entity or 0 if not found

Definition at line 533 of file ClientManager.cpp.

template<typename T >
bool adchpp::ClientManager::handle ( ,
Entity c,
AdcCommand cmd 
) throw () [inline, private]

Definition at line 195 of file ClientManager.h.

References c, and handleDefault().

Here is the call graph for this function:

bool adchpp::ClientManager::handle ( AdcCommand::INF  ,
Entity c,
AdcCommand cmd 
) throw () [private]

Definition at line 292 of file ClientManager.cpp.

References c, adchpp::Entity::getState(), adchpp::Entity::STATE_IDENTIFY, and adchpp::Entity::STATE_NORMAL.

Here is the call graph for this function:

bool adchpp::ClientManager::handle ( AdcCommand::SUP  ,
Entity c,
AdcCommand cmd 
) throw () [private]

Definition at line 202 of file ClientManager.cpp.

References c, adchpp::Entity::getState(), adchpp::Entity::STATE_NORMAL, and adchpp::Entity::STATE_PROTOCOL.

Here is the call graph for this function:

bool adchpp::ClientManager::handleDefault ( Entity c,
AdcCommand cmd 
) throw () [private]

Definition at line 194 of file ClientManager.cpp.

References c, adchpp::Entity::getState(), and adchpp::Entity::STATE_NORMAL.

Referenced by handle().

Here is the call graph for this function:

Here is the caller graph for this function:

void adchpp::ClientManager::handleIncoming ( const ManagedSocketPtr sock  )  throw () [private]

Definition at line 127 of file ClientManager.cpp.

References adchpp::Client::create().

Referenced by ClientManager().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t adchpp::ClientManager::makeSID (  )  [private]

Definition at line 131 of file ClientManager.cpp.

References adchpp::Encoder::base32Alphabet, entities, and adchpp::Util::rand().

Referenced by createBot().

Here is the call graph for this function:

Here is the caller graph for this function:

void adchpp::ClientManager::maybeSend ( Entity c,
const AdcCommand cmd 
) [private]

Definition at line 96 of file ClientManager.cpp.

References adchpp::Entity::send(), and signalSend_.

Here is the call graph for this function:

template<typename T>
static void adchpp::Singleton< T >::newInstance (  )  [inline, static, inherited]

Definition at line 42 of file Singleton.h.

void adchpp::ClientManager::onBadLine ( Client c,
const std::string &  aLine 
) throw () [private]

Definition at line 184 of file ClientManager.cpp.

References c.

void adchpp::ClientManager::onConnected ( Client c  )  throw () [private]
void adchpp::ClientManager::onFailed ( Client c,
const boost::system::error_code &  e 
) throw () [private]

Definition at line 543 of file ClientManager.cpp.

References c, dcdebug, adchpp::AdcCommand::fromSID(), and adchpp::Entity::getSID().

Here is the call graph for this function:

void adchpp::ClientManager::onReceive ( Entity c,
AdcCommand cmd 
) throw () [private]
void adchpp::ClientManager::regBot ( Bot bot  ) 

Definition at line 54 of file ClientManager.cpp.

References cids, enterIdentify(), enterNormal(), adchpp::Entity::getCID(), adchpp::Entity::getField(), and nicks.

Here is the call graph for this function:

void adchpp::ClientManager::removeEntity ( Entity c  )  throw () [private]
void adchpp::ClientManager::removeLogins ( Entity c  )  throw () [private]

Definition at line 490 of file ClientManager.cpp.

References c.

void adchpp::ClientManager::send ( const AdcCommand cmd  )  throw ()
void adchpp::ClientManager::sendTo ( const BufferPtr buffer,
uint32_t  to 
)

Send buffer to a single client regardless of type.

Definition at line 120 of file ClientManager.cpp.

References entities.

void adchpp::ClientManager::sendToAll ( const BufferPtr buffer  )  throw ()

Send a buffer to all connected entities.

Definition at line 104 of file ClientManager.cpp.

void adchpp::ClientManager::setLoginTimeout ( uint32_t  millis  )  [inline]

Definition at line 154 of file ClientManager.h.

References loginTimeout.

void adchpp::ClientManager::setState ( Entity c,
Entity::State  newState 
) throw ()

Update the state of c (this fires signalState as well).

Definition at line 428 of file ClientManager.cpp.

References c, adchpp::Entity::getState(), and adchpp::Entity::setState().

Here is the call graph for this function:

SignalBadLine::Signal& adchpp::ClientManager::signalBadLine (  )  [inline]

Definition at line 149 of file ClientManager.h.

References signalBadLine_.

SignalConnected::Signal& adchpp::ClientManager::signalConnected (  )  [inline]

Definition at line 147 of file ClientManager.h.

References signalConnected_.

SignalDisconnected::Signal& adchpp::ClientManager::signalDisconnected (  )  [inline]

Definition at line 152 of file ClientManager.h.

References signalDisconnected_.

SignalReceive::Signal& adchpp::ClientManager::signalReceive (  )  [inline]

Definition at line 148 of file ClientManager.h.

References signalReceive_.

SignalSend::Signal& adchpp::ClientManager::signalSend (  )  [inline]

Definition at line 150 of file ClientManager.h.

References signalSend_.

SignalState::Signal& adchpp::ClientManager::signalState (  )  [inline]

Definition at line 151 of file ClientManager.h.

References signalState_.

bool adchpp::ClientManager::verifyCID ( Entity c,
AdcCommand cmd 
) throw ()
bool adchpp::ClientManager::verifyINF ( Entity c,
AdcCommand cmd 
) throw ()

Do all INF verifications and update client data.

Call if you stop INF but still want the default processing.

Definition at line 236 of file ClientManager.cpp.

References c, adchpp::Client::disconnect(), adchpp::AdcCommand::ERROR_PROTOCOL_GENERIC, adchpp::Util::REASON_INVALID_DESCRIPTION, adchpp::Client::send(), adchpp::AdcCommand::SEV_FATAL, adchpp::Entity::updateFields(), and adchpp::Util::validateCharset().

Here is the call graph for this function:

bool adchpp::ClientManager::verifyIp ( Client c,
AdcCommand cmd 
) throw ()
bool adchpp::ClientManager::verifyNick ( Entity c,
const AdcCommand cmd 
) throw ()
bool adchpp::ClientManager::verifyOverflow ( Entity c  ) 

Verify that there aren't too many sockets overflowing (indicates lack of bandwidth).

Definition at line 275 of file ClientManager.cpp.

References adchpp::Entity::disconnect(), entities, adchpp::AdcCommand::ERROR_HUB_FULL, adchpp::Util::REASON_NO_BANDWIDTH, adchpp::Entity::send(), and adchpp::AdcCommand::SEV_FATAL.

Here is the call graph for this function:

bool adchpp::ClientManager::verifyPassword ( Entity c,
const std::string &  password,
const ByteVector salt,
const std::string &  suppliedHash 
)

Verify password.

Definition at line 261 of file ClientManager.cpp.

References adchpp::TigerHash::BYTES, adchpp::TigerHash::finalize(), adchpp::Encoder::fromBase32(), and adchpp::TigerHash::update().

Here is the call graph for this function:

bool adchpp::ClientManager::verifySUP ( Entity c,
AdcCommand cmd 
) throw ()

Do all SUP verifications and update client data.

Call if you stop SUP but still want the default processing.

Definition at line 216 of file ClientManager.cpp.

References c, adchpp::Client::disconnect(), adchpp::AdcCommand::ERROR_PROTOCOL_GENERIC, adchpp::Entity::hasSupport(), adchpp::Util::REASON_NO_BASE_SUPPORT, adchpp::Util::REASON_NO_TIGR_SUPPORT, adchpp::Client::send(), adchpp::AdcCommand::SEV_FATAL, adchpp::AdcCommand::toFourCC(), and adchpp::Entity::updateSupports().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Bot [friend]

Definition at line 160 of file ClientManager.h.

Referenced by createBot().

friend class Client [friend]

Definition at line 158 of file ClientManager.h.

friend class CommandHandler< ClientManager > [friend]

Definition at line 182 of file ClientManager.h.

friend class Entity [friend]

Definition at line 159 of file ClientManager.h.

friend class Singleton< ClientManager > [friend]

Definition at line 179 of file ClientManager.h.


Member Data Documentation

Definition at line 168 of file ClientManager.h.

Referenced by regBot().

const string adchpp::ClientManager::className = "ClientManager" [static, private]

Definition at line 177 of file ClientManager.h.

Definition at line 164 of file ClientManager.h.

Referenced by getEntities(), getQueuedBytes(), makeSID(), sendTo(), and verifyOverflow().

Definition at line 170 of file ClientManager.h.

Referenced by ClientManager().

Definition at line 180 of file ClientManager.h.

std::list<std::pair<Client*, uint32_t> > adchpp::ClientManager::logins [private]

Definition at line 162 of file ClientManager.h.

Definition at line 172 of file ClientManager.h.

Referenced by getLoginTimeout(), and setLoginTimeout().

Definition at line 166 of file ClientManager.h.

Referenced by regBot().

Definition at line 208 of file ClientManager.h.

Referenced by signalBadLine().

Definition at line 206 of file ClientManager.h.

Referenced by signalConnected().

Definition at line 211 of file ClientManager.h.

Referenced by signalDisconnected().

Definition at line 207 of file ClientManager.h.

Referenced by signalReceive().

Definition at line 209 of file ClientManager.h.

Referenced by maybeSend(), and signalSend().

Definition at line 210 of file ClientManager.h.

Referenced by signalState().

std::string adchpp::ClientManager::strtmp [private]

Definition at line 175 of file ClientManager.h.

Generated on Sat Nov 27 23:38:38 2010 for adchpp by  doxygen 1.6.3