Ejemplo n.º 1
0
    private string AddUser()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\n" + "usage: users add <user_name> <password> <admin? y|n>");
        }

        bool wantAdmin = argv [4] == "y" ? true : false;

        string username = IGC_Utils.EscapeUserOrGroup(argv [2]);

        if (wantAdmin && !issuer.isAdmin)
        {
            return("only admins can create admins");
        }

        if (registry.AddUser(new IGC_User(username, argv[3], wantAdmin, virtualSystem, true), issuer) != null)
        {
            return("user " + username + " created successfully");
        }
        else
        {
            return("user " + username + " already exists");
        }
    }
Ejemplo n.º 2
0
    private void LoadSavedState(string stateString)
    {
        string[] termInfo   = IGC_Utils.SplitString(":", stateString);
        int      vsID       = System.Int32.Parse(termInfo[3]);
        bool     powerstate = (termInfo[2] == "True" ? true : false);
        string
            currentUsername = termInfo[0],
            prevUsername    = termInfo[1],
            rawPrompt       = (termInfo[4] != "null" ? IGC_Utils.UnescapeSaved(termInfo[4]) : ""),
            rawDisplay      = (termInfo[5] != "null" ? IGC_Utils.UnescapeSaved(termInfo[5]) : "");

        screenColor = IGC_Utils.ColorFromString(termInfo [6]);
        textColor   = IGC_Utils.ColorFromString(termInfo [7]);

        //set vs
        if (vsID != this.virtualSystem.instanceID)
        {
            IGC_VirtualSystem tempRef = IGC_VirtualSystem.GetInstanceByID(vsID);
            SwapVirtualSystem(ref tempRef);
        }

        //since comp instances load one at a time, it's possible to swap a terminal's VS for one that's not setup yet.
        //therefore you have to wait for ready before setting current and prev users
        StartCoroutine(SetCurrenUserWhenURReady(virtualSystem.userRegistry, currentUsername, prevUsername));

        //set power state
        PowerActions(powerstate);

        SetTextColor(textColor);         //only text here, screen is already set in MonitorActions

        shell.rawPromptText  = rawPrompt;
        shell.rawDisplayText = rawDisplay;
    }
Ejemplo n.º 3
0
    public void BuildGroupsFromGroupsString(string groupsString)
    {
        if (groupsString == "NONE" || groupsString == "" || groupsString == null)
        {
            return;
        }

        string[] groupStringList = IGC_Utils.SplitString("\n", groupsString);

        //foreach group in groupstring
        for (int i = 0; i < groupStringList.Length; i++)
        {
            string[]
            group = IGC_Utils.SplitString(":", groupStringList[i]),
            groupUsers  = IGC_Utils.SplitString("~", group[2]),
            groupAdmins = IGC_Utils.SplitString("~", group[3]);

            //create group
            IGC_UserGroup newGroup = AddGroup(group[0], users[group[1]]);
            //add users
            foreach (string user in groupUsers)
            {
                newGroup.AddUser(users[user], false);
            }
            //add admins
            foreach (string admin in groupAdmins)
            {
                newGroup.AddUser(users[admin], true);
            }
        }
    }
Ejemplo n.º 4
0
    public void BuildUsersList()
    {
        if (Network.peerType == NetworkPeerType.Client || (Network.peerType != NetworkPeerType.Client && virtualSystem.HasSaveData()))
        {
            BuildUsersFromUserString(virtualSystem.GetUsersString(virtualSystem.restoreData));
            virtualSystem.OnUsersReady();
            BuildGroupsFromGroupsString(virtualSystem.GetGroupsString(virtualSystem.restoreData));
            virtualSystem.OnGroupsReady();
        }
        else
        {
            //create system default users
            defaultUser = AddUser(new IGC_User(defaultUsername, defaultUserPassword, false, virtualSystem, true), systemUser);
            rootUser    = AddUser(new IGC_User("root", rootUserPassword, true, virtualSystem, true), systemUser);

            //encrypt editor specified user password
            for (int i = 0; i < usersList.Length; i++)
            {
                string [] userinfo = IGC_Utils.SplitString(":", usersList[i]);
                userinfo[1] = IGC_Utils.Md5Sum(userinfo[1]);

                usersList[i] = string.Join(":", userinfo);
            }

            BuildUsersFromUserString(string.Join("\n", usersList));
            BuildGroupsFromGroupsString(string.Join("\n", groupsList));
        }

        ready = true;
        virtualSystem.OnSystemReady();
    }
Ejemplo n.º 5
0
    /*public void RestoreState(string target)
     * {
     *      Debug.Log(SystemStateKey());
     *      Debug.Log(GetSaveString());
     *      Debug.Log(GetUsersString(target));
     *      Debug.Log(GetGroupsString(target));
     *      Debug.Log(GetFilesString(target));
     * }*/

//get one chunk of save string OR current state string
    public string GetUsersString(string target)
    {
        string[] output = IGC_Utils.SplitString("\n\n", target);
        if (output.Length > 0)
        {
            return(output[0]);
        }
        return("");
    }
Ejemplo n.º 6
0
 public string GetGroupsString(string target)
 {
     string[] output = IGC_Utils.SplitString("\n\n", target);
     if (output.Length > 1)
     {
         return(output[1]);
     }
     return("");
 }
Ejemplo n.º 7
0
 public string GetFilesString(string target)
 {
     string[] output = IGC_Utils.SplitString("\n\n", target);
     if (output.Length > 2)
     {
         return(output[2]);
     }
     return("");
 }
Ejemplo n.º 8
0
    public string TerminalStateString()
    {
        string saveString = (currentUser != null ? currentUser.name : "null")
                            + ":" + (previousUser != null ? previousUser.name : "null")
                            + ":" + powerState.ToString()
                            + ":" + virtualSystem.instanceID.ToString()
                            + ":" + (!string.IsNullOrEmpty(shell.rawPromptText) ? IGC_Utils.EscapeForSave(shell.rawPromptText) : "null")
                            + ":" + (!string.IsNullOrEmpty(shell.rawDisplayText) ? IGC_Utils.EscapeForSave(shell.rawDisplayText) : "null")
                            + ":" + IGC_Utils.ColorString(screenColor)
                            + ":" + IGC_Utils.ColorString(textColor);

        //Debug.Log (instanceID+":"+virtualSystem.IP);

        return(saveString);
    }
Ejemplo n.º 9
0
    public override string command_function()
    {
        string output = "";

        foreach (string key in flags.Keys)
        {
            if (key != "s" && key != "t")
            {
                continue;
            }

            string[] channels = IGC_Utils.SplitString(",", flags[key]);

            if (channels.Length != 3)
            {
                return(malformed_error + "\n" + usage);
            }

            Color color = IGC_Utils.ColorFromString(flags[key]);

            if (key == "s")
            {
                output += "screen color set to " + flags["s"];
                issuer.terminal.SetScreenColor(color);
                issuer.terminal.screenColor = color;
            }
            if (key == "t")
            {
                output += "text color set to " + flags["t"];
                issuer.terminal.SetTextColor(color);
                issuer.terminal.textColor = color;
            }
        }

        output = output == "" ? "please specify a screen or text color\n" + usage : output;

        InGameComputer term = issuer.terminal;

        if (virtualSystem.networkReady)
        {
            term.GetComponent <NetworkView>().RPC("SetColorsRPC", RPCMode.Others,
                                                  IGC_Utils.ColorString(term.screenColor),
                                                  IGC_Utils.ColorString(term.textColor)
                                                  );
        }

        return(output);
    }
Ejemplo n.º 10
0
    public IGC_UserGroup AddGroup(string groupname, IGC_User owner)
    {
        groupname = IGC_Utils.EscapeUserOrGroup(groupname);

        if (!groups.ContainsKey(groupname))
        {
            groups.Add(groupname, new IGC_UserGroup(groupname, owner));

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("AddGroupRPC", RPCMode.Others, groupname, owner.name);
            }

            return(groups[groupname]);
        }
        return(null);
    }
Ejemplo n.º 11
0
    private string AddGroup()
    {
        if (argv.Length != 3)
        {
            return(malformed_error + "\n" + "usage: groups add <group_name>");
        }

        string groupname = IGC_Utils.EscapeUserOrGroup(argv [2]);

        if (registry.AddGroup(groupname, issuer) != null)
        {
            return("group " + groupname + " created successfully");
        }
        else
        {
            return("group " + groupname + " already exists");
        }
    }
Ejemplo n.º 12
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.º 13
0
    public IGC_User AddUser(IGC_User user, IGC_User requester)
    {
        user.name = IGC_Utils.EscapeUserOrGroup(user.name);

        if (!users.ContainsKey(user.name))
        {
            users.Add(user.name, user);

            CreateUserHomeDir(user);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("AddUserRPC", RPCMode.Others, user.name, user.password, user.isAdmin, virtualSystem.instanceID, user.canLogin);
            }

            return(user);
        }

        return(null);
    }
Ejemplo n.º 14
0
    public void BuildUsersFromUserString(string usersString)
    {
        if (usersString == "NONE" || usersString == "" || usersString == null)
        {
            return;
        }

        string[] userStringList = IGC_Utils.SplitString("\n", usersString);

        //foreach user in usersting
        for (int i = 0; i < userStringList.Length; i++)
        {
            string[] user = IGC_Utils.SplitString(":", userStringList[i]);

            int terminalID = user[4] == "-1"
                                ? System.Int32.Parse(user[4])
                                : gameObject.GetComponent <InGameComputer>().instanceID;

            string
                username = user[0],
                userCwd  = user[5];
            bool
                isAdmin        = user[2] == "True" ? true : false,
                loggedIn       = user[6] == "True" ? true : false,
                loggedRemotely = user[3] == "True" ? true : false;

            IGC_User newUser = AddUser(new IGC_User(username, "", isAdmin, virtualSystem, true), systemUser);

            newUser.password         = user[1];     //need to assign it directly since the user class encrypts whatever you hand to it
            newUser.loggedInRemotely = loggedRemotely;
            newUser.terminal         = InGameComputer.GetInstanceByID(terminalID);
            newUser.cwd = userCwd;

            if (loggedIn)
            {
                loggedInUsers.Add(newUser);
            }
        }
    }
Ejemplo n.º 15
0
    public void ApplyFileGroups()
    {
        string filesString = virtualSystem.GetFilesString(virtualSystem.restoreData);

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

        for (int i = 0; i < filesStringList.Length; i++)
        {
            string[]
            fileString = IGC_Utils.SplitString(":", filesStringList[i]),
            groups     = IGC_Utils.SplitString("~", fileString[7]),
            editgroups = IGC_Utils.SplitString("~", fileString[8]);

            IGC_File file = GetFile(fileString[0]);

            if (file == null)
            {
                continue;
            }                                       //if there are no groups of the file ! exist, go to next

            if (fileString[7] != "NONE")
            {
                foreach (string groupname in groups)
                {
                    file.accessGroups.Add(virtualSystem.userRegistry.groups[groupname]);
                }
            }

            if (fileString[8] != "NONE")
            {
                foreach (string editgroupname in editgroups)
                {
                    file.editGroups.Add(virtualSystem.userRegistry.groups[editgroupname]);
                }
            }
        }
    }
Ejemplo n.º 16
0
    private bool CLIReturnKey()
    {
        bool valid = false;

        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (prompt.text == "")
            {
                output.text = FormatForCLI("");
                valid       = true;
            }
            else
            {
                //semicolon command seporation
                string[] cmds = rawPromptText.Split(new string[1] {
                    ";"
                }, System.StringSplitOptions.RemoveEmptyEntries);

                foreach (string cmd in cmds)
                {
                    valid = false;

                    string trimmed, pipeTo = "";

                    //piping
                    if (cmd.IndexOf("|") > -1 && cmd.IndexOf("|") < cmd.Length - 1)
                    {
                        string[] pipedCmd = IGC_Utils.SplitString("|", cmd);
                        trimmed = TrimFront(pipedCmd[0]);
                        pipeTo  = TrimFront(pipedCmd[1]);
                    }
                    else
                    {
                        trimmed = TrimFront(cmd);
                    }


                    string outputString = string.Empty;
                    if (trimmed != "")
                    {
                        history.Add(trimmed + (pipeTo != "" ? "| " + pipeTo : ""));
                    }

                    foreach (string name in lang.commands.Keys)
                    {
                        if (computer.noUser && !lang.cmdSafeWhileLoggedOut(name))
                        {
                            continue;
                        }

                        if (trimmed.IndexOf(name) == 0)
                        {
                            //trigger command
                            valid        = true;
                            outputString = lang.commands[name].trigger(trimmed, ref computer.currentUser);

                            //if this command should be piped
                            if (pipeTo != "")
                            {
                                foreach (string pipeCmd in lang.commands.Keys)
                                {
                                    if (pipeTo.IndexOf(pipeCmd) == 0)
                                    {
                                        //and the pipe command accepts stdin
                                        if (!lang.commands[pipeCmd].CanPipe)
                                        {
                                            valid        = false;
                                            outputString = pipeCmd + " does not accept standard input";
                                            break;
                                        }
                                        //run the output of the left command through the cmd right of the pipe
                                        outputString = lang.commands[pipeCmd].trigger(pipeCmd + " " + outputString, ref computer.currentUser);
                                        Debug.Log(outputString);
                                    }
                                }
                            }
                        }
                    }

                    historyIndex  = history.Count;
                    rawPromptText = trimmed == "" ? " " : trimmed;                     //this ensures a carrot and line break if no text on command line
                    output.text   = FormatForCLI(outputString);
                    cursorOffset  = 0;
                    UpdateCursor();
                }
            }
            computer.UpdateInfoLine();
            UpdateScreenNetwork();
        }

        return(valid);
    }
Ejemplo n.º 17
0
 public void SetPassword(string pass)
 {
     this.password = IGC_Utils.Md5Sum(pass);
 }
Ejemplo n.º 18
0
 public bool CheckPassword(string pass)
 {
     return(IGC_Utils.Md5Sum(pass) == password);
 }
Ejemplo n.º 19
0
// current state of virtualSystem
    public string SystemStateString()
    {
        string saveString = "";

        // save users
        if (userRegistry.users.Values.Count == 0)
        {
            saveString += "NONE\n";
        }

        foreach (IGC_User user in userRegistry.users.Values)
        {
            int terminalID = user.terminal == null
                                ? -1 //if it's not remotely logged in--if the user's term is the local one, this val is -1
                                : user.terminal.instanceID;

            saveString += user.name
                          + ":" + user.password
                          + ":" + user.isAdmin.ToString()
                          + ":" + user.loggedInRemotely.ToString()
                          + ":" + terminalID
                          + ":" + user.cwd
                          + ":" + userRegistry.loggedInUsers.Contains(user).ToString();     //user logged in?

            saveString += "\n";
        }

        saveString += "\n";

        // save groups
        if (userRegistry.groups.Values.Count == 0)
        {
            saveString += "NONE\n";
        }

        foreach (IGC_UserGroup group in userRegistry.groups.Values)
        {
            saveString += group.name
                          + ":" + group.creator
                          + ":";

            foreach (IGC_User user in group.users)
            {
                saveString += user.name + "~";
            }

            saveString += ":";

            foreach (IGC_User admin in group.admins)
            {
                saveString += admin.name + "~";
            }

            saveString += "\n";
        }

        saveString += "\n";

        // save filesystem
        if (fileSystem.files.Values.Count == 0)
        {
            saveString += "NONE";
        }

        foreach (IGC_File file in fileSystem.files.Values)
        {
            saveString += file.path
                          + ":" + file.fileOwner
                          + ":" + file.protectedFile.ToString()
                          + ":" + file.isDir.ToString()
                          + ":" + file.ext
                          + ":" + file.type
                          + ":" + (file.data == "" ? "NONE" : IGC_Utils.EscapeForSave(file.data))
                          + ":";

            foreach (IGC_UserGroup group in file.accessGroups)
            {
                saveString += group.name + "~";
            }
            if (file.accessGroups.Count == 0)
            {
                saveString += "NONE";
            }
            saveString += ":";


            foreach (IGC_UserGroup editgroup in file.editGroups)
            {
                saveString += editgroup.name + "~";
            }
            if (file.editGroups.Count == 0)
            {
                saveString += "NONE";
            }


            saveString += "\n";
        }

        return(saveString);
    }
Ejemplo n.º 20
0
    public IGC_URL ParseURL(string path, string cwd)
    {
        var cwdList = PathDirList(cwd);

        path = IGC_Utils.EscapeURL(path);

        while (path[path.Length - 1] == '/' && path.Length > 1)
        {
            path = path.Remove(path.Length - 1, 1);
        }                                                                                                  //strip end slash

        if (path.IndexOf("./") == 0)
        {
            path = cwd + path.Remove(0, 1);        //replace ./ with cwd
        }
        else if (path.IndexOf("..") == 0)          //going up dirs
        {
            if (cwdList.Length == 0)
            {
                return(null);
            }

            string[] dirs = PathDirList(path);
            int      ups  = 0;
            for (int i = 0; i < dirs.Length; i++)
            {
                if (dirs[i] == "..")
                {
                    ups++; dirs[i] = "|)r(|";
                }
                else
                {
                    break;
                }
            }                                                                                                         //count the ups
            if (ups > cwdList.Length)
            {
                return(null);
            }
            string[] tempList = cwdList;
            for (int a = 0; a < ups; a++)
            {
                tempList[tempList.Length - a - 1] = "|)r(|";
            }

            path = "/" + string.Join("/", tempList) + "/" + string.Join("/", dirs);
            path = path.Replace("/|)r(|", "");
            if (path.IndexOf("../") != -1)
            {
                return(null);
            }
            if (path == "")
            {
                path = "/";
            }
        }

        else if (path.IndexOf("/") != 0)
        {
            path = (cwd == "/" ? "" : cwd) + "/" + path;
        }                                                                                     //if just a name, prepend cwd/

        string[] dirList = PathDirList(path);
        string
            dirpath  = "/",
            filename = dirList.Length > 0 ? dirList[dirList.Length - 1] : "",
            dirname  = dirList.Length > 1 ? dirList[dirList.Length - 2] : "/";

        for (int d = 0; d < dirList.Length - 1; d++)
        {
            dirpath += dirList[d] + (dirList.Length - 2 == d ? "" : "/");
        }
        //Debug.Log (path);
        return(new IGC_URL(filename, dirname, dirpath, path, cwd));
    }
Ejemplo n.º 21
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.º 22
0
 [RPC] public void SetColorsRPC(string s, string t)
 {
     SetScreenColor(IGC_Utils.ColorFromString(s));
     SetTextColor(IGC_Utils.ColorFromString(t));
 }
Ejemplo n.º 23
0
 public override string command_function()
 {
     issuer.terminal.shell.EnterViewMode(string.Join(" ", IGC_Utils.ArrayShift(argv)));
     return("");
 }