parent
425cc7f91f
commit
1385500e68
@ -0,0 +1,102 @@
|
|||||||
|
package network.Messages.Enums;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enum encapsulates the different ways in which a server may respond to a client {@link network.Messages.RequestToJoin} message.
|
||||||
|
*/
|
||||||
|
public enum JoinAcceptanceEnum {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client is allowed to join.
|
||||||
|
*/
|
||||||
|
JOIN_SUCCESSFUL(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The race is full - no more participants allowed.
|
||||||
|
*/
|
||||||
|
RACE_PARTICIPANTS_FULL(2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The race cannot allow any more ghost participants to join.
|
||||||
|
*/
|
||||||
|
GHOST_PARTICIPANTS_FULL(3),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The server is completely full, cannot participate or spectate.
|
||||||
|
*/
|
||||||
|
SERVER_FULL(4),
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to indicate that a given byte value is invalid.
|
||||||
|
*/
|
||||||
|
NOT_AN_ACCEPTANCE_TYPE(-1);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primitive value of the enum.
|
||||||
|
*/
|
||||||
|
private byte value;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor. Creates a JoinAcceptanceEnum from a given primitive integer value, cast to a byte.
|
||||||
|
* @param value Integer, which is cast to byte, to construct from.
|
||||||
|
*/
|
||||||
|
private JoinAcceptanceEnum(int value) {
|
||||||
|
this.value = (byte) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the primitive value of the enum.
|
||||||
|
* @return Primitive value of the enum.
|
||||||
|
*/
|
||||||
|
public byte getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a mapping between Byte values and JoinAcceptanceEnum values.
|
||||||
|
*/
|
||||||
|
private static final Map<Byte, JoinAcceptanceEnum> byteToAcceptanceMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Static initialization block. Initializes the byteToAcceptanceMap.
|
||||||
|
*/
|
||||||
|
static {
|
||||||
|
for (JoinAcceptanceEnum type : JoinAcceptanceEnum.values()) {
|
||||||
|
JoinAcceptanceEnum.byteToAcceptanceMap.put(type.value, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the enumeration value which corresponds to a given byte value.
|
||||||
|
* @param joinAcceptanceEnum Byte value to convert to a JoinAcceptanceEnum value.
|
||||||
|
* @return The RequestToJoinEnum value which corresponds to the given byte value.
|
||||||
|
*/
|
||||||
|
public static JoinAcceptanceEnum fromByte(byte joinAcceptanceEnum) {
|
||||||
|
//Gets the corresponding MessageType from the map.
|
||||||
|
JoinAcceptanceEnum type = JoinAcceptanceEnum.byteToAcceptanceMap.get(joinAcceptanceEnum);
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
//If the byte value wasn't found, return the NOT_AN_ACCEPTANCE_TYPE JoinAcceptanceEnum.
|
||||||
|
return JoinAcceptanceEnum.NOT_AN_ACCEPTANCE_TYPE;
|
||||||
|
} else {
|
||||||
|
//Otherwise, return the JoinAcceptanceEnum.
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
package network.Messages.Enums;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enum encapsulates the different ways in which a client may wish to connect to a server.
|
||||||
|
*/
|
||||||
|
public enum RequestToJoinEnum {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client wants to spectate.
|
||||||
|
*/
|
||||||
|
SPECTATOR(0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client wants to participate.
|
||||||
|
*/
|
||||||
|
PARTICIPANT(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client wants to particpate as a ghost.
|
||||||
|
*/
|
||||||
|
GHOST(5),
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to indicate that a given byte value is invalid.
|
||||||
|
*/
|
||||||
|
NOT_A_REQUEST_TYPE(-1);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primitive value of the enum.
|
||||||
|
*/
|
||||||
|
private byte value;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor. Creates a RequestToJoinEnum from a given primitive integer value, cast to a byte.
|
||||||
|
* @param value Integer, which is cast to byte, to construct from.
|
||||||
|
*/
|
||||||
|
private RequestToJoinEnum(int value) {
|
||||||
|
this.value = (byte) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the primitive value of the enum.
|
||||||
|
* @return Primitive value of the enum.
|
||||||
|
*/
|
||||||
|
public byte getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a mapping between Byte values and RequestToJoinEnum values.
|
||||||
|
*/
|
||||||
|
private static final Map<Byte, RequestToJoinEnum> byteToRequestMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Static initialization block. Initializes the byteToRequestMap.
|
||||||
|
*/
|
||||||
|
static {
|
||||||
|
for (RequestToJoinEnum type : RequestToJoinEnum.values()) {
|
||||||
|
RequestToJoinEnum.byteToRequestMap.put(type.value, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the enumeration value which corresponds to a given byte value.
|
||||||
|
* @param requestToJoinEnum Byte value to convert to a RequestToJoinEnum value.
|
||||||
|
* @return The RequestToJoinEnum value which corresponds to the given byte value.
|
||||||
|
*/
|
||||||
|
public static RequestToJoinEnum fromByte(byte requestToJoinEnum) {
|
||||||
|
//Gets the corresponding MessageType from the map.
|
||||||
|
RequestToJoinEnum type = RequestToJoinEnum.byteToRequestMap.get(requestToJoinEnum);
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
//If the byte value wasn't found, return the NOT_A_REQUEST_TYPE RequestToJoinEnum.
|
||||||
|
return RequestToJoinEnum.NOT_A_REQUEST_TYPE;
|
||||||
|
} else {
|
||||||
|
//Otherwise, return the RequestToJoinEnum.
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
package network.Messages;
|
||||||
|
|
||||||
|
public class JoinAcceptance {
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package network.Messages;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the message a client sends to a server to request to join/view a race.
|
||||||
|
*/
|
||||||
|
public class RequestToJoin {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue