本文整理汇总了C++中anope::string::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ string::c_str方法的具体用法?C++ string::c_str怎么用?C++ string::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anope::string
的用法示例。
在下文中一共展示了string::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
const Anope::string &nick = !params.empty() ? params[0] : source.GetNick();
const NickServ::Nick *na = NickServ::FindNick(nick);
spacesepstream sep(nick);
Anope::string nickbuf;
while (sep.GetToken(nickbuf))
{
#if 0
User *u2 = User::Find(nickbuf, true);
if (!u2) /* Nick is not online */
source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
else if (u2->IsIdentified() && na && na->GetAccount() == u2->Account()) /* Nick is identified */
source.Reply("STATUS %s %d %s", nickbuf.c_str(), 3, u2->Account()->GetDisplay().c_str());
else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */
source.Reply("STATUS %s %d %s", nickbuf.c_str(), 2, u2->Account() ? u2->Account()->GetDisplay().c_str() : "");
else if (!na) /* Nick is online, but NOT a registered */
source.Reply("STATUS %s %d %s", nickbuf.c_str(), 0, "");
else
/* Nick is not identified for the nick, but they could be logged into an account,
* so we tell the user about it
*/
source.Reply("STATUS %s %d %s", nickbuf.c_str(), 1, u2->Account() ? u2->Account()->GetDisplay().c_str() : "");
#endif
}
}
示例2: bot_raw_ban
/* Makes a simple ban and kicks the target
* @param requester The user requesting the kickban
* @param ci The channel
* @param u The user being kicked
* @param reason The reason
*/
void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string &reason)
{
if (!u || !ci)
return;
if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u)
{
ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, ACCESS_DENIED));
return;
}
AccessGroup u_access = ci->AccessFor(u), req_access = ci->AccessFor(requester);
if (ci->HasFlag(CI_PEACE) && u != requester && u_access >= req_access)
return;
if (matches_list(ci->c, u, CMODE_EXCEPT))
{
ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", translate(requester, _("User matches channel except.")));
return;
}
Anope::string mask;
get_idealban(ci, u, mask);
ci->c->SetMode(NULL, CMODE_BAN, mask);
/* Check if we need to do a signkick or not -GD */
if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK")))
ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str());
else
ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str());
}
示例3: Execute
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
{
User *u = source.u;
const Anope::string &nick = !params.empty() ? params[0] : u->nick;
NickAlias *na = findnick(nick);
spacesepstream sep(nick);
Anope::string nickbuf;
while (sep.GetToken(nickbuf))
{
User *u2 = finduser(nickbuf);
if (!u2) /* Nick is not online */
source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 0, "");
else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */
source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 3, u2->Account()->display.c_str());
else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */
source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : "");
else if (!na) /* Nick is online, but NOT a registered */
source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 0, "");
else
/* Nick is not identified for the nick, but they could be logged into an account,
* so we tell the user about it
*/
source.Reply(_("STATUS %s %d %s"), nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : "");
}
return;
}
示例4: Identify
void User::Identify(NickServ::Nick *na)
{
if (this->nick.equals_ci(na->GetNick()))
{
na->SetLastUsermask(this->GetIdent() + "@" + this->GetDisplayedHost());
na->SetLastRealhost(this->GetIdent() + "@" + this->host);
na->SetLastRealname(this->realname);
na->SetLastSeen(Anope::CurTime);
}
IRCD->SendLogin(this, na);
this->Login(na->GetAccount());
EventManager::Get()->Dispatch(&Event::NickIdentify::OnNickIdentify, this);
if (this->IsServicesOper())
{
Anope::string m = this->nc->o->GetType()->modes;
if (!m.empty())
{
this->SetModes(NULL, "%s", m.c_str());
this->SendMessage(Me, "Changing your usermodes to \002{0}\002", m.c_str());
UserMode *um = ModeManager::FindUserModeByName("OPER");
if (um && !this->HasMode("OPER") && m.find(um->mchar) != Anope::string::npos)
IRCD->SendOper(this);
}
if (IRCD->CanSetVHost && !this->nc->o->GetVhost().empty())
{
this->SendMessage(Me, "Changing your vhost to \002{0}\002", this->nc->o->GetVhost());
this->SetDisplayedHost(this->nc->o->GetVhost());
IRCD->SendVhost(this, "", this->nc->o->GetVhost());
}
}
}
示例5: CleanupRuntimeDirectory
void ModuleManager::CleanupRuntimeDirectory()
{
Anope::string dirbuf = services_dir + "/modules/runtime";
Log(LOG_DEBUG) << "Cleaning out Module run time directory (" << dirbuf << ") - this may take a moment please wait";
DIR *dirp = opendir(dirbuf.c_str());
if (!dirp)
{
Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")";
return;
}
for (dirent *dp; (dp = readdir(dirp));)
{
if (!dp->d_ino)
continue;
if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
continue;
Anope::string filebuf = dirbuf + "/" + dp->d_name;
unlink(filebuf.c_str());
}
closedir(dirp);
}
示例6: DoDel
void DoDel(CommandSource &source, ChannelInfo *ci, const Anope::string &message)
{
EntryMessageList *messages = ci->GetExt<EntryMessageList *>("cs_entrymsg");
if (!message.is_pos_number_only())
source.Reply(("Entry message \002%s\002 not found on channel \002%s\002."), message.c_str(), ci->name.c_str());
else if (messages != NULL)
{
try
{
unsigned i = convertTo<unsigned>(message);
if (i > 0 && i <= messages->size())
{
messages->erase(messages->begin() + i - 1);
if (messages->empty())
ci->Shrink("cs_entrymsg");
source.Reply(_("Entry message \002%i\002 for \002%s\002 deleted."), i, ci->name.c_str());
}
else
throw ConvertException();
}
catch (const ConvertException &)
{
source.Reply(_("Entry message \002%s\002 not found on channel \002%s\002."), message.c_str(), ci->name.c_str());
}
}
else
source.Reply(_("Entry message list for \002%s\002 is empty."), ci->name.c_str());
}
示例7: pton
void sockaddrs::pton(int type, const Anope::string &address, int pport)
{
this->clear();
switch (type)
{
case AF_INET:
{
int i = inet_pton(type, address.c_str(), &sa4.sin_addr);
if (i <= 0)
this->clear();
else
{
sa4.sin_family = type;
sa4.sin_port = htons(pport);
}
break;
}
case AF_INET6:
{
int i = inet_pton(type, address.c_str(), &sa6.sin6_addr);
if (i <= 0)
this->clear();
else
{
sa6.sin6_family = type;
sa6.sin6_port = htons(pport);
}
break;
}
default:
break;
}
}
示例8: run
int LDAPBind::run()
{
berval cred;
cred.bv_val = strdup(pass.c_str());
cred.bv_len = pass.length();
int i = ldap_sasl_bind_s(service->GetConnection(), who.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
free(cred.bv_val);
return i;
}
示例9: SendSyntax
void Command::SendSyntax(CommandSource &source)
{
Anope::string s = Language::Translate(source.GetAccount(), _("Syntax"));
if (!this->syntax.empty())
{
source.Reply("%s: \002%s %s\002", s.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[0].c_str()));
Anope::string spaces(s.length(), ' ');
for (unsigned i = 1, j = this->syntax.size(); i < j; ++i)
source.Reply("%s \002%s %s\002", spaces.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[i].c_str()));
}
else
source.Reply("%s: \002%s\002", s.c_str(), source.command.c_str());
}
示例10: moduleCopyFile
/**
* Copy the module from the modules folder to the runtime folder.
* This will prevent module updates while the modules is loaded from
* triggering a segfault, as the actaul file in use will be in the
* runtime folder.
* @param name the name of the module to copy
* @param output the destination to copy the module to
* @return MOD_ERR_OK on success
*/
static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &output)
{
Anope::string input = services_dir + "/modules/" + name + ".so";
struct stat s;
if (stat(input.c_str(), &s) == -1)
return MOD_ERR_NOEXIST;
else if (!S_ISREG(s.st_mode))
return MOD_ERR_NOEXIST;
std::ifstream source(input.c_str(), std::ios_base::in | std::ios_base::binary);
if (!source.is_open())
return MOD_ERR_NOEXIST;
char *tmp_output = strdup(output.c_str());
int target_fd = mkstemp(tmp_output);
if (target_fd == -1 || close(target_fd) == -1)
{
free(tmp_output);
source.close();
return MOD_ERR_FILE_IO;
}
output = tmp_output;
free(tmp_output);
Log(LOG_DEBUG) << "Runtime module location: " << output;
std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary);
if (!target.is_open())
{
source.close();
return MOD_ERR_FILE_IO;
}
int want = s.st_size;
char *buffer = new char[s.st_size];
while (want > 0 && !source.fail() && !target.fail())
{
source.read(buffer, want);
int read_len = source.gcount();
target.write(buffer, read_len);
want -= read_len;
}
delete [] buffer;
source.close();
target.close();
return !source.fail() && !target.fail() ? MOD_ERR_OK : MOD_ERR_FILE_IO;
}
示例11: Run
void Command::Run(CommandSource &source, const Anope::string &message)
{
std::vector<Anope::string> params;
spacesepstream(message).GetTokens(params);
bool has_help = source.service->commands.find("HELP") != source.service->commands.end();
CommandInfo::map::const_iterator it = source.service->commands.end();
unsigned count = 0;
for (unsigned max = params.size(); it == source.service->commands.end() && max > 0; --max)
{
Anope::string full_command;
for (unsigned i = 0; i < max; ++i)
full_command += " " + params[i];
full_command.erase(full_command.begin());
++count;
it = source.service->commands.find(full_command);
}
if (it == source.service->commands.end())
{
if (has_help)
source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
else
source.Reply(_("Unknown command \002%s\002."), message.c_str());
return;
}
const CommandInfo &info = it->second;
ServiceReference<Command> c("Command", info.name);
if (!c)
{
if (has_help)
source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
else
source.Reply(_("Unknown command \002%s\002."), message.c_str());
Log(source.service) << "Command " << it->first << " exists on me, but its service " << info.name << " was not found!";
return;
}
for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
params.erase(params.begin());
while (c->max_params > 0 && params.size() > c->max_params)
{
params[c->max_params - 1] += " " + params[c->max_params];
params.erase(params.begin() + c->max_params);
}
c->Run(source, it->first, info, params);
}
示例12: DoList
void DoList(CommandSource &source)
{
Log(LOG_ADMIN, source, this) << "LIST";
Anope::string index;
index = Anope::ReadOnly ? _("%s is enabled") : _("%s is disabled");
source.Reply(index.c_str(), "READONLY");
index = Anope::Debug ? _("%s is enabled") : _("%s is disabled");
source.Reply(index.c_str(), "DEBUG");
index = Anope::NoExpire ? _("%s is enabled") : _("%s is disabled");
source.Reply(index.c_str(), "NOEXPIRE");
return;
}
示例13: DoTop
void DoTop(CommandSource &source, const std::vector<Anope::string> ¶ms, bool is_global, int limit = 1)
{
Anope::string channel;
if (!params.empty())
channel = params[0];
else if (source.c && source.c->ci)
channel = source.c->ci->GetName();
if (!is_global && channel.empty())
is_global = true;
try
{
SQL::Query query;
query = "SELECT nick, letters, words, line, actions,"
"smileys_happy+smileys_sad+smileys_other as smileys "
"FROM `" + prefix + "chanstats` "
"WHERE `nick` != '' AND `chan` = @[email protected] AND `type` = 'total' "
"ORDER BY `letters` DESC LIMIT @[email protected];";
query.SetValue("limit", limit, false);
if (is_global)
query.SetValue("channel", "");
else
query.SetValue("channel", channel.c_str());
SQL::Result res = this->RunQuery(query);
if (res.Rows() > 0)
{
source.Reply(_("Top %i of %s"), limit, (is_global ? "Network" : channel.c_str()));
for (int i = 0; i < res.Rows(); ++i)
{
source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys: %s, actions: %s"),
i+1, res.Get(i, "nick").c_str(), res.Get(i, "letters").c_str(),
res.Get(i, "words").c_str(), res.Get(i, "line").c_str(),
res.Get(i, "smileys").c_str(), res.Get(i, "actions").c_str());
}
}
else
source.Reply(_("No stats for %s."), is_global ? "Network" : channel.c_str());
}
catch (const SQL::Exception &ex)
{
Log(LOG_DEBUG) << ex.GetReason();
}
}
示例14: LocalUser
ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : LocalUser(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), botmodes(bmodes)
{
this->type = UserType::BOT;
this->lastmsg = Anope::CurTime;
this->introduced = false;
bi = botinfo.Create();
bi->bot = this;
bi->SetNick(nnick);
bi->SetUser(nuser);
bi->SetHost(nhost);
bi->SetRealName(nreal);
bi->SetCreated(Anope::CurTime);
Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this);
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
{
Anope::string tmodes = !this->botmodes.empty() ? ("+" + this->botmodes) : IRCD->DefaultPseudoclientModes;
if (!tmodes.empty())
this->SetModesInternal(this, tmodes.c_str());
//XXX
//XLine x(this->nick, "Reserved for services");
//IRCD->SendSQLine(NULL, &x);
IRCD->SendClientIntroduction(this);
this->introduced = true;
}
}
示例15: Unescape
static Anope::string Unescape(const Anope::string &string)
{
Anope::string ret = string;
for (int i = 0; special[i].character.empty() == false; ++i)
if (!special[i].replace.empty())
ret = ret.replace_all_cs(special[i].replace, special[i].character);
for (size_t i, last = 0; (i = string.find("&#", last)) != Anope::string::npos;)
{
last = i + 1;
size_t end = string.find(';', i);
if (end == Anope::string::npos)
break;
Anope::string ch = string.substr(i + 2, end - (i + 2));
if (ch.empty())
continue;
long l;
if (!ch.empty() && ch[0] == 'x')
l = strtol(ch.substr(1).c_str(), NULL, 16);
else
l = strtol(ch.c_str(), NULL, 10);
if (l > 0 && l < 256)
ret = ret.replace_all_cs("&#" + ch + ";", Anope::string(l));
}
return ret;
}