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.
  • Field Details

    • closed

      protected boolean closed
    • running

      protected boolean running
    • port

      public final int port
      Port to bind this server.
    • networkSpeed

      public final NetworkSpeed networkSpeed
      Read/Write speed.
    • packetCounter

      public final NetworkSpeed packetCounter
      Read/Write speed.
    • receiver

      public final com.xpdustry.claj.common.net.ServerReceiver receiver
      Server packet receiver.
    • routines

      public final ClajRoutines routines
      Server routines that manages cache and cleaning things.
    • connections

      public final arc.struct.IntMap<ClajConnection> connections
      List of valid connections. DO NOT EDIT MANUALLY!
    • rooms

      public final arc.struct.LongMap<ClajRoom> 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>> types
      Rooms sorted by type. DO NOT EDIT MANUALLY!
    • beQuiet

      public volatile boolean beQuiet
      As the server is very talkative, here is a field to shut up info and warn logs for a time.
    • clientsInRooms

      protected int clientsInRooms
      Total number of clients in rooms.
  • Constructor Details

    • ClajRelay

      public ClajRelay(int port)
    • ClajRelay

      public ClajRelay(int port, boolean withCounters)
  • Method Details

    • info

      protected void info(String text, Object... args)
    • warn

      protected void warn(String text, Object... args)
    • allowConnected

      public boolean allowConnected(arc.net.Connection connection)
      Will also prepare the connection if valid. Called from network thread.
      Specified by:
      allowConnected in interface com.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:
      allowDisconnected in interface com.xpdustry.claj.common.net.NetListenerFilter
    • allowReceived

      public boolean allowReceived(arc.net.Connection connection, Object object)
      Specified by:
      allowReceived in interface com.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:
      allowIdle in interface com.xpdustry.claj.common.net.NetListenerFilter
    • onConnect

      public void onConnect(ClajConnection connection)
    • onDisconnect

      public void onDisconnect(ClajConnection connection, arc.net.DcReason reason)
    • onIdle

      public void onIdle(ClajConnection connection)
    • onRoomCreate

      public com.xpdustry.claj.common.status.CloseReason onRoomCreate(ClajConnection connection, int version, com.xpdustry.claj.common.status.ClajType type)
      Returns:
      not null if action was denied.
    • onRoomClose

      public boolean onRoomClose(ClajConnection connection)
      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 null if 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

      public boolean onRoomState(ClajConnection connection, ByteBuffer state)
      Returns:
      whether the action was allowed or not.
    • onInfoRequest

      public boolean onInfoRequest(ClajConnection connection, long roomId)
      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

      public boolean onConClose(ClajConnection connection, int conId, arc.net.DcReason reason)
      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

      public void update(int timeout) throws IOException
      Specified by:
      update in interface arc.net.EndPoint
      Overrides:
      update in class arc.net.Server
      Throws:
      IOException
    • init

      public void init()
      Specified by:
      init in interface arc.ApplicationListener
    • dispose

      public void dispose()
      At this point it's too late to notify closure.
      Specified by:
      dispose in interface arc.ApplicationListener
      Overrides:
      dispose in class arc.net.Server
    • host

      public void host() throws RuntimeException
      Throws:
      RuntimeException
    • host

      public void host(int port) throws RuntimeException
      Throws:
      RuntimeException
    • run

      public void run()
      Specified by:
      run in interface arc.net.EndPoint
      Specified by:
      run in interface Runnable
      Overrides:
      run in class arc.net.Server
    • stop

      public void stop()
      Specified by:
      stop in interface arc.net.EndPoint
      Overrides:
      stop in class arc.net.Server
    • stop

      public void stop(boolean notify)
    • stop

      public void stop(Runnable stopped)
    • stop

      public void stop(boolean notify, Runnable stopped)
    • notifyStop

      public void notifyStop(Runnable notified)
      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

      public void setRoomAfk(ClajRoom room, boolean isAfk)
    • createRoom

      public ClajRoom createRoom(ClajConnection host, com.xpdustry.claj.common.status.ClajType type)
      Creates a room with it's associated caches. If the room failed to create, it will immediately closed.
    • closeRoom

      public void closeRoom(ClajRoom room)
      Will not notify closure to room host.
    • closeRoom

      public void closeRoom(ClajRoom room, com.xpdustry.claj.common.status.CloseReason reason)
    • 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. -1 if no room have the type.
    • addClient

      public boolean addClient(ClajRoom room, ClajConnection con)
      Returns:
      whether the client has been added to the room or not.
    • removeClient

      public boolean removeClient(ClajConnection con)
    • removeClient

      public boolean removeClient(ClajConnection con, arc.net.DcReason reason)
    • removeClient

      public boolean removeClient(ClajConnection con, arc.net.DcReason reason, boolean quiet)
      Returns:
      whether client was the host. If so the room will be closed.
    • clearRoom

      public void clearRoom(ClajRoom room, arc.net.DcReason reason, boolean quiet)
      Disconnect all clients of the room.
    • setRoomConfiguration

      public void setRoomConfiguration(ClajRoom room, boolean isPublic, boolean isProtected, short password, boolean requestState, int maxClients)
    • setRoomState

      public void setRoomState(ClajRoom room, ByteBuffer state)
    • requestRoomState

      public boolean requestRoomState(ClajConnection con, ClajRoom room)
      Requests a room state (if not already) and adds the connection to the pending requests cache.
    • sendRoomState

      public boolean sendRoomState(ClajRoom room)
      Send room state to connections that awaiting it.
      Returns:
      whether any connections are waiting for the state.
    • requestRoomList

      public int requestRoomList(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.
      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

      public boolean checkRateLimit(ClajConnection con)
      Simple packet spam protection.
      Returns:
      whether the packet is allowed or not. If not, the client will be kicked and the room warned.
    • rejectObsoleteClient

      public void rejectObsoleteClient(ClajConnection connection)
    • rejectRateLimitedClient

      public void rejectRateLimitedClient(ClajConnection connection)
    • rejectRateLimitedHost

      public void rejectRateLimitedHost(ClajRoom room)
    • 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

      public void acceptJoinRequest(ClajConnection connection, ClajRoom room)
    • rejectRoomInfo

      public void rejectRoomInfo(ClajConnection connection, ClajRoom room, boolean rateLimited)
    • rejectRoomList

      public void rejectRoomList(ClajConnection connection, com.xpdustry.claj.common.status.ClajType type, boolean rateLimited)
    • clientsInRooms

      public int clientsInRooms()
    • newRoomId

      public long newRoomId()
    • newRoom

      public ClajRoom newRoom(ClajConnection host, com.xpdustry.claj.common.status.ClajType type)
    • getRoom

      public ClajRoom getRoom(long roomId)
    • getRoom

      public ClajRoom getRoom(String encodedRoomId)
      Try to find a room using the base64 encoded id.
    • toClajCon

      public static ClajConnection toClajCon(arc.net.Connection con)