mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-06 03:13:13 +02:00
+- Added CommandHash optimation .. this is not done 100% yet. uses msgtab as
+ reference
This commit is contained in:
@@ -255,3 +255,5 @@
|
||||
global variable. Done on request on Great Master codemastr.
|
||||
- Made crule.c use the server list rather than the whole client list for checking (faster)
|
||||
- Sped up some channel stuff a lot using a bahamut type user search
|
||||
- Added CommandHash optimation .. this is not done 100% yet. uses msgtab as
|
||||
reference
|
||||
|
||||
+12
@@ -388,6 +388,18 @@ extern char *inetntop(int af, const void *in, char *local_dummy,
|
||||
size_t the_size);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CommandHash -Stskeeps
|
||||
*/
|
||||
extern aCommand *CommandHash[256];
|
||||
void init_CommandHash(void);
|
||||
void add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token);
|
||||
void add_Command(char *cmd, char *token, int (*func)(), unsigned char parameters);
|
||||
void add_Command_to_list(aCommand *item, aCommand **list);
|
||||
aCommand *del_Command_from_list(aCommand *item, aCommand **list);
|
||||
|
||||
|
||||
/* CRULE */
|
||||
char *crule_parse PROTO((char *));
|
||||
int crule_eval PROTO((char *));
|
||||
void crule_free PROTO((char **));
|
||||
|
||||
+16
-1
@@ -104,7 +104,7 @@ typedef struct FloodOpt aFloodOpt;
|
||||
typedef struct ircstatsx ircstats;
|
||||
typedef struct MotdItem aMotd;
|
||||
typedef struct trecord aTrecord;
|
||||
|
||||
typedef struct Command aCommand;
|
||||
#ifdef NEED_U_INT32_T
|
||||
typedef unsigned int u_int32_t; /* XXX Hope this works! */
|
||||
#endif
|
||||
@@ -729,6 +729,21 @@ struct Server {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Command {
|
||||
aCommand *next;
|
||||
aCommand *prev;
|
||||
char *cmd;
|
||||
int (*func) ();
|
||||
unsigned int count;
|
||||
unsigned parameters : 5;
|
||||
unsigned token : 1;
|
||||
unsigned long bytes;
|
||||
#ifdef DEBUGMODE
|
||||
unsigned long lticks;
|
||||
unsigned long rticks;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct t_vhost {
|
||||
char *usermask;
|
||||
char *hostmask;
|
||||
|
||||
+67
-1
@@ -29,6 +29,9 @@ ID_Copyright
|
||||
("(C) 1988 University of Oulu, Computing Center and Jarkko Oikarinen");
|
||||
ID_Notes("2.12 1/30/94");
|
||||
|
||||
aCommand *CommandHash[256];
|
||||
|
||||
|
||||
/*
|
||||
* inittoken
|
||||
* Cheat here, blah. Build the lookup tables from msgtab's,
|
||||
@@ -37,6 +40,7 @@ ID_Notes("2.12 1/30/94");
|
||||
*/
|
||||
void inittoken(void)
|
||||
{
|
||||
aCommand *p;
|
||||
int loopy;
|
||||
int final;
|
||||
|
||||
@@ -48,9 +52,12 @@ void inittoken(void)
|
||||
msgmap[loopy] = &msgtab[final];
|
||||
/* Build references to existing commands */
|
||||
for (loopy = 0; msgtab[loopy].cmd; loopy++)
|
||||
{
|
||||
msgmap[msgtab[loopy].token[0]] = &msgtab[loopy];
|
||||
add_Command(msgtab[loopy].cmd, msgtab[loopy].token,
|
||||
msgtab[loopy].func, msgtab[loopy].parameters);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** dopacket
|
||||
** cptr - pointer to client structure for which the buffer data
|
||||
@@ -141,3 +148,62 @@ int dopacket(cptr, buffer, length)
|
||||
cptr->count = ch1 - cptr->buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_CommandHash(void)
|
||||
{
|
||||
bzero(CommandHash, sizeof(CommandHash));
|
||||
}
|
||||
|
||||
void add_Command_backend(char *cmd, int (*func)(), unsigned char parameters, unsigned char token)
|
||||
{
|
||||
aCommand *newcmd = (aCommand *) MyMalloc(sizeof(aCommand));
|
||||
|
||||
bzero(newcmd, sizeof(aCommand));
|
||||
|
||||
newcmd->cmd = (char *) strdup(cmd);
|
||||
newcmd->parameters = parameters;
|
||||
newcmd->token = token;
|
||||
newcmd->func = func;
|
||||
|
||||
/* Add in hash with hash value = first byte */
|
||||
add_Command_to_list(newcmd, &CommandHash[toupper(*cmd)]);
|
||||
}
|
||||
|
||||
void add_Command(char *cmd, char *token, int (*func)(), unsigned char parameters)
|
||||
{
|
||||
add_Command_backend(cmd, func, parameters, 0);
|
||||
add_Command_backend(token, func, parameters, 1);
|
||||
}
|
||||
|
||||
void add_Command_to_list(aCommand *item, aCommand **list)
|
||||
{
|
||||
item->next = *list;
|
||||
item->prev = NULL;
|
||||
if (*list)
|
||||
(*list)->prev = item;
|
||||
*list = item;
|
||||
}
|
||||
|
||||
aCommand *del_Command_from_list(aCommand *item, aCommand **list)
|
||||
{
|
||||
aCommand *p, *q;
|
||||
|
||||
for (p = *list; p; p = p->next)
|
||||
{
|
||||
if (p == item)
|
||||
{
|
||||
q = p->next;
|
||||
if (p->prev)
|
||||
p->prev->next = p->next;
|
||||
else
|
||||
*list = p->next;
|
||||
|
||||
if (p->next)
|
||||
p->next->prev = p->prev;
|
||||
return q;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+37
-54
@@ -184,6 +184,22 @@ void ban_flooder(aClient *cptr)
|
||||
return;
|
||||
}
|
||||
|
||||
inline aCommand *find_Command(char *cmd, int token)
|
||||
{
|
||||
aCommand *p;
|
||||
|
||||
for (p = CommandHash[toupper(*cmd)]; p; p = p->next)
|
||||
if (p->token && token)
|
||||
{
|
||||
if (!strcmp(p->cmd, cmd))
|
||||
return (p);
|
||||
}
|
||||
else
|
||||
if (!match(p->cmd, cmd))
|
||||
return (p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* parse a buffer.
|
||||
*
|
||||
@@ -202,7 +218,7 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
time_t then, ticks;
|
||||
int retval;
|
||||
#endif
|
||||
struct Message *bmptr;
|
||||
aCommand *cmptr = NULL;
|
||||
|
||||
Debug((DEBUG_ERROR, "Parsing: %s (from %s)", buffer,
|
||||
(*cptr->name ? cptr->name : "*")));
|
||||
@@ -317,7 +333,7 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
if (len == 3 &&
|
||||
isdigit(*ch) && isdigit(*(ch + 1)) && isdigit(*(ch + 2)))
|
||||
{
|
||||
mptr = NULL;
|
||||
cmptr = NULL;
|
||||
numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10
|
||||
+ (*(ch + 2) - '0');
|
||||
paramcount = MAXPARA;
|
||||
@@ -327,43 +343,10 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
{
|
||||
if (s)
|
||||
*s++ = '\0';
|
||||
|
||||
cmptr = find_Command(ch, IsServer(cptr) ? 1 : 0);
|
||||
|
||||
/* xx or x = token :P */
|
||||
if ((strlen(ch) < 3) && IsServer(cptr))
|
||||
{
|
||||
token = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
token = 0;
|
||||
}
|
||||
bmptr = mptr;
|
||||
|
||||
/* run a fast token search through if token */
|
||||
mfound = 0;
|
||||
if (token == 1)
|
||||
{
|
||||
for (; mptr->cmd; mptr++)
|
||||
{
|
||||
if (strcmp(mptr->token, ch) == 0)
|
||||
{
|
||||
mfound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no token match .. grr :P */
|
||||
if (mfound == 0)
|
||||
{
|
||||
mptr = bmptr;
|
||||
for (; mptr->cmd; mptr++)
|
||||
{
|
||||
if (mycmp(mptr->cmd, ch) == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!mptr->cmd)
|
||||
if (!cmptr)
|
||||
{
|
||||
/*
|
||||
** Note: Give error message *only* to recognized
|
||||
@@ -389,9 +372,9 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
ircstp->is_unco++;
|
||||
return (-1);
|
||||
}
|
||||
paramcount = mptr->parameters;
|
||||
paramcount = cmptr->parameters;
|
||||
i = bufend - ch; /* Is this right? -Donwulff */
|
||||
mptr->bytes += i;
|
||||
cmptr->bytes += i;
|
||||
/* Changed this whole lag generating crap ..
|
||||
* We only generate fake lag in HTM ..
|
||||
* --Stskeeps
|
||||
@@ -445,23 +428,23 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
}
|
||||
}
|
||||
para[++i] = NULL;
|
||||
if (mptr == NULL)
|
||||
if (cmptr == NULL)
|
||||
return (do_numeric(numeric, cptr, from, i, para));
|
||||
/* now, lets make sure they use a legit commnd... -nikb */
|
||||
/* There is code in s_serv.c for ADMIN and VERSION and
|
||||
* in s_user.c for NOTICE to limit commands by
|
||||
* unregistered users. -Studded */
|
||||
if (IsShunned(cptr) && IsRegistered(cptr))
|
||||
if ((mptr->func != m_admin) && (mptr->func != m_quit)
|
||||
&& (mptr->func != m_pong))
|
||||
if ((cmptr->func != m_admin) && (cmptr->func != m_quit)
|
||||
&& (cmptr->func != m_pong))
|
||||
return -4;
|
||||
|
||||
if ((!IsRegistered(cptr)) &&
|
||||
(((mptr->func != m_user) && (mptr->func != m_nick) &&
|
||||
(mptr->func != m_server) && (mptr->func != m_pong) &&
|
||||
(mptr->func != m_pass) && (mptr->func != m_quit) &&
|
||||
(mptr->func != m_protoctl) && (mptr->func != m_error) &&
|
||||
(mptr->func != m_admin) && (mptr->func != m_version)
|
||||
(((cmptr->func != m_user) && (cmptr->func != m_nick) &&
|
||||
(cmptr->func != m_server) && (cmptr->func != m_pong) &&
|
||||
(cmptr->func != m_pass) && (cmptr->func != m_quit) &&
|
||||
(cmptr->func != m_protoctl) && (cmptr->func != m_error) &&
|
||||
(cmptr->func != m_admin) && (cmptr->func != m_version)
|
||||
)))
|
||||
{
|
||||
sendto_one(from, ":%s %d %s :You have not registered",
|
||||
@@ -469,22 +452,22 @@ int parse(cptr, buffer, bufend, mptr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mptr->count++;
|
||||
if (IsRegisteredUser(cptr) && mptr->func == m_private)
|
||||
cmptr->count++;
|
||||
if (IsRegisteredUser(cptr) && cmptr->func == m_private)
|
||||
from->user->last = TStime();
|
||||
|
||||
#ifndef DEBUGMODE
|
||||
return (*mptr->func) (cptr, from, i, para);
|
||||
return (*cmptr->func) (cptr, from, i, para);
|
||||
#else
|
||||
then = clock();
|
||||
retval = (*mptr->func) (cptr, from, i, para);
|
||||
retval = (*cmptr->func) (cptr, from, i, para);
|
||||
if (retval != FLUSH_BUFFER)
|
||||
{
|
||||
ticks = (clock() - then);
|
||||
if (IsServer(cptr))
|
||||
mptr->rticks += ticks;
|
||||
cmptr->rticks += ticks;
|
||||
else
|
||||
mptr->lticks += ticks;
|
||||
cmptr->lticks += ticks;
|
||||
cptr->cputime += ticks;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user