Permalink
Browse files

Added a rehash ability via terminal signals, fixed too many \n's in t…

…erminal, making debug output messy, removed useless terminal signals
  • Loading branch information...
1 parent 9f34f8d commit f14da11644947864412368a569a705e877b39571 @Justasic committed Jun 25, 2011
View
0 Readme.txt 100644 → 100755
No changes.
View
0 Sepstream.cpp 100644 → 100755
No changes.
View
0 Sepstream.h 100644 → 100755
No changes.
View
2 Socket.cpp 100644 → 100755
@@ -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;
}
View
0 Socket.h 100644 → 100755
No changes.
View
0 SocketException.h 100644 → 100755
No changes.
View
0 bot.conf 100644 → 100755
No changes.
View
0 defs.h 100644 → 100755
No changes.
View
99 flux_net_irc.hpp 100644 → 100755
@@ -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);
@@ -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;
@@ -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
View
0 ftp.sh 100644 → 100755
No changes.
View
0 includes.h 100644 → 100755
No changes.
View
0 inireader/INIReader.cpp 100644 → 100755
No changes.
View
0 inireader/INIReader.h 100644 → 100755
No changes.
View
0 inireader/ini.c 100644 → 100755
No changes.
View
0 inireader/ini.h 100644 → 100755
No changes.
View
4 main.cpp 100644 → 100755
@@ -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.
View
0 modules/.gitignore 100644 → 100755
No changes.
View
0 modules/Flux_Services.h 100644 → 100755
No changes.
View
0 modules/about_me.h 100644 → 100755
No changes.
View
0 modules/channel_logger.h 100644 → 100755
No changes.
View
0 modules/ctcp.h 100644 → 100755
No changes.
View
0 modules/da_goat.h 100644 → 100755
No changes.
View
0 modules/dns.h 100644 → 100755
No changes.
View
0 modules/dummy.h 100644 → 100755
No changes.
View
0 modules/help.h 100644 → 100755
No changes.
View
0 modules/ping_pong.h 100644 → 100755
No changes.
View
0 modules/searcher.h 100644 → 100755
No changes.
View
18 modules/system.h 100644 → 100755
@@ -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")){
View
0 modules/weather.h 100644 → 100755
No changes.
View
0 modules/world_clock.h 100644 → 100755
No changes.

0 comments on commit f14da11

Please sign in to comment.