2003-03-23 21:27:14 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* Purpose ...............: mbtask - chat server
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2006-01-24 22:36:58 +00:00
|
|
|
* Copyright (C) 1997-2006
|
2003-03-23 21:27:14 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2003-03-24 19:44:38 +00:00
|
|
|
#include "taskutil.h"
|
|
|
|
#include "taskregs.h"
|
2003-03-23 21:27:14 +00:00
|
|
|
#include "taskchat.h"
|
2005-04-16 14:49:58 +00:00
|
|
|
#include "taskibc.h"
|
2005-04-15 21:36:44 +00:00
|
|
|
|
2003-03-23 21:27:14 +00:00
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
#define MAXMESSAGES 100 /* Maximum ringbuffer for messages */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer for messages, this is the structure of a ringbuffer which will
|
|
|
|
* hold all messages, private public etc. There is one global input pointer
|
|
|
|
* which points to the current head of the ringbuffer. When a user connects
|
|
|
|
* to a channel, he will get the latest messages in the channel if they
|
|
|
|
* are present.
|
|
|
|
*/
|
|
|
|
typedef struct _chatmsg {
|
|
|
|
pid_t topid; /* Destination pid of message */
|
|
|
|
char fromname[36]; /* Message from user */
|
|
|
|
char message[81]; /* The message to display */
|
|
|
|
time_t posted; /* Timestamp for posted message */
|
|
|
|
} _chat_messages;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The buffers
|
|
|
|
*/
|
2003-04-01 21:41:36 +00:00
|
|
|
_chat_messages chat_messages[MAXMESSAGES];
|
2003-03-24 19:44:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
int buffer_head = 0; /* Messages buffer head */
|
|
|
|
extern struct sysconfig CFG; /* System configuration */
|
2003-04-03 20:51:19 +00:00
|
|
|
extern int s_bbsopen; /* The BBS open status */
|
2005-04-22 20:10:03 +00:00
|
|
|
extern int usrchg;
|
2005-04-23 14:27:52 +00:00
|
|
|
extern int chnchg;
|
2005-05-01 13:35:43 +00:00
|
|
|
extern int srvchg;
|
2006-02-15 19:56:26 +00:00
|
|
|
extern int Run_IBC;
|
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
|
|
|
|
|
2003-04-01 21:41:36 +00:00
|
|
|
/*
|
|
|
|
* Prototypes
|
|
|
|
*/
|
2006-02-13 19:26:30 +00:00
|
|
|
void Chatlog(char *, char *, char *);
|
2003-04-03 20:51:19 +00:00
|
|
|
void chat_dump(void);
|
|
|
|
void system_msg(pid_t, char *);
|
2006-02-04 16:30:48 +00:00
|
|
|
void chat_help(pid_t, int);
|
2003-04-03 20:51:19 +00:00
|
|
|
int join(pid_t, char *, int);
|
|
|
|
int part(pid_t, char*);
|
2003-04-01 21:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-23 18:59:16 +00:00
|
|
|
void Chatlog(char *level, char *channel, char *msg)
|
|
|
|
{
|
|
|
|
char *logm;
|
|
|
|
|
|
|
|
if (CFG.iAutoLog && strlen(CFG.chat_log)) {
|
|
|
|
logm = calloc(PATH_MAX, sizeof(char));
|
|
|
|
snprintf(logm, PATH_MAX, "%s/log/%s", getenv("MBSE_ROOT"), CFG.chat_log);
|
|
|
|
ulog(logm, level, channel, (char *)"-1", msg);
|
|
|
|
free(logm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-01 21:41:36 +00:00
|
|
|
void chat_dump(void)
|
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
int i, first;
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
first = TRUE;
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (usr_list[i].pid) {
|
2005-05-01 12:27:27 +00:00
|
|
|
if (first) {
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', " pid username nick channel sysop");
|
|
|
|
Syslog('c', "----- ------------------------------------ --------- -------------------- -----");
|
2005-05-01 12:27:27 +00:00
|
|
|
first = FALSE;
|
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
Syslog('c', "%5d %-36s %-9s %-20s %s", usr_list[i].pid, usr_list[i].realname, usr_list[i].nick,
|
|
|
|
usr_list[i].channel, usr_list[i].sysop?"True ":"False");
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-01 21:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a system message into the chatbuffer
|
|
|
|
*/
|
|
|
|
void system_msg(pid_t pid, char *msg)
|
|
|
|
{
|
|
|
|
if (buffer_head < MAXMESSAGES)
|
|
|
|
buffer_head++;
|
|
|
|
else
|
|
|
|
buffer_head = 0;
|
|
|
|
|
|
|
|
memset(&chat_messages[buffer_head], 0, sizeof(_chat_messages));
|
|
|
|
chat_messages[buffer_head].topid = pid;
|
2006-03-06 16:34:26 +00:00
|
|
|
strncpy(chat_messages[buffer_head].fromname, "Server", 36);
|
2003-03-24 19:44:38 +00:00
|
|
|
strncpy(chat_messages[buffer_head].message, msg, 80);
|
|
|
|
chat_messages[buffer_head].posted = time(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-22 21:18:45 +00:00
|
|
|
/*
|
|
|
|
* Shout a message to all users
|
|
|
|
*/
|
|
|
|
void system_shout(const char *format, ...)
|
|
|
|
{
|
2005-09-11 13:07:42 +00:00
|
|
|
char *buf;
|
2005-04-22 21:18:45 +00:00
|
|
|
va_list va_ptr;
|
2006-05-25 16:37:52 +00:00
|
|
|
int i;
|
2005-04-22 21:18:45 +00:00
|
|
|
|
2005-09-11 13:07:42 +00:00
|
|
|
buf = calloc(512, sizeof(char));
|
2005-04-22 21:18:45 +00:00
|
|
|
va_start(va_ptr, format);
|
2005-08-29 21:03:28 +00:00
|
|
|
vsnprintf(buf, 512, format, va_ptr);
|
2005-04-22 21:18:45 +00:00
|
|
|
va_end(va_ptr);
|
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (usr_list[i].pid) {
|
|
|
|
system_msg(usr_list[i].pid, buf);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
}
|
2005-09-11 13:07:42 +00:00
|
|
|
|
2006-01-23 18:59:16 +00:00
|
|
|
Chatlog((char *)"-", (char *)" ", buf);
|
2005-09-11 13:07:42 +00:00
|
|
|
free(buf);
|
2005-04-22 21:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
/*
|
|
|
|
* Show help
|
|
|
|
*/
|
2006-02-04 16:30:48 +00:00
|
|
|
void chat_help(pid_t pid, int owner)
|
2003-03-24 19:44:38 +00:00
|
|
|
{
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, (char *)" Help topics available:");
|
|
|
|
system_msg(pid, (char *)"");
|
|
|
|
system_msg(pid, (char *)" /BYE - Exit from chatserver");
|
2003-04-09 19:38:06 +00:00
|
|
|
system_msg(pid, (char *)" /ECHO <message> - Echo message to yourself");
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, (char *)" /EXIT - Exit from chatserver");
|
|
|
|
system_msg(pid, (char *)" /JOIN #channel - Join or create a channel");
|
|
|
|
system_msg(pid, (char *)" /J #channel - Join or create a channel");
|
|
|
|
// system_msg(pid, (char *)" /KICK <nick> - Kick nick out of the channel");
|
|
|
|
system_msg(pid, (char *)" /LIST - List active channels");
|
2003-04-09 19:38:06 +00:00
|
|
|
system_msg(pid, (char *)" /NAMES - List nicks in current channel");
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, (char *)" /NICK <name> - Set new nickname");
|
|
|
|
system_msg(pid, (char *)" /PART - Leave current channel");
|
|
|
|
system_msg(pid, (char *)" /QUIT - Exit from chatserver");
|
2006-02-04 16:52:53 +00:00
|
|
|
if (owner)
|
|
|
|
system_msg(pid, (char *)" /TOPIC <topic> - Set topic for current channel");
|
2003-03-24 19:44:38 +00:00
|
|
|
system_msg(pid, (char *)"");
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, (char *)" All other input (without a starting /) is sent to the channel.");
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-01 21:41:36 +00:00
|
|
|
/*
|
|
|
|
* Join a channel
|
|
|
|
*/
|
2003-04-03 20:51:19 +00:00
|
|
|
int join(pid_t pid, char *channel, int sysop)
|
2003-04-01 21:41:36 +00:00
|
|
|
{
|
2005-04-23 14:27:52 +00:00
|
|
|
char buf[81];
|
2006-05-25 16:37:52 +00:00
|
|
|
int i, j;
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "Join pid %d to channel %s", pid, channel);
|
2005-04-23 14:27:52 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_CHN; i++) {
|
|
|
|
if (strcmp(chn_list[i].name, channel) == 0) {
|
|
|
|
for (j = 0; j < MAXIBC_USR; j++) {
|
|
|
|
if (usr_list[j].pid == pid) {
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
strncpy(usr_list[j].channel, channel, 20);
|
|
|
|
chn_list[i].users++;
|
|
|
|
Syslog('+', "IBC: user %s has joined channel %s", usr_list[j].nick, channel);
|
|
|
|
usrchg = TRUE;
|
|
|
|
srvchg = TRUE;
|
|
|
|
chnchg = TRUE;
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
chat_dump();
|
|
|
|
snprintf(buf, 81, "%s has joined channel %s, now %d users", usr_list[j].nick, channel, chn_list[i].users);
|
|
|
|
chat_msg(channel, NULL, buf);
|
2005-04-23 14:27:52 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
/*
|
|
|
|
* The sysop channel is private to the system, no broadcast
|
|
|
|
*/
|
|
|
|
if (strcasecmp(channel, "#sysop"))
|
|
|
|
send_at((char *)"JOIN", usr_list[j].nick, channel);
|
|
|
|
return TRUE;
|
2005-04-23 14:27:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2003-04-03 20:51:19 +00:00
|
|
|
/*
|
|
|
|
* A new channel must be created, but only the sysop may create the "sysop" channel
|
|
|
|
*/
|
2005-04-27 20:26:53 +00:00
|
|
|
if (!sysop && (strcasecmp(channel, "#sysop") == 0)) {
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 81, "*** Only the sysop may create channel \"%s\"", channel);
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, buf);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-04-01 21:41:36 +00:00
|
|
|
/*
|
|
|
|
* No matching channel found, add a new channel.
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
for (j = 0; j < MAXIBC_USR; j++) {
|
|
|
|
if (usr_list[j].pid == pid) {
|
|
|
|
if (add_channel(channel, usr_list[j].nick, CFG.myfqdn) == 0) {
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
strncpy(usr_list[j].channel, channel, 20);
|
|
|
|
Syslog('+', "IBC: user %s created and joined channel %s", usr_list[j].nick, channel);
|
2005-05-01 12:27:27 +00:00
|
|
|
usrchg = TRUE;
|
2005-05-01 13:35:43 +00:00
|
|
|
chnchg = TRUE;
|
|
|
|
srvchg = TRUE;
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 81, "* Created channel %s", channel);
|
2005-04-23 14:27:52 +00:00
|
|
|
chat_msg(channel, NULL, buf);
|
|
|
|
chat_dump();
|
2005-05-01 09:46:39 +00:00
|
|
|
if (strcasecmp(channel, "#sysop"))
|
2006-05-25 16:37:52 +00:00
|
|
|
send_at((char *)"JOIN", usr_list[j].nick, channel);
|
2005-04-30 12:14:42 +00:00
|
|
|
|
2005-04-23 14:27:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-01 21:41:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* No matching or free channels
|
|
|
|
*/
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 81, "*** Cannot create chat channel %s, no free channels", channel);
|
2003-04-03 20:51:19 +00:00
|
|
|
system_msg(pid, buf);
|
2003-04-01 21:41:36 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Part from a channel
|
|
|
|
*/
|
|
|
|
int part(pid_t pid, char *reason)
|
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
char buf[81], *p;
|
|
|
|
int i, j;
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2005-04-24 12:14:39 +00:00
|
|
|
if (strlen(reason) > 54)
|
|
|
|
reason[54] = '\0';
|
|
|
|
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "Part pid %d from channel, reason %s", pid, reason);
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if ((usr_list[i].pid == pid) && strlen(usr_list[i].channel)) {
|
|
|
|
for (j = 0; j < MAXIBC_CHN; j++) {
|
|
|
|
if (strcmp(chn_list[j].name, usr_list[i].channel) == 0) {
|
2005-04-23 14:27:52 +00:00
|
|
|
/*
|
|
|
|
* Inform other users
|
|
|
|
*/
|
2005-05-01 12:27:27 +00:00
|
|
|
if (reason != NULL) {
|
2006-05-25 16:37:52 +00:00
|
|
|
chat_msg(usr_list[i].channel, usr_list[i].nick, reason);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
snprintf(buf, 81, "%s has left channel %s, %d users left",
|
|
|
|
usr_list[i].nick, chn_list[j].name, chn_list[j].users -1);
|
|
|
|
chat_msg(usr_list[i].channel, NULL, buf);
|
|
|
|
if (strcasecmp(chn_list[j].name, (char *)"#sysop")) {
|
|
|
|
p = xstrcpy(chn_list[j].name);
|
2006-01-25 19:50:36 +00:00
|
|
|
if (reason && strlen(reason)) {
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)" ");
|
|
|
|
p = xstrcat(p, reason);
|
2006-01-25 19:50:36 +00:00
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
send_at((char *)"PART", usr_list[i].nick, p);
|
2006-03-06 16:34:26 +00:00
|
|
|
free(p);
|
2005-04-24 12:14:39 +00:00
|
|
|
}
|
2005-04-23 14:27:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean channel
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
if (chn_list[j].users > 0)
|
|
|
|
chn_list[j].users--;
|
|
|
|
Syslog('+', "IBC: nick %s leaves channel %s, %d user left",
|
|
|
|
usr_list[i].nick, chn_list[j].name, chn_list[j].users);
|
|
|
|
if (chn_list[j].users == 0) {
|
2005-04-23 14:27:52 +00:00
|
|
|
/*
|
|
|
|
* Last user in channel, remove channel
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
snprintf(buf, 81, "* Removed channel %s", chn_list[j].name);
|
2006-02-04 16:30:48 +00:00
|
|
|
system_msg(pid, buf);
|
2006-05-25 16:37:52 +00:00
|
|
|
Syslog('+', "IBC: removed channel %s, no more users left", chn_list[j].name);
|
|
|
|
del_channel(chn_list[j].name);
|
2005-04-23 14:27:52 +00:00
|
|
|
}
|
2005-04-30 12:14:42 +00:00
|
|
|
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Update user data
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
usr_list[i].channel[0] = '\0';
|
2005-05-01 12:27:27 +00:00
|
|
|
usrchg = TRUE;
|
2005-05-01 13:35:43 +00:00
|
|
|
chnchg = TRUE;
|
|
|
|
srvchg = TRUE;
|
2005-04-30 12:14:42 +00:00
|
|
|
|
2005-04-23 14:27:52 +00:00
|
|
|
chat_dump();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-01 21:41:36 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
void chat_init(void)
|
|
|
|
{
|
2005-04-23 14:27:52 +00:00
|
|
|
memset(&chat_messages, 0, sizeof(chat_messages));
|
2003-04-01 21:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void chat_cleanuser(pid_t pid)
|
|
|
|
{
|
|
|
|
part(pid, (char *)"I'm hanging up!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send message into channel
|
|
|
|
*/
|
2005-04-23 14:27:52 +00:00
|
|
|
void chat_msg(char *channel, char *nick, char *msg)
|
2005-05-01 12:27:27 +00:00
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
char *p;
|
|
|
|
int i;
|
|
|
|
|
2005-05-01 12:27:27 +00:00
|
|
|
if (nick == NULL)
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcpy(msg);
|
|
|
|
else {
|
|
|
|
p = xstrcpy((char *)"<");
|
|
|
|
p = xstrcat(p, nick);
|
|
|
|
p = xstrcat(p, (char *)"> ");
|
|
|
|
p = xstrcat(p, msg);
|
|
|
|
}
|
|
|
|
Chatlog((char *)"+", channel, p);
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (strlen(usr_list[i].channel) && (strcmp(usr_list[i].channel, channel) == 0)) {
|
|
|
|
system_msg(usr_list[i].pid, p);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-06 16:34:26 +00:00
|
|
|
|
|
|
|
free(p);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2003-03-24 19:44:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Connect a session to the chatserver.
|
|
|
|
*/
|
2006-02-04 13:39:51 +00:00
|
|
|
void chat_connect_r(char *data, char *buf)
|
2003-03-24 19:44:38 +00:00
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *realname, *nick, *temp;
|
2006-05-25 16:37:52 +00:00
|
|
|
int i, j, rc, count = 0, sys = FALSE;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "CCON:%s", data);
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2006-02-15 19:56:26 +00:00
|
|
|
if (! Run_IBC) {
|
|
|
|
snprintf(buf, 200, "100:1,*** Chatserver not configured;");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
if (IsSema((char *)"upsalarm")) {
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:1,*** Power failure, running on UPS;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-04-03 20:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s_bbsopen == FALSE) {
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:1,*** The BBS is closed now;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-04-02 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Register with IBC
|
|
|
|
*/
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ","); /* Should be 3 */
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ",")); /* The pid */
|
2005-10-17 14:36:12 +00:00
|
|
|
realname = xstrcpy(cldecode(strtok(NULL, ",")));/* Username */
|
|
|
|
nick = xstrcpy(cldecode(strtok(NULL, ","))); /* Nickname */
|
|
|
|
sys = atoi(strtok(NULL, ";")); /* Sysop flag */
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
rc = add_user(CFG.myfqdn, nick, realname);
|
|
|
|
if (rc == 1) {
|
|
|
|
free(realname);
|
|
|
|
free(nick);
|
|
|
|
snprintf(buf, 200, "100:1,Already registered;");
|
|
|
|
return;
|
|
|
|
} else if (rc == 2) {
|
|
|
|
free(realname);
|
|
|
|
free(nick);
|
|
|
|
snprintf(buf, 200, "100:1,Too many users connected;");
|
|
|
|
return;
|
|
|
|
}
|
2005-05-01 12:27:27 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
send_at((char *)"USER", nick, realname);
|
|
|
|
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Now search the added entry to update the data
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if ((strcmp(usr_list[i].server, CFG.myfqdn) == 0) &&
|
|
|
|
(strcmp(usr_list[i].name, nick) == 0) && (strcmp(usr_list[i].realname, realname) == 0)) {
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Oke, found
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
usr_list[i].pid = pid;
|
|
|
|
usr_list[i].pointer = buffer_head;
|
|
|
|
usr_list[i].sysop = sys;
|
2005-05-01 13:35:43 +00:00
|
|
|
usrchg = TRUE;
|
|
|
|
srvchg = TRUE;
|
2006-05-25 16:37:52 +00:00
|
|
|
Syslog('c', "Connected user %s (%d) with chatserver, sysop %s", realname, (int)pid, sys ? "True":"False");
|
2005-05-01 12:27:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now put welcome message into the ringbuffer and report success.
|
|
|
|
*/
|
2006-02-04 13:39:51 +00:00
|
|
|
temp = calloc(81, sizeof(char));
|
|
|
|
snprintf(temp, 200, "MBSE BBS v%s chat server; type /help for help", VERSION);
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, temp);
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(temp, 200, "Welcome to the Internet BBS Chat Network");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, temp);
|
2006-02-06 14:32:25 +00:00
|
|
|
snprintf(temp, 200, "Current connected servers:");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, temp);
|
|
|
|
for (j = 0; j < MAXIBC_SRV; j++) {
|
|
|
|
if (strlen(srv_list[j].server)) {
|
|
|
|
snprintf(temp, 200, " %s (%d user%s)", srv_list[j].fullname,
|
|
|
|
srv_list[j].users, (srv_list[j].users == 1) ? "":"s");
|
|
|
|
system_msg(usr_list[i].pid, temp);
|
|
|
|
count += srv_list[j].users;
|
|
|
|
}
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(temp, 200, "There %s %d user%s connected", (count != 1)?"are":"is", count, (count != 1)?"s":"");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, temp);
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:0;");
|
2006-02-04 13:39:51 +00:00
|
|
|
free(realname);
|
|
|
|
free(nick);
|
|
|
|
free(temp);
|
|
|
|
return;
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-04 13:39:51 +00:00
|
|
|
void chat_close_r(char *data, char *buf)
|
2003-03-24 19:44:38 +00:00
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
pid_t pid;
|
|
|
|
int i;
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "CCLO:%s", data);
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2005-04-20 16:59:32 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (usr_list[i].pid == pid) {
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Remove from IBC network
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
send_at((char *)"QUIT", usr_list[i].name, (char *)"Leaving chat");
|
|
|
|
del_user(CFG.myfqdn, usr_list[i].name);
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('c', "Closing chat for pid %d", (int)pid);
|
2005-09-11 13:07:42 +00:00
|
|
|
snprintf(buf, 81, "100:0;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-13 19:26:30 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('c', "Pid %d was not connected to chatserver", (int)pid);
|
2005-09-11 13:07:42 +00:00
|
|
|
snprintf(buf, 81, "100:1,*** ERROR - Not connected to server;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-02-04 13:39:51 +00:00
|
|
|
void chat_put_r(char *data, char *buf)
|
2003-03-24 19:44:38 +00:00
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *p, *q, *msg, *cmd, *mbuf, *flags, temp[81];
|
2006-05-25 16:37:52 +00:00
|
|
|
int i, j, k, first, count, owner = FALSE, found;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
if (IsSema((char *)"upsalarm")) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(buf, 81, "100:2,1,*** Power alarm, running on UPS;");
|
|
|
|
return;
|
2003-04-02 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2003-04-03 20:51:19 +00:00
|
|
|
if (s_bbsopen == FALSE) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(buf, 81, "100:2,1,*** The BBS is closed now;");
|
|
|
|
return;
|
2003-04-03 20:51:19 +00:00
|
|
|
}
|
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2005-10-17 14:36:12 +00:00
|
|
|
msg = xstrcpy(cldecode(strtok(NULL, ";")));
|
2006-02-04 13:39:51 +00:00
|
|
|
mbuf = calloc(200, sizeof(char));
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (usr_list[i].pid == pid) {
|
2003-03-24 19:44:38 +00:00
|
|
|
if (msg[0] == '/') {
|
|
|
|
/*
|
2006-05-25 16:37:52 +00:00
|
|
|
* A command, process this but first see if we are in a channel
|
2006-02-04 16:30:48 +00:00
|
|
|
* and own the channel. This gives us more power.
|
2003-03-24 19:44:38 +00:00
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strlen(usr_list[i].channel)) {
|
|
|
|
for (j = 0; j < MAXIBC_CHN; j++) {
|
|
|
|
if (((strcmp(usr_list[i].nick, chn_list[j].owner) == 0) ||
|
|
|
|
(strcmp(usr_list[i].name, chn_list[j].owner) == 0)) &&
|
|
|
|
(strcmp(usr_list[i].server, chn_list[j].server) == 0)) {
|
2006-02-04 16:30:48 +00:00
|
|
|
owner = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-24 19:44:38 +00:00
|
|
|
if (strncasecmp(msg, "/help", 5) == 0) {
|
2006-05-22 12:09:15 +00:00
|
|
|
chat_help(pid, owner);
|
2003-04-01 21:41:36 +00:00
|
|
|
goto ack;
|
2003-04-09 19:38:06 +00:00
|
|
|
} else if (strncasecmp(msg, "/echo", 5) == 0) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "%s", msg);
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-09 19:38:06 +00:00
|
|
|
goto ack;
|
2003-04-03 20:51:19 +00:00
|
|
|
} else if ((strncasecmp(msg, "/exit", 5) == 0) ||
|
2003-04-01 21:41:36 +00:00
|
|
|
(strncasecmp(msg, "/quit", 5) == 0) ||
|
|
|
|
(strncasecmp(msg, "/bye", 4) == 0)) {
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strlen(usr_list[i].channel)) {
|
2006-02-04 16:30:48 +00:00
|
|
|
/*
|
|
|
|
* If in a channel, leave channel first
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
part(usr_list[i].pid, (char *)"Quitting");
|
2006-02-04 16:30:48 +00:00
|
|
|
snprintf(mbuf, 81, "Goodbye");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2006-02-04 16:30:48 +00:00
|
|
|
}
|
2003-04-02 21:36:47 +00:00
|
|
|
goto hangup;
|
2003-04-03 20:51:19 +00:00
|
|
|
} else if ((strncasecmp(msg, "/join", 5) == 0) ||
|
|
|
|
(strncasecmp(msg, "/j ", 3) == 0)) {
|
2003-03-24 19:44:38 +00:00
|
|
|
cmd = strtok(msg, " \0");
|
|
|
|
cmd = strtok(NULL, "\0");
|
|
|
|
if ((cmd == NULL) || (cmd[0] != '#') || (strcmp(cmd, "#") == 0)) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Try /join #channel");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
|
|
|
} else if (strlen(usr_list[i].channel)) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Cannot join while in a channel");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2005-05-01 12:27:27 +00:00
|
|
|
} else {
|
2006-05-25 16:37:52 +00:00
|
|
|
join(usr_list[i].pid, cmd, usr_list[i].sysop);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2003-04-03 20:51:19 +00:00
|
|
|
chat_dump();
|
2003-04-01 21:41:36 +00:00
|
|
|
goto ack;
|
2003-04-03 20:51:19 +00:00
|
|
|
} else if (strncasecmp(msg, "/list", 5) == 0) {
|
|
|
|
first = TRUE;
|
2006-05-25 16:37:52 +00:00
|
|
|
for (j = 0; j < MAXIBC_CHN; j++) {
|
|
|
|
if (strlen(chn_list[j].server)) {
|
|
|
|
if (first) {
|
|
|
|
snprintf(mbuf, 200, "Cnt Channel name Channel topic");
|
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
|
|
|
snprintf(mbuf, 200, "--- -------------------- ------------------------------------------------------");
|
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
|
|
|
}
|
|
|
|
first = FALSE;
|
|
|
|
q = calloc(81, sizeof(char));
|
|
|
|
snprintf(q, 81, "%3d %-20s ", chn_list[j].users, chn_list[j].name);
|
|
|
|
p = xstrcpy(q);
|
|
|
|
p = xstrcat(p, chn_list[j].topic);
|
|
|
|
system_msg(usr_list[i].pid, p);
|
|
|
|
free(p);
|
|
|
|
free(q);
|
2005-04-23 14:27:52 +00:00
|
|
|
}
|
2003-04-03 20:51:19 +00:00
|
|
|
}
|
|
|
|
if (first) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "No active channels to list");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-03 20:51:19 +00:00
|
|
|
}
|
|
|
|
goto ack;
|
2003-04-09 19:38:06 +00:00
|
|
|
} else if (strncasecmp(msg, "/names", 6) == 0) {
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strlen(usr_list[i].channel)) {
|
|
|
|
snprintf(mbuf, 200, "Present in channel %s:", usr_list[i].channel);
|
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "Nick Real name Flags");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2006-02-04 16:30:48 +00:00
|
|
|
snprintf(mbuf, 200, "---------------------------------------- ------------------------------ -----");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-09 19:38:06 +00:00
|
|
|
count = 0;
|
2006-05-25 16:37:52 +00:00
|
|
|
for (j = 0; j < MAXIBC_USR; j++) {
|
|
|
|
if (strcmp(usr_list[j].channel, usr_list[i].channel) == 0) {
|
2006-02-04 16:30:48 +00:00
|
|
|
/*
|
|
|
|
* Get channel flags
|
|
|
|
*/
|
|
|
|
flags = xstrcpy((char *)"--");
|
2006-05-25 16:37:52 +00:00
|
|
|
for (k = 0; k < MAXIBC_CHN; k++) {
|
|
|
|
if (strcmp(chn_list[k].name, usr_list[i].channel) == 0) {
|
|
|
|
if (((strcmp(chn_list[k].owner, usr_list[j].nick) == 0) ||
|
|
|
|
(strcmp(chn_list[k].owner, usr_list[j].name) == 0)) &&
|
|
|
|
(strcmp(chn_list[k].server, usr_list[j].server) == 0)) {
|
2006-02-04 16:30:48 +00:00
|
|
|
flags[0] = 'O';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
if (usr_list[j].sysop)
|
2006-02-04 16:30:48 +00:00
|
|
|
flags[1] = 'S';
|
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
snprintf(temp, 81, "%s@%s", usr_list[j].nick, usr_list[j].server);
|
|
|
|
snprintf(mbuf, 200, "%-40s %-30s %s", temp, usr_list[j].realname, flags);
|
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2005-04-27 21:09:23 +00:00
|
|
|
count++;
|
2006-02-04 16:30:48 +00:00
|
|
|
free(flags);
|
2005-04-27 21:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "%d user%s in this channel", count, (count == 1) ?"":"s");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2005-05-01 12:27:27 +00:00
|
|
|
} else {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Not in a channel");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2003-04-09 19:38:06 +00:00
|
|
|
goto ack;
|
2003-04-03 20:51:19 +00:00
|
|
|
} else if (strncasecmp(msg, "/nick", 5) == 0) {
|
|
|
|
cmd = strtok(msg, " \0");
|
|
|
|
cmd = strtok(NULL, "\0");
|
2005-04-20 16:59:32 +00:00
|
|
|
if ((cmd == NULL) || (strlen(cmd) == 0) || (strlen(cmd) > 9)) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Nickname must be between 1 and 9 characters");
|
2003-04-03 20:51:19 +00:00
|
|
|
} else {
|
2005-04-22 19:40:05 +00:00
|
|
|
found = FALSE;
|
2006-05-25 16:37:52 +00:00
|
|
|
for (j = 0; j < MAXIBC_USR; j++) {
|
|
|
|
if ((strcmp(usr_list[j].name, cmd) == 0) || (strcmp(usr_list[j].nick, cmd) == 0)) {
|
2005-04-22 19:40:05 +00:00
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found ) {
|
2006-05-25 16:37:52 +00:00
|
|
|
strncpy(usr_list[i].nick, cmd, 9);
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "Nick set to \"%s\"", cmd);
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
|
|
|
send_nick(usr_list[i].nick, usr_list[i].name, usr_list[i].realname);
|
2005-05-01 12:27:27 +00:00
|
|
|
usrchg = TRUE;
|
|
|
|
chat_dump();
|
|
|
|
goto ack;
|
2005-04-22 19:40:05 +00:00
|
|
|
}
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "Can't set nick");
|
2005-04-22 19:40:05 +00:00
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-03 20:51:19 +00:00
|
|
|
chat_dump();
|
|
|
|
goto ack;
|
|
|
|
} else if (strncasecmp(msg, "/part", 5) == 0) {
|
2003-04-01 21:41:36 +00:00
|
|
|
cmd = strtok(msg, " \0");
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "\"%s\"", cmd);
|
2003-04-01 21:41:36 +00:00
|
|
|
cmd = strtok(NULL, "\0");
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "\"%s\"", printable(cmd, 0));
|
2006-05-25 16:37:52 +00:00
|
|
|
if (part(usr_list[i].pid, cmd ? cmd : (char *)"Quitting") == FALSE) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Not in a channel");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2003-04-03 20:51:19 +00:00
|
|
|
chat_dump();
|
|
|
|
goto ack;
|
2003-04-09 19:38:06 +00:00
|
|
|
} else if (strncasecmp(msg, "/topic", 6) == 0) {
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strlen(usr_list[i].channel)) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Internal system error");
|
2006-05-25 16:37:52 +00:00
|
|
|
for (j = 0; j < MAXIBC_CHN; j++) {
|
|
|
|
if (strcmp(usr_list[i].channel, chn_list[j].name) == 0) {
|
2006-02-04 16:52:53 +00:00
|
|
|
if (owner) {
|
2005-04-23 14:27:52 +00:00
|
|
|
cmd = strtok(msg, " \0");
|
|
|
|
cmd = strtok(NULL, "\0");
|
|
|
|
if ((cmd == NULL) || (strlen(cmd) == 0) || (strlen(cmd) > 54)) {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Topic must be between 1 and 54 characters");
|
2005-04-23 14:27:52 +00:00
|
|
|
} else {
|
2006-05-25 16:37:52 +00:00
|
|
|
strncpy(chn_list[j].topic, cmd, 54);
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "Topic set to \"%s\"", cmd);
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcpy((char *)"TOPIC ");
|
2006-05-25 16:37:52 +00:00
|
|
|
p = xstrcat(p, chn_list[j].name);
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)" ");
|
2006-05-25 16:37:52 +00:00
|
|
|
p = xstrcat(p, chn_list[j].topic);
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)"\r\n");
|
|
|
|
send_all(p);
|
|
|
|
free(p);
|
2005-04-23 14:27:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** You are not the channel owner");
|
2005-04-23 14:27:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-01 12:27:27 +00:00
|
|
|
} else {
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** Not in a channel");
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-09 19:38:06 +00:00
|
|
|
chat_dump();
|
|
|
|
goto ack;
|
2003-04-03 20:51:19 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If still here, the command was not recognized.
|
|
|
|
*/
|
|
|
|
cmd = strtok(msg, " \t\r\n\0");
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "*** \"%s\" :Unknown command", cmd+1);
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-01 21:41:36 +00:00
|
|
|
goto ack;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strlen(usr_list[i].channel) == 0) {
|
2003-03-24 19:44:38 +00:00
|
|
|
/*
|
|
|
|
* Trying messages while not in a channel
|
|
|
|
*/
|
2006-02-04 13:39:51 +00:00
|
|
|
snprintf(mbuf, 200, "** No channel joined. Try /join #channel");
|
2006-05-25 16:37:52 +00:00
|
|
|
system_msg(usr_list[i].pid, mbuf);
|
2003-04-01 21:41:36 +00:00
|
|
|
goto ack;
|
|
|
|
} else {
|
2006-05-25 16:37:52 +00:00
|
|
|
chat_msg(usr_list[i].channel, usr_list[i].nick, msg);
|
2006-02-06 14:23:35 +00:00
|
|
|
/*
|
|
|
|
* Send message to all links but not the #sysop channel
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
if (strcmp(usr_list[i].channel, "#sysop")) {
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcpy((char *)"PRIVMSG ");
|
2006-05-25 16:37:52 +00:00
|
|
|
p = xstrcat(p, usr_list[i].channel);
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)" <");
|
2006-05-25 16:37:52 +00:00
|
|
|
p = xstrcat(p, usr_list[i].nick);
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)"> ");
|
|
|
|
p = xstrcat(p, msg);
|
|
|
|
p = xstrcat(p, (char *)"\r\n");
|
|
|
|
send_all(p);
|
|
|
|
free(p);
|
|
|
|
}
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
2003-04-01 21:41:36 +00:00
|
|
|
goto ack;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-06 12:26:03 +00:00
|
|
|
|
2006-02-06 12:32:24 +00:00
|
|
|
Syslog('+', "Pid %s was not connected to chatserver", pid);
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:2,1,*** ERROR - Not connected to server;");
|
2005-10-17 14:36:12 +00:00
|
|
|
free(msg);
|
2006-02-04 13:39:51 +00:00
|
|
|
free(mbuf);
|
|
|
|
return;
|
2003-04-01 21:41:36 +00:00
|
|
|
|
|
|
|
ack:
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:0;");
|
2005-10-17 14:36:12 +00:00
|
|
|
free(msg);
|
2006-02-04 13:39:51 +00:00
|
|
|
free(mbuf);
|
|
|
|
return;
|
2003-04-02 21:36:47 +00:00
|
|
|
|
|
|
|
hangup:
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:2,1,Disconnecting;");
|
2005-10-17 14:36:12 +00:00
|
|
|
free(msg);
|
2006-02-04 13:39:51 +00:00
|
|
|
free(mbuf);
|
|
|
|
return;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-04-03 20:51:19 +00:00
|
|
|
/*
|
|
|
|
* Check for a message for the user. Return the message or signal that
|
|
|
|
* nothing is there to display.
|
|
|
|
*/
|
2006-02-04 13:39:51 +00:00
|
|
|
void chat_get_r(char *data, char *buf)
|
2003-03-24 19:44:38 +00:00
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
char *p;
|
|
|
|
pid_t pid;
|
|
|
|
int i;
|
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
if (IsSema((char *)"upsalarm")) {
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:2,1,*** Power failure, running on UPS;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-04-03 20:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s_bbsopen == FALSE) {
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:2,1,*** The BBS is closed now;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-04-02 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (pid == usr_list[i].pid) {
|
|
|
|
while (usr_list[i].pointer != buffer_head) {
|
|
|
|
if (usr_list[i].pointer < MAXMESSAGES)
|
|
|
|
usr_list[i].pointer++;
|
2005-05-01 12:27:27 +00:00
|
|
|
else
|
2006-05-25 16:37:52 +00:00
|
|
|
usr_list[i].pointer = 0;
|
|
|
|
if (usr_list[i].pid == chat_messages[usr_list[i].pointer].topid) {
|
2005-05-01 12:27:27 +00:00
|
|
|
/*
|
|
|
|
* Message is for us
|
|
|
|
*/
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcpy((char *)"100:2,0,");
|
2006-05-25 16:37:52 +00:00
|
|
|
p = xstrcat(p, clencode(chat_messages[usr_list[i].pointer].message));
|
2006-03-06 16:34:26 +00:00
|
|
|
p = xstrcat(p, (char *)";");
|
|
|
|
strncpy(buf, p, 200);
|
|
|
|
free(p);
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:0;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 200, "100:2,1,*** ERROR - Not connected to server;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-04-02 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for sysop present for forced chat
|
|
|
|
*/
|
2006-02-04 13:39:51 +00:00
|
|
|
void chat_checksysop_r(char *data, char *buf)
|
2003-04-02 21:36:47 +00:00
|
|
|
{
|
2006-05-25 16:37:52 +00:00
|
|
|
pid_t pid;
|
|
|
|
int i;
|
2006-05-22 12:09:15 +00:00
|
|
|
|
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2006-02-13 19:26:30 +00:00
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
if (reg_ispaging(pid)) {
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "Check sysopchat for pid %s, user has paged", pid);
|
2003-04-02 21:36:47 +00:00
|
|
|
|
2006-02-13 19:26:30 +00:00
|
|
|
/*
|
|
|
|
* Now check if sysop is present in the sysop channel
|
|
|
|
*/
|
2006-05-25 16:37:52 +00:00
|
|
|
for (i = 0; i < MAXIBC_USR; i++) {
|
|
|
|
if (pid != usr_list[i].pid) {
|
|
|
|
if (strlen(usr_list[i].channel) && (strcasecmp(usr_list[i].channel, "#sysop") == 0) && usr_list[i].sysop) {
|
2005-11-15 22:18:31 +00:00
|
|
|
Syslog('c', "Sending ACK on check");
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 20, "100:1,1;");
|
2005-05-01 12:27:27 +00:00
|
|
|
reg_sysoptalk(pid);
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2005-05-01 12:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-02 21:36:47 +00:00
|
|
|
}
|
|
|
|
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 20, "100:1,0;");
|
2006-02-04 13:39:51 +00:00
|
|
|
return;
|
2003-03-24 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 21:27:14 +00:00
|
|
|
|