void plexus_cmd_privmsg(char *source, char *dest, char *buf) { Uid *ud, *ud2; ud = find_uid(source); ud2 = find_uid(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "PRIVMSG %s :%s", (UseTS6 ? (ud2 ? ud2->uid : dest) : dest), buf); }
void plexus_cmd_motd(char *sender, char *server) { Uid *ud; ud = find_uid(sender); send_cmd((ud ? ud->uid : sender), "MOTD %s", server); }
void plexus_cmd_stats(char *sender, const char *letter, char *server) { Uid *ud; ud = find_uid(sender); send_cmd((ud ? ud->uid : sender), "STATS %s %s", letter, server); }
void plexus_cmd_version(char *server) { Uid *ud; ud = find_uid(s_StatServ); send_cmd((ud ? ud->uid : s_StatServ), "VERSION %s", server); }
void plexus_cmd_join(char *user, char *channel, time_t chantime) { Uid *ud; ud = find_uid(user); send_cmd(NULL, "SJOIN %ld %s + :%s", (long int) chantime, channel, (UseTS6 ? (ud ? ud->uid : user) : user)); }
/* GLOBOPS */ void asuka_cmd_global(char *source, char *buf) { Uid *id; id = find_uid(source); send_cmd((id ? id->uid : ServerName), "WA :%s", buf); }
/* ABAAA L #ircops */ void asuka_cmd_part(char *nick, char *chan, char *buf) { Uid *ud; ud = find_uid(nick); if (buf) { send_cmd((ud ? ud->uid : nick), "L %s :%s", chan, buf); } else { send_cmd((ud ? ud->uid : nick), "L %s", chan); } }
void plexus_cmd_notice(char *source, char *dest, char *buf) { Uid *ud; User *u; ud = find_uid(source); u = finduser(dest); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "NOTICE %s :%s", (UseTS6 ? (u ? u->uid : dest) : dest), buf); }
void asuka_cmd_version(char *server) { Uid *ud; Server *s; ud = find_uid(s_StatServ); s = server_find(server); send_cmd((ud ? ud->uid : s_StatServ), "V :%s", (s ? (s->suid ? s->suid : server) : server)); }
void asuka_cmd_motd(char *sender, char *server) { Uid *ud; Server *s; ud = find_uid(sender); s = server_find(server); send_cmd((ud ? ud->uid : sender), "MO :%s", (s ? (s->suid ? s->suid : server) : server)); }
/* QUIT */ void nefarious_cmd_quit(char *source, char *buf) { Uid *ud; ud = find_uid(source); if (buf) { send_cmd((ud ? ud->uid : source), "QUIT :%s", buf); } else { send_cmd((ud ? ud->uid : source), "QUIT"); } }
void asuka_cmd_privmsg(char *source, char *dest, char *buf) { User *u; Uid *ud; u = finduser(dest); ud = find_uid(source); send_cmd((ud ? ud->uid : source), "P %s :%s", (u ? u->uid : dest), buf); }
/* QUIT */ void asuka_cmd_quit(char *source, char *buf) { Uid *ud; ud = find_uid(source); if (buf) { send_cmd((ud ? ud->uid : source), "Q :%s", buf); } else { send_cmd((ud ? ud->uid : source), "Q"); } }
void nefarious_cmd_notice(char *source, char *dest, char *buf) { User *u; Uid *ud; u = finduser(dest); ud = find_uid(source); send_cmd((ud ? ud->uid : source), "O %s :%s", (u ? u->uid : dest), buf); }
void asuka_cmd_stats(char *sender, const char *letter, char *server) { Uid *ud; Server *s; ud = find_uid(sender); s = server_find(server); send_cmd((ud ? ud->uid : sender), "R %s :%s", letter, (s ? (s->suid ? s->suid : server) : server)); }
void scarynet_cmd_ping(char *server) { Uid *ud; Server *s; struct timeval t; ud = find_uid(s_StatServ); s = server_find(server); gettimeofday(&t, NULL); send_cmd(p10id, "RI %s %s %ld %ld :<No client start time>", ((s && s->suid) ? s->suid : server), (ud ? ud->uid : s_StatServ), t.tv_sec, t.tv_usec); }
/* AB B #opserv 1116184708 +smtin AKAAA:o */ void asuka_cmd_join(char *user, char *channel, time_t chantime) { Uid *ud; ud = find_uid(user); if (started) { send_cmd((ud ? ud->uid : user), "J %s %ld", channel, (long int) chantime); } else { send_cmd(p10id, "B %s %ld %s:o", channel, (long int) time(NULL), (ud ? ud->uid : user)); } }
void plexus_cmd_mode(char *source, char *dest, char *buf) { Uid *ud; if (source) { ud = find_uid(source); send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "MODE %s %s", dest, buf); } else { send_cmd(source, "MODE %s %s", dest, buf); } }
/* QUIT */ void plexus_cmd_quit(char *source, char *buf) { Uid *ud; ud = find_uid(source); if (buf) { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "QUIT :%s", buf); } else { send_cmd((UseTS6 ? (ud ? ud->uid : source) : source), "QUIT"); } }
void plexus_cmd_part(char *nick, char *chan, char *buf) { Uid *ud; ud = find_uid(nick); if (buf) { send_cmd((UseTS6 ? ud->uid : nick), "PART %s :%s", chan, buf); } else { send_cmd((UseTS6 ? ud->uid : nick), "PART %s", chan); } }
void nefarious_cmd_ping(char *server) { /* AB G !1115872042.64217 denora.nomadirc.net 1115872042.64217 * [OUT]: AB RI AL ABAAB 1165972073 45741 :<No client start time> * [IN ]: AL RO ScaryNet.Org ABAAB 1165972073 45741 :<No client start time> */ Uid *ud; Server *s; struct timeval t; ud = find_uid(s_StatServ); s = server_find(server); gettimeofday(&t, NULL); send_cmd(p10id, "RI %s %s %ld %ld :<No client start time>", ((s && s->suid) ? s->suid : server), (ud ? ud->uid : s_StatServ), t.tv_sec, t.tv_usec); }
dbref find_uid(dbref player, struct frame * fr, int st, dbref program) { if ((FLAGS(program) & STICKY) || (fr->perms == STD_SETUID)) { if (FLAGS(program) & HAVEN) { if ((st > 1) && (TrueWizard(OWNER(program)))) return (find_uid(player, fr, st - 1, fr->caller.st[st - 1])); return (OWNER(program)); } return (OWNER(program)); } if (ProgMLevel(program) < 2) return (OWNER(program)); if ((FLAGS(program) & HAVEN) || (fr->perms == STD_HARDUID)) { if (fr->trig == NOTHING) return (OWNER(program)); return (OWNER(fr->trig)); } return (OWNER(player)); }
void plexus_cmd_global(char *source, char *buf) { Uid *u; if (source) { u = find_uid(source); if (u) { send_cmd((UseTS6 ? u->uid : source), "OPERWALL :%s", buf); } else { send_cmd((UseTS6 ? TS6SID : ServerName), "OPERWALL :%s", buf); } } else { send_cmd((UseTS6 ? TS6SID : ServerName), "OPERWALL :%s", buf); } }
/* ABAAB J #ircops 1098031328 */ void nefarious_cmd_join(char *user, char *channel, time_t chantime) { Uid *ud; char *modes = NULL; ud = find_uid(user); if (started) { send_cmd((ud ? ud->uid : user), "J %s %ld", channel, (long int) chantime); } else { if (AutoOp && AutoMode) { modes = sstrdup(AutoMode); modes++; /* since the first char is +, we skip it */ send_cmd(p10id, "B %s %ld %s:%s", channel, (long int) chantime, (ud ? ud->uid : user), modes); } else { send_cmd(p10id, "B %s %ld %s", channel, (long int) chantime, (ud ? ud->uid : user)); } } }
static time_t check_pings(time_t currenttime) { #ifdef TIMEDKLINES static time_t lkill = 0; #endif Reg aClient *cptr; Reg int kflag = 0; aClient *bysptr = NULL; int ping = 0, i; time_t oldest = 0, timeout; char *reason = NULL; for (i = highest_fd; i >= 0; i--) { if (!(cptr = local[i]) || IsListener(cptr)) continue; #ifdef TIMEDKLINES kflag = 0; reason = NULL; /* ** Once per TIMEDKLINES seconds. ** (1 minute is minimum resolution in K-line field) */ if ((currenttime - lkill > TIMEDKLINES) && IsPerson(cptr) && !IsKlineExempt(cptr)) { kflag = find_kill(cptr, 1, &reason); } #endif ping = IsRegistered(cptr) ? cptr->ping : ACCEPTTIMEOUT; Debug((DEBUG_DEBUG, "c(%s) %d p %d k %d a %d", cptr->name, cptr->status, ping, kflag, currenttime - cptr->lasttime)); /* * Ok, so goto's are ugly and can be avoided here but this code * is already indented enough so I think its justified. -avalon */ if (!kflag && IsRegistered(cptr) && (ping >= currenttime - cptr->lasttime)) goto ping_timeout; /* * If the server hasnt talked to us in 2*ping seconds * and it has a ping time, then close its connection. * If the client is a user and a KILL line was found * to be active, close this connection too. */ if (kflag || ((currenttime - cptr->lasttime) >= (2 * ping) && (cptr->flags & FLAGS_PINGSENT)) || (!IsRegistered(cptr) && (currenttime - cptr->firsttime) >= ping)) { if (!IsRegistered(cptr) && (DoingDNS(cptr) || DoingAuth(cptr) || DoingXAuth(cptr))) { if (cptr->authfd >= 0) { (void)close(cptr->authfd); cptr->authfd = -1; cptr->count = 0; *cptr->buffer = '\0'; } Debug((DEBUG_NOTICE, "%s/%c%s timeout %s", (DoingDNS(cptr)) ? "DNS" : "dns", (DoingXAuth(cptr)) ? "X" : "x", (DoingAuth(cptr)) ? "AUTH" : "auth", get_client_name(cptr,TRUE))); del_queries((char *)cptr); ClearAuth(cptr); #if defined(USE_IAUTH) if (DoingDNS(cptr) || DoingXAuth(cptr)) { if (DoingDNS(cptr) && (iauth_options & XOPT_EXTWAIT)) { /* iauth wants more time */ sendto_iauth("%d d", cptr->fd); ClearDNS(cptr); cptr->lasttime = currenttime; continue; } if (DoingXAuth(cptr) && (iauth_options & XOPT_NOTIMEOUT)) { cptr->exitc = EXITC_AUTHTOUT; sendto_iauth("%d T", cptr->fd); exit_client(cptr, cptr, &me, "Authentication Timeout"); continue; } sendto_iauth("%d T", cptr->fd); SetDoneXAuth(cptr); } #endif ClearDNS(cptr); ClearXAuth(cptr); ClearWXAuth(cptr); cptr->firsttime = currenttime; cptr->lasttime = currenttime; continue; } if (IsServer(cptr) || IsConnecting(cptr) || IsHandshake(cptr)) { if (cptr->serv && cptr->serv->byuid[0]) { bysptr = find_uid(cptr->serv->byuid, NULL); } /* we are interested only in *remote* opers */ if (bysptr && !MyConnect(bysptr)) { sendto_one(bysptr, ":%s NOTICE %s :" "No response from %s, closing" " link", ME, bysptr->name, get_client_name(cptr, FALSE)); } sendto_flag(SCH_NOTICE, "No response from %s closing link", get_client_name(cptr, FALSE)); } /* * this is used for KILL lines with time restrictions * on them - send a message to the user being killed * first. */ if (kflag && IsPerson(cptr)) { char buf[100]; sendto_flag(SCH_NOTICE, "Kill line active for %s", get_client_name(cptr, FALSE)); cptr->exitc = EXITC_KLINE; if (!BadPtr(reason)) sprintf(buf, "Kill line active: %.80s", reason); (void)exit_client(cptr, cptr, &me, (reason) ? buf : "Kill line active"); } else { cptr->exitc = EXITC_PING; (void)exit_client(cptr, cptr, &me, "Ping timeout"); } continue; } else if (IsRegistered(cptr) && (cptr->flags & FLAGS_PINGSENT) == 0) { /* * if we havent PINGed the connection and we havent * heard from it in a while, PING it to make sure * it is still alive. */ cptr->flags |= FLAGS_PINGSENT; /* not nice but does the job */ cptr->lasttime = currenttime - ping; sendto_one(cptr, "PING :%s", me.name); } ping_timeout: timeout = cptr->lasttime + ping; while (timeout <= currenttime) timeout += ping; if (timeout < oldest || !oldest) oldest = timeout; } #ifdef TIMEDKLINES if (currenttime - lkill > 60) lkill = currenttime; #endif if (!oldest || oldest < currenttime) oldest = currenttime + PINGFREQUENCY; if (oldest < currenttime + 30) oldest += 30; Debug((DEBUG_NOTICE,"Next check_ping() call at: %s, %d %d %d", myctime(oldest), ping, oldest, currenttime)); return (oldest); }
int main (int argc, char *argv[]) { fd_set readset; fd_set writeset; int n, sel; int c, errflg=0; struct sigaction sigact; sigset_t sigmask; char *scratch, *next_scratch; char nmea_buf[1024]; char send_buf[1024]; int gps_buf[15]; int nmea_index = 0; int send_len = 0; /* Set default options */ outfile = stdout; int sAnt = 0; memset(gps_buf, 0, 15); memset(send_buf, 0, 1024); send_len = 0; /* Process options */ while ((c = getopt(argc, argv, "Vlqvs:o:p:t:m:u:g:/:")) != EOF) switch (c) { case 'q': quiet=1; break; case 'v': verbose = 1; break; case 'l': linebuff = 1; break; case 'p': opt_ptyname = optarg; break; case 't': opt_ttyname = optarg; break; case 'm': /* mode for pty: [user,[group,]]mode */ scratch = strdup(optarg); if ((next_scratch = strchr(scratch,',')) != NULL) { /* Username */ *next_scratch = '\0'; next_scratch++; frontend_owner = find_uid(scratch); scratch = next_scratch; if ((next_scratch = strchr(scratch,',')) != NULL) { /* Group */ *next_scratch = '\0'; next_scratch++; frontend_group = find_gid(scratch); scratch = next_scratch; } } frontend_mode = strtol(scratch,NULL,8); break; case 'u': switch_uid = find_uid(optarg); break; case 'g': switch_gid = find_gid(optarg); break; case '/': switch_root = strdup(optarg); break; case 's': settings = optarg; break; case 'o': outfilename=optarg; if ( (outfile = fopen(outfilename,"w")) == NULL) errorf("Couldn't open output file '%s' for write: %s\n",outfilename,strerror(errno)); break; case 'V': puts(VERSION); exit(0); case '?': default: errflg++; break; } if (errflg || ((argc-optind) < 1) || ((argc-optind) > 2)) { usage(argv[0]); exit (2); } /* Process the two non-flag options */ backend = argv[optind]; if ((argc-optind) == 2) frontend = argv[optind+1]; if (strcmp(frontend,"-") == 0) frontend = NULL; if (linebuff) setlinebuf(outfile); atexit (closedown); /* Do some initialization */ stty_initstore(); sendudp_open(); /* Setup backend */ if (setup_backend(backfd) < 0) errorf ("select failed. errno = %d\n", errno); /* Setup frontend */ if ((setup_frontend(frontfd)) < 0) errorf("setup_frontend failed: %s\n",strerror(errno)); /* Drop privileges if we've been asked to */ if (switch_root) { if (chroot(switch_root) != 0) errorf("chroot(%s) failed: %s\n",switch_root,strerror(errno)); } if (switch_gid != -1) { if (setgroups(1,&switch_gid) == -1) errorf("setgroups(1,[%d]) failed: %s\n",switch_gid, strerror(errno)); if (setregid(switch_gid, switch_gid) == -1) errorf("setregid(%d,%d) failed: %s\n",switch_gid,switch_gid); if (getgid() != switch_gid) errorf("setregid succeeded, but we're the wrong gid!"); if (getegid() != switch_gid) errorf("setregid succeeded, but we're the wrong effective gid!"); } if (switch_uid != -1) { if (setreuid(switch_uid, switch_uid) == -1) errorf("setreuid(%d,%d) failed: %s\n",switch_uid,switch_uid,strerror(errno)); if (getuid() != switch_uid) errorf("setreuid succeeded, but we're the wrong uid!"); if (geteuid() != switch_uid) errorf("setregid succeeded, but we're the wrong effective uid!"); } /* calc (initial) max file descriptor to use in select() */ fdmax = max(backfd[0], frontfd[0]); /* Set up signal handlers and such */ sigemptyset(&sigmask); memset(&sigact,0,sizeof sigact); sigact.sa_handler = sigdeath; sigact.sa_mask = sigmask; sigaction(SIGHUP,&sigact,NULL); sigaction(SIGINT,&sigact,NULL); sigaction(SIGQUIT,&sigact,NULL); sigaction(SIGPIPE,&sigact,NULL); sigaction(SIGTERM,&sigact,NULL); sigact.sa_handler = sigchld; sigaction(SIGCHLD,&sigact,NULL); pthread_t udp_recv; pthread_create(&udp_recv, NULL, udp_recv_gnssmode_thread, NULL); pthread_detach(udp_recv); struct tm p; time_t timep; while (!please_die_now) { do { FD_ZERO (&readset); FD_SET (backfd[0], &readset); FD_SET (frontfd[0], &readset); FD_ZERO (&writeset); FD_SET (backfd[1], &writeset); FD_SET (frontfd[1], &writeset); sel = select(fdmax + 1, &readset, &writeset, NULL, NULL); } while (sel == -1 && errno == EINTR && !please_die_now); if (sel == -1 && errno != EINTR) errorf ("select failed. errno = %d\n", errno); else if (please_die_now) break; if (FD_ISSET(backfd[0], &readset)) { if ((n = read(backfd[0], buff, BUFF_SIZE)) == 0) { /* Serial port has closed. This doesn't really make sense for * a real serial port, but for sockets and programs, probably * we should just exit. */ if (!quiet) errorf("Backend device was closed.\n"); break; } else if (n < 0) { if ( (errno != EAGAIN) && (errno != EINTR) ) { errorf("Error reading from backend device: %s\n",strerror(errno)); } break; } else { /* We should handle this better. FIX */ if(FD_ISSET(frontfd[1], &writeset)) { if (write (frontfd[1], buff, n) != n) errorf("Error writing to frontend device: %s\n",strerror(errno)); } // if (!quiet) // dumpbuff(1,buff,n); //nmea decode { tNmea_Msg nmeamsg ; int i=0; int ret = 0; for(i=0; i<n; i++) { if(buff[i] == '$') nmea_index = 0; nmea_buf[nmea_index] = buff[i]; if(buff[i] == '\r') nmea_buf[nmea_index] = 0; if(buff[i] == '\n') { nmea_buf[nmea_index] = 0; #if 0 if (!quiet) fprintf(outfile,"%s\n",nmea_buf); #endif #if 1 ret = NmeaDecode(nmea_buf,&nmeamsg); if(nmeamsg.nMsgMask == GGA_DECODE) { memset(send_buf, 0, 1024); send_len = 0; } memcpy(send_buf+send_len, nmea_buf, nmea_index); send_len += strlen(nmea_buf); send_buf[send_len] = 0x0D; send_len ++; if(nmeamsg.nMsgMask & ANT_DECODE) { sAnt = nmeamsg.nAnttenaStatus; //sendudp(1011,&sAnt, 4); //gui sAnt |= (nmeamsg.version<<8); } if(nmeamsg.nMsgMask & RMC_DECODE) { if (nmea_buf[3] == 'R' && nmea_buf[4] == 'M' && nmea_buf[5] == 'C' ) { if (!quiet) fprintf(outfile,"%s=len=%d\n",nmea_buf, strlen(nmea_buf)); sendudp(1014,nmea_buf, strlen(nmea_buf)); //busdemaon } } if(nmeamsg.nMsgMask >= 0x8F) { sendudp(1012, send_buf, send_len); sendudp(1011,&nmeamsg.aSvInfo, 2*sizeof(tSVData)); //gui satelite display if (!quiet) { //fprintf(outfile,"\r\n\r\n%s---------send_len=%d\n\n",send_buf,send_len); fprintf(outfile,"nAnttenaStatus=%d,position=%c mode=%d fy=%f fx=%f (%d-%d-%d)(%d:%d:%f)\n", sAnt, nmeamsg.cFixFlag, NmeaGetRxRunMode(), nmeamsg.fLatInDegree, nmeamsg.fLonInDegree, nmeamsg.usYear, nmeamsg.ucMonth, nmeamsg.ucDay, nmeamsg.usHours, nmeamsg.usMinutes, nmeamsg.fSeconds); } #if 1 localtime_r(&timep, &p); p.tm_sec = (int)nmeamsg.fSeconds; p.tm_min = nmeamsg.usMinutes; p.tm_hour = nmeamsg.usHours+8; p.tm_mday = nmeamsg.ucDay; p.tm_mon = nmeamsg.ucMonth-1; p.tm_year = nmeamsg.usYear + 100; timep = mktime(&p); if(nmeamsg.cFixFlag == 'A') gps_buf[0] = 1; else gps_buf[0] = 0; gps_buf[1] = nmeamsg.fLonInDegree*1000000; gps_buf[2] = nmeamsg.fLatInDegree*1000000; gps_buf[3] = (int)timep; gps_buf[4] = (int)timep; gps_buf[5] = nmeamsg.fHeading; gps_buf[6] = nmeamsg.fGroundVel*1.85; if(nmeamsg.cLatIdx == 'S') gps_buf[7] = 1; else gps_buf[7] = 0; if(nmeamsg.cLonIdx == 'W') gps_buf[8] = 1; else gps_buf[8] = 0; gps_buf[9] = nmeamsg.fAltitude; gps_buf[10] = NmeaGetRxRunMode(); gps_buf[11] = nmeamsg.aSvInfo[1].nSvsUsed; gps_buf[12] = nmeamsg.aSvInfo[0].nSvsUsed; gps_buf[13] = sAnt; #if 0 printf("position=%d, flon=%d, flat=%d, %d, %d, iOrientation=%d, vel=%d, s=%d, w=%d, alt=%d, mode=%d, gps=%d, bd=%d\n", gps_buf[0], gps_buf[1],gps_buf[2],gps_buf[3], gps_buf[4],gps_buf[5], gps_buf[6],gps_buf[7], gps_buf[8],gps_buf[9], gps_buf[10], gps_buf[11], gps_buf[12]); #endif sendudp(1013, gps_buf, 4*14); sendudp(1015, gps_buf, 4*14); //busdemaon memset(gps_buf, 0 , 15); #endif memset(send_buf, 0, 1024); send_len = 0; } #endif } nmea_index++; // fprintf(outfile,"nmea_index = %d\n",nmea_index); if(nmea_index >= 1024) nmea_index = 0; } } } } if (please_die_now) break; if (FD_ISSET(frontfd[0], &readset)) { if ((n = read(frontfd[0], buff, BUFF_SIZE)) == 0) { if (listenfd) { if (close(frontfd[0]) < 0) errorf("Couldn't close old frontfd: %s\n",strerror(errno)); if ((frontfd[0]=frontfd[1]=accept(listenfd,NULL,NULL)) < 0) errorf("Couldn't accept new socket connection: %s\n",strerror(errno)); } } else if (n <= 0) { if ( (errno == EAGAIN) || (errno == EINTR) ) { /* No real error */ } else { errorf("Error reading from frontend device: %s\n",strerror(errno)); } } else { if (write (backfd[1], buff, n) != n) errorf("Error writing to backend device: %s\n",strerror(errno)); if (!quiet) dumpbuff(0,buff,n); } } } stty_orig(); exit(0); }
/* ** send_queued ** This function is called from the main select-loop (or whatever) ** when there is a chance the some output would be possible. This ** attempts to empty the send queue as far as possible... */ int send_queued(aClient *to) { char *msg; int len, rlen, more = 0; aClient *bysptr = NULL; /* ** Once socket is marked dead, we cannot start writing to it, ** even if the error is removed... */ if (IsDead(to)) { /* ** Actually, we should *NEVER* get here--something is ** not working correct if send_queued is called for a ** dead socket... --msa */ return -1; } #ifdef ZIP_LINKS /* ** Here, we must make sure than nothing will be left in to->zip->outbuf ** This buffer needs to be compressed and sent if all the sendQ is sent */ if ((to->flags & FLAGS_ZIP) && to->zip->outcount) { if (DBufLength(&to->sendQ) > 0) more = 1; else { msg = zip_buffer(to, NULL, &len, 1); if (len == -1) return dead_link(to, "fatal error in zip_buffer()"); if (dbuf_put(&to->sendQ, msg, len) < 0) { to->exitc = EXITC_MBUF; return dead_link(to, "Buffer allocation error for %s", get_client_name(to, FALSE)); } } } #endif while (DBufLength(&to->sendQ) > 0 || more) { msg = dbuf_map(&to->sendQ, &len); /* Returns always len > 0 */ if ((rlen = deliver_it(to, msg, len)) < 0) { if ( (IsConnecting(to) || IsHandshake(to)) && to->serv && to->serv->byuid[0]) { bysptr = find_uid(to->serv->byuid, NULL); if (bysptr && !MyConnect(bysptr)) { sendto_one(bysptr, ":%s NOTICE %s :" "Write error (%s) to %s, closing link", ME, bysptr->name, strerror(-rlen), to->name); } } return dead_link(to, "Write error (%s) to %s, closing link", strerror(-rlen), get_client_name(to, FALSE)); } (void)dbuf_delete(&to->sendQ, rlen); to->lastsq = DBufLength(&to->sendQ)/1024; if (rlen < len) /* ..or should I continue until rlen==0? */ break; #ifdef ZIP_LINKS if (DBufLength(&to->sendQ) == 0 && more) { /* ** The sendQ is now empty, compress what's left ** uncompressed and try to send it too */ more = 0; msg = zip_buffer(to, NULL, &len, 1); if (len == -1) return dead_link(to, "fatal error in zip_buffer()"); if (dbuf_put(&to->sendQ, msg, len) < 0) { to->exitc = EXITC_MBUF; return dead_link(to, "Buffer allocation error for %s", get_client_name(to, FALSE)); } } #endif } return (IsDead(to)) ? -1 : 0; }
static int do_chanstats(User * u, int ac, char **av) { char *cmd1 = NULL; char *cmd2 = NULL; char *cmd3 = NULL; char *cmd4 = NULL; lnode_t *tn; ChannelStats *cs; Channel *c; int i; int x = 0; char *sqlchan; Uid *ud; char *modes; char nickbuf[BUFSIZE]; *nickbuf = '\0'; if (ac >= 1) { cmd1 = av[0]; } if (ac >= 2) { cmd2 = av[1]; } if (ac >= 3) { cmd3 = av[2]; } if (ac >= 4) { cmd4 = av[3]; } if (cmd1) { /* Since ChanStats does require SQL code... */ if (!denora->do_sql) { notice_lang(s_StatServ, u, SQL_DISABLED); return MOD_CONT; } if (!stricmp("ADD", cmd1)) { if (LargeNet) { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_LARGENET); return MOD_CONT; } if (!cmd2) { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_ADD_SYNTAX); return MOD_CONT; } if (BadChanName(cmd2)) { notice_lang(s_StatServ, u, STAT_CHANSTATS_NOT_VALID_CHAN); return MOD_CONT; } if (strlen(cmd2) > CHANMAX) { notice_lang(s_StatServ, u, STAT_CHANSTATS_NOT_VALID_CHAN); return MOD_CONT; } if (LogChannel) { if (!stricmp(cmd2, LogChannel)) { notice_lang(s_StatServ, u, STAT_CHANSTATS_LOGCHAN); return MOD_CONT; } } if (!(cs = find_cs(cmd2))) { cs = makecs(cmd2); save_cs_db(); sqlchan = rdb_escape(cmd2); if (CSDefFlag) { if (CSDefFlag == 1) { cs->flags |= CS_FANTASY; cs->flags &= ~CS_NOTICE; } else if (CSDefFlag == 2) { cs->flags |= CS_FANTASY; cs->flags |= CS_NOTICE; } } rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, sqlchan); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, sqlchan); cs->timeadded = time(NULL); for (i = 0; i < 4; i++) { rdb_query (QUERY_LOW, "INSERT INTO %s SET chan=\'%s\', type=%i, timeadded=%ld;", CStatsTable, sqlchan, i, cs->timeadded); } notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_ADDED, cmd2); ud = find_uid(s_StatServ); if (PartOnEmpty) { c = findchan(cmd2); if (c) { denora_cmd_join(s_StatServ, cs->name, time(NULL)); if (AutoOp && AutoMode) { modes = sstrdup(AutoMode); while (*modes) { switch (*modes) { case '+': break; case '-': break; default: ircsnprintf(nickbuf, BUFSIZE, "%s %s", nickbuf, ((ircd->p10 && ud) ? ud->uid : s_StatServ)); } (void) *modes++; } denora_cmd_mode(ServerName, cs->name, "%s%s", AutoMode, nickbuf); } } } else { denora_cmd_join(s_StatServ, cs->name, time(NULL)); if (AutoOp && AutoMode) { modes = sstrdup(AutoMode); while (*modes) { switch (*modes) { case '+': break; case '-': break; default: ircsnprintf(nickbuf, BUFSIZE, "%s %s", nickbuf, ((ircd->p10 && ud) ? ud->uid : s_StatServ)); } (void) *modes++; } denora_cmd_mode(ServerName, cs->name, "%s%s", AutoMode, nickbuf); } } free(sqlchan); } else { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_ALREADY, cmd2); } } else if (!stricmp("DEL", cmd1)) { if (!cmd2) { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_DEL_SYNTAX); return MOD_CONT; } sqlchan = rdb_escape(cmd2); if ((cs = find_cs(cmd2))) { del_cs(cs); save_cs_db(); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, sqlchan); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, sqlchan); notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_DEL, cmd2); if (LogChannel) { if (stricmp(LogChannel, cmd2)) { denora_cmd_part(s_StatServ, cmd2, getstring(NULL, STATS_CHANSTATS_PART), cmd2); } } else { denora_cmd_part(s_StatServ, cmd2, getstring(NULL, STATS_CHANSTATS_PART), cmd2); } } else { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_NOTFOUND, cmd2); } free(sqlchan); } else if (!stricmp("LIST", cmd1)) { tn = list_first(CStatshead); while (tn != NULL) { cs = lnode_get(tn); notice(s_StatServ, u->nick, "%d %s", x, cs->name); x++; tn = list_next(CStatshead, tn); } if (!x) { notice_lang(s_StatServ, u, STATS_CHANSTATS_NOCHANNELS); } } else if (!stricmp("SUMUSER", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SUMUSER_SYNTAX); return MOD_CONT; } sumuser(u, cmd2, cmd3); } else if (!stricmp("RENAME", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_RENAMEUSER_SYNTAX); return MOD_CONT; } renameuser(u, cmd2, cmd3); } else if (!stricmp("SET", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); return MOD_CONT; } if (!(cs = find_cs(cmd2))) { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_NOTFOUND, cmd2); return MOD_CONT; } if (!stricmp("FANTASY", cmd3)) { if (!cmd4) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); return MOD_CONT; } if (!stricmp("ON", cmd4)) { cs->flags |= CS_FANTASY; cs->flags &= ~CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_ON, cmd2); } else if (!stricmp("OFF", cmd4)) { cs->flags &= ~CS_FANTASY; cs->flags &= ~CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_OFF, cmd2); } else if (!stricmp("NOTICE", cmd4)) { cs->flags |= CS_FANTASY; cs->flags |= CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_NOTICE, cmd2); } else { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); } } /* fantasy */ } else { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_SYNTAX); } } else { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_SYNTAX); } return MOD_CONT; }