⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chat.c

📁 运行在linux下的聊天软件
💻 C
📖 第 1 页 / 共 3 页
字号:
	  dump("included/chat-left.html");
	  
	  printf("</td><td valign=top>\n");
	}
      else
	{
	  dump("included/chat-post-top.html");
	}
      
      printf("<table border=0 cellspacing=0 cellpadding=0><tr><td>\n");
      
      dumpform(name, email, time, name2, mesg, only_posting, password,
	       whisper_to);
      
      
      /* Add their message: */
      
      if (strlen(mesg) != 0)
	{
	  ok = noswear(mesg);
	  if (ok == 0)
	    printf("</td><td><b><i><blink><u>NO SWEARING!!!</u></blink></b></i>\n");
	}
      else
	ok = 0;
      
      if (strcmp(lastmesg, mesg) == 0 && strlen(mesg) > 0)
	{
	  printf("</td><td><b><i><blink><u>YOU ALREADY SAID\n");
	  printf("THAT!</u></blink></b></i>\n");
	  ok = 0;
	}

      
      if (ok == 1)
	{
	  chatwrite(time, name, mesg);
	  robotspeak(time, name, mesg);
	}
      
      
      /* Notify them if their message is in all caps! */

      if (mesg[0] != '/')
	strcpy(temp, mesg);
      else
	{
	  if (strchr(mesg, ' ') != NULL)
	    strcpy(temp, strchr(mesg, ' ') + 1);
	  else
	    strcpy(temp, "");
	}
      
      
      ok = 0;
      for (i = 0; i < strlen(temp); i++)
	ok = ok + (islower(temp[i]));
      
      if (ok == 0)
	{
	  ok = 1;
	  for (i = 0; i < strlen(temp); i++)
	    if (isalpha(temp[i]))
	      ok = 0;
	}
      
      if (ok == 0 && strlen(temp) > 5)
	{
	  printf("</td><td><b><i><blink><u>PLEASE TURN OFF YOUR CAPS\n");
	  printf("KEY!</u></blink></b></i>\n");
	}
      
      
      printf("</td></tr></table>\n");
    }
  else
    {
      printf("<html><head>\n");
      printf("<meta http-equiv=\"refresh\"\n");
      printf("content=\"20;URL=chat.cgi?watch=yes&");
      printf("name=%s&email=%s&password=%s&time=%s\"></head>\n", name, email,
	     password, time);
      
      dump("included/chat-watch-top.html");
      
      printf("<table border=0><tr>\n");
      printf("<td valign=top width=120>\n");
      
      printf("<h2 align=center>%s</h2>\n", topic);
      
      printf("<h3 align=center>");
      
      whattime(time);

      here = whohere(name, email, time, 0, 1);
      
      if (here == 1 || here == 0)
	printf("You are the only person here.");
      else
	printf("There are %d people here.", here);
      printf("</h3>\n");
      
      dump("included/chat-left.html");
      printf("</td><td valign=top>\n");
    }
  
  
  if (only_posting == 0)
    {
      /* Dump messages: */
      
      fi = myopen("chat.dat", "r");
      if (fi == NULL)
	{
	  printf("System is down!\n");
	  exit(0);
	}
      
      printf("<table border=0 width=100%% cellpadding=4>\n");
      
      num_shownfaces = 0;
      
      do
	{
	  readline(fi, xtime);
	  if (!feof(fi))
	    {
	      readline(fi, xname);
	      readline(fi, xmesg);
	      
	      ok = 1;
	      
	      if (xmesg[0] == '/')
		{
		  ok = -1;
		  sscanf(xmesg, "%s", temp);
		  if (strcmp(temp + 1, name) == 0 ||
		      strcmp(xname, name) == 0 || god == 1)
		    ok = 2;
		}
	      
	      strcpy(your_url, "");
	      
	      
	      if (ok != 0)
		{
		  printf("<tr><td valign=top align=right>\n");
		  
		  
		  printf("<table border=0 cellspacing=0 cellpadding=0\n");
		  printf("width=100%%><tr>");
		  
		  printf("<td valign=top align=right>\n");
		  
		  /* Show their face if we haven't seen it already: */
		  
		  found = 0;
		  for (i = 0; i < num_shownfaces; i++)
		    {
		      if (strcmp(shownfaces[i], xname) == 0)
			found = 1;
		    }
		  
		  showed_pict = 0;
		  
		  if (found == 0)
		    {
		      for (j = 0; j <= strlen(xname); j++)
			{
			  if (xname[j] == '-')
			    temp2[j] = '_';
			  else
			    temp2[j] = xname[j];
			}
		      
		      strcpy(shownfaces[num_shownfaces], xname);
		      num_shownfaces++;
		      
		      sprintf(temp, "%sphotos/%s.gif", UNIX_PREPEND, temp2);
		      
		      fiface = fopen(temp, "r");
		      if (fiface != NULL)
			{
			  fclose(fiface);
			  
			  printf("<img src=\"%sphotos/%s.gif\" width=40 height=40\n",
				 PREPEND, temp2);
			  printf("width=40 height=40 alt=\"\" border=0\n");
			  printf("alt=\"\" border=0>\n");
			  
			  showed_pict = 1;
			}

		      printf("</td><td valign=top align=right>\n");
		      
		      getentry(password, "password");
		      fiface = fopen(ACCESS_FILE, "r");
		      
		      if (fiface != NULL)
			{
			  do
			    {
			      readline(fiface, access_name);
			      
			      if (!feof(fiface))
				{
				  readline(fiface, access_pass);
				  readline(fiface, access_type);
				  readline(fiface, access_url);
				  readline(fiface, temp);
				  
				  if (strcasecmp(access_name, xname) == 0)
				    strcpy(your_url, access_url);
				}
			    }
			  while (!feof(fiface));
			  
			  fclose(fiface);
			}
		    }
		  
		  printf("<font size=-");
		  if (showed_pict == 1)
		    printf("2");
		  else
		    printf("1");
		  
		  printf(" face=\"Arial\">");
		  
		  if (strlen(your_url) != 0 &&
		      strcmp(your_url, "nourl") != 0)
		    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)
	{

⌨️ 快捷键说明

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