Home Showcase
Welcome to the new Diaspora forums, please let us know if you see anything broken! Notice: Some users may need to reupload their avatars due to an issue during forum setup!

User access template

KatelynKatelyn Registered, Administrator Posts: 171
edited April 2011 in Showcase #1
This is an old e2 and it will definitely give you an error if you try to paste it due to using old outdated file functions. It however details a user access system, and you can learn from it if you're trying to make one yourself. It uses some older chat functions that need to be cleaned up. It is actually an early version of a Faction warfare expression I was making for Mcbuilds.
@name Factional Warfare Moderation Chip
@inputs 
@outputs Debug:array K Error Dbg Users:table Users1:array Find:string Cmd:array
@persist Config:table  Access Command:string  User:string  A
@trigger 
if (first()) 
{
    #fileRemove("FWMcfg.txt")
    #fileRemove("FWMuser.txt")
    if (!fileLoaded("FWMcfg.txt"))
    {
        Config["Contested", number] = 0
        Config["Captime", number] = 10000
        Config["Timer", number] = 600000
        Config["Timeron", number] = 0
        Config["Teamlock", number] = 1
        Config["Autotele", number] = 0
        Config["Ownerlock", number] = 1

        Config[map() + "1", vector] = entity():pos() + vec(0,0,30)
        Config[map() + "2", vector] = entity():pos() + vec(0,0,30)
        Config[map() + "3", vector] = entity():pos() + vec(0,0,30)
        
        fileWrite("FWMcfg.txt", glonEncode(Config))
        Debug[1, string] = "Configuration file not found, creating one with default settings."
        Error = 1
    }
    else
    {
        Debug[1, string] = "Configuration file loaded..."
        Config = glonDecodeTable(fileRead("FWMcfg.txt"))
        if (Config[map() + "1", vector] == vec())
        {
            Config[map() + "1", vector] = entity():pos() + vec(0,0,30)
            Debug[2, string] = "Team 1 spawn not found, defaulting to chip"
            Error = 1
        } 
        else
        {
            Debug[2, string] = "Team 1 spawn loaded..."
        }
        if (Config[map() + "2", vector] == vec())
        {
            Config[map() + "2", vector] = entity():pos() + vec(0,0,30)
            Debug[3, string] = "Team 2 spawn not found, defaulting to chip"
            Error = 1
        }
        else
        {
            Debug[3, string] = "Team 2 spawn loaded..."
        }
        if (Config[map() + "3", vector] == vec())
        {
            Config[map() + "3", vector] = entity():pos() + vec(0,0,30)
            Debug[4, string] = "Neutral spawn not found, defaulting to chip"
            Error = 1
        }
        else
        {
            Debug[4, string] = "Neutral spawn loaded..."
        }
    }
    if (!fileLoaded("FWMuser.txt"))
    {
        Users[owner():steamID() + owner():name():lower(), number] = 9
        fileWrite("FWMuser.txt", glonEncode(Users))
        Debug[5, string] = "User databased not found. Creating default."
        Error = 1
    }
    else
    {
        Users = glonDecodeTable(fileRead("FWMuser.txt"))
        Debug[5, string] = "User databased found."
    }
    Debug[6, string] = Users:count():toString() + " users loaded..."

    print(_HUD_PRINTCONSOLE, "#####################################")
    print(_HUD_PRINTCONSOLE, "#####################################")

    for (K = 1, 6)
    {
        print(_HUD_PRINTCONSOLE, Debug[K, string])
    }
    
    print(_HUD_PRINTCONSOLE, "#####################################")
    print(_HUD_PRINTCONSOLE, "#####################################")

    if (Error)
    {
        print("An error occured while loading the databases. Check your console for more information.")
    }
}


runOnChat(1)

if (Users[lastSpoke():steamID() + lastSpoke():name():lower(), number] & lastSaid()[1] == "!")
{
    User = lastSpoke():steamID() + lastSpoke():name():lower()
    Access = Users[User, number]
    Command = lastSaid():lower():trim()
    Cmd = Command:explode(" ")
    if (Access >= 1)
    {
        if (Cmd[1, string] == "!whoami")
        {
            concmd("ulx csay User " + lastSpoke():name() + " found with " + Access:toString() + " access.")
        }
        ##########
        #END WHOAMI
        ##########
        if (Cmd[1, string] == "!whois")
        {
            A = 0
            Users1 = Users:keys()
            Dbg = Users1:count()
            for (K = 0, Users1:count() + 1, 1)
            {
                if (Users1[K, string]:find(Cmd[2, string]))
                {
                    Find = Users1[K, string]
                    A++
                }
            }
            if (A == 1)
            {                
                concmd("ulx csay FWM: User " + Find + " has " + Users[Find, number]:toString() + " access.")
            }
            elseif (A > 1)
            {
                concmd("ulx csay FWM: Multiple users found")
            }
            else
            {
                concmd("ulx csay FWM: User not found.")
            }                 
        }
        ##########
        #END WHOIS
        ##########
    }
    if (Access >= 2)
    {
        
    }
    if (Access >= 3)
    {
        
    }
    if (Access >= 4)
    {
        
    }
    if (Access >= 5)
    {
        if (Cmd[1, string] == "!adduser")
        {
            if (Users[User, number] > Cmd[3, string]:toNumber() & Cmd[3, string]:toNumber() > -1)
            {
                findByClass("Player")
                findClipToName(Cmd[2, string])
                if (find())
                {
                    if (Users[find():steamID() + find():name():lower(), number] == 0)
                    {
                        Users[find():steamID() + find():name():lower(), number] = Cmd[3, string]:toNumber()
                        fileWrite("FWMuser.txt", glonEncode(Users))
                        concmd("ulx csay FWM: User " + find():name() + " added to the database with " + Cmd[3, string] + " access.")
                    }
                    else
                    {
                        if (Users[find():steamID() + find():name():lower(), number] < Users[User, number])
                        {
                            Users[find():steamID() + find():name():lower(), number] = Cmd[3, string]:toNumber()
                            fileWrite("FWMuser.txt", glonEncode(Users))
                            concmd("ulx csay FWM: User " + find():name() + " access changed to " + Cmd[3, string] + " access.")
                        }
                        else
                        {
                            concmd("ulx csay FWM: User access is greater than your access.")
                        }
                    }
                }
                else
                {
                    concmd("ulx csay FWM: User not found.")
                }
            }
            else
            {
                concmd("ulx csay FWM: Invalid access number. Can not be equal to or higher than your acces and must positive.")
            }
        }
        ##########
        #END ADDUSER
        ##########
    }
    if (Access >= 6)
    {
        if (Cmd[1, string] == "!remuser")
        {
            A = 0
            Users1 = Users:keys()
            Dbg = Users1:count()
            for (K = 0, Users1:count() + 1, 1)
            {
                if (Users1[K, string]:find(Cmd[2, string]))
                {
                    Find = Users1[K, string]
                    A++
                }
            }
            if (A == 1)
            {
                if (Users[User, number] > Users[Find, number])
                {
                    Users[Find, number] = 0
                    fileWrite("FWMuser.txt", glonEncode(Users))
                    concmd("ulx csay FWM: User " + Find + " removed from the access database")
                }
                else
                {
                    concmd("ulx csay FWM: User has greater access that you.")
                }
            }
            elseif (A > 1)
            {
                concmd("ulx csay FWM: Multiple users found")
            }
            else
            {
                concmd("ulx csay FWM: User not found.")
            }        
        }
        ##########
        #END REMUSER
        ##########
    }
    if (Access >= 7)
    {
        
    }
    if (Access >= 8)
    {
        
    }
    if (Access >= 9)
    {
        
    }
        
    
    
    
}


Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file