The client represents one connection to a user. More...
#include <Client.h>
Public Types | |
typedef std::function< void(Client &, const uint8_t *, size_t) | DataFunction ) |
Set data mode for aBytes bytes. | |
enum | Flag { FLAG_BOT = 0x01, FLAG_REGISTERED = 0x02, FLAG_OP = 0x04, FLAG_SU = 0x08, FLAG_OWNER = 0x10, FLAG_HUB = 0x20, FLAG_HIDDEN = 0x40, MASK_CLIENT_TYPE = FLAG_BOT | FLAG_REGISTERED | FLAG_OP | FLAG_SU | FLAG_OWNER | FLAG_HUB | FLAG_HIDDEN, FLAG_PASSWORD = 0x100, FLAG_EXT_AWAY = 0x200, FLAG_OK_IP = 0x400, FLAG_GHOST = 0x800 } |
enum | State { STATE_PROTOCOL, STATE_IDENTIFY, STATE_VERIFY, STATE_NORMAL, STATE_DATA } |
Public Member Functions | |
ADCHPP_DLL bool | addSupports (uint32_t feature) |
ADCHPP_DLL void | clearPluginData (const PluginDataHandle &handle) throw () |
Clear any data referenced by the handle, calling the registered delete function. | |
virtual ADCHPP_DLL void | disconnect (Util::Reason reason) throw () |
ADCHPP_DLL bool | getAllFields (AdcCommand &cmd) const throw () |
Add any flags that have been updated to the AdcCommand (type etc is not set). | |
const CID & | getCID () const |
ADCHPP_DLL const std::string & | getField (const char *name) const |
ADCHPP_DLL const BufferPtr & | getINF () const |
const std::string & | getIp () const throw () |
size_t | getMaxCommandSize () |
virtual time_t | getOverflow () const |
The time that this entity's write buffer size exceeded the maximum buffer size, 0 if no overflow. | |
ADCHPP_DLL void * | getPluginData (const PluginDataHandle &handle) const throw () |
virtual size_t | getQueuedBytes () const |
The number of bytes in the write buffer. | |
uint32_t | getSID () const |
State | getState () const |
ADCHPP_DLL const BufferPtr & | getSUP () const |
ADCHPP_DLL StringList | getSupportList () const |
ADCHPP_DLL bool | hasField (const char *name) const |
ADCHPP_DLL bool | hasSupport (uint32_t feature) const |
virtual ADCHPP_DLL void | inject (AdcCommand &cmd) |
bool | isAnySet (size_t aFlag) const |
ADCHPP_DLL bool | isFiltered (const std::string &features) const |
bool | isSet (size_t aFlag) const |
ADCHPP_DLL bool | removeSupports (uint32_t feature) |
void | send (const AdcCommand &cmd) |
virtual void | send (const BufferPtr &command) throw () |
void | setCID (const CID &cid_) |
void | setDataMode (const DataFunction &handler, int64_t aBytes) |
ADCHPP_DLL void | setField (const char *name, const std::string &value) |
ADCHPP_DLL void | setFlag (size_t aFlag) |
void | setMaxCommandSize (size_t newSize) |
ADCHPP_DLL void | setPluginData (const PluginDataHandle &handle, void *data) throw () |
Set PSD (plugin specific data). | |
void | setState (State state_) |
ADCHPP_DLL void | unsetFlag (size_t aFlag) |
ADCHPP_DLL void | updateFields (const AdcCommand &cmd) |
ADCHPP_DLL void | updateSupports (const AdcCommand &cmd) throw () |
Static Public Member Functions | |
static Client * | create (const ManagedSocketPtr &ms_, uint32_t sid_) throw () |
static size_t | getDefaultMaxCommandSize () |
static void | setDefaultMaxCommandSize (size_t newSize) |
Protected Types | |
typedef std::map < PluginDataHandle, void * > | PluginDataMap |
Protected Attributes | |
CID | cid |
FieldMap | fields |
INF fields. | |
std::vector< uint32_t > | filters |
INF SU. | |
Flags | flags |
BufferPtr | INF |
Latest INF cached. | |
PluginDataMap | pluginData |
Plugin data, see PluginManager::registerPluginData. | |
uint32_t | sid |
State | state |
BufferPtr | SUP |
Latest SUP cached. | |
std::vector< uint32_t > | supports |
SUP items. | |
Private Member Functions | |
Client (uint32_t sid_) throw () | |
void | onConnected () throw () |
void | onData (const BufferPtr &) throw () |
void | onFailed (const boost::system::error_code &ec) throw () |
void | setSocket (const ManagedSocketPtr &aSocket) throw () |
virtual | ~Client () |
Private Attributes | |
BufferPtr | buffer |
int64_t | dataBytes |
DataFunction | dataHandler |
bool | disconnecting |
size_t | maxCommandSize |
ManagedSocketPtr | socket |
Static Private Attributes | |
static size_t | defaultMaxCommandSize = 16 * 1024 |
The client represents one connection to a user.
Definition at line 35 of file Client.h.
typedef std::function<void (Client&, const uint8_t*, size_t) adchpp::Client::DataFunction) |
typedef std::map<PluginDataHandle, void*> adchpp::Entity::PluginDataMap [protected, inherited] |
enum adchpp::Entity::Flag [inherited] |
enum adchpp::Entity::State [inherited] |
adchpp::Client::Client | ( | uint32_t | sid_ | ) | throw () [private] |
Definition at line 38 of file Client.cpp.
adchpp::Client::~Client | ( | ) | [private, virtual] |
Definition at line 42 of file Client.cpp.
bool adchpp::Entity::addSupports | ( | uint32_t | feature | ) | [inherited] |
Definition at line 93 of file Entity.cpp.
References adchpp::Entity::SUP, and adchpp::Entity::supports.
Referenced by adchpp::ClientManager::ClientManager().
void adchpp::Entity::clearPluginData | ( | const PluginDataHandle & | handle | ) | throw () [inherited] |
Clear any data referenced by the handle, calling the registered delete function.
Definition at line 186 of file Entity.cpp.
Client * adchpp::Client::create | ( | const ManagedSocketPtr & | ms_, | |
uint32_t | sid_ | |||
) | throw () [static] |
Definition at line 32 of file Client.cpp.
References c, ms, and setSocket().
Referenced by adchpp::ClientManager::handleIncoming().
void adchpp::Client::disconnect | ( | Util::Reason | reason | ) | throw () [virtual] |
reason | The statistic to update |
Implements adchpp::Entity.
Definition at line 149 of file Client.cpp.
Referenced by adchpp::ClientManager::badState(), adchpp::ClientManager::onConnected(), adchpp::ClientManager::onReceive(), adchpp::ClientManager::verifyCID(), adchpp::ClientManager::verifyINF(), adchpp::ClientManager::verifyIp(), adchpp::ClientManager::verifyNick(), and adchpp::ClientManager::verifySUP().
bool adchpp::Entity::getAllFields | ( | AdcCommand & | cmd | ) | const throw () [inherited] |
Add any flags that have been updated to the AdcCommand (type etc is not set).
Definition at line 69 of file Entity.cpp.
References adchpp::AdcCommand::fromField().
Referenced by adchpp::Entity::getINF().
const CID& adchpp::Entity::getCID | ( | ) | const [inline, inherited] |
Definition at line 119 of file Entity.h.
Referenced by adchpp::ClientManager::regBot(), adchpp::ClientManager::removeEntity(), and adchpp::ClientManager::verifyCID().
static size_t adchpp::Client::getDefaultMaxCommandSize | ( | ) | [inline, static] |
const std::string & adchpp::Entity::getField | ( | const char * | name | ) | const [inherited] |
Definition at line 37 of file Entity.cpp.
References adchpp::Util::emptyString, adchpp::Entity::fields, and adchpp::AdcCommand::toField().
Referenced by adchpp::ClientManager::regBot(), adchpp::ClientManager::removeEntity(), and adchpp::ClientManager::verifyNick().
const BufferPtr & adchpp::Entity::getINF | ( | ) | const [inherited] |
Definition at line 84 of file Entity.cpp.
References adchpp::Entity::getAllFields(), adchpp::AdcCommand::getBuffer(), adchpp::Entity::getSID(), adchpp::AdcCommand::HUB_SID, adchpp::Entity::INF, adchpp::AdcCommand::TYPE_BROADCAST, and adchpp::AdcCommand::TYPE_INFO.
Referenced by adchpp::ClientManager::enterNormal().
const std::string& adchpp::Client::getIp | ( | ) | const throw () [inline] |
Definition at line 45 of file Client.h.
Referenced by adchpp::ClientManager::verifyIp().
virtual time_t adchpp::Client::getOverflow | ( | ) | const [inline, virtual] |
The time that this entity's write buffer size exceeded the maximum buffer size, 0 if no overflow.
Reimplemented from adchpp::Entity.
void * adchpp::Entity::getPluginData | ( | const PluginDataHandle & | handle | ) | const throw () [inherited] |
handle | Plugin data handle, as returned by PluginManager::registerPluginData |
Definition at line 181 of file Entity.cpp.
virtual size_t adchpp::Client::getQueuedBytes | ( | ) | const [inline, virtual] |
The number of bytes in the write buffer.
Reimplemented from adchpp::Entity.
uint32_t adchpp::Entity::getSID | ( | ) | const [inline, inherited] |
Definition at line 91 of file Entity.h.
Referenced by adchpp::ClientManager::enterIdentify(), adchpp::ClientManager::enterNormal(), adchpp::ClientManager::enterVerify(), adchpp::Entity::getINF(), adchpp::Entity::getSUP(), adchpp::ClientManager::onConnected(), adchpp::ClientManager::onFailed(), adchpp::ClientManager::removeEntity(), adchpp::ClientManager::verifyCID(), adchpp::ClientManager::verifyIp(), and adchpp::ClientManager::verifyNick().
State adchpp::Entity::getState | ( | ) | const [inline, inherited] |
Definition at line 122 of file Entity.h.
Referenced by adchpp::ClientManager::enterIdentify(), adchpp::ClientManager::enterNormal(), adchpp::ClientManager::enterVerify(), adchpp::ClientManager::handle(), adchpp::ClientManager::handleDefault(), adchpp::ClientManager::onConnected(), adchpp::PluginManager::CommandDispatch::operator()(), adchpp::ClientManager::removeEntity(), adchpp::ClientManager::setState(), adchpp::ClientManager::verifyCID(), and adchpp::ClientManager::verifyIp().
const BufferPtr & adchpp::Entity::getSUP | ( | ) | const [inherited] |
Definition at line 127 of file Entity.cpp.
References adchpp::AdcCommand::addParam(), adchpp::AdcCommand::fromFourCC(), adchpp::AdcCommand::getBuffer(), adchpp::Entity::getSID(), adchpp::AdcCommand::HUB_SID, adchpp::Entity::SUP, adchpp::Entity::supports, adchpp::AdcCommand::TYPE_BROADCAST, and adchpp::AdcCommand::TYPE_INFO.
StringList adchpp::Entity::getSupportList | ( | ) | const [inherited] |
Definition at line 105 of file Entity.cpp.
References adchpp::AdcCommand::fromFourCC(), and adchpp::Entity::supports.
bool adchpp::Entity::hasField | ( | const char * | name | ) | const [inherited] |
Definition at line 42 of file Entity.cpp.
References adchpp::Entity::fields, and adchpp::AdcCommand::toField().
Referenced by adchpp::ClientManager::verifyIp().
bool adchpp::Entity::hasSupport | ( | uint32_t | feature | ) | const [inherited] |
Definition at line 138 of file Entity.cpp.
References adchpp::Entity::supports.
Referenced by adchpp::ClientManager::verifySUP().
void adchpp::Entity::inject | ( | AdcCommand & | cmd | ) | [virtual, inherited] |
Definition at line 33 of file Entity.cpp.
References adchpp::Singleton< T >::getInstance().
bool adchpp::Entity::isAnySet | ( | size_t | aFlag | ) | const [inline, inherited] |
bool adchpp::Entity::isFiltered | ( | const std::string & | features | ) | const [inherited] |
Definition at line 157 of file Entity.cpp.
References adchpp::Entity::filters, and adchpp::AdcCommand::toFourCC().
bool adchpp::Entity::isSet | ( | size_t | aFlag | ) | const [inline, inherited] |
Definition at line 125 of file Entity.h.
Referenced by adchpp::ClientManager::removeEntity(), and adchpp::ClientManager::verifyIp().
void adchpp::Client::onConnected | ( | ) | throw () [private] |
Definition at line 78 of file Client.cpp.
void adchpp::Client::onData | ( | const BufferPtr & | buf | ) | throw () [private] |
Definition at line 82 of file Client.cpp.
void adchpp::Client::onFailed | ( | const boost::system::error_code & | ec | ) | throw () [private] |
Definition at line 167 of file Client.cpp.
bool adchpp::Entity::removeSupports | ( | uint32_t | feature | ) | [inherited] |
Definition at line 114 of file Entity.cpp.
References adchpp::Entity::SUP, and adchpp::Entity::supports.
void adchpp::Entity::send | ( | const AdcCommand & | cmd | ) | [inline, inherited] |
Definition at line 71 of file Entity.h.
References adchpp::AdcCommand::getBuffer(), and adchpp::Entity::send().
Referenced by adchpp::ClientManager::maybeSend(), adchpp::Entity::send(), adchpp::ClientManager::verifyCID(), and adchpp::ClientManager::verifyOverflow().
virtual void adchpp::Client::send | ( | const BufferPtr & | command | ) | throw () [inline, virtual] |
Implements adchpp::Entity.
Definition at line 41 of file Client.h.
Referenced by adchpp::ClientManager::badState(), adchpp::ClientManager::enterIdentify(), adchpp::ClientManager::enterNormal(), adchpp::ClientManager::enterVerify(), adchpp::ClientManager::onReceive(), adchpp::ClientManager::verifyCID(), adchpp::ClientManager::verifyINF(), adchpp::ClientManager::verifyIp(), adchpp::ClientManager::verifyNick(), and adchpp::ClientManager::verifySUP().
void adchpp::Entity::setCID | ( | const CID & | cid_ | ) | [inline, inherited] |
Definition at line 120 of file Entity.h.
Referenced by adchpp::Bot::Bot(), and adchpp::ClientManager::verifyCID().
void adchpp::Client::setDataMode | ( | const DataFunction & | handler, | |
int64_t | aBytes | |||
) | [inline] |
static void adchpp::Client::setDefaultMaxCommandSize | ( | size_t | newSize | ) | [inline, static] |
void adchpp::Entity::setField | ( | const char * | name, | |
const std::string & | value | |||
) | [inherited] |
Definition at line 46 of file Entity.cpp.
References adchpp::Entity::fields, adchpp::Entity::filters, adchpp::Entity::INF, adchpp::AdcCommand::toField(), and adchpp::AdcCommand::toFourCC().
Referenced by adchpp::Hub::Hub(), adchpp::Entity::setFlag(), adchpp::Entity::unsetFlag(), adchpp::Entity::updateFields(), and adchpp::ClientManager::verifyIp().
void adchpp::Entity::setFlag | ( | size_t | aFlag | ) | [inherited] |
Definition at line 196 of file Entity.cpp.
References adchpp::Entity::flags, adchpp::Flags::getFlags(), adchpp::Entity::MASK_CLIENT_TYPE, adchpp::Entity::setField(), adchpp::Flags::setFlag(), and adchpp::Util::toString().
Referenced by adchpp::Bot::Bot(), adchpp::Hub::Hub(), and adchpp::ClientManager::verifyCID().
void adchpp::Client::setMaxCommandSize | ( | size_t | newSize | ) | [inline] |
void adchpp::Entity::setPluginData | ( | const PluginDataHandle & | handle, | |
void * | data | |||
) | throw () [inherited] |
Set PSD (plugin specific data).
This allows a plugin to store arbitrary per-client data, and retrieve it later on. The life cycle of the data follows that of the client unless explicitly removed. Any data referenced by the plugin will have its delete function called when the Entity is deleted.
id | Id as retrieved from PluginManager::getPluginId() | |
data | Data to store, this can be pretty much anything |
Definition at line 176 of file Entity.cpp.
void adchpp::Client::setSocket | ( | const ManagedSocketPtr & | aSocket | ) | throw () [private] |
Definition at line 70 of file Client.cpp.
Referenced by create().
void adchpp::Entity::setState | ( | State | state_ | ) | [inline, inherited] |
Definition at line 123 of file Entity.h.
Referenced by adchpp::ClientManager::setState().
void adchpp::Entity::unsetFlag | ( | size_t | aFlag | ) | [inherited] |
Definition at line 203 of file Entity.cpp.
References adchpp::Entity::flags, adchpp::Flags::getFlags(), adchpp::Entity::MASK_CLIENT_TYPE, adchpp::Entity::setField(), adchpp::Flags::setFlag(), and adchpp::Util::toString().
void adchpp::Entity::updateFields | ( | const AdcCommand & | cmd | ) | [inherited] |
Definition at line 75 of file Entity.cpp.
References dcassert, adchpp::AdcCommand::getCommand(), adchpp::AdcCommand::getParameters(), and adchpp::Entity::setField().
Referenced by adchpp::ClientManager::verifyINF().
void adchpp::Entity::updateSupports | ( | const AdcCommand & | cmd | ) | throw () [inherited] |
Definition at line 142 of file Entity.cpp.
References adchpp::AdcCommand::toFourCC().
Referenced by adchpp::ClientManager::verifySUP().
BufferPtr adchpp::Client::buffer [private] |
CID adchpp::Entity::cid [protected, inherited] |
int64_t adchpp::Client::dataBytes [private] |
DataFunction adchpp::Client::dataHandler [private] |
size_t adchpp::Client::defaultMaxCommandSize = 16 * 1024 [static, private] |
bool adchpp::Client::disconnecting [private] |
FieldMap adchpp::Entity::fields [protected, inherited] |
INF fields.
Definition at line 155 of file Entity.h.
Referenced by adchpp::Entity::getField(), adchpp::Entity::hasField(), and adchpp::Entity::setField().
std::vector<uint32_t> adchpp::Entity::filters [protected, inherited] |
INF SU.
Definition at line 152 of file Entity.h.
Referenced by adchpp::Entity::isFiltered(), and adchpp::Entity::setField().
Flags adchpp::Entity::flags [protected, inherited] |
Definition at line 145 of file Entity.h.
Referenced by adchpp::Entity::setFlag(), and adchpp::Entity::unsetFlag().
BufferPtr adchpp::Entity::INF [mutable, protected, inherited] |
Latest INF cached.
Definition at line 161 of file Entity.h.
Referenced by adchpp::Entity::getINF(), and adchpp::Entity::setField().
size_t adchpp::Client::maxCommandSize [private] |
PluginDataMap adchpp::Entity::pluginData [protected, inherited] |
Plugin data, see PluginManager::registerPluginData.
Definition at line 158 of file Entity.h.
Referenced by adchpp::Entity::~Entity().
uint32_t adchpp::Entity::sid [protected, inherited] |
ManagedSocketPtr adchpp::Client::socket [private] |
State adchpp::Entity::state [protected, inherited] |
BufferPtr adchpp::Entity::SUP [mutable, protected, inherited] |
Latest SUP cached.
Definition at line 164 of file Entity.h.
Referenced by adchpp::Entity::addSupports(), adchpp::Entity::getSUP(), and adchpp::Entity::removeSupports().
std::vector<uint32_t> adchpp::Entity::supports [protected, inherited] |
SUP items.
Definition at line 149 of file Entity.h.
Referenced by adchpp::Entity::addSupports(), adchpp::Entity::getSUP(), adchpp::Entity::getSupportList(), adchpp::Entity::hasSupport(), and adchpp::Entity::removeSupports().