Пример #1
0
	virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
	{
		std::multimap<std::string, Alias>::iterator i, upperbound;

		/* If theyre not registered yet, we dont want
		 * to know.
		 */
		if (user->registered != REG_ALL)
			return 0;

		/* We dont have any commands looking like this? Stop processing. */
		i = Aliases.find(command);
		if (i == Aliases.end())
			return 0;
		/* Avoid iterating on to different aliases if no patterns match. */
		upperbound = Aliases.upper_bound(command);

		irc::string c = command.c_str();
		/* The parameters for the command in their original form, with the command stripped off */
		std::string compare = original_line.substr(command.length());
		while (*(compare.c_str()) == ' ')
			compare.erase(compare.begin());

		while (i != upperbound)
		{
			if (i->second.UserCommand)
			{
				if (DoAlias(user, NULL, &(i->second), compare, original_line))
				{
					return 1;
				}
			}

			i++;
		}

		// If we made it here, no aliases actually matched.
		return 0;
	}
Пример #2
0
DWORD _CRTAPI1
main(
    int argc,
    char *argv[]
    )
{
    DWORD rc;
    char *s, *s1, *AliasName;
    char *ExeName;
    BOOL fDelete;
    BOOL DisplayAllAliases;

    ConvertAppToOem( argc,argv );
    AliasName = NULL;
    ExeName = NULL;
    fVerbose = FALSE;
    fDelete = FALSE;
    DisplayAllAliases = TRUE;
    rc = NO_ERROR;
    while (rc == NO_ERROR && --argc) {
        s = *++argv;
        if (*s == '-' || *s == '/') {
            while (*++s) {
                switch( *s ) {
                    case '?':
                    case 'h':
                    case 'H':
                        usage();
                        break;

                    case 'd':
                    case 'D':
                        fDelete = TRUE;
                        break;

                    case 'v':
                    case 'V':
                        fVerbose = TRUE;
                        break;

                    case 'p':
                    case 'P':
                        if (!--argc) {
                            fprintf( stderr, "ALIAS: Argument to -p switch missing.\n" );
                            usage();
                            }

                        if (ExeName != NULL) {
                            free( ExeName );
                            ExeName = NULL;
                            }
                        s1 = *++argv;
                        ExeName = calloc( 1, strlen( s1 )+2 );
                        strcpy( ExeName, s1 );
                        break;

                    case 'f':
                    case 'F':
                        if (!--argc) {
                            fprintf( stderr, "ALIAS: Argument to -f switch missing.\n" );
                            usage();
                            }

                        DisplayAllAliases = FALSE;
                        rc = DoAliasFile( *++argv, ExeName ? ExeName : "CMD.EXE", fDelete );
                        break;

                    default:
                        fprintf( stderr, "ALIAS: invalid switch /%c\n", *s );
                        usage();
                        break;
                    }
                }
            }
        else {
            DisplayAllAliases = FALSE;
            if (AliasName == NULL) {
                if (fDelete) {
                    rc = DoAlias( s, NULL, ExeName ? ExeName : "CMD.EXE" );
                    }
                else {
                    AliasName = s;
                    }
                }
            else {
                if (fDelete) {
                    rc = DoAlias( AliasName, NULL, ExeName ? ExeName : "CMD.EXE" );
                    AliasName = s;
                    }
                else {
                    rc = DoAlias( AliasName, s, ExeName ? ExeName : "CMD.EXE" );
                    AliasName = NULL;
                    }
                }
            }
        }

    if (rc == NO_ERROR) {
        if (AliasName != NULL) {
            if (fDelete) {
                rc = DoAlias( AliasName, NULL, ExeName ? ExeName : "CMD.EXE" );
                }
            else {
                rc = DisplayAlias( AliasName, ExeName ? ExeName : "CMD.EXE" );
                }
            }
        else
        if (DisplayAllAliases) {
            rc = DisplayAliases( ExeName );
            }
        }

    if (ExeName != NULL) {
        free( ExeName );
        ExeName = NULL;
        }

    exit( rc );
    return rc;
}
Пример #3
0
DWORD
DoAliasFile(
    char * FileName,
    char * ExeName,
    BOOL fDelete
    )
{
    DWORD rc;
    FILE *fh;
    char LineBuffer[ 256 ], *Source, *Target, *s;

    if (!(fh = fopen( FileName, "rt" ))) {
        fprintf( stderr, "ALIAS: Unable to open file - %s\n", FileName );
        return ERROR_FILE_NOT_FOUND;
        }

    if (fVerbose) {
        fprintf( stderr,
                 "ALIAS: %s aliases defined in %s\n",
                 fDelete ? "Deleting" : "Loading",
                 FileName
               );
        }
    while (s = fgets( LineBuffer, sizeof( LineBuffer ), fh )) {
        while (*s <= ' ') {
            if (!*s) {
                break;
                }
            s++;
            }

        if (!*s || (*s == '/' && s[1] == '/')) {
            continue;
            }

        Source = s;
        while (*s > ' ') {
            s++;
            }
        *s++ = '\0';

        while (*s <= ' ') {
            if (!*s) {
                break;
                }
            s++;
            }

        Target = s;
        s += strlen( s );
        while (*s <= ' ') {
            *s-- = '\0';
            if (s < Target) {
                break;
                }
            }

        rc = DoAlias( Source, fDelete ? NULL : Target, ExeName );
        if (rc != NO_ERROR) {
            break;
            }
        }

    return rc;
}
Пример #4
0
	virtual void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
	{
		if (target_type != TYPE_CHANNEL)
		{
			return;
		}

		// fcommands are only for local users. Spanningtree will send them back out as their original cmd.
		if (!user || !IS_LOCAL(user))
		{
			return;
		}

		/* Stop here if the user is +B and allowbot is set to no. */
		if (!AllowBots && user->IsModeSet('B'))
		{
			return;
		}

		Channel *c = (Channel *)dest;
		std::string fcommand;

		// text is like "!moo cows bite me", we want "!moo" first
		irc::spacesepstream ss(text);
		ss.GetToken(fcommand);

		if (fcommand.empty())
		{
			return; // wtfbbq
		}

		// we don't want to touch non-fantasy stuff
		if (*fcommand.c_str() != fprefix)
		{
			return;
		}

		// nor do we give a shit about the prefix
		fcommand.erase(fcommand.begin());
		std::transform(fcommand.begin(), fcommand.end(), fcommand.begin(), ::toupper);

		std::multimap<std::string, Alias>::iterator i = Aliases.find(fcommand);

		if (i == Aliases.end())
			return;

		/* Avoid iterating on to other aliases if no patterns match */
		std::multimap<std::string, Alias>::iterator upperbound = Aliases.upper_bound(fcommand);


		/* The parameters for the command in their original form, with the command stripped off */
		std::string compare = text.substr(fcommand.length() + 1);
		while (*(compare.c_str()) == ' ')
			compare.erase(compare.begin());

		while (i != upperbound)
		{
			if (i->second.ChannelCommand)
			{
				// We use substr(1) here to remove the fantasy prefix
				if (DoAlias(user, c, &(i->second), compare, text.substr(1)))
					return;
			}

			i++;
		}

		return;
	}