Ejemplo n.º 1
0
        public override async Task Handle(ChatSentPacket packet, SharpStarClient client)
        {
            SharpStarMain.Instance.PluginManager.CallEvent("chatSent", packet, client);

            string message = packet.Message;

            if (message.StartsWith("/"))
            {
                string[] ex = message.Substring(1).Split(' ');

                string cmd = ex[0];

                string[] args = ex.Skip(1).ToArray();

                if (cmd.Equals("createacct", StringComparison.OrdinalIgnoreCase) && SharpStarMain.Instance.Config.ConfigFile.EnableAccounts)
                {
                    if (client.Server.Player.UserAccount != null)
                    {
                        client.SendChatMessage("Server", "You are already logged into an account!");
                    }
                    else if (args.Length == 2)
                    {
                        string username = args[0];
                        string password = args[1];

                        if (SharpStarMain.Instance.Database.AddUser(username, password))
                        {
                            client.SendChatMessage("Server", "Account created! Please reconnect with your login details.");
                        }
                        else
                        {
                            client.SendChatMessage("Server", "Account already exists!");
                        }
                    }
                    else
                    {
                        client.SendChatMessage("Server", "Syntax: /createacct <username> <password>");
                    }

                    packet.Ignore = true;
                }
                else
                {
                    if (!SharpStarMain.Instance.Config.ConfigFile.AllowedStarboundCommands.Any(p => p.Equals(cmd, StringComparison.OrdinalIgnoreCase)))
                    {
                        if (!await SharpStarMain.Instance.PluginManager.PassChatCommand(client, cmd, args).ConfigureAwait(false))
                        {
                            client.SendChatMessage("Server", "Unknown Command!");
                        }

                        packet.Ignore = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static bool CanUserAccess(this SharpStarClient client, string command, bool sendMsg = false)
        {
            if (client.IsAdmin())
            {
                return(true);
            }

            var cmds = SharpStarMain.Instance.PluginManager.CSPluginManager.Commands;

            var cmd = cmds.SingleOrDefault(p => p.Item1 == command);

            if (cmd == null || cmd.Item4)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(cmd.Item3))
            {
                return(true);
            }

            bool hasPerm = client.Server.Player.HasPermission(cmd.Item3);

            if (!hasPerm && sendMsg)
            {
                client.SendChatMessage("Server", "You do not have permission to use this command!");
            }

            return(hasPerm);
        }
Ejemplo n.º 3
0
 public virtual void OnCommandPermissionDenied(SharpStarClient client, string command)
 {
     client.SendChatMessage("Server", String.Format("Permission denied for command {0}!", command));
 }