一网深情 上有人反映说明明看到对方在线确不能给他发消息的问题。
经过研究,发现问题出来talk.c中的 t_search 算法上。
原来的t_search是顺序搜索shm中的用户信息,若对方一个ID多个上线
的话就以第一个ID的状态作为信息返回。
现把talk.c中的t_search重写,加入优先级处理,解决这个问题.
注意:
前提是mode.h中的各种mode必须是按优先级排序(一般FB系统都已经是这样的了)
struct user_info *
t_search(sid, pid)
char *sid;
int pid;
{
int i;
/*优先级处理 by ZV 2002.5.9*/
struct user_info *best;
int mCost = 100000;
extern struct UTMPFILE *utmpshm;
struct user_info *cur, *tmp = NULL;
resolve_utmp();
for (i = 0; i < USHM_SIZE; i++) {
cur = &(utmpshm->uinfo[i]);
if (!cur->active || !cur->pid)
continue;
if (!strcasecmp(cur->userid, sid)) {
if (pid == 0) {
if (cur->mode < mCost) {
mCost = cur->mode;
best = cur;
}
}
tmp = cur;
if (pid == cur->pid)
break;
}
}
if (mCost < 100000)
return isreject(best) ? NULL : best;
else
return isreject(cur) ? NULL : tmp;
}
--
FROM AfterDark