This repository has been archived on 2025-02-12. You can view files and clone it, but cannot push or open issues or pull requests.
NeoStats-stupidserv/ss.c

252 lines
7 KiB
C
Raw Permalink Normal View History

2004-01-14 11:41:12 +00:00
/* NeoStats - IRC Statistical Services Copyright (c) 1999-2004 NeoStats Group Inc.
** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond
2003-02-18 13:52:05 +00:00
** http://www.neostats.net/
**
** Portions Copyright (c) 2000-2001 ^Enigma^
**
** This program 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 of the License, or
** (at your option) any later version.
**
** This program 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 this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** NeoStats CVS Identification
2003-05-22 14:05:09 +00:00
** $Id: ss.c,v 1.4 2003/05/22 14:05:09 fishwaldo Exp $
2003-02-18 13:52:05 +00:00
*/
#include <stdio.h>
2004-03-13 23:44:57 +00:00
#include "modconfig.h"
2004-03-08 22:15:17 +00:00
#include "neostats.h"
2004-02-16 21:39:17 +00:00
#include "ss.h"
2003-02-18 13:52:05 +00:00
#include "talkfilters.h"
2003-10-06 13:00:31 +00:00
/*
* StupidServ name
*/
2004-02-02 21:14:23 +00:00
static char s_StupidServ[MAXNICK];
2004-02-16 20:43:35 +00:00
static ModUser *ss_bot;
2003-02-18 13:52:05 +00:00
struct ss_cfg {
char user[MAXUSER];
char host[MAXHOST];
2004-03-06 21:06:26 +00:00
char realname[MAXREALNAME];
} ss_cfg;
2003-10-06 13:00:31 +00:00
/*
* Local declarations
*/
2004-02-16 20:43:35 +00:00
static int s_send(User *u, char **av, int ac);
static int s_convert(User *u, char **av, int ac);
static int s_list(User *u, char **av, int ac);
static int s_version(User *u, char **av, int ac);
static int s_about(User *u, char **av, int ac);
2003-02-18 13:52:05 +00:00
2004-02-16 20:43:35 +00:00
static bot_cmd ss_commands[]=
{
{"SEND", s_send, 3, 0, s_help_send, s_help_send_oneline },
2004-02-16 23:45:44 +00:00
{"CONVERT", s_convert, 2, 0, s_help_convert, s_help_convert_oneline },
2004-02-16 20:43:35 +00:00
{"LIST", s_list, 0, 0, s_help_list, s_help_list_oneline },
{"VERSION", s_version, 0, 0, s_help_version, s_help_version_oneline },
{"ABOUT", s_about, 0, 0, s_help_about, s_help_about_oneline },
{NULL, NULL, 0, 0, NULL, NULL}
};
static bot_setting ss_settings[]=
{
2004-02-21 16:26:01 +00:00
{"NICK", &s_StupidServ, SET_TYPE_NICK, 0, MAXNICK, NS_ULEVEL_ADMIN, "Nick", NULL, ns_help_set_nick },
{"USER", &ss_cfg.user, SET_TYPE_USER, 0, MAXUSER, NS_ULEVEL_ADMIN, "User", NULL, ns_help_set_user },
{"HOST", &ss_cfg.host, SET_TYPE_HOST, 0, MAXHOST, NS_ULEVEL_ADMIN, "Host", NULL, ns_help_set_host },
2004-03-06 21:06:26 +00:00
{"REALNAME",&ss_cfg.realname,SET_TYPE_REALNAME, 0, MAXREALNAME, NS_ULEVEL_ADMIN, "RealName",NULL, ns_help_set_realname },
{NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL },
};
2003-10-06 13:00:31 +00:00
/*
* Module info descriptor
*/
2003-10-08 13:59:31 +00:00
ModuleInfo __module_info = {
2003-02-18 13:52:05 +00:00
"StupidServ",
"A Language Translator",
2004-03-13 23:44:57 +00:00
MODULE_VERSION,
2003-10-08 13:59:31 +00:00
__DATE__,
__TIME__
};
2003-02-18 13:52:05 +00:00
2003-10-06 13:00:31 +00:00
/*
* Introduce the StupidServ bot onto the network
*/
2004-02-02 21:14:23 +00:00
static int Online(char **av, int ac)
2003-10-06 13:00:31 +00:00
{
2004-03-06 21:06:26 +00:00
ss_bot = init_mod_bot(s_StupidServ, ss_cfg.user, ss_cfg.host, ss_cfg.realname,
services_bot_modes, BOT_FLAG_DEAF, ss_commands, ss_settings, __module_info.module_name);
2003-02-18 13:52:05 +00:00
return 1;
};
2003-10-06 13:00:31 +00:00
/*
* IRC events that StupidServ responds to
*/
2003-10-08 13:59:31 +00:00
EventFnList __module_events[] = {
2003-11-05 23:04:59 +00:00
{ EVENT_ONLINE, Online},
2003-02-18 13:52:05 +00:00
{ NULL, NULL}
};
2003-10-06 13:00:31 +00:00
/*
*
*/
int __ModInit(int modnum, int apiver)
2003-09-29 13:24:39 +00:00
{
char *temp = NULL;
#ifdef NS_ERR_VERSION /* Forward port version checks */
/* Check that our compiled version if compatible with the calling version of NeoStats */
if( ircstrncasecmp (me.version, NEOSTATS_VERSION, VERSIONSIZE) !=0) {
return NS_ERR_VERSION;
}
#endif
if(GetConf((void *) &temp, CFGSTR, "Nick") < 0) {
strlcpy(s_StupidServ ,"StupidServ" ,MAXNICK);
}
else {
strlcpy(s_StupidServ , temp, MAXNICK);
free(temp);
}
if(GetConf((void *) &temp, CFGSTR, "User") < 0) {
strlcpy(ss_cfg.user, "SS", MAXUSER);
}
else {
strlcpy(ss_cfg.user, temp, MAXUSER);
free(temp);
}
if(GetConf((void *) &temp, CFGSTR, "Host") < 0) {
strlcpy(ss_cfg.host, me.name, MAXHOST);
}
else {
strlcpy(ss_cfg.host, temp, MAXHOST);
free(temp);
}
if(GetConf((void *) &temp, CFGSTR, "RealName") < 0) {
2004-03-20 20:12:56 +00:00
strlcpy(ss_cfg.realname, "A Language Translator", MAXREALNAME);
}
else {
2004-03-06 21:06:26 +00:00
strlcpy(ss_cfg.realname, temp, MAXREALNAME);
free(temp);
}
2003-09-29 13:24:39 +00:00
return 1;
2003-02-18 13:52:05 +00:00
}
2003-10-06 13:00:31 +00:00
/*
*
*/
2003-09-29 13:24:39 +00:00
void __ModFini()
{
2003-02-18 13:52:05 +00:00
};
2003-10-06 13:00:31 +00:00
/*
* Routine for VERSION
*/
2004-02-16 20:43:35 +00:00
static int s_version(User *u, char **av, int ac)
2003-02-18 13:52:05 +00:00
{
2003-09-29 13:24:39 +00:00
SET_SEGV_LOCATION();
2003-10-06 13:00:31 +00:00
prefmsg(u->nick, s_StupidServ, "\2%s Version Information\2", s_StupidServ);
prefmsg(u->nick, s_StupidServ, "%s Version: %s Compiled %s at %s", s_StupidServ,
__module_info.module_version, __module_info.module_build_date, __module_info.module_build_time);
2003-10-06 13:00:31 +00:00
prefmsg(u->nick, s_StupidServ, "%s Author Fish <fish@neostats.net>", s_StupidServ);
prefmsg(u->nick, s_StupidServ, "http://www.neostats.net");
2003-02-18 13:52:05 +00:00
}
2004-02-16 20:43:35 +00:00
/*
* Routine for VERSION
*/
static int s_about(User *u, char **av, int ac)
{
SET_SEGV_LOCATION();
privmsg_list(u->nick, s_StupidServ, s_help_about);
}
2003-10-06 13:00:31 +00:00
/*
* Routine for convert
*/
2004-02-16 20:43:35 +00:00
static int s_convert(User *u, char **av, int ac)
2003-10-06 13:00:31 +00:00
{
2003-02-18 13:52:05 +00:00
const gtf_filter_t *fp;
2003-10-06 13:00:31 +00:00
char *inbuf;
char outbuf[450];
2003-02-18 13:52:05 +00:00
2003-09-29 13:24:39 +00:00
SET_SEGV_LOCATION();
2003-02-18 13:52:05 +00:00
/* now find the language they want */
2004-02-16 20:43:35 +00:00
fp = gtf_filter_lookup(av[2]);
2003-02-18 13:52:05 +00:00
if (!fp) {
prefmsg(u->nick, s_StupidServ, "Can not find that Language. /msg %s list for language list", s_StupidServ);
return;
}
2004-02-16 20:43:35 +00:00
inbuf = joinbuf(av, ac, 3);
2003-02-18 13:52:05 +00:00
if (fp->filter(inbuf, outbuf, 450) > 0) {
prefmsg(u->nick, s_StupidServ, "Translated Text was too Long. Sending shortened text only");
}
prefmsg(u->nick, s_StupidServ, "%s", outbuf);
free(inbuf);
}
2003-10-06 13:00:31 +00:00
/*
* Routine for list
*/
2004-02-16 20:43:35 +00:00
static int s_list(User *u, char **av, int ac)
2003-10-06 13:00:31 +00:00
{
2003-02-18 13:52:05 +00:00
const gtf_filter_t *fp, *fp1;
int i;
2003-10-06 13:00:31 +00:00
2003-02-18 13:52:05 +00:00
prefmsg(u->nick, s_StupidServ, "There are %d available Languages", gtf_filter_count());
fp1 = gtf_filter_list();
for (i = 0, fp = fp1; i < gtf_filter_count(); i++, fp++) {
prefmsg(u->nick, s_StupidServ, "Language: %s, Description: %s", fp->name, fp->desc);
}
prefmsg(u->nick, s_StupidServ, "End of List.");
}
2003-10-06 13:00:31 +00:00
/*
* Routine for send
*/
2004-02-16 20:43:35 +00:00
static int s_send(User *u, char **av, int ac)
2003-10-06 13:00:31 +00:00
{
2003-02-18 13:52:05 +00:00
const gtf_filter_t *fp;
2003-10-06 13:00:31 +00:00
char *inbuf;
char outbuf[450];
2003-02-18 13:52:05 +00:00
2003-09-29 13:24:39 +00:00
SET_SEGV_LOCATION();
2004-02-16 20:43:35 +00:00
if (findchan(av[3])) {
2003-11-19 21:54:25 +00:00
if (UserLevel(u) < NS_ULEVEL_OPER) {
2003-02-18 13:52:05 +00:00
prefmsg(u->nick, s_StupidServ, "Only Operators can send to channels.");
2004-02-27 09:50:49 +00:00
return;
2003-02-18 13:52:05 +00:00
}
2004-02-16 20:43:35 +00:00
} else if (!finduser(av[3])) {
2003-02-18 13:52:05 +00:00
prefmsg(u->nick, s_StupidServ, "That user cannot be found on IRC. As a result, your message was not sent. Please check the spelling and try again!");
return;
}
/* The user has passed the minimum requirements for input */
/* now find the language they want */
2004-02-16 20:43:35 +00:00
fp = gtf_filter_lookup(av[2]);
2003-02-18 13:52:05 +00:00
if (!fp) {
prefmsg(u->nick, s_StupidServ, "Can not find that Language. /msg %s list for language list", s_StupidServ);
return;
}
2004-02-16 20:43:35 +00:00
inbuf = joinbuf(av, ac, 4);
2003-02-18 13:52:05 +00:00
if (fp->filter(inbuf, outbuf, 450) > 0) {
prefmsg(u->nick, s_StupidServ, "Translated Text was too Long. Sending shortened text only");
}
2004-02-16 20:43:35 +00:00
prefmsg(av[3], s_StupidServ, "%s is talking %s, and sent this:", u->nick, av[2]);
prefmsg(av[3], s_StupidServ, "%s", outbuf);
prefmsg(u->nick, s_StupidServ, "Your Message was sent to %s", av[3]);
2003-02-18 13:52:05 +00:00
free(inbuf);
}