本文整理汇总了C++中LocalUser类的典型用法代码示例。如果您正苦于以下问题:C++ LocalUser类的具体用法?C++ LocalUser怎么用?C++ LocalUser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: layer
void ContactsRpcOperation::runGetContacts()
{
TLContactsContacts result;
result.tlType = TLValue::ContactsContacts;
LocalUser *self = layer()->getUser();
const QVector<UserContact> importedContacts = self->importedContacts();
result.contacts.reserve(importedContacts.size());
result.users.reserve(importedContacts.size());
TLUser userInfo;
TLContact outputContact;
for (const UserContact &contact : importedContacts) {
if (contact.id) {
const AbstractUser *contactUser = api()->getAbstractUser(contact.id);
Utils::setupTLUser(&userInfo, contactUser, self);
result.users.append(userInfo);
outputContact.userId = contact.id;
outputContact.mutual = userInfo.flags & TLUser::MutualContact;
result.contacts.append(outputContact);
} else {
++result.savedCount;
}
}
sendRpcReply(result);
}
示例2: qDebug
void ContactsRpcOperation::runImportContacts()
{
qDebug() << Q_FUNC_INFO;
TLContactsImportedContacts result;
LocalUser *self = layer()->getUser();
for (const TLInputContact &c : m_importContacts.contacts) {
UserContact contact;
contact.phone = api()->normalizeIdentifier(c.phone);
contact.firstName = c.firstName;
contact.lastName = c.lastName;
AbstractUser *registeredUser = api()->getAbstractUser(contact.phone);
if (registeredUser) {
contact.id = registeredUser->id();
} else {
result.retryContacts.append(c.clientId);
}
self->importContact(contact);
if (registeredUser) {
result.users.append(TLUser());
Utils::setupTLUser(&result.users.last(), registeredUser, self);
TLImportedContact imported;
imported.clientId = c.clientId;
imported.userId = contact.id;
result.imported.append(imported);
}
}
sendRpcReply(result);
}
示例3: Handle
CmdResult Handle (const std::vector<std::string> ¶meters, User *src)
{
std::map<std::string,int> closed;
for (LocalUserList::const_iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); ++u)
{
LocalUser* user = *u;
if (user->registered != REG_ALL)
{
ServerInstance->Users->QuitUser(user, "Closing all unknown connections per request");
std::string key = ConvToStr(user->GetIPString())+"."+ConvToStr(user->GetServerPort());
closed[key]++;
}
}
int total = 0;
for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
{
src->WriteNotice("*** Closed " + ConvToStr(ci->second) + " unknown " + (ci->second == 1 ? "connection" : "connections") +
" from [" + ci->first + "]");
total += ci->second;
}
if (total)
src->WriteNotice("*** " + ConvToStr(total) + " unknown " + (total == 1 ? "connection" : "connections") + " closed");
else
src->WriteNotice("*** No unknown connections found");
return CMD_SUCCESS;
}
示例4: SendAlert
void SendAlert(unsigned int numeric, const std::string& nick)
{
const IRCv3::Monitor::WatcherList* list = manager.GetWatcherList(nick);
if (!list)
return;
for (IRCv3::Monitor::WatcherList::const_iterator i = list->begin(); i != list->end(); ++i)
{
LocalUser* curr = *i;
curr->WriteNumeric(numeric, nick);
}
}
示例5: Handle
CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
{
User* u = ServerInstance->FindNick(parameters[0]);
Channel* c = ServerInstance->FindChan(parameters[1]);
if ((!c) || (!u) || (u->registered != REG_ALL))
{
if (!c)
{
user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[1].c_str());
}
else
{
user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
}
return CMD_FAILURE;
}
if (IS_LOCAL(user))
{
if (c->GetPrefixValue(user) < HALFOP_VALUE)
{
user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator", user->nick.c_str(), c->name.c_str(), c->GetPrefixValue(u) == HALFOP_VALUE ? "" : "half-");
return CMD_FAILURE;
}
}
/* Servers remember invites only for their local users, so act
* only if the target is local. Otherwise the command will be
* passed to the target users server.
*/
LocalUser* lu = IS_LOCAL(u);
if (lu)
{
irc::string xname(c->name.c_str());
if (!lu->IsInvited(xname))
{
user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server.c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str());
return CMD_FAILURE;
}
user->SendText(":%s 494 %s %s %s :Uninvited", user->server.c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str());
lu->RemoveInvite(xname);
lu->WriteNumeric(493, "%s :You were uninvited from %s by %s", u->nick.c_str(), c->name.c_str(), user->nick.c_str());
std::string msg = "*** " + user->nick + " uninvited " + u->nick + ".";
c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE " + c->name + " :" + msg);
ServerInstance->PI->SendChannelNotice(c, 0, msg);
}
return CMD_SUCCESS;
}
示例6: SendAlert
void SendAlert(User* user, const std::string& nick, unsigned int numeric, const char* numerictext, time_t shownts)
{
const IRCv3::Monitor::WatcherList* list = manager.GetWatcherList(nick);
if (!list)
return;
Numeric::Numeric num(numeric);
num.push(nick).push(user->ident).push(user->GetDisplayedHost()).push(ConvToStr(shownts)).push(numerictext);
for (IRCv3::Monitor::WatcherList::const_iterator i = list->begin(); i != list->end(); ++i)
{
LocalUser* curr = *i;
curr->WriteNumeric(num);
}
}
示例7: snprintf
void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
{
char tb1[MAXBUF];
char tb2[MAXBUF];
if (this->registered != REG_ALL)
return;
already_sent_t uniq_id = ++LocalUser::already_sent_id;
snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
std::string out1 = tb1;
std::string out2 = tb2;
UserChanList include_c(chans);
std::map<User*,bool> exceptions;
FOREACH_MOD(I_OnBuildNeighborList,OnBuildNeighborList(this, include_c, exceptions));
for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
{
LocalUser* u = IS_LOCAL(i->first);
if (u && !u->quitting)
{
u->already_sent = uniq_id;
if (i->second)
u->Write(IS_OPER(u) ? out2 : out1);
}
}
for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
{
const UserMembList* ulist = (*v)->GetUsers();
for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
{
LocalUser* u = IS_LOCAL(i->first);
if (u && !u->quitting && (u->already_sent != uniq_id))
{
u->already_sent = uniq_id;
u->Write(IS_OPER(u) ? out2 : out1);
}
}
}
}
示例8: HandleServerTarget
CmdResult HandleServerTarget(User* source, const Params& parameters)
{
// If the source isn't allowed to mass message users then reject
// the attempt to mass-message users.
if (!source->HasPrivPermission("users/mass-message"))
return CMD_FAILURE;
// Extract the server glob match from the target parameter.
std::string servername(parameters[0], 1);
// Fire the pre-message events.
MessageTarget msgtarget(&servername);
CTCTags::TagMessageDetails msgdetails(parameters.GetTags());
if (!FirePreEvents(source, msgtarget, msgdetails))
return CMD_FAILURE;
// If the current server name matches the server name glob then send
// the message out to the local users.
if (InspIRCd::Match(ServerInstance->Config->ServerName, servername))
{
CTCTags::TagMessage message(source, "$*", parameters.GetTags());
const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
for (UserManager::LocalList::const_iterator iter = list.begin(); iter != list.end(); ++iter)
{
LocalUser* luser = IS_LOCAL(*iter);
// Don't send to unregistered users or the user who is the source.
if (luser->registered != REG_ALL || luser == source)
continue;
// Don't send to exempt users.
if (msgdetails.exemptions.count(luser))
continue;
// Send to users if they have the capability.
if (cap.get(luser))
luser->Send(msgevprov, message);
}
}
// Fire the post-message event.
return FirePostEvent(source, msgtarget, msgdetails);
}
示例9: GenerateStatsLl
static void GenerateStatsLl(User* user, string_list& results, char c)
{
results.push_back(InspIRCd::Format("211 %s nick[[email protected]%s] sendq cmds_out bytes_out cmds_in bytes_in time_open", user->nick.c_str(), (c == 'l' ? "host" : "ip")));
const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
{
LocalUser* u = *i;
results.push_back("211 "+user->nick+" "+u->nick+"["+u->ident+"@"+(c == 'l' ? u->dhost : u->GetIPString())+"] "+ConvToStr(u->eh.getSendQSize())+" "+ConvToStr(u->cmds_out)+" "+ConvToStr(u->bytes_out)+" "+ConvToStr(u->cmds_in)+" "+ConvToStr(u->bytes_in)+" "+ConvToStr(ServerInstance->Time() - u->age));
}
}
示例10: FOREACH_MOD
void User::Oper(OperInfo* info)
{
ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
if (this->IsModeSet(opermh))
this->UnOper();
this->SetMode(opermh, true);
this->oper = info;
this->WriteCommand("MODE", "+o");
FOREACH_MOD(OnOper, (this, info->name));
std::string opername;
if (info->oper_block)
opername = info->oper_block->getString("name");
if (IS_LOCAL(this))
{
LocalUser* l = IS_LOCAL(this);
std::string vhost = oper->getConfig("vhost");
if (!vhost.empty())
l->ChangeDisplayedHost(vhost.c_str());
std::string opClass = oper->getConfig("class");
if (!opClass.empty())
l->SetClass(opClass);
}
ServerInstance->SNO->WriteToSnoMask('o',"%s (%[email protected]%s) is now an IRC operator of type %s (using oper '%s')",
nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str());
this->WriteNumeric(RPL_YOUAREOPER, ":You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str());
ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str());
ServerInstance->Users->all_opers.push_back(this);
// Expand permissions from config for faster lookup
if (IS_LOCAL(this))
oper->init();
FOREACH_MOD(OnPostOper, (this, oper->name, opername));
}
示例11: include_c
void User::WriteCommonRaw(const std::string &line, bool include_self)
{
if (this->registered != REG_ALL || quitting)
return;
LocalUser::already_sent_id++;
IncludeChanList include_c(chans.begin(), chans.end());
std::map<User*,bool> exceptions;
exceptions[this] = include_self;
FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
{
LocalUser* u = IS_LOCAL(i->first);
if (u && !u->quitting)
{
u->already_sent = LocalUser::already_sent_id;
if (i->second)
u->Write(line);
}
}
for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v)
{
Channel* c = (*v)->chan;
const UserMembList* ulist = c->GetUsers();
for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
{
LocalUser* u = IS_LOCAL(i->first);
if (u && u->already_sent != LocalUser::already_sent_id)
{
u->already_sent = LocalUser::already_sent_id;
u->Write(line);
}
}
}
}
示例12: FOREACH_MOD
void User::Oper(OperInfo* info)
{
if (this->IsModeSet('o'))
this->UnOper();
this->modes[UM_OPERATOR] = 1;
this->oper = info;
this->WriteServ("MODE %s :+o", this->nick.c_str());
FOREACH_MOD(I_OnOper, OnOper(this, info->name));
std::string opername;
if (info->oper_block)
opername = info->oper_block->getString("name");
if (IS_LOCAL(this))
{
LocalUser* l = IS_LOCAL(this);
std::string vhost = oper->getConfig("vhost");
if (!vhost.empty())
l->ChangeDisplayedHost(vhost.c_str());
std::string opClass = oper->getConfig("class");
if (!opClass.empty())
l->SetClass(opClass);
}
ServerInstance->SNO->WriteToSnoMask('o',"%s (%[email protected]%s) is now an IRC operator of type %s (using oper '%s')",
nick.c_str(), ident.c_str(), host.c_str(), oper->NameStr(), opername.c_str());
this->WriteNumeric(381, "%s :You are now %s %s", nick.c_str(), strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->NameStr());
ServerInstance->Logs->Log("OPER", DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->NameStr());
ServerInstance->Users->all_opers.push_back(this);
// Expand permissions from config for faster lookup
if (IS_LOCAL(this))
oper->init();
FOREACH_MOD(I_OnPostOper,OnPostOper(this, oper->name, opername));
}
示例13: OnModeChange
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
LocalUser* user = IS_LOCAL(dest);
/* For remote clients, we don't take any action, we just allow it.
* The local server where they are will set their cloak instead.
* This is fine, as we will receive it later.
*/
if (!user)
{
dest->SetMode(this, adding);
return MODEACTION_ALLOW;
}
if (user->uuid == debounce_uid && debounce_ts == ServerInstance->Time())
{
// prevent spamming using /mode user +x-x+x-x+x-x
if (++debounce_count > 2)
return MODEACTION_DENY;
}
else
{
debounce_uid = user->uuid;
debounce_count = 1;
debounce_ts = ServerInstance->Time();
}
if (adding == user->IsModeSet(this))
return MODEACTION_DENY;
/* don't allow this user to spam modechanges */
if (source == dest)
user->CommandFloodPenalty += 5000;
if (adding)
{
std::string* cloak = ext.get(user);
if (!cloak)
{
/* Force creation of missing cloak */
creator->OnUserConnect(user);
cloak = ext.get(user);
}
if (cloak)
{
user->ChangeDisplayedHost(*cloak);
user->SetMode(this, true);
return MODEACTION_ALLOW;
}
else
return MODEACTION_DENY;
}
else
{
/* User is removing the mode, so restore their real host
* and make it match the displayed one.
*/
user->SetMode(this, false);
user->ChangeDisplayedHost(user->host.c_str());
return MODEACTION_ALLOW;
}
}
示例14: LocalUser
/* add a client connection to the sockets list */
void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
{
/* NOTE: Calling this one parameter constructor for User automatically
* allocates a new UUID and places it in the hash_map.
*/
LocalUser* New = NULL;
try
{
New = new LocalUser(socket, client, server);
}
catch (...)
{
ServerInstance->Logs->Log("USERS", DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkeys have been unleashed.");
ServerInstance->SNO->WriteToSnoMask('a', "WARNING *** Duplicate UUID allocated!");
return;
}
UserIOHandler* eh = &New->eh;
/* Give each of the modules an attempt to hook the user for I/O */
FOREACH_MOD(I_OnHookIO, OnHookIO(eh, via));
if (eh->GetIOHook())
{
try
{
eh->GetIOHook()->OnStreamSocketAccept(eh, client, server);
}
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
ServerInstance->Logs->Log("USERS", DEBUG,"New user fd: %d", socket);
this->unregistered_count++;
/* The users default nick is their UUID */
New->nick.assign(New->uuid, 0, ServerInstance->Config->Limits.NickMax);
(*(this->clientlist))[New->nick] = New;
New->registered = REG_NONE;
New->signon = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
New->lastping = 1;
ServerInstance->Users->AddLocalClone(New);
ServerInstance->Users->AddGlobalClone(New);
New->localuseriter = this->local_users.insert(local_users.end(), New);
if ((this->local_users.size() > ServerInstance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)ServerInstance->SE->GetMaxFds()))
{
ServerInstance->SNO->WriteToSnoMask('a', "Warning: softlimit value has been reached: %d clients", ServerInstance->Config->SoftLimit);
this->QuitUser(New,"No more connections allowed");
return;
}
/*
* First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
* See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
*/
New->SetClass();
/*
* Check connect class settings and initialise settings into User.
* This will be done again after DNS resolution. -- w00t
*/
New->CheckClass();
if (New->quitting)
return;
/*
* even with bancache, we still have to keep User::exempt current.
* besides that, if we get a positive bancache hit, we still won't fuck
* them over if they are exempt. -- w00t
*/
New->exempt = (ServerInstance->XLines->MatchesLine("E",New) != NULL);
if (BanCacheHit *b = ServerInstance->BanCache->GetHit(New->GetIPString()))
{
if (!b->Type.empty() && !New->exempt)
{
/* user banned */
ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Positive hit for " + New->GetIPString());
if (!ServerInstance->Config->MoronBanner.empty())
New->WriteServ("NOTICE %s :*** %s", New->nick.c_str(), ServerInstance->Config->MoronBanner.c_str());
this->QuitUser(New, b->Reason);
return;
}
else
{
ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCache: Negative hit for " + New->GetIPString());
}
}
else
{
if (!New->exempt)
{
XLine* r = ServerInstance->XLines->MatchesLine("Z",New);
//.........这里部分代码省略.........
示例15: HandleChannelTarget
CmdResult HandleChannelTarget(User* source, const Params& parameters, const char* target, PrefixMode* pm)
{
Channel* chan = ServerInstance->FindChan(target);
if (!chan)
{
// The target channel does not exist.
source->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
return CMD_FAILURE;
}
if (IS_LOCAL(source))
{
if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(source))
{
// The noextmsg mode is set and the source is not in the channel.
source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
return CMD_FAILURE;
}
bool no_chan_priv = chan->GetPrefixValue(source) < VOICE_VALUE;
if (no_chan_priv && chan->IsModeSet(moderatedmode))
{
// The moderated mode is set and the source has no status rank.
source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m)");
return CMD_FAILURE;
}
if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(source))
{
// The source is banned in the channel and restrictbannedusers is enabled.
if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
return CMD_FAILURE;
}
}
// Fire the pre-message events.
MessageTarget msgtarget(chan, pm ? pm->GetPrefix() : 0);
CTCTags::TagMessageDetails msgdetails(parameters.GetTags());
if (!FirePreEvents(source, msgtarget, msgdetails))
return CMD_FAILURE;
unsigned int minrank = pm ? pm->GetPrefixRank() : 0;
CTCTags::TagMessage message(source, chan, parameters.GetTags());
const Channel::MemberMap& userlist = chan->GetUsers();
for (Channel::MemberMap::const_iterator iter = userlist.begin(); iter != userlist.end(); ++iter)
{
LocalUser* luser = IS_LOCAL(iter->first);
// Don't send to remote users or the user who is the source.
if (!luser || luser == source)
continue;
// Don't send to unprivileged or exempt users.
if (iter->second->getRank() < minrank || msgdetails.exemptions.count(luser))
continue;
// Send to users if they have the capability.
if (cap.get(luser))
luser->Send(msgevprov, message);
}
return FirePostEvent(source, msgtarget, msgdetails);
}