Index: Unreal3.2.orig/include/h.h
===================================================================
--- Unreal3.2.orig.orig/include/h.h
+++ Unreal3.2.orig/include/h.h
@@ -29,6 +29,9 @@
 #ifndef NO_FDLIST
 #include "fdlist.h"
 #endif
+
+#include "splaytree.h"
+
 extern MODVAR char *extraflags;
 extern MODVAR int tainted;
 /* for the new s_err.c */
@@ -500,8 +503,8 @@ char	*Inet_ia2pNB(struct IN_ADDR *ia, in
 /*
  * CommandHash -Stskeeps
 */
-extern MODVAR aCommand *CommandHash[256];
-extern MODVAR aCommand *TokenHash[256];
+extern MODVAR SplayTree *CommandTree;
+extern MODVAR SplayTree *TokenTree;
 extern void	init_CommandHash(void);
 extern aCommand	*add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags);
 extern void	add_Command(char *cmd, char *token, int (*func)(), unsigned char parameters);
Index: Unreal3.2.orig/src/api-command.c
===================================================================
--- Unreal3.2.orig.orig/src/api-command.c
+++ Unreal3.2.orig/src/api-command.c
@@ -30,16 +30,12 @@ int CommandExists(char *name)
 {
 	aCommand *p;
 	
-	for (p = CommandHash[toupper(*name)]; p; p = p->next)
-	{
-		if (!stricmp(p->cmd, name))
-			return 1;
-	}
-	for (p = TokenHash[*name]; p; p = p->next)
-	{
-		if (!strcmp(p->cmd, name))
-			return 1;
-	}
+	if ((p = splaytree_retrieve(CommandTree, name)) != NULL)
+		return 1;
+
+	if ((p = splaytree_retrieve(TokenTree, name)) != NULL)
+		return 1;
+
 	return 0;
 }
 
@@ -52,6 +48,7 @@ Command *CommandAdd(Module *module, char
 			module->errorcode = MODERR_EXISTS;
 		return NULL;
 	}
+
 	command = MyMallocEx(sizeof(Command));
 	command->cmd = add_Command_backend(cmd,func,params, 0, flags);
 	command->tok = NULL;
@@ -122,9 +119,10 @@ void CommandDel(Command *command) {
 		else
 			cmdstr = tmp;
 	}
-	DelListItem(command->cmd, CommandHash[toupper(*command->cmd->cmd)]);
+
+	splaytree_delete(CommandTree, command->cmd->cmd);
 	if (command->tok)
-		DelListItem(command->tok, TokenHash[*command->tok->cmd]);
+		splaytree_delete(TokenTree, command->tok->cmd);
 	if (command->cmd->owner) {
 		ModuleObject *cmdobj;
 		for (cmdobj = command->cmd->owner->objects; cmdobj; cmdobj = (ModuleObject *)cmdobj->next) {
Index: Unreal3.2.orig/src/modules.c
===================================================================
--- Unreal3.2.orig.orig/src/modules.c
+++ Unreal3.2.orig/src/modules.c
@@ -1094,7 +1094,9 @@ int  m_module(aClient *cptr, aClient *sp
 	p = tmp;
 	for (i=0; i < 256; i++)
 	{
-		for (mptr = CommandHash[i]; mptr; mptr = mptr->next)
+		SplayTreeIter iter;
+
+		SPLAYTREE_FOREACH(mptr, &iter, CommandTree)
 			if (mptr->overriders)
 			{
 				sprintf(p, "%s ", mptr->cmd);
Index: Unreal3.2.orig/src/modules/m_stats.c
===================================================================
--- Unreal3.2.orig.orig/src/modules/m_stats.c
+++ Unreal3.2.orig/src/modules/m_stats.c
@@ -604,9 +604,10 @@ int stats_command(aClient *sptr, char *p
 {
 	int i;
 	aCommand *mptr;
-	for (i = 0; i < 256; i++)
-		for (mptr = CommandHash[i]; mptr; mptr = mptr->next)
-			if (mptr->count)
+	SplayTreeIter iter;
+
+	SPLAYTREE_FOREACH(mptr, &iter, CommandTree)
+		if (mptr->count)
 #ifndef DEBUGMODE
 			sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
 				me.name, sptr->name, mptr->cmd,
@@ -618,9 +619,9 @@ int stats_command(aClient *sptr, char *p
 				mptr->lticks, mptr->lticks / CLOCKS_PER_SEC,
 				mptr->rticks, mptr->rticks / CLOCKS_PER_SEC);
 #endif
-	for (i = 0; i < 256; i++)
-		for (mptr = TokenHash[i]; mptr; mptr = mptr->next)
-			if (mptr->count)
+
+	SPLAYTREE_FOREACH(mptr, &iter, TokenTree)
+		if (mptr->count)
 #ifndef DEBUGMODE
 			sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
 				me.name, sptr->name, mptr->cmd,
Index: Unreal3.2.orig/src/packet.c
===================================================================
--- Unreal3.2.orig.orig/src/packet.c
+++ Unreal3.2.orig/src/packet.c
@@ -23,13 +23,14 @@
 #include "sys.h"
 #include "msg.h"
 #include "h.h"
+#include "splaytree.h"
 #include <string.h>
 ID_Copyright
     ("(C) 1988 University of Oulu, Computing Center and Jarkko Oikarinen");
 ID_Notes("2.12 1/30/94");
 
-aCommand	*CommandHash[256]; /* one per letter */
-aCommand	*TokenHash[256]; 
+SplayTree	*CommandTree = NULL;
+SplayTree	*TokenTree = NULL;
 
 /*
 ** dopacket
@@ -212,14 +213,9 @@ int  dopacket(aClient *cptr, char *buffe
 
 void	init_CommandHash(void)
 {
-#ifdef DEVELOP_DEBUG
-	aCommand	 *p;
-	int		 i;
-	long		chainlength;
-#endif
-	
-	bzero(CommandHash, sizeof(CommandHash));
-	bzero(TokenHash, sizeof(TokenHash));
+	CommandTree = splaytree_create(stricmp);
+	TokenTree = splaytree_create(stricmp);
+
 	add_CommandX(MSG_ERROR, TOK_ERROR, m_error, MAXPARA, M_UNREGISTERED|M_SERVER);
 	add_CommandX(MSG_VERSION, TOK_VERSION, m_version, MAXPARA, M_UNREGISTERED|M_USER|M_SERVER);
 	add_Command(MSG_SUMMON, NULL, m_summon, 1);
@@ -233,28 +229,6 @@ void	init_CommandHash(void)
 	add_Command(MSG_CREDITS, TOK_CREDITS, m_credits, MAXPARA);
 	add_Command(MSG_LICENSE, TOK_LICENSE, m_license, MAXPARA);
 	add_Command(MSG_MODULE, TOK_MODULE, m_module, MAXPARA);	
-		
-#ifdef DEVELOP_DEBUG
-	for (i = 0; i <= 255; i++)
-	{
-		chainlength = 0;
-		for (p = CommandHash[i]; p; p = p->next)
-			chainlength++;
-		if (chainlength)
-			fprintf(stderr, "%c chainlength = %i\r\n",
-					i, chainlength);
-	}				
-	fprintf(stderr, "Tokens:\n");
-	for (i = 0; i <= 255; i++)
-	{
-		chainlength = 0;
-		for (p = TokenHash[i]; p; p = p->next)
-			chainlength++;
-		if (chainlength)
-			fprintf(stderr, "%c chainlength = %i\r\n",
-					i, chainlength);
-	}				
-#endif
 }
 
 aCommand *add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token, int flags)
@@ -268,11 +242,11 @@ aCommand *add_Command_backend(char *cmd,
 	newcmd->func = func;
 	newcmd->flags = flags;
 	
-	/* Add in hash with hash value = first byte */
 	if (!token)
-		AddListItem(newcmd, CommandHash[toupper(*cmd)]);
+		splaytree_add(CommandTree, cmd, newcmd);
 	else
-		AddListItem(newcmd, TokenHash[*cmd]);
+		splaytree_add(TokenTree, cmd, newcmd);
+
 	return newcmd;
 }
 
@@ -310,14 +284,15 @@ inline aCommand *find_CommandEx(char *cm
 	
 	if (!token)
 	{
-		for (p = CommandHash[toupper(*cmd)]; p; p = p->next)
-			if (!stricmp(p->cmd, cmd) && p->func == func)
-				return p;
+		if ((p = splaytree_retrieve(CommandTree, cmd)) != NULL)
+			return p;
+
 		return NULL;
 	}
-	for (p = TokenHash[*cmd]; p; p = p->next)
-		if (!strcmp(p->cmd, cmd) && p->func == func)
-			return p;
+
+	if ((p = splaytree_retrieve(TokenTree, cmd)) != NULL)
+		return p;
+
 	return NULL;
 	
 }
@@ -332,7 +307,7 @@ int del_Command(char *cmd, char *token, 
 	else
 	{
 		Cmdoverride *ovr, *ovrnext;
-		DelListItem(p, CommandHash[toupper(*cmd)]);
+		splaytree_delete(CommandTree, cmd);
 		for (ovr = p->overriders; ovr; ovr = ovrnext)
 		{
 			ovrnext = ovr->next;
@@ -349,7 +324,7 @@ int del_Command(char *cmd, char *token, 
 			i--;
 		else
 		{
-			DelListItem(p, TokenHash[*token]);
+			splaytree_delete(TokenTree, token);
 			if (p->cmd)
 				MyFree(p->cmd);
 			MyFree(p);
@@ -363,36 +338,47 @@ static inline aCommand *find_Token(char 
 {
 	aCommand *p;
 
-	for (p = TokenHash[*cmd]; p; p = p->next) {
+	if ((p = splaytree_retrieve(TokenTree, cmd)) != NULL)
+	{
 		if ((flags & M_UNREGISTERED) && !(p->flags & M_UNREGISTERED))
-			continue;
+			return NULL;
+
 		if ((flags & M_SHUN) && !(p->flags & M_SHUN))
-			continue;
+			return NULL;
+
 		if ((flags & M_VIRUS) && !(p->flags & M_VIRUS))
-			continue;
+			return NULL;
+
 		if ((flags & M_ALIAS) && !(p->flags & M_ALIAS))
-			continue;
-		if (!strcmp(p->cmd, cmd))
-			return p;
+			return NULL;
+
+		return p;
 	}
+
 	return NULL;
 }
 
 static inline aCommand *find_Cmd(char *cmd, int flags)
 {
 	aCommand *p;
-	for (p = CommandHash[toupper(*cmd)]; p; p = p->next) {
+
+	if ((p = splaytree_retrieve(CommandTree, cmd)) != NULL)
+	{
 		if ((flags & M_UNREGISTERED) && !(p->flags & M_UNREGISTERED))
-			continue;
+			return NULL;
+
 		if ((flags & M_SHUN) && !(p->flags & M_SHUN))
-			continue;
+			return NULL;
+
 		if ((flags & M_VIRUS) && !(p->flags & M_VIRUS))
-			continue;
+			return NULL;
+
 		if ((flags & M_ALIAS) && !(p->flags & M_ALIAS))
-			continue;
-		if (!stricmp(p->cmd, cmd))
-			return p;
+			return NULL;
+
+		return p;
 	}
+
 	return NULL;
 }
 
@@ -421,15 +407,9 @@ aCommand *find_Command_simple(char *cmd)
 {
 	aCommand	*p;
 	
-	for (p = CommandHash[toupper(*cmd)]; p; p = p->next) {
-		if (!stricmp(p->cmd, cmd))
-				return (p);
-	}
+	if ((p = splaytree_retrieve(CommandTree, cmd)) != NULL)
+		return p;
 
-	for (p = TokenHash[*cmd]; p; p = p->next) {
-		if (!strcmp(p->cmd, cmd))
-				return p;
-	}
 	return NULL;
 }
 
