summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-05-11 23:04:29 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-05-11 23:04:29 +0800
commit5a07030f13bacf160ce9c068f6c3b2b68fa72d25 (patch)
tree7d733927e7932a91d3214afb22b18a04a128c0e8
parent7be678a70a3718dcda2e036b6812654cfa49ff11 (diff)
downloadpttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar.gz
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar.bz2
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar.lz
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar.xz
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.tar.zst
pttbbs-5a07030f13bacf160ce9c068f6c3b2b68fa72d25.zip
- chat: add /ban and /unban commands
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4298 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/chat.c5
-rw-r--r--util/xchatd.c138
2 files changed, 126 insertions, 17 deletions
diff --git a/mbbsd/chat.c b/mbbsd/chat.c
index 3af6f4f6..b513311d 100644
--- a/mbbsd/chat.c
+++ b/mbbsd/chat.c
@@ -143,6 +143,8 @@ chat_help(char *arg)
chathelp("[/o]p <id>", "將 Op 的權力轉移給 <id>");
chathelp("[/t]opic <text>", "換個話題");
chathelp("[/w]all", "廣播 (站長專用)");
+ chathelp(" /ban <userid>", "拒絕 <userid> 再次進入此聊天室 (加入黑名單)");
+ chathelp(" /unban <userid>", "把 <userid> 移出黑名單");
// chathelp(" /ban <id>", "拒絕 <id> 再次進入此談天室");
} else {
chathelp(" /help op", "談天室管理員專用指令");
@@ -477,7 +479,8 @@ t_chat(void)
vgetstring(inbuf, 68, VGET_TRANSPARENT, "", &vge, &vgetparam);
// quick check for end flag or exit command.
- if (!chatting || strncmp(inbuf, "/b", 2) == 0)
+ if (!chatting ||
+ (strncasecmp(inbuf, "/b", 2) == 0 && strncasecmp(inbuf, "/ban", 4) != 0))
break;
// quick continue for empty input
diff --git a/util/xchatd.c b/util/xchatd.c
index 18cb0968..5b216b9d 100644
--- a/util/xchatd.c
+++ b/util/xchatd.c
@@ -113,6 +113,7 @@ struct ChatRoom
int rflag; /* ROOM_LOCKED, ROOM_SECRET, ROOM_OPENTOPIC */
int occupants; /* number of users in room */
UserList *invite;
+ UserList *ban;
};
@@ -1267,7 +1268,9 @@ enter_room(ChatUser *cuser, char *rname, char *msg)
return 0;
}
- if (!CHATSYSOP(cuser) && LOCKED(room) && !list_belong(room->invite, cuser->userno))
+ if (!CHATSYSOP(cuser) &&
+ (list_belong(room->ban, cuser->userno) ||
+ (LOCKED(room) && !list_belong(room->invite, cuser->userno))))
{
send_to_user(cuser, "※ 內有惡犬,非請莫入", 0, MSG_MESSAGE);
return 0;
@@ -1654,6 +1657,34 @@ chat_unignore(ChatUser *cu, char *msg)
send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
}
+static void
+chat_unban(ChatUser *cu, char *msg)
+{
+ char *unban;
+ UserList **list;
+
+ if (!ROOMOP(cu))
+ {
+ send_to_user(cu, msg_not_op, 0, MSG_MESSAGE);
+ return;
+ }
+
+ unban = nextword(&msg);
+ list = &(cu->room->ban);
+
+ if (*unban)
+ {
+ sprintf(chatbuf, (list_delete(list, unban)) ?
+ "◆ [%s] 不再被列為黑名單" :
+ "◆ [%s] 並不在黑名單中,請用 /ban 檢查列表", unban);
+ }
+ else
+ {
+ strcpy(chatbuf, "◆ 請指明使用者 ID");
+ }
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+}
+
static void
chat_join(ChatUser *cu, char *msg)
@@ -1816,6 +1847,94 @@ chat_invite(ChatUser *cu, char *msg)
send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
}
+static void
+chat_ban(ChatUser *cu, char *msg)
+{
+ char *banned;
+ ChatUser *xuser;
+ ChatRoom *room;
+ UserList **list;
+ int unum = 0;
+
+ banned = nextword(&msg);
+
+ if (!banned || !*banned)
+ {
+ // list all
+ UserList *list;
+ if(!(list = cu->room->ban))
+ {
+ strcpy(chatbuf, "◆ 目前黑名單是空的");
+ }
+ else
+ {
+ int len;
+ char buf[16];
+
+ send_to_user(cu, "◆ 黑名單列表:", 0, MSG_MESSAGE);
+ len = 0;
+ do
+ {
+ sprintf(buf, "%-13s", list->userid);
+ strcpy(chatbuf + len, buf);
+ len += 13;
+ if (len >= 78)
+ {
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+ len = 0;
+ }
+ } while((list = list->next));
+ chatbuf[len] = 0;
+ }
+ if (chatbuf[0])
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+ return;
+ }
+
+ if (!ROOMOP(cu))
+ {
+ send_to_user(cu, msg_not_op, 0, MSG_MESSAGE);
+ return;
+ }
+ xuser = cuser_by_chatid(banned);
+
+ if (!xuser)
+ unum = searchuser(banned, NULL);
+ else
+ unum = xuser->userno;
+
+ if (!unum)
+ {
+ sprintf(chatbuf, msg_no_such_id, banned);
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+ return;
+ }
+
+ room = cu->room;
+ assert(room);
+ list = &(room->ban);
+
+ if (list_belong(*list, unum))
+ {
+ sprintf(chatbuf, "※ %s 已經在黑名單內了", banned);
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+ return;
+ }
+
+ if (xuser)
+ {
+ list_add(list, xuser);
+ sprintf(chatbuf, "※ %s (%s) 已被加入黑名單", xuser->chatid, xuser->userid);
+ }
+ else
+ {
+ list_add_id(list, banned);
+ sprintf(chatbuf, "※ %s 已被加入黑名單", banned);
+ }
+
+ send_to_user(cu, chatbuf, 0, MSG_MESSAGE);
+}
+
static void
chat_broadcast(ChatUser *cu, char *msg)
@@ -2278,6 +2397,7 @@ view_action_verb(ChatUser *cu, char cmd) /* Thor.0726: 新加動詞分類顯示 */
static ChatCmd chatcmdlist[] =
{
{"act", chat_act, 0},
+ {"ban", chat_ban, 0},
{"bye", chat_goodbye, 0},
{"chatroom", chat_chatroom, 1}, /* Xshadow: for common client */
{"cloak", chat_cloak, 2},
@@ -2294,6 +2414,7 @@ static ChatCmd chatcmdlist[] =
{"room", chat_list_rooms, 0},
{"unignore", chat_unignore, 1},
+ {"unban", chat_unban, 1},
{"whoin", chat_list_by_room, 1},
{"wall", chat_broadcast, 2},
@@ -2435,21 +2556,6 @@ cuser_serve(ChatUser *cu)
return -1;
}
-#if 0
- /* Xshadow: 將送達的資料忠實紀錄下來 */
- memcpy(logbuf, buf, sizeof(buf));
- for (ch = 0; ch < sizeof(buf); ch++)
- if (!logbuf[ch])
- logbuf[ch] = '$';
-
- logbuf[len + 1] = '\0';
- logit("recv: ", logbuf);
-#endif
-
-#if 0
- logit(cu->userid, str);
-#endif
-
isize = cu->isize;
cmd = cu->ibuf;
while (len--) {