Class ClajRoom
java.lang.Object
com.xpdustry.claj.server.ClajRoom
- All Implemented Interfaces:
arc.net.NetListener
-
Nested Class Summary
Nested classes/interfaces inherited from interface arc.net.NetListener
arc.net.NetListener.LagListener, arc.net.NetListener.QueuedListener, arc.net.NetListener.ThreadedListener -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanWhether the host want, or not, the server to request his state when needed.final arc.struct.Seq<ClajConnection> final arc.struct.IntMap<ClajConnection> protected booleanlongClosing date of the room.static final intId meaning that that the connection is invalid, and used to broadcast packets to all clients.protected booleanlongCreation date of the room.final ClajConnectionThe host connection of this room.final longThe room id.booleanWhether the room needs a password or not to join it.booleanWhether the room will be added is public list or not.longTime of the last received room state.longTime of the last requested room state.intMaximum number of CLaJ client allowed in this room.shortThe room passwordState of the room as raw data.booleanWhether a state has been requested to the room.final StringThe room id encoded in an url-safe base64 string.De-serialized room state, only present if the right decoder is present.final arc.util.RatekeeperRoom state rate-limit.final NetworkSpeedFor debugging, to know how many packets were transferred from a client to a host, and vice versa.final com.xpdustry.claj.common.status.ClajTypeRoom implementation type.static final longId saying that no room is created. -
Constructor Summary
ConstructorsConstructorDescriptionClajRoom(long id, ClajConnection host, com.xpdustry.claj.common.status.ClajType type) -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowsType(com.xpdustry.claj.common.status.ClajType type) intclients()voidclose()voidclose(com.xpdustry.claj.common.status.CloseReason reason) Closes the room and disconnects the host and all clients.protected voidclose(com.xpdustry.claj.common.status.CloseReason reason, boolean notify) voidSame asclose(), but doesn't notify closure to host.voidconnected(arc.net.Connection connection) Alerts the host that a new client is comingvoidconnected(ClajConnection connection) Alerts the host of the client arrival.booleancontains(arc.net.Connection con) booleancontains(ClajConnection con) booleancontainsClient(arc.net.Connection con) booleanvoidcreate()Link this room to the host and notify it's id.voiddisconnectAllClients(arc.net.DcReason reason, boolean notify) Close all connections of the room.voiddisconnected(arc.net.Connection connection, arc.net.DcReason reason) Alerts the host that a client disconnected.voiddisconnected(ClajConnection connection, arc.net.DcReason reason) Alerts the host that a client disconnected.voiddisconnectedQuietly(arc.net.Connection connection, arc.net.DcReason reason) Doesn't notify the room host about a disconnected client.voiddisconnectedQuietly(ClajConnection connection, arc.net.DcReason reason) Doesn't notify the room host about a disconnected client, but this does close it.booleanOnly usesidas identity.inthashCode()Only hashesid.voididle(arc.net.Connection connection) Notifies the host of an idle connection.voididle(ClajConnection connection) Notifies the host of an idle connection.booleanisClosed()booleanbooleanisEmpty()booleanisHost(arc.net.Connection con) booleanisHost(ClajConnection con) booleanbooleanisStateOutdated(long timeNs) booleanbooleanisStateRequestTimedOut(long timeNs) voidmessage(com.xpdustry.claj.common.status.MessageType message) Sends a message the host and clients.voidSends a message to the host and clients.booleanneedStateRequest(long timeNs) voidSends a popup to the room host.voidreceived(arc.net.Connection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket wrap) Unwraps the packet and sends it to the corresponding connection.voidreceived(arc.net.Connection connection, com.xpdustry.claj.common.packets.RawPacket raw) We never send claj packets to anyone other than the room host, framework packets are ignored and mindustry packets are saved as raw buffer.voidWraps and re-sends the packet to the host, if it come from a connection.voidreceived(ClajConnection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket wrap) voidreceived(ClajConnection connection, com.xpdustry.claj.common.packets.RawPacket raw) voidreceived(ClajConnection connection, Object object) protected voidremoveRoom(ClajConnection con) booleanOnly requests state if not already done.booleanrequestState(long timeNs) Only requests state if not already done.static voidsendConnectionAccepted(ClajConnection dest, ClajRoom room) static voidsendConnectionJoined(ClajConnection dest, ClajConnection joined) static voidsendConnectionRejected(ClajConnection dest, long roomId, com.xpdustry.claj.common.status.RejectReason reason) static voidsendDisconnect(ClajConnection dest, int conId, arc.net.DcReason reason) static voidsendIdle(ClajConnection dest, int conId) static voidsendMessage(ClajConnection dest, com.xpdustry.claj.common.status.MessageType message) static voidsendMessage(ClajConnection dest, String text) static voidsendPayload(ClajConnection dest, int conId, com.xpdustry.claj.common.packets.RawPacket raw, boolean isTcp) Note that raw packet will be freed after serialization.static voidsendPopup(ClajConnection dest, String text) static voidsendRoomClosed(ClajConnection dest, com.xpdustry.claj.common.status.CloseReason reason) static voidsendRoomCreated(ClajConnection dest, long roomId) static voidvoidsendRoomState(ClajConnection connection) State is only send if roomisPublic.static voidsendRoomState(ClajConnection dest, ClajRoom room) static voidvoidsetConfiguration(boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) protected voidsetRoom(ClajConnection con) voidsetState(ByteBuffer rawState) booleantoString()
-
Field Details
-
UNCREATED_ROOM
public static final long UNCREATED_ROOMId saying that no room is created. This should be handled as an invalid id.- See Also:
-
CON_BROADCAST
public static final int CON_BROADCASTId meaning that that the connection is invalid, and used to broadcast packets to all clients.
This is used for disconnect, received and idle events, but not for connected one, as it makes no sense.- See Also:
-
created
protected boolean created -
closed
protected boolean closed -
id
public final long idThe room id. -
sid
-
host
The host connection of this room. -
clientsMap
-
clients
-
transferredPackets
For debugging, to know how many packets were transferred from a client to a host, and vice versa. -
stateRate
public final arc.util.Ratekeeper stateRateRoom state rate-limit. New states will simply be discarded. -
createdAt
public long createdAtCreation date of the room. Sets whencreate()is called. -
closedAt
public long closedAtClosing date of the room. Sets whenclose()is called. -
isPublic
public boolean isPublicWhether the room will be added is public list or not. -
isProtected
public boolean isProtectedWhether the room needs a password or not to join it. -
password
public short passwordThe room password -
canRequestState
public boolean canRequestStateWhether the host want, or not, the server to request his state when needed. -
state
De-serialized room state, only present if the right decoder is present. -
rawState
State of the room as raw data.nullif no state was received. -
lastReceivedState
public long lastReceivedStateTime of the last received room state. (in ns). -
lastRequestedState
public long lastRequestedStateTime of the last requested room state. (in ns). -
requestingState
public boolean requestingStateWhether a state has been requested to the room. -
type
public final com.xpdustry.claj.common.status.ClajType typeRoom implementation type. Can benull. -
maxClients
public int maxClientsMaximum number of CLaJ client allowed in this room.
0means no limit and the value must not be higher that the server limit.
-
-
Constructor Details
-
ClajRoom
-
-
Method Details
-
setRoom
-
removeRoom
-
connected
public void connected(arc.net.Connection connection) Alerts the host that a new client is coming- Specified by:
connectedin interfacearc.net.NetListener
-
connected
Alerts the host of the client arrival. -
disconnected
public void disconnected(arc.net.Connection connection, arc.net.DcReason reason) Alerts the host that a client disconnected. This doesn't close the connection.- Specified by:
disconnectedin interfacearc.net.NetListener
-
disconnected
Alerts the host that a client disconnected. This doesn't close the connection. -
disconnectedQuietly
public void disconnectedQuietly(arc.net.Connection connection, arc.net.DcReason reason) Doesn't notify the room host about a disconnected client. -
disconnectedQuietly
Doesn't notify the room host about a disconnected client, but this does close it. -
disconnectAllClients
public void disconnectAllClients(arc.net.DcReason reason, boolean notify) Close all connections of the room. -
received
Wraps and re-sends the packet to the host, if it come from a connection.
Or un-wraps and re-sends the packet to the specified connection.Only
ConnectionPayloadPacketandRawPacketare allowed.- Specified by:
receivedin interfacearc.net.NetListener
-
received
-
received
public void received(arc.net.Connection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket wrap) Unwraps the packet and sends it to the corresponding connection.
This will notify the host if the connection is not found.Please note that this method is mainly called from network thread.
-
received
public void received(ClajConnection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket wrap) -
received
public void received(arc.net.Connection connection, com.xpdustry.claj.common.packets.RawPacket raw) We never send claj packets to anyone other than the room host, framework packets are ignored and mindustry packets are saved as raw buffer.Please note that this method is mainly called from network thread.
-
received
-
idle
public void idle(arc.net.Connection connection) Notifies the host of an idle connection.- Specified by:
idlein interfacearc.net.NetListener
-
idle
Notifies the host of an idle connection. -
allowsType
public boolean allowsType(com.xpdustry.claj.common.status.ClajType type) - Returns:
trueiftypeisnull, the provided one is the same ornull, ifClajConfig.acceptNoTypeistrue.
-
isEmpty
public boolean isEmpty()- Returns:
- whether this room have clients or not.
-
clients
public int clients()- Returns:
- the number of CLaJ clients in this room.
-
isCreataed
public boolean isCreataed()- Returns:
- whether the room is created or not.
-
isClosed
public boolean isClosed()- Returns:
- whether the room is closed or not.
-
create
public void create()Link this room to the host and notify it's id. Can only be called once. -
close
public void close() -
close
public void close(com.xpdustry.claj.common.status.CloseReason reason) Closes the room and disconnects the host and all clients.
The room object cannot be used anymore after this. -
close
protected void close(com.xpdustry.claj.common.status.CloseReason reason, boolean notify) -
closeQuietly
public void closeQuietly()Same asclose(), but doesn't notify closure to host. -
message
Sends a message to the host and clients. -
message
public void message(com.xpdustry.claj.common.status.MessageType message) Sends a message the host and clients. Will be translated by the room host. -
popup
Sends a popup to the room host. -
setConfiguration
public void setConfiguration(boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) -
requestState
public boolean requestState()Only requests state if not already done.- Returns:
- whether the state has been requested.
-
requestState
public boolean requestState(long timeNs) Only requests state if not already done.- Returns:
- whether the state has been requested.
-
setState
-
isStateRequestTimedOut
public boolean isStateRequestTimedOut() -
isStateRequestTimedOut
public boolean isStateRequestTimedOut(long timeNs) -
isStateOutdated
public boolean isStateOutdated() -
isStateOutdated
public boolean isStateOutdated(long timeNs) -
shouldRequestState
public boolean shouldRequestState() -
needStateRequest
public boolean needStateRequest(long timeNs) -
sendRoomState
State is only send if roomisPublic. -
isHost
public boolean isHost(arc.net.Connection con) - Returns:
- whether specified connection is the room host or not.
-
isHost
- Returns:
- whether specified connection is the room host or not.
-
contains
- Returns:
- whether the connection is the room host or one of his client.
-
contains
public boolean contains(arc.net.Connection con) - Returns:
- whether the connection is the room host or one of his client.
-
containsClient
- Returns:
- whether the connection is in this room.
-
containsClient
public boolean containsClient(arc.net.Connection con) - Returns:
- whether the connection is in this room.
-
hashCode
-
equals
-
toString
-
sendConnectionJoined
-
sendConnectionAccepted
-
sendConnectionRejected
public static void sendConnectionRejected(ClajConnection dest, long roomId, com.xpdustry.claj.common.status.RejectReason reason) -
sendDisconnect
-
sendPayload
public static void sendPayload(ClajConnection dest, int conId, com.xpdustry.claj.common.packets.RawPacket raw, boolean isTcp) Note that raw packet will be freed after serialization. -
sendIdle
-
sendRoomCreated
-
sendRoomClosed
public static void sendRoomClosed(ClajConnection dest, com.xpdustry.claj.common.status.CloseReason reason) -
sendMessage
-
sendMessage
public static void sendMessage(ClajConnection dest, com.xpdustry.claj.common.status.MessageType message) -
sendPopup
-
sendRoomStateRequest
-
sendRoomState
-
sendRoomInfoRejected
-