Ejemplo n.º 1
0
        public void FromBytes(byte[] bytes, IChannelToServerZone channelToServerZone)
        {
            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream))
                {
                    while (stream.Position < stream.Length)
                    {
                        var code = reader.ReadByte();
                        switch (code)
                        {
                        case 11:
                        {
                            var entityId      = reader.ReadInt32();
                            var invokePayload = (IInvokePayload)ProtobufStreamHelper.ReadObject(
                                reader, TypeTable, TypeModel);
                            channelToServerZone.Invoke(ClientId, entityId, invokePayload);
                            break;
                        }

                        case 12:
                        {
                            var entityId           = reader.ReadInt32();
                            var trackableDataIndex = reader.ReadByte();
                            var tracker            = (ITracker)ProtobufStreamHelper.ReadObject(
                                reader, TypeTable, TypeModel);
                            channelToServerZone.UpdateChange(ClientId, entityId, trackableDataIndex, tracker);
                            break;
                        }

                        default:
                            throw new Exception("Invalid code: " + code);
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        public void FromBytes(byte[] bytes, IChannelToClientZone channelToClientZone)
        {
            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream))
                {
                    while (stream.Position < stream.Length)
                    {
                        var code = reader.ReadByte();
                        switch (code)
                        {
                        case 1:
                        {
                            var clientId    = reader.ReadInt32();
                            var startTime   = reader.ReadInt64();
                            var elapsedTime = reader.ReadInt64();
                            channelToClientZone.Init(clientId,
                                                     new DateTime(startTime, DateTimeKind.Utc),
                                                     new TimeSpan(elapsedTime));
                            break;
                        }

                        case 2:
                        {
                            var entityId  = reader.ReadInt32();
                            var typeAlias = reader.ReadInt32();
                            var ownerId   = reader.ReadInt32();
                            var flags     = (EntityFlags)reader.ReadByte();
                            var payload   = (ISpawnPayload)ProtobufStreamHelper.ReadObject(reader, TypeTable, TypeModel);
                            channelToClientZone.Spawn(entityId, TypeTable.GetType(typeAlias), ownerId, flags, payload);
                            break;
                        }

                        case 3:
                        {
                            var entityId = reader.ReadInt32();
                            channelToClientZone.Despawn(entityId);
                            break;
                        }

                        case 4:
                        {
                            var entityId = reader.ReadInt32();
                            var payload  = (IInvokePayload)ProtobufStreamHelper.ReadObject(reader, TypeTable, TypeModel);
                            channelToClientZone.Invoke(entityId, payload);
                            break;
                        }

                        case 5:
                        {
                            var entityId = reader.ReadInt32();
                            var payload  =
                                (IUpdateChangePayload)ProtobufStreamHelper.ReadObject(reader, TypeTable, TypeModel);
                            channelToClientZone.UpdateChange(entityId, payload);
                            break;
                        }

                        case 6:
                        {
                            var entityId = reader.ReadInt32();
                            var ownerId  = reader.ReadInt32();
                            channelToClientZone.OwnershipChange(entityId, ownerId);
                            break;
                        }

                        default:
                            throw new Exception("Invalid code: " + code);
                        }
                    }
                }
        }