- command_p[0] = parameters+1;
- return 1;
- }
-
- if (q)
- {
- if ((strchr(parameters,' ')==NULL) || (parameters[0] == ':'))
- {
- /* only one parameter */
- command_p[0] = parameters;
- if (parameters[0] == ':')
- {
- if (strchr(parameters,' ') != NULL)
- {
- command_p[0]++;
- }
- }
-
- return 1;
- }
- }
-
- command_p[j++] = parameters;
-
- for (int i = 0; i <= q; i++)
- {
- if (parameters[i] == ' ')
- {
- command_p[j++] = parameters+i+1;
- parameters[i] = '\0';
-
- if (command_p[j-1][0] == ':')
- {
- *command_p[j-1]++; /* remove dodgy ":" */
- break;
- /* parameter like this marks end of the sequence */
- }
- }
- }
-
- return j; /* returns total number of items in the list */
-}
-
-void CommandParser::ProcessCommand(userrec *user, char* cmd)
-{
- char *parameters;
- char *command;
- char *command_p[127];
- char p[MAXBUF], temp[MAXBUF];
- int j, items, cmd_found;
- int total_params = 0;
- unsigned int xl;
-
- for (int i = 0; i < 127; i++)
- command_p[i] = NULL;
-
- if (!user || !cmd || !*cmd)
- {
- return;
- }
-
- xl = strlen(cmd);
-
- if (xl > 2)
- {
- for (unsigned int q = 0; q < xl - 1; q++)
- {
- if (cmd[q] == ' ')
- {
- if (cmd[q+1] == ':')
- {
- total_params++;
- // found a 'trailing', we dont count them after this.
- break;
- }
- else
- total_params++;
- }
- }
- }
-
- // another phidjit bug...
- if (total_params > 126)
- {
- *(strchr(cmd,' ')) = '\0';
- WriteServ(user->fd,"421 %s %s :Too many parameters given",user->nick,cmd);
- return;
- }
-
- strlcpy(temp,cmd,MAXBUF);
-
- std::string tmp = cmd;
-
- for (int i = 0; i <= MODCOUNT; i++)
- {
- std::string oldtmp = tmp;
- modules[i]->OnServerRaw(tmp,true,user);
- if (oldtmp != tmp)
- {
- log(DEBUG,"A Module changed the input string!");
- log(DEBUG,"New string: %s",tmp.c_str());
- log(DEBUG,"Old string: %s",oldtmp.c_str());
- break;
- }
- }
-
- strlcpy(cmd,tmp.c_str(),MAXBUF);
- strlcpy(temp,cmd,MAXBUF);
-
- if (!strchr(cmd,' '))
- {
- /*
- * no parameters, lets skip the formalities and not chop up
- * the string
- */
- log(DEBUG,"About to preprocess command with no params");
- items = 0;
- command_p[0] = NULL;
- parameters = NULL;
- unsigned int tl = strlen(cmd);
- for (unsigned int i = 0; i <= tl; i++)
- {
- cmd[i] = toupper(cmd[i]);
- }
- command = cmd;
- }
- else
- {
- *cmd = 0;
- j = 0;
-
- unsigned int vl = strlen(temp);
- /* strip out extraneous linefeeds through mirc's crappy pasting (thanks Craig) */
- for (unsigned int i = 0; i < vl; i++)
- {
- if ((temp[i] != 10) && (temp[i] != 13) && (temp[i] != 0) && (temp[i] != 7))
- {
- cmd[j++] = temp[i];
- cmd[j] = 0;
- }
- }
-
- /* split the full string into a command plus parameters */
- parameters = p;
- p[0] = ' ';
- p[1] = 0;
-
- command = cmd;
-
- if (strchr(cmd,' '))
- {
- unsigned int cl = strlen(cmd);
-
- for (unsigned int i = 0; i <= cl; i++)
- {
- /* capitalise the command ONLY, leave params intact */
- cmd[i] = toupper(cmd[i]);
- /* are we nearly there yet?! :P */
- if (cmd[i] == ' ')
- {
- command = cmd;
- parameters = cmd+i+1;
- cmd[i] = '\0';
- break;
- }
- }
- }
- else
- {
- for (char* i = cmd; *i; i++)
- {
- *i = toupper(*i);
- }
- }
- }
-
- if (strlen(command)>MAXCOMMAND)
- {
- WriteServ(user->fd,"421 %s %s :Command too long",user->nick,command);
- return;
- }
-
- for (char* x = command; *x; x++)
- {
- if (((*x < 'A') || (*x > 'Z')) && (*x != '.'))
- {
- if (((*x < '0') || (*x> '9')) && (*x != '-'))
- {
- if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",*x))
- {
- ServerInstance->stats->statsUnknown++;
- WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
- return;
- }
- }
- }
- }
-
- std::string xcommand = command;
- if ((user->registered != 7) && (xcommand == "SERVER"))
- {
- kill_link(user,"Server connection to non-server port");
- return;
- }
-
- /* Tweak by brain - why was this INSIDE the mainloop? */
- if (parameters)
- {
- if (parameters[0])
- {
- items = this->ProcessParameters(command_p,parameters);
- }
- else
- {
- items = 0;
- command_p[0] = NULL;
- }
- }
- else
- {
- items = 0;
- command_p[0] = NULL;