/// <summary>
        /// Reads an array of values from a <see cref="BitStream"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        /// <param name="count">The number of values to read.</param>
        /// <returns>The array of read values.</returns>
        public static string[] ReadStrings(this BitStream bs, int count)
        {
            var ret = new string[count];

            for (var i = 0; i < count; i++)
            {
                ret[i] = bs.ReadString();
            }
            return(ret);
        }
        void RecvNotifyGetItem(IIPSocket conn, BitStream r)
        {
            var name = r.ReadString();
            var amount = r.ReadByte();

            string msg;
            if (amount > 1)
                msg = string.Format("You got {0} {1}s", amount, name);
            else
                msg = string.Format("You got a {0}", name);

            GameplayScreen.InfoBox.Add(msg);
        }
        void RecvCreateAccountCharacter(IIPSocket conn, BitStream r)
        {
            var successful = r.ReadBool();
            var errorMessage = successful ? string.Empty : r.ReadString();

            if (ReceivedCreateAccountCharacter != null)
                ReceivedCreateAccountCharacter.Raise(conn, new CreateAccountEventArgs(successful, errorMessage));
        }
        void RecvChatSay(IIPSocket conn, BitStream r)
        {
            var name = r.ReadString(GameData.MaxServerSayNameLength);
            var mapEntityIndex = r.ReadMapEntityIndex();
            var text = r.ReadString(GameData.MaxServerSayLength);

            var chatText = CreateChatText(name, text);
            GameplayScreen.AppendToChatOutput(chatText);

            var entity = Map.GetDynamicEntity(mapEntityIndex);
            if (entity == null)
                return;

            GameplayScreen.AddChatBubble(entity, text);
        }
示例#5
0
        /// <summary>
        /// Handles <see cref="GroupInfoMessages.AddMember"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        void ReadAddMember(BitStream bs)
        {
            var name = bs.ReadString();

            if (!_members.Contains(name, _membersListComparer))
                _members.Add(name);
            else
            {
                const string errmsg = "Tried to add `{0}` to the group member list, but they were already in the list!";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, name);
                Debug.Fail(string.Format(errmsg, name));
            }

            // Raise events
            OnMemberAdded(name);

            if (MemberAdded != null)
                MemberAdded.Raise(this, EventArgsHelper.Create(name));
        }
        void RecvSaveFriends(IIPSocket conn, BitStream r)
        {
            var account = TryGetAccount(conn);
            if (account == null)
                return;

            account.SetFriends(r.ReadString());
        }
        void RecvLogin(IIPSocket conn, BitStream r)
        {
            ThreadAsserts.IsMainThread();

            var name = r.ReadString();
            var password = r.ReadString();

            Server.LoginAccount(conn, name, password);
        }
        void RecvCreateNewAccount(IIPSocket conn, BitStream r)
        {
            ThreadAsserts.IsMainThread();

            var name = r.ReadString();
            var password = r.ReadString();
            var email = r.ReadString();

            // Ensure the connection isn't logged in
            var user = TryGetUser(conn, false);
            if (user != null)
            {
                const string errmsg = "User `{0}` tried to create a new account while already logged in.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, user);
                return;
            }

            // Create the new account
            Server.CreateAccount(conn, name, password, email);
        }
        void RecvStartShopping(IIPSocket conn, BitStream r)
        {
            var shopOwnerIndex = r.ReadMapEntityIndex();
            var canBuy = r.ReadBool();
            var name = r.ReadString();
            var itemCount = r.ReadByte();

            var items = new IItemTemplateTable[itemCount];
            for (var i = 0; i < itemCount; i++)
            {
                var value = new ItemTemplateTable();
                value.ReadState(r);
                items[i] = value;
            }

            var shopOwner = Map.GetDynamicEntity(shopOwnerIndex);
            var shopInfo = new ShopInfo<IItemTemplateTable>(shopOwner, name, canBuy, items);

            GameplayScreen.ShopForm.DisplayShop(shopInfo);
        }
示例#10
0
 /// <summary>
 /// Reads the <see cref="GuildInfoMessages.UpdateNameTag"/> message.
 /// </summary>
 /// <param name="r">The stream to read the message from.</param>
 void ReadUpdateNameTag(BitStream r)
 {
     Name = r.ReadString();
     Tag = r.ReadString();
 }
示例#11
0
        /// <summary>
        /// Reads the <see cref="GuildInfoMessages.SetGuild"/> message.
        /// </summary>
        /// <param name="r">The stream to read the message from.</param>
        void ReadSetGuild(BitStream r)
        {
            _members.Clear();
            _onlineMembers.Clear();

            InGuild = r.ReadBool();

            if (InGuild)
            {
                Name = r.ReadString();
                Tag = r.ReadString();

                var numMembers = r.ReadUShort();
                for (var i = 0; i < numMembers; i++)
                {
                    var v = r.ReadGuildMemberNameRank(null);
                    _members.Add(v);
                }

                var onlineMembers = r.ReadUShort();
                for (var i = 0; i < onlineMembers; i++)
                {
                    var name = r.ReadString();
                    SetOnlineValue(name, true);
                }

                _members.Sort();
            }

            OnGuildChanged();

            if (GuildChanged != null)
                GuildChanged.Raise(this, EventArgs.Empty);
        }
示例#12
0
        /// <summary>
        /// Reads the <see cref="GuildInfoMessages.RemoveOnlineMember"/> message.
        /// </summary>
        /// <param name="r">The stream to read the message from.</param>
        void ReadRemoveOnlineMember(BitStream r)
        {
            var name = r.ReadString();
            SetOnlineValue(name, false);

            OnOnlineMemberRemoved(name);

            if (OnlineMemberRemoved != null)
                OnlineMemberRemoved.Raise(this, EventArgsHelper.Create(name));
        }
示例#13
0
        /// <summary>
        /// Reads the <see cref="GuildInfoMessages.RemoveMember"/> message.
        /// </summary>
        /// <param name="r">The stream to read the message from.</param>
        void ReadRemoveMember(BitStream r)
        {
            var name = r.ReadString();
            var removeCount = _members.RemoveAll(x => StringComparer.OrdinalIgnoreCase.Equals(x.Name, name));

            Debug.Assert(removeCount != 0, "Nobody with the name " + name + " existed in the collection.");
            Debug.Assert(removeCount < 2, "How the hell did we remove more than one item?");

            OnMemberRemoved(name);

            if (MemberRemoved != null)
                MemberRemoved.Raise(this, EventArgsHelper.Create(name));
        }
示例#14
0
        /// <summary>
        /// Handles <see cref="GroupInfoMessages.SetGroup"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        void ReadSetGroup(BitStream bs)
        {
            _members.Clear();
            _founder = null;

            var isInGroup = bs.ReadBool();

            if (isInGroup)
            {
                // Read the group members
                var numMembers = bs.ReadByte();
                var members = bs.ReadStrings(numMembers);
                _members.AddRange(members);

                // Read the founder's name
                _founder = bs.ReadString();
            }

            // Raise events
            OnGroupChanged();

            if (GroupChanged != null)
                GroupChanged.Raise(this, EventArgs.Empty);
        }
示例#15
0
        /// <summary>
        /// Handles <see cref="GroupInfoMessages.RemoveMember"/>.
        /// </summary>
        /// <param name="bs">The <see cref="BitStream"/> to read from.</param>
        void ReadRemoveMember(BitStream bs)
        {
            var name = bs.ReadString();

            if (!_members.Remove(name))
            {
                const string errmsg = "Tried to remove `{0}` from the group member list, but they were not in the list!";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, name);
                Debug.Fail(string.Format(errmsg, name));
            }

            // Raise events
            OnMemberRemoved(name);

            if (MemberRemoved != null)
                MemberRemoved.Raise(this, EventArgsHelper.Create(name));
        }
示例#16
0
        void RecvSetCharacterPaperDoll(IIPSocket conn, BitStream r)
        {
            var mapEntityIndex = r.ReadMapEntityIndex();
            var count = r.ReadByte();

            var layers = new string[count];
            for (var i = 0; i < layers.Length; i++)
            {
                layers[i] = r.ReadString();
            }

            var character = _objGrabber.GetDynamicEntity<Character>(mapEntityIndex);
            if (character == null)
                return;

            character.CharacterSprite.SetPaperDollLayers(layers);
        }
示例#17
0
 /// <summary>
 /// Reads a variable-length string of up to 65535 characters in length.
 /// </summary>
 /// <param name="name">Unused by the <see cref="BinaryValueReader"/>.</param>
 /// <returns>String read from the reader.</returns>
 public string ReadString(string name)
 {
     return(_reader.ReadString());
 }
示例#18
0
        void RecvReceiveFriends(IIPSocket conn, BitStream r)
        {
            List<String> _onlineFriends = new List<String>();
            _onlineFriends = r.ReadString().Split(',').ToList<string>();
            string[] FriendsMap = r.ReadString().Split(',');
            string[] FriendsList = r.ReadString().Split(',');

            _onlineFriends.RemoveAll(x => x == "");
            int i = 0;
            FriendsForm._myFriends = new List<Friends>();

            foreach (string friend in _onlineFriends)
            {
                FriendsForm._myFriends.Add(new Friends
                {
                    Name = friend,
                    Map = FriendsMap[i],
                    Online = true
                });
            }

            foreach (string _friend in FriendsList)
            {
                FriendsForm._myFriends.Add(new Friends
                {
                    Name = _friend,
                    Online = false
                });

                i++;
            }

            FriendsForm._myFriends.RemoveDuplicates((x, y) => x.Name == y.Name);
            FriendsForm._myFriends.RemoveAll((x) => x.Name == "");
            FriendsForm.SortList();
        }
示例#19
0
        void RecvCreateNewAccountCharacter(IIPSocket conn, BitStream r)
        {
            ThreadAsserts.IsMainThread();

            var name = r.ReadString();

            // Check for a valid account
            var account = TryGetAccount(conn);
            if (account == null)
            {
                const string errmsg =
                    "Connection `{0}` tried to create a new account character but no account is associated with this connection.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, conn);
                return;
            }

            // Ensure the connection isn't logged in
            if (account.User != null)
            {
                const string errmsg = "User `{0}` tried to create a new account character while already logged in.";
                if (log.IsWarnEnabled)
                    log.WarnFormat(errmsg, account.User);
                return;
            }

            // Create the new account character
            Server.CreateAccountCharacter(conn, name);
        }
示例#20
0
        void RecvReceivePrivateMessage(IIPSocket conn, BitStream r)
        {
            string Message = r.ReadString();
            string PrivateMessage = Message;

            // Display the private message
            GameplayScreen.AppendToChatOutput(Message, Color.BlueViolet);
        }
示例#21
0
        void RecvSay(IIPSocket conn, BitStream r)
        {
            var text = r.ReadString(GameData.MaxClientSayLength);

            User user;
            if ((user = TryGetUser(conn)) == null)
                return;

            _sayHandler.Process(user, text);
        }
示例#22
0
        void RecvReceiveOnlineUsers(IIPSocket conn, BitStream r)
        {
            List<String> online = r.ReadString().Split(';').ToList();
            online.RemoveAll(x => x.IsEmpty());

            foreach (string user in online)
                OnlineUsersForm.Online.Add(user);

            OnlineUsersForm.Online.RemoveDuplicates((x, y) => x == y);
            OnlineUsersForm.Online.RemoveAll(x => x.IsEmpty());
            OnlineUsersForm.UpdateUsersList();
        }
示例#23
0
        void RecvSendPrivateMessage(IIPSocket conn, BitStream r)
        {

            string TargetName = r.ReadString();
            string Text = r.ReadString();

            // Get the user to send the message to
            User TargetChar = World.FindUser(TargetName);

            string PrivateMessage = TargetName + " Says: " + Text;

            using (var pw = ServerPacket.ReceivePrivateMessage(PrivateMessage))
            {
                TargetChar.Send(pw, ServerMessageType.GUIChat);
            }
        }
示例#24
0
 void RecvChat(IIPSocket conn, BitStream r)
 {
     var text = r.ReadString(GameData.MaxServerSayLength);
     GameplayScreen.AppendToChatOutput(text);
 }