📄 chat.c
字号:
/*
chat.c
For Free Chat (beta release 2e2)
By Bill Kendrick
kendrick@zippy.sonoma.edu
http://zippy.sonoma.edu/kendrick/
September 29, 1996 - June 9, 1998
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "cgi-util.h"
#include "dump.h"
#include "readline.h"
#include "instr.h"
#include "copyback.h"
#include "defines.h"
#include "whattime.h"
#include "myopen.h"
#include "nicetime.h"
#define VER "b2e2"
int noswear(char * text);
int whohere(char * name, char * email, char * time, int only_posting,
int only_watching);
void spacetoplus(char * dest, char * source);
void dumpform(char * name, char * email, char * time, char * name2,
char * lastmesg, int only_posting, char * password,
char * whisper_to);
void addfaces(char * mesg);
void addconverts(char * mesg);
int isnew(char * this, char * last);
void addurls(char * str);
void robotspeak(char * time, char * name, char * mesg);
void informadmin(char * name, char * mesg);
int sysop, god, registered, joining;
int main(int argc, char * argv[])
{
char name[STRLEN], email[STRLEN], mesg[STRLEN], topic[STRLEN], name2[STRLEN],
temp[STRLEN], time[STRLEN], xname[STRLEN], xtime[STRLEN], xmesg[STRLEN],
lastmesg[STRLEN], lasttime[20], password[32], access_name[100],
access_pass[100], access_type[100], access_url[512], your_url[512],
temp2[STRLEN], whisper_to[STRLEN];
char shownfaces[MAXLINES][STRLEN];
int here, found, ok, i, x, space, only_watching, only_posting,
num_shownfaces, j, showed_pict, fdi;
FILE * fi, * fiface;
sysop = 0;
god = 0;
registered = 0;
/* Initialize CGI Interface: */
cgiinit();
printf("Content-type: text/html\n\n");
if (getentryyesno("version", 0))
{
printf("Free Chat<br>version %s<p>\n", VER);
printf("<a href=\"mailto:%s\"><code>%s</code></a><p>\n",
ADMIN_EMAIL, ADMIN_EMAIL);
exit(0);
}
joining = getentryyesno("join", 0);
only_watching = getentryyesno("watch", 0);
getentry(name, "name");
for (i = 0; i < strlen(name); i++)
if (isalnum(name[i]) == 0)
name[i] = '-';
while (name[0] == '-')
{
strcpy(temp, name + 1);
strcpy(name, temp);
}
while (name[strlen(name) - 1] == '-')
name[strlen(name) - 1] = '\0';
if (strlen(name) < 3)
error("Please enter a more descriptive name!");
clean(name);
strcpy(name2, name);
getentry(email, "email");
clean(email);
if (strlen(email) != 0 && goodemailaddress(email) == 0)
error("Bad e-mail address!");
getentry(password, "password");
fi = fopen(ACCESS_FILE, "r");
strcpy(your_url, "");
registered = 0;
if (fi != NULL)
{
do
{
readline(fi, access_name);
if (!feof(fi))
{
readline(fi, access_pass);
readline(fi, access_type);
readline(fi, access_url);
readline(fi, temp);
if (strcasecmp(access_name, name) == 0)
{
strcpy(your_url, access_url);
if (strcmp(access_pass, password) == 0)
{
registered = 1;
if (strcmp(access_type, "sysop") == 0)
sysop = 1;
else if (strcmp(access_type, "god") == 0)
{
sysop = 1;
god = 1;
}
}
else
{
printf("<h1>Password Required</h1>\n");
printf("<form action=\"chat.cgi\" method=\"post\">\n");
printf("<input type=\"hidden\" name=\"name\"\n");
printf("value=\"%s\">\n", name);
printf("<input type=\"hidden\" name=\"email\"\n");
printf("value=\"%s\">\n", email);
if (getentryyesno("duelenter", 0) == 1)
{
printf("<input type=\"hidden\"\n");
printf("name=\"duelenter\"\n");
printf("value=\"yes\">\n");
}
printf("Password:\n");
printf("<input type=\"password\" name=\"password\">\n");
printf("<input type=\"submit\" value=\"Enter Chat\">\n");
printf("<br>\n</form>\n");
fclose(fi);
exit(0);
}
}
}
}
while (!feof(fi));
fclose(fi);
}
if (MUST_BE_REGISTERED == YES && registered == 0)
{
printf("Registered users only!<p>\n");
exit(0);
}
if (getentryyesno("duelenter", 0) == 1)
{
only_posting = 1;
printf("<html><head><title>Free Chat - Frames Mode");
printf("</title></head>\n");
printf("<FRAMESET Rows=\"%d,%d,*\" FRAMEBORDER=NO BORDER=NO\n",
FRAME1_HEIGHT, FRAME2_HEIGHT);
printf("FRAMESPACING=\"0\">\n");
printf("<FRAME NAME=\"ad\" SRC=\"%sad.html\" SCROLLING=\"NO\"\n",
PREPEND);
printf("BORDER=NO NORESIZE MARGINWIDTH=1 MARGINHEIGHT=1>\n");
printf("<FRAME NAME=\"entry\" SRC=\"");
printf("chat.cgi?name=%s&email=%s&password=%s&join=yes&",
name, email, password);
printf("post=yes\"\n");
printf("FRAMEBORDER=NO SCROLLING=NO>\n");
printf("<FRAME NAME=\"text\" SRC=\"");
printf("chat.cgi?watch=yes&name=%s&email=%s&password=%s\"\n",
name, email, password);
printf("FRAMEBORDER=NO>\n");
printf("<NOFRAMES>\n");
printf("<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\"\n");
printf("vlink=\"#FF0000\">\n");
printf("<h1 align=center>");
printf("<a href=\"chat.cgi?name=%s&email=%s&password=%s\">",
name, email, password);
printf("Enter Chat</h1>\n");
printf("</body></html>\n");
printf("</NOFRAMES>\n");
printf("</FRAMESET>\n");
exit(0);
}
else
only_posting = getentryyesno("post", 0);
/* Grab file lock on lock.dat so we don't let anyone clobber anything!: */
fdi = open("lock.dat", O_CREAT | O_WRONLY | O_TRUNC);
#ifdef SYSV
lockf(fdi, F_LOCK, 0);
#else
flock(fdi, LOCK_EX);
#endif
/* Get current topic: */
fi = myopen("topic.dat", "r");
if (fi != NULL)
{
readline(fi, topic);
fclose(fi);
}
else
strcpy(topic, "");
getentry(lasttime, "time");
/* Get current time: */
whattime(time);
if (only_watching == 0)
{
fi = fopen("banned.dat", "r");
if (fi != NULL)
{
do
{
readline(fi, temp);
if (!feof(fi))
{
if (strcmp(temp, name) == 0)
{
printf("<b>YOU HAVE BEEN BANNED!</b><p>\n");
printf("Misconduct is not allowed in chat!<p>\n");
printf("<a href=\"mailto:%s\"><code>%s</code></a><p>\n",
ADMIN_EMAIL);
exit(0);
}
if (strstr(getenv("REMOTE_ADDR"), temp) != NULL)
{
printf("<b>IP ADDRESS BLOCK!</b><p>\n");
printf("Sorry!<p>\n");
printf("<a href=\"mailto:%s\"><code>%s</code></a><p>\n",
ADMIN_EMAIL);
exit(0);
}
}
}
while (!feof(fi));
fclose(fi);
}
getentry(temp, "refresh.x");
if (strlen(temp) == 0)
{
getentry(mesg, "mesg");
clean(mesg);
if (strlen(mesg) != 0)
{
getentry(whisper_to, "whisper");
if (strlen(whisper_to) != 0 && mesg[0] != '/' &&
strcmp(whisper_to, "NONE") != 0)
{
sprintf(temp, "/%s %s", whisper_to, mesg);
strcpy(mesg, temp);
}
}
}
else
strcpy(mesg, "");
/* Kill whispers if whispering is turned off: */
if (WHISPERING == OFF || (WHISPERING == SYSOPS_ONLY && sysop == 0) ||
(WHISPERING == REGISTERED_ONLY && registered == 0))
{
if (mesg[0] == '/')
{
strcmp(temp, mesg + 1);
strcpy(mesg, temp);
}
}
getentry(temp, "refresh");
if (strlen(temp) != 0)
strcpy(mesg, "");
getentry(lastmesg, "lastmesg");
space = -1;
x = 0;
for (i = 0; i < strlen(mesg); i++)
{
if (mesg[i] == ' ')
{
x = 0;
space = i;
}
x = x + 1;
if (x > 80)
{
strcpy(temp, mesg + i);
mesg[i] = ' ';
mesg[i + 1] = '\0';
strcat(mesg, temp);
space = i;
x = 0;
}
}
/* No blank names! */
if (strlen(name) == 0 || noswear(name) == 0)
{
if (strcmp(email, "") == 0)
{
dump("included/noname.html");
exit(0);
}
else
{
strcpy(name, email);
if (strchr(name, '@') != NULL)
strcpy(strchr(name, '@'), "\0");
}
}
/* Find out how many people are here.. making sure you're in this
list. */
here = whohere(name, email, time, only_posting, 0);
/* Ban users! */
if (strstr(mesg, "BAN ") == mesg)
{
if (INFORM_ADMIN == YES || INFORM_ADMIN == SMALL)
informadmin(name, mesg);
if (sysop == 1)
{
fi = fopen("banned.dat", "a");
if (fi != NULL)
{
fprintf(fi, "%s\n", strchr(mesg, ' ') + 1);
fclose(fi);
sprintf(temp, "%s has been banned!", strchr(mesg, ' ') + 1);
strcpy(mesg, temp);
}
}
else
ok = 0;
}
/* Change the TOPIC: */
if (strstr(mesg, "TOPIC ") == mesg)
{
if (INFORM_ADMIN == YES)
informadmin(name, mesg);
if (sysop == 1)
{
fi = fopen("topic.dat", "w");
if (fi != NULL)
{
fprintf(fi, "%s\n", strchr(mesg, ' ') + 1);
fclose(fi);
sprintf(temp, "The topic is now \"%s\"!",
strchr(mesg, ' ') + 1);
strcpy(mesg, temp);
}
}
else
ok = 0;
}
/* Dump top of page: */
if (only_posting == 0)
{
dump("included/chat-top.html");
printf("<td>\n");
#ifdef AD_CMD
fflush(stdout);
system(AD_CMD);
fflush(stdout);
#endif
printf("</td></tr></table></center>\n");
printf("<table border=1 cellspacing=0 width=100%%\n");
printf("cellpadding=8>\n");
printf("<tr><td valign=top width=20%% align=center>\n");
printf("<h2 align=center>%s</h2>\n", topic);
printf("<font size=+1><b>");
if (here == 1 || here == 0)
printf("You are the only person here.");
else
printf("There are %d people here.", here);
printf("</b></font><br>\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -