+/* $Id$ */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <string.h>
+#include <limits.h>
#include <pthread.h>
#include "citadel.h"
#include "server.h"
#include <syslog.h>
-#ifdef NEED_SELECT_H
+#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
-#include "proto.h"
+#include "serv_chat.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "dynloader.h"
-extern struct config config;
-
-typedef struct CitContext t_context;
+struct ChatLine *ChatQueue = NULL;
+int ChatLastMsg = 0;
extern struct CitContext *ContextList;
-struct ChatLine *ChatQueue = NULL;
-int ChatLastMsg = 0;
+#define MODULE_NAME "Chat module"
+#define MODULE_AUTHOR "Art Cancro"
+#define MODULE_EMAIL "ajc@uncnsrd.mt-kisco.ny.us"
+#define MAJOR_VERSION 0
+#define MINOR_VERSION 2
+static struct DLModule_Info info =
+{
+ MODULE_NAME,
+ MODULE_AUTHOR,
+ MODULE_EMAIL,
+ MAJOR_VERSION,
+ MINOR_VERSION
+};
+
+struct DLModule_Info *Dynamic_Module_Init(void)
+{
+ CtdlRegisterProtoHook(cmd_chat, "CHAT",
+ "Initiates a real-time chat session");
+ CtdlRegisterProtoHook(cmd_pexp, "PEXP", "Poll for express messages");
+ CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an express message");
+ return &info;
+}
void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
{
{
sprintf(bcast,":|<%s whispers %s>", un, cmdbuf);
}
- if ((strucmp(cmdbuf,"NOOP")) && (flag !=2)) {
+ if ((strcasecmp(cmdbuf,"NOOP")) && (flag !=2)) {
fp = fopen(CHATLOG,"a");
fprintf(fp,"%s\n",bcast);
fclose(fp);
}
clnew = (struct ChatLine *) malloc(sizeof(struct ChatLine));
- bzero(clnew, sizeof(struct ChatLine));
+ memset(clnew, 0, sizeof(struct ChatLine));
if (clnew == NULL) {
fprintf(stderr, "citserver: cannot alloc chat line: %s\n",
strerror(errno));
time(&now);
clnew->next = NULL;
clnew->chat_time = now;
- strncpy(clnew->chat_room, roomname, 19);
+ strncpy(clnew->chat_room, roomname, sizeof clnew->chat_room);
+ clnew->chat_room[sizeof clnew->chat_room - 1] = 0;
if (username)
- strncpy(clnew->chat_username, username, 31);
+ {
+ strncpy(clnew->chat_username, username,
+ sizeof clnew->chat_username);
+ clnew->chat_username[sizeof clnew->chat_username - 1] = 0;
+ }
else
clnew->chat_username[0] = '\0';
strcpy(clnew->chat_text, bcast);
else
name = t_cc->curr_user;
tptr = *unstr;
- if ((!struncmp(name, tptr, strlen(name))) && (tptr[strlen(name)] == ' '))
+ if ((!strncasecmp(name, tptr, strlen(name))) && (tptr[strlen(name)] == ' '))
{
found_cc = t_cc;
*unstr = &(tptr[strlen(name)+1]);
/*
* List users in chat. Setting allflag to 1 also lists users elsewhere.
*/
-
void do_chat_listing(int allflag)
{
cprintf(":|\n:| Users currently in chat:\n");
begin_critical_section(S_SESSION_TABLE);
for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
- if ( (!strucmp(ccptr->cs_room, "<chat>"))
+ if ( (!strcasecmp(ccptr->cs_room, "<chat>"))
&& ((ccptr->cs_flags & CS_STEALTH) == 0)) {
cprintf(":| %-25s <%s>\n", (ccptr->fake_username[0]) ? ccptr->fake_username : ccptr->curr_user, ccptr->chat_room);
}
cprintf(":|\n:| Users not in chat:\n");
for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next)
{
- if ( (strucmp(ccptr->cs_room, "<chat>"))
+ if ( (strcasecmp(ccptr->cs_room, "<chat>"))
&& ((ccptr->cs_flags & CS_STEALTH) == 0))
{
cprintf(":| %-25s <%s>:\n", (ccptr->fake_username[0]) ? ccptr->fake_username : ccptr->curr_user, (ccptr->fake_roomname[0]) ? ccptr->fake_roomname : ccptr->cs_room);
char cmdbuf[256];
char *un;
char *strptr1;
- char hold_cs_room[20];
+ char hold_cs_room[ROOMNAMELEN];
int MyLastMsg, ThisLastMsg;
struct ChatLine *clptr;
struct CitContext *t_context;
time(&CC->lastcmd);
time(&CC->lastidle);
- if ( (!strucmp(cmdbuf,"exit"))
- ||(!strucmp(cmdbuf,"/exit"))
- ||(!strucmp(cmdbuf,"quit"))
- ||(!strucmp(cmdbuf,"logout"))
- ||(!strucmp(cmdbuf,"logoff"))
- ||(!strucmp(cmdbuf,"/q"))
- ||(!strucmp(cmdbuf,".q"))
- ||(!strucmp(cmdbuf,"/quit"))
+ if ( (!strcasecmp(cmdbuf,"exit"))
+ ||(!strcasecmp(cmdbuf,"/exit"))
+ ||(!strcasecmp(cmdbuf,"quit"))
+ ||(!strcasecmp(cmdbuf,"logout"))
+ ||(!strcasecmp(cmdbuf,"logoff"))
+ ||(!strcasecmp(cmdbuf,"/q"))
+ ||(!strcasecmp(cmdbuf,".q"))
+ ||(!strcasecmp(cmdbuf,"/quit"))
) strcpy(cmdbuf,"000");
if (!strcmp(cmdbuf,"000")) {
return;
}
- if ((!strucmp(cmdbuf,"/help"))
- ||(!strucmp(cmdbuf,"help"))
- ||(!strucmp(cmdbuf,"/?"))
- ||(!strucmp(cmdbuf,"?"))) {
+ if ((!strcasecmp(cmdbuf,"/help"))
+ ||(!strcasecmp(cmdbuf,"help"))
+ ||(!strcasecmp(cmdbuf,"/?"))
+ ||(!strcasecmp(cmdbuf,"?"))) {
cprintf(":|\n");
cprintf(":|Available commands: \n");
cprintf(":|/help (prints this message) \n");
cprintf(":|\n");
ok_cmd = 1;
}
- if (!strucmp(cmdbuf,"/who")) {
+ if (!strcasecmp(cmdbuf,"/who")) {
do_chat_listing(0);
ok_cmd = 1;
}
- if (!strucmp(cmdbuf,"/whobbs")) {
+ if (!strcasecmp(cmdbuf,"/whobbs")) {
do_chat_listing(1);
ok_cmd = 1;
}
- if (!struncmp(cmdbuf,"/me ",4)) {
+ if (!strncasecmp(cmdbuf,"/me ",4)) {
allwrite(&cmdbuf[4],1, CC->chat_room, NULL);
ok_cmd = 1;
}
- if (!struncmp(cmdbuf,"/msg ", 5))
+ if (!strncasecmp(cmdbuf,"/msg ", 5))
{
ok_cmd =1;
strptr1 = &cmdbuf[5];
if ((t_context = find_context(&strptr1)))
{
allwrite(strptr1, 2, "", CC->curr_user);
- if (strucmp(CC->curr_user, t_context->curr_user))
+ if (strcasecmp(CC->curr_user, t_context->curr_user))
allwrite(strptr1, 2, "", t_context->curr_user);
}
else
cprintf("\n");
}
- if (!struncmp(cmdbuf,"/join ", 6))
+ if (!strncasecmp(cmdbuf,"/join ", 6))
{
ok_cmd = 1;
allwrite("<changing rooms>",0, CC->chat_room, NULL);
strcpy(CC->chat_room, "Main room");
else
{
- strncpy(CC->chat_room, &cmdbuf[6], 20);
+ strncpy(CC->chat_room, &cmdbuf[6],
+ sizeof CC->chat_room);
+ CC->chat_room[sizeof CC->chat_room - 1] = 0;
}
allwrite("<joining room>",0, CC->chat_room, NULL);
cprintf("\n");
allwrite(cmdbuf,0, CC->chat_room, NULL);
}
- if (!ok_cmd)
+ if ((!ok_cmd) && (cmdbuf[0]) && (cmdbuf[0] != '\n'))
cprintf(":|Command %s is not understood.\n", cmdbuf);
strcpy(cmdbuf, "");
ThisLastMsg = ChatLastMsg;
for (clptr=ChatQueue; clptr!=NULL; clptr=clptr->next)
{
- if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!struncmp(un, clptr->chat_username, 32))))
+ if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!strncasecmp(un, clptr->chat_username, 32))))
{
- if ((!clptr->chat_room[0]) || (!struncmp(CC->chat_room, clptr->chat_room, 20)))
+ if ((!clptr->chat_room[0]) || (!strncasecmp(CC->chat_room, clptr->chat_room, ROOMNAMELEN)))
{
cprintf("%s\n", clptr->chat_text);
}
/*
* poll for express messages
*/
-void cmd_pexp(void) {
+void cmd_pexp(char *argbuf) /* arg unused */ {
struct ExpressMessage *emptr;
if (CC->FirstExpressMessage == NULL) {
cprintf("000\n");
}
-/*
- * returns an asterisk if there are any express messages waiting,
- * space otherwise.
- */
-char check_express(void) {
- if (CC->FirstExpressMessage == NULL) {
- return(' ');
- }
- else {
- return('*');
- }
- }
-
/*
* send express messages <bc>
return;
}
- if ( (!strucmp(x_user, "broadcast")) && (CC->usersupp.axlevel < 6) ) {
+ if ( (!strcasecmp(x_user, "broadcast")) && (CC->usersupp.axlevel < 6) ) {
cprintf("%d Higher access required to send a broadcast.\n",
ERROR+HIGHER_ACCESS_REQUIRED);
return;
else
un = ccptr->usersupp.fullname;
- if ( (!strucmp(un, x_user))
- || (!strucmp(x_user, "broadcast")) ) {
+ if ( (!strcasecmp(un, x_user))
+ || (!strcasecmp(x_user, "broadcast")) ) {
strcpy(ccptr->last_pager, CC->curr_user);
emnew = (struct ExpressMessage *)
malloc(sizeof(struct ExpressMessage));
emnew->next = NULL;
sprintf(emnew->em_text, "%s from %s:\n %s\n",
- ( (!strucmp(x_user, "broadcast")) ? "Broadcast message" : "Message" ),
+ ( (!strcasecmp(x_user, "broadcast")) ? "Broadcast message" : "Message" ),
lun, x_msg);
if (ccptr->FirstExpressMessage == NULL) {