Class ClajRelay
java.lang.Object
arc.net.Server
com.xpdustry.claj.server.ClajRelay
- All Implemented Interfaces:
arc.ApplicationListener, arc.net.EndPoint, com.xpdustry.claj.common.net.NetListenerFilter, Runnable
public class ClajRelay
extends arc.net.Server
implements arc.ApplicationListener, com.xpdustry.claj.common.net.NetListenerFilter
CLaJ server main class that doing all the stuff.
-
Nested Class Summary
Nested classes/interfaces inherited from class arc.net.Server
arc.net.Server.ServerConnectFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanAs the server is very talkative, here is a field to shut up info and warn logs for a time.protected intTotal number of clients in rooms.protected booleanfinal arc.struct.IntMap<ClajConnection> List of valid connections.final NetworkSpeedRead/Write speed.final NetworkSpeedRead/Write speed.final intPort to bind this server.final com.xpdustry.claj.common.net.ServerReceiverServer packet receiver.final arc.struct.LongMap<ClajRoom> List of created rooms.final ClajRoutinesServer routines that manages cache and cleaning things.protected booleanfinal arc.struct.ObjectMap<com.xpdustry.claj.common.status.ClajType, arc.struct.LongMap<ClajRoom>> Rooms sorted by type.Fields inherited from class arc.net.Server
discoveryHandler, discoveryReceiver, multicastGroupFields inherited from interface com.xpdustry.claj.common.net.NetListenerFilter
defaultFilter, noIdleFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptJoinRequest(ClajConnection connection, ClajRoom room) booleanaddClient(ClajRoom room, ClajConnection con) booleanallowConnected(arc.net.Connection connection) Will also prepare the connection if valid.booleanallowDisconnected(arc.net.Connection connection, arc.net.DcReason reason) Weird name =/.booleanallowIdle(arc.net.Connection connection) We don't need that for moment.booleanallowReceived(arc.net.Connection connection, Object object) booleanSimple packet spam protection.protected booleancheckRoomHost(ClajConnection con, com.xpdustry.claj.common.status.MessageType errType, String errMsg) protected booleancheckRoomHost(ClajConnection con, com.xpdustry.claj.common.status.MessageType errType, String errMsg, Object extra) protected voidvoidDisconnect all clients of the room.intvoidWill not notify closure to room host.voidprotected voidcloseRoom(ClajRoom room, com.xpdustry.claj.common.status.CloseReason reason, boolean removeFromTypes) intcloseRoomList(com.xpdustry.claj.common.status.ClajType type) intcloseRoomList(com.xpdustry.claj.common.status.ClajType type, com.xpdustry.claj.common.status.CloseReason reason) voidvoidcloseRooms(com.xpdustry.claj.common.status.CloseReason reason) createRoom(ClajConnection host, com.xpdustry.claj.common.status.ClajType type) Creates a room with it's associated caches.voiddenyAction(ClajConnection con, ClajRoom room, com.xpdustry.claj.common.status.MessageType type) voiddispose()At this point it's too late to notify closure.intgetRoom(long roomId) Try to find a room using the base64 encoded id.voidhost()voidhost(int port) protected voidvoidinit()booleanisClosed()booleanisHosted()newRoom(ClajConnection host, com.xpdustry.claj.common.status.ClajType type) longvoidnotifyStop(Runnable notified) Will notify stopping and wait a little before running callback.booleanonConClose(ClajConnection connection, int conId, arc.net.DcReason reason) Will not notify the host about closing.voidonConnect(ClajConnection connection) voidonConPacket(ClajConnection connection, com.xpdustry.claj.common.packets.RawPacket packet) voidonDisconnect(ClajConnection connection, arc.net.DcReason reason) booleanonHostPacket(ClajConnection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket packet) voidonIdle(ClajConnection connection) booleanonInfoRequest(ClajConnection connection, long roomId) booleanonListRequest(ClajConnection connection, com.xpdustry.claj.common.status.ClajType type) booleanonRoomClose(ClajConnection connection) booleanonRoomConfig(ClajConnection connection, boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) com.xpdustry.claj.common.status.CloseReasononRoomCreate(ClajConnection connection, int version, com.xpdustry.claj.common.status.ClajType type) com.xpdustry.claj.common.status.RejectReasononRoomJoin(ClajConnection connection, boolean isRequest, long roomId, com.xpdustry.claj.common.status.ClajType type, boolean withPassword, short password) booleanonRoomState(ClajConnection connection, ByteBuffer state) booleanrefreshRoomList(com.xpdustry.claj.common.status.ClajType type) booleanrefreshRoomList(com.xpdustry.claj.common.status.ClajType type, boolean force) voidvoidrejectObsoleteClient(ClajConnection connection) voidrejectRateLimitedClient(ClajConnection connection) voidvoidrejectRoomCreation(ClajConnection connection, com.xpdustry.claj.common.status.CloseReason reason) voidrejectRoomInfo(ClajConnection connection, ClajRoom room, boolean rateLimited) protected voidrejectRoomJoin(ClajConnection connection, ClajRoom room, long roomId, com.xpdustry.claj.common.status.RejectReason reason) voidrejectRoomJoin(ClajConnection connection, ClajRoom room, com.xpdustry.claj.common.status.RejectReason reason) voidrejectRoomList(ClajConnection connection, com.xpdustry.claj.common.status.ClajType type, boolean rateLimited) booleanbooleanremoveClient(ClajConnection con, arc.net.DcReason reason) booleanremoveClient(ClajConnection con, arc.net.DcReason reason, boolean quiet) intrequestRoomList(ClajConnection con, com.xpdustry.claj.common.status.ClajType type) Requests a room list (if not already) and adds the connection to the pending requests cache.booleanrequestRoomState(ClajConnection con, ClajRoom room) Requests a room state (if not already) and adds the connection to the pending requests cache.voidrun()booleansendRoomList(com.xpdustry.claj.common.status.ClajType type) booleansendRoomList(com.xpdustry.claj.common.status.ClajType type, boolean force) booleansendRoomState(ClajRoom room) Send room state to connections that awaiting it.voidsetRoomAfk(ClajRoom room, boolean isAfk) voidsetRoomConfiguration(ClajRoom room, boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) voidsetRoomState(ClajRoom room, ByteBuffer state) voidstop()voidstop(boolean notify) voidvoidstatic ClajConnectiontoClajCon(arc.net.Connection con) voidupdate(int timeout) protected voidupdateTime(int timeout) protected voidMethods inherited from class arc.net.Server
addListener, bind, bind, bind, close, getConnectFilter, getConnections, getUpdateThread, newConnection, removeListener, sendToAllExceptTCP, sendToAllExceptUDP, sendToAllTCP, sendToAllUDP, sendToTCP, sendToUDP, setConnectFilter, setDiscoveryHandler, setMulticast, startMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface arc.ApplicationListener
exit, fileDropped, pause, resize, resume, update
-
Field Details
-
closed
protected boolean closed -
running
protected boolean running -
port
public final int portPort to bind this server. -
networkSpeed
Read/Write speed. -
packetCounter
Read/Write speed. -
receiver
public final com.xpdustry.claj.common.net.ServerReceiver receiverServer packet receiver. -
routines
Server routines that manages cache and cleaning things. -
connections
List of valid connections. DO NOT EDIT MANUALLY! -
rooms
List of created rooms. DO NOT EDIT MANUALLY! -
types
public final arc.struct.ObjectMap<com.xpdustry.claj.common.status.ClajType, arc.struct.LongMap<ClajRoom>> typesRooms sorted by type. DO NOT EDIT MANUALLY! -
beQuiet
public volatile boolean beQuietAs the server is very talkative, here is a field to shut up info and warn logs for a time. -
clientsInRooms
protected int clientsInRoomsTotal number of clients in rooms.
-
-
Constructor Details
-
ClajRelay
public ClajRelay(int port) -
ClajRelay
public ClajRelay(int port, boolean withCounters)
-
-
Method Details
-
info
-
warn
-
allowConnected
public boolean allowConnected(arc.net.Connection connection) Will also prepare the connection if valid. Called from network thread.- Specified by:
allowConnectedin interfacecom.xpdustry.claj.common.net.NetListenerFilter
-
allowDisconnected
public boolean allowDisconnected(arc.net.Connection connection, arc.net.DcReason reason) Weird name =/. Called from network thread.- Specified by:
allowDisconnectedin interfacecom.xpdustry.claj.common.net.NetListenerFilter
-
allowReceived
- Specified by:
allowReceivedin interfacecom.xpdustry.claj.common.net.NetListenerFilter
-
allowIdle
public boolean allowIdle(arc.net.Connection connection) We don't need that for moment. Will be useful for back-pressure. called from network thread.- Specified by:
allowIdlein interfacecom.xpdustry.claj.common.net.NetListenerFilter
-
onConnect
-
onDisconnect
-
onIdle
-
onRoomCreate
public com.xpdustry.claj.common.status.CloseReason onRoomCreate(ClajConnection connection, int version, com.xpdustry.claj.common.status.ClajType type) - Returns:
- not
nullif action was denied.
-
onRoomClose
- Returns:
- whether the action was allowed or not.
-
onRoomJoin
public com.xpdustry.claj.common.status.RejectReason onRoomJoin(ClajConnection connection, boolean isRequest, long roomId, com.xpdustry.claj.common.status.ClajType type, boolean withPassword, short password) - Returns:
- not
nullif the action was denied.
-
onRoomConfig
public boolean onRoomConfig(ClajConnection connection, boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) - Returns:
- whether the action was allowed or not.
-
onRoomState
- Returns:
- whether the action was allowed or not.
-
onInfoRequest
- Returns:
- whether the action was allowed or not.
-
onListRequest
public boolean onListRequest(ClajConnection connection, com.xpdustry.claj.common.status.ClajType type) - Returns:
- whether the action was allowed or not.
-
onConClose
Will not notify the host about closing.- Returns:
- whether the action was allowed or not.
-
onHostPacket
public boolean onHostPacket(ClajConnection connection, com.xpdustry.claj.common.packets.ConnectionPayloadPacket packet) -
onConPacket
public void onConPacket(ClajConnection connection, com.xpdustry.claj.common.packets.RawPacket packet) -
updateTime
protected void updateTime(int timeout) -
getFramesPerSecond
public int getFramesPerSecond() -
update
- Specified by:
updatein interfacearc.net.EndPoint- Overrides:
updatein classarc.net.Server- Throws:
IOException
-
init
public void init()- Specified by:
initin interfacearc.ApplicationListener
-
dispose
public void dispose()At this point it's too late to notify closure.- Specified by:
disposein interfacearc.ApplicationListener- Overrides:
disposein classarc.net.Server
-
host
- Throws:
RuntimeException
-
host
- Throws:
RuntimeException
-
run
-
stop
public void stop()- Specified by:
stopin interfacearc.net.EndPoint- Overrides:
stopin classarc.net.Server
-
stop
public void stop(boolean notify) -
stop
-
stop
-
notifyStop
Will notify stopping and wait a little before running callback. (if configured for) -
clearAndStop
protected void clearAndStop() -
isClosed
public boolean isClosed() -
isHosted
public boolean isHosted() -
closeRooms
public void closeRooms() -
closeRooms
public void closeRooms(com.xpdustry.claj.common.status.CloseReason reason) -
setRoomAfk
-
createRoom
Creates a room with it's associated caches. If the room failed to create, it will immediately closed. -
closeRoom
Will not notify closure to room host. -
closeRoom
-
closeRoom
protected void closeRoom(ClajRoom room, com.xpdustry.claj.common.status.CloseReason reason, boolean removeFromTypes) -
closeRoomList
public int closeRoomList(com.xpdustry.claj.common.status.ClajType type) -
closeRoomList
public int closeRoomList(com.xpdustry.claj.common.status.ClajType type, com.xpdustry.claj.common.status.CloseReason reason) - Returns:
- the number of room that has been closed.
-1if no room have the type.
-
addClient
- Returns:
- whether the client has been added to the room or not.
-
removeClient
-
removeClient
-
removeClient
- Returns:
- whether client was the host. If so the room will be closed.
-
clearRoom
Disconnect all clients of the room. -
setRoomConfiguration
public void setRoomConfiguration(ClajRoom room, boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients) -
setRoomState
-
requestRoomState
Requests a room state (if not already) and adds the connection to the pending requests cache. -
sendRoomState
Send room state to connections that awaiting it.- Returns:
- whether any connections are waiting for the state.
-
requestRoomList
Requests a room list (if not already) and adds the connection to the pending requests cache.- Returns:
- the state value. (0: refreshing, 1: up to date, 2: updating, 3: pending request limit, 4: type not found)
-
sendRoomList
public boolean sendRoomList(com.xpdustry.claj.common.status.ClajType type) -
sendRoomList
public boolean sendRoomList(com.xpdustry.claj.common.status.ClajType type, boolean force) -
refreshRoomList
public boolean refreshRoomList(com.xpdustry.claj.common.status.ClajType type) -
refreshRoomList
public boolean refreshRoomList(com.xpdustry.claj.common.status.ClajType type, boolean force) -
refreshRoomLists
public void refreshRoomLists() -
denyAction
public void denyAction(ClajConnection con, ClajRoom room, com.xpdustry.claj.common.status.MessageType type) -
checkRoomHost
protected boolean checkRoomHost(ClajConnection con, com.xpdustry.claj.common.status.MessageType errType, String errMsg) -
checkRoomHost
protected boolean checkRoomHost(ClajConnection con, com.xpdustry.claj.common.status.MessageType errType, String errMsg, Object extra) -
checkRateLimit
Simple packet spam protection.- Returns:
- whether the packet is allowed or not. If not, the client will be kicked and the room warned.
-
rejectObsoleteClient
-
rejectRateLimitedClient
-
rejectRateLimitedHost
-
rejectRoomCreation
public void rejectRoomCreation(ClajConnection connection, com.xpdustry.claj.common.status.CloseReason reason) -
rejectRoomJoin
public void rejectRoomJoin(ClajConnection connection, ClajRoom room, com.xpdustry.claj.common.status.RejectReason reason) -
rejectRoomJoin
protected void rejectRoomJoin(ClajConnection connection, ClajRoom room, long roomId, com.xpdustry.claj.common.status.RejectReason reason) -
acceptJoinRequest
-
rejectRoomInfo
-
rejectRoomList
public void rejectRoomList(ClajConnection connection, com.xpdustry.claj.common.status.ClajType type, boolean rateLimited) -
clientsInRooms
public int clientsInRooms() -
newRoomId
public long newRoomId() -
newRoom
-
getRoom
-
getRoom
-
toClajCon
-