Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 6
0
        void RecvSaveFriends(IIPSocket conn, BitStream r)
        {
            var account = TryGetAccount(conn);
            if (account == null)
                return;

            account.SetFriends(r.ReadString());
        }
Exemplo n.º 7
0
        void RecvLogin(IIPSocket conn, BitStream r)
        {
            ThreadAsserts.IsMainThread();

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

            Server.LoginAccount(conn, name, password);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 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();
 }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
 }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 20
0
        void RecvReceivePrivateMessage(IIPSocket conn, BitStream r)
        {
            string Message = r.ReadString();
            string PrivateMessage = Message;

            // Display the private message
            GameplayScreen.AppendToChatOutput(Message, Color.BlueViolet);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 24
0
 void RecvChat(IIPSocket conn, BitStream r)
 {
     var text = r.ReadString(GameData.MaxServerSayLength);
     GameplayScreen.AppendToChatOutput(text);
 }