public HomeController(IConfiguration configuration, PacketRepository packetRepository) { _trustedKey = configuration["Application:KeyAuthorization:TrustedKey"]; _path = configuration["Application:KeyAuthorization:Path"]; _site = configuration["Application:KeyAuthorization:KeyValidationSite"]; _packetRepository = packetRepository; }
/// <summary> /// Sends a game packet to the client. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="channel"></param> /// <param name="context"></param> public static void SendGamePacket <T>(IChannel channel, T context) where T : PacketContext { var packet = PacketRepository.GetPacketEncoder(context) as PacketEncoder <T>; Preconditions.Check.NotNull(packet, $"Packet not found for context {context.ToString()}").Encode(context); channel.WriteAndFlushAsync(new GamePacketResponse(packet.GetId(), packet.GetPacketType(), packet.GetBuilder())); }
/// <summary> /// Reads the inbound data. /// </summary> /// <param name="context"></param> /// <param name="message"></param> public void MessageRead(IChannelHandlerContext context, object message) { if (message.GetType() == typeof(GamePacketRequest)) { var request = (GamePacketRequest)message; int id = request.GetId(); var packet = PacketRepository.GetPacketDecoder(id); //dont use preconditions because it doesnt need to throw some exception. if (packet == null) { Console.WriteLine($"Incoming packet not implemented: {id}."); return; } packet.Decode(request.GetPlayer(), id, new PacketReader(request.GetPayload())); } }
public PacketFeaturesService(PacketRepository repo) { _repo = repo; }
public PacketService(PacketRepository PacketRepository) { _PacketRepository = PacketRepository; }
/// <summary> /// apply your validations inside the method /// </summary> /// <param name="data"></param> /// <returns></returns> private ExcelUploadResponseModel ApplyValidation(DataTable data) { IRepository <Product> productRepository = new ProductRepository(_unitOfWork); IRepository <Packet> packetRepsitory = new PacketRepository(_unitOfWork); List <ErrorMessageModel> errorMessageModels = new List <ErrorMessageModel>(); if (data == null) { throw new InvalidOperationException(); } // performing the validation here if (data.Rows.Count == 0) { throw new IndexOutOfRangeException(); } var products = productRepository.GetAll(); var packets = packetRepsitory.GetAll(); var inputData = data.ToListof <InputDataModelV1>(); int row = 0; int count = inputData.Count(); List <ProductDetail> productDetailsList = new List <ProductDetail>(); inputData.RemoveAll((inputModel) => { bool canDelete = false; var errorMessageModel = new ErrorMessageModel(row); var packet = packets.FirstOrDefault(p => p.PacketCode.Equals(inputModel.Packet, StringComparison.InvariantCultureIgnoreCase)); if (packet == null) { errorMessageModel.ErrorMessagees.Add($" Row {row}, packet code {inputModel.Packet} does not exists"); canDelete = true; } var product = products.FirstOrDefault(p => p.ProductCode.Equals(inputModel.Product, StringComparison.InvariantCultureIgnoreCase)); if (product == null) { errorMessageModel.ErrorMessagees.Add($" Row {row}, product code {inputModel.Packet} does not exists"); canDelete = true; } row++; if (canDelete) { errorMessageModels.Add(errorMessageModel); } else { productDetailsList.Add(new ProductDetail { ProductId = product.ProductId, PacketId = packet.PacketId //add the other values over here }); } return(canDelete); }); if (productDetailsList.Count() == count) { IRepository <ProductDetail> productDetailrepository = new ProductDetailRepository(_unitOfWork); productDetailsList.ForEach(detaiils => { productDetailrepository.Insert(detaiils); }); _unitOfWork.SaveChanges(); return(new ExcelUploadResponseModel(null)); } return(new ExcelUploadResponseModel(errorMessageModels)); //save functionality here }
public void LoadCharacterData() { Character character = new Character(_player, _characterId); Common.Networking.Client.OriginClient dbClient = GameService.GetDbClient(); PacketBuilder bldr = new PacketBuilder(Common.Database.Opcodes.LOAD_GAME_CHARACTER); bldr.WriteInt(_player.index); bldr.WriteInt(_characterId); bldr.WriteInt(GameService.GetServerId()); dbClient.Write(bldr.ToPacket(), (_data, _length) => { byte response = (_data[0]); // If the response was not 0 (0 is success), then we delete the character instance and cancel loading if (response != 0) { PacketBuilder responseBldr = new PacketBuilder(Common.Packets.Opcodes.CHARACTER_SELECTION); // Write a failed opcode responseBldr.WriteByte(response); responseBldr.WriteByte((byte)character.GetIndex()); character.Write(responseBldr.ToPacket()); return; } else { PacketBuilder responseBldr = new PacketBuilder(Common.Packets.Opcodes.CHARACTER_SELECTION); responseBldr.WriteByte(response); responseBldr.WriteByte((byte)character.GetIndex()); Common.Database.Structs.Game.CharacterLoadInfo info = new Common.Database.Structs.Game.CharacterLoadInfo(); info = Serializer.Deserialize <Common.Database.Structs.Game.CharacterLoadInfo>(_data.Skip(1).ToArray()); character.name = Encoding.UTF8.GetString(info.name).TrimEnd('\0'); character.profession = info.profession; character.race = info.race; character.mode = info.mode; character.statPoints = info.statPoints; character.skillPoints = info.skillPoints; character.gold = info.gold; character.kills = info.kills; character.deaths = info.deaths; character.victories = info.victories; character.defeats = info.defeats; character.guildId = info.guildId; character.GetPosition().Set(info.mapId, info.positionX, info.positionY, info.positionHeight, info.direction); var attributes = character.GetAttributes(); attributes.level = info.level; attributes.strength = info.strength; attributes.dexterity = info.dexterity; attributes.resistance = info.resistance; attributes.intelligence = info.intelligence; attributes.wisdom = info.wisdom; attributes.luck = info.luck; attributes.currentHp = info.currentHp; attributes.currentMp = info.currentMp; attributes.currentSp = info.currentSp; character.Write(responseBldr.ToPacket()); // TODO: Start loading character's details, skills, items, buffs, bars etc... PacketRepository.SendCharacterData(character); PacketRepository.SendAp(character.GetPlayer()); } }); }