PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Trunk/WorldServer/Packets/Client/System.cs

http://aioncxx.codeplex.com
C# | 209 lines | 166 code | 27 blank | 16 comment | 20 complexity | 8c53b9ab8cf32ed7adb0af0ec5ae456c MD5 | raw file
  1. /* Copyright (c) 2011-2012, Zetatron Consulting
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  4. * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  5. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  6. * Neither the name of Zetatron Consulting nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  7. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8. */
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using AionCxxLibrary.Packets;
  14. using AionCxxLibrary.Utilities;
  15. using AionCxxLibrary.Enums;
  16. using WorldServer.Packets.Server;
  17. using AionCxxLibrary.DAO;
  18. using WorldServer.Services;
  19. using WorldServer.DAO;
  20. using WorldServer.Models;
  21. namespace WorldServer.Packets.Client
  22. {
  23. public class CPkt_ClientVersion : AionClientPacket
  24. {
  25. public override void ProcessPacket()
  26. {
  27. Connection.SendPacket(new SPkt_ServerVersion());
  28. }
  29. }
  30. public class CPkt_MACAddress : AionClientPacket
  31. {
  32. public override void ProcessPacket()
  33. {
  34. ReadBytes(22);
  35. string mac = ReadString();
  36. Log.Debug(Connection.GetRemoteIP() + " <=> " + mac);
  37. }
  38. }
  39. public class CPkt_MACAddressUpdate : AionClientPacket
  40. {
  41. public override void ProcessPacket()
  42. {
  43. }
  44. }
  45. public class CPkt_Login : AionClientPacket
  46. {
  47. public override void ProcessPacket()
  48. {
  49. int KeyWorld2 = ReadInt();
  50. int KeyWorld1 = ReadInt();
  51. int AccountID = ReadInt();
  52. int KeyLogin = ReadInt();
  53. bool Authed = false;
  54. bool CloseAfter = true;
  55. // account id 8 = xita, for debugging, when I reboot GS (clear reconnecting account table) i stay on LS (realm list) so I don't restart client every time, so PollAccount will fail ;)
  56. if (KeyWorld1 == 0 && KeyWorld2 == 0 && AccountID > 0 && KeyLogin > 0 && (NetworkService.PollReconnectingAccount(AccountID) || AccountID == 8) && AccountDAO.CheckSession(AccountID, KeyLogin))
  57. Authed = true;
  58. else if (AccountDAO.CheckSession(AccountID, KeyLogin, KeyWorld1, KeyWorld2))
  59. Authed = true;
  60. else
  61. Log.Warn(Connection.GetRemoteIP() + " failed to authenticate with " + AccountID + "/" + KeyLogin + "/" + KeyWorld1 + "/" + KeyWorld2);
  62. if (Authed)
  63. {
  64. Connection.account = AccountDAO.LoadAccount(AccountID);
  65. WorldConnection wc = (WorldConnection)Connection;
  66. wc.Keys[0] = KeyLogin;
  67. wc.Keys[1] = KeyWorld1;
  68. wc.Keys[2] = KeyWorld2;
  69. CloseAfter = false;
  70. }
  71. Connection.SendPacket(new SPkt_Login());
  72. if (CloseAfter)
  73. {
  74. Connection.Close();
  75. }
  76. }
  77. }
  78. public class CPkt_Time : AionClientPacket
  79. {
  80. public override void ProcessPacket()
  81. {
  82. Connection.SendPacket(new SPkt_Time(ReadInt()));
  83. }
  84. }
  85. public class CPkt_ChooseServer : AionClientPacket
  86. {
  87. static Random rnd = new Random();
  88. public override void ProcessPacket()
  89. {
  90. int key = rnd.Next();
  91. WorldConnection wc = ((WorldConnection)Connection);
  92. AccountDAO.UpdateSession(wc.account.ID, wc.Keys[0], wc.Keys[1], wc.Keys[2], key);
  93. NetworkService.AddReconnectingAccount(wc.account.ID);
  94. Connection.SendPacket(new SPkt_ChooseServer(key));
  95. }
  96. }
  97. public class CPkt_KeepAlive : AionClientPacket
  98. {
  99. public override void ProcessPacket()
  100. {
  101. Connection.SendPacket(new SPkt_KeepAlive());
  102. }
  103. }
  104. public class CPkt_EnterWorldCheck : AionClientPacket
  105. {
  106. public override void ProcessPacket()
  107. {
  108. Connection.SendPacket(new SPkt_EnterWorldCheck());
  109. }
  110. }
  111. public class CPkt_ClientSettings : AionClientPacket
  112. {
  113. public override void ProcessPacket()
  114. {
  115. byte type = ReadByte(); // 0 = Settings - 1 = Quick Bars
  116. ReadShort();
  117. ReadShort();
  118. byte[] data = ReadBytes((int)(Length - Position));
  119. CharacterDAO.UpdateSettings(((WorldConnection)Connection).Character.Template.ID, type, data);
  120. }
  121. }
  122. public class CPkt_WorldQuit : AionClientPacket
  123. {
  124. public override void ProcessPacket()
  125. {
  126. byte action = ReadByte();
  127. CharacterService.OnDisconnect(((WorldConnection)Connection).Character);
  128. ((WorldConnection)Connection).Character = null;
  129. Connection.SendPacket(new SPkt_WorldQuit(false), action == 0);
  130. }
  131. }
  132. public class CPkt_WorldQuitInit : AionClientPacket
  133. {
  134. public override void ProcessPacket()
  135. {
  136. }
  137. }
  138. public class CPkt_UIQuestionResponse : AionClientPacket
  139. {
  140. public override void ProcessPacket()
  141. {
  142. int QuestionID = ReadInt();
  143. byte Response = ReadByte();
  144. (Connection as WorldConnection).Character.UI.QuestionResponse(QuestionID, Response == 1);
  145. }
  146. }
  147. public class CPkt_TargetChange : AionClientPacket
  148. {
  149. public override void ProcessPacket()
  150. {
  151. int TargetGUID = ReadInt();
  152. byte type = ReadByte();
  153. AionObject target;
  154. try
  155. {
  156. target = LevelService.Objects[TargetGUID];
  157. }
  158. catch (Exception)
  159. {
  160. target = null;
  161. }
  162. if (target == null)
  163. {
  164. (Connection as WorldConnection).Character.Target = null;
  165. }
  166. else
  167. {
  168. if (type == 1)
  169. (Connection as WorldConnection).Character.Target = target.Target;
  170. else
  171. (Connection as WorldConnection).Character.Target = target;
  172. }
  173. // Send Player Packet
  174. // Broadcast NearbyTargetUpdate
  175. }
  176. }
  177. }