コード例 #1
0
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            args = Utils.ParseArgs(args);
            ChestManager.Pending pending = (ChestManager.Pending)Enum.Parse(typeof(ChestManager.Pending), args[0], true);
            int    plr    = Main.myPlayer;
            string friend = args.Length > 1 ? args[1] : null;

            MessageSender.SendChestCommand(pending, plr, friend);
        }
コード例 #2
0
        public static void SendChestCommand(ChestManager.Pending pending, int plr, string friendName = null)
        {
            ModPacket pack = ServerSideCharacter.Instance.GetPacket();

            pack.Write((int)SSCMessageType.ChestCommand);
            pack.Write((byte)plr);
            pack.Write((int)pending);
            if (pending.HasFlag(ChestManager.Pending.AddFriend) || pending.HasFlag(ChestManager.Pending.RemoveFriend))
            {
                Player friend = Utils.TryGetPlayer(friendName);
                if (friend == null || !friend.active)
                {
                    Main.NewText("Player not found", Color.Red);
                    return;
                }
                if (friend.whoAmI == plr)
                {
                    Main.NewText("You cannot add yourself as a friend", Color.Red);
                    return;
                }
                pack.Write((byte)friend.whoAmI);
            }
            pack.Send();
        }
コード例 #3
0
        private bool RequestChestOpen(ref BinaryReader reader, int playerNumber)
        {
            if (!ServerSideCharacter.Config.EnableChestProtection)
            {
                return(false);
            }
            if (Main.netMode == 2)
            {
                int                  x       = reader.ReadInt16();
                int                  y       = reader.ReadInt16();
                int                  id      = Chest.FindChest(x, y);
                Player               player  = Main.player[playerNumber];
                ServerPlayer         sPlayer = player.GetServerPlayer();
                ChestManager.Pending pending = ServerSideCharacter.ChestManager.GetPendings(sPlayer);
                switch (pending)
                {
                case ChestManager.Pending.AddFriend:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer);
                        ServerSideCharacter.ChestManager.AddFriend(id, friend);
                        sPlayer.SendSuccessInfo($"{friend.Name} can open this chest now");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.RemoveFriend:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerPlayer friend = ServerSideCharacter.ChestManager.GetFriendP(sPlayer);
                        ServerSideCharacter.ChestManager.RemoveFriend(id, friend);
                        sPlayer.SendSuccessInfo($"{friend.Name} can't open this chest now");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Public:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        if (!ServerSideCharacter.ChestManager.IsPublic(id))
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, true);
                            sPlayer.SendSuccessInfo("This chest is now Public");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("This chest is already public");
                        }
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.UnPublic:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        if (ServerSideCharacter.ChestManager.IsPublic(id))
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                            sPlayer.SendSuccessInfo("This chest is not Public anymore");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("This chest is not public");
                        }
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Protect:
                    if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                        sPlayer.SendSuccessInfo("You now own this chest");
                    }
                    else if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        sPlayer.SendErrorInfo("You already protected this chest");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("This chest as already been protected by other player");
                    }
                    break;

                case ChestManager.Pending.DeProtect:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ServerSideCharacter.ChestManager.SetOwner(id, -1, false);
                        sPlayer.SendSuccessInfo("This chest is no longer yours");
                    }
                    else if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        sPlayer.SendErrorInfo("This chest don't have a owner");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                case ChestManager.Pending.Info:
                    if (ServerSideCharacter.ChestManager.IsOwner(id, sPlayer))
                    {
                        ChestInfo     chest = ServerSideCharacter.ChestManager.ChestInfo[id];
                        StringBuilder info  = new StringBuilder();
                        if (sPlayer.PermissionGroup.HasPermission("chest"))
                        {
                            info.AppendLine($"Owner: {ServerPlayer.FindPlayer(chest.OwnerID).Name}");                                     //For Admins
                        }
                        info.AppendLine($"Public Chest: {chest.IsPublic.ToString().ToUpper()}");
                        info.AppendLine($"Friends ({chest.Friends.Count.ToString()}): {string.Join(", ", chest.Friends.ToArray().Take(10).Select(uuid => ServerPlayer.FindPlayer(uuid).Name))}");
                        sPlayer.SendInfo(info.ToString());
                    }
                    else if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        sPlayer.SendErrorInfo("This chest don't have a owner");
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You are not the owner of this chest");
                    }
                    break;

                default:
                    if (ServerSideCharacter.ChestManager.IsNull(id))
                    {
                        if (ServerSideCharacter.Config.AutoProtectChests)
                        {
                            ServerSideCharacter.ChestManager.SetOwner(id, sPlayer.UUID, false);
                            sPlayer.SendSuccessInfo("You now own this chest");
                        }
                        else
                        {
                            sPlayer.SendErrorInfo("Use '/chest protect' to become the owner of this chest");
                        }
                        return(false);
                    }
                    else if (ServerSideCharacter.ChestManager.CanOpen(id, sPlayer))
                    {
                        return(false);
                    }
                    else
                    {
                        sPlayer.SendErrorInfo("You cannot open this chest");
                    }
                    break;
                }
                ServerSideCharacter.ChestManager.RemovePending(sPlayer, pending);
            }
            return(true);
        }