void onkill(char *source, char *target, char *comment) { char buffer[200]; if (!strcasecmp(target, mynick)) { #if 0 /* ignore kill for nick collisions because we * already check in onnick() if we're collided. * This kill is prolly a lost kill resulting of * another nick collision.. */ if (strstr(comment, "older nick overruled") || strstr(comment, "collided yourself")) { log("ERROR: Nick collision on me?"); return; } #endif sprintf(buffer, ":%s SQUIT %s 0 :killed by %s\n", SERVERNAME, SERVERNAME, source); sendtoserv(buffer); dumpbuff(); close(Irc.fd); Irc.fd = -1; if (reconnect(server)) { try_later(server); } #ifdef BACKUP } else if (!strcasecmp(target, MAIN_NICK)) { quit(MAIN_NICK " is back", 0); #endif #ifdef FAKE_UWORLD } else if (!strcasecmp(target, UFAKE_NICK)) { char buffer[200]; sprintf(buffer, "%s is KILLED by %s", UFAKE_NICK, source); log(buffer); Uworld_status = 0; KillUworld("Killed"); #endif } else onquit(target); }
int run(){ #ifdef _WIN32 WSADATA globalWSAData; WSAStartup( MAKEWORD(2, 2), &globalWSAData ); #endif functions["ping"].push_back(callbacks::ping); functions["pong"].push_back(callbacks::pong); functions["privmsg"].push_back(callbacks::privmsg); functions["whois"].push_back(callbacks::whois); functions["join"].push_back(callbacks::join); functions["nick"].push_back(callbacks::nick); functions["part"].push_back(callbacks::part); functions["motd"].push_back(callbacks::motd); functions["invite"].push_back(callbacks::invite); functions["ban"].push_back(callbacks::ban); functions["unban"].push_back(callbacks::unban); functions["kick"].push_back(callbacks::kick); functions["mute"].push_back(callbacks::mute); functions["unmute"].push_back(callbacks::unmute); functions["mod"].push_back(callbacks::mod); functions["voice"].push_back(callbacks::voice); functions["star"].push_back(callbacks::star); functions["op"].push_back(callbacks::op); functions["sop"].push_back(callbacks::sop); functions["options"].push_back(callbacks::options); functions["servmute"].push_back(callbacks::servmute); functions["guestpass"].push_back(callbacks::guestpass); functions["servstrip"].push_back(callbacks::servstrip); functions["strip"].push_back(callbacks::strip); functions["servoper"].push_back(callbacks::servoper); functions["servmod"].push_back(callbacks::servmod); functions["servban"].push_back(callbacks::servban); functions["servunban"].push_back(callbacks::servunban); functions["servbanlist"].push_back(callbacks::servbanlist); functions["banlist"].push_back(callbacks::banlist); functions["help"].push_back(callbacks::help); functions["echo"].push_back(callbacks::echo); functions["who"].push_back(callbacks::who); functions["mode"].push_back(callbacks::mode); functions["ignore"].push_back(callbacks::ignore); functions["listen"].push_back(callbacks::listen); functions["ignorelist"].push_back(callbacks::ignorelist); functions["color"].push_back(callbacks::color); functions["away"].push_back(callbacks::away); functions["motdhistory"].push_back(callbacks::motdhistory); functions["topic"].push_back(callbacks::motd); functions["timezone"].push_back(callbacks::timezone); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); //functions[""].push_back(callbacks::); DEBUG; user u; u.id = 0; u.access = 0; u.nick = u.name = u.ip = u.color = ""; users.push_back( u ); u.id = 1; u.access = ACCESS_SOP|ACCESS_AOP|ACCESS_HOP|ACCESS_VOP|ACCESS_NONE; u.nick = u.name = servername; u.ip = "Coldstorm"; u.color = "FFFFFF"; u.country = "CS"; users.push_back( u ); frist = users.size(); DEBUG; readdb("database.kdb"); DEBUG; //atexit( onquit ); //atexit( socketcleanup ); DEBUG; guestpasses.push_back("1"); guestpasses.push_back("2"); guestpasses.push_back("3"); guestpasses.push_back("4"); guestpasses.push_back("5"); guestpasses.push_back("6"); DEBUG; call_thread( flushthread, 0 ); call_thread( listenfortcp, 0 ); DEBUG; call_thread( listenforajax, 0 ); DEBUG; char test[100]; DEBUG; gets(test); DEBUG; socketcleanup(); onquit(); return ERROR_NONE; }
void onsquit(char *source, char *theserver, char *args) { register aserver *serv, **s; register int i; char TS[80]; #ifdef FAKE_UWORLD if (!strcasecmp(theserver, UFAKE_SERVER) && Uworld_status == 1) { GetWord(0, args, TS); if (atol(TS) == UworldServTS) { char buffer[200]; sprintf(buffer, "%s squitted", UFAKE_NICK); log(buffer); Uworld_status = 0; } return; } #endif s = FindServer(&ServerList, theserver); if (s == NULL) { char buffer[200]; sprintf(buffer, "ERROR: SQUIT unknown server %s (from %s)", theserver, source); log(buffer); return; } serv = *s; #ifdef DEBUG printf("SQUIT: %s %s\n", source, theserver); #endif if (args != NULL) { GetWord(0, args, TS); #ifdef DEBUG if (s != NULL) printf("ConnectTS: %ld SquitTS: %ld\n", serv->TS, atol(TS)); #endif } if (serv != ServerList && args != NULL && serv->TS != atol(TS)) { #ifdef DEBUG printf("TS's are different.. ignoring squit!\n"); #endif return; } while (serv->down != NULL) { onsquit(NULL, serv->down->name, NULL); } for (i = 0; i < 100; i++) { while (serv->users[i] != NULL) { onquit(serv->users[i]->N->nick); } } TTLALLOCMEM -= strlen(serv->name) + 1; free(serv->name); *s = serv->next; TTLALLOCMEM -= sizeof(aserver); free(serv); }
void onnick(char *source, char *newnick, char *body) { register aluser *user, **u; register asuser *suser, **s; register aserver *serv; char username[80]; char hostname[80]; char TS[80]; char server[80]; register achannelnode *chan; register anickchange *curr, *prec; char buffer[512]; int i = 0; #ifdef DEBUG printf("NICK: %s --> %s ...\n", source, newnick); #endif /* a new user */ if (!ToLuser(source)) { /* Not a user, so a server or nothing */ if (strchr(source, '.') == NULL) { /* Source is not a user and not a server either */ return; } if (!strcasecmp(newnick, mynick)) { log("ERROR: I'm nick collided"); #ifdef DEBUG printf("ARGH!!! I'M NICK COLLIDED!\n"); #endif GetWord(1, body, TS); GetWord(2, body, username); GetWord(3, body, hostname); if (atol(TS) <= logTS && strcasecmp(username, myuser) && strcasecmp(hostname, mysite)) { NickInUse(); log(source); log(newnick); log(body); } else { onquit(source); return; /*ignore */ } #ifdef BACKUP } else if (!strcasecmp(newnick, MAIN_NICK)) { return; /* ignore */ #endif } else if (ToLuser(newnick)) { #ifdef DEBUG printf("ARGH!!! NICK COLLISION\n"); #endif onquit(newnick); } GetWord(1, body, TS); GetWord(2, body, username); GetWord(3, body, hostname); GetWord(4, body, server); #ifdef FAKE_UWORLD if (Uworld_status == 1 && !strcasecmp(newnick, UFAKE_NICK)) { if (atol(TS) <= UworldTS && atol(TS) != 0 && strcasecmp(username, UFAKE_NICK) && strcasecmp(hostname, UFAKE_HOST)) { sprintf(buffer, "%s nick collided", UFAKE_NICK); log(buffer); Uworld_status = 0; KillUworld("nick collision"); return; /* ignore if younger */ } } #endif user = (aluser *) MALLOC(sizeof(aluser)); user->nick = (char *)MALLOC(strlen(newnick) + 1); strcpy(user->nick, newnick); user->username = (char *)MALLOC(strlen(username) + 1); strcpy(user->username, username); user->site = (char *)MALLOC(strlen(hostname) + 1); strcpy(user->site, hostname); if (*newnick == '+') serv = &VirtualServer; else serv = ToServer(server); user->server = serv; user->time = atol(TS); user->mode = 0; user->channel = NULL; user->valchan = NULL; user->next = Lusers[lu_hash(newnick)]; Lusers[lu_hash(newnick)] = user; /* add user in server's userlist */ suser = (asuser *) MALLOC(sizeof(asuser)); suser->N = user; suser->next = serv->users[su_hash(newnick)]; serv->users[su_hash(newnick)] = suser; #ifdef NICKSERV nserv_nick(newnick, user); #endif } else { /* nick change */ #if 0 if (!strcasecmp(source, DEFAULT_NICKNAME) && strcasecmp(newnick, DEFAULT_NICKNAME)) { ChNick(DEFAULT_NICKNAME); } #endif if (!strcasecmp(newnick, mynick)) { #ifdef DEBUG printf("ARGH!!! I'M NICK COLLIDED!\n"); #endif GetWord(0, body, TS); if (atol(TS + 1) <= logTS) { NickInUse(); log(source); log(newnick); log(body); } else { onquit(source); return; /*ignore */ } } u = &Lusers[lu_hash(source)]; while (*u && strcasecmp(source, (*u)->nick)) u = &(*u)->next; user = *u; #ifdef NICKSERV nserv_nick(newnick, user); #endif if (user == NULL) quit("ERROR! onnick() can't find user", 1); s = &user->server->users[su_hash(source)]; while (*s && strcasecmp((*s)->N->nick, user->nick)) s = &(*s)->next; suser = *s; /* change the nick in memory */ TTLALLOCMEM -= strlen(user->nick) + 1; free(user->nick); user->nick = (char *)MALLOC(strlen(newnick) + 1); strcpy(user->nick, newnick); /* now relocate the structure */ *u = user->next; user->next = Lusers[lu_hash(newnick)]; Lusers[lu_hash(newnick)] = user; *s = suser->next; suser->next = user->server->users[su_hash(newnick)]; user->server->users[su_hash(newnick)] = suser; /* NICK FLOOD PROTECTION */ /* 1st wipe old nick changes off */ chan = user->channel; while (chan) { curr = chan->nickhist; prec = NULL; /* if not on channel.. ignore nick flood pro */ if (!chan->N->on) { chan = chan->next; continue; /* yurk.. as bad as a goto ;) */ } while (curr) { if (curr->time < (now - 15)) { if (prec) { prec->next = curr->next; TTLALLOCMEM -= sizeof(anickchange); free(curr); curr = prec->next; } else { chan->nickhist = curr->next; TTLALLOCMEM -= sizeof(anickchange); free(curr); curr = chan->nickhist; } } else { prec = curr; curr = curr->next; } } /* now add the new nick change to the history */ curr = (anickchange *) MALLOC(sizeof(anickchange)); strcpy(curr->nick, source); curr->time = now; /* a lil confusing :( */ curr->next = chan->nickhist; chan->nickhist = curr; /* now count the nick changes in history if there are more than allowed.. grrrr */ for (i = 0, curr = chan->nickhist; curr; curr = curr->next, i++); if (i == chan->N->NickFloodPro && chan->N->NickFloodPro != 0 && chan->N->on) { sprintf(buffer, "%s!%s@%s", user->nick, user->username, user->site); notice(newnick, "### NICK FLOOD PROTECTION ACTIVATED ###"); sprintf(buffer, "%s %d", newnick, NICK_FLOOD_SUSPEND_TIME); suspend("", chan->N->name, buffer); ban("", chan->N->name, newnick); } chan = chan->next; } } }