📄 irc_connection.cpp
字号:
std::vector<std::string> params;
params.push_back(channel_list);
params.push_back(user_list);
if (!comment.empty()) params.push_back(comment);
send_command("", "KICK", params);
}
void CL_IRCConnection::send_version(const std::string &server)
{
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
send_command("", "VERSION", params);
}
void CL_IRCConnection::send_stats(const std::string &query, const std::string &server)
{
std::vector<std::string> params;
if (!query.empty()) params.push_back(query);
if (!server.empty()) params.push_back(server);
send_command("", "STATS", params);
}
void CL_IRCConnection::send_links(const std::string &remote_server, const std::string &server_mask)
{
std::vector<std::string> params;
if (!remote_server.empty()) params.push_back(remote_server);
if (!server_mask.empty()) params.push_back(server_mask);
send_command("", "LINKS", params);
}
void CL_IRCConnection::send_time(const std::string &server)
{
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
send_command("", "TIME", params);
}
void CL_IRCConnection::send_connect(const std::string &target_server, int port, const std::string &remote_server)
{
std::vector<std::string> params;
params.push_back(target_server);
// if (port) params.push_back(CL_String::from_int(port));
if (!remote_server.empty()) params.push_back(remote_server);
send_command("", "CONNECT", params);
}
void CL_IRCConnection::send_trace(const std::string &server)
{
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
send_command("", "TRACE", params);
}
void CL_IRCConnection::send_admin(const std::string &server)
{
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
send_command("", "ADMIN", params);
}
void CL_IRCConnection::send_info(const std::string &server)
{
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
send_command("", "INFO", params);
}
void CL_IRCConnection::send_privmsg(const std::string &receiver, const std::string &text)
{
std::list<std::string> receivers;
receivers.push_back(receiver);
send_privmsg(receivers, text);
}
void CL_IRCConnection::send_privmsg(const std::list<std::string> &receivers, const std::string &text)
{
std::list<std::string>::const_iterator it;
std::string receiver_list;
bool first = true;
for (it = receivers.begin(); it != receivers.end(); ++it)
{
if (!first) receiver_list.append(",");
first = false;
receiver_list.append(*it);
}
std::vector<std::string> params;
params.push_back(receiver_list);
params.push_back(text);
send_command("", "PRIVMSG", params);
}
void CL_IRCConnection::send_privmsg_ctcp(const std::string &receiver, const std::string &command, const std::string &data)
{
std::list<std::string> receivers;
receivers.push_back(receiver);
send_privmsg_ctcp(receivers, command, data);
}
void CL_IRCConnection::send_privmsg_ctcp(std::list<std::string> &receivers, const std::string &command, const std::string &data)
{
std::string line = data.empty() ? command : command + std::string(" ") + data;
// Add CTCP escapes:
std::string::size_type pos;
pos = 0;
while (pos != std::string::npos)
{
pos = line.find('\\', pos);
if (pos == std::string::npos) break;
line.replace( pos, 1, "\\\\" );
pos++;
}
pos = 0;
while (pos != std::string::npos)
{
pos = line.find('\001', pos);
if (pos == std::string::npos) break;
line.replace( pos, 1, "\\a" );
pos++;
}
std::string ctcp = std::string("\001") + line + std::string("\001");
std::list<std::string>::const_iterator it;
std::string receiver_list;
bool first = true;
for (it = receivers.begin(); it != receivers.end(); ++it)
{
if (!first) receiver_list.append(",");
first = false;
receiver_list.append(*it);
}
std::vector<std::string> params;
params.push_back(receiver_list);
params.push_back(ctcp);
send_command("", "PRIVMSG", params);
}
void CL_IRCConnection::send_notice(const std::string &nickname, const std::string &text)
{
std::vector<std::string> params;
params.push_back(nickname);
params.push_back(text);
send_command("", "NOTICE", params);
}
void CL_IRCConnection::send_notice_ctcp(const std::string &nickname, const std::string &command, const std::string &data)
{
std::string line = data.empty() ? command : command + std::string(" ") + data;
// Add CTCP escapes:
std::string::size_type pos;
pos = 0;
while (pos != std::string::npos)
{
pos = line.find('\\', pos);
if (pos == std::string::npos) break;
line.replace( pos, 1, "\\\\" );
pos++;
}
pos = 0;
while (pos != std::string::npos)
{
pos = line.find('\001', pos);
if (pos == std::string::npos) break;
line.replace( pos, 1, "\\a" );
pos++;
}
std::string ctcp = std::string("\001") + line + std::string("\001");
std::vector<std::string> params;
params.push_back(nickname);
params.push_back(ctcp);
send_command("", "NOTICE", params);
}
void CL_IRCConnection::send_who(const std::string &name, bool oper)
{
std::vector<std::string> params;
params.push_back(name);
if (oper) params.push_back("o");
send_command("", "WHO", params);
}
void CL_IRCConnection::send_whois(const std::string &nickmask)
{
std::vector<std::string> params;
params.push_back(nickmask);
send_command("", "WHOIS", params);
}
void CL_IRCConnection::send_whois(const std::string &server, const std::string &nickmask)
{
std::vector<std::string> params;
params.push_back(server);
params.push_back(nickmask);
send_command("", "WHOIS", params);
}
void CL_IRCConnection::send_whois(const std::list<std::string> &nickmasks)
{
send_whois("", nickmasks);
}
void CL_IRCConnection::send_whois(const std::string &server, const std::list<std::string> &nickmasks)
{
std::list<std::string>::const_iterator it;
std::string nickmask_list;
bool first = true;
for (it = nickmasks.begin(); it != nickmasks.end(); ++it)
{
if (!first) nickmask_list.append(",");
first = false;
nickmask_list.append(*it);
}
std::vector<std::string> params;
if (!server.empty()) params.push_back(server);
params.push_back(nickmask_list);
send_command("", "WHOIS", params);
}
void CL_IRCConnection::send_whowas(const std::string &nickname, int count, const std::string &server)
{
std::vector<std::string> params;
params.push_back(nickname);
// if (count > 0) params.push_back(CL_String::from_int(count));
if (!server.empty()) params.push_back(server);
send_command("", "WHOWAS", params);
}
void CL_IRCConnection::send_kill(const std::string &nickname, const std::string &comment)
{
std::vector<std::string> params;
params.push_back(nickname);
if (!comment.empty()) params.push_back(comment);
send_command("", "KILL", params);
}
void CL_IRCConnection::send_ping(const std::string &server, const std::string &server2)
{
std::vector<std::string> params;
params.push_back(server);
if (!server2.empty()) params.push_back(server2);
send_command("", "PING", params);
}
void CL_IRCConnection::send_pong(const std::string &daemon, const std::string &daemon2)
{
std::vector<std::string> params;
params.push_back(daemon);
if (!daemon2.empty()) params.push_back(daemon2);
send_command("", "PONG", params);
}
std::string CL_IRCConnection::extract_nick(const std::string &str)
{
std::string::size_type pos = str.find_first_of('!');
if (pos == std::string::npos) return str;
return str.substr(0, pos);
}
std::string CL_IRCConnection::extract_user(const std::string &str)
{
std::string::size_type pos = str.find_first_of('!');
if (pos == std::string::npos) return std::string();
std::string::size_type pos_at = str.find_first_of('@', pos);
if (pos_at == std::string::npos) return str.substr(pos+1);
return str.substr(pos+1, pos_at-pos-1);
}
std::string CL_IRCConnection::extract_address(const std::string &str)
{
std::string::size_type pos = str.find_first_of('!');
if (pos == std::string::npos) return std::string();
std::string::size_type pos_at = str.find_first_of('@', pos);
if (pos_at == std::string::npos) return std::string();
return str.substr(pos_at+1);
}
/////////////////////////////////////////////////////////////////////////////
// CL_IRCConnection signals:
CL_Signal_v1<const std::string &> &CL_IRCConnection::sig_socket_error()
{
return impl->sig_socket_error;
}
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &CL_IRCConnection::sig_command_received()
{
return impl->sig_command_received;
}
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &CL_IRCConnection::sig_unknown_command_received()
{
return impl->sig_unknown_command_received;
}
CL_Signal_v3<const std::string &, int, const std::vector<std::string> &> &CL_IRCConnection::sig_numeric_reply()
{
return impl->sig_numeric_reply;
}
CL_Signal_v3<const std::string &, const std::string &, const std::vector<std::string> &> &CL_IRCConnection::sig_name_reply()
{
return impl->sig_name_reply;
}
CL_Signal_v2<const std::string &, const std::string &> &CL_IRCConnection::sig_nick()
{
return impl->sig_nick;
}
CL_Signal_v2<const std::string &, const std::string &> &CL_IRCConnection::sig_join()
{
return impl->sig_join;
}
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_part()
{
return impl->sig_part;
}
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::vector<std::string> &> &CL_IRCConnection::sig_mode()
{
return impl->sig_mode;
}
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_topic()
{
return impl->sig_topic;
}
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_invite()
{
return impl->sig_invite;
}
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_kick()
{
return impl->sig_kick;
}
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_privmsg()
{
return impl->sig_privmsg;
}
CL_Signal_v3<const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_notice()
{
return impl->sig_notice;
}
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_privmsg_ctcp()
{
return impl->sig_privmsg_ctcp;
}
CL_Signal_v4<const std::string &, const std::string &, const std::string &, const std::string &> &CL_IRCConnection::sig_notice_ctcp()
{
return impl->sig_notice_ctcp;
}
CL_Signal_v2<const std::string &, const std::string &> &CL_IRCConnection::sig_ping()
{
return impl->sig_ping;
}
/////////////////////////////////////////////////////////////////////////////
// CL_IRCConnection implementation:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -