Example #1
0
        private string Add(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 },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                    { "player=", v => playerName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

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

            uint playerId;

            if (!world.FindPlayerId(playerName, out playerId))
            {
                return("Player not found");
            }

            uint tribeId;

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

            Dictionary <uint, IPlayer> players;

            locker.Lock(out players, playerId, tribeId).Do(() =>
            {
                ITribe tribe  = players[tribeId].Tribesman.Tribe;
                var tribesman = new Tribesman(tribe, players[playerId], tribe.DefaultRank);
                tribe.AddTribesman(tribesman, true);
            });

            return("OK");
        }
Example #2
0
        public Error CreateTribe(IPlayer player, string name, out ITribe tribe)
        {
            tribe = null;

            if (player.Tribesman != null)
            {
                return(Error.TribesmanAlreadyInTribe);
            }

            if (SystemClock.Now.Subtract(player.LastDeletedTribe).TotalDays < 1)
            {
                return(Error.TribeCannotCreateYet);
            }

            if (TribeNameTaken(name))
            {
                return(Error.TribeAlreadyExists);
            }

            if (!Tribe.IsNameValid(name))
            {
                return(Error.TribeNameInvalid);
            }

            tribe = tribeFactory.CreateTribe(player, name);

            tribe.CreateRank(0, "Chief", TribePermission.All);
            tribe.CreateRank(1, "Elder", TribePermission.Invite | TribePermission.Kick | TribePermission.Repair | TribePermission.AssignmentCreate);
            tribe.CreateRank(2, "Protector", TribePermission.Repair | TribePermission.AssignmentCreate);
            tribe.CreateRank(3, "Aggressor", TribePermission.AssignmentCreate);
            tribe.CreateRank(4, "Tribesmen", TribePermission.None);

            Add(tribe);

            var tribesman = new Tribesman(tribe, player, tribe.ChiefRank);

            tribe.AddTribesman(tribesman);

            return(Error.Ok);
        }
Example #3
0
        public void Confirm(Session session, Packet packet)
        {
            bool isAccepting;

            try
            {
                isAccepting = packet.GetByte() != 0;
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            ITribe tribe = null;

            locker.Lock(session.Player).Do(() =>
            {
                if (session.Player.TribeRequest == 0)
                {
                    ReplyError(session, packet, Error.TribesmanNoRequest);
                    return;
                }

                var tribeRequestId = session.Player.TribeRequest;

                session.Player.TribeRequest = 0;
                dbManager.Save(session.Player);

                if (!isAccepting)
                {
                    ReplySuccess(session, packet);
                    return;
                }

                if (!world.TryGetObjects(tribeRequestId, out tribe))
                {
                    ReplyError(session, packet, Error.TribeNotFound);
                }
            });

            if (tribe == null)
            {
                return;
            }

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

                var tribesman = new Tribesman(tribe, session.Player, tribe.DefaultRank);

                var error = tribe.AddTribesman(tribesman);

                if (error != Error.Ok)
                {
                    ReplyError(session, packet, error);
                    return;
                }

                var reply = new Packet(packet);
                reply.AddInt32(tribeManager.GetIncomingList(tribe).Count());
                reply.AddInt16(tribe.AssignmentCount);
                PacketHelper.AddTribeRanksToPacket(tribe, reply);
                session.Write(reply);
            });
        }