Class ServerApiImpl

java.lang.Object
com.tenio.common.logger.AbstractLogger
com.tenio.common.logger.SystemLogger
com.tenio.core.api.implement.ServerApiImpl
All Implemented Interfaces:
ServerApi

public final class ServerApiImpl extends com.tenio.common.logger.SystemLogger implements ServerApi
An implementation for Server APIs.
  • Method Details

    • newInstance

      public static ServerApi newInstance(Server server)
      Initialization.
      Parameters:
      server - an instance of Server
      Returns:
      an instance of ServerApi
    • login

      public void login(String playerName)
      Description copied from interface: ServerApi
      Allows creating an instance of a player in the server. The player does not contain session, it should act like a server's bot.
      Specified by:
      login in interface ServerApi
      Parameters:
      playerName - a unique player's name (String value) on the server
      See Also:
    • login

      public void login(String playerName, Session session)
      Description copied from interface: ServerApi
      Allows creating an instance of a player in the server.
      Specified by:
      login in interface ServerApi
      Parameters:
      playerName - a unique player's name (String value) on the server
      session - a Session associated to the player
      See Also:
    • login

      public void login(Player player)
      Description copied from interface: ServerApi
      Allows creating an instance of a player on the server which could be a custom one.
      Specified by:
      login in interface ServerApi
      Parameters:
      player - a Player who must have a unique name on the server
      See Also:
    • logout

      public void logout(Player player, ConnectionDisconnectMode connectionDisconnectMode, PlayerDisconnectMode playerDisconnectMode)
      Description copied from interface: ServerApi
      Removes a player from the management list and from the server as well. This is a silent logout, so please do not perform any responding to the client since it may not work as expected (each command runs in different threads, so it may not get synchronized. In case you want to send a message to the client before closing connect or logout the player, please use this method Response.writeThenClose()
      Specified by:
      logout in interface ServerApi
      Parameters:
      player - the current Player in the management list, on the server
      connectionDisconnectMode - ConnectionDisconnectMode session disconnected reason
      playerDisconnectMode - PlayerDisconnectMode player disconnected reason
      See Also:
    • createRoom

      public Room createRoom(InitialRoomSetting roomSetting, Player roomOwner)
      Description copied from interface: ServerApi
      Creates a new room on the server.
      Specified by:
      createRoom in interface ServerApi
      Parameters:
      roomSetting - all room InitialRoomSetting at the time its created
      roomOwner - a Player owner of this room, owner can also be declared by null value
      Returns:
      a new instance of Room if available, otherwise null
    • addRoom

      public Room addRoom(Room room, InitialRoomSetting roomSetting, Player roomOwner)
      Description copied from interface: ServerApi
      Adds a new room to the server.
      Specified by:
      addRoom in interface ServerApi
      Parameters:
      room - an instance of Room
      roomSetting - all settings created by a InitialRoomSetting builder
      roomOwner - a Player as the room's owner
      Returns:
      the room instance
    • getPlayerByName

      public Optional<Player> getPlayerByName(String playerName)
      Description copied from interface: ServerApi
      Retrieves a player on the server by using its name.
      Specified by:
      getPlayerByName in interface ServerApi
      Parameters:
      playerName - a unique String value for player's name on the server
      Returns:
      a corresponding instance of optional Player
      See Also:
    • getPlayerCount

      public int getPlayerCount()
      Description copied from interface: ServerApi
      Fetches the current number of players activating on the server.
      Specified by:
      getPlayerCount in interface ServerApi
      Returns:
      the current number of players (integer value)
    • getPlayerIterator

      public Iterator<Player> getPlayerIterator()
      Description copied from interface: ServerApi
      Retrieves an iterator for the global player management list on the server. This method should be used to prevent the "escape references" issue.
      Specified by:
      getPlayerIterator in interface ServerApi
      Returns:
      an iterator of Player management list
      See Also:
    • getReadonlyPlayersList

      public List<Player> getReadonlyPlayersList()
      Description copied from interface: ServerApi
      Retrieves a read-only global player management list on the server. This method should be used to prevent the "escape references" issue.
      Specified by:
      getReadonlyPlayersList in interface ServerApi
      Returns:
      a list of all Players in the management list on the server
      See Also:
    • getRoomById

      public Optional<Room> getRoomById(long roomId)
      Description copied from interface: ServerApi
      Retrieves a room instance by using its ID.
      Specified by:
      getRoomById in interface ServerApi
      Parameters:
      roomId - a unique room ID (long value)
      Returns:
      an optional Room instance
      See Also:
    • getRoomIterator

      public Iterator<Room> getRoomIterator()
      Description copied from interface: ServerApi
      Retrieves an iterator for the room management list on the server. This method should be used to prevent the "escape references" issue.
      Specified by:
      getRoomIterator in interface ServerApi
      Returns:
      a list of all rooms Room in the management list on the server
      See Also:
    • getReadonlyRoomsList

      public List<Room> getReadonlyRoomsList()
      Description copied from interface: ServerApi
      Retrieves a read-only global room management list on the server. This method should be used to prevent the "escape references" issue.
      Specified by:
      getReadonlyRoomsList in interface ServerApi
      Returns:
      a list of all rooms Room in the management list on the server
      See Also:
    • getRoomCount

      public int getRoomCount()
      Description copied from interface: ServerApi
      Fetches the current number of rooms on the server.
      Specified by:
      getRoomCount in interface ServerApi
      Returns:
      the current number of rooms (integer value)
    • joinRoom

      public void joinRoom(Player player, Room room, String roomPassword, int slotInRoom, boolean asSpectator)
      Description copied from interface: ServerApi
      Allows a player to join a particular room.
      Specified by:
      joinRoom in interface ServerApi
      Parameters:
      player - the joining Player
      room - the current Room
      roomPassword - a String credential using for a player to join room. In case of free join, this value would be set to null
      slotInRoom - the position of player located in the room (integer value)
      asSpectator - sets by true if the player operating in the room as a spectator, otherwise sets it false
    • leaveRoom

      public void leaveRoom(Player player, PlayerLeaveRoomMode leaveRoomMode)
      Description copied from interface: ServerApi
      Makes a player to leave its current room.
      Specified by:
      leaveRoom in interface ServerApi
      Parameters:
      player - the leaving Player
      leaveRoomMode - a rule (PlayerLeaveRoomMode) applied for the leaving player
    • removeRoom

      public void removeRoom(Room room, RoomRemoveMode removeRoomMode)
      Description copied from interface: ServerApi
      Removes a room from the management list, server.
      Specified by:
      removeRoom in interface ServerApi
      Parameters:
      room - the removing Room
      removeRoomMode - a rule (RoomRemoveMode) applied for the removing room
    • getCurrentAvailableUdpPort

      public int getCurrentAvailableUdpPort()
      Description copied from interface: ServerApi
      Retrieves the current available UDP port.
      Specified by:
      getCurrentAvailableUdpPort in interface ServerApi
      Returns:
      an integer value of UDP port
    • getStartedTime

      public long getStartedTime()
      Description copied from interface: ServerApi
      Retrieves the time when server starts in milliseconds.
      Specified by:
      getStartedTime in interface ServerApi
      Returns:
      started time in milliseconds
    • getUptime

      public long getUptime()
      Description copied from interface: ServerApi
      Retrieves the current uptime of server in milliseconds.
      Specified by:
      getUptime in interface ServerApi
      Returns:
      the current server's uptime in milliseconds