diff -urbBN include/config.h include/config.h
--- include/config.h	Mon Feb  6 00:03:16 2006
+++ include/config.h	Wed Mar 15 21:20:23 2006
@@ -455,6 +455,9 @@
  */
 #define JOINTHROTTLE
 
+#define CODEPAGE_USE
+#define WITH_ICONV
+
 /* ------------------------- END CONFIGURATION SECTION -------------------- */
 #define MOTD MPATH
 #define RULES RPATH
diff -urbBN include/h.h include/h.h
--- include/h.h	Mon Feb  6 00:03:16 2006
+++ include/h.h	Wed Mar 15 21:21:09 2006
@@ -101,6 +101,9 @@
 extern MODVAR ConfigItem_include	*conf_include;
 extern MODVAR ConfigItem_help		*conf_help;
 extern MODVAR ConfigItem_offchans	*conf_offchans;
+#ifdef CODEPAGE_USE
+extern MODVAR ConfigItem_codepage	*conf_codepage;
+#endif
 extern int		completed_connection(aClient *);
 extern void clear_unknown();
 extern EVENT(e_unload_module_delayed);
@@ -129,6 +132,12 @@
 ConfigItem_deny_channel *Find_channel_allowed(char *name);
 ConfigItem_alias	*Find_alias(char *name);
 ConfigItem_help 	*Find_Help(char *command);
+#ifdef CODEPAGE_USE
+ConfigItem_codepage	*Find_codepage(char *name);
+#ifdef WITH_ICONV
+ConfigItem_codepage	*Find_def_codepage(void);
+#endif
+#endif
 int			AllowClient(aClient *cptr, struct hostent *hp, char *sockhost, char *username);
 int parse_netmask(const char *text, struct irc_netmask *netmask);
 int match_ip(struct IN_ADDR addr, char *uhost, char *mask, struct irc_netmask *netmask);
diff -urbBN include/msg.h include/msg.h
--- include/msg.h	Mon Feb  6 00:03:16 2006
+++ include/msg.h	Wed Mar 15 21:21:39 2006
@@ -297,6 +297,13 @@
 #define MSG_EOS		"EOS"
 #define TOK_EOS		"ES"
 
+#ifdef CODEPAGE_USE
+#define MSG_CODEPAGE 	"CODEPAGE"
+#define TOK_CODEPAGE 	"CP"
+#define MSG_CODEPAGES 	"CODEPAGES"
+#define TOK_CODEPAGES 	"CPS"
+#endif
+
 #define MAXPARA    	15
 
 extern int m_error();
diff -urbBN include/numeric.h include/numeric.h
--- include/numeric.h	Mon Feb  6 00:03:16 2006
+++ include/numeric.h	Wed Mar 15 21:21:56 2006
@@ -358,6 +358,14 @@
 
 #define RPL_WHOISSECURE      671
 
+#ifdef CODEPAGE_USE
+#define RPL_CODEPAGE         700
+#define RPL_CODEPAGES        701
+#define RPL_ENDOFCODEPAGES   702
+#define RPL_WHOISSCHEME      703
+#define RPL_STATSCODEPAGE    704
+#endif
+
 #define ERR_CANNOTDOCOMMAND 972
 #define ERR_CANNOTCHANGECHANMODE 974
 #define ERR_NUMERICERR       999
diff -urbBN include/struct.h include/struct.h
--- include/struct.h	Mon Feb  6 00:03:16 2006
+++ include/struct.h	Wed Mar 15 21:24:05 2006
@@ -123,6 +123,9 @@
 typedef struct _configitem_include ConfigItem_include;
 typedef struct _configitem_help ConfigItem_help;
 typedef struct _configitem_offchans ConfigItem_offchans;
+#ifdef CODEPAGE_USE
+typedef struct _configitem_codepage ConfigItem_codepage;
+#endif
 typedef struct liststruct ListStruct;
 
 #define CFG_TIME 0x0001
@@ -923,6 +926,9 @@
 	char info[REALLEN + 1];	/* Free form additional client information */
 	aClient *srvptr;	/* Server introducing this.  May be &me */
 	short status;		/* client type */
+#ifdef CODEPAGE_USE
+	char *codepage;		/* Codepage */
+#endif
 	/*
 	   ** The following fields are allocated only for local clients
 	   ** (directly connected to *this* server with a socket.
@@ -1169,6 +1175,9 @@
 	ConfigItem 	*prev, *next;
 	ConfigFlag 	flag;
 	char		*ip;
+#ifdef CODEPAGE_USE
+	char		*codepage;
+#endif
 	int		port;
 	int		options, clients;
 	aClient		*listener;
@@ -1323,6 +1332,21 @@
 	char *format, *parameters;
 	regex_t expr;
 };
+
+#ifdef CODEPAGE_USE
+struct _configitem_codepage {
+	ConfigItem *prev, *next;
+	ConfigFlag flag;
+#ifdef WITH_ICONV
+	short defcpage;
+#else
+	char *file;
+	char repl1[256];
+	char repl2[256];
+#endif
+	char *name;
+};
+#endif
 
 #define INCLUDE_NOTLOADED  0x1
 #define INCLUDE_REMOTE     0x2
diff -urbBN src/api-isupport.c src/api-isupport.c
--- src/api-isupport.c	Mon Feb  6 00:03:16 2006
+++ src/api-isupport.c	Wed Mar 15 21:25:35 2006
@@ -145,6 +145,9 @@
 	ircsprintf(tmpbuf, "#:%d", MAXCHANNELSPERUSER);
 	IsupportAdd(NULL, "CHANLIMIT", tmpbuf);
 	IsupportAdd(NULL, "MAXCHANNELS", my_itoa(MAXCHANNELSPERUSER));
+#ifdef CODEPAGE_USE
+	IsupportAdd(NULL, "CODEPAGES", NULL);
+#endif
 	IsupportAdd(NULL, "HCN", NULL);
 	IsupportAdd(NULL, "SAFELIST", NULL);
 	if (cmdstr)
diff -urbBN src/modules/Makefile.in src/modules/Makefile.in
--- src/modules/Makefile.in	Mon Feb  6 00:03:16 2006
+++ src/modules/Makefile.in	Wed Mar 15 22:14:32 2006
@@ -55,7 +55,7 @@
 	 m_svsfline.so m_dccdeny.so m_undccdeny.so m_whowas.so \
 	 m_connect.so m_dccallow.so m_userip.so m_nick.so m_user.so \
 	 m_mode.so m_watch.so m_part.so m_join.so m_motd.so m_opermotd.so \
-	 m_botmotd.so m_lusers.so cloak.so 
+	 m_botmotd.so m_lusers.so cloak.so m_codepage.so
 
 #note change of .c to .o
 COMMANDS=m_sethost.o m_chghost.o m_chgident.o m_setname.o m_setident.o \
@@ -77,7 +77,7 @@
 	 m_svsfline.o m_dccdeny.o m_undccdeny.o m_whowas.o \
 	 m_connect.o m_dccallow.o m_userip.o m_nick.o m_user.o \
 	 m_mode.o m_watch.o m_part.o m_join.o m_motd.o m_opermotd.o \
-	 m_botmotd.o m_lusers.o
+	 m_botmotd.o m_lusers.o m_codepage.o
 
 
 MODULES=commands.so $(R_MODULES)
@@ -399,6 +399,9 @@
 m_lusers.o: m_lusers.c $(INCLUDES)
 	$(CC) $(CFLAGS) $(MODULEFLAGS)  -c m_lusers.c
 
+m_codepage.o: m_codepage.c $(INCLUDES)
+	$(CC) $(CFLAGS) $(MODULEFLAGS)  -c m_codepage.c
+
 #############################################################################
 #             .so's section
 #############################################################################
@@ -802,6 +805,10 @@
 m_lusers.so: m_lusers.c $(INCLUDES)
 	$(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \
 	       -o m_lusers.so m_lusers.c
+
+m_codepage.so: m_codepage.c $(INCLUDES)
+	$(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \
+	       -o m_codepage.so m_codepage.c
 
 #############################################################################
 #             and now the remaining modules...
diff -urbBN src/modules/l_commands.c src/modules/l_commands.c
--- src/modules/l_commands.c	Mon Feb  6 00:03:16 2006
+++ src/modules/l_commands.c	Wed Mar 15 22:11:36 2006
@@ -122,6 +122,9 @@
 #ifdef GUEST
 extern int m_guest_Init(ModuleInfo *modinfo);
 #endif
+#ifdef CODEPAGE_USE
+extern int m_codepage_Init(ModuleInfo *modinfo);
+#endif
 
 extern int m_sethost_Load(int module_load), m_setname_Load(int module_load), m_chghost_Load(int module_load);
 extern int m_chgident_Load(int module_load), m_setident_Load(int module_load), m_sdesc_Load(int module_load);
@@ -169,6 +172,9 @@
 #ifdef GUEST
 extern int m_guest_Load(int module_load);
 #endif
+#ifdef CODEPAGE_USE
+extern int m_codepage_Load(int module_load);
+#endif
 
 extern int m_sethost_Unload(), m_setname_Unload(), m_chghost_Unload(), m_chgident_Unload();
 extern int m_setident_Unload(), m_sdesc_Unload(), m_svsmode_Unload(), m_swhois_Unload();
@@ -204,6 +210,9 @@
 #ifdef GUEST
 extern int m_guest_Unload();
 #endif
+#ifdef CODEPAGE_USE
+extern int m_codepage_Unload();
+#endif
 
 #ifdef DYNAMIC_LINKING
 DLLFUNC int Mod_Test(ModuleInfo *modinfo)
@@ -341,6 +350,9 @@
 #ifdef GUEST
 	m_guest_Init(ModCmdsInfo);
 #endif
+#ifdef CODEPAGE_USE
+	m_codepage_Init(ModCmdsInfo);
+#endif
 	MARK_AS_OFFICIAL_MODULE(modinfo);
 	return MOD_SUCCESS;
 }
@@ -452,6 +464,9 @@
 #ifdef GUEST
 	m_guest_Load(module_load);
 #endif
+#ifdef CODEPAGE_USE
+	m_codepage_Load(module_load);
+#endif
 	return MOD_SUCCESS;
 }
 
@@ -562,6 +577,9 @@
 	m_lusers_Unload();
 #ifdef GUEST
 	m_guest_Unload();
+#endif
+#ifdef CODEPAGE_USE
+	m_codepage_Unload();
 #endif
 	return MOD_SUCCESS;
 }
diff -urbBN src/modules/m_codepage.c src/modules/m_codepage.c
--- src/modules/m_codepage.c	Thu Jan  1 06:00:00 1970
+++ src/modules/m_codepage.c	Fri Sep 10 18:43:06 2004
@@ -0,0 +1,300 @@
+/*
+ *   IRC - Internet Relay Chat, src/modules/m_codepage.c
+ *   (C) 1999-2001 Carsten Munk (Techie/Stskeeps) <stskeeps@tspre.org>
+ *
+ *   See file AUTHORS in IRC package for additional names of
+ *   the programmers. 
+ *
+ *   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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#include "config.h"
+#include "struct.h"
+#include "common.h"
+#include "sys.h"
+#include "numeric.h"
+#include "msg.h"
+#include "channel.h"
+#include <time.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef _WIN32
+#include <io.h>
+#endif
+#include <fcntl.h>
+#include "h.h"
+#include "proto.h"
+#ifdef STRIPBADWORDS
+#include "badwords.h"
+#endif
+#ifdef _WIN32
+#include "version.h"
+#endif
+
+#ifdef CODEPAGE_USE
+#define MSG_CODEPAGE 	"CODEPAGE"
+#define TOK_CODEPAGE 	"CP"
+#define MSG_CODEPAGES 	"CODEPAGES"
+#define TOK_CODEPAGES 	"CPS"
+#endif
+
+DLLFUNC int m_codepage(aClient *cptr, aClient *sptr, int parc, char *parv[]);
+DLLFUNC int m_codepages(aClient *cptr, aClient *sptr, int parc, char *parv[]);
+/*DLLFUNC int codepage_config_test(ConfigFile *, ConfigEntry *, int, int *);
+DLLFUNC int codepage_config_run(ConfigFile *, ConfigEntry *, int);
+DLLFUNC int codepage_rehash();
+DLLFUNC int codepage_config_posttest(int *);
+*/
+#ifndef DYNAMIC_LINKING
+ModuleHeader m_codepage_Header
+#define Mod_Header m_codepage_Header
+#else
+ModuleHeader Mod_Header
+#endif
+  = {
+	"codepage",	/* Name of module */
+	"$Id: m_codepage.c,v 1.1.0.0 2002/12/29 14:20:45 Spider Exp $", /* Version */
+	"/codepage", /* Short description of module */
+	"3.2-b8-1",
+    };
+
+/*
+ * The purpose of these ifdefs, are that we can "static" link the ircd if we
+ * want to
+*/
+
+/*ModuleInfo CodepageModInfo;
+static Hook *HookConnect = NULL, *HookConfTest = NULL, *HookConfRun = NULL;
+static Hook *HookRehash = NULL, *HookPostConf = NULL;
+
+#ifdef DYNAMIC_LINKING
+DLLFUNC int Mod_Test(ModuleInfo *modinfo)
+#else
+int    m_codepage_Test(ModuleInfo *modinfo)
+#endif
+{
+	bcopy(modinfo,&CodepageModInfo,modinfo->size);
+	HookConfTest = HookAddEx(CodepageModInfo.handle, HOOKTYPE_CONFIGTEST, codepage_config_test);
+	HookPostConf = HookAddEx(CodepageModInfo.handle, HOOKTYPE_CONFIGPOSTTEST, codepage_config_posttest);
+	return MOD_SUCCESS;
+}
+*/
+#ifdef DYNAMIC_LINKING
+DLLFUNC int	Mod_Init(ModuleInfo *modinfo)
+#else
+int    m_codepage_Init(ModuleInfo *modinfo)
+#endif
+{
+/*	bcopy(modinfo,&CodepageModInfo,modinfo->size);
+	HookConfRun = HookAddEx(CodepageModInfo.handle, HOOKTYPE_CONFIGRUN, codepage_config_run);
+	HookRehash = HookAddEx(CodepageModInfo.handle, HOOKTYPE_REHASH, codepage_rehash);
+*/	add_Command(MSG_CODEPAGE, TOK_CODEPAGE, m_codepage, MAXPARA);
+	add_Command(MSG_CODEPAGES, TOK_CODEPAGES, m_codepages, MAXPARA);
+	return MOD_SUCCESS;
+	
+}
+#ifdef DYNAMIC_LINKING
+DLLFUNC int	Mod_Load(int module_load)
+#else
+int    m_codepage_Load(int module_load)
+#endif
+{
+	return MOD_SUCCESS;
+	
+}
+#ifdef DYNAMIC_LINKING
+DLLFUNC int	Mod_Unload(int module_unload)
+#else
+int	m_codepage_Unload(int module_unload)
+#endif
+{
+//	HookDel(HookConnect);
+/*	HookDel(HookRehash);
+	HookDel(HookConfRun);
+	HookDel(HookConfTest);
+	HookDel(HookPostConf);
+*/	if (del_Command(MSG_CODEPAGE, TOK_CODEPAGE, m_codepage) < 0)
+	{
+		sendto_realops("Failed to delete commands when unloading %s",
+				Mod_Header.name);
+	}
+	return MOD_SUCCESS;
+	
+}
+
+/* 
+ * m_codepage - 12/29/2002 - ECTb
+ * :prefix CODEPAGE <new codepage>
+ * parv[0] - sender
+ * parv[1] - codepage
+ *
+*/
+
+DLLFUNC int m_codepage(aClient *cptr, aClient *sptr, int parc, char *parv[])
+{
+	if (!MyClient(sptr)) {
+		aClient *acptr;
+
+		if (parc < 3)
+			return 0;	
+		acptr = find_person(parv[1], (aClient *)NULL);
+        	if (!acptr)
+                	return 0;
+		if (Find_codepage(parv[2])) {
+			if (!acptr->codepage)
+				acptr->codepage=strdup(parv[2]);
+			else
+				strcpy(acptr->codepage, parv[2]);
+		}
+		return 0;
+	}
+#ifndef CODEPAGE_USE
+	if (MyClient(sptr))
+	{
+		sendto_one(sptr, ":%s NOTICE %s :*** The /codepage command is disabled on this server", me.name, sptr->name);
+		return 0;
+	}
+#endif
+
+	if (parc < 2)
+	{
+		sendto_one(sptr,
+		    ":%s NOTICE %s :*** /codepage syntax is /codepage <new_codepage>",
+		    me.name, sptr->name);
+		return 0;
+	}
+
+	if (strlen(parv[1]) < 1)
+	{
+		sendto_one(sptr,
+		    ":%s NOTICE %s :*** Write atleast something to change the codepage to!",
+		    me.name, sptr->name);
+		return 0;
+	}
+
+	if (strlen(parv[1]) > 16)
+	{
+		sendto_one(sptr,
+		    ":%s NOTICE %s :*** Codepage Error: Too long codepage!!",
+		    me.name, sptr->name);
+		return 0;
+	}
+
+	if (Find_codepage(parv[1]))
+	{
+		sptr->codepage = strdup(parv[1]);
+		sendto_one(sptr, rpl_str(RPL_CODEPAGE), me.name, parv[0], sptr->codepage);
+		sendto_serv_butone_token(cptr, sptr->name,
+				MSG_CODEPAGE, TOK_CODEPAGE, "%s :%s", sptr->name, sptr->codepage);
+		return 0;
+	}
+	else
+	{
+		sendto_one(sptr,
+		    ":%s NOTICE %s :*** /Codepage Error: Codepage not found",
+		    me.name, parv[0]);
+		return 0;
+	}
+
+	return 0;
+}
+
+
+/* 
+ * m_codepages - 2/09/2003 - ECTb
+ * :prefix CODEPAGES
+ * parv[0] - sender
+ *
+*/
+
+DLLFUNC int m_codepages(aClient *cptr, aClient *sptr, int parc, char *parv[])
+{
+	ConfigItem_codepage *cpage = NULL;
+	for (cpage = conf_codepage; cpage; cpage = (ConfigItem_codepage *)cpage->next) {
+#ifdef WITH_ICONV
+		sendto_one(sptr, rpl_str(RPL_CODEPAGES), me.name, parv[0], cpage->name, cpage->defcpage?" default":"");
+#else
+		sendto_one(sptr, rpl_str(RPL_CODEPAGES), me.name, parv[0], cpage->name, cpage->file);
+#endif
+		
+	}
+	sendto_one(sptr, rpl_str(RPL_ENDOFCODEPAGES), me.name, parv[0]);
+    return 0;
+}
+
+
+/*------------------------------------------------------------------------------------
+
+DLLFUNC int codepage_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
+{
+int errors = 0;
+
+	if (type != CONFIG_SET)
+		return 0;
+
+	if (!strcmp(ce->ce_varname, "bopm-nick"))
+	{
+		if (!ce->ce_vardata)
+		{
+			config_error("%s:%i: set::codepage has no value", ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
+			errors++;
+		}
+		bopmnick_present = 1;
+		*errs = errors;
+		return errors ? -1 : 1;
+	}
+	else
+		return 0;
+}
+
+DLLFUNC int codepage_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
+{
+	if (type != CONFIG_SET)
+		return 0;
+
+	if (!strcmp(ce->ce_varname, "bopm-nick"))
+	{
+		if (bopmnick)
+			free(bopmnick);
+		bopmnick = strdup(ce->ce_vardata);
+		return 1;
+	}
+	else
+		return 0;
+}
+
+DLLFUNC int codepage_config_posttest(int *errs)
+{
+int errors = 0;
+	if (!bopmnick_present)
+	{
+		config_error("set::bopm-nick missing");
+		errors++;
+	}
+	*errs = errors;
+	return errors ? -1 : 1;
+}
+
+DLLFUNC int codepage_rehash()
+{
+	if (bopmnick) {
+		free(bopmnick);
+		bopmnick = NULL;
+		bopmnick_present = 0;
+	}
+	return 1;
+}
+*/
diff -urbBN src/modules/m_nick.c src/modules/m_nick.c
--- src/modules/m_nick.c	Mon Feb  6 00:03:17 2006
+++ src/modules/m_nick.c	Wed Mar 15 21:51:27 2006
@@ -811,6 +811,9 @@
 int _register_user(aClient *cptr, aClient *sptr, char *nick, char *username, char *umode, char *virthost, char *ip)
 {
 	ConfigItem_ban *bconf;
+#ifdef CODEPAGE_USE
+	ConfigItem_listen *plisten;
+#endif
 	char *parv[3], *tmpstr;
 #ifdef HOSTILENAME
 	char stripuser[USERLEN + 1], *u1 = stripuser, *u2, olduser[USERLEN + 1],
@@ -842,6 +845,21 @@
 	
 	if (MyConnect(sptr))
 	{
+#ifdef CODEPAGE_USE
+		plisten = Find_listen("*",cptr->listener->port);
+		if (plisten)
+		{
+			cptr->codepage = strdup(plisten->codepage);
+			sendto_one(cptr, ":%s NOTICE AUTH :*** You connected on %d port. Using %s translation scheme as default.", me.name, cptr->listener->port, cptr->codepage);
+		}
+		else
+		{
+#ifdef WITH_ICONV
+			cptr->codepage = strdup(Find_def_codepage()->name);
+#endif
+			sendto_one(cptr, ":%s NOTICE AUTH :*** You connected on %d port. Translation scheme not specified for this port.", me.name, cptr->listener->port);
+		}
+#endif	
 		if ((i = check_client(sptr, username))) {
 			/* This had return i; before -McSkaf */
 			if (i == -5)
@@ -1151,6 +1169,18 @@
 	    user->server, user->servicestamp, sptr->info,
 	    (!buf || *buf == '\0' ? "+" : buf),
 	    sptr->umodes & UMODE_SETHOST ? sptr->user->virthost : NULL);
+
+#ifdef CODEPAGE_USE
+	if (MyConnect(sptr))
+	{
+		if (sptr->codepage)
+		{
+			sendto_one(sptr, rpl_str(RPL_CODEPAGE), sptr->name, parv[0], sptr->codepage);
+			sendto_serv_butone_token(sptr, sptr->name,
+				MSG_CODEPAGE, TOK_CODEPAGE, "%s :%s", sptr->name, sptr->codepage);
+		}
+	}
+#endif
 
 	/* Send password from sptr->passwd to NickServ for identification,
 	 * if passwd given and if NickServ is online.
diff -urbBN src/modules/m_server.c src/modules/m_server.c
--- src/modules/m_server.c	Mon Feb  6 00:03:17 2006
+++ src/modules/m_server.c	Wed Mar 15 21:52:20 2006
@@ -881,6 +881,15 @@
 					    MSG_SWHOIS), acptr->name,
 					    acptr->user->swhois);
 
+#ifdef CODEPAGE_USE
+ 			if (acptr->codepage)
+ 				if (*acptr->codepage != '\0')
+ 					sendto_one(cptr, "%s %s :%s",
+ 					    (IsToken(cptr) ? TOK_CODEPAGE :
+ 					    MSG_CODEPAGE), acptr->name,
+ 					    acptr->codepage);
+#endif
+
 			if (!SupportSJOIN(cptr))
 				send_user_joins(cptr, acptr);
 		}
diff -urbBN src/modules/m_stats.c src/modules/m_stats.c
--- src/modules/m_stats.c	Mon Feb  6 00:03:17 2006
+++ src/modules/m_stats.c	Wed Mar 15 21:54:36 2006
@@ -119,6 +119,9 @@
 int stats_zip(aClient *, char *);
 int stats_officialchannels(aClient *, char *);
 int stats_spamfilter(aClient *, char *);
+#ifdef CODEPAGE_USE
+int stats_codepages(aClient *, char *);
+#endif
 
 #define SERVER_AS_PARA 0x1
 #define FLAGS_AS_PARA 0x2
@@ -168,6 +171,9 @@
 	{ 'm', "command",	stats_command,		0 		},
 	{ 'n', "banrealname",	stats_banrealname,	0 		},
 	{ 'o', "oper",		stats_oper,		0 		},
+#ifdef CODEPAGE_USE
+	{ 'p', "codepages",	stats_codepages,	0 		},
+#endif
 	{ 'q', "bannick",	stats_bannick,		FLAGS_AS_PARA	},
 	{ 'r', "chanrestrict",	stats_chanrestrict,	0 		},
 	{ 's', "shun",		stats_shun,		FLAGS_AS_PARA	},
@@ -275,6 +281,10 @@
 		"O - oper - Send the oper block list");
 	sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name,
 		"P - port - Send information about ports");
+#ifdef CODEPAGE_USE
+	sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name,
+		"p - codepages - Send information about codepages");
+#endif
 	sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name,
 		"q - bannick - Send the ban nick block list");
 	sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name,
@@ -680,12 +690,23 @@
 			continue;
 	  	if (!IsListening(acptr))
 	  		continue;
+#ifdef CODEPAGE_USE
 	  	sendto_one(sptr, ":%s %s %s :*** Listener on %s:%i, clients %i. is %s %s",
+#else
+		sendto_one(sptr, ":%s %s %s :*** Listener on %s:%i, clients %i. is %s %s %s",
+#endif
 	  		me.name, IsWebTV(sptr) ? "PRIVMSG" : "NOTICE", sptr->name,
 	  		((ConfigItem_listen *)acptr->class)->ip,
 			((ConfigItem_listen *)acptr->class)->port,
 			((ConfigItem_listen *)acptr->class)->clients,
 			((ConfigItem_listen *)acptr->class)->flag.temporary ? "TEMPORARY" : "PERM",
+#ifdef CODEPAGE_USE
+#ifdef WITH_ICONV
+			((ConfigItem_listen *)acptr->class)->codepage ? ((ConfigItem_listen *)acptr->class)->codepage : (conf_codepage->defcpage?Find_def_codepage()->name:"CP1251"),
+#else
+			((ConfigItem_listen *)acptr->class)->codepage ? ((ConfigItem_listen *)acptr->class)->codepage : "CP1251",
+#endif
+#endif
 			stats_port_helper(acptr));
 	}
 	return 0;
@@ -1635,3 +1656,18 @@
 #endif
 	return 0;
 }
+
+#ifdef CODEPAGE_USE
+int stats_codepages(aClient *sptr, char *para)
+{
+	ConfigItem_codepage *x;
+	for (x = conf_codepage; x; x = (ConfigItem_codepage *)x->next)
+		sendto_one(sptr, ":%s %i %s :%s %s",
+#ifdef WITH_ICONV
+			me.name, RPL_TEXT, sptr->name, x->name, x->defcpage ? " default" : "");
+#else
+			me.name, RPL_TEXT, sptr->name, x->name, x->file);
+#endif
+	return 0;
+}
+#endif
diff -urbBN src/modules/m_whois.c src/modules/m_whois.c
--- src/modules/m_whois.c	Mon Feb  6 00:03:18 2006
+++ src/modules/m_whois.c	Wed Mar 15 21:55:08 2006
@@ -334,6 +334,15 @@
 				sendto_one(sptr, rpl_str(RPL_WHOISIDLE),
 				    me.name, parv[0], name,
 				    TStime() - acptr->last, acptr->firsttime);
+#ifdef CODEPAGE_USE
+	    	sendto_one(sptr, rpl_str(RPL_WHOISSCHEME), 
+			    me.name, parv[0], name,
+#ifdef WITH_ICONV
+			    acptr->codepage ? acptr->codepage : Find_def_codepage()->name);
+#else
+			    acptr->codepage ? acptr->codepage : "CP1251");
+#endif
+#endif
 		}
 		if (!found)
 			sendto_one(sptr, err_str(ERR_NOSUCHNICK),
diff -urbBN src/s_bsd.c src/s_bsd.c
--- src/s_bsd.c	Fri Feb  3 19:57:20 2006
+++ src/s_bsd.c	Wed Mar 15 21:56:48 2006
@@ -68,6 +68,9 @@
 #endif
 #include "sock.h"		/* If FD_ZERO isn't define up to this point,  */
 #include <string.h>
+#if defined(CODEPAGE_USE) && defined(WITH_ICONV)
+#include <iconv.h>
+#endif
 #include "proto.h"
 			/* define it (BSD4.2 needs this) */
 #include "h.h"
@@ -1394,6 +1397,58 @@
 		SetAccess(acptr);
 }
 
+#ifdef CODEPAGE_USE
+/*
+ *  decoding codepage...
+ */
+#ifndef WITH_ICONV
+int dech_codepage(char *codepage, int *lengths) {
+	ConfigItem_codepage *cpage = NULL;
+	int i = 0;
+//	static char new_str[8192];
+	cpage = Find_codepage(codepage);
+	if (!cpage) {return 0;}
+	for (i=0;i<*lengths;i++) {
+		readbuf[i] = cpage->repl2[readbuf[i]];
+	}
+	readbuf[*lengths]=0;
+	return 1;
+}
+#else
+int dech_codepage(char *codepage, int *length) {
+    char buf[READBUF_SIZE], *buf1=&buf[0], *msg = readbuf;
+    int insize, outsize, r;
+    iconv_t cd;
+    ConfigItem_codepage *cp = Find_def_codepage();
+
+    if (!codepage || !cp) return 0;
+
+    if (!stricmp(codepage, cp->name)) { return 0; }
+
+    cd = iconv_open (cp->name, codepage);
+    if (cd == (iconv_t)(-1)) return 0;
+
+    insize = *length;
+    outsize = READBUF_SIZE;
+
+    /* perfome convert */
+    r = iconv (cd, &msg, &insize, &buf1, &outsize);
+    if (r < 0 || insize != 0) {
+          iconv_close (cd);
+          return 0;
+    }
+
+    /* calculate size of output string */   
+    *length = READBUF_SIZE - outsize;
+
+    memcpy (readbuf, buf, *length);
+    readbuf[*length]='\0';
+
+    iconv_close (cd);
+}
+#endif
+#endif
+
 /*
 ** read_packet
 **
@@ -1418,6 +1473,11 @@
 		else
 #endif
 			length = recv(cptr->fd, readbuf, sizeof(readbuf), 0);
+
+#ifdef CODEPAGE_USE
+		if (!IsServer(cptr)) dech_codepage(cptr->codepage,&length);
+#endif
+
 		cptr->lasttime = now;
 		if (cptr->lasttime > cptr->since)
 			cptr->since = cptr->lasttime;
diff -urbBN src/s_conf.c src/s_conf.c
--- src/s_conf.c	Fri Feb  3 19:57:20 2006
+++ src/s_conf.c	Wed Mar 15 22:06:25 2006
@@ -108,6 +108,9 @@
 static int	_conf_help		(ConfigFile *conf, ConfigEntry *ce);
 static int	_conf_offchans		(ConfigFile *conf, ConfigEntry *ce);
 static int	_conf_spamfilter	(ConfigFile *conf, ConfigEntry *ce);
+#ifdef CODEPAGE_USE
+static int	_conf_codepage		(ConfigFile *conf, ConfigEntry *ce);
+#endif
 
 /* 
  * Validation commands 
@@ -140,6 +143,9 @@
 static int	_test_help		(ConfigFile *conf, ConfigEntry *ce);
 static int	_test_offchans		(ConfigFile *conf, ConfigEntry *ce);
 static int	_test_spamfilter	(ConfigFile *conf, ConfigEntry *ce);
+#ifdef CODEPAGE_USE
+static int	_test_codepage		(ConfigFile *conf, ConfigEntry *ce);
+#endif
  
 /* This MUST be alphabetized */
 static ConfigCommand _ConfigCommands[] = {
@@ -151,6 +157,9 @@
 #endif
 	{ "ban", 		_conf_ban,		_test_ban	},
 	{ "class", 		_conf_class,		_test_class	},
+#ifdef CODEPAGE_USE
+	{ "codepage", 		_conf_codepage,		_test_codepage	},
+#endif
 	{ "deny",		_conf_deny,		_test_deny	},
 	{ "drpass",		_conf_drpass,		_test_drpass	},
 	{ "except",		_conf_except,		_test_except	},
@@ -372,6 +381,9 @@
 ConfigItem_alias	*conf_alias = NULL;
 ConfigItem_include	*conf_include = NULL;
 ConfigItem_help		*conf_help = NULL;
+#ifdef CODEPAGE_USE
+ConfigItem_codepage	*conf_codepage = NULL;
+#endif
 #ifdef STRIPBADWORDS
 ConfigItem_badword	*conf_badword_channel = NULL;
 ConfigItem_badword      *conf_badword_message = NULL;
@@ -1765,6 +1777,9 @@
 	ConfigItem_alias		*alias_ptr;
 	ConfigItem_help			*help_ptr;
 	ConfigItem_offchans		*of_ptr;
+#ifdef CODEPAGE_USE
+	ConfigItem_codepage		*codepage_ptr;
+#endif
 	OperStat 			*os_ptr;
 	ListStruct 	*next, *next2;
 	aTKline *tk, *tk_next;
@@ -2079,6 +2094,19 @@
 		DelListItem(alias_ptr, conf_alias);
 		MyFree(alias_ptr);
 	}
+#ifdef CODEPAGE_USE
+	for (codepage_ptr = conf_codepage; codepage_ptr; codepage_ptr = (ConfigItem_codepage *)next)
+	{
+		next = (ListStruct *)codepage_ptr->next;	 
+#ifndef WITH_ICONV
+		ircfree(codepage_ptr->file);
+#endif
+//		ircfree(codepage_ptr->defcpage);
+		ircfree(codepage_ptr->name);
+		DelListItem(codepage_ptr, conf_codepage);
+		MyFree(codepage_ptr);		
+	}
+#endif
 	for (help_ptr = conf_help; help_ptr; help_ptr = (ConfigItem_help *)next) {
 		aMotd *text;
 		next = (ListStruct *)help_ptr->next;
@@ -2124,6 +2152,9 @@
 int	config_post_test()
 {
 #define Error(x) { config_error((x)); errors++; }
+#ifdef CODEPAGE_USE
+	ConfigItem_listen	*p = NULL;
+#endif
 	int 	errors = 0;
 	Hook *h;
 	
@@ -2359,6 +2390,46 @@
 	return NULL;
 }
 
+#ifdef CODEPAGE_USE
+#ifndef WITH_ICONV
+ConfigItem_codepage	*Find_codepage(char *name) {
+	ConfigItem_codepage *codepage;
+
+	if (!name)
+		return NULL;
+
+	for (codepage = conf_codepage; codepage; codepage = (ConfigItem_codepage *)codepage->next) {
+		if (!stricmp(codepage->name, name))
+			return codepage;
+	}
+	return NULL;
+}
+#else
+ConfigItem_codepage	*Find_codepage(char *name) {
+	ConfigItem_codepage *codepage;
+
+	if (!name)
+		return NULL;
+
+	for (codepage = conf_codepage; codepage; codepage = (ConfigItem_codepage *)codepage->next) {
+		if (!stricmp(codepage->name, name))
+			return codepage;
+	}
+	return NULL;
+}
+
+ConfigItem_codepage	*Find_def_codepage(void) {
+	ConfigItem_codepage *codepage;
+
+	for (codepage = conf_codepage; codepage; codepage = (ConfigItem_codepage *)codepage->next) {
+		if (codepage->defcpage)
+			return codepage;
+	}
+	return NULL;
+}
+#endif
+#endif
+
 ConfigItem_class	*Find_class(char *name)
 {
 	ConfigItem_class	*p;
@@ -3995,6 +4066,9 @@
 	char	    copy[256];
 	char	    *ip;
 	char	    *port;
+#ifdef CODEPAGE_USE
+	char        *tempcodepage;
+#endif
 	int	    start, end, iport, isnew;
 	int tmpflags =0;
 
@@ -4029,6 +4103,12 @@
 					tmpflags |= ofp->flag;
 			}
 		}
+#ifdef CODEPAGE_USE
+		if (!strcmp(cep->ce_varname, "codepage"))
+		{
+			tempcodepage = strdup(cep->ce_vardata);
+		}
+#endif
 	}
 #ifndef USE_SSL
 	tmpflags &= ~LISTENER_SSL;
@@ -4048,6 +4128,14 @@
 			tmpflags |= LISTENER_BOUND;
 
 		listen->options = tmpflags;
+#ifdef CODEPAGE_USE
+#ifndef WITH_ICONV
+		if (!tempcodepage) listen->codepage = strdup("CP1251");
+#else
+		if (!tempcodepage) listen->codepage = strdup(Find_def_codepage()->name);
+#endif
+		else listen->codepage = strdup(tempcodepage);
+#endif
 		if (isnew)
 			AddListItem(listen, conf_listen);
 		listen->flag.temporary = 0;
@@ -4180,6 +4268,11 @@
 #endif
 			}
 		}
+#ifdef CODEPAGE_USE
+		else if (!strcmp(cep->ce_varname, "codepage")) {
+			//do nothing
+		}
+#endif
 		else
 		{
 			config_error_unknown(cep->ce_fileptr->cf_filename, cep->ce_varlinenum,
@@ -7653,6 +7746,191 @@
 	return errors;
 }
 
++#ifdef CODEPAGE_USE
+#ifdef WITH_ICONV
+int	_conf_codepage(ConfigFile *conf, ConfigEntry *ce)
+{
+	ConfigEntry *cep,*cepp;
+	ConfigItem_codepage *cp;
+	char *defcp;
+
+	cep = config_find_entry(ce->ce_entries, "default");
+	defcp = strdup(cep->ce_vardata);
+	cep = config_find_entry(ce->ce_entries, "codepages");	
+	for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next)
+	{
+		cp = MyMallocEx(sizeof(ConfigItem_codepage));
+		ircstrdup(cp->name, cepp->ce_varname);
+		if (!stricmp(cepp->ce_varname,defcp)) { cp->defcpage = 1; }
+		else cp->defcpage = 0;
+		AddListItem(cp, conf_codepage);
+	}
+	config_status("default codepage = %s",defcp);
+	ircfree(defcp);
+	return 1;
+}
+
+int	_test_codepage(ConfigFile *conf, ConfigEntry *ce)
+{
+	ConfigEntry	*cep, *cepp;
+	char *defcp;
+	short find=0;
+
+	if (!(cep = config_find_entry(ce->ce_entries, "default")))
+	{
+		config_status("%s:%i: codepage::default: no dafult codepage given",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
+		return -1;
+	}
+	defcp = strdup(cep->ce_vardata);
+	if ((cep = config_find_entry(ce->ce_entries, "codepages")))
+	{	
+		for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next)
+		{
+			if (!cepp->ce_varname)
+			{
+				config_error("%s:%i: codepage::codepages: item without variable name",
+						cepp->ce_fileptr->cf_filename, cepp->ce_varlinenum);
+					continue;
+			}
+			if (!find && (stricmp(cepp->ce_varname,defcp)==0)) find=1;
+		}
+	} 
+	else 
+	{
+		config_status("%s:%i: codepage::codepages: no allowed codepages given",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
+		ircfree(defcp);
+		return -1;
+	}
+	ircfree(defcp);
+	return 0;
+}
+#else
+int	_conf_codepage(ConfigFile *conf, ConfigEntry *ce)
+{
+#ifdef GLOBH
+	glob_t files;
+	int i;
+#elif defined(_WIN32)
+	HANDLE hFind;
+	WIN32_FIND_DATA FindData;
+	char cPath[MAX_PATH], *cSlash = NULL, *path;
+#endif
+
+	if (!ce->ce_vardata)
+	{
+		config_status("%s:%i: codepage: no filename given",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum);
+		return -1;
+	}
+#if !defined(_WIN32) && !defined(_AMIGA) && DEFAULT_PERMISSIONS != 0
+	chmod(ce->ce_vardata, DEFAULT_PERMISSIONS);
+#endif
+#ifdef GLOBH
+#if defined(__OpenBSD__) && defined(GLOB_LIMIT)
+	glob(ce->ce_vardata, GLOB_NOSORT|GLOB_NOCHECK|GLOB_LIMIT, NULL, &files);
+#else
+	glob(ce->ce_vardata, GLOB_NOSORT|GLOB_NOCHECK, NULL, &files);
+#endif
+	if (!files.gl_pathc) {
+		globfree(&files);
+		config_status("%s:%i: codepage %s: invalid file given",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum,
+			ce->ce_vardata);
+		return -1;
+	}	
+	for (i = 0; i < files.gl_pathc; i++) {
+		_conf_codepage_load(files.gl_pathv[i],ce);
+	}
+	globfree(&files);
+#elif defined(_WIN32)
+	bzero(cPath,MAX_PATH);
+	if (strchr(ce->ce_vardata, '/') || strchr(ce->ce_vardata, '\\')) {
+		strncpyzt(cPath,ce->ce_vardata,MAX_PATH);
+		cSlash=cPath+strlen(cPath);
+		while(*cSlash != '\\' && *cSlash != '/' && cSlash > cPath)
+			cSlash--; 
+		*(cSlash+1)=0;
+	}
+	hFind = FindFirstFile(ce->ce_vardata, &FindData);
+	if (!FindData.cFileName) {
+		config_status("%s:%i: codepage %s: invalid file given",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum,
+			ce->ce_vardata);
+		FindClose(hFind);
+		return -1;
+	}
+	do {
+		if (cPath) {
+			path = MyMalloc(strlen(cPath) + strlen(FindData.cFileName)+1);
+			strcpy(path,cPath);
+			strcat(path,FindData.cFileName);
+			_conf_codepage_load(path,ce);
+			free(path);
+		}
+		else
+			_conf_codepage_load(FindData.cFileName,ce);
+	
+	} while (FindNextFile(hFind, &FindData) != 0);
+	FindClose(hFind);
+	//if (ret < 0) return ret;
+#else
+	return 1;//(load_conf(ce->ce_vardata));
+#endif
+	return 1;
+}
+
+int _conf_codepage_load (char *filename,ConfigEntry *ce)
+{
+	ConfigItem_codepage *cpage = NULL;
+	int	fds;
+	int	ret1,ret2,ret3;
+	char	line1[256],line2[256],line3[256];
+#ifndef _WIN32
+	fds = open(filename, O_RDONLY);
+#else
+	fds = open(filename, O_RDONLY|O_BINARY);
+#endif
+	if (fds < 0) {
+		config_status("%s:%i: codepage %s: can not open file %s",
+			ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_vardata, filename);
+		return -1;
+	}
+	else
+	{
+		cpage = MyMallocEx(sizeof(ConfigItem_codepage));
+		ret1 = read(fds,cpage->repl1,256);
+		ret2 = read(fds,cpage->repl2,256);
+		ret3 = read(fds,line1,256);
+		if (ret1 < 256 || ret2 < 256 || ret3 < 2 || ret3 > 16)
+		{
+			config_status("%s:%i: codepage %s: file %s corrupted",
+				ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_vardata, filename);
+		}
+		else
+		{
+			line1[ret3] = 0;
+			ircstrdup(cpage->name,line1);
+			ircstrdup(cpage->file,filename);
+			AddListItem(cpage, conf_codepage);
+			/*config_status("%s:%i: codepage %s: %s %s",
+				ce->ce_fileptr->cf_filename, ce->ce_varlinenum, ce->ce_vardata, filename,
+				line1);*/
+		}
+	
+	}
+	close(fds);
+	return 1;
+}
+
+int	_test_codepage(ConfigFile *conf, ConfigEntry *ce)
+{
+	return 0;
+}
+#endif
+#endif
+
 int	_conf_loadmodule(ConfigFile *conf, ConfigEntry *ce)
 {
 #ifdef GLOBH
@@ -8793,6 +9071,9 @@
 		if (listen_ptr->flag.temporary && !listen_ptr->clients)
 		{
 			ircfree(listen_ptr->ip);
+#ifdef CODEPAGE_USE
+			ircfree(listen_ptr->codepage);
+#endif
 			DelListItem(listen_ptr, conf_listen);
 			MyFree(listen_ptr);
 			i++;
diff -urbBN src/s_err.c src/s_err.c
--- src/s_err.c	Fri Feb  3 19:57:20 2006
+++ src/s_err.c	Wed Mar 15 22:07:06 2006
@@ -756,11 +756,19 @@
 /* 697 */ NULL,
 /* 698 */ NULL,
 /* 699 */ NULL,
+#ifdef CODEPAGE_USE
+/* 700 RPL_CODEPAGE */	":%s 700 %s %s :is now your translation scheme",
+/* 701 RPL_CODEPAGES */	":%s 701 %s :%s%s",
+/* 702 RPL_ENDOFCODEPAGES */ ":%s 702 %s :End of /CODEPAGES list",
+/* 703 RPL_WHOISSCHEME */	":%s 703 %s %s %s :translation scheme",
+/* 704 RPL_STATSCODEPAGE */	":%s 704 %s j %s %d :%s",
+#else
 /* 700 */ NULL,
 /* 701 */ NULL,
 /* 702 */ NULL,
 /* 703 */ NULL,
 /* 704 */ NULL,
+#endif
 /* 705 */ NULL,
 /* 706 */ NULL,
 /* 707 */ NULL,
diff -urbBN src/send.c src/send.c
--- src/send.c	Fri Feb  3 19:57:21 2006
+++ src/send.c	Wed Mar 15 22:09:00 2006
@@ -39,6 +39,9 @@
 #include <io.h>
 #endif
 #include <string.h>
+#ifdef CODEPAGE_USE
+#include <iconv.h>
+#endif
 
 void vsendto_one(aClient *to, char *pattern, va_list vl);
 void sendbufto_one(aClient *to, char *msg, unsigned int quick);
@@ -227,6 +230,63 @@
 	return (IsDead(to)) ? -1 : 0;
 }
 
++#ifdef CODEPAGE_USE
+/*
+ *  encoding codepage...
+ */
+#ifdef WITH_ICONV
+char *ch_codepage(char *codepage,char *text) {    
+    static char buf[2048];
+    char *msghold = text, *holder=&buf;
+    int outsize, r, len = strlen(text);
+    iconv_t cd;
+    ConfigItem_codepage *cp = Find_def_codepage();
+
+    if (!codepage || !cp) { return text; }
+
+    if (!stricmp(codepage, cp->name)) { return text; }
+
+    cd = iconv_open (codepage, cp->name);
+    if (cd == (iconv_t)(-1)) { return text; }
+
+    outsize = 2048;
+    
+    /* perfome convert */
+    r = iconv (cd, &msghold, &len, &holder, &outsize);
+    if (r < 0 || len != 0) {
+          iconv_close (cd);
+          return text;
+    }
+
+    /* calculate size of output string */
+    len = 2048 - outsize;
+    buf[len] = 0;
+
+//    strcpy(text,buf);
+    iconv_close (cd);
+    return buf;
+}
+#else
+char *ch_codepage(char *codepage,char *text) {
+	ConfigItem_codepage *cpage = NULL;
+	int i = 0, len = strlen(text);
+	static char new_str[4096];
+	char *holder=text;
+	cpage = Find_codepage(codepage);
+	if (!cpage) {return text;}
+	while (len > 0) {
+		new_str[i] = cpage->repl1[*text];
+		i++;
+		len--;
+		text++;
+	}
+	new_str[i] = 0;
+//	strcpy(holder,new_str);
+	return new_str;
+}
+#endif
+#endif
+
 /*
  *  send message to single client
  */
@@ -259,6 +319,9 @@
 void sendbufto_one(aClient *to, char *msg, unsigned int quick)
 {
 	int  len;
+#ifdef CODEPAGE_USE
+	char *holder=msg;
+#endif
 	
 	Debug((DEBUG_ERROR, "Sending [%s] to %s", msg, to->name));
 
@@ -278,6 +341,10 @@
 		    to->fd));
 		return;
 	}
+
+#ifdef CODEPAGE_USE
+	if (!IsServer(to)) msg=ch_codepage(to->codepage,msg);
+#endif
 
 	if (!quick)
 	{
diff -urbBN wircd.def wircd.def
--- wircd.def	Fri Feb  3 19:57:17 2006
+++ wircd.def	Wed Mar 15 22:09:39 2006
@@ -919,3 +919,6 @@
 	whowas_next
 	write_pidfile
 	zlinebuf
+	conf_codepage
+	Find_def_codepage
+	Find_codepage
