Ejemplo n.º 1
0
        public async Task HandleAsync(IGameWebSocketConnection connection, GamePacket packet)
        {
            var result = false;

            if (packet.Data is CharacterSkillUpdate update)
            {
                result = this.playerManager.UpdateExperience(
                    connection.SessionToken,
                    update.UserId,
                    update.Level,
                    update.Experience,
                    update.CharacterId);
            }
            else
            {
                logger.LogError("CharacterSkillUpdate package received but the packet data did not contain the proper structure.");
            }

            //await connection.ReplyAsync(packet.CorrelationId, packet.Type, result, CancellationToken.None);
        }
Ejemplo n.º 2
0
        public GamePacket Deserialize(byte[] data, int length)
        {
            var packet = new GamePacket();

            using (var ms = new MemoryStream(data, 0, length))
                using (var br = new BinaryReader(ms))
                {
                    packet.Id            = br.ReadString();
                    packet.Type          = br.ReadString();
                    packet.CorrelationId = new Guid(br.ReadBytes(br.ReadInt32()));

                    var dataSize = br.ReadInt32();
                    var payload  = br.ReadBytes(dataSize);

                    packet.Data = loadedTypes.TryGetValue(packet.Type, out var targetType)
                    ? binarySerializer.Deserialize(payload, targetType)
                    : payload;
                }
            return(packet);
        }
        public async Task HandleAsync(IGameWebSocketConnection connection, GamePacket packet)
        {
            var result = false;

            if (connection == null)
            {
                logger.LogError("Connection dropped during saving.");
                return;
            }
            if (connection.SessionToken == null && packet != null)
            {
                logger.LogError("SessionToken is null. UpdateCharacterExperiencePacketHandler:" + packet.Data);
                return;
            }

            if (packet.TryGetValue <CharacterExpUpdate>(out var update))
            {
                if (connection.SessionToken.Expired)
                {
                    logger.LogError("Trying to saving character but session expired. " + connection.SessionToken.SessionId);
                    return;
                }

                result = this.playerManager.UpdateExperience(
                    connection.SessionToken,
                    update.SkillIndex,
                    update.Level,
                    update.Experience,
                    update.CharacterId);
            }
            else
            {
                logger.LogError("CharacterExpUpdate package received but the packet data did not contain the proper structure.");
            }

            //await connection.ReplyAsync(packet.CorrelationId, packet.Type, result, CancellationToken.None);
        }
 public Task HandleAsync(
     IWebSocketConnection connection,
     GamePacket packet)
 {
     return(logger.WriteErrorAsync($"Unsupported packet received with id: {packet.Id}. payload type: {packet.Type}"));
 }
Ejemplo n.º 5
0
        public async Task HandleAsync(IGameWebSocketConnection connection, GamePacket packet)
        {
            var result = false;

            await connection.ReplyAsync(packet.CorrelationId, packet.Type, result, CancellationToken.None);
        }
Ejemplo n.º 6
0
 public abstract void Handle(GamePacket packet);
Ejemplo n.º 7
0
 public override void Handle(GamePacket packet)
 {
 }