Skip to content

Commit

Permalink
Added a rehash ability via terminal signals, fixed too many \n's in t…
Browse files Browse the repository at this point in the history
…erminal, making debug output messy, removed useless terminal signals
  • Loading branch information
Justin Crawford authored and Justin Crawford committed Jun 25, 2011
1 parent 9f34f8d commit f14da11
Show file tree
Hide file tree
Showing 30 changed files with 53 additions and 70 deletions.
Empty file modified Readme.txt 100644 → 100755
Empty file.
Empty file modified Sepstream.cpp 100644 → 100755
Empty file.
Empty file modified Sepstream.h 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Socket.cpp 100644 → 100755
Expand Up @@ -96,7 +96,7 @@ const Socket& Socket::operator >> (std::string& s) const
memset ( buf, 0, MAXRECV + 1 );
::recv ( m_sock, buf, MAXRECV, 0 );
s = buf;
std::cout << s << "\n";
std::cout << strip(s) << "\n";
//recvlog("%s", s.c_str());
return *this;
}
Expand Down
Empty file modified Socket.h 100644 → 100755
Empty file.
Empty file modified SocketException.h 100644 → 100755
Empty file.
Empty file modified bot.conf 100644 → 100755
Empty file.
Empty file modified defs.h 100644 → 100755
Empty file.
99 changes: 48 additions & 51 deletions flux_net_irc.hpp 100644 → 100755
Expand Up @@ -95,14 +95,12 @@ class IsoHost:string{
string nick;
string host;
string user;

IsoHost(string fullhost){
nick = isolate(':','!',fullhost);
raw = fullhost;
host = isolate('@',' ',fullhost);
user = isolate('!','@',fullhost);
}

IsoHost(string fullhost){
nick = isolate(':','!',fullhost);
raw = fullhost;
host = isolate('@',' ',fullhost);
user = isolate('!','@',fullhost);
}
string isolate(char begin, char end, string msg){
string to_find;
size_t pos = msg.find(begin);
Expand Down Expand Up @@ -568,7 +566,35 @@ void restart(string reason){
exit(1);
}
}

static void Rehash(){
cout << "Rehashing config file." << nl;
try{
INIReader config("bot.conf");
if (config.ParseError() < 0) {
throw ConfigException("Cannot load bot.conf");
}
cout << "\033[22;31mReading Config File\033[22;30m... \033[1m\033[22;32mCHECK\033[1m\033[22;36m"<<nl;
ReadConfig(config);
}catch(ConfigException &ex){
cout << "\r\nConfig Exception was caught: \033[22;31m" << ex.GetReason() << "\033[22;37m" << nl;
log("Config Exception Caught: ", stringify(ex.GetReason()).c_str());
}
}
static void Rehash(Socket &sock){
cout << "Rehashing config file." << nl;
try{
INIReader config("bot.conf");
if (config.ParseError() < 0) {
throw ConfigException("Cannot load bot.conf");
}
cout << "\033[22;31mReading Config File\033[22;30m... \033[1m\033[22;32mCHECK\033[1m\033[22;36m"<<nl;
ReadConfig(config);
}catch(ConfigException &ex){
cout << "\r\nConfig Exception was caught: \033[22;31m" << ex.GetReason() << "\033[22;37m" << nl;
log("Config Exception Caught: ", stringify(ex.GetReason()).c_str());
sock << notice(owner_nick, "Config Exception Caught: %s", stringify(ex.GetReason()).c_str());
}
}
static void WritePID(){
//logging to a text file and making the PID file.
FILE *pidfile;
Expand Down Expand Up @@ -741,56 +767,27 @@ void sigact(int sig)
{
string sigstr;
switch (sig){
case 1:
//this case can later be used to rehash the bot.

case 2:
sigstr = "Someone pressed CTRL + C";
case SIGHUP:
signal(sig, SIG_IGN);
quitting = true;
break;
case 3:
sigstr = "Someone closed my terminal -_-";
quitting = true;
Rehash();
break;
case 4:
sigstr = "Illegal instruction (SIGILL)";
quitting = true;
break;
case 6:
sigstr = "Abort signal (SIGABRT)";
quitting = true;
break;
case 9:
sigstr = "KILL (SIGKILL)";
quitting = true;
break;
case 10:
sigstr = "User defined signal 1 (SIGUSR1)";
quitting = true;
break;
case 11:
sigstr = "Segmentation Fault (SIGSEGV)";
exit(1);
break;
case 13:
sigstr = "Broken pipe (SIGPIPE)";
quitting = true;
break;
case 14:
sigstr = "Timer signal from alarm (SIGALRM)";
case SIGINT:
cout << "\r\n\033[0m";
sigstr = "Someone pressed CTRL + C";
signal(sig, SIG_IGN);
quitmsg = "Recieved Signal: "+sigstr;
quitting = true;
break;
case 15:
sigstr = "Termination signal (SIGTERM)";
case SIGTERM:
cout << "\r\n\033[0m";
sigstr = "Someone killed me";
signal(sig, SIG_IGN);
quitmsg = "Recieved Signal: "+sigstr;
quitting = true;
break;
default:
quitmsg = "Recieved weird signal from terminal. Sig Number: "+stringify(sig);
cout << "\r\n\033[0m";
throw CoreException("Recieved weird signal from terminal. Signal Number: "+stringify(sig));
}
quitmsg = "Recieved Signal: "+sigstr;
cout << "\r\n\033[0m";
}
}
#endif
Empty file modified ftp.sh 100644 → 100755
Empty file.
Empty file modified includes.h 100644 → 100755
Empty file.
Empty file modified inireader/INIReader.cpp 100644 → 100755
Empty file.
Empty file modified inireader/INIReader.h 100644 → 100755
Empty file.
Empty file modified inireader/ini.c 100644 → 100755
Empty file.
Empty file modified inireader/ini.h 100644 → 100755
Empty file.
4 changes: 1 addition & 3 deletions main.cpp 100644 → 100755
Expand Up @@ -59,9 +59,7 @@ int main (int argcx, char** argvx, char *envp[])

signal(SIGTERM, sigact); //catch any terminal signals if possible
signal(SIGINT, sigact);
signal(SIGABRT, sigact);
signal(SIGILL, sigact);
signal(SIGSEGV, sigact);
signal(SIGHUP, sigact);

/*
struct sigaction act; // to catch a signal sent from the terminal.
Expand Down
Empty file modified modules/.gitignore 100644 → 100755
Empty file.
Empty file modified modules/Flux_Services.h 100644 → 100755
Empty file.
Empty file modified modules/about_me.h 100644 → 100755
Empty file.
Empty file modified modules/channel_logger.h 100644 → 100755
Empty file.
Empty file modified modules/ctcp.h 100644 → 100755
Empty file.
Empty file modified modules/da_goat.h 100644 → 100755
Empty file.
Empty file modified modules/dns.h 100644 → 100755
Empty file.
Empty file modified modules/dummy.h 100644 → 100755
Empty file.
Empty file modified modules/help.h 100644 → 100755
Empty file.
Empty file modified modules/ping_pong.h 100644 → 100755
Empty file.
Empty file modified modules/searcher.h 100644 → 100755
Empty file.
18 changes: 3 additions & 15 deletions modules/system.h 100644 → 100755
Expand Up @@ -81,23 +81,11 @@ void system_m(Socket &sock, irc_string *reply, string rply){
string getpass = reply->params(1);
if(unick == owner_nick || getpass == usrpass){
sock << notice(unick, "Rehashing config file.");
cout << "Rehashing config file." << nl;
log("%s rehashed config file.", unick.c_str());
try{
INIReader config("bot.conf");
if (config.ParseError() < 0) {
throw ConfigException("Cannot load bot.conf");
}
ReadConfig(config);
}catch(ConfigException &ex){
cout << "\r\nConfig Exception was caught: \033[22;31m" << ex.GetReason() << "\033[22;37m" << nl;
log("Config Exception Caught: %s", stringify(ex.GetReason()).c_str());
sock << notice(unick, "Config Exception Caught: %s", stringify(ex.GetReason()).c_str());
}
cout << "\033[22;31mReading Config File\033[22;30m... \033[1m\033[22;32mCHECK\033[1m\033[22;36m"<<nl;
Rehash(sock);
}else{
sock << notice(unick, access_denied);
log("%s attempted a rehash.", unick.c_str());
sock << notice(unick, access_denied);
log("%s attempted a rehash.", unick.c_str());
}
}
if(reply->said("!bugs")){
Expand Down
Empty file modified modules/weather.h 100644 → 100755
Empty file.
Empty file modified modules/world_clock.h 100644 → 100755
Empty file.

0 comments on commit f14da11

Please sign in to comment.