/// <summary> /// This method is invoked when the client has data ready to be processed by the server. The server will /// switch between the packet type to find an appropriate function for processing the packet. If the /// packet was not found, the packet will be outputted to the console as an error. /// </summary> /// <param name="pState">Represents the status of an asynchronous operation.</param> public void Receive(AsynchronousState pState) { var pServer = pState.Client as LoginClient; if (pServer != null && pServer.Packet != null) { var type = (PacketType)BitConverter.ToUInt16(pServer.Packet, 2); Action <LoginClient, byte[]> action = m_pProcessor[type]; // Process the client's packet: if (action != null) { action(pServer, pServer.Packet); } else { GamePacketHandler.Report(pServer.Packet); } } }
public static void HandleGuideInfo(Character pRole, MsgGuideInfo pMsg) { switch (pMsg.Type) { case 1: // request mentor { if (pRole.Mentor == null) { return; } pRole.Mentor.Send(); break; } case 2: // request apprentices { if (pRole.Apprentices != null && pRole.Apprentices.Count > 0) { foreach (var appr in pRole.Apprentices.Values) { appr.Send(); } } break; } case 4: { break; } // not tested, probably asked after sending apprentices information to client // Mentor identity gets the value of the apprentices identity // which means that offset 8 isn't really the mentor identity, but a general identity :) // what would I call this? what about offset 12 that carries the student identity? default: ServerKernel.Log.SaveLog("Unhandled packet type 2066:" + pMsg.Type, true, "guide", LogType.DEBUG); GamePacketHandler.Report(pMsg); return; } }
public static void HandleRank(Character pUser, MsgRank pMsg) { switch (pMsg.Mode) { case 2: { if (pUser.Gender != 2) { return; } FlowerObject obj = ServerKernel.FlowerRanking.FetchUser(pUser.Identity); if (obj == null) { ServerKernel.FlowerRanking.AddFlowers(FlowerType.RED_ROSE, 0, pUser.Identity); obj = ServerKernel.FlowerRanking.FetchUser(pUser.Identity); if (obj == null) { return; } } string szFlowers = string.Format("{0} {1} {2} {3} {4} {5} {6} {7}" , pUser.RedRoses, obj.RedRosesToday , pUser.WhiteRoses, obj.WhiteRosesToday , pUser.Orchids, obj.OrchidsToday , pUser.Tulips, obj.TulipsToday); pMsg.Mode = 1; pMsg.SetFlowers(szFlowers); pUser.Send(pMsg); break; } default: GamePacketHandler.Report(pMsg); break; } }
public static void HandleFriendPacket(Character pRole, MsgFriend pMsg) { // pRole -> Request // pRoleTarget -> Target Friend // pRole -> SetFriendRequest(pRoleTarget->Identity) // pRoleTarget -> FetchFriendRequest(pRole->Identity) switch (pMsg.Mode) { #region Request Friend case RelationAction.REQUEST_FRIEND: { Client pTarget; if (ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget)) { if (pTarget.Character == null) { return; } Character pRoleTarget = pTarget.Character; uint dwVipUsr = FRIEND_VIP_AMOUNT[pRole.Owner.VipLevel], dwVipTgt = FRIEND_VIP_AMOUNT[pRoleTarget.Owner.VipLevel]; if (pRole.Friends.Count >= dwVipUsr) { pRole.Send(string.Format("You can only have {0} friends.", dwVipUsr)); return; } if (pRoleTarget.Friends.Count >= dwVipTgt) { pRole.Send("The target has reached it´s max friend amount."); return; } if (pRoleTarget.FetchFriendRequest(pRole.Identity)) { pRole.CreateFriend(pRoleTarget); pRoleTarget.ClearFriendRequest(); } else { pRole.SetFriendRequest(pRoleTarget.Identity); pMsg.Identity = pRole.Identity; pMsg.Name = pRole.Name; pRoleTarget.Send(pMsg); pRole.Send(ServerString.STR_MAKE_FRIEND_SENT); } } break; } #endregion #region Break case RelationAction.REMOVE_FRIEND: { pRole.DeleteFriend(pMsg.Identity); break; } #endregion #region Remove Enemy case RelationAction.REMOVE_ENEMY: { pRole.DeleteEnemy(pMsg.Identity); break; } #endregion default: ServerKernel.Log.SaveLog("Not handled 1019:" + pMsg.Mode, true, LogType.WARNING); GamePacketHandler.Report(pMsg); break; } }
public static void HandleFamily(Character pUser, MsgFamily pMsg) { // 22 - kick // Add Enemy and Add Ally send the family name switch (pMsg.Type) { #region Information case FamilyType.INFO: { if (pUser.Family == null) { return; } pUser.Family.SendFamily(pUser); break; } #endregion #region Members List case FamilyType.MEMBERS: { if (pUser.Family == null) { return; } pUser.Family.SendMembers(pUser); break; } #endregion #region Announcement case FamilyType.ANNOUNCE: { if (pUser.Family == null) { return; } pMsg.Identity = pUser.FamilyIdentity; pMsg.AddString(pUser.Family.Announcement); pUser.Send(pMsg); break; } #endregion #region Set Announcement case FamilyType.SET_ANNOUNCEMENT: { if (pUser.Family == null) { return; } if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } string szAnnounce = pMsg.Announcement; if (szAnnounce.Length > 127) { szAnnounce = szAnnounce.Substring(0, 127); } pUser.Family.Announcement = szAnnounce; pUser.Send(pMsg); break; } #endregion #region My Clan case FamilyType.MY_CLAN: { if (pUser.Family == null) { return; } pUser.Family.SendFamily(pUser); pUser.Family.SendOccupation(pUser); break; } #endregion #region Dedicate case FamilyType.DEDICATE: { if (pUser.Family == null) { return; } if (!pUser.ReduceMoney(pMsg.Identity, true)) { return; } pUser.Family.MoneyFunds += pMsg.Identity; pUser.FamilyMember.Donation += pMsg.Identity; pUser.Family.SendFamily(pUser); break; } #endregion #region Invite case FamilyType.RECRUIT: { if (pUser.Family == null) { return; } if (pUser.Family.IsFull) { return; } Client pTarget; if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget)) { return; } if (pTarget.Character.Family != null) { return; } pMsg.Identity = pUser.Family.Identity; pMsg.AddString(pUser.FamilyName); pMsg.AddString(pUser.Name); pTarget.Send(pMsg); pUser.SetFamilyRecruitRequest(pTarget.Character.Identity); break; } #endregion #region Accept Invite case FamilyType.ACCEPT_RECRUIT: { if (pUser.Family != null) { return; } Family pFamily; if (!ServerKernel.Families.TryGetValue(pMsg.Identity, out pFamily)) { return; } if (pFamily.IsFull) { return; } Client pLeaderS; if (!ServerKernel.Players.TryGetValue(pFamily.LeaderIdentity, out pLeaderS)) { return; } Character pLeader = pLeaderS.Character; if (pLeader.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } if (!pLeader.FetchFamilyRecruitRequest(pUser.Identity)) { return; } pFamily.AppendMember(pLeader, pUser); pLeader.ClearFamilyRecruitRequest(); break; } #endregion #region Join case FamilyType.JOIN: { if (pUser.Family != null) { return; } Client pTarget; if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget)) { return; } if (pTarget.Character.Family == null || pTarget.Character.Family.IsFull) { return; } pMsg.Identity = pUser.Identity; pMsg.AddString(pUser.Name); pTarget.Send(pMsg); pUser.SetFamilyJoinRequest(pTarget.Character.Identity); break; } #endregion #region Accept Join case FamilyType.ACCEPT_JOIN_REQUEST: { if (pUser.Family == null || pUser.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } Client pClienTarget; if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pClienTarget)) { return; } Character pInvited = pClienTarget.Character; if (pInvited.Family != null) { return; } if (!pInvited.FetchFamilyJoinRequest(pUser.Identity)) { return; } pUser.Family.AppendMember(pUser, pInvited); pInvited.ClearFamilyJoinRequest(); break; } #endregion #region Quit case FamilyType.QUIT: { if (pUser.Family == null) { return; } if (pUser.FamilyPosition == FamilyRank.CLAN_LEADER) { return; } if (pUser.FamilyPosition == FamilyRank.SPOUSE) { return; } pUser.Family.KickoutMember(pUser.FamilyMember); break; } #endregion #region Abdicate case FamilyType.TRANSFER_LEADER: { break; } #endregion #region Kickout case (FamilyType)22: { if (pUser.Family == null || pUser.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } FamilyMember pTarget = null; foreach (var client in pUser.Family.Members.Values) { if (client.Name == pMsg.Name) { pTarget = client; break; } } if (pTarget == null || pTarget.Position == FamilyRank.CLAN_LEADER || pTarget.Position == FamilyRank.SPOUSE) { return; } pUser.Family.KickoutMember(pTarget); pUser.Family.SendFamily(pUser); pUser.Family.SendMembers(pUser); break; } #endregion #region Ally case FamilyType.ADD_ALLY: { if (pUser.Family == null) { return; } if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } if (pUser.Family.Allies.Count >= 5) { return; } Client pTargetLeader; if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTargetLeader)) { return; } if (pTargetLeader.Character.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } Family pTarget = pTargetLeader.Character.Family; if (pTarget == null) { return; } RequestBox pAlly = new RequestBox { OwnerIdentity = pUser.FamilyIdentity, OwnerName = pUser.FamilyName, ObjectIdentity = pTarget.Identity, ObjectName = pTarget.Name, Type = RequestBoxType.FAMILY_ALLY, Message = string.Format("{0} Leader of the Clan {1} wants to be your ally. Do you accept?", pUser.Name, pUser.FamilyName) }; pUser.RequestBox = pTargetLeader.Character.RequestBox = pAlly; pAlly.Send(pTargetLeader.Character); break; } #endregion #region Delete Ally case FamilyType.DELETE_ALLY: { break; } #endregion #region Enemy case FamilyType.ADD_ENEMY: { if (pUser.Family == null) { return; } if (pUser.FamilyPosition != FamilyRank.CLAN_LEADER) { return; } if (pUser.Family.Enemies.Count >= 5) { return; } Family pTarget = ServerKernel.Families.Values.FirstOrDefault(x => x.Name == pMsg.Name); if (pTarget == null) { return; } pUser.Family.EnemyFamily(pTarget); break; } #endregion #region Delete Enemy case FamilyType.DELETE_ENEMY: { break; } #endregion default: { ServerKernel.Log.SaveLog(string.Format("MsgFamily:Type{0} not handled", pMsg.Type), true, LogType.WARNING); GamePacketHandler.Report(pMsg); break; } } }
public static void HandleTradeBuddy(Character pRole, MsgTradeBuddy pMsg) { switch (pMsg.Type) { #region Request Partnership case TradePartnerType.REQUEST_PARTNERSHIP: { Client pTargetUser; if (!ServerKernel.Players.TryGetValue(pMsg.Identity, out pTargetUser)) { pRole.Send(ServerString.STR_TRADE_BUDDY_NOT_FOUND); return; } Character pRoleTarget = pTargetUser.Character; if (pRoleTarget == null) { return; } if (pRole.FetchTradeBuddyRequest(pRoleTarget.Identity)) { if (pRoleTarget.TradePartners.ContainsKey(pRole.Identity) || pRole.TradePartners.ContainsKey(pRoleTarget.Identity)) { pRole.Send(ServerString.STR_TRADE_BUDDY_ALREADY_ADDED); return; } var pSender = new TradePartner(pRole); var pTarget = new TradePartner(pRoleTarget); if (!pSender.Create(pRoleTarget.Identity) || !pTarget.Create(pRole.Identity)) { pRole.Send(ServerString.STR_TRADE_BUDDY_SOMETHING_WRONG); return; } pRole.Screen.Send(string.Format("{0} and {1} accepted a trade partnership that will be approved within 3 days.", pRole.Name, pRoleTarget.Name), true); } else { pRoleTarget.SetTradeBuddyRequest(pRole.Identity); pMsg.Identity = pRole.Identity; pMsg.Name = pRole.Name; pTargetUser.Send(pMsg); pTargetUser.Character.SendRelation(pRole); } break; } #endregion #region Reject Request case TradePartnerType.REJECT_REQUEST: { Client pTarget; if (ServerKernel.Players.TryGetValue(pMsg.Identity, out pTarget)) { pMsg.Identity = pRole.Identity; pMsg.Name = pRole.Name; pMsg.Online = true; pTarget.Character.Send(pMsg); } break; } #endregion #region Break partnership case TradePartnerType.BREAK_PARTNERSHIP: { TradePartner pTarget; if (pRole.TradePartners.TryRemove(pMsg.Identity, out pTarget)) { pTarget.Delete(); if (pTarget.TargetOnline) { TradePartner trash; pTarget.Owner.TradePartners.TryRemove(pRole.Identity, out trash); trash.Delete(); pTarget.Owner.Send(string.Format(ServerString.STR_TRADE_BUDDY_BROKE_PARTNERSHIP0, pRole.Name)); } else { new BusinessRepository().DeleteBusiness(pRole.Identity, pTarget.OwnerIdentity); } pRole.Send(string.Format(ServerString.STR_TRADE_BUDDY_BROKE_PARTNERSHIP1, pTarget.Name)); } break; } #endregion default: { ServerKernel.Log.SaveLog("Missing packet handler for type 2046:" + pMsg.Type, true, LogType.WARNING); GamePacketHandler.Report(pMsg); break; } } }
public static void HandleQualifyingRank(Character pUser, MsgQualifyingRank pMsg) { switch (pMsg.RankType) { case ArenaRankType.QUALIFIER_RANK: { var rank = ServerKernel.ArenaRecord.Values.Where(x => x.TodayWins > 0 || x.TodayLoses > 0) .OrderByDescending(x => x.Points) .ThenByDescending(x => x.TodayWins) .ThenBy(x => x.TodayLoses) .ToList(); pMsg.Count = (uint)rank.Count; int idx = (pMsg.PageNumber - 1) * 10; int nStartIdx = idx; for (; idx < nStartIdx + 10; idx++) { if (idx >= rank.Count) { break; } var obj = rank[idx]; pMsg.AddPlayer((ushort)(idx + 1), obj.PlayerName, 0, obj.Points, obj.Profession, obj.Level, obj.Identity); } //pMsg.Count = 8; //pMsg.AddPlayer(1, "Player1", 0, 15000, 15, 140, 1000001); //pMsg.AddPlayer(2, "Player2", 0, 15000, 55, 140, 1000002); //pMsg.AddPlayer(3, "Player3", 0, 15000, 15, 140, 1000003); //pMsg.AddPlayer(4, "Player4", 0, 15000, 45, 140, 1000004); //pMsg.AddPlayer(5, "Player5", 0, 15000, 55, 140, 1000005); //pMsg.AddPlayer(6, "Player6", 0, 15000, 45, 140, 1000006); //pMsg.AddPlayer(7, "Player7", 0, 15000, 25, 140, 1000007); //pMsg.AddPlayer(8, "Player8", 0, 15000, 15, 140, 1000008); break; } case ArenaRankType.HONOR_HISTORY: { var rank = ServerKernel.ArenaRecord.Values.Where(x => x.TotalHonorPoints > 0) .OrderByDescending(x => x.TotalHonorPoints) .ThenByDescending(x => x.TodayWins) .ThenBy(x => x.TodayLoses) .ToList(); pMsg.Count = (uint)rank.Count; int idx = (pMsg.PageNumber - 1) * 10; int nStartIdx = idx; for (; idx < nStartIdx + 10; idx++) { if (idx >= rank.Count) { break; } var obj = rank[idx]; pMsg.AddPlayer((ushort)(idx + 1), obj.PlayerName, 6004, obj.TotalHonorPoints, obj.Profession, obj.Level, obj.Identity); } //pMsg.Count = 8; //pMsg.AddPlayer(1, "Player1", 6004, 15000, 15, 140, 33942209); //pMsg.AddPlayer(2, "Player2", 6004, 15000, 55, 140, 33942209); //pMsg.AddPlayer(3, "Player3", 6004, 15000, 15, 140, 33942209); //pMsg.AddPlayer(4, "Player4", 6004, 15000, 45, 140, 33942209); //pMsg.AddPlayer(5, "Player5", 6004, 15000, 55, 140, 33942209); //pMsg.AddPlayer(6, "Player6", 6004, 15000, 45, 140, 33942209); //pMsg.AddPlayer(7, "Player7", 6004, 15000, 25, 140, 33942209); //pMsg.AddPlayer(8, "Player8", 6004, 15000, 15, 140, 33942209); break; } default: { ServerKernel.Log.SaveLog(string.Format("MsgQualifyingRank::{0}", pMsg.RankType)); GamePacketHandler.Report(pMsg); break; } } pUser.Send(pMsg); }
public static void HandleTrade(Character pSender, MsgTrade pMsg) { switch (pMsg.Type) { #region Request case TradeType.REQUEST: { Client pUserTarget; if (!ServerKernel.Players.TryGetValue(pMsg.Target, out pUserTarget)) { return; } if (pUserTarget.Character == null) { pSender.Send(ServerString.STR_NO_TRADE_TARGET); return; } Character pAcceptRole = pUserTarget.Character; if (pAcceptRole.FetchTradeRequest(pSender.Identity)) { pSender.Trade = pAcceptRole.Trade = new Trade(pSender, pAcceptRole); pSender.Trade.ShowTable(); pAcceptRole.ClearTradeRequest(); return; } if (pUserTarget.Character == null) { return; } Character pRoleTarget = pUserTarget.Character; if (pRoleTarget.Trade == null) { pMsg.Target = pSender.Identity; pRoleTarget.Send(pMsg); pRoleTarget.SendRelation(pSender); pSender.SetTradeRequest(pRoleTarget.Identity); pSender.Send(ServerString.STR_TRADING_REQEST_SENT); return; } else { pSender.Send(ServerString.STR_TARGET_TRADING); return; } break; } #endregion #region Time out case TradeType.TIME_OUT: { GamePacketHandler.Report(pMsg); //Console.WriteLine("Trade close due to timeout"); //pSender.Trade.CloseWindow(pMsg); break; } #endregion #region Accept Trade case TradeType.ACCEPT: { pSender.Trade.AcceptTrade(pSender, pMsg); break; } #endregion #region Add Item case TradeType.ADD_ITEM: { pSender.Trade.AddItem(pMsg.Target, pSender); break; } #endregion #region Set Money case TradeType.SET_MONEY: { pSender.Trade.AddMoney(pMsg.Target, pSender, pMsg); break; } #endregion #region Set Conquer Points case TradeType.SET_CONQUER_POINTS: { pSender.Trade.AddEmoney(pMsg.Target, pSender, pMsg); break; } #endregion #region Close case TradeType.CLOSE: { if (pSender.Trade != null) { pSender.Trade.CloseWindow(pMsg); } break; } #endregion } }
public static void HandleQualifyingInteractive(Character pUser, MsgQualifyingInteractive pMsg) { switch (pMsg.Type) { case ArenaType.ARENA_ICON_ON: { if (ServerKernel.ArenaQualifier.Inscribe(pUser)) { pUser.SendArenaStatus(); } else { ServerKernel.ArenaQualifier.Uninscribe(pUser); pUser.SendArenaStatus(); } break; } case ArenaType.ARENA_ICON_OFF: { if (ServerKernel.ArenaQualifier.Uninscribe(pUser)) { pUser.SendArenaStatus(); } break; } case ArenaType.ACCEPT_DIALOG: { ArenaMatch pMatch = ServerKernel.ArenaQualifier.FindUser(pUser.Identity); if (pMatch == null) { pUser.Send(ServerString.STR_ARENIC_NOT_JOINED); if (ServerKernel.ArenaQualifier.IsWaitingMatch(pUser.Identity)) { ServerKernel.ArenaQualifier.Uninscribe(pUser); } pUser.SendArenaStatus(); return; } if (pMsg.Option == 1) // accept { pMatch.Accept(pUser); if (pMatch.ReadyToStart()) { pMatch.Start(); } pUser.SendArenaStatus(); } else if (pMsg.Option == 2) // give up { pMatch.GiveUp(pUser); pUser.SendArenaStatus(); } break; } case ArenaType.OPPONENT_GAVE_UP: { ArenaMatch pMatch = ServerKernel.ArenaQualifier.FindUser(pUser.Identity); if (pMatch == null) { return; } //Client pTarget; //uint idTarget = pMatch.Identity1 == pUser.Identity ? pMatch.Identity2 : pMatch.Identity1; //if (ServerKernel.Players.TryGetValue(idTarget, out pTarget)) { if (pUser.Identity == pMatch.Identity1) { pMatch.Points2 = uint.MaxValue; } else { pMatch.Points1 = uint.MaxValue; } pMatch.Finish(/*pUser, pTarget.Character*/); pUser.SendArenaStatus(); } break; } case ArenaType.END_MATCH_JOIN: // rejoin { if (ServerKernel.ArenaQualifier.Uninscribe(pUser)) { ServerKernel.ArenaQualifier.Inscribe(pUser); pUser.SendArenaStatus(); } break; } default: { pUser.Send(string.Format("The request {0} is not handled. Please contact the admin and provide an screenshot of the error.", pMsg.Type)); ServerKernel.Log.SaveLog(string.Format("MsgQualifyingInteractive::{0}", pMsg.Type), true); GamePacketHandler.Report(pMsg); break; } } }