bbschat.c

来自「bbs server linux平台下软件源码」· C语言 代码 · 共 615 行 · 第 1/2 页

C
615
字号
           "	<option value=\"//happy\">幸福</option>\n"           "	<option value=\"//hungry\">肚子饿了</option>\n"           "	<option value=\"//strut\">大摇大摆</option>\n"           "	<option value=\"//miss\">想念</option>\n"           "	<option value=\"//think\">想一想</option>\n"           "	<option value=\"//?\">疑惑不已</option>\n"           "	<option value=\"//bearbug\">热情拥抱</option>\n"           "	<option value=\"//bless\">祝福</option>\n"           "	<option value=\"//bow\">鞠躬</option>\n"           "        <option value=\"//caress\">抚摸</option>\n"           "        <option value=\"//cringe\">企求宽恕</option>\n"           "        <option value=\"//cry\">放声大哭</option>\n"           "        <option value=\"//comfort\">安慰一下</option>\n"           "	<option value=\"//clap\">热烈鼓掌</option>\n"           "        <option value=\"//dance\">翩翩起舞</option>\n"           "    	<option value=\"//drivel\">流口水</option>\n"           "    	<option value=\"//wave\">摇手</option>\n"           "    	<option value=\"//bye\">再见</option>\n"           "  	<option value=\"//giggle\">呆笑</option>\n"           "    	<option value=\"//grin\">邪恶地笑</option>\n"           "      	<option value=\"//growl\">大声咆哮</option>\n"           "        </select>\n"           "	<select name=\"ccc\" onChange=\"add_cc0(this, this.options[this.selectedIndex].value)\">\n"           "	<option value=\"\" selected>白色</option>\n"           "	<option value=\"%s\"><font color=\"green\">红色</font></option>\n"           "	<option value=\"%s\"><font color=\"red\">绿色</font></option>\n"           "        <option value=\"%s\"><font color=\"blue\">蓝色</font></option>\n"           "        <option value=\"%s\"><font color=\"blue\">天蓝</font></option>\n"           "        <option value=\"%s\"><font color=\"yellow\">黄色</font></option>\n"           "        <option value=\"%s\"><font color=\"red\">品红</font></option>\n"           "	<option value=\"%s\">大字</option>\n"           "	</select>\n"           "	<select onChange=\"do_func(this.selectedIndex);this.selectedIndex=0;\">\n"           " 	<option selected>聊天室功能</option>\n"           "	<option>进入" CHAT_ROOM_NAME "</option>\n"           "	<option>查看" CHAT_ROOM_NAME "名称</option>\n"           "	<option>本" CHAT_ROOM_NAME "有谁</option>\n"           "	<option>看有谁在线</option>\n"           "	<option>丢小纸条</option>\n"           "	<option>改聊天代号</option>\n"           "	<option>贴图片</option>\n"           "	<option>清除屏幕</option>\n"           "	<option>背景反色</option>\n"           "	<option>离开聊天室</option>\n"           "        </select>\n"           "	<br>\n"           "	[<a href=\"javascript:do_quit()\">离开"           CHAT_SERVER           "</a>] \n"           "	[<a href=\"/chathelp.html\" target=\"_blank\">聊天室帮助</a>]\n"           "	<script>\n"           "	function do_func(n) {\n"           "		if(n==0) return;\n"           "		if(n==1) return do_room();\n"           "		if(n==2) return do_r();\n"           "		if(n==3) return do_w();\n"           "		if(n==4) return do_user();\n"           "		if(n==5) return do_msg();\n"           "		if(n==6) return do_n();\n"           "		if(n==7) return do_pic();\n"           "		if(n==8) return do_c();\n"           "		if(n==9) return do_css2();\n"           "		if(n==10) return do_quit();\n"           "	}\n"           "	var css1;\n"           "	css1='/bbschat.css';\n"           "	function do_c() {\n"           "		top.main.document.close();\n"           "                top.main.document.writeln('<link rel=\"stylesheet\" type=\"text/css\" href=\"'+css1+'\"><body><pre><font class=\"c37\">');\n"           "	}\n"           "	function do_css2() {\n"           "		if(css1=='bbschat.css')\n"           "			css1='/bbschat2.css';\n"           "		else\n"           "			css1='/bbschat.css';\n"           "		top.main.document.writeln('<link rel=\"stylesheet\" type=\"text/css\" href=\"'+css1+'\"><body><pre><font class=\"c37\">');\n"           "	}\n"           "	function add_cc() {\n"           "	 	xxx=form1.in1.value;\n"           "		if(xxx=='/h' || xxx=='//') {\n"           "			do_help();\n"           "			form1.in1.value='';\n"           "			return; \n"           "		}\n"           "		if(xxx=='/c') {\n"           "			do_c();\n"           "			form1.in1.value='';\n"           "			return;\n"           "		}\n"           "		if(xxx=='') return;\n"           " 		if(xxx.indexOf('/')<0) {\n"           " 			form1.in1.value=cc+xxx;\n"           " 		}\n"           " 		if(cc=='/I') {\n"           " 			cc='';\n"           " 			cc2.selectedIndex=0;\n" " 		}\n" " 	}\n" "	</script>\n" "	</form></body>\n", pid, pid, "%R", "%G", "%B", "%C", "%Y", "%M", "%I");    http_quit();}int chatsnd(int pid){    char in1[255], filename[256];    FILE *fp;    strsncpy(in1, getparm("in1"), 60);    sprintf(filename, "tmp/%d.in", pid);    fp = fopen(filename, "a");    fprintf(fp, "%s\n\n", in1);    fclose(fp);    chatrefresh(pid);}char *cco(char *s){    static char buf[512];    char *p = buf, co[20];    bzero(buf, 512);    while (s[0]) {        if (s[0] != '%') {            p[0] = s[0];            p++;            s++;            continue;        }        bzero(co, 20);        if (!strncmp(s, "%R", 2))            strcpy(co, "");        if (!strncmp(s, "%G", 2))            strcpy(co, "");        if (!strncmp(s, "%B", 2))            strcpy(co, "");        if (!strncmp(s, "%C", 2))            strcpy(co, "");        if (!strncmp(s, "%Y", 2))            strcpy(co, "");        if (!strncmp(s, "%M", 2))            strcpy(co, "");        if (!strncmp(s, "%N", 2))            strcpy(co, "");        if (!strncmp(s, "%W", 2))            strcpy(co, "");        if (!strncmp(s, "%I", 2))            strcpy(co, "");        if (co[0]) {            strncpy(p, co, strlen(co));            p += strlen(co);            s += 2;            continue;        }        p[0] = s[0];        p++;        s++;    }    return buf;}int chatrefresh(int pid){    char filename[256], tmp[256];    int t1;    FILE *fp;    kill(pid, SIGINT);    usleep(150000);    if (kill(pid, 0) != 0) {        printf("<script>top.location='javascript:close()';</script>");        exit(0);    }    sprintf(filename, "tmp/%d.out", pid);    t1 = time(0);    while (abs(t1 - time(0)) < 8 && !file_exist(filename)) {        sleep(1);        continue;    }    fp = fopen(filename, "r");    if (fp) {        while (1) {            int i;            char buf2[512];            if (fgets(buf2, 255, fp) == NULL)                break;            sprintf(genbuf, "%s", cco(buf2));            for (i = 0; genbuf[i]; i++) {                if (genbuf[i] == 10 || genbuf[i] == 13)                    genbuf[i] = 0;            }            if (!strncmp(genbuf, "/init", 5)) {                printf("<script>\n");                printf("top.main.document.write('");                printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"/bbschat.css\"><body id=\"body1\" bgColor=\"black\"><pre><img src=\"/pic001.gif\">");                printf("');");                printf("\n</script>\n");                continue;            }            if (!strncmp(genbuf, "/t", 2)) {                int i;                printf("<script>top.document.title='%s%s--话题: ", BBS_FULL_NAME, CHAT_SERVER);                hprintf("%s", genbuf + 2);                printf("'</script>");                sprintf(buf2, "本%s的话题是: [%s]", CHAT_ROOM_NAME, genbuf + 2);                strcpy(genbuf, buf2);            }            if (!strncmp(genbuf, "/r", 2)) {                sprintf(buf2, "本%s的名称是: [%s]", CHAT_ROOM_NAME, genbuf + 2);                strcpy(genbuf, buf2);            }            if (!strncmp(genbuf, "/", 1)) {                genbuf[0] = '>';                genbuf[1] = '>';            }            for (i = 0; i < strlen(genbuf); i++) {                if (genbuf[i] == 10 || genbuf[i] == 13)                    genbuf[i] = 0;                if (genbuf[i] == 34)                    genbuf[i] = 39;            }            printf("<script>\n");            printf("top.main.document.writeln('");            hhprintf("%s", genbuf);            printf(" <font class=\"c37\">");            printf("');");            printf("top.main.scrollBy(0, 99999);\n");            if (test == 0)                printf("top.input.form1.in1.value='';\n");            printf("</script>\n");        }    }    unlink(filename);    printf("<br>");    http_quit();}void foo(){    FILE *fp;    char filename[80], buf[256];    sprintf(filename, "tmp/%d.in", getpid());    fp = fopen(filename, "r");    if (fp) {        while (1) {            if (fgets(buf, 250, fp) == NULL)                break;            write(chat_fd, buf, strlen(buf));        }        fclose(fp);    }    unlink(filename);    alarm(60);}void abort_chat(){    int pid = getpid();    char filename[200];    sprintf(filename, "tmp/%d.out", pid);    unlink(filename);    sprintf(filename, "tmp/%d.in", pid);    unlink(filename);    exit(0);}int agent(int pid){    int i, num;    FILE *fp;    char filename[80];    struct sockaddr_in blah;    sprintf(filename, "tmp/%d.out", pid);    bzero((char *) &blah, sizeof(blah));    blah.sin_family = AF_INET;    blah.sin_addr.s_addr = inet_addr("127.0.0.1");    blah.sin_port = htons(CHATPORT3);    chat_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);    if (connect(chat_fd, (struct sockaddr *) &blah, 16) < 0)        return;    signal(SIGINT, foo);    signal(SIGALRM, abort_chat);    alarm(60);    sprintf(genbuf, "/! %d %d %s %s %d\n", u_info->uid, currentuser->userlevel, currentuser->userid, currentuser->userid, 0);    write(chat_fd, genbuf, strlen(genbuf));    read(chat_fd, genbuf, 2);    if (!strcasecmp(genbuf, "OK"))        exit(0);    fp = fopen(filename, "w");    fprintf(fp, "/init\n");    fclose(fp);    while (1) {        num = read(chat_fd, genbuf, 2048);        if (num <= 0)            break;        for (i = 0; i < num; i++)            if (genbuf[i] == 0)                genbuf[i] = 10;        genbuf[num] = 0;        fp = fopen(filename, "a");        fprintf(fp, "%s", genbuf);        fclose(fp);    }    abort_chat();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?