public object Deserialize(BMSByte buffer)
 {
     return(new Quaternion(buffer.GetBasicType <float>(),
                           buffer.GetBasicType <float>(),
                           buffer.GetBasicType <float>(),
                           buffer.GetBasicType <float>()));
 }
예제 #2
0
 /// <summary>
 /// Get a Vector2 out of a FrameStream
 /// </summary>
 /// <param name="stream">FrameStream to be used</param>
 /// <returns>A Vector2 out of the FrameStream</returns>
 public object MapVector2(BMSByte stream)
 {
     return(new Vector2(
                stream.GetBasicType <float>(),
                stream.GetBasicType <float>()
                ));
 }
예제 #3
0
        /// <summary>
        /// Get a mapped value out of the BMSByte
        /// </summary>
        /// <typeparam name="T">Value to get out of it</typeparam>
        /// <param name="stream">BMSByte to be used</param>
        /// <returns>Returns a mapped value from the BMSByte</returns>
        /// <summary>
        ///从BMSByte中获取映射值
        /// </ summary>
        /// <typeparam name =“T”>值类型Class</ typeparam>
        /// <param name =“stream”>要使用的BMSByte </ param>
        /// <returns>返回来自BMSByte的映射值 </ returns>
        public virtual T Map <T>(BMSByte stream)
        {
            object obj         = null;
            var    genericType = typeof(T);

            if (genericType == typeof(string))
            {
                obj = stream.GetBasicType <string>();
            }
            else if (genericType == typeof(Vector))
            {
                obj = stream.GetBasicType <Vector>();
            }
            else if (genericType.IsArray)
            {
                obj = MapArray(genericType, stream);
            }
            else if (genericType == typeof(BMSByte))
            {
                obj = MapBMSByte(stream);
            }
            else if (genericType.IsEnum)
            {
                obj = MapBasicType(Enum.GetUnderlyingType(genericType), stream);
            }
            else
            {
                obj = MapBasicType(genericType, stream);
            }

            return((T)obj);
        }
예제 #4
0
        /// <summary>
        /// Map a type of object from a BMSByte to a object
        /// </summary>
        /// <param name="type">Type of object to map</param>
        /// <param name="stream">BMSByte to be used</param>
        /// <returns>Returns the mapped object</returns>
        public virtual object Map(Type type, BMSByte stream)
        {
            object obj = null;

            if (type == typeof(string))
            {
                obj = stream.GetBasicType <string>();
            }
            else if (type == typeof(Vector))
            {
                obj = stream.GetBasicType <Vector>();
            }
            else if (type.IsArray)
            {
                obj = MapArray(type, stream);
            }
            else if (type == typeof(BMSByte))
            {
                obj = MapBMSByte(stream);
            }
            else if (type.IsEnum)
            {
                obj = MapBasicType(Enum.GetUnderlyingType(type), stream);
            }
            else
            {
                obj = MapBasicType(type, stream);
            }

            return(obj);
        }
예제 #5
0
 public void Desrialize(BMSByte buffer)
 {
     CurrentPlayers = buffer.GetBasicType <ushort>();
     MaxPlayers     = buffer.GetBasicType <ushort>();
     ServerName     = buffer.GetBasicType <string>();
     ServerType     = buffer.GetBasicType <string>();
     Port           = buffer.GetBasicType <ushort>();
 }
예제 #6
0
    public void VerifyResponse(NetWorker networker, NetworkingPlayer player, BMSByte response, System.Action <NetworkingPlayer> authUserAction, System.Action <NetworkingPlayer> rejectUserAction)
    {
        uint id;

        switch (status)
        {
        case Server.AuthStatus.Available:
            id = response.GetBasicType <uint>();

            BinaryFormatter binFor    = new BinaryFormatter();
            MemoryStream    memStream = new MemoryStream();

            byte[] bytes = response.GetByteArray(sizeof(uint));
            memStream.Write(bytes, 0, bytes.Length);
            memStream.Position = 0;

            List <uint> ids = binFor.Deserialize(memStream) as List <uint>;

            if (ids.Contains(id))
            {
                ids.Remove(id);
                authUserAction(player);
                status     = Server.AuthStatus.Checking;
                allowedIds = ids;
            }
            else
            {
                rejectUserAction(player);
            }

            //uint[] ids = ObjectMapper.Instance.Map<uint[]>(response);
            break;

        case Server.AuthStatus.Checking:
            id = response.GetBasicType <uint>();
            if (allowedIds.Contains(id))
            {
                authUserAction(player);
                allowedIds.Remove(id);
            }
            else
            {
                rejectUserAction(player);
            }
            return;

        case Server.AuthStatus.Closed:
            rejectUserAction(player);
            return;
        }
    }
        public void ReconstructMessagePage(BMSByte page, EndPoint sender)
        {
            Sender = sender;
            if (MessageReconstructed)
            {
                return;
            }

            if (page.Size == 0)
            {
                throw new ArgumentException($"The input page buffer had an invalid size of 0");
            }

            var pageNumber = page.GetBasicType <int>();
            var totalSize  = page.GetBasicType <int>();

            if (page.Size == 0)
            {
                throw new ArgumentException($"The input page buffer had an invalid size of 0");
            }

            if (page.Size + page.StartPointer == totalSize)
            {
                MessageBuffer.Append(page);
                MessageReconstructed = true;
            }
            else
            {
                if (_pages == null)
                {
                    double actualSize = page.StartPointer + page.Size;
                    MessageBuffer.SetArraySize(totalSize);
                    int count = (int)System.Math.Ceiling(totalSize / actualSize);
                    _pages = new BMSByte[count];
                }
                if (_pages[pageNumber] == null)
                {
                    _pages[pageNumber] = _bufferPool.Get(page.Size);
                    _pages[pageNumber].Clone(page);
                }
                if (IsDone())
                {
                    foreach (var p in _pages)
                    {
                        MessageBuffer.Append(p);
                        _bufferPool.Release(p);
                    }
                    MessageReconstructed = true;
                }
            }
        }
        public object Deserialize(BMSByte buffer)
        {
            int length = buffer.GetBasicType <int>();

            ServerListingEntry[] listing = new ServerListingEntry[length];
            for (int i = 0; i < length; i++)
            {
                listing[i] = new ServerListingEntry
                {
                    Address = buffer.GetBasicType <string>(),
                    Port    = buffer.GetBasicType <ushort>()
                };
            }
            return(listing);
        }
        private byte PullPacketMetadata(BMSByte packet)
        {
            byte meta = packet.GetBasicType <byte>(packet.Size - sizeof(byte));

            packet.SetSize(packet.Size - sizeof(byte));
            return(meta);
        }
        private int PullPacketOrderId(BMSByte packet)
        {
            // This assumes that packet metadata was pulled first
            int orderId = packet.GetBasicType <int>(packet.Size - sizeof(int));

            packet.SetSize(packet.Size - sizeof(int));
            return(orderId);
        }
        private int PullPacketGroupId(BMSByte packet)
        {
            // This assumes that packet order id was pulled first
            int groupId = packet.GetBasicType <int>(packet.Size - sizeof(int));

            packet.SetSize(packet.Size - sizeof(int));
            return(groupId);
        }
예제 #12
0
        /// <summary>
        /// Get a Vector4 out of a FrameStream
        /// </summary>
        /// <param name="type">Type of object to be mapped</param>
        /// <param name="stream">FrameStream to be used</param>
        /// <returns>A type of Vector4 (Vector4/Color/Quaternion) out of the FrameStream</returns>
        public object MapVector4(Type type, BMSByte stream)
        {
            x = stream.GetBasicType <float>();
            y = stream.GetBasicType <float>();
            z = stream.GetBasicType <float>();
            w = stream.GetBasicType <float>();

            if (type == typeof(Color))
            {
                return(new Color(x, y, z, w));
            }
            else if (type == typeof(Quaternion))
            {
                return(new Quaternion(x, y, z, w));
            }

            return(new Vector4(x, y, z, w));
        }
예제 #13
0
        protected override void ReadDirtyFields(BMSByte data, ulong timestep)
        {
            byte[] readFlags = new byte[dirtyFields.Length];
            Buffer.BlockCopy(data.byteArr, data.StartIndex(), readFlags, 0, readFlags.Length);
            data.MoveStartIndex(readFlags.Length);

            // Check to see if the field was sent as dirty
            if ((0x1 & readFlags[0]) != 0)
            {
                num = data.GetBasicType <int>();
            }

            Console.WriteLine("Read data and num is now " + Num);
        }
        private ulong PullPacketUniqueId(BMSByte packet, bool endPacket)
        {
            // This assumes that packet group id was pulled first
            ulong uniqueId = packet.GetBasicType <ulong>(packet.Size - sizeof(ulong));

            // Don't set the size like in the others unless it is the end packet
            // because the frame will consume this time step The frame expects
            // the last bytes in the message to be the time step
            if (!endPacket)
            {
                packet.SetSize(packet.Size - sizeof(ulong));
            }

            return(uniqueId);
        }
예제 #15
0
    public void AcceptChallenge(NetWorker networker, BMSByte challenge, Action <BMSByte> authServerAction, Action rejectServerAction)
    {
        Server.AuthStatus status = challenge.GetBasicType <Server.AuthStatus>();

        switch (status)
        {
        case Server.AuthStatus.Available:

            List <uint> memberIds = new List <uint>();

            /*foreach (Friend f in ourLobby.Members)
             * {
             *  memberIds.Add(f.Id.AccountId);
             * }*/

            BMSByte response = ObjectMapper.BMSByte(SteamClient.SteamId.AccountId);

            BinaryFormatter binFor    = new BinaryFormatter();
            MemoryStream    memStream = new MemoryStream();
            binFor.Serialize(memStream, memberIds);

            //response.Append(ObjectMapper.BMSByte(memberIds.ToArray()));
            response.Append(ObjectMapper.BMSByte(memStream.ToArray()));
            authServerAction(response);

            memStream.Close();
            return;

        case Server.AuthStatus.Checking:
            authServerAction(ObjectMapper.BMSByte(SteamClient.SteamId.AccountId));
            return;

        case Server.AuthStatus.Closed:
            rejectServerAction();
            return;
        }

        /*
         * BMSByte by = new BMSByte();
         * var binFormatter = new BinaryFormatter();
         * var mStream = new MemoryStream();
         * binFormatter.Serialize(mStream, allowedSteamIDs);
         *
         * var data = ObjectMapper.BMSByte(mStream.ToArray());
         *
         * authServerAction(data);
         */
    }
        public IMessageConstructor ReconstructPacketPage(BMSByte buffer, EndPoint sender)
        {
            int messageId = buffer.GetBasicType <int>();
            IMessageConstructor constructor = null;

            if (_messageConstructors.TryGetValue(sender, out var constructors))
            {
                foreach (var c in constructors)
                {
                    if (c.Id == messageId)
                    {
                        constructor = c;
                        ContinueProcessingExistingConstructor(buffer, constructor, sender);
                        break;
                    }
                }
            }

            if (constructor == null)
            {
                constructor = ProcessNewConstructor(buffer, messageId, sender);
            }
            return(constructor);
        }
예제 #17
0
 public object Deserialize(BMSByte buffer)
 {
     return(buffer.GetBasicType <ulong>());
 }
예제 #18
0
 public void Deserialize(BMSByte buffer)
 {
     Type        = buffer.GetBasicType <byte>();
     ChallengeId = (uint)System.Net.IPAddress.NetworkToHostOrder((int)buffer.GetBasicType <uint>());
 }
예제 #19
0
        /// <summary>
        /// Map a generic array from the BMSBytes
        /// </summary>
        /// <param name="type">The type of the array</param>
        /// <param name="bytes">The bytes to read from</param>
        /// <returns>The array that was found</returns>
        public object MapArray(Type type, BMSByte bytes)
        {
            //获取数组中的维数。
            int rank = type.GetArrayRank();
            // 当在派生类中重写时,返回当前数组、指针或引用类型包含的或引用的对象的 Type。
            Type targetType = type.GetElementType();

            if (targetType != typeof(byte))
            {
                throw new Exception("Currently only byte arrays can be sent as arrays");
            }

            if (rank > 4)
            {
                throw new Exception("Currently the system only supports up to 4 dimensions in an array");
            }

            int i, j, k, l;

            // Read each dimension length first
            int[] lengths = new int[rank];
            for (i = 0; i < rank; i++)
            {
                lengths[i] = bytes.GetBasicType <int>();
            }

            switch (rank)
            {
            case 1:
                byte[] arr1 = new byte[lengths[0]];

                for (i = 0; i < lengths[0]; i++)
                {
                    arr1[i] = bytes.GetBasicType <byte>();
                }

                return(arr1);

            case 2:
                byte[,] arr2 = new byte[lengths[0], lengths[1]];

                for (i = 0; i < lengths[0]; i++)
                {
                    for (j = 0; j < lengths[1]; j++)
                    {
                        arr2[i, j] = bytes.GetBasicType <byte>();
                    }
                }

                return(arr2);

            case 3:
                byte[,,] arr3 = new byte[lengths[0], lengths[1], lengths[2]];

                for (i = 0; i < lengths[0]; i++)
                {
                    for (j = 0; j < lengths[1]; j++)
                    {
                        for (k = 0; k < lengths[2]; k++)
                        {
                            arr3[i, j, k] = bytes.GetBasicType <byte>();
                        }
                    }
                }

                return(arr3);

            case 4:
                byte[,,,] arr4 = new byte[lengths[0], lengths[1], lengths[2], lengths[3]];

                for (i = 0; i < lengths[0]; i++)
                {
                    for (j = 0; j < lengths[1]; j++)
                    {
                        for (k = 0; k < lengths[2]; k++)
                        {
                            for (l = 0; l < lengths[3]; l++)
                            {
                                arr4[i, j, k, l] = bytes.GetBasicType <byte>();
                            }
                        }
                    }
                }

                return(arr4);
            }

            return(null);
        }
예제 #20
0
 /// <summary>
 /// Get a mapped basic type of object from the BMSByte
 /// </summary>
 /// <param name="type">Type of object to be mapped</param>
 /// <param name="stream">BMSByte to be used</param>
 /// <returns>Returns a mapped object of the given type</returns>
 public object MapBasicType(Type type, BMSByte stream)
 {
     if (type == typeof(sbyte))
     {
         return(unchecked ((sbyte)stream.GetBasicType <byte>()));
     }
     else if (type == typeof(byte))
     {
         return(stream.GetBasicType <byte>());
     }
     else if (type == typeof(char))
     {
         return(unchecked ((char)stream.GetBasicType <byte>()));
     }
     else if (type == typeof(short))
     {
         return(stream.GetBasicType <short>());
     }
     else if (type == typeof(ushort))
     {
         return(stream.GetBasicType <ushort>());
     }
     else if (type == typeof(bool))
     {
         return(stream.GetBasicType <bool>());
     }
     else if (type == typeof(int))
     {
         return(stream.GetBasicType <int>());
     }
     else if (type == typeof(uint))
     {
         return(stream.GetBasicType <uint>());
     }
     else if (type == typeof(float))
     {
         return(stream.GetBasicType <float>());
     }
     else if (type == typeof(long))
     {
         return(stream.GetBasicType <long>());
     }
     else if (type == typeof(ulong))
     {
         return(stream.GetBasicType <ulong>());
     }
     else if (type == typeof(double))
     {
         return(stream.GetBasicType <double>());
     }
     else if (type == typeof(string))
     {
         return(stream.GetBasicType <string>());
     }
     else if (type == typeof(Vector))
     {
         return(stream.GetBasicType <Vector>());
     }
     else
     {
         // TODO:  Make this an object mapper exception
         throw new BaseNetworkException("The type " + type.ToString() + " is not allowed to be sent over the Network (yet)");
     }
 }
예제 #21
0
 public void Deserialize(BMSByte buffer)
 {
     Header.Deserialize(buffer);
     Version         = (ushort)System.Net.IPAddress.NetworkToHostOrder((short)buffer.GetBasicType <ushort>());
     RequestedChunks = buffer.GetBasicType <byte>();
 }
예제 #22
0
 /// <summary>
 /// Map a string from the BMSByte
 /// </summary>
 /// <param name="stream">BMSByte to be used</param>
 /// <returns>Returns a string out of the BMSByte</returns>
 public object MapString(BMSByte stream)
 {
     return(stream.GetBasicType <string>());
 }
예제 #23
0
 public object Deserialize(BMSByte buffer)
 {
     return(new Vector3(buffer.GetBasicType <float>(),
                        buffer.GetBasicType <float>(),
                        buffer.GetBasicType <float>()));
 }
예제 #24
0
 protected override void ReadPayload(BMSByte payload, ulong timestep)
 {
     num = payload.GetBasicType <int>();
 }
 public override void Deserialize(BMSByte buffer)
 {
     MapId = buffer.GetBasicType <string>();
 }
예제 #26
0
        public object Deserialize(BMSByte buffer)
        {
            int length = buffer.GetBasicType <int>();

            return(buffer.GetByteRange(length));
        }