📄 chat.c
字号:
printf("<a target=new href=\"%s\">%s</a>", your_url, xname); else printf("%s", xname); printf("</font>:<br>\n"); printf("<font size=-1 color=\"#a0a0a0\"><code>%s", nicetime(xtime)); printf("</code></font></td>\n"); printf("</tr></table></td>\n"); printf("<td valign=top><code>"); /* Add color if messages are new */ if (isnew(xtime, lasttime) == 1) printf("<font color=\"#000088\"><b>"); addurls(xmesg); addfaces(xmesg); addconverts(xmesg); if (ok != -1) { if (ok == 2) { if (strstr(name, xmesg) == xmesg + 1) { if (strchr(xmesg, ' ') != NULL) printf("<i>%s</i>", strchr(xmesg, ' ') + 1); } else printf("<i>%s</i>", xmesg); } else printf("%s", xmesg); } else printf("<font size=-1><i>(whispering...)</i></font>"); if (isnew(xtime, lasttime) == 1) printf("</b></font>"); printf("</code><p></td></tr>\n"); } } } while (!feof(fi)); fclose(fi); printf("</table>\n"); } if (only_watching == 0) { if (only_posting == 0) { dumpform(name, email, time, name2, mesg, only_posting, password, whisper_to); printf("</td></tr></table>\n"); dump("included/chat-bottom.html"); } } else dump("included/chat-watch-bottom.html"); close(fdi); return(0);}/* -- NOSWEAR -- *//* Looks for swear words in a string. Returns 1 if there are no (it's ok) or 0 if there are swear words (it's not ok) */int noswear(char * text){ FILE * fi; char word[80], temp[80], ltext[STRLEN]; int a, ok, in, no_on_left, no_on_right; char left_char, right_char; /* Make my message all lowercase (there is no "strcasestr" function!!!) */ /* (Add spaces to either end for testing purposes later on) */ ltext[0] = ' '; for (a = 0; a <= strlen(text); a++) ltext[a + 1] = tolower(text[a]); strcat(ltext, " "); no_on_left = 0; no_on_right = 0; ok = 1; fi = myopen("swear.dat", "r"); if (fi != NULL) { do { fgets(temp, 80, fi); if (!feof(fi)) { temp[strlen(temp) - 1] = '\0'; strcpy(word, temp); /* Check for "wildcards" - ie, even words which CONTAIN this word are illegal. */ if (word[0] == '*') { strcpy(word, temp + 1); no_on_left = 1; } if (word[strlen(word) - 1] == '*') { word[strlen(word) - 1] = '\0'; no_on_right = 1; } /* If you found the word, then it's not ok to show message! */ in = instr(ltext, word); if (in != -1) { /* Make sure it's a whole word! */ left_char = ltext[in - 1]; right_char = ltext[in + strlen(word)]; if ((isalpha(left_char) == 0) && (isalpha(right_char) == 0)) ok = 0; } } } while (!feof(fi) && ok == 1); fclose(fi); } return(ok);}int whohere(char * name, char * email, char * time, int only_posting, int only_watching){ FILE * fi, * fo; int here, found, user_time, now_time; char temp[STRLEN], xname[STRLEN], xemail[STRLEN], xstarttime[STRLEN], xtime[STRLEN]; fo = myopen("who.tmp", "w"); if (fo == NULL) { printf("System is down!"); exit(0); } fi = myopen("who.dat", "r"); if (fi == NULL) { printf("System is down!"); exit(0); } here = 0; found = 0; do { readline(fi, xname); if (!feof(fi)) { readline(fi, xemail); readline(fi, xstarttime); readline(fi, xtime); readline(fi, temp); if (strcmp(name, xname) == 0) { found = 1; strcpy(xtime, time); } user_time = ((((xtime[0] - '0') * 10) + xtime[1] - '0') * 60) + (((xtime[3] - '0') * 10) + xtime[4] - '0'); now_time = ((((time[0] - '0') * 10) + time[1] - '0') * 60) + (((time[3] - '0') * 10) + time[4] - '0'); if (now_time < user_time) now_time = now_time + (24 * 60); if (now_time - user_time < IDLE) { fprintf(fo, "%s\n", xname); fprintf(fo, "%s\n", xemail); fprintf(fo, "%s\n", xstarttime); fprintf(fo, "%s\n", xtime); fprintf(fo, "\n"); here = here + 1; } else { sprintf(temp,"%s was idle over %d minutes and has been removed.", xname, IDLE); chatwrite(time, "IDLE", temp); } } } while (!feof(fi)); fclose(fi); /* Add you to the "who's here" list if you weren't in it... */ if (found == 0 && only_watching == 0) { if (joining == 1) { sprintf(temp, "%s has joined. (%s) ", name, getenv("REMOTE_ADDR")); if (sysop == 1) strcat(temp, SYSOP_JOIN_WARNING); chatwrite(time, "JOIN", temp); if (only_posting == 0) { sprintf(temp, "/%s NOTE - Remember to hit REFRESH to keep updated!", name); chatwrite(time, "NOTE", temp); } } fprintf(fo, "%s\n", name); fprintf(fo, "%s\n", email); fprintf(fo, "%s\n", time); fprintf(fo, "%s\n", time); fprintf(fo, "\n"); here = here + 1; } fclose(fo); copyback("who.dat", "who.tmp"); return(here);}void spacetoplus(char * dest, char * source){ int i; for (i = 0; i <= strlen(source); i++) { if (source[i] != ' ') dest[i] = source[i]; else dest[i] = '+'; }}void dumpform(char * name, char * email, char * time, char * name2, char * lastmesg, int only_posting, char * password, char * whisper_to){ FILE * fi; int i; char temp[1024]; printf("<form action=\"chat.cgi\" method=\"post\">\n"); printf("<input type=\"hidden\" name=\"name\" value=\"%s\">\n", name); printf("<input type=\"hidden\" name=\"email\" value=\"%s\">\n", email); printf("<input type=\"hidden\" name=\"password\" value=\"%s\">\n", password); printf("<input type=\"hidden\" name=\"time\" value=\"%s\">\n", time); printf("<input type=\"hidden\" name=\"lastmesg\" value=\"%s\">\n", lastmesg); if (only_posting == 1) printf("<input type=\"hidden\" name=\"post\" value=\"yes\">\n"); printf("<table border=0 cellspacing=0 cellpadding=2>\n"); printf("<tr><td valign=top><nobr>\n"); if (WHISPERING == ON || (WHISPERING == SYSOPS_ONLY && sysop == 1) || (WHISPERING == REGISTERED_ONLY && registered == 1)) { printf("Whisper to:<br>\n"); printf("<select name=\"whisper\">\n"); printf("<option value=\"\">NONE\n"); fi = myopen("who.dat", "r"); if (fi != NULL) { do { readline(fi, temp); if (!feof(fi)) { if (strcmp(name, temp) != 0) { printf("<option"); if (strcmp(temp, whisper_to) == 0) printf(" selected"); printf(">%s\n", temp); } readline(fi, temp); readline(fi, temp); readline(fi, temp); readline(fi, temp); } } while (!feof(fi)); fclose(fi); } printf("</select>\n"); } printf("</nobr></td>\n"); printf("<td valign=bottom><nobr>\n"); printf("<input type=\"text\" size=55 maxlength=%d name=\"mesg\">\n", STRLEN); printf("<code>%s</code> <br>\n", nicetime(time)); printf("<input type=\"image\" value=\"[Send]\"\n"); printf("alt=\"[Send]\"\n"); printf("src=\"%sbuttons/send.gif\" width=%d height=%d border=0>\n", PREPEND, SEND_W, SEND_H); if (only_posting == 1) { printf("<a href=\"chat.cgi?watch=yes&name=%s&email=%s&password=%s&random=%d&time=%s\" target=\"text\">\n", name, email, password, getpid(), time); printf("<img alt=\"[Refresh]\"\n"); printf("src=\"%sbuttons/refresh.gif\" width=%d height=%d border=0>", PREPEND, REFRESH_W, REFRESH_H); printf("</a>\n"); } else { printf("<input type=\"image\" name=\"refresh\" value=\"[Refresh]\"\n"); printf("alt=\"[Refresh]\"\n"); printf("src=\"%sbuttons/refresh.gif\" width=%d height=%d border=0>\n", PREPEND, REFRESH_W, REFRESH_H); } strcpy(temp, time); for (i = 0; i < strlen(temp); i++) if (temp[i] == ':') temp[i] = '_'; printf("<a href=\"who.cgi?%s\" target=\"text\"><img\n", temp); printf("src=\"%sbuttons/who.gif\" alt=\"[Who's Here?]\"", PREPEND); printf(" width=%d height=%d border=0></a>\n", WHO_W, WHO_H); printf("<a href=\"%shelp/\" target=\"text\"><img\n", PREPEND); printf("src=\"%sbuttons/help.gif\" alt=\"[Help]\"", PREPEND); printf(" width=%d height=%d border=0></a>\n", HELP_W, HELP_H); printf("<a href=\"leave.cgi?name=%s\" target=\"_top\"><img\n", name2); printf("src=\"%sbuttons/leave.gif\"\n", PREPEND); printf(" alt=\"[Leave]\" width=%d height=%d border=0></a>\n", LEAVE_W, LEAVE_H); printf("<font face=\"Arial, Geneva\" size=-2>"); printf("<a target=\"_top\"\n"); printf("href=\"chat.cgi?name=%s&email=%s&password=%s", name, email, password); if (only_posting == 0) printf("&duelenter=yes\">Turn Frames On"); else printf("\">Turn Frames Off"); printf("</a></font>\n"); printf("</nobr></td></tr>\n"); printf("</table>\n\n"); printf("</form>\n");}void addfaces(char * mesg){ int i, oi, l, ok, z; char temp[2048], face[1024], prefix[10], brows[10], mouth[10], alt[10]; l = 0; strcpy(temp, ""); for (i = 0; i < strlen(mesg); i++) { oi = i; ok = 1; if (mesg[i] == ':' || mesg[i] == '=' || mesg[i] == ';') { strcpy(alt, ""); strcpy(brows, "normal"); if (i >= 4) { if (mesg[i - 1] == ';' && mesg[i - 2] == 't' && mesg[i - 4] == '&') { if (mesg[i - 3] == 'g') { strcpy(brows, "mad"); strcpy(alt, "]"); } else if (mesg[i - 3] == 'l') { strcpy(brows, "upset"); strcpy(alt, "["); } } } strcpy(prefix, ""); if (mesg[i] == ';') { strcpy(prefix, "wink-"); strcat(alt, ";"); } else strcat(alt, ":"); i++; if (mesg[i] == '^' || mesg[i] == '-' || mesg[i] == '\'') i++; strcpy(mouth, ""); z = strlen(alt); alt[z] = mesg[i]; alt[z + 1] = '\0'; if (mesg[i] == ')' || mesg[i] == 'D' || mesg[i] == ']') strcpy(mouth, "smile"); else if (mesg[i] == '(') strcpy(mouth, "frown"); else if (mesg[i] == '|') strcpy(mouth, "shy"); else if (mesg[i] == 'P' || mesg[i] == 'p') strcpy(mouth, "tongue"); else if (mesg[i] == 'O' || mesg[i] == 'o') strcpy(mouth, "amazed"); if (strlen(mouth) != 0) { ok = 0; sprintf(face, "<img src=\"%sfaces/%s%s-%s.gif\" alt=\"%s\"", PREPEND, prefix, mouth, brows, alt); strcat(face, " width=16 height=16>"); temp[l] = '\0'; if (strcmp(brows, "normal") != 0) temp[l - 4] = '\0'; strcat(temp, face); l = strlen(temp); } else { i = oi; ok = 1; } } if (ok == 1) { temp[l++] = mesg[i]; temp[l] = '\0'; } } strcpy(mesg, temp);}void addconverts(char * mesg){ int width; char * mesg_ptr; char temp[STRLEN], img[STRLEN], text[STRLEN], right[STRLEN]; FILE * fi; fi = fopen("convert.dat", "r"); if (fi != NULL) { do { readline(fi, text); if (!feof(fi)) { readline(fi, img); readline(fi, temp); width = 0; if (strchr(img, ' ') != NULL) { width = atoi(strchr(img, ' ') + 1); strcpy(strchr(img, ' '), "\0"); } if (width == 0) width = 16; mesg_ptr = mesg; while (strstr(mesg_ptr, text) != NULL) { strcpy(right, strstr(mesg_ptr, text) + strlen(text)); sprintf(temp, "<img src=\"%sconvert/%s\" width=%d", PREPEND, img, width, text); strcat(temp, " height=16 alt=\"%s\">"); strcpy(strstr(mesg_ptr, text), temp); mesg_ptr = mesg + strlen(mesg); strcat(mesg_ptr, right); } } } while (!feof(fi)); fclose(fi); }}int isnew(char * this, char * last){ int thisint, lastint; thisint = timetoint(this); lastint = timetoint(last); /* if (thisint > lastint) lastint = lastint + (24 * 60 * 60); */ if (thisint <= lastint || thisint - 12*60*60 > lastint) return 0; else return 1;}int timetoint(char * str){ return ((((str[0] - '0') * 10 + (str[1] - '0')) * 60 + (str[3] - '0') * 10 + (str[4] - '0')) * 60 + (str[6] - '0') * 10 + (str[7] - '0'));}void addurls(char * str){ int i, l; char temp[10240], url[1024], temp2[1024]; strcpy(temp, ""); l = 0; for (i = 0; i < strlen(str); i++) { if (str[i] == 'h' && str[i + 1] == 't' && str[i + 2] == 't' && str[i + 3] == 'p' && (str[i + 4] == ':' || str[i + 4] == ';') && str[i + 5] == '/' && str[i + 6] == '/') { if (str[i + 4] == ';') str[i + 4] = ':'; strcpy(url, str + i); if (strchr(url, ' ') != NULL) strcpy(strchr(url, ' '), "\0"); if (strchr(url, '\"') != NULL) strcpy(strchr(url, '\"'), "\0"); if (strchr(url, ',') != NULL) strcpy(strchr(url, ','), "\0"); if (strstr(url, ">") != NULL) strcpy(strstr(url, ">"), "\0"); sprintf(temp2, "<a href=\"%s\" target=new>%s</a> ", url, url); strcat(temp, temp2); i = i + strlen(url) - 1; l = strlen(temp); } else { temp[l++] = str[i]; temp[l] = '\0'; } } strcpy(str, temp);}void robotspeak(char * time, char * name, char * mesg){ char response[1024], keyword[1024], try_response[1024], temp[1024], mesg2[STRLEN]; FILE * fi; int i; for (i = 0; i <= strlen(mesg); i++) mesg2[i] = tolower(mesg[i]); strcpy(response, ""); fi = fopen("robot.dat", "r"); if (fi != NULL) { do { readline(fi, keyword); if (!feof(fi)) { readline(fi, try_response); readline(fi, temp); if (strstr(mesg2, keyword) != NULL) strcpy(response, try_response); } } while (!feof(fi)); fclose(fi); } if (strlen(response) != 0) { if (strchr(response, '~') != NULL) { strcpy(temp, response); strcpy(strchr(temp, '~'), "\0"); strcat(temp, name); strcat(temp, strchr(response, '~') + 1); strcpy(response, temp); } chatwrite(time, "Chat_Robot", response); }}void informadmin(char * name, char * mesg){ char cmd[1024]; FILE * pi; sprintf(cmd, "%s %s", MAIL_CMD, ADMIN_EMAIL); pi = popen(cmd, "w"); if (pi != NULL) { fprintf(pi, "Subject: Sysop action\n\n"); fprintf(pi, "Sysop: %s\n", name); fprintf(pi, "Action: %s\n", mesg); pclose(pi); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -