void NaCl::loop(int32_t) { const double MS_PER_FRAME = 1.0/60.0; game.update(MS_PER_FRAME); game.draw(0.0); context.SwapBuffers(callback_factory.NewCallback(&NaCl::loop)); // Flush log flushLogs(); // Flush messages if(accumulatedEvents.Get("isDirty").AsBool()) { PostMessage(accumulatedEvents); this->resetAccumulatedEvents(); } }
/** * \brief Used at services startup to connect to its uplink * \param hostname Hostname of uplink * \param IRC port * Returns a file descriptor of a connected socket if successful. */ int ConnectToServer(char *hostname, int portnum) { fd_set wfd, xfd; struct sockaddr_in sa; struct hostent *hp; int s; if ((hp = gethostbyname(hostname)) == NULL) { errno = ECONNREFUSED; return (-1); } bzero(&sa, sizeof(sa)); bcopy(hp->h_addr, (char *)&sa.sin_addr, hp->h_length); /* set address */ sa.sin_family = hp->h_addrtype; sa.sin_port = htons((u_short) portnum); if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) /* get socket */ return (-1); if (connect(s, (struct sockaddr *)&sa, sizeof sa) < 0) { /* connect */ printf("Error: %s\n", strerror(errno)); close(s); return (-1); } /* * whoo hoo, we got connected. For some reason, if we don't pause here a * little while, we loose. XXX This should be fixed... */ FD_ZERO(&wfd); FD_ZERO(&xfd); FD_SET(s, &wfd); FD_SET(s, &xfd); if (select(s + 2, NULL, &wfd, &xfd, NULL) < 0 || !FD_ISSET(s, &wfd) || FD_ISSET(s, &xfd)) { logDump(corelog, "Error occured while attempting to establish connection [%d]", errno); flushLogs(NULL); sshutdown(2); } return (s); }
void TProfiler::profile() { QDir rootDir; rootDir.mkdir(_dir1); rootDir.mkdir(_dir2); _hashDir[0] = QDir(rootDir.absolutePath() + "/" + _dir1); _hashDir[1] = QDir(rootDir.absolutePath() + "/" + _dir2); clean(_hashDir[0]); clean(_hashDir[1]); for (int i = 0; i < _steps.size(); ++i) { for (int numberOfPackages = _steps[i].begin; numberOfPackages < _steps[i].end; numberOfPackages += _steps[i].step) { qDebug() << numberOfPackages; for (int hasher = 0; hasher < 2; ++hasher) { DataBase base( _hashDir[hasher].absolutePath() + "/" + QString::number(numberOfPackages) + ".db", _dbSize, numberOfPackages, _hashers[hasher]); base.buildDB(_source, _recToRead); searchInDB(&base); logResult(numberOfPackages, hasher); cleanResult(); } } } #ifdef DEBUG4 qDebug() << _ro[0]; qDebug() << _ro[1]; qDebug(); qDebug() << _over[0]; qDebug() << _over[1]; #endif flushLogs(); }
/* * WARNING WARNING WARNING * * This function is very ugly in terms of args handling, and it is * very easy to inadvertently break something if you make small tweaks * to it. * * args and numargs do NOT always map together in this function, * for example numargs = 3, means that args really has 3+3=6 elements * in some points: numargs should be numargs2. * * Basically, the bottom two elements of args[] are dropped * in this function when * it goes to args2 to call the particular handlers -Mysid */ void parseLine(char *line) { int i = 0, a = 0, x = 0, prefixed = 0; char *args2[MAX_IRC_LINE_LEN + 5]; char *args[MAX_IRC_LINE_LEN + 5]; char realargs[151][151]; u_int16_t numargs = 0; /* * Seems Ok to me ^^^ * sizes may be off(?) */ /* Yes, your sizes were off.. -Mysid */ strncpyzt(coreBuffer, line, MAX_IRC_LINE_LEN); #ifdef DEBUG printf("Read: %s\n", coreBuffer); #endif CTime = time(NULL); while (*line && x < 150) { while (*line != ' ' && *line && a < 150) { realargs[x][a] = *line; a++; line++; } realargs[x][a] = 0; args[x] = realargs[x]; x++; numargs++; while (*line == ' ') line++; a = 0; } /* ensure the next item is null so we can check it later */ realargs[x][0] = 0; args[x] = realargs[x]; if (args[0][0] == ':') { prefixed = 1; /** \bug old lame bugfix, what would be better is to use a 'from' value and args++'ing it, if there's no prefix then have from set to the uplink -Mysid */ args[0]++; } else prefixed = 0; if (!strcmp(args[0], "PING") && !prefixed) { sSend("PONG :%s", myname); return; } else if (!strcmp(args[0], "ERROR") && !strcmp(args[1], ":Closing")) sshutdown(0); else if (!strcmp(args[0], "NICK") && !prefixed) { if (strchr(args[4], '*') || strchr(args[4], '?') || strchr(args[4], '!') || strchr(args[4], '@')) { char nick[NICKLEN]; strncpyzt(nick, args[1], NICKLEN); sSend (":%s KILL %s :%s!%s (Your ident reply contains either a *, !, @, or ?. Please remove this before returning.)", services[1].name, nick, services[1].host, services[1].name); addGhost(nick); timer(15, delTimedGhost, strdup(nick)); return; } addNewUser(args, numargs); /* nickserv.c, add new user. */ return; } if (!strcmp(args[1], "PRIVMSG")) { UserList *tmp = getNickData(args[0]); if (strchr(args[2], '#') || strchr(args[2], '$')) return; if (!strcasecmp(args[0], NickServ) || !strcasecmp(args[0], GameServ) || !strcasecmp(args[0], OperServ) || !strcasecmp(args[0], ChanServ) || !strcasecmp(args[0], MemoServ) || !strcasecmp(args[0], InfoServ)) return; if (tmp && tmp->reg && tmp->reg->flags & NBANISH) { sSend(":%s NOTICE %s :This nickname is banished." " You cannot use services until you change" " nicknames.", NickServ, args[0]); return; } if (!tmp) { nDesynch(args[0], "PRIVMSG"); return; } if (addFlood(tmp, 1)) return; if (getBanInfo(tmp->nick, tmp->user, tmp->host, A_IGNORE) != NULL) { if (tmp->floodlevel.GetLev() < 2) sSend (":%s NOTICE %s :You are on services ignore, you may not use any Service", NickServ, tmp->nick); if (!isOper(tmp) || tmp->caccess < ACC_RECOGNIZED || !tmp->reg || !(tmp->reg->opflags & OROOT)) return; } args[3]++; while (*args[3] == ' ') args[3]++; for (i = 3; i < numargs; i++) args2[i - 3] = args[i]; numargs -= 3; /* Handle pings before even going to the services */ if (!strcasecmp(args2[0], "\001PING")) { if (addFlood(tmp, 3)) return; if (numargs < 3) sSend(":%s NOTICE %s :\001PING %s", args[2], args[0], args2[1]); else sSend(":%s NOTICE %s :\001PING %s %s", args[2], args[0], args2[1], args2[2]); return; } /* NOTE: numargs maps to args2 not args at this point */ if (!strncasecmp(args[2], OperServ, strlen(OperServ))) sendToOperServ(tmp, args2, numargs); else if (!strncasecmp(args[2], NickServ, strlen(NickServ))) sendToNickServ(tmp, args2, numargs); else if (!strncasecmp(args[2], ChanServ, strlen(ChanServ))) sendToChanServ(tmp, args2, numargs); else if (!strncasecmp(args[2], MemoServ, strlen(MemoServ))) sendToMemoServ(tmp, args2, numargs); else if (!strncasecmp(args[2], InfoServ, strlen(InfoServ))) sendToInfoServ(tmp, args2, numargs); else if (!strncasecmp(args[2], GameServ, strlen(GameServ))) sendToGameServ(tmp, args2, numargs); else if (isGhost(args[2])) { sSend (":%s NOTICE %s :This is a NickServ registered nick enforcer, and not a real user.", args[2], args[0]); } /* Note, the below should be correct. */ else if ((numargs >= 1) && adCheck(tmp, args[2], args2, numargs)) return; return; } else if (!strcmp(args[1], "QUIT")) { remUser(args[0], 0); return; } else if (!strcmp(args[1], "NICK")) { UserList *tmp = getNickData(args[0]); if (addFlood(tmp, 5)) return; changeNick(args[0], args[2], args[3]); return; } else if (!strcmp(args[1], "MODE") && !strcmp(args[0], args[2])) { setMode(args[0], args[3]); return; } else if (!strcmp(args[1], "MODE")) { setChanMode(args, numargs); return; } else if (!strcmp(args[1], "TOPIC")) { setChanTopic(args, numargs); return; } else if (!strcmp(args[1], "AWAY")) { if (numargs < 3) { setFlags(args[0], NISAWAY, '-'); checkMemos(getNickData(args[0])); } else setFlags(args[0], NISAWAY, '+'); return; } else if (!strcmp(args[1], "JOIN")) { addUserToChan(getNickData(args[0]), args[2]); return; } else if (!strcmp(args[1], "PART")) { remUserFromChan(getNickData(args[0]), args[2]); return; } else if (!strcmp(args[1], "KICK")) { remUserFromChan(getNickData(args[3]), args[2]); return; } else if (!strcmp(args[1], "KILL")) { int i; for (i = 0; i < NUMSERVS; i++) { if (!strcasecmp(args[2], services[i].name)) { addUser(services[i].name, services[i].uname, services[i].host, services[i].rname, services[i].mode); sSend(":%s KILL %s :%s!%s (services kill protection)", services[i].name, args[0], services[i].host, services[i].name); sSend(":%s GLOBOPS :%s just killed me!", services[i].name, args[0]); remUser(args[0], 0); return; } } if (isGhost(args[2])) { delGhost(args[2]); return; } else remUser(args[2], 1); return; } else if (!strcmp(args[1], "MOTD")) { UserList *tmp = getNickData(args[0]); if (addFlood(tmp, 1)) return; motd(args[0]); return; } else if (!strcmp(args[1], "INFO")) { UserList *tmp = getNickData(args[0]); if (!tmp || addFlood(tmp, 3)) return; sendInfoReply(tmp); return; } else if (!strcmp(args[1], "VERSION")) { UserList *tmp = getNickData(args[0]); if (addFlood(tmp, 1)) return; sSend(":%s 351 %s %s %s :%s", myname, args[0], VERSION_STRING, myname, VERSION_QUOTE); return; } else if ((!strcmp(args[1], "GNOTICE") || !strcmp(args[1], "GLOBOPS")) && !strcmp(args[2], ":Link") && !strcmp(args[3], "with") && !strncmp(args[4], myname, strlen(myname))) { sSend(":%s GNOTICE :Link with %s[services@%s] established.", myname, args[0], hostname); strncpyzt(hostname, args[0], sizeof(hostname)); expireNicks(NULL); expireChans(NULL); sync_cfg("1"); checkTusers(NULL); flushLogs(NULL); nextNsync = (SYNCTIME + CTime); nextCsync = ((SYNCTIME * 2) + CTime); nextMsync = ((SYNCTIME * 3) + CTime); loadakills(); return; } #ifdef IRCD_HURTSET else if (!strcmp(args[1], "HURTSET") && (numargs >= 4)) { UserList *hurtwho; if ((hurtwho = getNickData(args[2]))) { if (args[3] && *args[3] == '-') hurtwho->oflags &= ~(NISAHURT); else if (args[3] && atoi(args[3]) == 4) { hurtwho->oflags |= (NISAHURT); } else if (args[3] && isdigit(*args[3]) && (getBanInfo(hurtwho->nick, hurtwho->user, hurtwho->host, A_AHURT) != NULL)) hurtwho->oflags |= (NISAHURT); } } #endif else if (!strcmp(args[1], "SQUIT")) { time_t jupe; jupe = time(NULL); if (strchr(args[2], '.')) return; sSend(":%s WALLOPS :%s Un-jupitered by %s at %s", myname, args[2], args[0], ctime(&(jupe))); return; } else if (!strcmp(args[1], "STATS") && numargs > 3) { const char* from = args[0]; if (args[2] && !strcasecmp(args[2], "OPTS")) { sSend(":%s NOTICE %s :Network name: %s", InfoServ, from, NETWORK); #ifdef AKILLMAILTO sSend(":%s NOTICE %s :Akill log address: %s", InfoServ, from, AKILLMAILTO); #endif #ifdef ENABLE_GRPOPS sSend(":%s NOTICE %s :GRPops enabled.", InfoServ, from); #endif #ifdef MD5_AUTH sSend(":%s NOTICE %s :MD5 authentication available.", InfoServ, from); #endif } else if (args[2] && !strcasecmp(args[2], "V$")) { sSend(":%s NOTICE %s :Based on sn services1.4.", InfoServ, from); } } /* "No N-line" error */ else if (!strcmp(args[0], "ERROR") && !strcmp(args[1], ":No")) { fprintf(stderr, "Error connecting to server: No N-line\n"); sshutdown(2); } }