荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: jjk (pq), 信区: InstallBBS
标  题: SMTH_006  聊天室中察看当前上线好友
发信站: 荔园晨风BBS站 (Thu Nov 29 11:21:46 2001), 转信

【 以下文字转载自 jjk 的信箱 】
【 原文由 jjk.bbs@bbs.pku.edu.cn 所发表 】
发信人: Admin (新的一天从零开始), 信区: BBSDev
标  题: SMTH_006  聊天室中察看当前上线好友
发信站: 北大未名站 (2001年05月24日11:24:28 星期四), 站内信件

发信人: Leeward (AIX), 信区: BBSMan_Dev
标  题: SMTH_006  聊天室中察看当前上线好友
发信站: BBS 水木清华站 (Tue Feb  2 14:35:41 1999) WWW-POST

本文描述的修改在 FireBird 2.5 和 2.6 上均可使用.

本站使用 /g 指令进行聊天室的上线好友查询操作.

修改代码我不太清楚是在什么时候由水木清华站的哪位站长开发并运行的.
可能是 Alex 或者 snow,或者其他哪一位吧.修改的时间很早了.

下列代码用于在聊天室中,察看当前上线的好友:

============================================================================

1.在 bbs_src/chat.c 的 chat_users 函数定义后,添加下列两个函数:

int
print_friend_ent(uentp) /* print one user & status if he is a friend*/
  struct user_info *uentp;
{
  static char uline[256];
  static int cnt;
  char pline[50];

  if (!uentp)
  {
    if (cnt)
      printchatline(uline);
    bzero(uline, 256);
    cnt = 0;
    return 0;
  }
  if (!uentp->active || !uentp->pid)
    return 0;
  if (!HAS_PERM(PERM_SEECLOAK) && uentp->invisible)
    return 0;

#if 0
  if (kill(uentp->pid, 0) == -1)
    return 0;
#endif

  /*if (!myfriend(uentp->userid)) Leeward 99.02.01 */
  if (!myfriend(uentp->uid))
    return 0;

  sprintf(pline, " %-13s%c%-10s",
      uentp->userid, uentp->invisible ? '#' : ' ',
      modestring(uentp->mode, uentp->destuid, 0, NULL));
  if (cnt < 2)
    strcat(pline, "│");
  strcat(uline, pline);
  if (++cnt == 3)
  {
    printchatline(uline);
    memset(uline, 0, 256);
    cnt = 0;
  }
  return 0;
}

void
chat_friends()
{
  printchatline("");
  sprintf(genbuf,"^[[1m【 当前线上的好友列表 】^[[m");
  printchatline(genbuf);
  printchatline(msg_shortulist);

  if (apply_ulist(print_friend_ent) == -1)
  {
    printchatline("^[[1m没有朋友在线上^[[m");
  }
  print_friend_ent(NULL);
}

2.在 bbs_src/chat.c 的尾部,
    struct chat_command chat_cmdtbl[] 的定义中,
    加入 /g 指令的定义:

struct chat_command chat_cmdtbl[] = {
  {"pager",setpager},
  {"help", chat_help},
  {"clear", chat_clear},
  {"date", chat_date},
  {"g", chat_friends},
  {"users", chat_users},
   ... 中间的部分定义此处略去 ...
  {NULL, NULL}
};

特别说明两点:
1. ^[[1m 的输入方式是(在 vi 中):Esc i Ctrl-V Ctrl-[ [ 1 m 一共七次击键
2. 标有 "Leeward 99.02.01" 的地方, 可能不同的版本需要不同的代码.
   具体说, 请察看 bbs_src/list.c 中对 myfriend 函数的参数接口定义.
   在 2.6 版中, 这里的参数应该是个 unsigned short
   而 2.5 版中, 这里的参数可能是个 char *
   需要根据具体的代码中对调用参数的类型定义, 来修改 myfriend 函数的调用参数:
   如果参数类型定义为 unsigned short, 实际的调用参数用 uentp->uid 就可以;
   如果参数类型定义为 char *, 实际的调用参数用 uentp->userid 就可以.
--

        我 们 的 一 切 追 求 和 作 为, 都 有 一 个 令 人 厌 倦 的 过 程

   作 为 一 个 不 识 厌 倦 为 何 物 的 人, 便 掌 握 了 生 命 的 全 部 秘 密

※ 修改:·Leeward 於 Feb  2 15:08:47 修改本文·[FROM: bbs.huizhou.gd.]

--

     目前正在搜集整理内存管理相关资料
            欢迎提供

     泛一叶轻舟,漂流海上,逍遥有过于斯乎?


※ 来源:·北大未名站 bbs.pku.edu.cn·[FROM: 162.105.203.8]
--
※ 转寄:·北大未名站 bbs.pku.edu.cn·[FROM: 210.39.3.50]
--
※ 转载:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.146]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店