Merge branch 'master' of https://github.com/nullworks/cathook
This commit is contained in:
commit
8940256c87
2
external/chirc
vendored
2
external/chirc
vendored
@ -1 +1 @@
|
||||
Subproject commit e2379b05d7915fab6506dcc3f61a44b156027465
|
||||
Subproject commit ecf241a326bc0e3dad2d3fb240a7b52d1d533fe0
|
105
src/irc.cpp
105
src/irc.cpp
@ -5,6 +5,7 @@
|
||||
#include "Settings.hpp"
|
||||
#include "ChIRC.hpp"
|
||||
#include <random>
|
||||
#include "hack.hpp"
|
||||
|
||||
namespace IRC
|
||||
{
|
||||
@ -14,6 +15,8 @@ static settings::Bool authenticate("irc.auth", "true");
|
||||
static settings::String channel("irc.channel", "#cat_comms");
|
||||
static settings::String address("irc.address", "cathook.irc.inkcat.net");
|
||||
static settings::Int port("irc.port", "8080");
|
||||
static settings::String commandandcontrol_channel("irc.cc.channel", "");
|
||||
static settings::String commandandcontrol_password("irc.cc.password", "");
|
||||
|
||||
static ChIRC::ChIRC irc;
|
||||
|
||||
@ -44,37 +47,17 @@ void printmsgcopy(std::string usr, std::string msg)
|
||||
msg.c_str());
|
||||
}
|
||||
|
||||
void handleMessage(IRCMessage message, IRCClient *client)
|
||||
namespace handlers
|
||||
{
|
||||
void message(std::string &usr, std::string &msg)
|
||||
{
|
||||
std::string &cmd = message.command;
|
||||
std::string &channel = message.parameters.at(0);
|
||||
std::string &rawmsg = message.parameters.at(1);
|
||||
std::string &usr = message.prefix.nick;
|
||||
if (!ucccccp::validate(rawmsg))
|
||||
return;
|
||||
std::string msg(ucccccp::decrypt(rawmsg));
|
||||
if (msg == "Attempt at ucccccping and failing" ||
|
||||
msg == "Unsupported version")
|
||||
return;
|
||||
|
||||
// Handle privmsg (Message to #channel)
|
||||
if (cmd == "PRIVMSG")
|
||||
{
|
||||
if (msg.empty() || usr.empty())
|
||||
return;
|
||||
// Handle messages
|
||||
if (msg.find("msg") == 0)
|
||||
{
|
||||
std::string toprint = msg.substr(3);
|
||||
if (toprint.empty())
|
||||
return;
|
||||
printmsg(usr, toprint);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle auth requests
|
||||
if (msg.find("auth") == 0)
|
||||
{
|
||||
}
|
||||
void authreq(std::string &msg)
|
||||
{
|
||||
// Check if we are in a game
|
||||
if (g_Settings.bInvalid)
|
||||
return;
|
||||
@ -99,8 +82,7 @@ void handleMessage(IRCMessage message, IRCClient *client)
|
||||
auto tarsteamid = pinfo.friendsID;
|
||||
MD5Value_t result;
|
||||
// Hash steamid
|
||||
MD5_ProcessSingleBuffer(&tarsteamid, sizeof(tarsteamid),
|
||||
result);
|
||||
MD5_ProcessSingleBuffer(&tarsteamid, sizeof(tarsteamid), result);
|
||||
// Get bits of hash and store in string
|
||||
std::string tarhash;
|
||||
for (auto i : result.bits)
|
||||
@ -128,16 +110,63 @@ void handleMessage(IRCMessage message, IRCClient *client)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void cc_cmd(std::string &msg)
|
||||
{
|
||||
hack::ExecuteCommand(msg.substr(6));
|
||||
}
|
||||
} // namespace handlers
|
||||
|
||||
void handleIRC(IRCMessage message, IRCClient *client)
|
||||
{
|
||||
std::string &cmd = message.command;
|
||||
std::string &channel = message.parameters.at(0);
|
||||
std::string &rawmsg = message.parameters.at(1);
|
||||
std::string &usr = message.prefix.nick;
|
||||
if (!ucccccp::validate(rawmsg))
|
||||
return;
|
||||
std::string msg(ucccccp::decrypt(rawmsg));
|
||||
if (msg == "Attempt at ucccccping and failing" ||
|
||||
msg == "Unsupported version")
|
||||
return;
|
||||
|
||||
// Handle privmsg (Message to #channel)
|
||||
if (cmd == "PRIVMSG")
|
||||
{
|
||||
if (msg.empty() || usr.empty())
|
||||
return;
|
||||
// Handle public messages
|
||||
if (channel == irc.getData().comms_channel)
|
||||
{
|
||||
// Handle messages
|
||||
if (msg.find("msg") == 0)
|
||||
{
|
||||
handlers::message(usr, msg);
|
||||
return;
|
||||
}
|
||||
// Handle auth requests
|
||||
else if (msg.find("auth") == 0)
|
||||
{
|
||||
handlers::authreq(msg);
|
||||
}
|
||||
}
|
||||
else if (channel == irc.getData().commandandcontrol_channel)
|
||||
{
|
||||
if (msg.find("cc_cmd") == 0)
|
||||
{
|
||||
handlers::cc_cmd(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateData(std::string commandandcontrol)
|
||||
void updateData()
|
||||
{
|
||||
std::string nick("Anon");
|
||||
if (!*anon)
|
||||
nick = g_ISteamFriends->GetPersonaName();
|
||||
irc.UpdateData(nick, nick, *channel, commandandcontrol, *address, *port);
|
||||
irc.UpdateData(nick, nick, *channel, *commandandcontrol_channel,
|
||||
*commandandcontrol_password, *address, *port);
|
||||
}
|
||||
|
||||
bool sendmsg(std::string &msg, bool loopback)
|
||||
@ -165,7 +194,7 @@ void auth(bool reply)
|
||||
MD5Value_t result;
|
||||
MD5_ProcessSingleBuffer(&LOCAL_E->player_info.friendsID, sizeof(uint32),
|
||||
result);
|
||||
std::string msg = "auth";
|
||||
std::string msg("auth");
|
||||
if (reply)
|
||||
msg.append("rep");
|
||||
for (auto i : result.bits)
|
||||
@ -192,7 +221,7 @@ template <typename T> void rvarCallback(settings::VariableBase<T> &var, T after)
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono_literals::operator""ms(500));
|
||||
irc.Disconnect();
|
||||
updateData("");
|
||||
updateData();
|
||||
if (enabled)
|
||||
irc.Connect();
|
||||
restarting = false;
|
||||
@ -202,15 +231,17 @@ template <typename T> void rvarCallback(settings::VariableBase<T> &var, T after)
|
||||
}
|
||||
|
||||
static InitRoutine init([]() {
|
||||
updateData("");
|
||||
updateData();
|
||||
enabled.installChangeCallback(rvarCallback<bool>);
|
||||
anon.installChangeCallback(rvarCallback<bool>);
|
||||
authenticate.installChangeCallback(rvarCallback<bool>);
|
||||
channel.installChangeCallback(rvarCallback<std::string>);
|
||||
address.installChangeCallback(rvarCallback<std::string>);
|
||||
port.installChangeCallback(rvarCallback<int>);
|
||||
commandandcontrol_channel.installChangeCallback(rvarCallback<std::string>);
|
||||
commandandcontrol_password.installChangeCallback(rvarCallback<std::string>);
|
||||
|
||||
irc.installCallback("PRIVMSG", handleMessage);
|
||||
irc.installCallback("PRIVMSG", handleIRC);
|
||||
irc.Connect();
|
||||
});
|
||||
|
||||
@ -218,6 +249,12 @@ static CatCommand irc_send_cmd("irc_send_cmd", "Send cmd to IRC",
|
||||
[](const CCommand &args) {
|
||||
irc.sendraw(args.ArgS());
|
||||
});
|
||||
static CatCommand irc_exec_all("irc_exec_all", "Send command to C&C channel",
|
||||
[](const CCommand &args) {
|
||||
std::string msg("cc_cmd");
|
||||
msg.append(args.ArgS());
|
||||
irc.privmsg(msg, true);
|
||||
});
|
||||
|
||||
static CatCommand irc_send("irc_send", "Send message to IRC",
|
||||
[](const CCommand &args) {
|
||||
|
Reference in New Issue
Block a user