├── LICENSE
├── README.md
├── client-connect-api
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── client
│ └── connect
│ └── api
│ ├── Connect.java
│ ├── ConnectSettings.java
│ ├── MessageEvent.java
│ ├── MessageEventListener.java
│ ├── RedirectEvent.java
│ ├── RedirectEventListener.java
│ ├── ServerAddEvent.java
│ ├── ServerEventListener.java
│ ├── event
│ ├── Event.java
│ ├── EventListener.java
│ ├── MessageEvent.java
│ ├── RedirectEvent.java
│ ├── ServerAddEvent.java
│ └── ServerRemoveEvent.java
│ ├── request
│ ├── Request.java
│ ├── RequestException.java
│ └── impl
│ │ ├── AsProxyRequest.java
│ │ ├── AsServerRequest.java
│ │ ├── AuthenticateRequest.java
│ │ ├── GetDetailsRequest.java
│ │ ├── GetKeyRequest.java
│ │ ├── GetPlayersRequest.java
│ │ ├── GetWhoamiRequest.java
│ │ ├── MessageRequest.java
│ │ ├── NotifyPlayerRequest.java
│ │ └── RedirectRequest.java
│ ├── result
│ ├── FutureResult.java
│ ├── FutureResultListener.java
│ ├── Result.java
│ ├── StatusCode.java
│ └── impl
│ │ ├── AsProxyResult.java
│ │ ├── AsServerResult.java
│ │ ├── AuthenticateResult.java
│ │ ├── GetDetailsResult.java
│ │ ├── GetKeyResult.java
│ │ ├── GetPlayersResult.java
│ │ ├── GetWhoamiResult.java
│ │ ├── MessageResult.java
│ │ ├── NotifyPlayerResult.java
│ │ └── RedirectResult.java
│ └── util
│ └── SecurityUtils.java
├── client-connect-lib
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── client
│ └── connect
│ └── lib
│ ├── ConnectImpl.java
│ ├── ConnectNetworkHandler.java
│ ├── request
│ ├── ConnectRequestEncoderRegistry.java
│ ├── RequestEncoder.java
│ ├── RequestEncoderRegistry.java
│ └── impl
│ │ ├── AsProxyRequestEncoder.java
│ │ ├── AsServerRequestEncoder.java
│ │ ├── AuthenticateRequestEncoder.java
│ │ ├── GetDetailsRequestEncoder.java
│ │ ├── GetKeyRequestEncoder.java
│ │ ├── GetPlayersRequestEncoder.java
│ │ ├── GetWhoamiRequestEncoder.java
│ │ ├── MessageRequestEncoder.java
│ │ ├── NotifyPlayerRequestEncoder.java
│ │ └── RedirectRequestEncoder.java
│ ├── result
│ ├── ConnectResultDecoderRegistry.java
│ ├── FutureResultImpl.java
│ ├── ResultDecoder.java
│ ├── ResultDecoderRegistry.java
│ └── impl
│ │ ├── AsProxyResultDecoder.java
│ │ ├── AsServerResultDecoder.java
│ │ ├── AuthenticateResultDecoder.java
│ │ ├── GetDetailsResultDecoder.java
│ │ ├── GetKeyResultDecoder.java
│ │ ├── GetPlayersResultDecoder.java
│ │ ├── GetWhoamiResultDecoder.java
│ │ ├── MessageResultDecoder.java
│ │ ├── NotifyPlayerResultDecoder.java
│ │ └── RedirectResultDecoder.java
│ └── util
│ └── StringUtils.java
├── packet-common
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── packet
│ └── common
│ ├── Packet.java
│ ├── PacketCodec.java
│ ├── PacketCodecProvider.java
│ ├── PacketCodecRegistry.java
│ ├── PacketDecoder.java
│ ├── PacketEncoder.java
│ ├── VarIntFrameCodec.java
│ └── util
│ └── BufferUtils.java
├── packet-connect
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── packet
│ └── connect
│ ├── ConnectPacketCodecRegistry.java
│ ├── ConnectPacketConstants.java
│ └── impl
│ ├── KeepalivePacket.java
│ ├── KeepalivePacketCodec.java
│ ├── MessagePacket.java
│ ├── MessagePacketCodec.java
│ ├── RedirectPacket.java
│ ├── RedirectPacketCodec.java
│ ├── RequestPacket.java
│ ├── RequestPacketCodec.java
│ ├── ResultPacket.java
│ ├── ResultPacketCodec.java
│ ├── ServerAddPacket.java
│ ├── ServerPacket.java
│ └── ServerPacketCodec.java
├── server-common
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── common
│ ├── IAuthenticator.java
│ ├── IPlayable.java
│ ├── IPlayerCallback.java
│ ├── IRedirectable.java
│ ├── IServer.java
│ ├── IServerSource.java
│ ├── config
│ ├── FileConfig.java
│ ├── FileConfigGson.java
│ └── IConfig.java
│ ├── service
│ ├── Service.java
│ └── ServiceManager.java
│ └── util
│ ├── GsonUtils.java
│ ├── SecurityUtils.java
│ └── StringUtils.java
├── server-connect
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── connect
│ ├── ConnectConfig.java
│ ├── ConnectService.java
│ ├── node
│ ├── NodeHandler.java
│ ├── NodeSession.java
│ ├── NodeSessionKeepalive.java
│ ├── NodeSessionMapper.java
│ ├── NodeSessionRole.java
│ └── ProxyCache.java
│ └── query
│ ├── NodeQueryLookupService.java
│ ├── Query.java
│ ├── QueryLookupService.java
│ └── impl
│ ├── AsProxyQuery.java
│ ├── AsServerQuery.java
│ ├── AuthenticateQuery.java
│ ├── GetDetailsQuery.java
│ ├── GetKeyQuery.java
│ ├── GetPlayersQuery.java
│ ├── GetWhoamiQuery.java
│ ├── MessageQuery.java
│ ├── NotifyPlayer.java
│ └── RedirectQuery.java
├── server-proxy
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── proxy
│ ├── ProxyConfig.java
│ ├── ProxyService.java
│ ├── net
│ ├── AesCodec.java
│ ├── LegacyPingDecoder.java
│ ├── ProxyInboundHandler.java
│ ├── ProxyOutboundHandler.java
│ ├── ProxySession.java
│ ├── ProxySessionMapper.java
│ ├── ProxyState.java
│ └── http
│ │ ├── HttpGetClient.java
│ │ ├── HttpGetClientListener.java
│ │ └── impl
│ │ ├── AsyncHttpGetClient.java
│ │ ├── AsyncHttpGetClientHandler.java
│ │ ├── DummyTrustManager.java
│ │ └── SyncHttpGetClient.java
│ ├── packet
│ ├── GenericPacket.java
│ ├── GenericPacketCodec.java
│ ├── MinecraftPacketCodecRegistry.java
│ ├── MinecraftPacketConstants.java
│ ├── ProxyPacketCodecProvider.java
│ ├── StatefulPacketCodecProviderPair.java
│ ├── impl
│ │ ├── HandshakePacket.java
│ │ ├── HandshakePacketCodec.java
│ │ ├── LoginDisconnectPacket.java
│ │ ├── LoginDisconnectPacketCodec.java
│ │ ├── LoginEncryptRequestPacket.java
│ │ ├── LoginEncryptRequestPacketCodec.java
│ │ ├── LoginEncryptResponsePacket.java
│ │ ├── LoginEncryptResponsePacketCodec.java
│ │ ├── LoginStartPacket.java
│ │ ├── LoginStartPacketCodec.java
│ │ ├── LoginSuccessPacket.java
│ │ ├── LoginSuccessPacketCodec.java
│ │ ├── PlayClientSettingsPacket.java
│ │ ├── PlayClientSettingsPacketCodec.java
│ │ ├── PlayDisconnectPacket.java
│ │ ├── PlayDisconnectPacketCodec.java
│ │ ├── PlayJoinGamePacket.java
│ │ ├── PlayJoinGamePacketCodec.java
│ │ ├── PlayPlayerListPacket.java
│ │ ├── PlayPlayerListPacketCodec.java
│ │ ├── PlayRespawnPacket.java
│ │ ├── PlayRespawnPacketCodec.java
│ │ ├── PlayScoreObjectivePacket.java
│ │ ├── PlayScoreObjectivePacketCodec.java
│ │ ├── PlayTeamPacket.java
│ │ ├── PlayTeamPacketCodec.java
│ │ ├── StatusPingPacket.java
│ │ ├── StatusPingPacketCodec.java
│ │ ├── StatusRequestPacket.java
│ │ ├── StatusRequestPacketCodec.java
│ │ ├── StatusResponsePacket.java
│ │ └── StatusResponsePacketCodec.java
│ └── state
│ │ ├── HandshakeStateCodecProvider.java
│ │ ├── LoginStateCodecProvider.java
│ │ ├── PlayStateCodecProvider.java
│ │ └── StatusStateCodecProvider.java
│ └── util
│ ├── CipherUtils.java
│ └── MinecraftUtils.java
├── server-query
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── query
│ ├── tcp
│ ├── QueryTcpConfig.java
│ ├── QueryTcpService.java
│ └── net
│ │ ├── GsonResponse.java
│ │ └── QueryTcpHandler.java
│ └── udp
│ ├── QueryUdpConfig.java
│ ├── QueryUdpService.java
│ └── net
│ ├── QueryUdpHandler.java
│ └── QueryUdpIdentification.java
├── server-standalone-allinone
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── standalone
│ └── allinone
│ ├── AllInOne.java
│ ├── AllInOneConfig.java
│ └── Config.java
├── server-standalone-connect
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── standalone
│ └── connect
│ ├── Config.java
│ ├── Connect.java
│ ├── ConnectConfig.java
│ └── ConnectPlayable.java
├── server-standalone-proxy
├── .gitignore
├── pom.xml
└── src
│ └── main
│ └── java
│ └── lilypad
│ └── server
│ └── standalone
│ └── proxy
│ ├── Config.java
│ ├── ConnectPlayerCallback.java
│ ├── ConnectServer.java
│ ├── ConnectServerRedirect.java
│ ├── ConnectServerSource.java
│ ├── ConnectThread.java
│ ├── Proxy.java
│ └── ProxyConfig.java
└── server-standalone-query
├── .gitignore
├── pom.xml
└── src
└── main
└── java
└── lilypad
└── server
└── standalone
└── query
├── Config.java
├── Query.java
├── QueryCache.java
├── QueryCacheUpdater.java
└── QueryConfig.java
/README.md:
--------------------------------------------------------------------------------
1 | JLilyPad
2 | =============
3 |
4 | An implementation of LilyPad in the popular programming language Java.
5 |
6 | More information can be found at http://www.lilypadmc.org :)
7 |
--------------------------------------------------------------------------------
/client-connect-api/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | /.classpath
3 | /.project
4 | /.settings
5 |
6 | # Netbeans
7 | /nbproject
8 |
9 | # Maven
10 | /build.xml
11 | /target
12 |
13 | # vim
14 | .*.sw[a-p]
15 |
16 | # Build
17 | /build
18 | /bin
19 | /dist
20 | /manifest.mf
21 |
22 | # Mac OS X
23 | /.DS_Store
24 |
25 | # Intellij
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
31 | # Temp
32 | *~
33 | doc/*
34 |
--------------------------------------------------------------------------------
/client-connect-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | lilypad.client.connect
5 | api
6 | 0.0.1-SNAPSHOT
7 | jar
8 |
9 | Client-Connect-API
10 | http://www.lilypadmc.org
11 |
12 |
13 | UTF-8
14 | Unknown
15 |
16 |
17 |
18 | ${project.name}
19 |
20 |
21 | org.apache.maven.plugins
22 | maven-compiler-plugin
23 | 2.5.1
24 |
25 | 1.6
26 | 1.6
27 |
28 |
29 |
30 | maven-assembly-plugin
31 | 2.2
32 |
33 |
34 | make-assembly
35 | package
36 |
37 | single
38 |
39 |
40 | 1.6
41 | 1.6
42 | false
43 |
44 | jar-with-dependencies
45 |
46 |
47 | false
48 |
49 | ${name}
50 | ${build.number}
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/ConnectSettings.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | import java.net.InetSocketAddress;
4 |
5 | public interface ConnectSettings {
6 |
7 | /**
8 | *
9 | * @return the address of the remote network's server
10 | */
11 | public InetSocketAddress getOutboundAddress();
12 |
13 | /**
14 | *
15 | * @return the username to be authenticated with on the network
16 | */
17 | public String getUsername();
18 |
19 | /**
20 | *
21 | * @return the password to be authenticated with on the network
22 | */
23 | public String getPassword();
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/MessageEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | @Deprecated
4 | public class MessageEvent extends lilypad.client.connect.api.event.MessageEvent {
5 |
6 | /**
7 | * Create a legacy message event from a new message event.
8 | *
9 | * @param event
10 | */
11 | public MessageEvent(lilypad.client.connect.api.event.MessageEvent event) {
12 | super(event.getSender(), event.getChannel(), event.getMessage());
13 | }
14 |
15 | /**
16 | *
17 | * @param sender of the event
18 | * @param channel of the event
19 | * @param message of the event
20 | */
21 | public MessageEvent(String sender, String channel, byte[] message) {
22 | super(sender, channel, message);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/MessageEventListener.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | @Deprecated
4 | public interface MessageEventListener {
5 |
6 | /**
7 | * Called when a message has been received by the session.
8 | *
9 | * @param connect session that the event belongs to
10 | * @param messageEvent
11 | */
12 | public void onMessage(Connect connect, MessageEvent messageEvent);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/RedirectEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | @Deprecated
4 | public class RedirectEvent extends lilypad.client.connect.api.event.RedirectEvent {
5 |
6 | /**
7 | * Create a legacy redirect event from a new redirect event.
8 | *
9 | * @param event
10 | */
11 | public RedirectEvent(lilypad.client.connect.api.event.RedirectEvent event) {
12 | super(event.getServer(), event.getPlayer());
13 | }
14 |
15 | /**
16 | *
17 | * @param server the server to redirect to
18 | * @param player the player to be redirected
19 | */
20 | public RedirectEvent(String server, String player) {
21 | super(server, player);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/RedirectEventListener.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | @Deprecated
4 | public interface RedirectEventListener {
5 |
6 | /**
7 | * Called when a player is to be redirected to a specified
8 | * server by the session when the session is the role of a proxy.
9 | *
10 | * @param connect session that the event belongs to
11 | * @param redirectEvent
12 | */
13 | public void onRedirect(Connect connect, RedirectEvent redirectEvent);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/ServerAddEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | import java.net.InetSocketAddress;
4 |
5 | @Deprecated
6 | public class ServerAddEvent extends lilypad.client.connect.api.event.ServerAddEvent {
7 |
8 | /**
9 | * Create a legacy server add event from a new server add event.
10 | *
11 | * @param event
12 | */
13 | public ServerAddEvent(lilypad.client.connect.api.event.ServerAddEvent event) {
14 | super(event.getServer(), event.getSecurityKey(), event.getAddress());
15 | }
16 |
17 | /**
18 | *
19 | * @param server the server that has been added
20 | * @param securityKey the security key of the server
21 | * @param address the connection address of the server
22 | */
23 | public ServerAddEvent(String server, String securityKey, InetSocketAddress address) {
24 | super(server, securityKey, address);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/ServerEventListener.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api;
2 |
3 | @Deprecated
4 | public interface ServerEventListener {
5 |
6 | /**
7 | * Called when a server has been added to the network
8 | * when the session is the role of a proxy.
9 | *
10 | * @param connect session that the event belongs to
11 | * @param event
12 | */
13 | public void onServerAdd(Connect connect, ServerAddEvent event);
14 |
15 | /**
16 | * Called when a server has been removed from the network
17 | * when the session is the role of a proxy.
18 | *
19 | * @param connect session that the event belongs to
20 | * @param server that has been removed
21 | */
22 | public void onServerRemove(Connect connect, String server);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/Event.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | /**
4 | * Super-class for events.
5 | */
6 | public abstract class Event {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/EventListener.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Used to mark a method as an EventListener.
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.METHOD)
13 | public @interface EventListener {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/MessageEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | /**
6 | * Called when a message has been received by the session.
7 | */
8 | public class MessageEvent extends Event {
9 |
10 | private String sender;
11 | private String channel;
12 | private byte[] message;
13 |
14 | /**
15 | *
16 | * @param sender of the event
17 | * @param channel of the event
18 | * @param message of the event
19 | */
20 | public MessageEvent(String sender, String channel, byte[] message) {
21 | this.sender = sender;
22 | this.channel = channel;
23 | this.message = message;
24 | }
25 |
26 | /**
27 | *
28 | * @return sender of the message
29 | */
30 | public String getSender() {
31 | return this.sender;
32 | }
33 |
34 | /**
35 | *
36 | * @return channel to identify the message
37 | */
38 | public String getChannel() {
39 | return this.channel;
40 | }
41 |
42 | /**
43 | *
44 | * @return message
45 | */
46 | public byte[] getMessage() {
47 | return this.message;
48 | }
49 |
50 | /**
51 | *
52 | * @return message represented as a UTF-8 string
53 | * @throws UnsupportedEncodingException if the message can not be represented as a UTF-8 string
54 | */
55 | public String getMessageAsString() throws UnsupportedEncodingException {
56 | return new String(this.message, "UTF-8");
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/RedirectEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | /**
4 | * Called when a player is to be redirected to a specified
5 | * server by the session when the session is the role of a proxy.
6 | */
7 | public class RedirectEvent extends Event {
8 |
9 | private String server;
10 | private String player;
11 |
12 | /**
13 | *
14 | * @param server the server to redirect to
15 | * @param player the player to be redirected
16 | */
17 | public RedirectEvent(String server, String player) {
18 | this.server = server;
19 | this.player = player;
20 | }
21 |
22 | /**
23 | *
24 | * @return the server to redirect to
25 | */
26 | public String getServer() {
27 | return this.server;
28 | }
29 |
30 | /**
31 | *
32 | * @return the player to be redirected
33 | */
34 | public String getPlayer() {
35 | return this.player;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/ServerAddEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | import java.net.InetSocketAddress;
4 |
5 | /**
6 | * Called when a server has been added to the network
7 | * when the session is the role of a proxy.
8 | */
9 | public class ServerAddEvent extends Event {
10 |
11 | private String server;
12 | private String securityKey;
13 | private InetSocketAddress address;
14 |
15 | /**
16 | *
17 | * @param server the server that has been added
18 | * @param securityKey the security key of the server
19 | * @param address the connection address of the server
20 | */
21 | public ServerAddEvent(String server, String securityKey, InetSocketAddress address) {
22 | this.server = server;
23 | this.securityKey = securityKey;
24 | this.address = address;
25 | }
26 |
27 | /**
28 | *
29 | * @return the server that has been added
30 | */
31 | public String getServer() {
32 | return this.server;
33 | }
34 |
35 | /**
36 | *
37 | * @return the security key of the server
38 | */
39 | public String getSecurityKey() {
40 | return this.securityKey;
41 | }
42 |
43 | /**
44 | *
45 | * @return the connection address of the server
46 | */
47 | public InetSocketAddress getAddress() {
48 | return this.address;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/event/ServerRemoveEvent.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.event;
2 |
3 | /**
4 | * Called when a server has been removed from the network
5 | * when the session is the role of a proxy.
6 | */
7 | public class ServerRemoveEvent extends Event {
8 |
9 | private String server;
10 |
11 | /**
12 | *
13 | * @param server the server removed from the network
14 | */
15 | public ServerRemoveEvent(String server) {
16 | this.server = server;
17 | }
18 |
19 | /**
20 | *
21 | * @return the server removed from the network
22 | */
23 | public String getServer() {
24 | return this.server;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/Request.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 |
5 | public interface Request {
6 |
7 | /**
8 | *
9 | * @return accompanying result of the request
10 | */
11 | public Class getResult();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/RequestException.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request;
2 |
3 | public class RequestException extends Exception {
4 |
5 | private static final long serialVersionUID = 1L;
6 |
7 | /**
8 | * Showing a request failed
9 | *
10 | * @param reason of the exception
11 | */
12 | public RequestException(String reason) {
13 | super(reason);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/AsServerRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.AsServerResult;
5 |
6 | /**
7 | * Request to be assigned the role of a server on the network.
8 | */
9 | public class AsServerRequest implements Request {
10 |
11 | private String ip;
12 | private int port;
13 |
14 | /**
15 | * Shortcut to dictate that the network should assume it's ip
16 | * address.
17 | *
18 | * @param port of the server
19 | */
20 | public AsServerRequest(int port) {
21 | this(null, port);
22 | }
23 |
24 | /**
25 | *
26 | * @param ip of the server, null if the network should assume
27 | * it's ip address
28 | * @param port of the server
29 | */
30 | public AsServerRequest(String ip, int port) {
31 | this.ip = ip;
32 | this.port = port;
33 | }
34 |
35 | /**
36 | *
37 | * @return accompanying result of the request
38 | */
39 | public Class getResult() {
40 | return AsServerResult.class;
41 | }
42 |
43 | /**
44 | *
45 | * @return the ip address of the server, null if the network
46 | * should assume it's ip address
47 | */
48 | public String getIp() {
49 | return this.ip;
50 | }
51 |
52 | /**
53 | *
54 | * @return the port number of the server
55 | */
56 | public int getPort() {
57 | return this.port;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/AuthenticateRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.AuthenticateResult;
5 | import lilypad.client.connect.api.util.SecurityUtils;
6 |
7 | /**
8 | * Request to authenticate with the network.
9 | */
10 | public class AuthenticateRequest implements Request {
11 |
12 | private String username;
13 | private String password;
14 |
15 | /**
16 | *
17 | * @param username to be authenticated with
18 | * @param password to be authenticated with
19 | * @param passwordKey salt to hash the password with
20 | */
21 | public AuthenticateRequest(String username, String password, String passwordKey) {
22 | this.username = username;
23 | this.password = SecurityUtils.shaHex(SecurityUtils.shaHex(passwordKey) + SecurityUtils.shaHex(password));
24 | }
25 |
26 | /**
27 | *
28 | * @return accompanying result of the request
29 | */
30 | public Class getResult() {
31 | return AuthenticateResult.class;
32 | }
33 |
34 | /**
35 | *
36 | * @return username to be authenticated with
37 | */
38 | public String getUsername() {
39 | return this.username;
40 | }
41 |
42 | /**
43 | *
44 | * @return password to be authenticated with
45 | */
46 | public String getPassword() {
47 | return this.password;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/GetDetailsRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.GetDetailsResult;
5 |
6 | /**
7 | * Request to get the uniform connection details of the network,
8 | * not guaranteed to be an accurate representation.
9 | */
10 | public class GetDetailsRequest implements Request {
11 |
12 | /**
13 | *
14 | * @return accompanying result of the request
15 | */
16 | public Class getResult() {
17 | return GetDetailsResult.class;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/GetKeyRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.GetKeyResult;
5 |
6 | /**
7 | * Request to receive a shared salt to be used within the
8 | * authentication process.
9 | */
10 | public class GetKeyRequest implements Request {
11 |
12 | /**
13 | *
14 | * @return accompanying result of the request
15 | */
16 | public Class getResult() {
17 | return GetKeyResult.class;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/GetPlayersRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.GetPlayersResult;
5 |
6 | /**
7 | * Request to get an accurate representation of all players
8 | * on the network.
9 | */
10 | public class GetPlayersRequest implements Request {
11 |
12 | private boolean asList;
13 |
14 | /**
15 | * Shortcut to dictate that we needn't a list of every
16 | * player.
17 | */
18 | public GetPlayersRequest() {
19 | this(false);
20 | }
21 |
22 | /**
23 | *
24 | * @param asList if a list of every player is required
25 | */
26 | public GetPlayersRequest(boolean asList) {
27 | this.asList = asList;
28 | }
29 |
30 | /**
31 | *
32 | * @return accompanying result of the request
33 | */
34 | public Class getResult() {
35 | return GetPlayersResult.class;
36 | }
37 |
38 | /**
39 | *
40 | * @return if a list of every player is required
41 | */
42 | public boolean getAsList() {
43 | return this.asList;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/GetWhoamiRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.GetWhoamiResult;
5 |
6 | /**
7 | * Request to get the current identification the network
8 | * recognizes your session as.
9 | */
10 | public class GetWhoamiRequest implements Request {
11 |
12 | /**
13 | *
14 | * @return accompanying result of the request
15 | */
16 | public Class getResult() {
17 | return GetWhoamiResult.class;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/NotifyPlayerRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.NotifyPlayerResult;
5 |
6 | /**
7 | * Request to notify the network that a player has been added
8 | * or removed from our proxy.
9 | */
10 | public class NotifyPlayerRequest implements Request {
11 |
12 | private boolean addOrRemove;
13 | private String player;
14 |
15 | /**
16 | *
17 | * @param addOrRemove true if adding, false if removing
18 | * @param player in question
19 | */
20 | public NotifyPlayerRequest(boolean addOrRemove, String player) {
21 | this.addOrRemove = addOrRemove;
22 | this.player = player;
23 | }
24 |
25 | /**
26 | *
27 | * @return accompanying result of the request
28 | */
29 | public Class getResult() {
30 | return NotifyPlayerResult.class;
31 | }
32 |
33 | /**
34 | *
35 | * @return if this is a request to add
36 | */
37 | public boolean isAdding() {
38 | return this.addOrRemove;
39 | }
40 |
41 | /**
42 | *
43 | * @return if this is a request to remove
44 | */
45 | public boolean isRemoving() {
46 | return !this.addOrRemove;
47 | }
48 |
49 | /**
50 | *
51 | * @return the player in question
52 | */
53 | public String getPlayer() {
54 | return this.player;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/request/impl/RedirectRequest.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.request.impl;
2 |
3 | import lilypad.client.connect.api.request.Request;
4 | import lilypad.client.connect.api.result.impl.RedirectResult;
5 |
6 | /**
7 | * Request asking the network to redirect a player to a specified
8 | * server.
9 | */
10 | public class RedirectRequest implements Request {
11 |
12 | private String server;
13 | private String player;
14 |
15 | /**
16 | *
17 | * @param server to be redirected to
18 | * @param player to be redirected
19 | */
20 | public RedirectRequest(String server, String player) {
21 | this.server = server;
22 | this.player = player;
23 | }
24 |
25 | /**
26 | *
27 | * @return accompanying result of the request
28 | */
29 | public Class getResult() {
30 | return RedirectResult.class;
31 | }
32 |
33 | /**
34 | *
35 | * @return the server to be redirected to
36 | */
37 | public String getServer() {
38 | return this.server;
39 | }
40 |
41 | /**
42 | *
43 | * @return the player to be redirected
44 | */
45 | public String getPlayer() {
46 | return this.player;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/FutureResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result;
2 |
3 | public interface FutureResult {
4 |
5 | /**
6 | * Registers a listener to receive a callback when the future
7 | * has been completed.
8 | *
9 | * @param futureResultListener
10 | */
11 | public void registerListener(FutureResultListener futureResultListener);
12 |
13 | /**
14 | * Unregisters a listener to exclude from receiving a callback
15 | * when the future has been completed.
16 | *
17 | * @param futureResultListener
18 | */
19 | public void unregisterListener(FutureResultListener futureResultListener);
20 |
21 | /**
22 | * Awaits a result with no timeout.
23 | *
24 | * @return the result, null if cancelled
25 | * @throws InterruptedException
26 | */
27 | public T await() throws InterruptedException;
28 |
29 | /**
30 | * Awaits a result with a timeout in milliseconds.
31 | *
32 | * @return the result, null if cancelled
33 | * @throws InterruptedException
34 | */
35 | public T await(long timeout) throws InterruptedException;
36 |
37 | /**
38 | * Awaits a result uninterruptibly with no timeout.
39 | *
40 | * @return the result, null if cancelled
41 | */
42 | public T awaitUninterruptibly();
43 |
44 | /**
45 | * Awaits a result uninterruptibly with a timeout in milliseconds.
46 | *
47 | * @return the result, null if cancelled
48 | */
49 | public T awaitUninterruptibly(long timeout);
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/FutureResultListener.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result;
2 |
3 | public interface FutureResultListener {
4 |
5 | /**
6 | * Called when a result has been received for a registered
7 | * FutureResult.
8 | *
9 | * @param result of the request
10 | * @see FutureResult
11 | */
12 | public void onResult(T result);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/Result.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result;
2 |
3 | public abstract class Result {
4 |
5 | private StatusCode statusCode;
6 |
7 | /**
8 | *
9 | * @param statusCode of the result
10 | */
11 | public Result(StatusCode statusCode) {
12 | this.statusCode = statusCode;
13 | }
14 |
15 | /**
16 | * Showing how the request was handled by the network, namely
17 | * if it succeeded or failed.
18 | *
19 | * @return status code
20 | */
21 | public StatusCode getStatusCode() {
22 | return this.statusCode;
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/StatusCode.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result;
2 |
3 | public enum StatusCode {
4 |
5 | /**
6 | * Failure of any reason relative to what the result
7 | * entitles.
8 | */
9 | INVALID_GENERIC,
10 | /**
11 | * Failure due to the fact of the session not having
12 | * the required role to make the request.
13 | */
14 | INVALID_ROLE,
15 | /**
16 | * Success.
17 | */
18 | SUCCESS;
19 | }
20 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/AsProxyResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class AsProxyResult extends Result {
7 |
8 | /**
9 | *
10 | * @param statusCode of the result
11 | */
12 | public AsProxyResult(StatusCode statusCode) {
13 | super(statusCode);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/AsServerResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class AsServerResult extends Result {
7 |
8 | private String securityKey;
9 |
10 | /**
11 | * Called only when the result is unsuccessful.
12 | *
13 | * @param statusCode of the result
14 | */
15 | public AsServerResult(StatusCode statusCode) {
16 | super(statusCode);
17 | }
18 |
19 | /**
20 | * Showing the result was successful, passing the data
21 | * to accompany the result.
22 | *
23 | * @param securityKey of the result
24 | */
25 | public AsServerResult(String securityKey) {
26 | super(StatusCode.SUCCESS);
27 | this.securityKey = securityKey;
28 | }
29 |
30 | /**
31 | * Secret used within the game login process for authorization.
32 | *
33 | * @return security key
34 | */
35 | public String getSecurityKey() {
36 | return this.securityKey;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/AuthenticateResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class AuthenticateResult extends Result {
7 |
8 | /**
9 | *
10 | * @param statusCode of the result
11 | */
12 | public AuthenticateResult(StatusCode statusCode) {
13 | super(statusCode);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/GetDetailsResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class GetDetailsResult extends Result {
7 |
8 | private String ip;
9 | private int port;
10 | private String motd;
11 | private String version;
12 |
13 | /**
14 | * Called only when the result is unsuccessful.
15 | *
16 | * @param statusCode of the result
17 | */
18 | public GetDetailsResult(StatusCode statusCode) {
19 | super(statusCode);
20 | }
21 |
22 | /**
23 | * Showing the result was successful, passing the data
24 | * to accompany the result.
25 | *
26 | * @param ip of the result
27 | * @param port of the result
28 | * @param motd of the result
29 | * @param version of the result
30 | */
31 | public GetDetailsResult(String ip, int port, String motd, String version) {
32 | super(StatusCode.SUCCESS);
33 | this.ip = ip;
34 | this.port = port;
35 | this.motd = motd;
36 | this.version = version;
37 | }
38 |
39 | /**
40 | * Uniform ip address decided by the network deriving from a single
41 | * proxy. There is no guarantee which proxy this ip address derives from.
42 | *
43 | * @return ip address
44 | */
45 | public String getIp() {
46 | return this.ip;
47 | }
48 |
49 | /**
50 | * Uniform port number decided by the network deriving from a single
51 | * proxy. There is no guarantee which proxy this port number derives from.
52 | *
53 | * @return port number
54 | */
55 | public int getPort() {
56 | return this.port;
57 | }
58 |
59 | /**
60 | * Uniform motd decided by the network deriving from a single proxy.
61 | * There is no guarantee which proxy this motd derives from.
62 | *
63 | * @return motd
64 | */
65 | public String getMotd() {
66 | return this.motd;
67 | }
68 |
69 | /**
70 | * Uniform version decided by the network deriving from a single proxy.
71 | * There is no guarantee which proxy this version derives from.
72 | *
73 | * @return motd
74 | */
75 | public String getVersion() {
76 | return this.version;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/GetKeyResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class GetKeyResult extends Result {
7 |
8 | private String key;
9 |
10 | /**
11 | * Called only when the result is unsuccessful.
12 | *
13 | * @param statusCode of the result
14 | */
15 | public GetKeyResult(StatusCode statusCode) {
16 | super(statusCode);
17 | }
18 |
19 | /**
20 | * Showing the result was successful, passing the data
21 | * to accompany the result.
22 | *
23 | * @param key
24 | */
25 | public GetKeyResult(String key) {
26 | this(StatusCode.SUCCESS);
27 | this.key = key;
28 | }
29 |
30 | /**
31 | * Shared salt used within the authentication process for the password.
32 | *
33 | * @return salt
34 | */
35 | public String getKey() {
36 | return this.key;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/GetPlayersResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import java.util.Set;
4 |
5 | import lilypad.client.connect.api.result.Result;
6 | import lilypad.client.connect.api.result.StatusCode;
7 |
8 | public class GetPlayersResult extends Result {
9 |
10 | private int currentPlayers;
11 | private int maximumPlayers;
12 | private Set players;
13 |
14 | /**
15 | * Called only when the result is unsuccessful.
16 | *
17 | * @param statusCode of the result
18 | */
19 | public GetPlayersResult(StatusCode statusCode) {
20 | super(statusCode);
21 | }
22 |
23 | /**
24 | * Showing the result was successful, passing the data
25 | * to accompany the result.
26 | *
27 | * @param currentPlayers
28 | * @param maximumPlayers
29 | * @param players
30 | */
31 | public GetPlayersResult(int currentPlayers, int maximumPlayers, Set players) {
32 | super(StatusCode.SUCCESS);
33 | this.currentPlayers = currentPlayers;
34 | this.maximumPlayers = maximumPlayers;
35 | this.players = players;
36 | }
37 |
38 | /**
39 | * An accurate representation of the current player count
40 | * as reported by the network
41 | *
42 | * @return current players
43 | */
44 | public int getCurrentPlayers() {
45 | return this.currentPlayers;
46 | }
47 |
48 | /**
49 | * The maximum players allowed on the network. This is normally
50 | * calculated through the sum of all proxies' maximum player count,
51 | * however when at least one proxies' player count is below 2,
52 | * it will return the single proxies' player count instead
53 | *
54 | * @return max players
55 | */
56 | public int getMaximumPlayers() {
57 | return this.maximumPlayers;
58 | }
59 |
60 | /**
61 | * If the original request asked for the list of players, an accurate
62 | * representation of all players on the network will be returned.
63 | * Otherwise, it will return null.
64 | *
65 | * @return set of players
66 | */
67 | public Set getPlayers() {
68 | return this.players;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/GetWhoamiResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class GetWhoamiResult extends Result {
7 |
8 | private String identification;
9 |
10 | /**
11 | * Called only when the result is unsuccessful.
12 | *
13 | * @param statusCode of the result
14 | */
15 | public GetWhoamiResult(StatusCode statusCode) {
16 | super(statusCode);
17 | }
18 |
19 | /**
20 | * Showing the result was successful, passing the data
21 | * to accompany the result.
22 | *
23 | * @param identification
24 | */
25 | public GetWhoamiResult(String identification) {
26 | super(StatusCode.SUCCESS);
27 | this.identification = identification;
28 | }
29 |
30 | /**
31 | * The network will identify you differently based on your state.
32 | * If you are unauthenticated, your identification will be blank, while if
33 | * you are authenticated, your identification will be [username].[uniqueInt],
34 | * and if you are either a server or a proxy, your identification will simply
35 | * be [username].
36 | *
37 | * @return identification by the network
38 | */
39 | public String getIdentification() {
40 | return this.identification;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/MessageResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class MessageResult extends Result {
7 |
8 | /**
9 | *
10 | * @param statusCode of the result
11 | */
12 | public MessageResult(StatusCode statusCode) {
13 | super(statusCode);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/NotifyPlayerResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class NotifyPlayerResult extends Result {
7 |
8 | /**
9 | *
10 | * @param statusCode of the result
11 | */
12 | public NotifyPlayerResult(StatusCode statusCode) {
13 | super(statusCode);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/result/impl/RedirectResult.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.result.impl;
2 |
3 | import lilypad.client.connect.api.result.Result;
4 | import lilypad.client.connect.api.result.StatusCode;
5 |
6 | public class RedirectResult extends Result {
7 |
8 | /**
9 | *
10 | * @param statusCode of the result
11 | */
12 | public RedirectResult(StatusCode statusCode) {
13 | super(statusCode);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/client-connect-api/src/main/java/lilypad/client/connect/api/util/SecurityUtils.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.api.util;
2 |
3 | import java.math.BigInteger;
4 | import java.security.MessageDigest;
5 |
6 | public class SecurityUtils {
7 |
8 | /**
9 | * Calculates a SHA-1 Hex-Encoded Hash of a String's bytes given
10 | * the default system Charset.
11 | *
12 | * @param string input by which to derive the hash
13 | * @return SHA-1 Hex-Encoded Hash derived from the input
14 | */
15 | public static String shaHex(String string) {
16 | return shaHex(string.getBytes());
17 | }
18 |
19 | /**
20 | * Calculates a SHA-1 Hex-Encoded Hash of an input.
21 | *
22 | * @param bytesArray input by which to derive the hash
23 | * @return SHA-1 Hex-Encoded Hash derived from the input
24 | */
25 | public static String shaHex(byte[]... bytesArray) {
26 | try {
27 | MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
28 | for(byte[] bytes : bytesArray) {
29 | messageDigest.update(bytes);
30 | }
31 | String hash = new BigInteger(1, messageDigest.digest()).toString(16);
32 | if(hash.length() == 39) {
33 | hash = "0" + hash;
34 | }
35 | return hash;
36 | } catch(Exception exception) {
37 | exception.printStackTrace();
38 | return null;
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/client-connect-lib/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | /.classpath
3 | /.project
4 | /.settings
5 |
6 | # Netbeans
7 | /nbproject
8 |
9 | # Maven
10 | /build.xml
11 | /target
12 |
13 | # vim
14 | .*.sw[a-p]
15 |
16 | # Build
17 | /build
18 | /bin
19 | /dist
20 | /manifest.mf
21 |
22 | # Mac OS X
23 | /.DS_Store
24 |
25 | # Intellij
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
31 | # Temp
32 | *~
33 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/ConnectRequestEncoderRegistry.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request;
2 |
3 | import lilypad.client.connect.lib.request.impl.AsProxyRequestEncoder;
4 | import lilypad.client.connect.lib.request.impl.AsServerRequestEncoder;
5 | import lilypad.client.connect.lib.request.impl.AuthenticateRequestEncoder;
6 | import lilypad.client.connect.lib.request.impl.GetDetailsRequestEncoder;
7 | import lilypad.client.connect.lib.request.impl.GetKeyRequestEncoder;
8 | import lilypad.client.connect.lib.request.impl.GetPlayersRequestEncoder;
9 | import lilypad.client.connect.lib.request.impl.GetWhoamiRequestEncoder;
10 | import lilypad.client.connect.lib.request.impl.MessageRequestEncoder;
11 | import lilypad.client.connect.lib.request.impl.NotifyPlayerRequestEncoder;
12 | import lilypad.client.connect.lib.request.impl.RedirectRequestEncoder;
13 |
14 | public class ConnectRequestEncoderRegistry extends RequestEncoderRegistry {
15 |
16 | public static final ConnectRequestEncoderRegistry instance = new ConnectRequestEncoderRegistry();
17 |
18 | private ConnectRequestEncoderRegistry() {
19 | this.submit(new AsProxyRequestEncoder());
20 | this.submit(new AsServerRequestEncoder());
21 | this.submit(new AuthenticateRequestEncoder());
22 | this.submit(new GetDetailsRequestEncoder());
23 | this.submit(new GetKeyRequestEncoder());
24 | this.submit(new GetPlayersRequestEncoder());
25 | this.submit(new GetWhoamiRequestEncoder());
26 | this.submit(new MessageRequestEncoder());
27 | this.submit(new NotifyPlayerRequestEncoder());
28 | this.submit(new RedirectRequestEncoder());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/RequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.Request;
5 |
6 | public interface RequestEncoder> {
7 |
8 | public void encode(T request, ByteBuf buffer);
9 |
10 | public int getId();
11 |
12 | public Class getRequest();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/RequestEncoderRegistry.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import lilypad.client.connect.api.request.Request;
7 |
8 | public class RequestEncoderRegistry {
9 |
10 | private Map>, RequestEncoder>> registryByRequest = new HashMap>, RequestEncoder>>();
11 | private RequestEncoder>[] registryById = new RequestEncoder>[256];
12 |
13 | public void submit(RequestEncoder> requestEncoder) {
14 | if(requestEncoder == null) {
15 | return;
16 | }
17 | this.registryByRequest.put(requestEncoder.getRequest(), requestEncoder);
18 | this.registryById[requestEncoder.getId()] = requestEncoder;
19 | }
20 |
21 | public RequestEncoder> getById(int id) {
22 | return this.registryById[id];
23 | }
24 |
25 | public RequestEncoder> getByRequest(Class> request) {
26 | return this.registryByRequest.get(request);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/AsProxyRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.AsProxyRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class AsProxyRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(AsProxyRequest request, ByteBuf buffer) {
12 | if(request.getIp() == null) {
13 | BufferUtils.writeVarInt(buffer, 0);
14 | } else {
15 | BufferUtils.writeString(buffer, request.getIp());
16 | }
17 | buffer.writeShort(request.getPort());
18 | BufferUtils.writeString(buffer, request.getMotd());
19 | BufferUtils.writeString(buffer, request.getVersion());
20 | buffer.writeShort(request.getMaximumPlayers());
21 | }
22 |
23 | public int getId() {
24 | return ConnectPacketConstants.requestAsProxy;
25 | }
26 |
27 | public Class getRequest() {
28 | return AsProxyRequest.class;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/AsServerRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.AsServerRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class AsServerRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(AsServerRequest request, ByteBuf buffer) {
12 | if(request.getIp() == null) {
13 | BufferUtils.writeVarInt(buffer, 0);
14 | } else {
15 | BufferUtils.writeString(buffer, request.getIp());
16 | }
17 | buffer.writeShort(request.getPort());
18 | }
19 |
20 | public int getId() {
21 | return ConnectPacketConstants.requestAsServer;
22 | }
23 |
24 | public Class getRequest() {
25 | return AsServerRequest.class;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/AuthenticateRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.AuthenticateRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class AuthenticateRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(AuthenticateRequest request, ByteBuf buffer) {
12 | BufferUtils.writeString(buffer, request.getUsername());
13 | BufferUtils.writeString(buffer, request.getPassword());
14 | }
15 |
16 | public int getId() {
17 | return ConnectPacketConstants.requestAuthenticate;
18 | }
19 |
20 | public Class getRequest() {
21 | return AuthenticateRequest.class;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/GetDetailsRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.GetDetailsRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.connect.ConnectPacketConstants;
7 |
8 | public class GetDetailsRequestEncoder implements RequestEncoder {
9 |
10 | public void encode(GetDetailsRequest request, ByteBuf buffer) {
11 | // no payload
12 | }
13 |
14 | public int getId() {
15 | return ConnectPacketConstants.requestGetDetails;
16 | }
17 |
18 | public Class getRequest() {
19 | return GetDetailsRequest.class;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/GetKeyRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.GetKeyRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.connect.ConnectPacketConstants;
7 |
8 | public class GetKeyRequestEncoder implements RequestEncoder {
9 |
10 | public void encode(GetKeyRequest request, ByteBuf buffer) {
11 | // no payload
12 | }
13 |
14 | public int getId() {
15 | return ConnectPacketConstants.requestGetKey;
16 | }
17 |
18 | public Class getRequest() {
19 | return GetKeyRequest.class;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/GetPlayersRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.GetPlayersRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.connect.ConnectPacketConstants;
7 |
8 | public class GetPlayersRequestEncoder implements RequestEncoder {
9 |
10 | public void encode(GetPlayersRequest request, ByteBuf buffer) {
11 | buffer.writeBoolean(request.getAsList());
12 | }
13 |
14 | public int getId() {
15 | return ConnectPacketConstants.requestGetPlayers;
16 | }
17 |
18 | public Class getRequest() {
19 | return GetPlayersRequest.class;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/GetWhoamiRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.GetWhoamiRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.connect.ConnectPacketConstants;
7 |
8 | public class GetWhoamiRequestEncoder implements RequestEncoder {
9 |
10 | public void encode(GetWhoamiRequest request, ByteBuf buffer) {
11 | // no payload
12 | }
13 |
14 | public int getId() {
15 | return ConnectPacketConstants.requestGetWhoami;
16 | }
17 |
18 | public Class getRequest() {
19 | return GetWhoamiRequest.class;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/MessageRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.MessageRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class MessageRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(MessageRequest request, ByteBuf buffer) {
12 | buffer.writeShort(request.getRecipients().size());
13 | for(String username : request.getRecipients()) {
14 | BufferUtils.writeString(buffer, username);
15 | }
16 | BufferUtils.writeString(buffer, request.getChannel());
17 | buffer.writeShort(request.getMessage().length);
18 | buffer.writeBytes(request.getMessage());
19 | }
20 |
21 | public int getId() {
22 | return ConnectPacketConstants.requestMessage;
23 | }
24 |
25 | public Class getRequest() {
26 | return MessageRequest.class;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/NotifyPlayerRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.NotifyPlayerRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class NotifyPlayerRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(NotifyPlayerRequest request, ByteBuf buffer) {
12 | buffer.writeBoolean(request.isAdding());
13 | BufferUtils.writeString(buffer, request.getPlayer());
14 | }
15 |
16 | public int getId() {
17 | return ConnectPacketConstants.requestNotifyPlayer;
18 | }
19 |
20 | public Class getRequest() {
21 | return NotifyPlayerRequest.class;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/request/impl/RedirectRequestEncoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.request.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.request.impl.RedirectRequest;
5 | import lilypad.client.connect.lib.request.RequestEncoder;
6 | import lilypad.packet.common.util.BufferUtils;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class RedirectRequestEncoder implements RequestEncoder {
10 |
11 | public void encode(RedirectRequest request, ByteBuf buffer) {
12 | BufferUtils.writeString(buffer, request.getServer());
13 | BufferUtils.writeString(buffer, request.getPlayer());
14 | }
15 |
16 | public int getId() {
17 | return ConnectPacketConstants.requestRedirect;
18 | }
19 |
20 | public Class getRequest() {
21 | return RedirectRequest.class;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/ConnectResultDecoderRegistry.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result;
2 |
3 | import lilypad.client.connect.lib.result.impl.AsProxyResultDecoder;
4 | import lilypad.client.connect.lib.result.impl.AsServerResultDecoder;
5 | import lilypad.client.connect.lib.result.impl.AuthenticateResultDecoder;
6 | import lilypad.client.connect.lib.result.impl.GetDetailsResultDecoder;
7 | import lilypad.client.connect.lib.result.impl.GetKeyResultDecoder;
8 | import lilypad.client.connect.lib.result.impl.GetPlayersResultDecoder;
9 | import lilypad.client.connect.lib.result.impl.GetWhoamiResultDecoder;
10 | import lilypad.client.connect.lib.result.impl.MessageResultDecoder;
11 | import lilypad.client.connect.lib.result.impl.NotifyPlayerResultDecoder;
12 | import lilypad.client.connect.lib.result.impl.RedirectResultDecoder;
13 |
14 | public class ConnectResultDecoderRegistry extends ResultDecoderRegistry {
15 |
16 | public static final ConnectResultDecoderRegistry instance = new ConnectResultDecoderRegistry();
17 |
18 | private ConnectResultDecoderRegistry() {
19 | this.submit(new AsProxyResultDecoder());
20 | this.submit(new AsServerResultDecoder());
21 | this.submit(new AuthenticateResultDecoder());
22 | this.submit(new GetDetailsResultDecoder());
23 | this.submit(new GetKeyResultDecoder());
24 | this.submit(new GetPlayersResultDecoder());
25 | this.submit(new GetWhoamiResultDecoder());
26 | this.submit(new MessageResultDecoder());
27 | this.submit(new NotifyPlayerResultDecoder());
28 | this.submit(new RedirectResultDecoder());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/ResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.Result;
5 | import lilypad.client.connect.api.result.StatusCode;
6 |
7 | public interface ResultDecoder {
8 |
9 | public T decode(StatusCode statusCode, ByteBuf buffer);
10 |
11 | public int getId();
12 |
13 | public Class getResult();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/ResultDecoderRegistry.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import lilypad.client.connect.api.result.Result;
7 |
8 | public class ResultDecoderRegistry {
9 |
10 | private Map, ResultDecoder>> registryByResult = new HashMap, ResultDecoder>>();
11 | private ResultDecoder>[] registryById = new ResultDecoder>[256];
12 |
13 | public void submit(ResultDecoder> resultDecoder) {
14 | if(resultDecoder == null) {
15 | return;
16 | }
17 | this.registryByResult.put(resultDecoder.getResult(), resultDecoder);
18 | this.registryById[resultDecoder.getId()] = resultDecoder;
19 | }
20 |
21 | public ResultDecoder> getByResult(Class extends Result> resultClass) {
22 | return this.registryByResult.get(resultClass);
23 | }
24 |
25 | public ResultDecoder> getById(int id) {
26 | return this.registryById[id];
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/AsProxyResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.AsProxyResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class AsProxyResultDecoder implements ResultDecoder {
10 |
11 | public AsProxyResult decode(StatusCode statusCode, ByteBuf buffer) {
12 | return new AsProxyResult(statusCode);
13 | }
14 |
15 | public int getId() {
16 | return ConnectPacketConstants.requestAsProxy;
17 | }
18 |
19 | public Class getResult() {
20 | return AsProxyResult.class;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/AsServerResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.AsServerResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.common.util.BufferUtils;
8 | import lilypad.packet.connect.ConnectPacketConstants;
9 |
10 | public class AsServerResultDecoder implements ResultDecoder {
11 |
12 | public AsServerResult decode(StatusCode statusCode, ByteBuf buffer) {
13 | if(statusCode == StatusCode.SUCCESS) {
14 | return new AsServerResult(BufferUtils.readString(buffer));
15 | } else {
16 | return new AsServerResult(statusCode);
17 | }
18 | }
19 |
20 | public int getId() {
21 | return ConnectPacketConstants.requestAsServer;
22 | }
23 |
24 | public Class getResult() {
25 | return AsServerResult.class;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/AuthenticateResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.AuthenticateResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class AuthenticateResultDecoder implements ResultDecoder {
10 |
11 | public AuthenticateResult decode(StatusCode statusCode, ByteBuf buffer) {
12 | return new AuthenticateResult(statusCode);
13 | }
14 |
15 | public int getId() {
16 | return ConnectPacketConstants.requestAuthenticate;
17 | }
18 |
19 | public Class getResult() {
20 | return AuthenticateResult.class;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/GetDetailsResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.GetDetailsResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.common.util.BufferUtils;
8 | import lilypad.packet.connect.ConnectPacketConstants;
9 |
10 | public class GetDetailsResultDecoder implements ResultDecoder {
11 |
12 | public GetDetailsResult decode(StatusCode statusCode, ByteBuf buffer) {
13 | if(statusCode == StatusCode.SUCCESS) {
14 | return new GetDetailsResult(BufferUtils.readString(buffer), buffer.readUnsignedShort(), BufferUtils.readString(buffer), BufferUtils.readString(buffer));
15 | } else {
16 | return new GetDetailsResult(statusCode);
17 | }
18 | }
19 |
20 | public int getId() {
21 | return ConnectPacketConstants.requestGetDetails;
22 | }
23 |
24 | public Class getResult() {
25 | return GetDetailsResult.class;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/GetKeyResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.GetKeyResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.common.util.BufferUtils;
8 | import lilypad.packet.connect.ConnectPacketConstants;
9 |
10 | public class GetKeyResultDecoder implements ResultDecoder {
11 |
12 | public GetKeyResult decode(StatusCode statusCode, ByteBuf buffer) {
13 | if(statusCode == StatusCode.SUCCESS) {
14 | return new GetKeyResult(BufferUtils.readString(buffer));
15 | } else {
16 | return new GetKeyResult(statusCode);
17 | }
18 | }
19 |
20 | public int getId() {
21 | return ConnectPacketConstants.requestGetKey;
22 | }
23 |
24 | public Class getResult() {
25 | return GetKeyResult.class;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/GetPlayersResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import java.util.HashSet;
4 | import java.util.Set;
5 |
6 | import io.netty.buffer.ByteBuf;
7 | import lilypad.client.connect.api.result.StatusCode;
8 | import lilypad.client.connect.api.result.impl.GetPlayersResult;
9 | import lilypad.client.connect.lib.result.ResultDecoder;
10 | import lilypad.packet.common.util.BufferUtils;
11 | import lilypad.packet.connect.ConnectPacketConstants;
12 |
13 | public class GetPlayersResultDecoder implements ResultDecoder {
14 |
15 | public GetPlayersResult decode(StatusCode statusCode, ByteBuf buffer) {
16 | if(statusCode == StatusCode.SUCCESS) {
17 | boolean hasList = buffer.readBoolean();
18 | int currentPlayers = buffer.readUnsignedShort();
19 | int maximumPlayers = buffer.readUnsignedShort();
20 | Set players = new HashSet();
21 | if(hasList) {
22 | for(int i = 0; i < currentPlayers; i++) {
23 | players.add(BufferUtils.readString(buffer));
24 | }
25 | }
26 | return new GetPlayersResult(currentPlayers, maximumPlayers, players);
27 | } else {
28 | return new GetPlayersResult(statusCode);
29 | }
30 | }
31 |
32 | public int getId() {
33 | return ConnectPacketConstants.requestGetPlayers;
34 | }
35 |
36 | public Class getResult() {
37 | return GetPlayersResult.class;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/GetWhoamiResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.GetWhoamiResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.common.util.BufferUtils;
8 | import lilypad.packet.connect.ConnectPacketConstants;
9 |
10 | public class GetWhoamiResultDecoder implements ResultDecoder {
11 |
12 | public GetWhoamiResult decode(StatusCode statusCode, ByteBuf buffer) {
13 | if(statusCode == StatusCode.SUCCESS) {
14 | return new GetWhoamiResult(BufferUtils.readString(buffer));
15 | } else {
16 | return new GetWhoamiResult(statusCode);
17 | }
18 | }
19 |
20 | public int getId() {
21 | return ConnectPacketConstants.requestGetWhoami;
22 | }
23 |
24 | public Class getResult() {
25 | return GetWhoamiResult.class;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/MessageResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.MessageResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class MessageResultDecoder implements ResultDecoder {
10 |
11 | public MessageResult decode(StatusCode statusCode, ByteBuf buffer) {
12 | return new MessageResult(statusCode);
13 | }
14 |
15 | public int getId() {
16 | return ConnectPacketConstants.requestMessage;
17 | }
18 |
19 | public Class getResult() {
20 | return MessageResult.class;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/NotifyPlayerResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.NotifyPlayerResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class NotifyPlayerResultDecoder implements ResultDecoder {
10 |
11 | public NotifyPlayerResult decode(StatusCode statusCode, ByteBuf buffer) {
12 | return new NotifyPlayerResult(statusCode);
13 | }
14 |
15 | public int getId() {
16 | return ConnectPacketConstants.requestNotifyPlayer;
17 | }
18 |
19 | public Class getResult() {
20 | return NotifyPlayerResult.class;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/result/impl/RedirectResultDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.result.impl;
2 |
3 | import io.netty.buffer.ByteBuf;
4 | import lilypad.client.connect.api.result.StatusCode;
5 | import lilypad.client.connect.api.result.impl.RedirectResult;
6 | import lilypad.client.connect.lib.result.ResultDecoder;
7 | import lilypad.packet.connect.ConnectPacketConstants;
8 |
9 | public class RedirectResultDecoder implements ResultDecoder {
10 |
11 | public RedirectResult decode(StatusCode statusCode, ByteBuf buffer) {
12 | return new RedirectResult(statusCode);
13 | }
14 |
15 | public int getId() {
16 | return ConnectPacketConstants.requestRedirect;
17 | }
18 |
19 | public Class getResult() {
20 | return RedirectResult.class;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/client-connect-lib/src/main/java/lilypad/client/connect/lib/util/StringUtils.java:
--------------------------------------------------------------------------------
1 | package lilypad.client.connect.lib.util;
2 |
3 | import java.util.List;
4 |
5 | public class StringUtils {
6 |
7 | public static String join(List args, String seperator) {
8 | return join(args.toArray(new String[0]), seperator);
9 | }
10 |
11 | public static String join(String[] args, String seperator) {
12 | StringBuilder builder = new StringBuilder();
13 | for (int i = 0; i < args.length; i++) {
14 | if (i != 0) {
15 | builder.append(seperator);
16 | }
17 | builder.append(args[i]);
18 | }
19 | return builder.toString();
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/packet-common/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | /.classpath
3 | /.project
4 | /.settings
5 |
6 | # Netbeans
7 | /nbproject
8 |
9 | # Maven
10 | /build.xml
11 | /target
12 |
13 | # vim
14 | .*.sw[a-p]
15 |
16 | # Build
17 | /build
18 | /bin
19 | /dist
20 | /manifest.mf
21 |
22 | # Mac OS X
23 | /.DS_Store
24 |
25 | # Intellij
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
31 | # Temp
32 | *~
33 |
--------------------------------------------------------------------------------
/packet-common/src/main/java/lilypad/packet/common/Packet.java:
--------------------------------------------------------------------------------
1 | package lilypad.packet.common;
2 |
3 | public abstract class Packet {
4 |
5 | private int opcode;
6 |
7 | public Packet(int opcode) {
8 | this.opcode = opcode;
9 | }
10 |
11 | public int getOpcode() {
12 | return this.opcode;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/packet-common/src/main/java/lilypad/packet/common/PacketCodec.java:
--------------------------------------------------------------------------------
1 | package lilypad.packet.common;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | public abstract class PacketCodec {
6 |
7 | private int opcode;
8 |
9 | public PacketCodec(int opcode) {
10 | this.opcode = opcode;
11 | }
12 |
13 | public abstract T decode(ByteBuf buffer) throws Exception;
14 |
15 | public abstract void encode(T packet, ByteBuf buffer);
16 |
17 | @SuppressWarnings("unchecked")
18 | public final void encodePacket(Packet packet, ByteBuf buffer) {
19 | this.encode((T) packet, buffer);
20 | }
21 |
22 | public int getOpcode() {
23 | return this.opcode;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/packet-common/src/main/java/lilypad/packet/common/PacketCodecProvider.java:
--------------------------------------------------------------------------------
1 | package lilypad.packet.common;
2 |
3 | public interface PacketCodecProvider {
4 |
5 | public PacketCodec> getByOpcode(int opcode);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/packet-common/src/main/java/lilypad/packet/common/PacketCodecRegistry.java:
--------------------------------------------------------------------------------
1 | package lilypad.packet.common;
2 |
3 | public class PacketCodecRegistry implements PacketCodecProvider {
4 |
5 | private PacketCodec>[] packetCodecs = new PacketCodec>[256];
6 |
7 | public void register(PacketCodec> packetCodec) {
8 | this.packetCodecs[packetCodec.getOpcode()] = packetCodec;
9 | }
10 |
11 | public PacketCodec> getByOpcode(int opcode) {
12 | return this.packetCodecs[opcode];
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/packet-common/src/main/java/lilypad/packet/common/PacketDecoder.java:
--------------------------------------------------------------------------------
1 | package lilypad.packet.common;
2 |
3 | import java.util.List;
4 |
5 | import lilypad.packet.common.util.BufferUtils;
6 | import io.netty.buffer.ByteBuf;
7 | import io.netty.channel.ChannelHandlerContext;
8 | import io.netty.handler.codec.ByteToMessageDecoder;
9 |
10 | public class PacketDecoder extends ByteToMessageDecoder {
11 |
12 | private PacketCodecProvider packetCodecProvider;
13 |
14 | public PacketDecoder(PacketCodecProvider packetCodecProvider) {
15 | this.packetCodecProvider = packetCodecProvider;
16 | }
17 |
18 | @Override
19 | protected void decode(ChannelHandlerContext context, ByteBuf buffer, List