diff -burN eggdrop1.6.15/aclocal.m4 eggdrop1.6.15-ssl/aclocal.m4
--- eggdrop1.6.15/aclocal.m4	2003-05-05 00:09:24.000000000 +0200
+++ eggdrop1.6.15-ssl/aclocal.m4	2003-05-19 16:41:56.000000000 +0200
@@ -15,6 +15,62 @@
 AC_MSG_RESULT()
 ])dnl
 
+dnl  EGG_SSL_CRAP()
+dnl
+AC_DEFUN(EGG_SSL_CRAP, [dnl
+#ssl checks - hoe
+AC_MSG_CHECKING(whether to include SSL support)
+AC_ARG_WITH(ssl,
+[  --with-ssl[=PATH]         Include SSL support (DIR is OpenSSL's install dir).],
+[
+  case "$withval" in
+    no)
+      AC_MSG_RESULT(no) ;;
+    yes)
+      AC_MSG_RESULT(yes)
+      AC_CHECK_LIB(ssl,SSL_accept,[AC_DEFINE(EGG_SSL_EXT)
+      SSL_LIBS="-lssl -lcrypto"],[AC_MSG_ERROR([You requested SSL support, but OpenSSL was not found. Please supply a pathname to OpenSSL])],-lcrypto)
+      ;;
+    *)
+dnl A whole whack of possible places where this might be
+      test -f $withval/openssl/ssl.h && SSL_INCLUDE="$withval"
+      test -f $withval/include/openssl/ssl.h && SSL_INCLUDE="$withval/include"
+
+      test -f $withval/lib/libssl.a && SSL_LIB="$withval/lib"
+      test -f $withval/lib/ssl/libssl.a && SSL_LIB="$withval/lib/ssl"
+      test -f $withval/lib/openssl/libssl.a && SSL_LIB="$withval/lib/openssl/ssl"
+      test -f $withval/libssl.a && SSL_LIB="$withval"
+      test -f $withval/ssl/libssl.a && SSL_LIB="$withval/ssl"
+      test -f $withval/openssl/libssl.a && SSL_LIB="$withval/openssl"
+
+      test -f $withval/lib/libcrypto.a && CRYPTO_LIB="$withval/lib"
+      test -f $withval/lib/ssl/libcrypto.a && CRYPTO_LIB="$withval/lib/ssl"
+      test -f $withval/lib/openssl/libcrypto.a && CRYPTO_LIB="$withval/lib/openssl/ssl"
+      test -f $withval/libcrypto.a && CRYPTO_LIB="$withval"
+      test -f $withval/ssl/libcrypto.a && CRYPTO_LIB="$withval/ssl"
+      test -f $withval/openssl/libcrypto.a && CRYPTO_LIB="$withval/openssl"
+
+      if test -n "$SSL_INCLUDE" && test -n "$SSL_LIB" && test -n "$CRYPTO_LIB"; then
+        SSL_LIBS="-lssl -lcrypto -L$SSL_LIB -L$CRYPTO_LIB";
+        AC_DEFINE(EGG_SSL_EXT)
+        AC_MSG_RESULT(yes)
+      else
+        AC_MSG_RESULT(no)
+        AC_MSG_ERROR([You requested SSL support, but OpenSSL was not found. Please supply a pathname to OpenSSL])
+      fi ;;
+  esac
+],[
+    AC_MSG_RESULT(will try to find)
+    AC_CHECK_LIB(ssl,SSL_accept,[AC_DEFINE(EGG_SSL_EXT)
+     SSL_LIBS="-lssl -lcrypto"],[AC_MSG_ERROR([OpenSSL was not found. Please supply a pathname to OpenSSL])],-lcrypto)
+    AC_CHECK_HEADERS("openssl/ssl.h",,[AC_MSG_ERROR([OpenSSL was not found. Please supply a pathname to OpenSSL])],)
+
+    AC_SUBST(SSL_LIBS)dnl
+    AC_SUBST(SSL_INCLUDE)dnl
+])
+
+#end of ssl checks - hoe
+])dnl
 
 dnl  EGG_MSG_CONFIGURE_END()
 dnl
diff -burN eggdrop1.6.15/config.h.in eggdrop1.6.15-ssl/config.h.in
--- eggdrop1.6.15/config.h.in	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/config.h.in	2003-05-19 16:41:57.000000000 +0200
@@ -60,6 +60,9 @@
 /* Define to 1 if you have the `clock' function. */
 #undef HAVE_CLOCK
 
+/* Defines ssl mode  */
+#undef EGG_SSL_EXT 
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H
diff -burN eggdrop1.6.15/Makefile.in eggdrop1.6.15-ssl/Makefile.in
--- eggdrop1.6.15/Makefile.in	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/Makefile.in	2003-05-19 16:41:57.000000000 +0200
@@ -61,6 +61,8 @@
 # stuff for Tcl
 XREQS = @TCL_REQS@
 XLIBS = @TCL_LIBS@ @LIBS@
+XSSL_LIBS = @SSL_LIBS@
+XSSL_INCLUDE = @SSL_INCLUDE@
 TCLLIB = @TCLLIB@
 TCLLIBFN = @TCLLIBFN@
 
@@ -86,7 +88,8 @@
 MAKE_MODEGG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(MOD_CC)' 'LD=$(MOD_LD)' \
 'STRIP=$(MOD_STRIP)' 'RANLIB=$(RANLIB)' 'CFLGS=$(CFLGS)' \
 'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
-'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=' 'MODOBJS='
+'XSSL_LIBS=$(XSSL_LIBS)' 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' \
+'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'EGGBUILD=' 'MODOBJS='
 
 MAKE_MODULES = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(SHLIB_CC)' 'LD=$(SHLIB_LD)' \
 'STRIP=$(SHLIB_STRIP)' 'CFLGS=$(CFLGS)' 'XLIBS=$(XLIBS)' 'MOD_EXT=$(MOD_EXT)'
@@ -95,12 +98,13 @@
 'STRIP=$(STRIP)' 'RANLIB=$(RANLIB)' 'CFLGS=$(CFLGS) -DSTATIC' \
 'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(static version)' \
-'MODOBJS=mod/*.o'
+'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'XSSL_LIBS=$(XSSL_LIBS)' 'MODOBJS=mod/*.o'
 
 MAKE_DEBEGG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(MOD_CC)' 'LD=$(MOD_LD) -g' \
 'STRIP=touch' 'RANLIB=$(RANLIB)' 'CFLGS=-g3 $(DEBCFLAGS) $(CFLGS)' \
 'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
-'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(debug version)' 'MODOBJS='
+'XSSL_LIBS=$(XSSL_LIBS)' 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' \
+'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'EGGBUILD=(debug version)' 'MODOBJS='
 
 MAKE_DEBMODULES = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(SHLIB_CC)' 'LD=$(SHLIB_LD)' \
 'XLIBS=$(XLIBS)' 'STRIP=touch' 'CFLGS=-g3 $(DEBCFLAGS) $(CFLGS)' \
@@ -109,7 +113,8 @@
 MAKE_SDEBUG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)' 'LD=$(LD) -g' \
 'STRIP=touch' 'RANLIB=$(RANLIB)' 'CFLGS=-g3 $(DEBCFLAGS) -DSTATIC $(CFLGS)' \
 'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' 'XLIBS=$(XLIBS)' \
-'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(static and debug version)' 'MODOBJS=mod/*.o'
+'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'XSSL_LIBS=$(XSSL_LIBS)' 'EGGEXEC=$(EGGEXEC)' \
+'EGGBUILD=(static and debug version)' 'MODOBJS=mod/*.o'
 
 MAKE_DEPEND = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)' 'LD=$(LD)' \
 'STRIP=$(STRIP)' 'CFLGS=$(CFLGS)'
diff -burN eggdrop1.6.15/src/dcc.c eggdrop1.6.15-ssl/src/dcc.c
--- eggdrop1.6.15/src/dcc.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/dcc.c	2003-05-19 16:41:57.000000000 +0200
@@ -32,7 +32,11 @@
 #include "tandem.h"
 
 /* Includes for botnet md5 challenge/response code <cybah> */
+#ifndef EGG_SSL_EXT
 #include "md5/md5.h"
+#else
+#include "openssl/md5.h"
+#endif
 
 extern struct userrec *userlist;
 extern struct chanset_t *chanset;
diff -burN eggdrop1.6.15/src/dccutil.c eggdrop1.6.15-ssl/src/dccutil.c
--- eggdrop1.6.15/src/dccutil.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/dccutil.c	2003-05-19 16:41:57.000000000 +0200
@@ -33,6 +33,7 @@
 #include "chan.h"
 #include "modules.h"
 #include "tandem.h"
+#include "net.h"
 
 extern struct dcc_t *dcc;
 extern int dcc_total, max_dcc, dcc_flood_thr, backgrd, copy_to_tmp, MAXSOCKS;
diff -burN eggdrop1.6.15/src/eggdrop.h eggdrop1.6.15-ssl/src/eggdrop.h
--- eggdrop1.6.15/src/eggdrop.h	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/eggdrop.h	2003-05-19 16:41:57.000000000 +0200
@@ -594,17 +594,7 @@
 /* This is used by the net module to keep track of sockets and what's
  * queued on them
  */
-typedef struct {
-  int sock;
-  short flags;
-  char *inbuf;
-  char *outbuf;
-  unsigned long outbuflen;      /* Outbuf could be binary data  */
-  unsigned long inbuflen;       /* Inbuf could be binary data   */
-#ifdef USE_IPV6
-  unsigned int af;
-#endif /* USE_IPV6 */
-} sock_list;
+/* sock_list moved to net.h */
 
 enum {
   EGG_OPTION_SET = 1,           /* Set option(s).               */
diff -burN eggdrop1.6.15/src/main.c eggdrop1.6.15-ssl/src/main.c
--- eggdrop1.6.15/src/main.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/main.c	2003-05-19 16:41:57.000000000 +0200
@@ -162,6 +162,9 @@
 int cx_ptr = 0;
 #endif
 
+#ifdef EGG_SSL_EXT
+ int clean_net();
+#endif
 
 void fatal(const char *s, int recoverable)
 {
@@ -172,6 +175,9 @@
   for (i = 0; i < dcc_total; i++)
     if (dcc[i].sock >= 0)
       killsock(dcc[i].sock);
+#ifdef EGG_SSL_EXT
+  clean_net();
+#endif        
   unlink(pid_file);
   if (!recoverable) {
     bg_send_quit(BG_ABORT);
diff -burN eggdrop1.6.15/src/Makefile.in eggdrop1.6.15-ssl/src/Makefile.in
--- eggdrop1.6.15/src/Makefile.in	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/Makefile.in	2003-05-19 16:41:57.000000000 +0200
@@ -15,7 +15,8 @@
 CC = @CC@
 LD = @CC@
 STRIP = @STRIP@
-CFLAGS = @CFLAGS@ -I.. -I$(top_srcdir) @DEFS@ $(CFLGS)
+#CFLAGS = @CFLAGS@ -I.. -I$(top_srcdir) @DEFS@ $(CFLGS)
+CFLAGS = @CFLAGS@ -I$(XSSL_INCLUDE) -I.. -I$(top_srcdir) @DEFS@ $(CFLGS)
 CPPFLAGS = @CPPFLAGS@
 
 eggdrop_objs = bg.o botcmd.o botmsg.o botnet.o chanprog.o cmds.o dcc.o \
@@ -37,7 +38,8 @@
 	@echo "Linking eggdrop... $(EGGBUILD)"
 	@echo ""
 	@touch mod/mod.xlibs
-	$(LD) -o ../$(EGGEXEC) $(eggdrop_objs) $(MODOBJS) $(XLIBS) md5/md5c.o compat/*.o `cat mod/mod.xlibs`
+#	$(LD) -o ../$(EGGEXEC) $(eggdrop_objs) $(MODOBJS) $(XLIBS) md5/md5c.o compat/*.o `cat mod/mod.xlibs`
+	$(LD) -o ../$(EGGEXEC) $(eggdrop_objs) $(XSSL_LIBS) $(MODOBJS) $(XLIBS) md5/md5c.o compat/*.o `cat mod/mod.xlibs`
 	$(STRIP) ../$(EGGEXEC)
 	@echo "Successful compile: $(EGGEXEC)"
 	@echo ""
diff -burN eggdrop1.6.15/src/md5/md5c.c eggdrop1.6.15-ssl/src/md5/md5c.c
--- eggdrop1.6.15/src/md5/md5c.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/md5/md5c.c	2003-05-19 16:41:57.000000000 +0200
@@ -15,6 +15,9 @@
  * and avoid compile-time configuration.
  */
 
+#include "../config.h"
+#ifndef EGG_SSL_EXT
+
 #include <string.h>
 
 #include "md5.h"
@@ -269,3 +272,5 @@
 
 	egg_memset(ctx, 0, sizeof(ctx));
 }
+
+#endif
diff -burN eggdrop1.6.15/src/md5/md5.h eggdrop1.6.15-ssl/src/md5/md5.h
--- eggdrop1.6.15/src/md5/md5.h	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/md5/md5.h	2003-05-19 16:41:57.000000000 +0200
@@ -6,6 +6,9 @@
  * the public domain.  See md5c.c for more information.
  */
 
+#include "../config.h"
+#ifndef EGG_SSL_EXT
+
 #ifndef _MD5_H
 #define _MD5_H
 
@@ -24,3 +27,4 @@
 extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
 
 #endif
+#endif
diff -burN eggdrop1.6.15/src/mod/compress.mod/compress.c eggdrop1.6.15-ssl/src/mod/compress.mod/compress.c
--- eggdrop1.6.15/src/mod/compress.mod/compress.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/compress.mod/compress.c	2003-05-19 16:41:57.000000000 +0200
@@ -31,11 +31,12 @@
 
 #include <string.h>
 #include <errno.h>
-#include <zlib.h>
 
 #include "src/mod/module.h"
 #include "share.mod/share.h"
 
+#include <zlib.h>
+
 #include "compress_config.h"
 #ifdef HAVE_MMAP
 #  include <sys/types.h>
diff -burN eggdrop1.6.15/src/mod/irc.mod/chan.c eggdrop1.6.15-ssl/src/mod/irc.mod/chan.c
--- eggdrop1.6.15/src/mod/irc.mod/chan.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/irc.mod/chan.c	2003-05-19 16:41:57.000000000 +0200
@@ -924,10 +924,10 @@
         q = strchr(p, ' ');
         if (q != NULL) {
           *q = 0;
-          set_key(chan, p);
+          set_keyegg(chan, p);
           strcpy(p, q + 1);
         } else {
-          set_key(chan, p);
+          set_keyegg(chan, p);
           *p = 0;
         }
       }
diff -burN eggdrop1.6.15/src/mod/irc.mod/irc.c eggdrop1.6.15-ssl/src/mod/irc.mod/irc.c
--- eggdrop1.6.15/src/mod/irc.mod/irc.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/irc.mod/irc.c	2003-05-19 16:41:57.000000000 +0200
@@ -253,7 +253,7 @@
 
 /* Set the key.
  */
-static void set_key(struct chanset_t *chan, char *k)
+static void set_keyegg(struct chanset_t *chan, char *k)
 {
   nfree(chan->channel.key);
   if (k == NULL) {
diff -burN eggdrop1.6.15/src/mod/irc.mod/irc.h eggdrop1.6.15-ssl/src/mod/irc.mod/irc.h
--- eggdrop1.6.15/src/mod/irc.mod/irc.h	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/irc.mod/irc.h	2003-05-19 16:41:57.000000000 +0200
@@ -69,7 +69,7 @@
 
 static void reset_chan_info(struct chanset_t *);
 static void recheck_channel(struct chanset_t *, int);
-static void set_key(struct chanset_t *, char *);
+static void set_keyegg(struct chanset_t *, char *);
 static void maybe_revenge(struct chanset_t *, char *, char *, int);
 static int detect_chan_flood(char *, char *, char *, struct chanset_t *, int,
                              char *);
diff -burN eggdrop1.6.15/src/mod/irc.mod/mode.c eggdrop1.6.15-ssl/src/mod/irc.mod/mode.c
--- eggdrop1.6.15/src/mod/irc.mod/mode.c	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/irc.mod/mode.c	2003-05-19 16:41:57.000000000 +0200
@@ -1106,7 +1106,7 @@
           }
           check_tcl_mode(nick, from, u, chan->dname, ms2, op);
           if (ms2[0] == '+') {
-            set_key(chan, op);
+            set_keyegg(chan, op);
             if (channel_active(chan))
               got_key(chan, nick, from, op);
           } else {
@@ -1117,7 +1117,7 @@
                        !chan_master(user) && !match_my_nick(nick))
                 add_mode(chan, '+', 'k', chan->key_prot);
             }
-            set_key(chan, NULL);
+            set_keyegg(chan, NULL);
           }
           break;
         case 'o':
diff -burN eggdrop1.6.15/src/mod/module.h eggdrop1.6.15-ssl/src/mod/module.h
--- eggdrop1.6.15/src/mod/module.h	2003-05-05 00:05:32.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/module.h	2003-05-19 16:42:33.000000000 +0200
@@ -477,8 +477,12 @@
 #define file_readable ((int (*) (char *))global[285])
 #define getprotocol ((int (*)(char *))global[286])
 #define open_listen_by_af ((int (*) (int *, int))global[287])
-/* 288 - 291 */
+/* 288 - 293 */
 #define egg_inet_ntop ((int (*)(int af, const void *src, char *dst, socklen_t size))global[288])
+#ifdef EGG_SSL_EXT
+#define net_switch_to_ssl ((int (*)(int))global[289])
+#define use_ssl (*(int *)global[290]) /* kyotou */
+#endif
 
 /* hostmasking */
 #define maskhost(a,b) _maskhost((a),(b),1)
diff -burN eggdrop1.6.15/src/mod/server.mod/servmsg.c eggdrop1.6.15-ssl/src/mod/server.mod/servmsg.c
--- eggdrop1.6.15/src/mod/server.mod/servmsg.c	2003-05-05 00:05:33.000000000 +0200
+++ eggdrop1.6.15-ssl/src/mod/server.mod/servmsg.c	2003-05-19 16:41:57.000000000 +0200
@@ -1242,6 +1242,14 @@
       fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
   } else {
     dcc[servidx].sock = serv;
+#ifdef EGG_SSL_EXT
+    if (use_ssl) { /* kyotou */
+        if (net_switch_to_ssl(serv)==0) {
+            putlog(LOG_SERV, "*", "SSL %s %s (Error while switching to SSL)", IRC_FAILEDCONNECT, dcc[servidx].host);
+            lostdcc(servidx);    
+        }
+    }    
+#endif
     /* Queue standard login */
     dcc[servidx].timeval = now;
     SERVER_SOCKET.timeout_val = &server_timeout;
diff -burN eggdrop1.6.15/src/modules.c eggdrop1.6.15-ssl/src/modules.c
--- eggdrop1.6.15/src/modules.c	2003-05-05 00:05:33.000000000 +0200
+++ eggdrop1.6.15-ssl/src/modules.c	2003-05-19 16:41:57.000000000 +0200
@@ -28,7 +28,13 @@
 #include "main.h"
 #include "modules.h"
 #include "tandem.h"
+
+#ifndef EGG_SSL_EXT
 #include "md5/md5.h"
+#else
+#include "openssl/md5.h"
+#endif
+
 #include <ctype.h>
 #ifndef STATIC
 #  ifdef HPUX_HACKS
@@ -65,6 +71,7 @@
 extern struct dcc_t *dcc;
 
 #include "users.h"
+#include "net.h"
 
 
 extern struct userrec *userlist, *lastuser;
@@ -83,6 +90,9 @@
            default_flags, require_p, share_greet, use_invites, use_exempts,
            password_timeout, force_expire, protect_readonly, reserved_port_min,
            reserved_port_max, copy_to_tmp, quiet_reject;
+#ifdef EGG_SSL_EXT
+extern int      use_ssl; /* kyotou */
+#endif
 
 extern party_t *party;
 extern time_t now, online_since;
@@ -97,6 +107,11 @@
 int xtra_unpack();
 static int module_rename(char *name, char *newname);
 
+#ifdef EGG_SSL_EXT
+int net_switch_to_ssl(int);
+#endif
+
+
 
 #ifndef STATIC
 
@@ -563,7 +578,13 @@
   (Function) file_readable,
   (Function) getprotocol,
   (Function) open_listen_by_af,
+#ifdef EGG_SSL_EXT
+  (Function) egg_inet_ntop,
+  (Function) net_switch_to_ssl,
+  (Function) & use_ssl /* kyotou */
+#else
   (Function) egg_inet_ntop
+#endif
 };
 
 void init_modules(void)
diff -burN eggdrop1.6.15/src/net.c eggdrop1.6.15-ssl/src/net.c
--- eggdrop1.6.15/src/net.c	2003-05-05 00:05:33.000000000 +0200
+++ eggdrop1.6.15-ssl/src/net.c	2003-05-19 16:41:57.000000000 +0200
@@ -34,6 +34,17 @@
 #  endif
 #endif
 
+#ifdef EGG_SSL_EXT
+# ifndef EGG_SSL_INCS
+#  include <openssl/ssl.h>
+#  include <openssl/err.h>
+#  include <openssl/rand.h>
+#  define EGG_SSL_INCS 1
+# endif
+#endif
+
+#include "net.h"
+
 extern struct dcc_t *dcc;
 extern int backgrd, use_stderr, resolve_timeout, dcc_total;
 extern unsigned long otraffic_irc_today, otraffic_bn_today, otraffic_dcc_today,
@@ -53,6 +64,11 @@
 char botuser[21] = "eggdrop"; /* Username of the user running the bot         */
 int dcc_sanitycheck = 0;      /* We should do some sanity checking on dcc
                                * connections.                                 */
+#ifdef EGG_SSL_EXT
+SSL_CTX *ssl_ctx=NULL;
+char	*tls_rand_file = NULL;
+int     use_ssl = 0; /* kyotou */
+#endif
 sock_list *socklist = NULL;   /* Enough to be safe                            */
 int MAXSOCKS = 0;
 jmp_buf alarmret;             /* Env buffer for alarm() returns               */
@@ -109,6 +125,45 @@
 #endif /* USE_IPV6 */
 }
 
+#ifdef EGG_SSL_EXT
+int seed_PRNG(void)
+{
+    char stackdata[1024];
+    static char rand_file[300];
+    FILE *fh;
+    
+#if OPENSSL_VERSION_NUMBER >= 0x00905100
+    if (RAND_status())
+	return 0;     /* PRNG already good seeded */
+#endif
+    /* if the device '/dev/urandom' is present, OpenSSL uses it by default.
+     * check if it's present, else we have to make random data ourselfs.
+     */
+    if ((fh = fopen("/dev/urandom", "r"))) {
+	fclose(fh);
+	return 0;
+    }
+    if (RAND_file_name(rand_file, sizeof(rand_file)))
+	tls_rand_file = rand_file;
+    else
+	return 1;
+    if (!RAND_load_file(rand_file, 1024)) {
+	/* no .rnd file found, create new seed */
+	unsigned int c;
+	c = time(NULL);
+	RAND_seed(&c, sizeof(c));
+	c = getpid();
+	RAND_seed(&c, sizeof(c));
+	RAND_seed(stackdata, sizeof(stackdata));
+    }
+#if OPENSSL_VERSION_NUMBER >= 0x00905100
+    if (!RAND_status())
+	return 2;   /* PRNG still badly seeded */
+#endif
+    return 0;
+}
+#endif
+
 /* Initialize the socklist
  */
 void init_net()
@@ -117,9 +172,35 @@
 
   for (i = 0; i < MAXSOCKS; i++) {
     socklist[i].flags = SOCK_UNUSED;
+#ifdef EGG_SSL_EXT
+    socklist[i].ssl=NULL;
+#endif
   }
+#ifdef EGG_SSL_EXT
+  /* good place to init ssl stuff */
+  SSL_load_error_strings();
+  OpenSSL_add_ssl_algorithms();
+  ssl_ctx=SSL_CTX_new(SSLv23_client_method());
+  if (!ssl_ctx) 
+   fatal("SSL_CTX_new() failed",0);
+  if (seed_PRNG())
+    fatal("Wasn't able to properly seed the PRNG!",0);	
+#endif
 }
 
+#ifdef EGG_SSL_EXT
+/* cleanup mess when quiting */
+int clean_net() {
+   if (ssl_ctx) {
+	SSL_CTX_free(ssl_ctx);
+	ssl_ctx = NULL;
+  }
+  if (tls_rand_file)
+	RAND_write_file(tls_rand_file);
+ return 0;
+}
+#endif
+
 int expmem_net()
 {
   int i, tot = 0;
@@ -382,6 +463,13 @@
     return;
   for (i = 0; i < MAXSOCKS; i++) {
     if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
+#ifdef EGG_SSL_EXT
+      if (socklist[i].ssl) {
+    	SSL_shutdown(socklist[i].ssl);
+	SSL_free(socklist[i].ssl);
+	socklist[i].ssl=NULL;
+  }
+#endif
       close(socklist[i].sock);
       if (socklist[i].inbuf != NULL) {
         nfree(socklist[i].inbuf);
@@ -625,6 +713,63 @@
   return sock;
 }
 
+#ifdef EGG_SSL_EXT
+int net_switch_to_ssl(int sock) {
+int err;
+int i=0;
+    debug0("net_switch_to_ssl()");
+    while (i<MAXSOCKS) {
+     if (socklist[i].sock==sock) {
+      break;
+     }
+     i++;
+    }
+    if (i==MAXSOCKS) {
+        debug0("Error while swithing to SSL - sock not found in list");
+	return 0;
+    }
+
+    if (socklist[i].ssl) {
+        debug0("Error while swithing to SSL - already in ssl");
+	return 0;
+    }
+    socklist[i].ssl = SSL_new(ssl_ctx);
+    if (!socklist[i].ssl) {
+        debug0("Error while swithing to SSL - SSL_new() error");
+	return 0;
+    }
+
+     SSL_set_fd(socklist[i].ssl, socklist[i].sock);
+     err = SSL_connect(socklist[i].ssl);
+   
+     while (err <= 0) {
+        int errs;
+        errs=SSL_get_error(socklist[i].ssl,err);
+        if ((errs!=SSL_ERROR_WANT_READ)&&(errs!=SSL_ERROR_WANT_WRITE)&&
+	        (errs!=SSL_ERROR_WANT_X509_LOOKUP)) {
+		putlog(LOG_DEBUG,"*", "SSL_connect() = %d, %s", err,
+			(char *)ERR_error_string(ERR_get_error(), NULL));
+	 	SSL_shutdown(socklist[i].ssl);
+	 	SSL_free(socklist[i].ssl);
+	 	socklist[i].ssl = NULL;
+	        return 0;	    
+        }
+        usleep(1000);
+        err = SSL_connect(socklist[i].ssl);
+     }
+
+     if (err==1) {
+      debug0("SSL_connect() success"); 
+      return 1;
+     }
+     debug0("Error while SSL_connect()"); 
+     SSL_shutdown(socklist[i].ssl);
+     SSL_free(socklist[i].ssl); 
+     socklist[i].ssl = NULL;
+     return 0;
+}
+#endif
+
 /* Ordinary non-binary connection attempt */
 int open_telnet(char *server, int port)
 {
@@ -957,6 +1102,9 @@
     for (i = 0; i < MAXSOCKS; i++) {
       if ((!(socklist[i].flags & SOCK_UNUSED)) &&
           ((FD_ISSET(socklist[i].sock, &fd)) ||
+#ifdef EGG_SSL_EXT
+	   ((socklist[i].ssl)&&(SSL_pending(socklist[i].ssl))) ||
+#endif	  
           ((socklist[i].sock == STDOUT) && (!backgrd) &&
           (FD_ISSET(STDIN, &fd))))) {
         if (socklist[i].flags & (SOCK_LISTEN | SOCK_CONNECT)) {
@@ -981,7 +1129,31 @@
         if ((socklist[i].sock == STDOUT) && !backgrd)
           x = read(STDIN, s, grab);
         else
+#ifdef EGG_SSL_EXT
+	{
+        if (socklist[i].ssl) {
+           x=SSL_read(socklist[i].ssl,s,grab);
+ 	   if (x < 0) {
+	    int err = SSL_get_error(socklist[i].ssl, x);
+	    x = -1;
+	    switch (err) {
+	    	case SSL_ERROR_WANT_READ:
+		    errno = EAGAIN;
+		    break;
+	    	case SSL_ERROR_WANT_WRITE:
+ 		    errno = EAGAIN;
+		    break;
+         	case SSL_ERROR_WANT_X509_LOOKUP:
+		    errno = EAGAIN;
+		    break;
+		}
+  	    }
+        } else
           x = read(socklist[i].sock, s, grab);
+	}
+#else
+	  x = read(socklist[i].sock, s, grab);
+#endif      
         if (x <= 0) {           /* eof */
           if (errno != EAGAIN) { /* EAGAIN happens when the operation would
                                   * block on a non-blocking socket, if the
@@ -1283,6 +1455,26 @@
         socklist[i].outbuflen += len;
         return;
       }
+#ifdef EGG_SSL_EXT
+      if (socklist[i].ssl) {
+       x=SSL_write(socklist[i].ssl,s,len);
+ 	   if (x < 0) {
+	    int err = SSL_get_error(socklist[i].ssl, x);
+	    x = -1;
+	    switch (err) {
+	    	case SSL_ERROR_WANT_READ:
+		    errno = EAGAIN;
+		    break;
+        	case SSL_ERROR_WANT_WRITE:
+		    errno = EAGAIN;
+		    break;
+        	case SSL_ERROR_WANT_X509_LOOKUP:
+		    errno = EAGAIN;
+		    break;
+		}
+  	    }
+      } else
+#endif      
       /* Try. */
       x = write(z, s, len);
       if (x == -1)
@@ -1354,6 +1546,27 @@
         (socklist[i].outbuf != NULL) && (FD_ISSET(socklist[i].sock, &wfds))) {
       /* Trick tputs into doing the work */
       errno = 0;
+#ifdef EGG_SSL_EXT
+       if (socklist[i].ssl) {
+	   x = write(socklist[i].sock, socklist[i].outbuf,
+		socklist[i].outbuflen);
+ 	   if (x < 0) {
+ 	    int err = SSL_get_error(socklist[i].ssl, x);
+ 	    x = -1;
+ 	    switch (err) {
+ 	    	case SSL_ERROR_WANT_READ:
+ 		    errno = EAGAIN;
+ 		    break;
+ 	    	case SSL_ERROR_WANT_WRITE:
+ 		    errno = EAGAIN;
+ 		    break;
+ 	    	case SSL_ERROR_WANT_X509_LOOKUP:
+ 		    errno = EAGAIN;
+ 		    break;
+ 		}
+   	    }
+       } else
+#endif      
       x = write(socklist[i].sock, socklist[i].outbuf, socklist[i].outbuflen);
       if ((x < 0) && (errno != EAGAIN)
 #ifdef EBADSLT
diff -burN eggdrop1.6.15/src/net.h eggdrop1.6.15-ssl/src/net.h
--- eggdrop1.6.15/src/net.h	1970-01-01 01:00:00.000000000 +0100
+++ eggdrop1.6.15-ssl/src/net.h	2003-05-19 16:41:57.000000000 +0200
@@ -0,0 +1,30 @@
+#ifndef _EGG_NET_H
+#define _EGG_NET_H
+#ifdef EGG_SSL_EXT
+# ifndef EGG_SSL_INCS
+#  include <openssl/ssl.h>
+#  include <openssl/err.h>
+#  include <openssl/rand.h>
+#  define EGG_SSL_INCS 1
+# endif
+#endif
+
+/* This is used by the net module to keep track of sockets and what's
+ * queued on them
+ */
+typedef struct {
+  int		 sock;
+#ifdef EGG_SSL_EXT
+  SSL *ssl;  
+#endif
+  short		 flags;
+  char		*inbuf;
+  char		*outbuf;
+  unsigned long  outbuflen;	/* Outbuf could be binary data	*/
+  unsigned long	 inbuflen;	/* Inbuf could be binary data	*/
+#ifdef USE_IPV6
+  unsigned int af;
+#endif /* USE_IPV6 */
+} sock_list;
+
+#endif				/* _EGG_NET_H */
diff -burN eggdrop1.6.15/src/patch.h eggdrop1.6.15-ssl/src/patch.h
--- eggdrop1.6.15/src/patch.h	2003-05-05 00:08:01.000000000 +0200
+++ eggdrop1.6.15-ssl/src/patch.h	2003-05-19 16:41:57.000000000 +0200
@@ -32,6 +32,9 @@
  */
 #ifndef _EGG_PATCH_H
 #define _EGG_PATCH_H
+#ifdef EGG_SSL_EXT
+patch("SSL");
+#endif
 /*
  *
  *
diff -burN eggdrop1.6.15/src/tcl.c eggdrop1.6.15-ssl/src/tcl.c
--- eggdrop1.6.15/src/tcl.c	2003-05-05 00:05:33.000000000 +0200
+++ eggdrop1.6.15-ssl/src/tcl.c	2003-05-19 16:41:57.000000000 +0200
@@ -44,6 +44,9 @@
 
 
 extern time_t online_since;
+#ifdef EGG_SSL_EXT
+extern int      use_ssl; /* kyotou */
+#endif
 
 extern char origbotname[], botuser[], motdfile[], admin[], userfile[],
             firewall[], helpdir[], notify_new[], hostname[], myip[], moddir[],
@@ -529,6 +532,9 @@
   {"enable-simul",          &enable_simul,         0}, /* compat */
   {"debug-output",          &debug_output,         0}, /* compat */
   {"use-console-r",         &use_console_r,        0}, /* compat */
+#ifdef EGG_SSL_EXT
+  {"use-ssl",			&use_ssl,		0}, /* kyotou */
+#endif
   {NULL,                    NULL,                  0}
 };
 
diff -burN eggdrop1.6.15/src/tclmisc.c eggdrop1.6.15-ssl/src/tclmisc.c
--- eggdrop1.6.15/src/tclmisc.c	2003-05-05 00:05:33.000000000 +0200
+++ eggdrop1.6.15-ssl/src/tclmisc.c	2003-05-19 16:41:57.000000000 +0200
@@ -26,7 +26,13 @@
 #include "main.h"
 #include "modules.h"
 #include "tandem.h"
+
+#ifndef EGG_SSL_EXT
 #include "md5/md5.h"
+#else
+#include "openssl/md5.h"
+#endif
+
 #ifdef TIME_WITH_SYS_TIME
 # include <sys/time.h>
 # include <time.h>
