2
0

ValidatePosition.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.geoeditorcon.GeoEditorListener;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.serverpackets.ExValidateLocationInAirShip;
  23. import com.l2jserver.gameserver.network.serverpackets.PartyMemberPosition;
  24. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  25. import com.l2jserver.gameserver.network.serverpackets.ValidateLocationInVehicle;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision: 1.13.4.7 $ $Date: 2005/03/27 15:29:30 $
  30. */
  31. public class ValidatePosition extends L2GameClientPacket
  32. {
  33. private static Logger _log = Logger.getLogger(ValidatePosition.class.getName());
  34. private static final String _C__48_VALIDATEPOSITION = "[C] 48 ValidatePosition";
  35. /** urgent messages, execute immediately */
  36. public TaskPriority getPriority() { return TaskPriority.PR_HIGH; }
  37. private int _x;
  38. private int _y;
  39. private int _z;
  40. private int _heading;
  41. @SuppressWarnings("unused")
  42. private int _data;
  43. @Override
  44. protected void readImpl()
  45. {
  46. _x = readD();
  47. _y = readD();
  48. _z = readD();
  49. _heading = readD();
  50. _data = readD();
  51. }
  52. @Override
  53. protected void runImpl()
  54. {
  55. final L2PcInstance activeChar = getClient().getActiveChar();
  56. if (activeChar == null
  57. || activeChar.isTeleporting()
  58. || activeChar.inObserverMode())
  59. return;
  60. final int realX = activeChar.getX();
  61. final int realY = activeChar.getY();
  62. int realZ = activeChar.getZ();
  63. if (_x == 0 && _y == 0)
  64. {
  65. if (realX != 0) // in this case this seems like a client error
  66. return;
  67. }
  68. if(activeChar.getParty() != null && activeChar.getLastPartyPositionDistance(_x, _y, _z) > 150)
  69. {
  70. activeChar.setLastPartyPosition(_x, _y, _z);
  71. activeChar.getParty().broadcastToPartyMembers(activeChar,new PartyMemberPosition(activeChar));
  72. }
  73. final int dx = _x - realX;
  74. final int dy = _y - realY;
  75. final int dz = _z - realZ;
  76. double diffSq = (dx*dx + dy*dy);
  77. if (Config.DEVELOPER)
  78. {
  79. _log.fine("client pos: "+ _x + " "+ _y + " "+ _z +" head "+ _heading);
  80. _log.fine("server pos: "+ realX + " "+realY+ " "+realZ +" head "+activeChar.getHeading());
  81. }
  82. if (Config.ACCEPT_GEOEDITOR_CONN)
  83. if (GeoEditorListener.getInstance().getThread() != null
  84. && GeoEditorListener.getInstance().getThread().isWorking()
  85. && GeoEditorListener.getInstance().getThread().isSend(activeChar))
  86. GeoEditorListener.getInstance().getThread().sendGmPosition(_x,_y,(short)_z);
  87. if (activeChar.isFlying() || activeChar.isInsideZone(L2Character.ZONE_WATER))
  88. {
  89. activeChar.setXYZ(realX, realY, _z);
  90. if (diffSq > 90000) // validate packet, may also cause z bounce if close to land
  91. {
  92. if (activeChar.isInBoat())
  93. sendPacket(new ValidateLocationInVehicle(activeChar));
  94. else if (activeChar.isInAirShip())
  95. sendPacket(new ExValidateLocationInAirShip(activeChar));
  96. else
  97. activeChar.sendPacket(new ValidateLocation(activeChar));
  98. }
  99. }
  100. else if (diffSq < 360000) // if too large, messes observation
  101. {
  102. if (Config.COORD_SYNCHRONIZE == -1) // Only Z coordinate synched to server,
  103. // mainly used when no geodata but can be used also with geodata
  104. {
  105. activeChar.setXYZ(realX,realY,_z);
  106. return;
  107. }
  108. if (Config.COORD_SYNCHRONIZE == 1) // Trusting also client x,y coordinates (should not be used with geodata)
  109. {
  110. if (!activeChar.isMoving()
  111. || !activeChar.validateMovementHeading(_heading)) // Heading changed on client = possible obstacle
  112. {
  113. // character is not moving, take coordinates from client
  114. if (diffSq < 2500) // 50*50 - attack won't work fluently if even small differences are corrected
  115. activeChar.setXYZ(realX, realY, _z);
  116. else
  117. activeChar.setXYZ(_x, _y, _z);
  118. }
  119. else
  120. activeChar.setXYZ(realX, realY, _z);
  121. activeChar.setHeading(_heading);
  122. return;
  123. }
  124. // Sync 2 (or other),
  125. // intended for geodata. Sends a validation packet to client
  126. // when too far from server calculated true coordinate.
  127. // Due to geodata/zone errors, some Z axis checks are made. (maybe a temporary solution)
  128. // Important: this code part must work together with L2Character.updatePosition
  129. if (Config.GEODATA > 0 && (diffSq > 250000 || Math.abs(dz) > 200))
  130. {
  131. //if ((_z - activeChar.getClientZ()) < 200 && Math.abs(activeChar.getLastServerPosition().getZ()-realZ) > 70)
  132. if (Math.abs(dz) > 200
  133. && Math.abs(dz) < 1500
  134. && Math.abs(_z - activeChar.getClientZ()) < 800 )
  135. {
  136. activeChar.setXYZ(realX, realY, _z);
  137. realZ = _z;
  138. }
  139. else
  140. {
  141. if (Config.DEVELOPER)
  142. _log.info(activeChar.getName() + ": Synchronizing position Server --> Client");
  143. if (activeChar.isInBoat())
  144. sendPacket(new ValidateLocationInVehicle(activeChar));
  145. else if (activeChar.isInAirShip())
  146. sendPacket(new ExValidateLocationInAirShip(activeChar));
  147. else
  148. activeChar.sendPacket(new ValidateLocation(activeChar));
  149. }
  150. }
  151. }
  152. activeChar.setClientX(_x);
  153. activeChar.setClientY(_y);
  154. activeChar.setClientZ(_z);
  155. activeChar.setClientHeading(_heading); // No real need to validate heading.
  156. activeChar.setLastServerPosition(realX, realY, realZ);
  157. }
  158. /* (non-Javadoc)
  159. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  160. */
  161. @Override
  162. public String getType()
  163. {
  164. return _C__48_VALIDATEPOSITION;
  165. }
  166. }