Example #1
0
 public static void SaveUser(PlayerData player)
 {
     try
     {
         User user = new User(player.name, player.uuid, player.ip, player.group.name, player.isMuted, player.canBuild, Utils.getTimestamp(), player.freeFuel, player.receivedStarterKit, player.privateShip, player.shipWhitelist, player.shipBlacklist);
         Write(Path.Combine(UsersPath, player.name.ToLower() + ".json"), user);
     }
     catch (Exception e)
     {
         StarryboundServer.logException("Unable to save player data file for " + player.name + ": " + e.StackTrace);
     }
 }
Example #2
0
 static User Read(Stream stream, string[] data)
 {
     try
     {
         using (var sr = new StreamReader(stream))
         {
             return(JsonConvert.DeserializeObject <User>(sr.ReadToEnd()));
         }
     }
     catch (Exception)
     {
         StarryboundServer.logException("Persistant user storage for " + data[0] + " is corrupt - Creating with default values");
         return(new User(data[0], data[1], data[2], StarryboundServer.defaultGroup, false, true, Utils.getTimestamp(), false, false, false, new List <string>(), new List <string>()));
     }
 }
Example #3
0
 public static List <Group> Read(Stream stream)
 {
     try
     {
         using (var sr = new StreamReader(stream))
         {
             return(JsonConvert.DeserializeObject <List <Group> >(sr.ReadToEnd()));
         }
     }
     catch (Exception)
     {
         StarryboundServer.logException("Server player groups are unreadable - Re-creating config with default values");
         return(DefaultGroups());
     }
 }
Example #4
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            if (args.Length < 3)
            {
                showHelpText(); return(false);
            }

            string player      = args[0].Trim();
            string expiry      = args[1].Trim();
            int    remainStuff = player.Length + expiry.Length;
            string reason      = string.Join(" ", args).Substring(remainStuff + 2).Trim();

            Client target = StarryboundServer.getClient(player);

            if (target != null)
            {
                if (!this.player.group.canTarget(target.playerData.group))
                {
                    this.client.sendCommandMessage("^#f75d5d;You do not have permission to target this user.");
                    return(false);
                }

                string uuid = target.playerData.uuid;
                string name = target.playerData.name;
                string ip   = target.playerData.ip;

                int timeNow = Utils.getTimestamp();

                try
                {
                    int bExpiry = int.Parse(expiry);

                    if (bExpiry != 0)
                    {
                        bExpiry = timeNow + (bExpiry * 60);
                    }

                    Bans.addNewBan(name, uuid, ip, timeNow, this.player.name, bExpiry, reason);

                    target.banClient(reason);

                    return(true);
                }
                catch (Exception e)
                {
                    this.client.sendCommandMessage("An exception occured while attempting to ban " + player);
                    StarryboundServer.logException("Error occured while banning player " + player + ": " + e.Message);
                    return(false);
                }
            }
            else
            {
                this.client.sendCommandMessage("Player '" + player + "' not found.");
                return(false);
            }
        }