Class SteamClient


  • public class SteamClient
    extends CMClient
    Represents a single client that connects to the Steam3 network. This class is also responsible for handling the registration of client message handlers and callbacks.
    • Constructor Detail

      • SteamClient

        public SteamClient()
        Initializes a new instance of the SteamClient class with the default configuration.
      • SteamClient

        public SteamClient​(SteamConfiguration configuration)
        Initializes a new instance of the SteamClient class with a specific configuration.
        Parameters:
        configuration - The configuration to use for this client.
    • Method Detail

      • addHandler

        public void addHandler​(ClientMsgHandler handler)
        Adds a new handler to the internal list of message handlers.
        Parameters:
        handler - The handler to add.
      • removeHandler

        public void removeHandler​(java.lang.Class<? extends ClientMsgHandler> handler)
        Removes a registered handler by name.
        Parameters:
        handler - The handler name to remove.
      • removeHandler

        public void removeHandler​(ClientMsgHandler handler)
        Removes a registered handler.
        Parameters:
        handler - The handler name to remove.
      • getHandler

        public <T extends ClientMsgHandler> T getHandler​(java.lang.Class<T> type)
        Returns a registered handler.
        Type Parameters:
        T - The type of the handler to cast to. Must derive from ClientMsgHandler.
        Parameters:
        type - The type of the handler to cast to. Must derive from ClientMsgHandler.
        Returns:
        A registered handler on success, or null if the handler could not be found.
      • getCallback

        public ICallbackMsg getCallback()
        Gets the next callback object in the queue. This function does not dequeue the callback, you must call FreeLastCallback after processing it.
        Returns:
        The next callback in the queue, or null if no callback is waiting.
      • getCallback

        public ICallbackMsg getCallback​(boolean freeLast)
        Gets the next callback object in the queue, and optionally frees it.
        Parameters:
        freeLast - if set to true this function also frees the last callback if one existed.
        Returns:
        The next callback in the queue, or null if no callback is waiting.
      • waitForCallback

        public ICallbackMsg waitForCallback()
        Blocks the calling thread until a callback object is posted to the queue. This function does not dequeue the callback, you must call FreeLastCallback after processing it.
        Returns:
        The callback object from the queue.
      • waitForCallback

        public ICallbackMsg waitForCallback​(long timeout)
        Blocks the calling thread until a callback object is posted to the queue, or null after the timeout has elapsed. This function does not dequeue the callback, you must call FreeLastCallback after processing it.
        Parameters:
        timeout - The length of time to block in ms.
        Returns:
        A callback object from the queue if a callback has been posted, or null if the timeout has elapsed.
      • waitForCallback

        public ICallbackMsg waitForCallback​(boolean freeLast)
        Blocks the calling thread until a callback object is posted to the queue, and optionally frees it.
        Parameters:
        freeLast - if set to true this function also frees the last callback if one existed.
        Returns:
        The callback object from the queue.
      • waitForCallback

        public ICallbackMsg waitForCallback​(boolean freeLast,
                                            long timeout)
        Blocks the calling thread until a callback object is posted to the queue, and optionally frees it.
        Parameters:
        freeLast - if set to true this function also frees the last callback if one existed.
        timeout - The length of time to block.
        Returns:
        A callback object from the queue if a callback has been posted, or null if the timeout has elapsed.
      • getAllCallbacks

        public java.util.List<ICallbackMsg> getAllCallbacks​(boolean freeLast,
                                                            long timeout)
        Blocks the calling thread until the queue contains a callback object. Returns all callbacks, and optionally frees them.
        Parameters:
        freeLast - if set to true this function also frees all callbacks.
        timeout - The length of time to block.
        Returns:
        All current callback objects in the queue.
      • freeLastCallback

        public void freeLastCallback()
        Frees the last callback in the queue.
      • postCallback

        public void postCallback​(CallbackMsg msg)
        Posts a callback to the queue. This is normally used directly by client message handlers.
        Parameters:
        msg - The message.
      • getNextJobID

        public JobID getNextJobID()
        Returns the next available JobID for job based messages.
        Returns:
        The next available JobID.
      • onClientConnected

        protected void onClientConnected()
        Description copied from class: CMClient
        Called when the client is securely isConnected to Steam3.
        Overrides:
        onClientConnected in class CMClient
      • onClientDisconnected

        protected void onClientDisconnected​(boolean userInitiated)
        Description copied from class: CMClient
        Called when the client is physically disconnected from Steam3.
        Overrides:
        onClientDisconnected in class CMClient
        Parameters:
        userInitiated - whether the disconnect was initialized by the client