Ejemplo n.º 1
0
    public override string command_function()
    {
        IGC_FileSystem fs = virtualSystem.fileSystem;

        if (argv.Length > 1)
        {
            IGC_URL url = fs.ParseURL(argv[1], issuer.cwd);

            IGC_File file = fs.GetFile(url.fullpath);

            if (file != null)
            {
                if (!fs.CanAccessFile(file, issuer))
                {
                    return("You do not have permission to view this file");
                }

                return(file.data);
            }
            else
            {
                return("file " + url.fullpath + " does not exist");
            }
        }
        else
        {
            return(malformed_error + "\n" + this.usage);
        }
    }
Ejemplo n.º 2
0
    public IGC_File CreateFile(IGC_URL url, IGC_User user, bool isDir)
    {
        if (FileExists(url.fullpath))
        {
            return(null);
        }

        IGC_File targetDir = GetFile(url.dirpath);

        if (targetDir != null && targetDir.isDir)
        {
            if (!CanAccessFile(targetDir, user))
            {
                return(null);
            }

            IGC_File file = CreateFileGameObject(url, user.name, isDir);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("CreateFileRPC", RPCMode.Others, url.fullpath, user.name, isDir);
            }

            return(file);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 3
0
    public override string command_function()
    {
        if (argv.Length != 2)
        {
            return(malformed_error + "\n" + usage);
        }

        IGC_FileSystem fs = virtualSystem.fileSystem;

        IGC_URL  url  = fs.ParseURL(argv [1], issuer.cwd);
        IGC_File file = fs.GetFile(url.fullpath);

        if (file == null)
        {
            return(url.fullpath + " does not exits");
        }

        if (!fs.CanEditFile(file, issuer))
        {
            return("you do not have permission to edit this file");
        }

        issuer.terminal.shell.EnterEditMode(file);
        return("");
    }
Ejemplo n.º 4
0
    private string cd(IGC_URL url)
    {
        IGC_File file = fs.GetFile(url.fullpath);

        if (file != null)
        {
            if (file.isDir)
            {
                if (!fs.CanAccessFile(file, issuer))
                {
                    return("you do not have permission to enter this directory");
                }

                issuer.cwd = file.path;

                if (virtualSystem.networkReady)
                {
                    virtualSystem.GetComponent <NetworkView>().RPC("UpdateCWDRPC", RPCMode.Others, issuer.name, file.path);
                }

                return("");
            }
            else
            {
                return(url.fullpath + " is not a directory");
            }
        }
        return(url.fullpath + " does not exist");
    }
Ejemplo n.º 5
0
    public override string command_function()
    {
        if (argv.Length < 2)
        {
            return(malformed_error + "\n" + usage);
        }

        IGC_FileSystem fs  = virtualSystem.fileSystem;
        IGC_URL        url = fs.ParseURL(argv [1], issuer.cwd);

        if (!fs.FileExists(url.fullpath))
        {
            IGC_File file = fs.CreateFile(url, issuer, false);

            if (file != null)
            {
                return("file " + file.path + " created successfully");
            }
            else
            {
                return("error: insufficient privilages or broken path");
            }
        }
        return(url.fullpath + " already exists");
    }
Ejemplo n.º 6
0
    public bool RMFile(IGC_URL url, IGC_User user)
    {
        if (FileExists(url.fullpath))
        {
            IGC_File file = GetFile(url.fullpath);
            if (!CanAccessFile(file, user))
            {
                return(false);
            }
            else
            {
                RemoveFileActions(file);

                if (virtualSystem.networkReady)
                {
                    GetComponent <NetworkView>().RPC("RemoveFileRPC", RPCMode.Others, url.fullpath);
                }

                return(true);
            }
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 7
0
    public override string command_function()
    {
        if (argv.Length < 2)
        {
            return(malformed_error + "\n" + usage);
        }

        IGC_FileSystem fs  = virtualSystem.fileSystem;
        IGC_URL        url = fs.ParseURL(argv [1], issuer.cwd);

        if (!fs.CanAccessFile(fs.GetFile(url.dirpath), issuer))
        {
            return("you do not have permission to create files in that location");
        }

        if (!fs.FileExists(url.fullpath))
        {
            IGC_File dir = fs.CreateFile(url, issuer, true);
            if (dir != null)
            {
                return("directory " + url.fullpath + " created successfully");
            }
            else
            {
                return("error: broken path");
            }
        }
        return(url.fullpath + " already exists");
    }
Ejemplo n.º 8
0
    public override string command_function()
    {
        if (argv.Length != 3)
        {
            return(this.malformed_error + "\n" + this.usage);
        }

        IGC_FileSystem fs = virtualSystem.fileSystem;



        IGC_URL
            oldURL = fs.ParseURL(argv[1], issuer.cwd),
            newURL = fs.ParseURL(argv[2], issuer.cwd);

        if (!fs.FileExists(oldURL.fullpath))
        {
            return("cant move " + argv[1] + " because it doesn't exist");
        }
        Debug.Log("from " + oldURL.fullpath);
        if (!fs.FileExists(newURL.dirpath))
        {
            return("cant move " + argv[1] + " to " + newURL.dirname + " because that directory does not exist.");
        }
        Debug.Log("to " + newURL.dirpath);
        if (fs.FileExists(newURL.fullpath))
        {
            return("new path " + argv[2] + " already exists - have you added the file name to the path?");
        }
        Debug.Log("to fullpath " + newURL.fullpath);

        IGC_File file = fs.GetFile(oldURL.fullpath);
        IGC_File dir  = fs.GetFile(newURL.dirpath);

        if (!fs.CanAccessFile(file, issuer))
        {
            return("you do not have permission to edit " + oldURL.fullpath);
        }
        if (!fs.CanAccessFile(dir, issuer))
        {
            return("you do not have permission to access " + newURL.dirname);
        }

        if (argv[2] == "SVR-01")
        {
        }
        //if svr get gameobject tagged playerserver - move the file from current gameobject to the playerserver gameobject
        //new move file method in FS required, one that takes gameobjects - convert this to extract command?
        fs.MoveFile(oldURL, newURL);

        if (virtualSystem.networkReady)
        {
            fs.GetComponent <NetworkView>().RPC("MoveFileRPC", RPCMode.Others, oldURL.fullpath, newURL.fullpath);
        }

        return(oldURL.filename + " changed to " + newURL.fullpath);
    }
Ejemplo n.º 9
0
    public void MoveFile(IGC_URL oldURL, IGC_URL newURL)
    {
        IGC_File file = GetFile(oldURL.fullpath);

        files.Remove(oldURL.fullpath);

        file.path             = newURL.fullpath;
        file.transform.parent = GetFile(newURL.dirpath).transform;
        file.gameObject.name  = newURL.filename;

        files.Add(newURL.fullpath, file);
    }
Ejemplo n.º 10
0
    public void CopyFile(IGC_URL target, IGC_URL copy)
    {
        IGC_File file    = GetFile(target.fullpath);
        IGC_File dir     = GetFile(copy.dirpath);
        IGC_File newFile = (GameObject.Instantiate(file.gameObject) as GameObject).GetComponent <IGC_File>();

        newFile.gameObject.name  = copy.filename;
        newFile.path             = copy.fullpath;
        newFile.transform.parent = dir.transform;
        newFile.accessGroups     = file.accessGroups;
        newFile.editGroups       = file.editGroups;

        files.Add(copy.fullpath, newFile);
    }
Ejemplo n.º 11
0
    public override string command_function()
    {
        if (argv.Length != 3)
        {
            return(this.malformed_error + "\n" + this.usage);
        }

        IGC_FileSystem fs = virtualSystem.fileSystem;

        IGC_URL
            target = fs.ParseURL(argv[1], issuer.cwd),
            copy   = fs.ParseURL(argv[2], issuer.cwd);

        if (!fs.FileExists(target.fullpath))
        {
            return("cant copy " + target.fullpath + " because it doesn't exist");
        }
        if (!fs.FileExists(copy.dirpath))
        {
            return("cant copy " + target.filename + " to " + copy.dirname + " because that directory does not exist.");
        }
        if (fs.FileExists(copy.fullpath))
        {
            return(copy.fullpath + " already exists");
        }

        IGC_File file = fs.GetFile(target.fullpath);
        IGC_File dir  = fs.GetFile(copy.dirpath);

        if (!fs.CanAccessFile(file, issuer))
        {
            return("you do not have permission to copy " + target.fullpath);
        }
        if (!fs.CanAccessFile(dir, issuer))
        {
            return("you do not have permission to access " + copy.dirname);
        }


        fs.CopyFile(target, copy);

        if (virtualSystem.networkReady)
        {
            fs.GetComponent <NetworkView>().RPC("CopyFileRPC", RPCMode.Others, target.fullpath, copy.fullpath);
        }

        return(target.filename + " copied to " + copy.fullpath);
    }
Ejemplo n.º 12
0
    private IGC_File CreateFileGameObject(IGC_URL url, string username, bool isDir)
    {
        GameObject go = new GameObject(url.filename);

        go.transform.parent = url.dirpath == "/"
                        ? rootNode.transform
                        : GetFile(url.dirpath).transform;

        IGC_File file = go.AddComponent <IGC_File>();

        file.fileOwner = username;
        file.isDir     = isDir;
        files.Add(url.fullpath, file);

        return(file);
    }
Ejemplo n.º 13
0
    public IGC_URL[] ListFiles(IGC_URL url, string cwd, bool showHidden)
    {
        Transform dir = GetFile(url.fullpath).transform;

        List <IGC_URL> list = new List <IGC_URL>();

        foreach (Transform file in dir)
        {
            if (showHidden || file.name[0] != '.')
            {
                list.Add(ParseURL(file.GetComponent <IGC_File>().path, cwd));
            }
        }

        return(list.ToArray());
    }
Ejemplo n.º 14
0
    public override string command_function()
    {
        if (argv.Length != 3)
        {
            return(this.malformed_error + "\n" + this.usage);
        }

        IGC_FileSystem fs = virtualSystem.fileSystem;

        IGC_URL
            oldURL = fs.ParseURL(argv[1], issuer.cwd),
            newURL = fs.ParseURL(argv[2], issuer.cwd);

        if (!fs.FileExists(oldURL.fullpath))
        {
            return("cant move " + argv[1] + " because it doesn't exist");
        }
        if (!fs.FileExists(newURL.dirpath))
        {
            return("cant move " + argv[1] + " to " + newURL.dirname + " because that directory does not exist.");
        }
        if (fs.FileExists(newURL.fullpath))
        {
            return("new path " + argv[2] + " already exists");
        }

        IGC_File file = fs.GetFile(oldURL.fullpath);
        IGC_File dir  = fs.GetFile(newURL.dirpath);

        if (!fs.CanAccessFile(file, issuer))
        {
            return("you do not have permission to edit " + oldURL.fullpath);
        }
        if (!fs.CanAccessFile(dir, issuer))
        {
            return("you do not have permission to access " + newURL.dirname);
        }

        fs.MoveFile(oldURL, newURL);

        if (virtualSystem.networkReady)
        {
            fs.GetComponent <NetworkView>().RPC("MoveFileRPC", RPCMode.Others, oldURL.fullpath, newURL.fullpath);
        }

        return(oldURL.filename + " changed to " + newURL.fullpath);
    }
Ejemplo n.º 15
0
    public override string command_function()
    {
        if (argv.Length != 2)
        {
            return(malformed_error + "\n" + usage);
        }

        IGC_FileSystem fs   = virtualSystem.fileSystem;
        IGC_URL        url  = fs.ParseURL(argv [1], issuer.cwd);
        IGC_File       file = fs.GetFile(url.fullpath);

        if (file == null)
        {
            return("input file does not exist");
        }

        Transform platforms = GameObject.Find("room/platforms").transform;

        string[] bridgeFormationData = IGC_Utils.SplitString(",", file.data);

        if (bridgeFormationData.Length != 10)
        {
            return("incorrect number of comma seporated numbers in input file. must be 10.");
        }

        int i = 0;

        foreach (string s in bridgeFormationData)
        {
            int       num = int.Parse(s.Trim());
            Transform t   = platforms.Find(i.ToString());

            t.GetComponent <BridgeSegment>().SetTargetPosition(new Vector3(
                                                                   t.transform.localPosition.x,
                                                                   num,
                                                                   t.transform.localPosition.z
                                                                   ));

            i++;
        }

        return("bridge formation reset");
    }
Ejemplo n.º 16
0
    public override string command_function()
    {
        if (argv.Length < 2)
        {
            return(malformed_error + "\n" + usage);
        }

        IGC_FileSystem fs   = virtualSystem.fileSystem;
        IGC_URL        url  = fs.ParseURL(argv [1], issuer.cwd);
        IGC_File       file = fs.GetFile(url.fullpath);


        if (file != null)
        {
            if (!fs.CanAccessFile(file, issuer))
            {
                return("you do not have permission to delete " + file.path);
            }

            if (file.isDir && argv.Length < 3)
            {
                return("you must type '-r' after the folder name to delete a folder and all files/folders within");
            }

            if (!file.isDir || (file.isDir && argv[2] == "-r"))
            {
                if (fs.RMFile(url, issuer))
                {
                    return(url.fullpath + " deleted");
                }
                else
                {
                    return("system error. could not delete file...?");
                }
            }
            else
            {
                return(malformed_error + usage);
            }
        }
        return(url.fullpath + " does not exist");
    }
Ejemplo n.º 17
0
    private string FileInfo()
    {
        if (argv.Length != 2)
        {
            return(malformed_error + "\nusage: file <filename>");
        }

        IGC_URL  url  = fs.ParseURL(argv [1], issuer.cwd);
        IGC_File file = fs.GetFile(url.fullpath);

        if (file != null)
        {
            string output = "TYPE: " + file.type;
            output += "\nOWNER: " + file.owner.name;
            output += "\nPROTECTED: " + file.protectedFile;
            output += "\nREAD GROUPS: " + string.Join(", ", file.ListAccessGroups());
            output += "\nWRITE GROUPS: " + string.Join(", ", file.ListEditGroups());
            return(output);
        }
        return("file " + url.fullpath + " does not exist");
    }
Ejemplo n.º 18
0
    private string ls(IGC_URL url, bool showHidden, bool asList)
    {
        IGC_File file = fs.GetFile(url.fullpath);

        if (file != null)
        {
            if (!fs.CanAccessFile(file, issuer))
            {
                return("you do not have permission to view this directory");
            }

            if (file.isDir)
            {
                return(FormatLSString(fs.ListFiles(url, issuer.cwd, showHidden), asList));
            }
            else
            {
                return(file.path + " is not a directory");
            }
        }
        return(url.fullpath + " does not exist");
    }
Ejemplo n.º 19
0
    private string ProtectedYN()
    {
        if (argv.Length != 4)
        {
            return(malformed_error + "\nusage: file -a <filename> <y|n>");
        }

        bool     pro  = argv [3] == "y" ? true : false;
        IGC_URL  url  = fs.ParseURL(argv [2], issuer.cwd);
        IGC_File file = fs.GetFile(url.fullpath);

        if (file == null)
        {
            return(url.fullpath + " does not exist");
        }

        if (fs.CanAccessFile(file, issuer))
        {
            file.Protect(pro);
            return(url.fullpath + " is now " + (pro ? "protected" : "unprotected"));
        }

        return("you do not have permission to alter this file");
    }
Ejemplo n.º 20
0
    public void BuildFilesFromFileString()
    {
        string filesString = virtualSystem.GetFilesString(virtualSystem.restoreData);

        if (filesString == "NONE")
        {
            return;
        }

        Transform[] children = new Transform[transform.childCount];         //if you loop through a transform and change children's parents it alters the transform list b4 next loop

        int c = 0;

        foreach (Transform child in rootNode)        //build child list
        {
            children[c++] = child;
        }

        foreach (Transform child in children)        //edit it
        {
            if (child != null)
            {
                child.parent = trashBin;
            }
        }

        string[] filesStringList = IGC_Utils.SplitString("\n", filesString);

        //foreach file in filestring
        for (int i = 0; i < filesStringList.Length; i++)
        {
            string[] file       = IGC_Utils.SplitString(":", filesStringList[i]);
            IGC_URL  url        = ParseURL(file[0], "/");
            string   dataString = file[6] != "NONE"
                                ? IGC_Utils.UnescapeSaved(file[6])
                                : "";
            bool
                prot  = file[2] == "True" ? true : false,
                isdir = file[3] == "True" ? true : false;

            if (url.filename == "")            //root
            {
                var rootFile = rootNode.GetComponent <IGC_File>();
                files.Add("/", rootFile);
                rootFile.fileOwner = file[1];
            }
            else
            {
                GameObject go = new GameObject(url.filename);
                go.transform.parent = rootNode.Find(url.dirpath.Remove(0, 1)).transform;
                IGC_File fileComp = go.AddComponent <IGC_File>();
                fileComp.isDir         = isdir;
                fileComp.protectedFile = prot;
                fileComp.fileOwner     = file[1];
                fileComp.data          = dataString;

                files.Add(url.fullpath, fileComp);
            }
        }

        ready = true;
        virtualSystem.OnFilesReady();
    }
Ejemplo n.º 21
0
    [RPC] void CreateFileRPC(string filepath, string username, bool isDir)
    {
        IGC_URL url = ParseURL(filepath, "/");

        CreateFileGameObject(url, username, isDir);
    }
Ejemplo n.º 22
0
    private string GroupActions()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\nusage: file -r|w <add|rm> <groupname> <filename>");
        }

        string action = argv [2];

        if (action != "add" && action != "rm")
        {
            return("action " + argv[2] + " not understood");
        }

        IGC_UserGroup group = registry.GetGroup(argv [3]);

        if (group == null)
        {
            return(argv[3] + " does not exist");
        }

        IGC_URL  url  = fs.ParseURL(argv [4], issuer.cwd);
        IGC_File file = fs.GetFile(url.fullpath);

        if (file == null)
        {
            return(url.fullpath + " does not exist");
        }

        bool writeGroup = argv [1] == "-w";

        if (fs.CanAccessFile(file, issuer))
        {
            if (action == "add")
            {
                if (writeGroup)
                {
                    if (file.ApplyEditGroup(group) != null)
                    {
                        return(group.name + " added to " + file.path);
                    }
                    else
                    {
                        return(file.path + " already belongs to " + group.name);
                    }
                }
                else
                {
                    if (file.ApplyAccesGroup(group) != null)
                    {
                        return(group.name + " added to " + file.path);
                    }
                    else
                    {
                        return(file.path + " already belongs to " + group.name);
                    }
                }
            }
            else if (action == "rm")              //redundant, but more legible
            {
                if (writeGroup)
                {
                    if (file.RemoveEditGroup(group))
                    {
                        return(group.name + " removed from " + file.path);
                    }
                    else
                    {
                        return(file.path + " does not belong to " + group.name);
                    }
                }
                else
                {
                    if (file.RemoveAccessGroup(group))
                    {
                        return(group.name + " removed from " + file.path);
                    }
                    else
                    {
                        return(file.path + " does not belong to " + group.name);
                    }
                }
            }
        }

        return("you do not have permission to alter this file");
    }