-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cbd63b
commit 015a490
Showing
6 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/stmarygate/coral/network/codes/LoginResultCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.stmarygate.coral.network.codes; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum LoginResultCode { | ||
SUCCESS(1), | ||
FAILURE_NO_ACCOUNT(2), | ||
FAILURE_INCORRECT_PASSWORD(3); | ||
|
||
private final int code; | ||
|
||
LoginResultCode(int code) { | ||
this.code = code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/stmarygate/coral/network/packets/server/PacketLoginResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.stmarygate.coral.network.packets.server; | ||
|
||
import com.stmarygate.coral.network.packets.Packet; | ||
import com.stmarygate.coral.network.packets.PacketBuffer; | ||
import com.stmarygate.coral.network.packets.PacketHandler; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PacketLoginResult extends Packet { | ||
private boolean accepted; | ||
private int code; | ||
private String token; | ||
|
||
/** | ||
* Constructs a new {@code PacketVersionResult} with specified login informations. | ||
* | ||
* @param accepted Whether the login is accepted. | ||
* @param token The JWT token for the user if the login is accepted. | ||
*/ | ||
public PacketLoginResult(boolean accepted, int code, String token) { | ||
this.accepted = accepted; | ||
this.code = code; | ||
this.token = token; | ||
} | ||
|
||
/** Constructs a default {@code PacketLoginResult} with all version information set to zero. */ | ||
public PacketLoginResult() { | ||
this(false, 2, ""); | ||
} | ||
|
||
/** | ||
* Decodes the packet data from the provided {@link PacketBuffer}. | ||
* | ||
* @param packet The {@link PacketBuffer} containing the packet data. | ||
*/ | ||
@Override | ||
public void decode(PacketBuffer packet) throws Exception { | ||
this.accepted = packet.readUnsignedByte() == 1; | ||
this.code = packet.readUnsignedByte(); | ||
this.token = this.accepted ? packet.readString() : ""; | ||
} | ||
|
||
/** | ||
* Encodes the packet data into the provided {@link PacketBuffer}. | ||
* | ||
* @param packet The {@link PacketBuffer} to which the packet data will be written. | ||
*/ | ||
@Override | ||
public void encode(PacketBuffer packet) throws Exception { | ||
packet.writeByte(accepted ? 1 : 0); | ||
packet.writeByte(code); | ||
if (accepted) packet.writeString(token); | ||
packet.finish(); | ||
} | ||
|
||
/** | ||
* Handles the packet using the specified {@link PacketHandler}. | ||
* | ||
* @param handler The {@link PacketHandler} responsible for handling the packet. | ||
*/ | ||
@Override | ||
public void handle(PacketHandler handler) throws Exception { | ||
handler.handlePacket(this); | ||
} | ||
|
||
/** | ||
* Returns a string representation of the {@code PacketLoginResult}. | ||
* | ||
* @return A string representation containing version information. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "{ accepted: " + accepted + ", code: " + code + ", token: " + token + " }"; | ||
} | ||
} |