예제 #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);
            }

            StarryboundServer.sendGlobalMessage(this.player.name + " " + message, "#f49413");
            return(true);
        }
예제 #2
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);
            }
        }
        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);
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
            }
        }