Commit 33ccd70d authored by Justin Mitchell's avatar Justin Mitchell

Move gags into the server

parent 3f03f06e
......@@ -16,6 +16,7 @@
#include "files.h"
#include "alarm.h"
#include "strings.h"
#include "str_util.h"
#include "perms.h"
#include "read.h"
#include "main.h"
......
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "bork.h"
#include "bb.h"
char *apply_bork(char *text, const struct pattern *list, int caps)
{
static char buff[MAXTEXTLENGTH];
int tp=0, bp=0;
int len;
const struct pattern *p;
int rule;
if (text==NULL) return(NULL);
len=strlen(text);
#ifdef DEBUG
p=list;
rule=0;
while (p->from!=NULL)
{
rule++;
p++;
}
printf("This ruleset contains %d rules.\n",rule);
#endif
while (tp<len && bp<MAXTEXTLENGTH-2)
{
if (text[tp]==033)
{
/* skip colour encoding sequences */
/*tp+=3;*/
buff[bp++]=text[tp++];
buff[bp++]=text[tp++];
buff[bp++]=text[tp++];
continue;
}
p=list;
rule=0;
while (p->from !=NULL)
{
int i=0, j=0, l=strlen(p->from);
/*if (tp+l > len) {p++; continue;} */
#ifdef DEBUG
printf("Trying rule %d 0x%p '%s' at posn %d (%c): ",rule,p,p->from,tp,text[tp]);
#endif
while (i<l)
{
if (p->from[i]=='%')
{
char c;
if (i==0 && tp!=0) c=text[tp+j-1];
else
c=text[tp+j];
if (tp+i==0 || !isalpha(c))
{
#ifdef DEBUG
printf("Failed any-char (%c)\n",c);
#endif
break;
}
#ifdef DEBUG
else
printf("%% match i=%d tp=%d j=%d c=%c ",i,tp,j,c);
#endif
}else
if (p->from[i]=='^')
{
if (tp+j!=0 && !isspace(text[tp+j-1])
&& !ispunct(text[tp+j-1]))
{
#ifdef DEBUG
printf("Failed ^\n");
#endif
break;
}
}else
if (p->from[i]=='$')
{
if (tp+j<len &&
!isspace(text[tp+j]) &&
!ispunct(text[tp+j]))
{
#ifdef DEBUG
printf("Failed $\n");
#endif
break;
}
}else
if (tolower(p->from[i]) != tolower(text[tp+j]))
{
#ifdef DEBUG
printf (" %c != %c\n",p->from[i],text[tp+j]);
#endif
break;
}else
j++;
i++;
}
if (i==l)
{
/* if (p->from[0]=='^' && tp!=0)
buff[bp++]=' ';
*/
/* dont let it overflow */
if (bp+strlen(p->to) > MAXTEXTLENGTH-2)
{
#ifdef DEBUG
printf("Too Long\n");
#endif
tp=len;
break;
}
if (j==strlen(p->to))
{ /* same length, copy case */
#ifdef DEBUG
printf("Keep case. j=%d\n",j);
#endif
for (i=0;i<strlen(p->to);i++)
{
if (isupper(text[tp+i]))
buff[bp++]=toupper(p->to[i]);
else
buff[bp++]=tolower(p->to[i]);
}
}else
{
int cas=0;
for (i=0;i<j;i++)
{ if (isupper(text[tp+i])) cas++; }
if (cas==j) /* all upper ? */
cas=1;
else cas=0;
#ifdef DEBUG
printf("Ignore case. j=%d len=%d\n",j,strlen(p->to));
#endif
for (i=0;i<strlen(p->to);i++)
if (cas)
buff[bp++]=toupper(p->to[i]);
else
buff[bp++]=p->to[i];
}
tp+=j;
#ifdef DEBUG
printf("Matched.\n");
#endif
break;
}
p++;
rule++;
}
if (p->from==NULL)
{
buff[bp++]=text[tp++];
#ifdef DEBUG
printf("No Match after %d rules, Just copy, New: tp=%d bp=%d\n",rule,tp,bp);
#endif
}
}
buff[bp]=0;
if (caps == 1)
{
/* all upper */
int i;
for (i=0;i<bp;i++)
{
buff[i]=toupper(buff[i]);
}
} else if (caps == -1)
{
/* all lower */
int i;
for (i=0;i<bp;i++)
{
buff[i]=tolower(buff[i]);
}
}
return(buff);
}
#ifdef DEBUG
int main(void)
{
char line[1024];
char *c;
while (!feof(stdin))
{
if (fgets(line,1023, stdin)!=NULL)
{
if ((c=strchr(line, '\n'))!=NULL) *c=0;
printf("%s", apply_bork(line, jive,0));
}
}
exit(0);
}
#endif
......@@ -21,6 +21,7 @@
#include "ipc.h"
#include "files.h"
#include "strings.h"
#include "str_util.h"
#include "perms.h"
#include "getpass.h"
#include "edit.h"
......
#ifndef GAGS_H
#define GAGS_H
/* function prototypes */
void gag_normal(char *text);
void gag_chef(char *text);
void gag_kraut(char *text);
void gag_fudd(char *text);
void gag_jive(char *text);
void gag_mirror(char *text);
void gag_latin(char *text);
void gag_censor(char *text);
void gag_wibble(char *text);
void gag_swab(char *text);
void gag_strfry(char *text);
void gag_tnarg(char *text);
void gag_furby(char *text);
void gag_warez(char *text);
void gag_bunny(char *text);
void gag_duck(char *text);
void gag_saya(char *text);
void gag_morse(char *text);
void gag_annoy(char *text);
void gag_french(char *text);
void gag_babel(char *text);
void gag_nosport(char *text);
void gag_ack(char *text);
void gag_hazelesque(char *text);
void gag_pklong(char *text);
/* maximum gag flag used */
#define MAX_GAG_FLAG 6
#endif /* GAGS_H */
#ifndef GAGTABLE_H
#define GAGTABLE_H
struct pattern {
const char *from;
const char *to;
};
extern const struct pattern chef[];
extern const struct pattern kraut[];
extern const struct pattern fudd[];
extern const struct pattern jive[];
extern const struct pattern censor[];
extern const struct pattern wibble[];
extern const struct pattern annoy[];
extern const struct pattern tnarg[];
extern const struct pattern furby[];
extern const struct pattern warez[];
extern const struct pattern french[];
extern const struct pattern babelfish[];
extern const struct pattern nosport[];
#endif /* GAGTABLE_H */
......@@ -9,7 +9,7 @@
#include <curl/curl.h>
#include <sqlite.h>
#include "strings.h"
#include "str_util.h"
#include "js.h"
#include "log.h"
#include "uri.h"
......
......@@ -16,6 +16,7 @@
#include "command.h"
#include "alarm.h"
#include "strings.h"
#include "str_util.h"
#include "iconv.h"
#include "talker.h"
......
......@@ -10,7 +10,7 @@
#include <fcntl.h>
#include <string.h>
#include "files.h"
#include "strings.h"
#include "str_util.h"
#include "read.h"
#include "intl.h"
#include "mod.h"
......
......@@ -12,6 +12,7 @@
#include <unistd.h>
#include "alarm.h"
#include "incoming.h"
#include "str_util.h"
#include "strings.h"
#include "talker.h"
#include "perms.h"
......
......@@ -13,6 +13,7 @@
#include "folders.h"
#include "iconv.h"
#include "strings.h"
#include "str_util.h"
#include "main.h"
#include "perms.h"
#include "files.h"
......
......@@ -11,6 +11,7 @@
#include <string.h>
#include <stdbool.h>
#include "strings.h"
#include "str_util.h"
#include "perms.h"
#include "read.h"
#include "talker.h"
......
......@@ -11,6 +11,7 @@
#include "bb.h"
#include "talker_privs.h"
#include "strings.h"
#include "str_util.h"
#include "expand.h"
#include "talker.h"
#include "init.h"
......
......@@ -17,7 +17,7 @@
#include "alarm.h"
#include "rooms.h"
#include "alias.h"
#include "strings.h"
#include "str_util.h"
#include "expand.h"
#include "ipc.h"
#include "iconv.h"
......@@ -296,17 +296,14 @@ void scr_say( struct code *pc, int fargc, char **fargv )
}
else if (!strcasecmp(pc->inst->name, "shout"))
{
apply_gag(utf8buff);
talk_send_shout(utf8buff);
}
else if (!strcasecmp(pc->inst->name, "emote"))
{
apply_gag(utf8buff);
talk_send_emote(utf8buff, user->room, 0);
}
else if (!strcasecmp(pc->inst->name, "raw"))
{
apply_gag(utf8buff);
talk_send_raw(utf8buff, user->room);
}
free(tmp);
......
......@@ -10,32 +10,6 @@
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
int stringcmp(const char *a, const char *b, int n)
{
int length;
/* total match */
if (n==-1)
{
length=max(strlen(a),strlen(b));
}
/* first partial match */
else if (n==-2)
{
length=min(strlen(a),strlen(b));
}
/* match by atleast n (or shortest string) */
else
{
if (strlen(a)<n) return 0;
length=strlen(a)>strlen(b)?strlen(a):strlen(b);
length=n<length?n:length;
}
if (length==0) return 0;
return (!strncasecmp(a,b,length));
}
struct stacked_str *cmd_stack = NULL;
struct stacked_str **last_cmd = &cmd_stack;
static int stacked=0;
......@@ -89,26 +63,6 @@ void pop_cmd(char *string, int len, int *type)
string[len]=0;
}
void strip_str(char *string)
{
char *array;
int i,ptr=0;
int len;
len=strlen(string);
array=(char *)malloc(len+1);
for (i=0;i<len;i++)
{
if (string[i]==033 || (string[i]>=040 && string[i]<=0176) || (unsigned char)string[i]>0177)
array[ptr++]=string[i];
}
array[ptr]=0;
strcpy(string,array);
free(array);
}
/* common file functions */
char *buildpath(const char *a, const char *b, const char *c, const char *d)
......@@ -127,204 +81,3 @@ int err_open(const char *path,int type,int mode)
perror(path);
return(x);
}
int get_rand(int min, int max)
{
int r = rand();
float fValue;
fValue = (float)r * (float)(max - min + 1);
fValue /= (float)RAND_MAX;
fValue += (float)min;
return ((int)fValue);
}
void string_add(char **str, const char *add)
{
if (add != NULL)
{
if (*str == NULL)
{
*str = strdup(add);
}
else
{
*str = realloc(*str, sizeof(char) * (strlen(*str) + strlen(add) + 1));
strcat(*str, add);
}
}
}
int allspace(char *in)
{
if (!strcmp(in, "")) {
return(1);
} else {
int i;
for(i=0;i<strlen(in);i++)
{
if (in[i]!=' ') return(0);
}
return(1);
}
}
void strlower(char *szString)
{
int nLength, nIndex;
nLength = strlen(szString);
for (nIndex = 0; nIndex < nLength; nIndex++)
{
szString[nIndex] = tolower(szString[nIndex]);
}
}
/* replace ESC characters ('\033') with "[ESC]", maybe in black on white */
static void strip_esc(char *const in, int hilite)
{
static char szOutText[MAXTEXTLENGTH];
int oldlen = strlen(in), nInPos, nOutPos;
if (oldlen >= MAXTEXTLENGTH-1) oldlen = MAXTEXTLENGTH;
for (nInPos = 0, nOutPos = 0; nInPos < oldlen && nOutPos < MAXTEXTLENGTH-1; nInPos++)
{
/* escape character found */
if (in[nInPos] == 033)
{
const char*const esc = "\033[7m[ESC]\033[0m";
const char*const noesc = "[ESC]";
if (hilite) {
/* like strncpy, but avoid writing incomplete escape sequences */
if (nOutPos >= (MAXTEXTLENGTH << 1) + strlen(esc)) {
break; /* not enough space left */
}
strcpy(szOutText+nOutPos, esc);
nOutPos += strlen(esc);
} else {
strncpy(szOutText+nOutPos, noesc, MAXTEXTLENGTH-nOutPos-1);
nOutPos += strlen(noesc);
}
}
/* normal character */
else
{
szOutText[nOutPos++] = in[nInPos];
}
}
szOutText[nOutPos] = 0;
strcpy(in, szOutText);
}
void escprintf(const char *szFormat, ...)
{
static char szText[MAXTEXTLENGTH];
va_list vaList;
/* get text to process */
va_start(vaList, szFormat);
vsnprintf(szText, MAXTEXTLENGTH-1, szFormat, vaList);
va_end(vaList);
/* process control characters into strings */
strip_esc(szText,1);
printf("%s", szText);
}
/* returns a new string without any mw colour codes in */
char *strip_colours(const char *text)
{
char *new;
int i, j, len, k;
len = strlen(text);
new = malloc(sizeof(char) * (len+1));
i=0;
j=0;
while (i<len)
{
if (text[i]==033)
{
i++;
k=0;
//utf8 safe way to skip the next two chars
//we only need this in case someone is mean enough to try using something like
// [ESC]r£ as a colour sequence which would previously have us remove the first
// byte of the utf8 sequence leaving us with an invalid char.
while(i<len && k<2)
{
if(((unsigned char)text[i] & 192)==192 )
{
// skip char is the first byte of a utf8 sequence
i++;
while( ((unsigned char)text[i] & 192) == 128 && i<len)
{
//skip all utf8 continuation bytes
i++;
}
}
else
{
// char was ascii so we can just skip it.
i++;
}
k++;
}
continue;
}
new[j++]=text[i++];
}
new[j]=0;
return(new);
}
/* Strip any trailing quote characters (^a) that may have been left at the end
* * of a buffer by snprintf() truncating a quoted string.
* */
void strip_quote(char *a)
{
char *end = a + strlen(a);
/* Step back through quote chars */
while (end > a && *(--end) == '\001')
*end = '\0';
}
char *quotetext(const char *a)
{
int count;
int ai, bi;
char *b;
ai=0;
count=0;
while(a[ai]!=0)
{
if (a[ai]=='|') count++;
ai++;
}
b = malloc(sizeof(char) * (strlen(a) + count + 1));
ai=bi=0;
while (a[ai]!=0)
{
if (a[ai]=='|')
{
b[bi]=1;
bi++;
}
b[bi]=a[ai];
bi++;
ai++;
}
b[bi]=0;
return (b);
}
......@@ -18,17 +18,6 @@ void stack_str(char *string);
int is_stacked(void);
void pop_cmd(char *string, int len, int *type);
int pop_stack(char *string, int len);
int get_rand(int min, int max);
void string_add(char **str, const char *add);
int allspace(char *s);
void strlower(char *szString);
int stringcmp(const char *a, const char *b, int n);
void escprintf(const char *szFormat, ...) __attribute__((format(printf,1,2)));
char *strip_colours(const char *text);
void strip_str(char *string);
void strip_quote(char *a);
char *quotetext(const char *a);
char *buildpath(const char *a, const char *b, const char *c, const char *d);
#define makepath(a,b,c) (buildpath(HOMEPATH,a,b,c))
......
......@@ -11,7 +11,8 @@
#include "talker_privs.h"
#include "special.h"
#include "talker.h"
#include "gags.h"
#include <gags.h>
#include "str_util.h"
#include "strings.h"
#include "special.h"
#include "script_inst.h"
......@@ -410,7 +411,6 @@ void t_shout(CommandList *cm, int argc, const char **argv, char *args)
text[0]=0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
apply_gag(text);
talk_send_shout(text);
}
......@@ -430,7 +430,6 @@ void t_sayto(CommandList *cm, int argc, const char **argv, char *args)
const char *type = "says";
if (text[strlen(text)-1] == '?') type = "asks";
apply_gag(text);
talk_sayto(text, argv[1], type);
}
......@@ -450,7 +449,6 @@ void t_notsayto(CommandList *cm, int argc, const char **argv, char *args)
return;
}
snprintf(text, MAXTEXTLENGTH, "%s", args);
apply_gag(text);
mwlog("NSAYTO %s %s", argv[1], text);
/* variant of say_to_room but with an exclude clause */
......@@ -481,7 +479,6 @@ void t_ventril(CommandList *cm, int argc, const char **argv, char *args)
display_message("Invalid room number. Must be between 0 and 65535", 1, 1);
}else
{
apply_gag(text);
talk_send_say(text,i);
}
}
......@@ -507,7 +504,6 @@ void t_ventril_raw(CommandList *cm, int argc, const char **argv, char *args)
display_message("Invalid room number. Must be between 0 and 65535", 1, 1);
}else
{
apply_gag(text);
talk_send_raw(text,i);
}
}
......@@ -524,7 +520,6 @@ void t_emote(CommandList *cm, int argc, const char **argv, char *args)
text[0] = 0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
apply_gag(text);
talk_send_emote(text,user->room,0);
}
......@@ -535,7 +530,6 @@ void t_emotes(CommandList *cm, int argc, const char **argv, char *args)
text[0] = 0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
apply_gag(text);
talk_send_emote(text,user->room,1);
}
......@@ -546,7 +540,6 @@ void t_emotes2(CommandList *cm, int argc, const char **argv, char *args)
text[0] = 0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
apply_gag(text);
talk_send_emote(text,user->room,2);
}
......@@ -557,7 +550,6 @@ void t_emoted(CommandList *cm, int argc, const char **argv, char *args)
text[0] = 0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);
apply_gag(text);
talk_send_emote(text,user->room,3);
}
......@@ -568,7 +560,6 @@ void t_emotell(CommandList *cm, int argc, const char **argv, char *args)
text[0] = 0;
strncat(text, args, MAXTEXTLENGTH - strlen(text) - 1);