예제 #1
0
        public string RenameTribe(Session session, String[] parms)
        {
            bool   help         = false;
            string tribeName    = string.Empty;
            string newTribeName = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                    { "newname=", v => newTribeName = v.TrimMatchingQuotes() }
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(tribeName) || string.IsNullOrEmpty(newTribeName))
            {
                return("renametribe --tribe=name --newname=name");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }

            ITribe tribe;

            return(locker.Lock(tribeId, out tribe).Do(() =>
            {
                if (tribe == null)
                {
                    return "Tribe not found";
                }

                if (!Tribe.IsNameValid(newTribeName))
                {
                    return "New tribe name is not allowed";
                }

                if (tribeManager.TribeNameTaken(newTribeName))
                {
                    return "New tribe name is already taken";
                }

                tribe.Name = newTribeName;
                dbManager.Save(tribe);

                return "OK!";
            }));
        }
예제 #2
0
        private string RankUpdate(Session session, string[] parms)
        {
            bool   help       = false;
            string tribeName  = string.Empty;
            string rank       = string.Empty;
            string name       = string.Empty;
            string permission = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                    { "rank=", v => rank = v.TrimMatchingQuotes() },
                    { "name=", v => name = v.TrimMatchingQuotes() },
                    { "permission=", v => permission = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(tribeName) || string.IsNullOrEmpty(rank))
            {
                var str = Enum.GetNames(typeof(TribePermission)).Aggregate((s, s1) => s + "," + s1);
                return("TribeRankUpdate --rank=rank_id --tribe=tribe_name [--name=rank_name] [--Permission=Permission(" + str + ")]");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }
            ITribe tribe;

            return(locker.Lock(tribeId, out tribe).Do(() =>
            {
                ITribeRank tribeRank = tribe.Ranks.First(x => x.Id == byte.Parse(rank));
                if (tribeRank == null)
                {
                    return "Rank not found";
                }

                tribe.UpdateRank(tribeRank.Id,
                                 name == string.Empty ? tribeRank.Name : name,
                                 permission == string.Empty ? tribeRank.Permission : (TribePermission)Enum.Parse(typeof(TribePermission), permission, true));

                return "OK";
            }));
        }
예제 #3
0
        private string CmdStrongholdTransfer(Session session, string[] parms)
        {
            bool   help           = false;
            string strongholdName = string.Empty;
            string tribeName      = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "stronghold=", v => strongholdName = v.TrimMatchingQuotes() },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(strongholdName) || string.IsNullOrEmpty(tribeName))
            {
                return("StrongholdTransfer --stronghold=stronghold_name --tribe=tribe_name");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }

            ITribe tribe;

            if (!world.TryGetObjects(tribeId, out tribe))
            {
                return("Tribe not found");
            }

            IStronghold stronghold;

            if (!strongholdManager.TryGetStronghold(strongholdName, out stronghold))
            {
                return("Stronghold not found");
            }

            locker.Lock(custom => stronghold.LockList().ToArray(), null, tribe, stronghold)
            .Do(() => strongholdManager.TransferTo(stronghold, tribe));

            return("OK!");
        }
예제 #4
0
        private void GetInfoByName(Session session, Packet packet)
        {
            var    reply = new Packet(packet);
            string name;

            try
            {
                name = packet.GetString();
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            uint id;

            if (!tribeManager.FindTribeId(name, out id))
            {
                ReplyError(session, packet, Error.TribeNotFound);
                return;
            }

            ITribe tribe;

            locker.Lock(id, out tribe).Do(() =>
            {
                if (tribe == null)
                {
                    ReplyError(session, packet, Error.Unexpected);
                    return;
                }

                PacketHelper.AddTribeInfo(strongholdManager, tribeManager, session, tribe, reply);

                session.Write(reply);
            });
        }
예제 #5
0
        private string AssignmentList(Session session, string[] parms)
        {
            bool   help       = false;
            string playerName = string.Empty;
            string tribeName  = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "player=", v => playerName = v.TrimMatchingQuotes() },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(playerName) && string.IsNullOrEmpty(tribeName))
            {
                return("AssignmentList --player=player_name|--tribe=tribe_name");
            }

            uint playerId;

            if (!string.IsNullOrEmpty(playerName))
            {
                if (!world.FindPlayerId(playerName, out playerId))
                {
                    return("Player not found");
                }
            }
            else
            {
                if (!tribeManager.FindTribeId(tribeName, out playerId))
                {
                    return("Tribe not found");
                }
            }

            IPlayer player;
            ITribe  tribe;

            return(locker.Lock(playerId, out player).Do(() =>
            {
                if (player == null)
                {
                    return "Player not found";
                }

                if (!player.IsInTribe)
                {
                    return "Player does not have a tribe";
                }

                string result = string.Format("Now[{0}] Assignments:\n", DateTime.UtcNow);
                return player.Tribesman.Tribe.Assignments.Aggregate(result,
                                                                    (current, assignment) => current + assignment.ToNiceString());
            }));
        }