mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add mouse clicked message support and decoding.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import org.apollo.game.message.Message;
|
||||
|
||||
/**
|
||||
* A {@link Message} sent by the client to indicate when the mouse button/s have been clicked. This can be used in
|
||||
* combination with {@link org.apollo.game.message.impl.FocusUpdateMessage} to work out if the player is clicking
|
||||
* whilst the client is closed
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public final class MouseClickedMessage extends Message {
|
||||
|
||||
/**
|
||||
* Time in milliseconds since the last click
|
||||
*/
|
||||
private final long lastClickedDelay;
|
||||
/**
|
||||
* Right mouse button flag
|
||||
*/
|
||||
private final boolean rightMouseButton;
|
||||
/**
|
||||
* The y position of the cursor
|
||||
*/
|
||||
private final int x;
|
||||
/**
|
||||
* The x position of the cursor
|
||||
*/
|
||||
private final int y;
|
||||
|
||||
/**
|
||||
* Creates a new mouse clicked message
|
||||
*
|
||||
* @param lastClickedDelay The delay since the last click
|
||||
* @param rightMouseButton Whether or not the right mouse button was used
|
||||
* @param x The x cursor position when clicked
|
||||
* @param y The y cursor position when clicked
|
||||
*/
|
||||
public MouseClickedMessage(long lastClickedDelay, boolean rightMouseButton, int x, int y) {
|
||||
this.lastClickedDelay = lastClickedDelay;
|
||||
this.rightMouseButton = rightMouseButton;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time in milliseconds since the last click
|
||||
*
|
||||
* @return The time in milliseconds since the last click
|
||||
*/
|
||||
public long getLastClickedDelay() {
|
||||
return lastClickedDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the right mouse button was used or not
|
||||
*
|
||||
* @return If the mouse right button was used to click
|
||||
*/
|
||||
public boolean usingRightMouseButton() {
|
||||
return rightMouseButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the x position of the cursor
|
||||
*
|
||||
* @return The x position of the cursor when clicked
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y position of the cursor
|
||||
*
|
||||
* @return The y position of the cursor when clicked
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.message.impl.MouseClickedMessage;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketReader;
|
||||
import org.apollo.net.release.MessageDecoder;
|
||||
|
||||
/**
|
||||
* A {@link org.apollo.net.release.MessageDecoder} for the {@link org.apollo.game.message.impl.MouseClickedMessage}
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public final class MouseClickedMessageDecoder extends MessageDecoder<MouseClickedMessage> {
|
||||
|
||||
@Override
|
||||
public MouseClickedMessage decode(GamePacket packet) {
|
||||
GamePacketReader reader = new GamePacketReader(packet);
|
||||
int value = (int)reader.getUnsigned(DataType.INT);
|
||||
|
||||
long delay = (value >> 20) * 50;
|
||||
|
||||
boolean rightMouseButton = ((value >> 19) & 0x1) == 1;
|
||||
|
||||
int cords = (value & 0x3FFFF);
|
||||
int x = cords % 765;
|
||||
int y = cords / 765;
|
||||
|
||||
return new MouseClickedMessage(delay, rightMouseButton, x, y);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -129,6 +129,7 @@ public final class Release317 extends Release {
|
||||
|
||||
register(3, new FocusUpdateMessageDecoder());
|
||||
register(45, new FlaggedMouseEventMessageDecoder());
|
||||
register(241, new MouseClickedMessageDecoder());
|
||||
register(86, new ArrowKeyMessageDecoder());
|
||||
register(95, new PrivacyOptionMessageDecoder());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user