private void OnCS_UserData_UserInfo_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutStringAsUtf16(Nickname); resPacket.PutInt32(Level); resPacket.PutInt32(Exp); resPacket.PutInt32(VIPLevel); resPacket.PutInt32(VIPExp); // Energy resPacket.PutInt32(Energy.Items.Count); foreach (var energy in Energy.Items) { resPacket.PutInt32(energy.EnergyId); resPacket.PutInt32(energy.Point); resPacket.PutInt32(energy.RemainSecond); } // Resource resPacket.PutInt32(Resource.Items.Count); foreach (var resource in Resource.Items) { resPacket.PutInt32(resource.ResourceId); resPacket.PutInt32(resource.Point); } SendPacket(resPacket); }
private void OnCS_PvE_DungeonList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 4096); try { // 상위 필드정보 Int32 fieldId = reqPacket.GetInt32(); var field = GameMap.PvE_Field.Find(fieldId); // 결과 패킷 Int32 count = 0; Int32 idxCount = resPacket.PutInt32(count); foreach (var data in field.SubDungeons) { resPacket.PutInt32(data.DungeonId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.Level); resPacket.PutInt32(data.EnterFee_EnergyId); resPacket.PutInt32(data.EnterFee_Amount); ++count; } resPacket.ResultCodeNo = ResultCode.Ok; resPacket.OverwriteInt32(idxCount, count); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_GameData_CharacterBook_Req(SecurePacketRequest reqPacket) { Int32 startId = reqPacket.GetInt32(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65000); resPacket.ResultCodeNo = ResultCode.Ok; Int32 count = 0; Int32 idxCount = resPacket.PutInt32(count); foreach (var ch in CharacterBook.Data.Items .Where(v => v.CharacterId >= startId) .OrderBy(v => v.CharacterId)) { resPacket.PutInt32(ch.CharacterId); resPacket.PutStringAsUtf16(ch.Name); resPacket.PutInt32(ch.RaceId); resPacket.PutInt32(ch.CharacterTypeId); resPacket.PutInt32(ch.JobId); resPacket.PutInt32(ch.PositionId); resPacket.PutInt32(ch.DamageTypeId); resPacket.PutInt32(ch.InitGradeId); resPacket.PutInt32(ch.InitPromotionId); resPacket.PutInt32(ch.MaxGradeId); resPacket.PutInt32(ch.MaxPromotionId); resPacket.PutInt32(ch.AP); resPacket.PutInt32(ch.DP); resPacket.PutInt32(ch.HP); if (++count >= 400) break; } resPacket.OverwriteInt32(idxCount, count); SendPacket(resPacket); }
private void OnCS_UserData_InitUser_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); String nickname = reqPacket.GetStringFromUtf16(); resPacket.ResultCodeNo = InitUser(nickname); SendPacket(resPacket); }
public override StreamBuffer Clone() { SecurePacketRequest packet = new SecurePacketRequest(this); packet.ResetReadIndex(); packet.ResetWriteIndex(); packet.Read(ReadBytes); return packet; }
public SecurePacketResponse(SecurePacketRequest requestPacket, Int32 resultCode, UInt16 capacity = 0) { if (capacity > 0) Capacity(capacity); PacketId = (UInt16)(requestPacket.PacketId + 1); SeqNo = requestPacket.SeqNo; ResultCodeNo = resultCode; }
private void OnCS_Auth_Guest_Req(SecurePacketRequest reqPacket) { Int32 worldId = reqPacket.GetInt32(); String userToken = reqPacket.GetStringFromUtf16(); Boolean hasData = false; Int32 userNo = 0, authKey = 0; using (DBCommand cmd = AuthDB.NewCommand()) { cmd.CommandText.Append("select userno, authkey from t_accounts"); cmd.CommandText.Append(" where usertoken=@0;"); cmd.BindParameter("@0", userToken); cmd.PostQuery( () => { if ((hasData = cmd.Reader.Read()) == true) { userNo = cmd.Reader.GetInt32(0); authKey = cmd.Reader.GetInt32(1); } }, (exception) => { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); if (exception != null) { resPacket.ResultCodeNo = ResultCode.Database_Error; Logger.Write(LogType.Err, 2, exception.ToString()); } else if (hasData == true) { ServerInfo gameServerInfo = ServerCatalog.Items .Where(v => v.WorldId == worldId && v.Status == ServerStatus.Activate && v.ServerType == ServerType.GameServer) .OrderBy(v => v.Traffic) .FirstOrDefault(); if (gameServerInfo == null) resPacket.ResultCodeNo = ResultCode.NoAvailableServer; else { resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(userNo); resPacket.PutInt32(authKey); resPacket.PutStringAsUtf16(gameServerInfo.SystemIpAddress); resPacket.PutInt32(gameServerInfo.ListenPortNo); } } else resPacket.ResultCodeNo = ResultCode.InvalidUserToken; SendPacket(resPacket); }); } }
private void OnCS_UserData_InvenItem_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65000); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(PlayerBook.PlayerLevel.Items[Level].MaxItemInventory); resPacket.PutInt32(InvenItem.Items.Count); foreach (var item in InvenItem.Items) { resPacket.PutInt32(item.ItemNo); resPacket.PutInt32(item.Base.ItemId); resPacket.PutInt32(item.PromotionId); resPacket.PutInt32(item.Quantity); } SendPacket(resPacket); }
private void OnCS_PvE_EnterDungeon_Req(SecurePacketRequest reqPacket) { Int32 dungeonId = reqPacket.GetInt32(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { EnterDungeon(dungeonId); resPacket.ResultCodeNo = ResultCode.Ok; Int32 roundCount = 0, idxRoundCount = resPacket.PutInt32(0); foreach (var playingRound in PlayingRounds) { resPacket.PutInt32(playingRound.Round.RoundId); resPacket.PutStringAsUtf16(playingRound.Round.Name); resPacket.PutBoolean(playingRound.Round.IsBossRound); Int32 monsterCount = 0, idxMonsterCount = resPacket.PutInt32(0); foreach (var monster in playingRound.Monsters) { resPacket.PutInt32(monster.MonsterNo); resPacket.PutInt32(monster.MonsterId); resPacket.PutStringAsUtf16(monster.Base.Name); resPacket.PutInt32(monster.Base.GradeId); resPacket.PutInt32(monster.Base.PromotionId); resPacket.PutInt32(monster.Level); ++monsterCount; } resPacket.OverwriteInt32(idxMonsterCount, monsterCount); ++roundCount; } resPacket.OverwriteInt32(idxRoundCount, roundCount); } catch (AegisException e) { resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_UserData_InvenCharacter_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65000); resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(MainCharacter.CharacterNo); resPacket.PutInt32(PlayerBook.PlayerLevel.Items[Level].MaxCharacterInventory); resPacket.PutInt32(InvenCharacter.Items.Count); foreach (var ch in InvenCharacter.Items) { resPacket.PutInt32(ch.CharacterNo); resPacket.PutInt32(ch.Base.CharacterId); resPacket.PutInt32(ch.Level); resPacket.PutInt32(ch.Exp); resPacket.PutInt32(ch.GradeId); resPacket.PutInt32(ch.PromotionId); } SendPacket(resPacket); }
private void OnCS_PvE_FieldList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 4096); try { // 상위 월드정보 Int32 worldId = reqPacket.GetInt32(); var world = GameMap.PvE_World.Find(worldId); // 결과 패킷 Int32 count = 0; Int32 idxCount = resPacket.PutInt32(count); foreach (var data in world.SubFields) { resPacket.PutInt32(data.FieldId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.NeedVIPLevel); resPacket.PutInt32(data.NeedPlayerLevel); ++count; } resPacket.ResultCodeNo = ResultCode.Ok; resPacket.OverwriteInt32(idxCount, count); } catch (AegisException e) { resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_PvE_WorldList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 4096); Int32 count = 0; Int32 idxCount = resPacket.PutInt32(count); foreach (var data in GameMap.PvE_World.Worlds) { resPacket.PutInt32(data.WorldId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.NeedVIPLevel); resPacket.PutInt32(data.NeedPlayerLevel); resPacket.PutInt32(data.NeedCharacterLevel); ++count; } resPacket.ResultCodeNo = ResultCode.Ok; resPacket.OverwriteInt32(idxCount, count); SendPacket(resPacket); }
private void OnCS_PvE_SetDeck_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { DeckType deckType = (DeckType)reqPacket.GetInt32(); Int32 count = reqPacket.GetInt32(); PlayDeck.Deck deck = PlayDeck[deckType]; // 수신된 데이터로 덱 구성 deck.Clear(); while (count-- > 0) { Int32 slotNo = reqPacket.GetInt32(); Int32 characterNo = reqPacket.GetInt32(); deck.Characters[slotNo] = InvenCharacter.FindOrNull(characterNo); } // DB에 업데이트 PlayDeck.UpdateToDB(deckType); } catch (AegisException e) { resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_PvE_GetDeck_Req(SecurePacketRequest reqPacket) { DeckType deckType = (DeckType)reqPacket.GetInt32(); SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); try { PlayDeck.Deck deck = PlayDeck[deckType]; Int32 slotNo = 0, idxCount; resPacket.ResultCodeNo = ResultCode.Ok; idxCount = resPacket.PutInt32(0); foreach (Character ch in deck.Characters) { resPacket.PutInt32(slotNo); if (ch == null) resPacket.PutInt32(0); else resPacket.PutInt32(ch.CharacterNo); ++slotNo; } resPacket.OverwriteInt32(idxCount, slotNo); } catch (AegisException e) { resPacket.Clear(); resPacket.ResultCodeNo = e.ResultCodeNo; } SendPacket(resPacket); }
private void OnCS_Login_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); Int32 authKey = reqPacket.GetInt32(); UserManager.Login(reqPacket.UserNo, authKey, (user, resultCode) => { user.SeqNo = reqPacket.SeqNo; resPacket.ResultCodeNo = resultCode; SendPacket(resPacket); }); }
private void OnCS_GameData_Codes_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket, 65000); resPacket.ResultCodeNo = ResultCode.Ok; // Energy resPacket.PutInt32(Codes.Energy.Items.Count); foreach (var data in Codes.Energy.Items.Values) { resPacket.PutInt32(data.EnergyId); resPacket.PutStringAsUtf16(data.Name); } // Resource resPacket.PutInt32(Codes.Resource.Items.Count); foreach (var data in Codes.Resource.Items.Values) { resPacket.PutInt32(data.ResourceId); resPacket.PutStringAsUtf16(data.Name); } // Race resPacket.PutInt32(Codes.Race.Items.Count); foreach (var data in Codes.Race.Items.Values) { resPacket.PutInt32(data.RaceId); resPacket.PutStringAsUtf16(data.Name); } // DamageType resPacket.PutInt32(Codes.DamageType.Items.Count); foreach (var data in Codes.DamageType.Items.Values) { resPacket.PutInt32(data.DamageTypeId); resPacket.PutStringAsUtf16(data.Name); } // Grade resPacket.PutInt32(Codes.Grade.Items.Count); foreach (var data in Codes.Grade.Items.Values) { resPacket.PutInt32(data.GradeId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.GradeType); resPacket.PutInt32(data.Priority); } // Promotion resPacket.PutInt32(Codes.Promotion.Items.Count); foreach (var data in Codes.Promotion.Items.Values) { resPacket.PutInt32(data.PromotionId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.PromotionType); resPacket.PutInt32(data.Priority); } // Promotion resPacket.PutInt32(Codes.Job.Items.Count); foreach (var data in Codes.Job.Items.Values) { resPacket.PutInt32(data.JobId); resPacket.PutStringAsUtf16(data.Name); } // CharacterType resPacket.PutInt32(Codes.CharacterType.Items.Count); foreach (var data in Codes.CharacterType.Items.Values) { resPacket.PutInt32(data.CharacterTypeId); resPacket.PutStringAsUtf16(data.Name); } // Position resPacket.PutInt32(Codes.Position.Items.Count); foreach (var data in Codes.Position.Items.Values) { resPacket.PutInt32(data.PositionId); resPacket.PutStringAsUtf16(data.Name); resPacket.PutInt32(data.PositionType); } SendPacket(resPacket); }
private void OnReceived(Session session, StreamBuffer buffer) { SecurePacketRequest reqPacket = new SecurePacketRequest(buffer); reqPacket.Decrypt(ServerMain.AES_IV, ServerMain.AES_Key); reqPacket.SkipHeader(); try { reqPacket.Dispatch(this, "On" + Protocol.GetName(reqPacket.PacketId)); } catch (AegisException e) when (e.ResultCodeNo == AegisResult.BufferUnderflow) { Logger.Write(LogType.Err, 2, "Cannot read more data at PacketId(=0x{0:X}).", reqPacket.PacketId); } catch (Exception e) { Logger.Write(LogType.Err, 2, e.ToString()); } }
private void OnCS_Auth_WorldList_Req(SecurePacketRequest reqPacket) { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); Int32 idxCount, count = 0; resPacket.ResultCodeNo = ResultCode.Ok; idxCount = resPacket.PutInt32(count); foreach (var world in WorldCatalog.Items .Where(v => v.IsOpen == true)) { resPacket.PutInt32(world.WorldId); resPacket.PutStringAsUtf16(world.WorldName); ++count; } resPacket.OverwriteInt32(idxCount, count); SendPacket(resPacket); }
private void OnCS_Auth_RegisterGuest_Req(SecurePacketRequest reqPacket) { String userToken = reqPacket.GetStringFromUtf16(); Int32 ret = 0, userNo = 0, authKey = 0; using (DBCommand cmd = AuthDB.NewCommand()) { cmd.CommandText.Append("call sp_auth_register_guest(@0);"); cmd.BindParameter("@0", userToken); cmd.PostQuery( () => { if (cmd.Reader.Read()) { ret = cmd.Reader.GetInt32(0); userNo = cmd.Reader.GetInt32(1); authKey = cmd.Reader.GetInt32(2); } }, (exception) => { SecurePacketResponse resPacket = new SecurePacketResponse(reqPacket); if (exception != null) { resPacket.ResultCodeNo = ResultCode.Database_Error; Logger.Write(LogType.Err, 2, exception.ToString()); } else if (ret == 0) { resPacket.ResultCodeNo = ResultCode.Ok; resPacket.PutInt32(userNo); resPacket.PutInt32(authKey); } else if (ret == 1) resPacket.ResultCodeNo = ResultCode.ExistsUserToken; SendPacket(resPacket); }); } }
private void OnReceived(Session session, StreamBuffer buffer) { SecurePacketRequest reqPacket = new SecurePacketRequest(buffer); reqPacket.Decrypt(_aesIV, _aesKey); reqPacket.SkipHeader(); Statistics.ReceivedBytes.Add(reqPacket.Size); Statistics.ReceivedCount.Add(1); try { if (reqPacket.PacketId == Protocol.GetID("CS_Login_Req")) OnCS_Login_Req(reqPacket); else { _user = UserManager.Find(reqPacket.UserNo); if (_user == null) { ForceClose("Invalid UserNo."); return; } if (reqPacket.SeqNo != _user.SeqNo + 1) { ForceClose("Invalid Sequence Number."); return; } _user.SeqNo = reqPacket.SeqNo; _user.Session = this; reqPacket.Dispatch(_user, "On" + Protocol.GetName(reqPacket.PacketId)); UserManager.HeartPulse(_user); } } catch (AegisException e) when (e.ResultCodeNo == AegisResult.BufferUnderflow) { Logger.Write(LogType.Err, 2, "Cannot read more data at PacketId(=0x{0:X}).", reqPacket.PacketId); } catch (Exception e) { Logger.Write(LogType.Err, 2, e.ToString()); } }