Beispiel #1
0
BObjectImp* FileAccessExecutorModule::mf_ReadFile()
{
	const String* filename;
	if (!getStringParam( 0, filename ))
		return new BError( "Invalid parameter type" );

	const Package* outpkg;
	string path;
	if (!pkgdef_split( filename->value(), exec.prog()->pkg, &outpkg, &path ))
		return new BError( "Error in filename descriptor" );

	if (path.find( ".." ) != string::npos)
		return new BError( "No parent path traversal please." );

	if (!HasReadAccess( exec.prog()->pkg, outpkg, path ))
		return new BError( "Access denied" );

	string filepath;
	if (outpkg == NULL)
		filepath = path;
	else
		filepath = outpkg->dir() + path;

	ifstream ifs( filepath.c_str() );
	if (!ifs.is_open())
		return new BError( "File not found: " + filepath );

	ObjArray* arr = new ObjArray();

	string line;
	while (getline(ifs, line))
		arr->addElement( new String( line ) );

	return arr;
}
Beispiel #2
0
BObjectImp* FileAccessExecutorModule::mf_ListDirectory()
{
	const String* dirname;
	const String* extension;
	short listdirs;
	if ((!getStringParam( 0, dirname )) ||
		(!getStringParam( 1, extension )) ||
		(!getParam( 2, listdirs )) )
		return new BError( "Invalid parameter type" );

	const Package* outpkg;
	string path;
	if (!pkgdef_split( dirname->value(), exec.prog()->pkg, &outpkg, &path ))
		return new BError( "Error in dirname descriptor" );
	if (path.find( ".." ) != string::npos)
		return new BError( "No parent path traversal please." );

	if (outpkg != NULL)
		path = outpkg->dir() + path;
	path = normalized_dir_form(path);
	if ( !IsDirectory( path.c_str() ) )
		return new BError( "Directory not found." );
	bool asterisk = false;
	bool nofiles = false;
	if ( extension->getStringRep().find('*',0) != string::npos)
		asterisk = true;
	else if ( extension->length() == 0 )
		nofiles = true;

	ObjArray* arr = new ObjArray;

	for( DirList dl( path.c_str() ); !dl.at_end(); dl.next() )
	{
		string name = dl.name();
		if (name[0] == '.')
			continue;

		if ( IsDirectory( (path+name).c_str() ) )
		{
			if ( listdirs == 0 )
				continue;
		}
		else if ( nofiles )
			continue;
		else if (!asterisk)
		{
			string::size_type extensionPointPos = name.rfind('.');
			if (extensionPointPos == string::npos)
				continue;
			if (name.substr(extensionPointPos + 1) != extension->value())
				continue;
		}
		
		arr->addElement( new String(name) );
	}

	return arr;
}
Beispiel #3
0
/// uo.em functions:
///  ListGuilds(); // returns an array of Guild objects
BObjectImp* GuildExecutorModule::mf_ListGuilds()
{
    ObjArray* result = new ObjArray;
    for( Guilds::iterator itr = guilds.begin(); itr != guilds.end(); ++itr )
    {
        Guild* guild = (*itr).second.get();
        result->addElement( new EGuildRefObjImp( GuildRef(guild )) );
    }
    return result;
}
BObjectImp* PolSystemExecutorModule::mf_Packages()
{
    ObjArray* arr = new ObjArray;
    for( unsigned i = 0; i < packages.size(); ++i )
    {
        PackageObjImp* imp = new PackageObjImp( PackagePtrHolder( packages[i] ) );
        arr->addElement( imp );
    }
    return arr;
}
Beispiel #5
0
BObjectRef EGuildRefObjImp::get_member_id( const int id ) //id test
{
    if (obj_->_disbanded)
        return BObjectRef( new BError( "Guild has disbanded" ) );
 
    ObjArray* arr;
    switch(id)
    {
    case MBR_MEMBERS:
        arr = new ObjArray;
        for( SerialSet::iterator itr = obj_->_member_serials.begin();
             itr != obj_->_member_serials.end();
             /* do this earlier */)
        {
            unsigned long mserial = (*itr);
            SerialSet::iterator last_itr = itr;
            ++itr;

            Character* chr = system_find_mobile( mserial );
            if (chr != NULL)
            {
                arr->addElement( new EOfflineCharacterRefObjImp( chr ) );
            }
            else
            {
                obj_->_member_serials.erase( last_itr );
            }
        }
        return BObjectRef( arr );

    case MBR_ALLYGUILDS:
        arr = new ObjArray;
        for( SerialSet::iterator itr = obj_->_allyguild_serials.begin();
             itr != obj_->_allyguild_serials.end();
             /* do this earlier */)
        {
            unsigned long gserial = (*itr);
            SerialSet::iterator last_itr = itr;
            ++itr;

            Guild* guild = FindGuild( gserial );

            if (guild != NULL)
            {
                arr->addElement( new EGuildRefObjImp( ref_ptr<Guild>(guild) ) );
            }
            else
            {
                obj_->_allyguild_serials.erase( last_itr );
            }
        }
        return BObjectRef( arr );

    case MBR_ENEMYGUILDS:
        arr = new ObjArray;
        for( SerialSet::iterator itr = obj_->_enemyguild_serials.begin();
             itr != obj_->_enemyguild_serials.end();
             /* do this earlier */)
        {
            unsigned long gserial = (*itr);
            SerialSet::iterator last_itr = itr;
            ++itr;

            Guild* guild = FindGuild( gserial );

            if (guild != NULL)
            {
                arr->addElement( new EGuildRefObjImp( ref_ptr<Guild>(guild) ) );
            }
            else
            {
                obj_->_enemyguild_serials.erase( last_itr );
            }
        }
        return BObjectRef( arr );

    case MBR_GUILDID:
        return BObjectRef( new BLong( obj_->_guildid ) );
    default:
        return BObjectRef( UninitObject::create() );
    }
}