本文整理汇总了C++中TStime函数的典型用法代码示例。如果您正苦于以下问题:C++ TStime函数的具体用法?C++ TStime怎么用?C++ TStime使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TStime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoEvents
void DoEvents(void)
#endif
{
Event *eventptr;
Event temp;
for (eventptr = events; eventptr; eventptr = eventptr->next)
{
if (eventptr->howmany == -1)
goto freeit;
if ((eventptr->every == 0) || ((TStime() - eventptr->last) >= eventptr->every))
{
eventptr->last = TStime();
(*eventptr->event)(eventptr->data);
if (eventptr->howmany > 0)
{
eventptr->howmany--;
if (eventptr->howmany == 0)
{
freeit:
temp.next = EventDel(eventptr);
eventptr = &temp;
continue;
}
}
}
}
}
示例2: do_chanflood
int do_chanflood(ChanFloodProt *chp, int what)
{
if (!chp || !chp->l[what]) /* no +f or not restricted */
return 0;
if (TStime() - chp->t[what] >= chp->per)
{
chp->t[what] = TStime();
chp->c[what] = 1;
} else
{
chp->c[what]++;
if ((chp->c[what] > chp->l[what]) &&
(TStime() - chp->t[what] < chp->per))
{
/* reset it too (makes it easier for chanops to handle the situation) */
/*
*XXchp->t[what] = TStime();
*XXchp->c[what] = 1;
*
* BAD.. there are some situations where we might 'miss' a flood
* because of this. The reset has been moved to -i,-m,-N,-C,etc.
*/
return 1; /* flood detected! */
}
}
return 0;
}
示例3: ban_fizzer
static void ban_fizzer(aClient *cptr)
{
int i;
aClient *acptr;
char hostip[128], mo[100], mo2[100];
char *tkllayer[9] = {
me.name, /*0 server.name */
"+", /*1 +|- */
"z", /*2 G */
"*", /*3 user */
NULL, /*4 host */
NULL,
NULL, /*6 expire_at */
NULL, /*7 set_at */
NULL /*8 reason */
};
strlcpy(hostip, Inet_ia2p(&cptr->ip), sizeof(hostip));
tkllayer[4] = hostip;
tkllayer[5] = me.name;
ircsprintf(mo, "%li", 86400 + TStime());
ircsprintf(mo2, "%li", TStime());
tkllayer[6] = mo;
tkllayer[7] = mo2;
tkllayer[8] = "Fizzer";
m_tkl(&me, &me, 9, tkllayer);
return;
}
示例4: strlen
/*
** Get Channel block for i (and allocate a new channel
** block, if it didn't exists before).
*/
aChannel *get_channel(aClient *cptr, char *chname, int flag)
{
aChannel *chptr;
int len;
if (BadPtr(chname))
return NULL;
len = strlen(chname);
if (MyClient(cptr) && len > CHANNELLEN)
{
len = CHANNELLEN;
*(chname + CHANNELLEN) = '\0';
}
if ((chptr = find_channel(chname, (aChannel *)NULL)))
return (chptr);
if (flag == CREATE)
{
chptr = (aChannel *)MyMalloc(sizeof(aChannel) + len);
bzero((char *)chptr, sizeof(aChannel));
strncpyzt(chptr->chname, chname, len + 1);
if (channel)
channel->prevch = chptr;
chptr->topic = NULL;
chptr->topic_nick = NULL;
chptr->prevch = NULL;
chptr->nextch = channel;
chptr->creationtime = MyClient(cptr) ? TStime() : (TS)0;
channel = chptr;
(void)add_to_channel_hash_table(chname, chptr);
IRCstats.channels++;
RunHook2(HOOKTYPE_CHANNEL_CREATE, cptr, chptr);
}
return chptr;
}
示例5: m_sqline
/* m_sqline
** parv[0] = sender
** parv[1] = nickmask
** parv[2] = reason
*/
DLLFUNC int m_sqline(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
char mo[1024];
char *comment = (parc == 3) ? parv[2] : NULL;
char *tkllayer[9] = {
me.name, /*0 server.name */
"+", /*1 +|- */
"Q", /*2 G */
"*" , /*3 user */
parv[1], /*4 host */
sptr->name, /*5 setby */
"0", /*6 expire_at */
NULL, /*7 set_at */
"no reason" /*8 reason */
};
if (!IsServer(cptr))
return 0;
if (parc < 2)
return 0;
ircsprintf(mo, "%li", TStime());
tkllayer[7] = mo;
tkllayer[8] = comment ? comment : "no reason";
return m_tkl(&me, &me, 9, tkllayer);
}
示例6: do_settopic
/** Set a channel topic or report an error.
* @param[in] sptr Original topic setter.
* @param[in] cptr Neighbor that sent the topic message.
* @param[in] chptr Channel to set topic on.
* @param[in] topic New topic.
* @param[in] ts Timestamp that topic was set (0 for current time).
*/
static void do_settopic(struct Client *sptr, struct Client *cptr,
struct Channel *chptr, char *topic, time_t ts)
{
struct Client *from;
int newtopic;
if (feature_bool(FEAT_HIS_BANWHO) && IsServer(sptr))
from = &his;
else
from = sptr;
/* Note if this is just a refresh of an old topic, and don't
* send it to all the clients to save bandwidth. We still send
* it to other servers as they may have split and lost the topic.
*/
newtopic=ircd_strncmp(chptr->topic,topic,TOPICLEN)!=0;
/* setting a topic */
ircd_strncpy(chptr->topic, topic, TOPICLEN);
ircd_strncpy(chptr->topic_nick, cli_name(from), NICKLEN);
chptr->topic_time = ts ? ts : TStime();
/* Fixed in 2.10.11: Don't propagate local topics */
if (!IsLocalChannel(chptr->chname))
sendcmdto_serv(sptr, CMD_TOPIC, cptr, "%H %Tu %Tu :%s", chptr,
chptr->creationtime, chptr->topic_time, chptr->topic);
if (newtopic)
sendcmdto_channel(from, CMD_TOPIC, chptr, NULL, SKIP_SERVERS,
"%H :%s", chptr, chptr->topic);
/* if this is the same topic as before we send it to the person that
* set it (so they knew it went through ok), but don't bother sending
* it to everyone else on the channel to save bandwidth
*/
else if (MyUser(sptr))
sendcmdto_one(sptr, CMD_TOPIC, sptr, "%H :%s", chptr, chptr->topic);
}
示例7: m_lag
DLLFUNC int m_lag(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
if (MyClient(sptr))
if (!IsAnOper(sptr))
{
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name,
parv[0]);
return 0;
}
if (parc < 2)
{
sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
me.name, parv[0], "LAG");
return 0;
}
if (*parv[1] == '\0')
{
sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
me.name, parv[0], "LAG");
return 0;
}
if (hunt_server_token(cptr, sptr, MSG_LAG, TOK_LAG, ":%s", 1, parc,
parv) == HUNTED_NOSUCH)
{
return 0;
}
sendto_one(sptr, ":%s NOTICE %s :Lag reply -- %s %s %li",
me.name, sptr->name, me.name, parv[1], TStime());
return 0;
}
示例8: MyMallocEx
Event *EventAddEx(Module *module, char *name, long every, long howmany,
vFP event, void *data)
{
Event *newevent;
if (!name || (every < 0) || (howmany < 0) || !event)
{
if (module)
module->errorcode = MODERR_INVALID;
return NULL;
}
newevent = (Event *) MyMallocEx(sizeof(Event));
newevent->name = strdup(name);
newevent->howmany = howmany;
newevent->every = every;
newevent->event = event;
newevent->data = data;
/* We don't want a quick execution */
newevent->last = TStime();
newevent->owner = module;
AddListItem(newevent,events);
if (module) {
ModuleObject *eventobj = (ModuleObject *)MyMallocEx(sizeof(ModuleObject));
eventobj->object.event = newevent;
eventobj->type = MOBJ_EVENT;
AddListItem(eventobj, module->objects);
module->errorcode = MODERR_NOERROR;
}
return newevent;
}
示例9: completed_connection
/** Complete non-blocking connect()-sequence. Check access and
* terminate connection, if trouble detected.
* @param cptr Client to which we have connected, with all ConfItem structs attached.
* @return Zero on failure (caller should exit_client()), non-zero on success.
*/
static int completed_connection(struct Client* cptr)
{
struct ConfItem *aconf;
time_t newts;
struct Client *acptr;
int i;
assert(0 != cptr);
/*
* get the socket status from the fd first to check if
* connection actually succeeded
*/
if ((cli_error(cptr) = os_get_sockerr(cli_fd(cptr)))) {
const char* msg = strerror(cli_error(cptr));
if (!msg)
msg = "Unknown error";
sendto_opmask_butone(0, SNO_OLDSNO, "Connection failed to %s: %s",
cli_name(cptr), msg);
return 0;
}
if (!(aconf = find_conf_byname(cli_confs(cptr), cli_name(cptr), CONF_SERVER))) {
sendto_opmask_butone(0, SNO_OLDSNO, "Lost Server Line for %s", cli_name(cptr));
return 0;
}
if (s_state(&(cli_socket(cptr))) == SS_CONNECTING)
socket_state(&(cli_socket(cptr)), SS_CONNECTED);
if (!EmptyString(aconf->passwd))
sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
/*
* Create a unique timestamp
*/
newts = TStime();
for (i = HighestFd; i > -1; --i) {
if ((acptr = LocalClientArray[i]) &&
(IsServer(acptr) || IsHandshake(acptr))) {
if (cli_serv(acptr)->timestamp >= newts)
newts = cli_serv(acptr)->timestamp + 1;
}
}
assert(0 != cli_serv(cptr));
cli_serv(cptr)->timestamp = newts;
SetHandshake(cptr);
/*
* Make us timeout after twice the timeout for DNS look ups
*/
cli_lasttime(cptr) = CurrentTime;
ClearPingSent(cptr);
sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s +%s6n :%s",
cli_name(&me), cli_serv(&me)->timestamp, newts,
MAJOR_PROTOCOL, NumServCap(&me),
feature_bool(FEAT_HUB) ? "h" : "", cli_info(&me));
return (IsDead(cptr)) ? 0 : 1;
}
示例10: m_join
/** Handle a JOIN message from a client connection.
* See @ref m_functions for discussion of the arguments.
* @param[in] cptr Client that sent us the message.
* @param[in] sptr Original source of message.
* @param[in] parc Number of arguments.
* @param[in] parv Argument vector.
*/
int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
struct JoinBuf join;
struct JoinBuf create;
char *p = 0;
char *chanlist;
char *name;
char *keys;
if (parc < 2 || *parv[1] == '\0')
return need_more_params(sptr, "JOIN");
if (!IsAnOper(sptr) && IsRestrictJoin(sptr)) {
send_reply(sptr, ERR_BANNEDFROMCHAN, parv[1]);
return 0;
}
joinbuf_init(&join, sptr, cptr, JOINBUF_TYPE_JOIN, 0, 0);
joinbuf_init(&create, sptr, cptr, JOINBUF_TYPE_CREATE, 0, TStime());
chanlist = last0(cptr, sptr, parv[1]); /* find last "JOIN 0" */
keys = parv[2]; /* remember where keys are */
for (name = ircd_strtok(&p, chanlist, ","); name;
name = ircd_strtok(&p, 0, ",")) {
char *key = 0;
/* If we have any more keys, take the first for this channel. */
if (!BadPtr(keys)
&& (keys = strchr(key = keys, ',')))
*keys++ = '\0';
/* Empty keys are the same as no keys. */
if (key && !key[0])
key = 0;
if (!IsChannelName(name) || !strIsIrcCh(name))
{
/* bad channel name */
send_reply(sptr, ERR_NOSUCHCHANNEL, name);
continue;
}
if (cli_user(sptr)->joined >= get_client_maxchans(sptr)
&& !HasPriv(sptr, PRIV_CHAN_LIMIT)) {
send_reply(sptr, ERR_TOOMANYCHANNELS, name);
break; /* no point processing the other channels */
}
do_join(cptr, sptr, &join, &create, name, key, 0);
}
joinbuf_flush(&join); /* must be first, if there's a JOIN 0 */
joinbuf_flush(&create);
return 0;
}
示例11: init_random
/*
* init_random, written by Syzop.
* This function tries to initialize the arc4 random number generator securely.
*/
void init_random()
{
struct {
#ifdef USE_SSL
char egd[32]; /* from EGD */
#endif
#ifndef _WIN32
struct timeval nowt; /* time */
char rnd[32]; /* /dev/urandom */
#else
MEMORYSTATUS mstat; /* memory status */
struct _timeb nowt; /* time */
#endif
} rdat;
unsigned int seed, egd = 0;
time_t now = TStime();
int n;
#ifndef _WIN32
struct timeval nowt;
int fd;
#else
MEMORYSTATUS mstat;
struct _timeb nowt;
#endif
arc4_init();
/* Grab non-OS specific "random" data */
#ifdef USE_SSL
#if OPENSSL_VERSION_NUMBER >= 0x000907000
if (EGD_PATH) {
n = RAND_query_egd_bytes(EGD_PATH, rdat.egd, sizeof(rdat.egd));
}
#endif
#endif
/* Grab OS specific "random" data */
#ifndef _WIN32
gettimeofday(&rdat.nowt, NULL);
fd = open("/dev/urandom", O_RDONLY);
if (fd) {
n = read(fd, &rdat.rnd, sizeof(rdat.rnd));
Debug((DEBUG_INFO, "init_random: read from /dev/urandom returned %d", n));
close(fd);
}
/* TODO: more!?? */
#else
_ftime(&rdat.nowt);
GlobalMemoryStatus (&rdat.mstat);
#endif
arc4_addrandom(&rdat, sizeof(rdat));
/* NOTE: addtional entropy is added by add_entropy_* function(s) */
}
示例12: m_time
/*
* m_time - generic message handler
*
* parv[0] = sender prefix
* parv[1] = servername
*/
int m_time(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
if (hunt_server_cmd(sptr, CMD_TIME, cptr, feature_int(FEAT_HIS_REMOTE), ":%C",
1, parc, parv)
!= HUNTED_ISME)
return 0;
send_reply(sptr, RPL_TIME, cli_name(&me), TStime(), TSoffset, date((long)0));
return 0;
}
示例13: ircd_log
/* irc logs.. */
void ircd_log(int flags, char *format, ...)
{
va_list ap;
ConfigItem_log *logs;
char buf[2048], timebuf[128];
int fd;
struct stat fstats;
va_start(ap, format);
ircvsprintf(buf, format, ap);
snprintf(timebuf, sizeof timebuf, "[%s] - ", myctime(TStime()));
RunHook3(HOOKTYPE_LOG, flags, timebuf, buf);
strlcat(buf, "\n", sizeof buf);
for (logs = conf_log; logs; logs = (ConfigItem_log *) logs->next) {
#ifdef HAVE_SYSLOG
if (!stricmp(logs->file, "syslog") && logs->flags & flags) {
#ifdef HAVE_VSYSLOG
vsyslog(LOG_INFO, format, ap);
#else
/* %s just to be safe */
syslog(LOG_INFO, "%s", buf);
#endif
continue;
}
#endif
if (logs->flags & flags) {
if (stat(logs->file, &fstats) != -1 && logs->maxsize && fstats.st_size >= logs->maxsize) {
#ifndef _WIN32
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
#else
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE);
#endif
if (fd == -1)
continue;
write(fd, "Max file size reached, starting new log file\n", 45);
}
else {
#ifndef _WIN32
fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
#else
fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IREAD|S_IWRITE);
#endif
if (fd == -1)
continue;
}
write(fd, timebuf, strlen(timebuf));
write(fd, buf, strlen(buf));
close(fd);
}
}
va_end(ap);
}
示例14: cmodej_increase_usercounter
static void cmodej_increase_usercounter(aClient *cptr, aChannel *chptr)
{
CmodeParam *m;
aJFlood *e;
int num=0, t=0;
if (!MyClient(cptr))
return;
for (m = chptr->mode.extmodeparam; m; m=m->next)
if (m->flag == 'j')
{
num = ((aModejEntry *)m)->num;
t = ((aModejEntry *)m)->t;
break;
}
if (!num || !t)
return;
/* Grab user<->chan entry.. */
for (e = cptr->user->jflood; e; e=e->next_u)
if (e->chptr == chptr)
break;
if (!e)
{
/* Allocate one */
e = cmodej_addentry(cptr, chptr);
e->firstjoin = TStime();
e->numjoins = 1;
} else if ((TStime() - e->firstjoin) < t) /* still valid? */
{
e->numjoins++;
} else {
/* reset :p */
e->firstjoin = TStime();
e->numjoins = 1;
}
}
示例15: add_listmode
int add_listmode(Ban **list, aClient *cptr, aChannel *chptr, char *banid)
{
Ban *ban;
int cnt = 0, len;
if (MyClient(cptr))
(void)collapse(banid);
len = strlen(banid);
if (!*list && ((len > MAXBANLENGTH) || (MAXBANS < 1)))
{
sendto_one(cptr, err_str(ERR_BANLISTFULL),
me.name, cptr->name, chptr->chname, banid);
return -1;
}
for (ban = *list; ban; ban = ban->next)
{
len += strlen(ban->banstr);
if (MyClient(cptr))
if ((len > MAXBANLENGTH) || (++cnt >= MAXBANS))
{
sendto_one(cptr, err_str(ERR_BANLISTFULL),
me.name, cptr->name, chptr->chname, banid);
return -1;
}
else
{
#ifdef SOCALLEDSMARTBANNING
/* Temp workaround added in b19. -- Syzop */
if (!mycmp(ban->banstr, banid) || (!strchr(banid, '\\') && !strchr(ban->banstr, '\\')))
if (!match(ban->banstr, banid))
return -1;
#endif
if (!mycmp(ban->banstr, banid))
return -1;
}
else if (!mycmp(ban->banstr, banid))
return -1;
}
ban = make_ban();
bzero((char *)ban, sizeof(Ban));
ban->next = *list;
ban->banstr = (char *)MyMalloc(strlen(banid) + 1);
(void)strcpy(ban->banstr, banid);
ban->who = (char *)MyMalloc(strlen(cptr->name) + 1);
(void)strcpy(ban->who, cptr->name);
ban->when = TStime();
*list = ban;
return 0;
}