对于FB系统,如果两个sterm用户都开了自动应答,有可能出现双方都不断回
答"我不在.."而使得讯息不断反弹的情况。在网速快的时候,这会占用大量的
系统资源。通过限制短时间内连续对同样的人发送同样内容的讯息可以避免这
个问题。
具体改动如下:
在sendmsg.c的do_sendmsg()函数的适当地方加上:
if(flood_msg(msgbuf, userpid)) {
move(1, 0);
clrtoeol();
prints("错误! 您刚才已经发过这个消息了...\n");
refresh();
sleep(1);
return -1;
}
然后再加上flood_msg()函数:
int flood_msg(char *msgbuf, int pid) {
static char last_buf[256]="";
static int last_pid=0;
static int last_time=0;
if(abs(time(0)-last_time)>10 || pid!=last_pid || strcmp(msgbuf, last_buf)) {
last_time=time(0);
last_pid=pid;
strncpy(last_buf, msgbuf, 256);
return 0;
} else {
return 1;
}
}
--
FROM bbs.nju.edu.cn