public static bool Remove(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : rm [fileName]"); } var activeDirectory = process.ActiveDirectory; foreach (var file in activeDirectory.children) { if (file.Name == command[1]) { if (!file.HasWritePermission(process.Credentials)) { process.Print("Permission denied."); return(true); } process.Print("File " + command[1] + " removed."); process.computer.Kernel.RemoveFile(process, file); return(true); } } process.Print("File does not exist."); return(true); }
public static bool Compile(CommandProcess process, string[] command) { ServerAdmin serverAdmin = (ServerAdmin)process; if (command.Length != 2) { process.Print("Usage: compile FILENAME TYPE"); return(true); } string[] args = command[1].Split(' '); if (args.Length != 2) { process.Print("Usage: compile FILENAME TYPE"); return(true); } File file = process.ActiveDirectory.GetFile(args[0]); if (file == null) { process.Print("File not found"); return(true); } if (file.IsFolder()) { process.Print("Invalid file, cannot be folder"); return(true); } serverAdmin.client.server.GetCompileManager().AddType(file.Checksum, args[1]); return(true); }
public static bool PlayMusic(CommandProcess process, string[] commandUnsplit) { try { List <string> command = new List <string>(); command.Add("music"); command.AddRange(commandUnsplit[1].Split()); if (command.Count < 2) { process.Print("Usage: music [(nameofsong) (Note: Must be in a folder called \"HNMPMusic\" in the Mods folder as an .wav file.)]\nOR music shuffle\nOR music list"); return(true); } process.computer.Kernel.PlayMusic(process, command[1]); return(true); } catch (ObjectDisposedException e) { Console.WriteLine(e); return(true); } catch (Exception e) { Console.WriteLine(e); return(true); } }
public static bool MkDir(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : mkdir [folderName]"); return(true); } var activeDirectory = process.ActiveDirectory; foreach (var fileC in activeDirectory.children) { if (fileC.Name == command[1]) { process.Print("Folder " + command[1] + " already exists."); return(true); } } bool passed = activeDirectory.HasWritePermission(process.Credentials); if (!passed) { process.Print("Permission denied."); return(true); } File file = process.computer.fileSystem.CreateFile(process.computer, activeDirectory, command[1]); file.OwnerId = process.Credentials.UserId; file.Permissions.SetPermission(FilePermissions.PermissionType.User, true, true, true); file.Permissions.SetPermission(FilePermissions.PermissionType.Group, true, true, true); file.Group = file.Parent.Group; return(true); }
private static bool Passwd(CommandProcess process, string[] command) { if (command.Length == 1) { return(false); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 2) { return(false); } Account account = Account.FromId(process.Credentials.UserId, process.computer); if (account == null) { return(true); } string oldpass = cmdArgs[0]; string newpass = cmdArgs[1]; if (oldpass != account.Password) { process.Print("The old password is invalid"); return(true); } account.Password = newpass; account.ApplyChanges(); process.Print("Changes successfully applied"); return(true); }
public static bool Touch(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : touch [fileName]"); } var activeDirectory = process.ActiveDirectory; foreach (var fileC in activeDirectory.children) { if (fileC.Name == command[1]) { process.Print("File " + command[1] + " touched."); fileC.Dirty = true; return(true); } } if (!activeDirectory.HasWritePermission(process.Credentials)) { process.Print("Permission denied."); return(true); } File file = process.computer.fileSystem.CreateFile(process.computer, activeDirectory, command[1]); file.OwnerId = process.Credentials.UserId; file.Permissions.SetPermission(FilePermissions.PermissionType.User, true, true, false); file.Permissions.SetPermission(FilePermissions.PermissionType.Group, true, true, false); file.Group = file.Parent.Group; process.Print("File " + command[1]); return(true); }
public static bool Balance(CommandProcess process, string[] command) { BankClient client = (BankClient)process; BankDaemon daemon = (BankDaemon)client.Daemon; if (command[0] == "balance") { if (command.Length < 2) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length < 2) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } if (cmdArgs[0] == "set" && cmdArgs.Length < 3) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } BankAccount account = null; foreach (var account2 in daemon.accounts) { if (account2.accountName == cmdArgs[1]) { account = account2; break; } } if (account == null) { process.Print("Account data for this account does not exist in the database"); return(true); } if (cmdArgs[0] == "set") { if (int.TryParse(cmdArgs[2], out int val)) { account.balance = val; daemon.UpdateAccountDatabase(); var bankFolder = process.computer.fileSystem.rootFile.GetFile("bank"); daemon.LogTransaction($"{account.accountName},CHEATED Balance set to {val}", client.Session.sessionId, client.Session.owner.homeComputer.ip); } else { process.Print("Error: non-integer value specified"); return(true); } } process.Print($"Account balance for {account.accountName} is {account.balance}"); return(true); } return(false); }
public static bool CommandExec(CommandProcess process, string[] command) { if (command.Length > 1) { return(process.RunCommand(command[1])); } process.Print(commands[command[0]].Item1); return(true); }
public static bool Balance(CommandProcess process, string[] command) { BankClient client = (BankClient)process; BankDaemon daemon = (BankDaemon)client.Daemon; if (command[0] == "balance") { if (command.Length < 2) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length < 2) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } if (cmdArgs[0] == "set" && cmdArgs.Length < 3) { process.Print("Usage : balance set [accountname] [value]/get [accountname]"); return(true); } Account account = null; foreach (var account2 in daemon.accounts) { if (account2.accountName == cmdArgs[1]) { account = account2; break; } } if (account == null) { process.Print("Account data for this account does not exist in the database"); return(true); } if (cmdArgs[0] == "set") { if (int.TryParse(cmdArgs[2], out int val)) { account.balance = val; daemon.UpdateAccountDatabase(); } else { process.Print("Error: non-integer value specified"); return(true); } } process.Print($"Account balance for {account.accountName} is {account.balance}"); return(true); } return(false); }
public static bool GivePermissions(CommandProcess process, string[] commandUnsplit) { GameClient client = ((ServerAdmin)process).client; if (client.permissions.Contains(HackLinks_Server.Permissions.Admin) == false && client.permissions.Contains(HackLinks_Server.Permissions.GivePerms) == false) { client.Send(NetUtil.PacketType.MESSG, "Insufficent Privileges"); return(true); } List <string> command = new List <string>(); command.Add("giveperms"); command.AddRange(commandUnsplit[1].Split(' ')); if (command.Count < 3) { client.Send(NetUtil.PacketType.MESSG, "Usage: giveperms [username] [admin/kick/ban/giveperms]"); return(true); } if (!Server.Instance.DatabaseLink.GetUsersInDatabase().ContainsValue(command[1])) { client.Send(NetUtil.PacketType.MESSG, "User does not exist in the user database"); return(true); } List <HackLinks_Server.Permissions> permissions = Server.Instance.DatabaseLink.GetUserPermissions()[command[1]]; if (command[2] == "admin") { permissions.Add(HackLinks_Server.Permissions.Admin); } if (command[2] == "kick") { permissions.Add(HackLinks_Server.Permissions.Kick); } if (command[2] == "ban") { permissions.Add(HackLinks_Server.Permissions.Ban); } if (command[2] == "giveperms") { permissions.Add(HackLinks_Server.Permissions.GivePerms); } Server.Instance.DatabaseLink.SetUserPermissions(command[1], permissions); foreach (var client2 in Server.Instance.clients) { if (client2.username == command[1]) { client = client2; } } client.permissions = permissions; return(true); }
public static bool Unban(CommandProcess process, string[] command) { GameClient client = ((ServerAdmin)process).client; if (command.Length < 2) { client.Send(NetUtil.PacketType.MESSG, "Usage: unban [username]"); return(true); } Server.Instance.DatabaseLink.SetUserBanStatus(command[1], 0, true); return(true); }
public static bool Connect(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : command [ip]"); return(true); } process.computer.Kernel.Connect(process, command[1]); return(true); }
public static bool ConfigCommand(CommandProcess process, string[] command) { MailClient client = (MailClient)process; MailDaemon daemon = (MailDaemon)client.Daemon; File mailFolder = process.computer.fileSystem.RootFile.GetFile("mail"); if (command.Length < 2) { process.Print("Usage : config dns [IP]"); return(true); } string[] cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 2) { process.Print("Usage : config dns [IP]"); return(true); } if (cmdArgs[0] == "dns") { if (!Permissions.PermissionHelper.CheckCredentials(process.Credentials, Permissions.Group.ROOT)) { process.Print("You must be logged in as root to use this command!"); return(true); } if (cmdArgs.Length != 2) { process.Print("config dns [IP of DNS Server]"); return(true); } Node dnsServer = Server.Instance.GetComputerManager().GetNodeByIp(cmdArgs[1]); if (dnsServer == null) { process.Print($"{cmdArgs[1]} does not exist!"); return(true); } File dnsDaemon = dnsServer.fileSystem.RootFile.GetFileAtPath("daemons/dns"); if (dnsDaemon == null) { process.Print($"{dnsServer.ip} doesn't have a DNS daemon"); return(true); } File configFile = client.computer.fileSystem.RootFile.GetFileAtPath("mail/config.json"); JObject configObject = JObject.Parse(configFile.Content); configObject["DNS"] = cmdArgs[1]; configFile.Content = configObject.ToString(); process.Print($"DNS changed to {cmdArgs[1]}"); return(true); } process.Print("Config option not found"); return(true); }
private static bool Daemon(CommandProcess process, string[] command) { if (command.Length != 2) { process.Print("Usage : daemon [name of daemon]"); return(true); } string target = command[1]; process.computer.Kernel.OpenDaemon(process, target); return(true); }
public static bool Web(CommandProcess process, string[] arguments) { HTTPClient client = (HTTPClient)process; if (arguments.Length < 2) { process.Print("Usage : web [interface name] [arguments]"); return(true); } client.ActivePage.UseInterfaces(client, arguments[1].Split(' ')); return(true); }
public static bool PlayMusic(CommandProcess process, string[] commandUnsplit) { List <string> command = new List <string>(); command.Add("music"); command.AddRange(commandUnsplit[1].Split()); if (command.Count < 3) { process.Print("Usage: music [file ((DLC\\)Music\\NameOfFile)] [playimmediately (0/1)]"); return(true); } process.computer.Kernel.PlayMusic(process, command[1], command[2]); return(true); }
public static bool AddToNetMap(CommandProcess process, string[] commandUnsplit) { List <string> command = new List <string>(); command.Add("netmap"); command.AddRange(commandUnsplit[1].Split()); if (command.Count < 4) { //TODO kernel //client.Send(NetUtil.PacketType.MESSG, "Usage: netmap [ip] [x] [y]"); return(true); } //TODO kernel //Server.Instance.DatabaseLink.AddUserNode(client.username, command[1], command[2] + ":" + command[3]); return(true); }
public static bool AddToNetMap(CommandProcess process, string[] commandUnsplit) { List <string> command = new List <string>(); command.Add("netmap"); command.AddRange(commandUnsplit[1].Split()); if (command.Count < 4) { //TODO kernel process.Print("Usage: netmap [ip] [x] [y]"); return(true); } //TODO kernel process.computer.Kernel.AddNodeToNetMap(process, Server.Instance.DatabaseLink.Computers.Find(command[1]), command[2], command[3]); return(true); }
public static bool Login(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : login [username] [password]"); return(true); } var args = command[1].Split(' '); if (args.Length < 2) { process.Print("Usage : login [username] [password]"); return(true); } process.computer.Kernel.Login(process, args[0], args[1]); return(true); }
public static bool Ping(CommandProcess process, string[] command) { //TODO ping //var compManager = client.server.GetComputerManager(); //if (command.Length < 2) //{ // process.Print("Usage : ping [ip]"); // return true; //} //var connectingToNode = compManager.GetNodeByIp(command[1]); //if (connectingToNode == null) //{ // process.Print("Ping on " + command[1] + " timeout."); // return true; //} //process.Print("Ping on " + command[1] + " success."); return(true); }
public static bool SetPrimaryGroup(CommandProcess process, string[] command) { if (command.Length == 1) { return(false); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 2) { return(false); } string username = cmdArgs[0]; string groupname = cmdArgs[1]; File groupsFile = process.computer.fileSystem.RootFile.GetFile("etc").GetFile("group"); File usersFile = process.computer.fileSystem.RootFile.GetFile("etc").GetFile("passwd"); if (!groupsFile.HasWritePermission(process.Credentials) && !usersFile.HasWritePermission(process.Credentials)) { process.Print("You do not have the required permissions"); return(true); } string[] groups = groupsFile.Content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); List <Account> accounts = process.computer.Kernel.GetAccounts(); if (accounts.All(acc => acc.Username.ToLower() != username.ToLower())) { process.Print("The user \"" + username + "\" does not exists"); return(true); } if (groups.All(g => !g.StartsWith(groupname.ToLower() + ":"))) { process.Print("The group \"" + groupname + "\" does not exists"); return(true); } Account user = accounts.Find(acc => acc.Username.ToLower() == username.ToLower()); Enum.TryParse(groupname, true, out Group theGroup); user.GroupId = (int)theGroup; user.ApplyChanges(); process.Print("done"); return(true); }
public static bool ChangeTheme(CommandProcess process, string[] command) { GameClient client = ((ServerAdmin)process).client; if (command.Length < 2) { client.Send(NetUtil.PacketType.MESSG, "Usage: changetheme [filepathtotheme]"); return(true); } var file = process.ActiveDirectory.GetFile(command[1]); if (file == null) { client.Send(NetUtil.PacketType.MESSG, "File " + command[1] + " not found."); return(true); } client.Send(NetUtil.PacketType.KERNL, "changetheme", file.Content); return(true); }
public static bool ChMod(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print(commands[command[0]].Item1); return(true); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 2) { process.Print(commands[command[0]].Item1); return(true); } var activePrivs = process.Credentials.Groups; var activeDirectory = process.ActiveDirectory; foreach (var fileC in activeDirectory.children) { if (fileC.Name == cmdArgs[1]) { if (process.Credentials.UserId != fileC.OwnerId) { process.Print("Permission denied."); return(true); } if (!Permissions.PermissionHelper.ApplyModifiers(cmdArgs[0], fileC.Permissions)) { process.Print($"Invalid mode '{cmdArgs[0]}'\r\nUsage : chmod [permissions] [file]"); return(true); } process.Print($"File {fileC.Name} permissions changed. to {fileC.Permissions.PermissionValue}"); return(true); } } process.Print("File " + cmdArgs[1] + " was not found."); return(true); }
public static bool ChangeDirectory(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : cd [folder]"); return(true); } if (command[1] == "..") { if (process.ActiveDirectory.Parent != null) { process.ActiveDirectory = process.ActiveDirectory.Parent; return(true); } else { process.Print("Invalid operation."); return(true); } } foreach (var file in process.ActiveDirectory.children) { if (file.Name == command[1]) { if (!file.IsFolder()) { process.Print("You cannot change active directory to a file."); return(true); } if (!file.HasExecutePermission(process.Credentials)) { process.Print("You do not have permission to do this. You must have execute permission to access a directory."); return(true); } process.ActiveDirectory = file; process.computer.Kernel.CD(process, file.Name); return(true); } } process.Print("No such folder."); return(true); }
public static bool TraceDebug(CommandProcess process, string[] command) { GameClient client = ((ServerAdmin)process).client; if (command.Length != 2) { return(true); } if (command[1] == "over") { client.TraceTermination(); return(true); } if (command[1] == "beep") { client.Send(NetUtil.PacketType.FX, "warnBlink"); } if (command[1] == "trace") { client.Send(NetUtil.PacketType.FX, "trace", "100", "5"); } if (command[1] == "traceEnd") { client.Send(NetUtil.PacketType.FX, "traceEnd"); } if (command[1] == "realTrace") { if (client.activeSession != null) { client.activeSession.SetTraceLevel(5); } } if (command[1] == "realMagic") { if (client.activeSession != null) { client.activeSession.SetTraceLevel(-5); } } return(true); }
public static bool UserInfo(CommandProcess process, string[] command) { if (command.Length == 1) { return(false); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 1) { return(false); } File usersFile = process.computer.fileSystem.RootFile.GetFile("etc").GetFile("passwd"); if (!usersFile.HasReadPermission(process.Credentials)) { process.Print("You do not have the required permissions"); return(true); } string username = cmdArgs[0]; List <Account> accounts = process.computer.Kernel.GetAccounts(); if (accounts.Find(acc => acc.Username == username) == null) { process.Print("The user \"" + username + "\" does not exists"); return(true); } Account account = accounts.Find(acc => acc.Username == username); process.Print("--------------------------------"); process.Print("Username : "******"UserId : " + account.UserId); process.Print("Primary group : " + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(account.GetGroup().ToString()) + " (" + account.GroupId + ")"); process.Print("Info : " + account.Info); process.Print("System : " + (account.UserId < 100 ? "True" : "False")); process.Print("Home directory : " + account.HomeString); process.Print("Default process : " + account.DPString); process.Print("--------------------------------"); return(true); }
public static bool ShowCommand(CommandProcess process, string[] command) { MailClient client = (MailClient)process; MailDaemon daemon = (MailDaemon)client.Daemon; File mailFolder = process.computer.fileSystem.RootFile.GetFile("mail"); if (command.Length < 2) { process.Print("Usage : show [message ID]"); return(true); } string[] cmdArgs = command[1].Split(' '); if (client.loggedInAccount == null) { process.Print("You aren't logged in!"); return(true); } if (cmdArgs.Length != 1) { process.Print("Usage : show [message ID]"); return(true); } if (!int.TryParse(cmdArgs[0], out int number)) { process.Print("Please provide a proper message number"); return(true); } File message = process.computer.fileSystem.RootFile.GetFileAtPath($"mail/users/{client.loggedInAccount.accountName}/Inbox/{number}.json"); if (message == null) { process.Print("That message doesn't exist!"); return(true); } MailMessage messageObject = new MailMessage(message); process.Print(messageObject.Body); return(true); }
public static bool Ban(CommandProcess process, string[] commandUnsplit) { GameClient client = ((ServerAdmin)process).client; List <string> command = new List <string>(); command.Add("ban"); command.AddRange(commandUnsplit[1].Split()); if (client.permissions.Contains(HackLinks_Server.Permissions.Admin) == false && client.permissions.Contains(HackLinks_Server.Permissions.Ban) == false) { process.Print("Insufficent Privileges"); return(true); } if (command.Count < 3) { process.Print("Usage: ban [username] [unban (t/f)] [permban (t/f)] [days] [hr] [mins]"); return(true); } if (command.Count < 4) { Server.Instance.DatabaseLink.SetUserBanStatus(command[1], command[3] == "t" ? -1 : 0, false); return(true); } int days = Convert.ToInt32(command[4]); int hours = command.Count <= 6 ? Convert.ToInt32(command[5]) : 0; int minutes = command.Count <= 7 ? Convert.ToInt32(command[6]) : 0; days = days * 86400; hours = hours * 3600; minutes = minutes * 60; int banExpiry = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds() + days + hours + minutes; if (!Server.Instance.DatabaseLink.SetUserBanStatus(command[1], banExpiry, false)) { process.Print("The user does not exist in the user database"); } return(true); }
public static bool Ls(CommandProcess process, string[] command) { File root = process.computer.fileSystem.rootFile; if (command.Length == 2) { foreach (File file in process.ActiveDirectory.children) { if (command[1] == file.Name) { process.Print($"File {file.Name} > Owner '{process.computer.GetUsername(file.OwnerId)}' Group '{file.Group}' Permissions '{Permissions.PermissionHelper.PermissionToDisplayString(file.Permissions)}'"); return(true); } } process.Print("File " + command[1] + " not found."); return(true); } else { List <string> fileList = new List <string>(new string[] { process.ActiveDirectory.Name }); foreach (File file in process.ActiveDirectory.children) { if (file.HasReadPermission(process.Credentials)) { fileList.AddRange(new string[] { file.Name, (file.IsFolder() ? "d" : "f"), (file.HasWritePermission(process.Credentials) ? "w" : "-") }); } else { Logger.Warning($"User {process.computer.GetUsername(process.Credentials.UserId)} doesn't have permission for {file.Name} {file.Group} {file.Permissions.PermissionValue}"); } } process.computer.Kernel.LS(process, fileList.ToArray()); return(true); } }
public static bool View(CommandProcess process, string[] command) { if (command.Length < 2) { process.Print("Usage : view [file]"); return(true); } var cmdArgs = command[1].Split(' '); if (cmdArgs.Length != 1) { process.Print("Usage : view [file]"); return(true); } var activeDirectory = process.ActiveDirectory; var file = activeDirectory.GetFile(cmdArgs[0]); if (file == null) { process.Print("File " + cmdArgs[0] + " not found."); return(true); } if (file.IsFolder()) { process.Print("You cannot display a directory."); return(true); } if (!file.HasReadPermission(process.Credentials)) { process.Print("Permission denied."); return(true); } process.computer.Kernel.Display(process, "view", file.Name, file.Content); return(true); }