00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00041 #include "services.h"
00042 #include "hash.h"
00043 #include "nickserv.h"
00044 #include "memoserv.h"
00045 #include "infoserv.h"
00046 #include "db.h"
00047 #include "log.h"
00048
00049
00050
00051 #ifdef USE_SQL
00052
00055 PGconn *dbConn = NULL;
00056 #endif
00057
00061 char myname[255],
00062 mypass[33];
00063
00064
00065
00066
00067 char hostname[255];
00068 int port;
00069
00070
00071
00072
00073 int server;
00074
00075
00076
00077
00078
00079 Service services[NUMSERVS];
00080 database db;
00081 SLogfile *operlog, *nicklog, *chanlog;
00082 FILE *corelog;
00083 u_long totalusers;
00084 u_long mostusers = 0, mostnicks = 0, mostchans = 0, mostmemos = 0;
00085 extern unsigned long top_akill_stamp;
00086 long startup, firstup;
00087 char *OperServ, *NickServ, *ChanServ, *MemoServ, *InfoServ, *GameServ;
00088 char *MassServ;
00089 char coreBuffer[IRCBUF];
00090 u_int AccessLimit = 3, OpLimit = 25, AkickLimit = 30, ChanLimit = 10, NickLimit = 5;
00091 time_t CTime;
00092
00093 time_t nextNsync, nextCsync;
00094 time_t nextMsync;
00095
00103 void flushLogs(char *)
00104 {
00105 nicklog->flush();
00106 chanlog->flush();
00107 operlog->flush();
00108 fflush(corelog);
00109
00110 timer(60, flushLogs, NULL);
00111 }
00112
00122 void checkTusers(char *)
00123 {
00124 #ifdef PLUSLCHAN
00125 static u_int last_mostusers = 0;
00126
00127 if (last_mostusers < mostusers) {
00128 sSend(":%s MODE %s +l %lu", OperServ, PLUSLCHAN, mostusers + 5);
00129 last_mostusers = mostusers;
00130 }
00131
00132 timer(60, checkTusers, NULL);
00133 #endif
00134 }
00135
00142 void writeServicesTotals()
00143 {
00144 FILE *fp = fopen("services.totals", "w");
00145
00146 if (fp) {
00147 fprintf(fp, "%lu\n%lu\n%lu\n%lu\n%lu\n", mostusers, mostnicks,
00148 mostchans, mostmemos, top_akill_stamp);
00149 fflush(fp);
00150 fclose(fp);
00151 }
00152 }
00153
00155
00165 void sshutdown(int type)
00166 {
00167 if (type != (-1) && type != 2) {
00168 writeServicesTotals();
00169 saveakills();
00170 saveNickData();
00171 syncChanData(1);
00172 saveMemoData();
00173 saveInfoData();
00174 }
00175
00176 timed_akill_queue(NULL);
00177 unlink("services.pid");
00178
00179 if (1 ) {
00180 #ifdef USE_SQL
00181 if (dbConn != NULL)
00182 PQfinish(dbConn);
00183 dbConn = NULL;
00184 #endif
00185 }
00186
00187 if (type == 1) {
00188 sSend("SQUIT %s :Services %s fall down go BOOM!", hostname,
00189 VERSION_NUM);
00190 close(server);
00191 abort();
00192 }
00193 else if (type == 2) {
00194 fprintf(stderr,
00195 "Error connecting to server, check above message\n");
00196 exit(-1);
00197 }
00198 else if (type == 0) {
00199 sSend("SQUIT %s :Services %s shutdown", hostname, VERSION_NUM);
00200 close(server);
00201 exit(66);
00202 }
00203 else {
00204 sSend("SQUIT %s :Services %s shutdown", hostname, VERSION_NUM);
00205 close(server);
00206 exit(1);
00207 }
00208 }
00209
00216 void handler(int sig)
00217 {
00218 switch (sig) {
00219 case SIGTERM:
00220 sSend("WALLOPS "
00221 ":Received some signal thats telling me to shutdown");
00222 timed_akill_queue(NULL);
00223 sshutdown(0);
00224 break;
00225 case SIGSEGV:
00226 timed_akill_queue(NULL);
00227 logDump(corelog, "Core dumped ---\n\"%s\"", coreBuffer);
00228 sSend("WALLOPS :Segmentation Violation, shutdown NOW");
00229 sSend("GOPER :Buffer is -> %s", coreBuffer);
00230 dlogDump(corelog);
00231 sshutdown(1);
00232 break;
00233
00234 case SIGPIPE:
00235 timed_akill_queue(NULL);
00236 signal(SIGPIPE, SIG_IGN);
00237
00238 break;
00239
00240 default:
00241 sSend("GNOTICE :Recieved unidentified signal %i", sig);
00242 return;
00243 }
00244 }
00245
00246
00247
00248