ValidatePosition.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.TaskPriority;
  19. import com.l2jserver.gameserver.Universe;
  20. import com.l2jserver.gameserver.geoeditorcon.GeoEditorListener;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.serverpackets.ExValidateLocationInAirShip;
  24. import com.l2jserver.gameserver.network.serverpackets.PartyMemberPosition;
  25. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  26. import com.l2jserver.gameserver.network.serverpackets.ValidateLocationInVehicle;
  27. /**
  28. * This class ...
  29. *
  30. * @version $Revision: 1.13.4.7 $ $Date: 2005/03/27 15:29:30 $
  31. */
  32. public class ValidatePosition extends L2GameClientPacket
  33. {
  34. private static Logger _log = Logger.getLogger(ValidatePosition.class.getName());
  35. private static final String _C__48_VALIDATEPOSITION = "[C] 48 ValidatePosition";
  36. /** urgent messages, execute immediately */
  37. public TaskPriority getPriority() { return TaskPriority.PR_HIGH; }
  38. private int _x;
  39. private int _y;
  40. private int _z;
  41. private int _heading;
  42. @SuppressWarnings("unused")
  43. private int _data;
  44. @Override
  45. protected void readImpl()
  46. {
  47. _x = readD();
  48. _y = readD();
  49. _z = readD();
  50. _heading = readD();
  51. _data = readD();
  52. }
  53. @Override
  54. protected void runImpl()
  55. {
  56. L2PcInstance activeChar = getClient().getActiveChar();
  57. if (activeChar == null || activeChar.isTeleporting()) return;
  58. int realX = activeChar.getX();
  59. int realY = activeChar.getY();
  60. int realZ = activeChar.getZ();
  61. if (_x == 0 && _y == 0)
  62. {
  63. if (realX != 0) // in this case this seems like a client error
  64. return;
  65. }
  66. if(activeChar.getParty() != null && activeChar.getLastPartyPositionDistance(_x, _y, _z) > 150)
  67. {
  68. activeChar.setLastPartyPosition(_x, _y, _z);
  69. activeChar.getParty().broadcastToPartyMembers(activeChar,new PartyMemberPosition(activeChar));
  70. }
  71. double dx = _x - realX;
  72. double dy = _y - realY;
  73. double dz = _z - realZ;
  74. double diffSq = (dx*dx + dy*dy);
  75. if (Config.DEVELOPER) {
  76. _log.fine("client pos: "+ _x + " "+ _y + " "+ _z +" head "+ _heading);
  77. _log.fine("server pos: "+ realX + " "+realY+ " "+realZ +" head "+activeChar.getHeading());
  78. }
  79. if (Config.ACCEPT_GEOEDITOR_CONN)
  80. if (GeoEditorListener.getInstance().getThread() != null
  81. && GeoEditorListener.getInstance().getThread().isWorking()
  82. && GeoEditorListener.getInstance().getThread().isSend(activeChar))
  83. GeoEditorListener.getInstance().getThread().sendGmPosition(_x,_y,(short)_z);
  84. if (Config.ACTIVATE_POSITION_RECORDER
  85. && !activeChar.isFlying()
  86. && Universe.getInstance().shouldLog(activeChar.getObjectId()))
  87. Universe.getInstance().registerHeight(realX, realY, _z);
  88. if (activeChar.isFlying() || activeChar.isInsideZone(L2Character.ZONE_WATER))
  89. {
  90. activeChar.setXYZ(realX, realY, _z);
  91. if (diffSq > 90000) // validate packet, may also cause z bounce if close to land
  92. {
  93. if (activeChar.isInBoat())
  94. {
  95. sendPacket(new ValidateLocationInVehicle(activeChar));
  96. }
  97. else if (activeChar.isInAirShip())
  98. {
  99. sendPacket(new ExValidateLocationInAirShip(activeChar));
  100. }
  101. else
  102. {
  103. activeChar.sendPacket(new ValidateLocation(activeChar));
  104. }
  105. }
  106. }
  107. else if (diffSq < 250000) // if too large, messes observation
  108. {
  109. if (Config.COORD_SYNCHRONIZE == -1) // Only Z coordinate synched to server,
  110. // mainly used when no geodata but can be used also with geodata
  111. {
  112. activeChar.setXYZ(realX,realY,_z);
  113. return;
  114. }
  115. if (Config.COORD_SYNCHRONIZE == 1) // Trusting also client x,y coordinates (should not be used with geodata)
  116. {
  117. if (!activeChar.isMoving()
  118. || !activeChar.validateMovementHeading(_heading)) // Heading changed on client = possible obstacle
  119. {
  120. // character is not moving, take coordinates from client
  121. if (diffSq < 2500) // 50*50 - attack won't work fluently if even small differences are corrected
  122. activeChar.setXYZ(realX, realY, _z);
  123. else
  124. activeChar.setXYZ(_x, _y, _z);
  125. }
  126. else
  127. {
  128. activeChar.setXYZ(realX, realY, _z);
  129. }
  130. activeChar.setHeading(_heading);
  131. return;
  132. }
  133. // Sync 2 (or other),
  134. // intended for geodata. Sends a validation packet to client
  135. // when too far from server calculated true coordinate.
  136. // Due to geodata/zone errors, some Z axis checks are made. (maybe a temporary solution)
  137. // Important: this code part must work together with L2Character.updatePosition
  138. if (Config.GEODATA > 0
  139. && (diffSq > 10000 || Math.abs(dz) > 200))
  140. {
  141. //if ((_z - activeChar.getClientZ()) < 200 && Math.abs(activeChar.getLastServerPosition().getZ()-realZ) > 70)
  142. if (Math.abs(dz) > 200 && Math.abs(dz) < 1500 && Math.abs(_z - activeChar.getClientZ()) < 800 )
  143. {
  144. activeChar.setXYZ(realX, realY, _z);
  145. realZ = _z;
  146. }
  147. else
  148. {
  149. if (Config.DEVELOPER)
  150. _log.info(activeChar.getName() + ": Synchronizing position Server --> Client");
  151. if (activeChar.isInBoat())
  152. {
  153. sendPacket(new ValidateLocationInVehicle(activeChar));
  154. }
  155. else if (activeChar.isInAirShip())
  156. {
  157. sendPacket(new ExValidateLocationInAirShip(activeChar));
  158. }
  159. else
  160. {
  161. activeChar.sendPacket(new ValidateLocation(activeChar));
  162. }
  163. }
  164. }
  165. }
  166. activeChar.setClientX(_x);
  167. activeChar.setClientY(_y);
  168. activeChar.setClientZ(_z);
  169. activeChar.setClientHeading(_heading); // No real need to validate heading.
  170. activeChar.setLastServerPosition(realX, realY, realZ);
  171. }
  172. /* (non-Javadoc)
  173. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  174. */
  175. @Override
  176. public String getType()
  177. {
  178. return _C__48_VALIDATEPOSITION;
  179. }
  180. }