| 14 |
|
/* ignore_init: Initialize ignore-related fields of a new User structure. */ |
| 15 |
|
|
| 16 |
|
void |
| 17 |
< |
ignore_init(User * u) |
| 17 |
> |
ignore_init(User *u) |
| 18 |
|
{ |
| 19 |
|
u->ignore = 0; |
| 20 |
|
u->lastcmd = time_msec(); |
| 43 |
|
*/ |
| 44 |
|
|
| 45 |
|
void |
| 46 |
< |
ignore_update(User * u, uint32 msec) |
| 46 |
> |
ignore_update(User *u, uint32 msec) |
| 47 |
|
{ |
| 48 |
|
time_t now; |
| 49 |
|
uint32 now_msec; |
| 50 |
|
|
| 51 |
|
if (!IgnoreDecay) |
| 52 |
< |
{ |
| 53 |
< |
/* Ignore code disabled, just return */ |
| 54 |
< |
return; |
| 55 |
< |
} |
| 52 |
> |
return; /* Ignore code disabled, just return */ |
| 53 |
> |
|
| 54 |
|
now = time(NULL); |
| 55 |
|
now_msec = time_msec(); |
| 56 |
+ |
|
| 57 |
|
if (now - u->lastcmd_s > 1000000) |
| 58 |
|
{ |
| 59 |
|
/* Millisecond counter may have overflowed, just reset to 0 */ |
| 62 |
|
else |
| 63 |
|
{ |
| 64 |
|
double zerolen = (now_msec - msec) - u->lastcmd; |
| 65 |
+ |
|
| 66 |
|
if (zerolen > 0) |
| 67 |
|
u->ignore *= pow(2, -(zerolen / IgnoreDecay)); |
| 68 |
|
} |
| 69 |
+ |
|
| 70 |
|
if (msec) |
| 71 |
|
{ |
| 72 |
|
double factor; |
| 73 |
+ |
|
| 74 |
|
while (msec > IgnoreDecay) |
| 75 |
|
{ |
| 76 |
|
u->ignore = u->ignore * 0.5 + 0.5; |
| 77 |
|
msec -= IgnoreDecay; |
| 78 |
|
} |
| 79 |
+ |
|
| 80 |
|
factor = pow(2, -((double) msec / IgnoreDecay)); |
| 81 |
|
u->ignore = u->ignore * factor + (1 - factor); |
| 82 |
|
} |
| 83 |
+ |
|
| 84 |
|
u->lastcmd = now_msec; |
| 85 |
|
u->lastcmd_s = now; |
| 86 |
|
} |