ValidatePosition.java 6.7 KB

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