summaryrefslogtreecommitdiffstats
path: root/mbbsd/friend.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-06 01:10:28 +0800
commit1603deaec5d0a94c9a8201b0ba286e8e492a3602 (patch)
treee6405cfd39f8ac166ab7d00752ed6cfa3ac0a928 /mbbsd/friend.c
parent10bda3e57cad194ac33ccdcd01aee2d935f1544a (diff)
downloadpttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.gz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.bz2
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.lz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.xz
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.tar.zst
pttbbs-1603deaec5d0a94c9a8201b0ba286e8e492a3602.zip
indent
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@415 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/friend.c')
-rw-r--r--mbbsd/friend.c311
1 files changed, 143 insertions, 168 deletions
diff --git a/mbbsd/friend.c b/mbbsd/friend.c
index c24f6240..81abf097 100644
--- a/mbbsd/friend.c
+++ b/mbbsd/friend.c
@@ -1,4 +1,4 @@
-/* $Id: friend.c,v 1.8 2002/07/02 13:01:43 in2 Exp $ */
+/* $Id: friend.c,v 1.9 2002/07/05 17:10:27 in2 Exp $ */
#include "bbs.h"
/* ------------------------------------- */
@@ -6,8 +6,8 @@
/* ------------------------------------- */
/* Ptt 其他特別名單的檔名 */
-static char special_list[] = "list.0";
-static char special_des[] = "ldes.0";
+static char special_list[] = "list.0";
+static char special_des[] = "ldes.0";
/* 特別名單的上限 */
static unsigned int friend_max[8] = {
@@ -24,7 +24,7 @@ static unsigned int friend_max[8] = {
/* Ptt 各種特別名單的補述 */
-static char *friend_desc[8] = {
+static char *friend_desc[8] = {
"友誼描述:",
"惡形惡狀:",
"",
@@ -36,7 +36,7 @@ static char *friend_desc[8] = {
};
/* Ptt 各種特別名單的中文敘述 */
-static char *friend_list[8] = {
+static char *friend_list[8] = {
"好友名單",
"壞人名單",
"上線通知",
@@ -47,17 +47,21 @@ static char *friend_list[8] = {
"看板好友名單"
};
-static void setfriendfile(char *fpath, int type) {
+static void
+setfriendfile(char *fpath, int type)
+{
if (type <= 4) /* user list Ptt */
setuserfile(fpath, friend_file[type]);
else /* board list */
setbfile(fpath, currboard, friend_file[type]);
}
-static int friend_count(char *fname) {
- FILE *fp;
- int count = 0;
- char buf[200];
+static int
+friend_count(char *fname)
+{
+ FILE *fp;
+ int count = 0;
+ char buf[200];
#if 0
if ((fp = fopen(fname, "r")))
@@ -65,37 +69,36 @@ static int friend_count(char *fname) {
count++;
#endif
-/*rocker.011018: 忘記關檔了... */
- if ((fp = fopen(fname, "r")))
- {
- while (fgets(buf, 200, fp)) count++;
- fclose (fp);
+ /* rocker.011018: 忘記關檔了... */
+ if ((fp = fopen(fname, "r"))) {
+ while (fgets(buf, 200, fp))
+ count++;
+ fclose(fp);
}
-
return count;
}
-void friend_add(char *uident, int type) {
- char fpath[80];
+void
+friend_add(char *uident, int type)
+{
+ char fpath[80];
setfriendfile(fpath, type);
if (friend_count(fpath) > friend_max[type])
return;
- if ((uident[0] > ' ') && !belong(fpath, uident))
- {
- FILE *fp;
- char buf[40] = "";
- char t_uident[IDLEN + 1];
+ if ((uident[0] > ' ') && !belong(fpath, uident)) {
+ FILE *fp;
+ char buf[40] = "";
+ char t_uident[IDLEN + 1];
- /* Thor: avoid uident run away when get data */
+ /* Thor: avoid uident run away when get data */
strcpy(t_uident, uident);
if (type != FRIEND_ALOHA && type != FRIEND_POST)
getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO);
- if ((fp = fopen(fpath, "a")))
- {
+ if ((fp = fopen(fpath, "a"))) {
flock(fileno(fp), LOCK_EX);
fprintf(fp, "%-13s%s\n", t_uident, buf);
flock(fileno(fp), LOCK_UN);
@@ -104,19 +107,19 @@ void friend_add(char *uident, int type) {
}
}
-static void friend_special() {
- char genbuf[70], i, fname[70];
+static void
+friend_special()
+{
+ char genbuf[70], i, fname[70];
friend_file[FRIEND_SPECIAL] = special_list;
- for (i = 0; i <= 9; i++)
- {
+ for (i = 0; i <= 9; i++) {
sprintf(genbuf, " (\033[36m%d\033[m) .. ", i);
special_des[5] = i + '0';
setuserfile(fname, special_des);
- if (dashf(fname))
- {
- /* no NULL check?? */
- FILE *fp = fopen(fname, "r");
+ if (dashf(fname)) {
+ /* no NULL check?? */
+ FILE *fp = fopen(fname, "r");
fgets(genbuf + 15, 40, fp);
genbuf[47] = 0;
@@ -126,45 +129,41 @@ static void friend_special() {
outs(genbuf);
}
getdata(22, 0, "請選擇第幾號特別名單 (0~9)[0]?", genbuf, 3, LCECHO);
- if (genbuf[0] >= '0' && genbuf[0] <= '9')
- {
+ if (genbuf[0] >= '0' && genbuf[0] <= '9') {
special_list[5] = genbuf[0];
special_des[5] = genbuf[0];
- }
- else
- {
+ } else {
special_list[5] = '0';
special_des[5] = '0';
}
}
-static void friend_append(int type, int count) {
- char fpath[80], i, j, buf[80], sfile[80];
- FILE *fp, *fp1;
+static void
+friend_append(int type, int count)
+{
+ char fpath[80], i, j, buf[80], sfile[80];
+ FILE *fp, *fp1;
setfriendfile(fpath, type);
- do
- {
+ do {
move(2, 0);
clrtobot();
outs("要引入哪一個名單?\n");
for (j = i = 0; i <= 4; i++)
- if( i != type ){
+ if (i != type) {
++j;
- sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int) i]);
+ sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int)i]);
outs(buf);
}
-
- if( HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD )
- for( ; i < 8 ; ++i )
- if( i != type ){
+ if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD)
+ for (; i < 8; ++i)
+ if (i != type) {
++j;
sprintf(buf, " (%d) %s 板的 %s\n", j, currboard,
- friend_list[(int) i]);
+ friend_list[(int)i]);
outs(buf);
}
-
outs(" (S) 選擇其他看板的特別名單");
getdata(11, 0, "請選擇 或 直接[Enter] 放棄:", buf, 3, LCECHO);
if (!buf[0])
@@ -174,7 +173,7 @@ static void friend_append(int type, int count) {
j = buf[0] - '1';
if (j >= type)
j++;
- if( !(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4 )
+ if (!(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4)
return;
}
while (buf[0] < '1' || buf[0] > '9');
@@ -184,13 +183,13 @@ static void friend_append(int type, int count) {
setfriendfile(sfile, j);
- if( (fp = fopen(sfile, "r")) != NULL ){
- while (fgets(buf, 80, fp) && count <= friend_max[type]){
- char the_id[15];
-
+ if ((fp = fopen(sfile, "r")) != NULL) {
+ while (fgets(buf, 80, fp) && count <= friend_max[type]) {
+ char the_id[15];
+
sscanf(buf, "%s", the_id);
- if (!belong(fpath, the_id)){
- if ((fp1 = fopen(fpath, "a"))){
+ if (!belong(fpath, the_id)) {
+ if ((fp1 = fopen(fpath, "a"))) {
flock(fileno(fp1), LOCK_EX);
fputs(buf, fp1);
flock(fileno(fp1), LOCK_UN);
@@ -202,17 +201,18 @@ static void friend_append(int type, int count) {
}
}
-void friend_delete(char *uident, int type) {
- FILE *fp, *nfp;
- char fn[80], fnnew[80];
- char genbuf[200];
+void
+friend_delete(char *uident, int type)
+{
+ FILE *fp, *nfp;
+ char fn[80], fnnew[80];
+ char genbuf[200];
setfriendfile(fn, type);
sprintf(fnnew, "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w")))
- {
- int length = strlen(uident);
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
+ int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp))
if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length))
@@ -223,22 +223,21 @@ void friend_delete(char *uident, int type) {
}
}
-static void friend_editdesc(char *uident, int type) {
- FILE *fp, *nfp;
- char fnnew[200], genbuf[200], fn[200];
+static void
+friend_editdesc(char *uident, int type)
+{
+ FILE *fp, *nfp;
+ char fnnew[200], genbuf[200], fn[200];
setfriendfile(fn, type);
sprintf(fnnew, "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w")))
- {
- int length = strlen(uident);
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
+ int length = strlen(uident);
- while (fgets(genbuf, STRLEN, fp))
- {
+ while (fgets(genbuf, STRLEN, fp)) {
if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length))
fputs(genbuf, nfp);
- else if (!strncmp(genbuf, uident, length))
- {
- char buf[50] = "";
+ else if (!strncmp(genbuf, uident, length)) {
+ char buf[50] = "";
getdata(2, 0, "修改描述:", buf, 40, DOECHO);
fprintf(nfp, "%-13s%s\n", uident, buf);
}
@@ -249,19 +248,20 @@ static void friend_editdesc(char *uident, int type) {
}
}
-void friend_load() {
- FILE *fp;
- int myfriends[MAX_FRIEND];
- int myrejects[MAX_REJECT];
- int friendcount, rejectedcount;
- char genbuf[200];
+void
+friend_load()
+{
+ FILE *fp;
+ int myfriends[MAX_FRIEND];
+ int myrejects[MAX_REJECT];
+ int friendcount, rejectedcount;
+ char genbuf[200];
memset(myfriends, 0, sizeof(myfriends));
friendcount = 0;
setuserfile(genbuf, fn_overrides);
- if ((fp = fopen(genbuf, "r")))
- {
- int unum;
+ if ((fp = fopen(genbuf, "r"))) {
+ int unum;
while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1)
if (strtok(genbuf, str_space))
@@ -274,9 +274,8 @@ void friend_load() {
memset(myrejects, 0, sizeof(myrejects));
rejectedcount = 0;
setuserfile(genbuf, fn_reject);
- if ((fp = fopen(genbuf, "r")))
- {
- int unum;
+ if ((fp = fopen(genbuf, "r"))) {
+ int unum;
while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1)
if (strtok(genbuf, str_space))
@@ -285,52 +284,52 @@ void friend_load() {
fclose(fp);
}
memcpy(currutmp->reject, myrejects, sizeof(myrejects));
- if(currutmp->friendtotal)
+ if (currutmp->friendtotal)
logout_friend_online(currutmp);
login_friend_online();
}
-static void friend_water(char *message, int type) { /* 群體水球 added by Ptt */
- char fpath[80], line[80], userid[IDLEN + 1];
- FILE *fp;
+static void
+friend_water(char *message, int type)
+{ /* 群體水球 added by Ptt */
+ char fpath[80], line[80], userid[IDLEN + 1];
+ FILE *fp;
setfriendfile(fpath, type);
if ((fp = fopen(fpath, "r")))
- while(fgets(line, 80, fp)) {
- userinfo_t *uentp;
- int tuid;
-
+ while (fgets(line, 80, fp)) {
+ userinfo_t *uentp;
+ int tuid;
+
sscanf(line, "%s", userid);
- if((tuid = searchuser(userid)) && tuid != usernum &&
- (uentp = (userinfo_t *) search_ulist(tuid)) &&
- isvisible_uid(tuid))
+ if ((tuid = searchuser(userid)) && tuid != usernum &&
+ (uentp = (userinfo_t *) search_ulist(tuid)) &&
+ isvisible_uid(tuid))
my_write(uentp->pid, message, uentp->userid, 1, NULL);
}
fclose(fp);
}
-void friend_edit(int type) {
- char fpath[80], line[80], uident[20];
- int count, column, dirty;
- FILE *fp;
- char genbuf[200];
+void
+friend_edit(int type)
+{
+ char fpath[80], line[80], uident[20];
+ int count, column, dirty;
+ FILE *fp;
+ char genbuf[200];
if (type == FRIEND_SPECIAL)
friend_special();
setfriendfile(fpath, type);
- if (type == FRIEND_ALOHA || type == FRIEND_POST)
- {
- if (dashf(fpath))
- {
+ if (type == FRIEND_ALOHA || type == FRIEND_POST) {
+ if (dashf(fpath)) {
sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath);
system(genbuf);
}
}
-
dirty = 0;
- while (1)
- {
+ while (1) {
stand_title(friend_list[type]);
move(0, 40);
sprintf(line, "(名單上限:%d個人)", friend_max[type]);
@@ -338,20 +337,17 @@ void friend_edit(int type) {
count = 0;
CreateNameList();
- if ((fp = fopen(fpath, "r")))
- {
+ if ((fp = fopen(fpath, "r"))) {
move(3, 0);
column = 0;
- while (fgets(genbuf, STRLEN, fp))
- {
+ while (fgets(genbuf, STRLEN, fp)) {
if (genbuf[0] <= ' ')
continue;
strtok(genbuf, str_space);
AddNameList(genbuf);
prints("%-13s", genbuf);
count++;
- if (++column > 5)
- {
+ if (++column > 5) {
column = 0;
outc('\n');
}
@@ -363,108 +359,83 @@ void friend_edit(int type) {
"(K)刪除整個名單(W)丟水球(Q)結束?[Q]" :
"(A)增加 (P)引入其他名單 (Q)結束?[Q]"),
uident, 3, LCECHO);
- if (*uident == 'a')
- {
+ if (*uident == 'a') {
move(1, 0);
usercomplete(msg_uid, uident);
- if (uident[0] && searchuser(uident) && !InNameList(uident))
- {
+ if (uident[0] && searchuser(uident) && !InNameList(uident)) {
friend_add(uident, type);
dirty = 1;
}
- }
- else if (*uident == 'p')
- {
+ } else if (*uident == 'p') {
friend_append(type, count);
dirty = 1;
- }
- else if (*uident == 'e' && count)
- {
+ } else if (*uident == 'e' && count) {
move(1, 0);
namecomplete(msg_uid, uident);
- if (uident[0] && InNameList(uident))
- {
+ if (uident[0] && InNameList(uident)) {
friend_editdesc(uident, type);
}
- }
- else if (*uident == 'd' && count)
- {
+ } else if (*uident == 'd' && count) {
move(1, 0);
namecomplete(msg_uid, uident);
- if (uident[0] && InNameList(uident))
- {
+ if (uident[0] && InNameList(uident)) {
friend_delete(uident, type);
dirty = 1;
}
- }
- else if (*uident == 'l' && count)
+ } else if (*uident == 'l' && count)
more(fpath, YEA);
- else if (*uident == 'k' && count)
- {
+ else if (*uident == 'k' && count) {
getdata(2, 0, "整份名單將會被刪除,您確定嗎 (a/N)?", uident, 3,
LCECHO);
if (*uident == 'a')
unlink(fpath);
dirty = 1;
- }
- else if (*uident == 'w' && count)
- {
- char wall[60];
+ } else if (*uident == 'w' && count) {
+ char wall[60];
if (!getdata(0, 0, "群體水球:", uident, sizeof(wall), DOECHO))
continue;
if (getdata(0, 0, "確定丟出群體水球? [Y]", line, 4, LCECHO) &&
*line == 'n')
continue;
friend_water(wall, type);
- }
- else
+ } else
break;
}
- if (dirty)
- {
+ if (dirty) {
move(2, 0);
outs("更新資料中..請稍候.....");
refresh();
- if (type == FRIEND_ALOHA || type == FRIEND_POST)
- {
+ if (type == FRIEND_ALOHA || type == FRIEND_POST) {
sprintf(genbuf, "%s.old", fpath);
- if ((fp = fopen(genbuf, "r")))
- {
- while (fgets(line, 80, fp))
- {
+ if ((fp = fopen(genbuf, "r"))) {
+ while (fgets(line, 80, fp)) {
sscanf(line, "%s", uident);
sethomefile(genbuf, uident,
- type == FRIEND_ALOHA ? "aloha" : "postnotify");
+ type == FRIEND_ALOHA ? "aloha" : "postnotify");
del_distinct(genbuf, cuser.userid);
}
fclose(fp);
}
sprintf(genbuf, "%s", fpath);
- if ((fp = fopen(genbuf, "r")))
- {
- while (fgets(line, 80, fp))
- {
+ if ((fp = fopen(genbuf, "r"))) {
+ while (fgets(line, 80, fp)) {
sscanf(line, "%s", uident);
sethomefile(genbuf, uident,
- type == FRIEND_ALOHA ? "aloha" : "postnotify");
+ type == FRIEND_ALOHA ? "aloha" : "postnotify");
add_distinct(genbuf, cuser.userid);
}
fclose(fp);
}
- }
- else if (type == FRIEND_SPECIAL)
- {
+ } else if (type == FRIEND_SPECIAL) {
genbuf[0] = 0;
setuserfile(line, special_des);
- if ((fp = fopen(line, "r")))
- {
+ if ((fp = fopen(line, "r"))) {
fgets(genbuf, 30, fp);
fclose(fp);
}
getdata_buf(2, 0, " 請為此特別名單取一個簡短名稱:", genbuf, 30,
DOECHO);
- if ((fp = fopen(line, "w")))
- {
+ if ((fp = fopen(line, "w"))) {
fprintf(fp, "%s", genbuf);
fclose(fp);
}
@@ -473,12 +444,16 @@ void friend_edit(int type) {
}
}
-int t_override() {
+int
+t_override()
+{
friend_edit(FRIEND_OVERRIDE);
return 0;
}
-int t_reject() {
+int
+t_reject()
+{
friend_edit(FRIEND_REJECT);
return 0;
}