Esempio n. 1
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string message = string.Join(" ", args).Trim();

            if (message == null || message.Length < 1)
            {
                showHelpText(); return(false);
            }

            if (this.player.group.hasPermission("admin.chat"))
            {
                message = "^#f75d5d;[ADMIN] " + this.player.name + ": " + message;
            }
            else
            {
                message = "^#ff00c7;Message to admins from " + this.player.name + ": " + message;
            }

            foreach (Client client in StarryboundServer.getClients())
            {
                if (client.playerData.group.hasPermission("admin.chat") || client == this.client)
                {
                    client.sendChatMessage(message);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public static User GetUser(string name, string uuid, string ip)
        {
            if (File.Exists(Path.Combine(UsersPath, name.ToLower() + ".json")))
            {
                try
                {
                    User user = Read(Path.Combine(UsersPath, name.ToLower() + ".json"), new string[] { name, uuid });
                    return(user);
                }
                catch (Exception)
                {
                    StarryboundServer.logError("Player data for user " + name.ToLower() + " with UUID " + uuid + " is corrupt. Re-generating user file");

                    User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, true, true, false, new List <string>(), new List <string>());
                    Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                    return(user);
                }
            }
            else
            {
                User user = new User(name, uuid, ip, StarryboundServer.defaultGroup, false, true, 0, false, false, false, new List <string>(), new List <string>());
                Write(Path.Combine(UsersPath, name.ToLower() + ".json"), user);

                return(user);
            }
        }
Esempio n. 3
0
        public static void GenerateSAKey()
        {
            if (!File.Exists(Path.Combine(StarryboundServer.SavePath, "authcode.txt")))
            {
                var r = new Random((int)DateTime.Now.ToBinary());
                StarryboundServer.authCode = r.Next(100000, 10000000).ToString();

                using (var tw = new StreamWriter(Path.Combine(StarryboundServer.SavePath, "authcode.txt")))
                {
                    tw.WriteLine(StarryboundServer.authCode);
                }
            }
            else
            {
                using (var tr = new StreamReader(Path.Combine(StarryboundServer.SavePath, "authcode.txt")))
                {
                    StarryboundServer.authCode = tr.ReadLine();
                }
            }

            StarryboundServer.logWarn("************************************************************************");
            StarryboundServer.logWarn("Important notice: To become SuperAdmin, you need to join the game and type /auth " + StarryboundServer.authCode);
            StarryboundServer.logWarn("This token will display until disabled by verification and is usable by any player.");
            StarryboundServer.logWarn("************************************************************************");
        }
Esempio n. 4
0
        public override bool doProcess(string[] args)
        {
            if (args.Length < 1)
            {
                this.client.sendCommandMessage("Incorrect auth code. This incident has been logged.");
                StarryboundServer.logWarn(this.client.playerData.name + " (IP: " + this.client.playerData.ip + ") attempted to use /auth even though it was disabled.");
                return(false);
            }

            string code = args[0];

            if (code != StarryboundServer.authCode)
            {
                this.client.sendCommandMessage("Incorrect auth code. This incident has been logged.");
                StarryboundServer.logWarn(this.client.playerData.name + " (IP: " + this.client.playerData.ip + ") attempted to use /auth even though it was disabled.");
                return(false);
            }

            this.client.playerData.group = StarryboundServer.groups["superadmin"];
            Users.SaveUser(this.client.playerData);
            StarryboundServer.authCode = null;

            if (File.Exists(Path.Combine(StarryboundServer.SavePath, "authcode.txt")))
            {
                File.Delete(Path.Combine(StarryboundServer.SavePath, "authcode.txt"));
            }

            this.client.sendCommandMessage("Thank you for installing Starrybound v" + StarryboundServer.VersionNum + "!");
            this.client.sendCommandMessage("You are now superadmin, your setup is now complete.");
            this.client.sendCommandMessage("You can use /group adduser <username> <group> to provide access to other users.");

            return(true);
        }
Esempio n. 5
0
 public static WorldCoordinate findGlobalCoords(byte[] input)
 {
     try
     {
         for (int i = 0; i < input.Length - 26; i++)
         {
             foreach (byte[] sector in StarryboundServer.sectors)
             {
                 byte[] buffer = new byte[sector.Length];
                 Buffer.BlockCopy(input, i, buffer, 0, sector.Length);
                 if (sector.SequenceEqual(buffer))
                 {
                     byte[] returnBytes = new byte[sector.Length + 21];
                     Buffer.BlockCopy(input, i - 1, returnBytes, 0, sector.Length + 21);
                     BinaryReader    coords  = new BinaryReader(new MemoryStream(returnBytes));
                     WorldCoordinate rCoords = coords.ReadStarWorldCoordinate();
                     if (String.IsNullOrEmpty(rCoords._syscoord._sector))
                     {
                         rCoords = null;
                     }
                     return(rCoords);
                 }
             }
         }
         return(null);
     }
     catch (Exception e)
     {
         StarryboundServer.logDebug("findGlobalCoords", "Exception: " + e.ToString());
         return(null);
     }
 }
Esempio n. 6
0
 static User Read(string path, string[] data)
 {
     using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         User file = Read(fs, data);
         StarryboundServer.logInfo("Loaded persistant user storage for " + file.name);
         return(file);
     }
 }
Esempio n. 7
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            StarryboundServer.changeState(ServerState.GracefulShutdown, "Command::Shutdown", "Shutdown requested by " + this.player.name);
            return(true);
        }
Esempio n. 8
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string player = string.Join(" ", args).Trim();

            uint warp;

            if (player == null || player.Length < 1)
            {
                this.client.sendCommandMessage("Teleporting to your ship.");

                player = "";
                warp   = (uint)WarpType.WarpToOwnShip;
            }
            else
            {
                if (!hasPermission(true))
                {
                    permissionError(2); return(false);
                }

                Client target = StarryboundServer.getClient(player);
                if (target != null)
                {
                    PlayerData targetPlayer = target.playerData;
                    if (!this.player.canAccessShip(targetPlayer))
                    {
                        this.client.sendCommandMessage("You cannot access this player's ship due to their ship's access settings.");
                        return(false);
                    }
                    this.client.sendCommandMessage("Teleporting to " + player + " ship!");

                    warp = (uint)WarpType.WarpToPlayerShip;
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + player + "' not found.");
                    return(false);
                }
            }

            MemoryStream packetWarp  = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            packetWrite.WriteBE(warp);
            packetWrite.Write(new WorldCoordinate());
            packetWrite.WriteStarString(player);
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());

            return(true);
        }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
        public override bool doProcess(string[] args)
        {
            //if (!hasPermission()) { permissionError(); return false; }

            string message = string.Join(" ", args).Trim();

            if (message == null || message.Length < 1)
            {
                showHelpText(); return(false);
            }

            StarryboundServer.sendGlobalMessage(this.player.name + " " + message, "#f49413");
            return(true);
        }
Esempio n. 11
0
        public static List <Group> Read(string path)
        {
            if (!File.Exists(path))
            {
                return(DefaultGroups());
            }

            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                List <Group> file = Read(fs);
                StarryboundServer.logInfo("Starrybound groups loaded successfully.");
                return(file);
            }
        }
Esempio n. 12
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>()));
     }
 }
Esempio n. 13
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());
     }
 }
Esempio n. 14
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string player;
            string reason;

            if (args.Length > 1)
            {
                player = args[0].Trim();
                reason = string.Join(" ", args).Substring(player.Length + 1).Trim();
            }
            else
            {
                player = string.Join(" ", args).Trim();
                reason = "breaking the rules";
            }

            if (player == null || player.Length < 1)
            {
                showHelpText(); return(false);
            }

            Client target = StarryboundServer.getClient(player);

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

            if (target != null)
            {
                target.kickClient(reason);
                return(true);
            }
            else
            {
                this.client.sendCommandMessage("Player '" + player + "' not found.");
                return(false);
            }
        }
Esempio n. 15
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string player = string.Join(" ", args).Trim();

            WorldCoordinate loc = this.player.loc;

            if (player == null || player.Length < 1)
            {
                showHelpText();
                return(false);
            }
            else
            {
                Client target = StarryboundServer.getClient(player);
                if (target != null)
                {
                    loc = target.playerData.loc;
                    if (loc == null)
                    {
                        this.client.sendCommandMessage("Unable to find an exact location for " + player + ".");
                        return(false);
                    }
                    this.client.sendCommandMessage("Warping ship to " + player + " [" + loc.ToString() + "]");
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + player + "' not found.");
                    return(false);
                }
            }

            MemoryStream packetWarp  = new MemoryStream();
            BinaryWriter packetWrite = new BinaryWriter(packetWarp);

            packetWrite.WriteBE((uint)WarpType.MoveShip);
            packetWrite.Write(loc);
            packetWrite.WriteStarString("");
            client.sendServerPacket(Packet.WarpCommand, packetWarp.ToArray());
            return(true);
        }
Esempio n. 16
0
        public static void ProcessGroups(List <Group> groupList)
        {
            try
            {
                string defaultGroup = null;

                foreach (Group group in groupList)
                {
                    StarryboundServer.groups.Add(group.name, group);
                    if (group.isDefault)
                    {
                        defaultGroup = group.name;
                    }
                }

                if (String.IsNullOrWhiteSpace(defaultGroup))
                {
                    StarryboundServer.logFatal("Default user group flag (isDefault) is not set for any groups - Please set this in the groups.json!");
                    Thread.Sleep(5000);
                    Environment.Exit(5);
                }

                foreach (Group groupCheck in StarryboundServer.groups.Values)
                {
                    if (!String.IsNullOrWhiteSpace(groupCheck.parent))
                    {
                        if (!StarryboundServer.groups.ContainsKey(groupCheck.parent))
                        {
                            throw new RankException("Parent (" + groupCheck.parent + ") for group " + groupCheck.name + " does not exist!");
                        }
                    }
                }

                StarryboundServer.defaultGroup = defaultGroup;

                StarryboundServer.logInfo("Loaded " + StarryboundServer.groups.Count + " group(s). Default group is " + defaultGroup);
            }
            catch (RankException e)
            {
                StarryboundServer.logFatal("A fatal exception occurred while processing the groups (Groups::ProcessGroups): " + e.ToString());
                Thread.Sleep(5000);
                Environment.Exit(5);
            }
        }
        public override object onReceive()
        {
            BinaryReader packetData = (BinaryReader)this.stream;

            bool   success      = packetData.ReadBoolean();
            uint   clientID     = packetData.ReadVarUInt32();
            string rejectReason = packetData.ReadStarString();

            Client target = StarryboundServer.getClient(clientID);

            if (target != null)
            {
                target.forceDisconnect(direction, "The parent server reclaimed this clientId");
                StarryboundServer.logError("[" + this.client.playerData.name + "] " + direction + ": The parent server reclaimed this clientId (" + clientID + ")");
                return(true);
            }

            this.client.playerData.id = clientID;
            PlayerData player = this.client.playerData;

            if (!success)
            {
                this.client.rejectPreConnected("Connection Failed: Rejected by parent server: " + rejectReason);
                return(true);
            }

            StarryboundServer.addClient(this.client);

            string geoip_prefix = "";

            if (StarryboundServer.config.enableGeoIP && StarryboundServer.Geo != null)
            {
                var code    = StarryboundServer.Geo.TryGetCountryCode(IPAddress.Parse(player.ip));
                var geo_loc = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code);
                geoip_prefix = String.Format("({0})", geo_loc);
            }

            StarryboundServer.sendGlobalMessage(String.Format("{0}{1} has joined the server!", player.name, geoip_prefix));
            this.client.state = ClientState.Connected;
            StarryboundServer.logInfo(String.Format("[{0}][{1}] joined with UUID [{2}]{3}", this.client.playerData.client, this.client.playerData.ip, player.uuid,
                                                    geoip_prefix != "" ? String.Format(" from {0}", geoip_prefix) : ""));

            return(true);
        }
Esempio n. 18
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string player = string.Join(" ", args).Trim();

            if (player == null || player.Length < 1)
            {
                showHelpText(); return(false);
            }

            Client target = StarryboundServer.getClient(player);

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

            if (target != null)
            {
                PlayerData pData = target.playerData;

                pData.canBuild = !pData.canBuild;

                if (!pData.canBuild)
                {
                    StarryboundServer.sendGlobalMessage("^#f75d5d;" + pData.name + " has had their build rights revoked!");
                }
                else
                {
                    StarryboundServer.sendGlobalMessage("^#6cdb67;" + pData.name + " has been granted build rights on the server.");
                }
                return(true);
            }
            else
            {
                this.client.sendCommandMessage("Player '" + player + "' not found.");
                return(false);
            }
        }
Esempio n. 19
0
        public static string ReloadGroups()
        {
            try
            {
                Dictionary <string, Group> tmpDict = new Dictionary <string, Group>();

                List <Group> groupList    = GroupFile.Read(GroupsPath);
                string       defaultGroup = null;

                foreach (Group group in groupList)
                {
                    tmpDict.Add(group.name, group);
                    if (group.isDefault)
                    {
                        defaultGroup = group.name;
                    }
                }

                if (String.IsNullOrWhiteSpace(defaultGroup))
                {
                    StarryboundServer.logFatal("Default user group flag (isDefault) is not set for any groups - Please set this in the groups.json!");
                    return("isDefault flag is not set for any group!");
                }

                var buffer = StarryboundServer.getClients();
                foreach (Client client in buffer)
                {
                    if (!tmpDict.ContainsKey(client.playerData.group.name))
                    {
                        StarryboundServer.logInfo("Updating user " + client.playerData.name + " to default group (" + defaultGroup + ") as old group " + client.playerData.group.name + " has been deleted.");
                        client.playerData.group = tmpDict[defaultGroup];
                    }
                }

                StarryboundServer.defaultGroup = defaultGroup;
                StarryboundServer.groups       = tmpDict;

                StarryboundServer.logInfo("Loaded " + StarryboundServer.groups.Count + " group(s). Default group is " + defaultGroup);
                return(null);
            }
            catch (Exception) { return("Command handler threw an exception!"); }
        }
Esempio n. 20
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string message = string.Join(" ", args).Trim();

            if (message == null || message.Length < 1)
            {
                showHelpText(); return(false);
            }

            message = "[Broadcast]: " + message;

            StarryboundServer.sendGlobalMessage(message);

            return(true);
        }
Esempio n. 21
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            string player = string.Join(" ", args).Trim();

            if (player == null || player.Length < 1)
            {
                if (this.client.playerData.loc == null)
                {
                    this.client.sendCommandMessage("Unable to find your exact location at this time.");
                    return(false);
                }
                this.client.sendCommandMessage("You are located [" + this.player.loc.ToString() + "]");
                return(true);
            }
            else
            {
                Client target = StarryboundServer.getClient(player);
                if (target != null)
                {
                    PlayerData playerData = target.playerData;
                    if (playerData.loc == null)
                    {
                        this.client.sendCommandMessage("Unable to find an exact location for " + player + ".");
                        return(false);
                    }
                    this.client.sendCommandMessage(player + " located at [" + playerData.loc.ToString() + "]" + (playerData.inPlayerShip ? "in a ship." : ""));
                    return(true);
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + player + "' not found.");
                    return(false);
                }
            }
        }
Esempio n. 22
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            if (StarryboundServer.restartTime != 0)
            {
                StarryboundServer.sendGlobalMessage("^#f75d5d;The server restart has been aborted by " + this.player.name);
                StarryboundServer.logWarn("The server restart has been aborted.");
                StarryboundServer.changeState(ServerState.Running, "Command::Restart");
                StarryboundServer.restartTime = 0;
            }
            else
            {
                StarryboundServer.sendGlobalMessage("^#f75d5d;The server will restart in 30 seconds. We will be back shortly.");
                StarryboundServer.logWarn("The server will restart in 30 seconds.");
                StarryboundServer.restartTime = Utils.getTimestamp() + 30;
            }

            return(true);
        }
        public override Object onReceive()
        {
            byte   context  = stream.ReadByte();
            string world    = stream.ReadStarString();
            uint   clientID = stream.ReadUInt32BE();
            string name     = stream.ReadStarString();
            string message  = stream.ReadStarString();

            Client target = StarryboundServer.getClient(clientID);

            if (target != null)
            {
                target.playerData.serverName = name;
                string formatName = target.playerData.formatName;
                if (!String.IsNullOrEmpty(formatName))
                {
                    client.sendChatMessage((ChatReceiveContext)context, world, clientID, formatName, message);
                    return(false);
                }
            }

            return(null);
        }
Esempio n. 24
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            if (this.client.playerData.loc == null)
            {
                this.client.sendCommandMessage("Unable to find your exact location at this time.");
                return(false);
            }

            string list = "";

            foreach (Client otherClient in StarryboundServer.getClients())
            {
                PlayerData otherPlayer = otherClient.playerData;
                if (otherPlayer.loc == null)
                {
                    continue;
                }
                else if (this.player.isInSameWorldAs(otherPlayer) && this.player.name != otherPlayer.name)
                {
                    list += otherPlayer.name + ", ";
                }
            }
            if (list.Length != 0)
            {
                this.client.sendChatMessage("^#5dc4f4;Players in this world: " + list.Substring(0, list.Length - 2));
            }
            else
            {
                this.client.sendChatMessage("^#5dc4f4;There are no other players in this world.");
            }
            return(true);
        }
Esempio n. 25
0
        public override bool doProcess(string[] args)
        {
            string staffListO = "";
            string userListO  = "";

            int noOfUsers = StarryboundServer.clientCount;
            int i         = 0;

            foreach (Group group in StarryboundServer.groups.Values)
            {
                if (group.isStaff)
                {
                    List <Client> clients = StarryboundServer.getClients(group.name);
                    foreach (Client client in clients)
                    {
                        this.staffList.Add(client);
                    }
                }
                else
                {
                    List <Client> clients = StarryboundServer.getClients(group.name);
                    foreach (Client client in clients)
                    {
                        this.userList.Add(client);
                    }
                }
            }

            this.client.sendChatMessage("^#5dc4f4;There are " + noOfUsers + "/" + StarryboundServer.config.maxClients + " player(s) online.");

            foreach (Client staffMember in this.staffList)
            {
                staffListO = staffListO + "^shadow,yellow;" + staffMember.playerData.formatName + "^#5dc4f4;";
                if (i != staffList.Count - 1)
                {
                    staffListO = staffListO + ", ";
                }
                i++;
            }

            i = 0;

            foreach (Client player in this.userList)
            {
                userListO = userListO + "^shadow,yellow;" + player.playerData.formatName + "^#5dc4f4;";
                if (i != userList.Count - 1)
                {
                    userListO = userListO + ", ";
                }
                i++;
            }

            if (staffList.Count > 0)
            {
                this.client.sendChatMessage("Staff: " + staffListO);
            }
            if (userList.Count > 0)
            {
                this.client.sendChatMessage("Players: " + userListO);
            }

            return(true);
        }
Esempio n. 26
0
        public override Object onReceive()
        {
            byte[] assetDigest = stream.ReadStarByteArray();

            var claim = stream.ReadStarVariant();

            byte[] UUID    = stream.ReadStarUUID();
            string name    = stream.ReadStarString();
            string species = stream.ReadStarString();

            byte[] shipWorld = stream.ReadStarByteArray();
            string account   = stream.ReadStarString();

            // Identify player to server
            this.client.playerData.uuid    = Utils.ByteArrayToString(Utils.HashUUID(UUID)).ToLower();
            this.client.playerData.name    = name;
            this.client.playerData.account = account;

            User userPData = Users.GetUser(name, this.client.playerData.uuid, this.client.playerData.ip);

            if (StarryboundServer.config.maxClients <= StarryboundServer.clientCount)
            {
                if (!userPData.getGroup().hasPermission("admin.reservedlist") || StarryboundServer.clientCount == (StarryboundServer.serverConfig.maxPlayers - 1))
                {
                    this.client.rejectPreConnected("The server is full. Please try again later.");
                    return(false);
                }
            }

            string[] reasonExpiry = Bans.checkForBan(new string[] { name, this.client.playerData.uuid, this.client.playerData.ip });
            if (reasonExpiry.Length == 2 && !userPData.getGroup().hasPermission("admin.bypassban"))
            {
                this.client.rejectPreConnected("You are " + ((reasonExpiry[1] == "0") ? "permanently" : "temporarily") + " banned from this server.\nReason: " + reasonExpiry[0]);
                return(false);
            }

            string sAssetDigest = Utils.ByteArrayToString(assetDigest);

            StarryboundServer.logDebug("AssetDigest", "[" + this.client.playerData.client + "] [" + sAssetDigest + "]");
            if (!StarryboundServer.config.allowModdedClients)
            {
                if (sAssetDigest != StarryboundServer.unmoddedClientDigest)
                {
                    this.client.rejectPreConnected("Modded client detected: You cannot modify or add asset files or mods. Please delete your entire Starbound folder and reinstall Starbound to join.");
                    return(false);
                }
            }

            if (String.IsNullOrWhiteSpace(this.client.playerData.name))
            {
                this.client.rejectPreConnected("You may not have a blank name.");
                return(false);
            }

            if (!StarryboundServer.config.allowSpaces)
            {
                if (this.client.playerData.name.Contains(" "))
                {
                    this.client.rejectPreConnected("You may not have spaces in your name on this server.");
                    return(false);
                }
            }

            if (!StarryboundServer.config.allowSymbols)
            {
                Regex r = new Regex("^[a-zA-Z0-9_\\- ]*$");
                if (!r.IsMatch(this.client.playerData.name))
                {
                    this.client.rejectPreConnected("You may not have special characters in your name on this server.");
                    return(false);
                }
            }

            if (!userPData.getGroup().hasPermission("admin.bypassban"))
            {
                foreach (string bannedUnamePhrase in StarryboundServer.config.bannedUsernames)
                {
                    if (this.client.playerData.name.ToLower().Contains(bannedUnamePhrase.ToLower()))
                    {
                        this.client.rejectPreConnected("Your name contains a phrase that is banned on this server. (" + bannedUnamePhrase + ")");
                        return(false);
                    }
                }
            }

            if (!String.IsNullOrEmpty(account))
            {
                this.client.rejectPreConnected("You need clear the server account field of all text.");
                return(false);
            }

            try
            {
                PlayerData pData = this.client.playerData;

                pData.isMuted            = userPData.isMuted;
                pData.canBuild           = userPData.canBuild;
                pData.lastOnline         = userPData.lastOnline;
                pData.group              = userPData.getGroup();
                pData.freeFuel           = userPData.freeFuel;
                pData.receivedStarterKit = userPData.receivedStarterKit;
                pData.privateShip        = userPData.privateShip;
                pData.shipBlacklist      = userPData.shipBlacklist;
                pData.shipWhitelist      = userPData.shipWhitelist;

                if (userPData.uuid != pData.uuid && userPData.groupName != StarryboundServer.defaultGroup)
                {
                    this.client.rejectPreConnected("Connection Failed: You cannot use \"" + pData.name + "\" on this server.");
                    return(false);
                }
            }
            catch (Exception)
            {
                this.client.rejectPreConnected("Connection Failed: A internal server error occurred (2)");
                return(false);
            }

            foreach (Client checkClient in StarryboundServer.getClients())
            {
                if (checkClient.playerData.name.ToLower() == name.ToLower())
                {
                    if (userPData.groupName != StarryboundServer.defaultGroup)
                    {
                        checkClient.delayDisconnect("Someone else is attempting to connect with your name. Disconnecting.");
                        this.client.rejectPreConnected("We have disconnected the old player on the server. Please try again in 15 seconds.");
                    }
                    else
                    {
                        this.client.rejectPreConnected("Someone is already logged in with this name.");
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Reads the data from the packet stream
        /// </summary>
        /// <returns>true to maintain packet and send to client, false to drop packet, -1 will boot the client</returns>
        public override Object onReceive()
        {
            BinaryReader packetData = (BinaryReader)this.stream;

            string message = packetData.ReadStarString();
            byte   context = packetData.ReadByte();

            #region Command Processor
            if (message.StartsWith("#"))
            {
                StarryboundServer.logInfo("[Admin Chat] [" + this.client.playerData.name + "]: " + message);

                bool aChat = new AdminChat(this.client).doProcess(new string[] { message.Remove(0, 1) });

                return(false);
            }
            else if (message.StartsWith("/"))
            {
                try
                {
                    StarryboundServer.logInfo("[Command] [" + this.client.playerData.name + "]: " + message);
                    string[] args = message.Remove(0, 1).Split(' ');
                    string   cmd  = args[0].ToLower();

                    args = parseArgs(message.Remove(0, cmd.Length + 1));

                    switch (cmd)
                    {
                    case "ban":
                        new BanC(this.client).doProcess(args);
                        break;

                    case "unban":
                        new UnbanCommand(this.client).doProcess(args);
                        break;

                    case "reload":
                        new Reload(this.client).doProcess(args);
                        break;

                    case "kick":
                        new Kick(this.client).doProcess(args);
                        break;

                    case "fuel":
                        new Fuel(this.client).doProcess(args);
                        break;

                    case "starteritems":
                        new StarterItems(this.client).doProcess(args);
                        break;

                    case "admin":
                        new AdminChat(this.client).doProcess(args);
                        break;

                    case "rules":
                        new Rules(this.client).doProcess(args);
                        break;

                    case "version":
                        new VersionC(this.client).doProcess(args);
                        break;

                    case "me":
                        new Me(this.client).doProcess(args);
                        break;

                    case "pvp":
                    case "w":
                        return(true);

                    case "nick":
                        if (this.client.playerData.hasPermission("cmd.nick"))
                        {
                            return(true);
                        }
                        else
                        {
                            this.client.sendChatMessage(ChatReceiveContext.Whisper, "", "You do not have permission to use this command.");
                        }
                        break;

                    case "who":
                    case "online":
                    case "players":
                        new List(this.client).doProcess(args);
                        break;

                    case "whosthere":
                        new WhosThere(this.client).doProcess(args);
                        break;

                    case "broadcast":
                        new Broadcast(this.client).doProcess(args);
                        break;

                    case "ship":
                        new Ship(this.client).doProcess(args);
                        break;

                    case "planet":
                        new Planet(this.client).doProcess(args);
                        break;

                    case "home":
                        new Home(this.client).doProcess(args);
                        break;

                    case "item":
                    case "give":
                        new Item(this.client).doProcess(args);
                        break;

                    case "mute":
                        new Mute(this.client).doProcess(args);
                        break;

                    case "uptime":
                        new Uptime(this.client).doProcess(args);
                        break;

                    case "shutdown":
                        new Shutdown(this.client).doProcess(args);
                        break;

                    case "restart":
                        new Restart(this.client).doProcess(args);
                        break;

                    case "build":
                        new Build(this.client).doProcess(args);
                        break;

                    case "where":
                    case "find":
                        new Find(this.client).doProcess(args);
                        break;

                    case "warpship":
                        new WarpShip(this.client).doProcess(args);
                        break;

                    case "spawn":
                        new Spawn(this.client).doProcess(args);
                        break;

                    case "group":
                        new GroupC(this.client).doProcess(args);
                        break;

                    /*
                     * case "sethome":
                     * new SetHome(this.client).doProcess(args);
                     * break;
                     */

                    case "shipaccess":
                        new ShipAccess(this.client).doProcess(args);
                        break;

                    case "help":
                    case "commands":
                    case "commandlist":
                    case "?":
                        new Help(this.client).doProcess(args);
                        break;

                    case "auth":
                        if (String.IsNullOrWhiteSpace(StarryboundServer.authCode))
                        {
                            goto default;
                        }
                        else
                        {
                            new Auth(this.client).doProcess(args);
                        }
                        break;

                    case "claim":
                        new Claim(this.client).doProcess(args);
                        break;

                    default:
                        this.client.sendCommandMessage("Command " + cmd + " not found.");
                        break;
                    }
                    return(false);
                }
                catch (Exception e)
                {
                    this.client.sendCommandMessage("Command failed: " + e.Message);
                    Console.WriteLine(e.ToString());
                }
            }
            #endregion

            if (this.client.playerData.isMuted)
            {
                this.client.sendCommandMessage("^#f75d5d;You try to speak, but nothing comes out... You have been muted.");
                return(false);
            }

            StarryboundServer.logInfo("[" + ((ChatSendContext)context).ToString() + "] [" + this.client.playerData.name + "]: " + message);
            return(true);
        }
Esempio n. 28
0
        public override bool doProcess(string[] args)
        {
            if (!hasPermission())
            {
                permissionError(); return(false);
            }

            if (args.Length < 1)
            {
                this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                return(false);
            }

            string command = args[0].Trim().ToLower();

            if (command == "list") // List all groups start
            {
                string groupList = "";
                foreach (Group group in StarryboundServer.groups.Values)
                {
                    groupList += group.name + ", ";
                }
                // TODO: Remove last comma
                this.client.sendChatMessage("^#5dc4f4;Group list: " + groupList.Substring(0, groupList.Length - 2));
                return(true);
            } // List all groups end
            else if (command == "add") // Add new group start
            {
                if (args.Length <= 1)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string groupName = args[1].Trim();
                if (String.IsNullOrEmpty(groupName) || String.IsNullOrWhiteSpace(groupName))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                Dictionary <string, bool> pPerms = new Dictionary <string, bool>();
                pPerms.Add("client.*", true);
                pPerms.Add("chat.*", true);
                Group newGroup = new Group(groupName, null, null, pPerms);
                StarryboundServer.groups.Add(newGroup.name, newGroup);
                Groups.SaveGroups();
                this.client.sendCommandMessage("New group " + newGroup.name + " has been added.");
                return(true);
            } // Add new group end
            else if (command == "adduser")
            {
                if (args.Length <= 1)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string playerName = args[1].Trim();
                string groupName  = args[2].Trim();
                if (String.IsNullOrWhiteSpace(playerName) || String.IsNullOrWhiteSpace(groupName))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                Client target = StarryboundServer.getClient(playerName);
                if (target != null)
                {
                    if (StarryboundServer.groups.ContainsKey(groupName))
                    {
                        PlayerData playerData = target.playerData;
                        playerData.group = StarryboundServer.groups[groupName];
                        this.client.sendCommandMessage("Player " + playerName + " has been added to group " + groupName + ".");
                        StarryboundServer.sendGlobalMessage(playerName + " has been assigned the group " + groupName);
                        Users.SaveUser(playerData);
                        return(true);
                    }
                    else
                    {
                        this.client.sendCommandMessage("A Group with the name " + groupName + " does not exist.");
                        return(false);
                    }
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + playerName + "' not found.");
                    return(false);
                }
            }
            else if (command == "deluser")
            {
                if (args.Length <= 1)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string playerName = args[1].Trim();
                if (String.IsNullOrWhiteSpace(playerName))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                Client target = StarryboundServer.getClient(playerName);
                if (target != null)
                {
                    PlayerData playerData = target.playerData;
                    playerData.group = StarryboundServer.groups[StarryboundServer.defaultGroup];
                    this.client.sendCommandMessage("Player " + playerName + " has had their access revoked.");
                    StarryboundServer.sendGlobalMessage(playerName + " has been demoted to " + StarryboundServer.defaultGroup);
                    Users.SaveUser(playerData);
                    return(true);
                }
                else
                {
                    this.client.sendCommandMessage("Player '" + playerName + "' not found.");
                    return(false);
                }
            }
            else if (command == "del")
            { // Delete a group start
                if (args.Length <= 1)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string groupName = args[1].Trim();
                if (String.IsNullOrEmpty(groupName) || String.IsNullOrWhiteSpace(groupName))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                if (StarryboundServer.groups.ContainsKey(groupName))
                {
                    StarryboundServer.groups.Remove(groupName);
                    Groups.SaveGroups();
                    this.client.sendCommandMessage("Group " + groupName + " has been removed.");
                    return(true);
                }
                else
                {
                    this.client.sendCommandMessage("A Group with the name " + groupName + " does not exist.");
                    return(false);
                }
            } // Delete a group end
            else if (command == "info")
            { // Group info start
                if (args.Length <= 1)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string groupName = args[1].Trim();
                if (String.IsNullOrEmpty(groupName) || String.IsNullOrWhiteSpace(groupName))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                if (StarryboundServer.groups.ContainsKey(groupName))
                {
                    Group targetGroup = StarryboundServer.groups[groupName];
                    this.client.sendCommandMessage("Group info: Name: " + targetGroup.name + "; Prefix: " + (String.IsNullOrEmpty(targetGroup.prefix) ? "None" : targetGroup.prefix) + "; Name color: " + (String.IsNullOrEmpty(targetGroup.nameColor) ? "None" : targetGroup.nameColor));
                    return(true);
                }
                else
                {
                    this.client.sendCommandMessage("A Group with the name " + groupName + " does not exist.");
                    return(false);
                }
            } // Group info end
            else if (command == "mod")
            { // Group mod start
                if (args.Length <= 3)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string groupName  = args[1].Trim();
                string modCommand = args[2].Trim().ToLower();
                string modValue   = args[3].Trim();

                if (String.IsNullOrEmpty(groupName) || String.IsNullOrEmpty(modCommand) || String.IsNullOrEmpty(modValue))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                if (StarryboundServer.groups.ContainsKey(groupName))
                {
                    Group targetGroup = StarryboundServer.groups[groupName];
                    if (modCommand == "prefix")
                    {
                        targetGroup.prefix = modValue;
                        Groups.SaveGroups();
                        this.client.sendCommandMessage("Group " + targetGroup.name + "'s prefix is now set to " + modValue);
                        return(true);
                    }
                    else if (modCommand == "color")
                    {
                        if (modValue.Length == 7 && modValue[0] == '#')
                        {
                            targetGroup.nameColor = modValue;
                            Groups.SaveGroups();
                            this.client.sendCommandMessage("Group " + targetGroup.name + "'s name color is now set to " + modValue);
                            return(true);
                        }
                        else
                        {
                            this.client.sendCommandMessage("Invalid color. Must be a hex color starting with #");
                            return(false);
                        }
                    }
                    else
                    {
                        this.client.sendCommandMessage("Invalid modification parameter. Use /group help for instructions.");
                        return(false);
                    }
                }
                else
                {
                    this.client.sendCommandMessage("A Group with the name " + groupName + " does not exist.");
                    return(false);
                }
            } // Group mod end
            else if (command == "permissions")
            { // Group permissions start
                if (args.Length <= 2)
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                string groupName  = args[1].Trim();
                string prmCommand = args[2].Trim().ToLower();

                if (String.IsNullOrEmpty(groupName) || String.IsNullOrEmpty(prmCommand))
                {
                    this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                    return(false);
                }

                if (StarryboundServer.groups.ContainsKey(groupName))
                {
                    Group targetGroup = StarryboundServer.groups[groupName];

                    if (prmCommand == "list")
                    {
                        string permissionList = "";
                        foreach (string prm in targetGroup.permissions.Keys)
                        {
                            permissionList += prm + "; ";
                        }
                        this.client.sendChatMessage("^#5dc4f4;Group permissions: " + permissionList.Substring(0, permissionList.Length - 2));
                        return(true);
                    }
                    else if (prmCommand == "add")
                    {
                        if (args.Length <= 3)
                        {
                            this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                            return(false);
                        }

                        string prmValue = args[3].Trim();
                        if (targetGroup.givePermission(prmValue))
                        {
                            Groups.SaveGroups();
                            this.client.sendCommandMessage("Permission " + prmValue + " was successfully added.");
                            return(true);
                        }
                        else
                        {
                            this.client.sendCommandMessage("Failed to add permission " + prmValue + ". Make sure it is valid.");
                            return(false);
                        }
                    }
                    else if (prmCommand == "del")
                    {
                        if (args.Length <= 3)
                        {
                            this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                            return(false);
                        }

                        string prmValue = args[3].Trim();
                        if (targetGroup.permissions.ContainsKey(prmValue))
                        {
                            targetGroup.permissions.Remove(prmValue);
                            Groups.SaveGroups();
                            this.client.sendCommandMessage("Permission " + prmValue + " was successfully removed.");
                            return(true);
                        }
                        else
                        {
                            this.client.sendCommandMessage("Failed to remove permission " + prmValue + ". Make sure the group has it.");
                            return(false);
                        }
                    }
                    else
                    {
                        this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                        return(false);
                    }
                }
                else
                {
                    this.client.sendCommandMessage("A Group with the name " + groupName + " does not exist.");
                    return(false);
                }
            }
            else if (command == "help")
            {
                this.client.sendChatMessage("^#5dc4f4;Group command help:");
                this.client.sendChatMessage("^#5dc4f4;/group list - shows a list of all groups.");
                this.client.sendChatMessage("^#5dc4f4;/group add <group name> - adds a new group.");
                this.client.sendChatMessage("^#5dc4f4;/group del <group name> - deletes a group.");
                this.client.sendChatMessage("^#5dc4f4;/group adduser <player> <group name> - adds user to a group.");
                this.client.sendChatMessage("^#5dc4f4;/group deluser <player> <group name> - demotes user to default group.");
                this.client.sendChatMessage("^#5dc4f4;/group info <group name> - shows information about a group.");
                this.client.sendChatMessage("^#5dc4f4;/group mod <group name> <prefix/color> <value> - changes a group parameter.");
                this.client.sendChatMessage("^#5dc4f4;/group permissions <group name> list - lists the permissions of a group.");
                this.client.sendChatMessage("^#5dc4f4;/group permissions <group name> <add/del> <permission> - adds or removes a permission from the group.");
                return(true);
            }
            else
            {
                this.client.sendCommandMessage("Invalid syntax. Use /group help for instructions.");
                return(false);
            }
        }
Esempio n. 29
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);
            }
        }