Class SteamClient
- java.lang.Object
-
- in.dragonbra.javasteam.steam.CMClient
-
- in.dragonbra.javasteam.steam.steamclient.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 Summary
Constructors Constructor Description SteamClient()Initializes a new instance of theSteamClientclass with the default configuration.SteamClient(SteamConfiguration configuration)Initializes a new instance of theSteamClientclass with a specific configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHandler(ClientMsgHandler handler)Adds a new handler to the internal list of message handlers.voidfreeLastCallback()Frees the last callback in the queue.java.util.List<ICallbackMsg>getAllCallbacks(boolean freeLast, long timeout)Blocks the calling thread until the queue contains a callback object.ICallbackMsggetCallback()Gets the next callback object in the queue.ICallbackMsggetCallback(boolean freeLast)Gets the next callback object in the queue, and optionally frees it.<T extends ClientMsgHandler>
TgetHandler(java.lang.Class<T> type)Returns a registered handler.JobIDgetNextJobID()Returns the next available JobID for job based messages.protected voidonClientConnected()Called when the client is securely isConnected to Steam3.protected voidonClientDisconnected(boolean userInitiated)Called when the client is physically disconnected from Steam3.protected booleanonClientMsgReceived(IPacketMsg packetMsg)voidpostCallback(CallbackMsg msg)Posts a callback to the queue.voidremoveHandler(ClientMsgHandler handler)Removes a registered handler.voidremoveHandler(java.lang.Class<? extends ClientMsgHandler> handler)Removes a registered handler by name.ICallbackMsgwaitForCallback()Blocks the calling thread until a callback object is posted to the queue.ICallbackMsgwaitForCallback(boolean freeLast)Blocks the calling thread until a callback object is posted to the queue, and optionally frees it.ICallbackMsgwaitForCallback(boolean freeLast, long timeout)Blocks the calling thread until a callback object is posted to the queue, and optionally frees it.ICallbackMsgwaitForCallback(long timeout)Blocks the calling thread until a callback object is posted to the queue, or null after the timeout has elapsed.-
Methods inherited from class in.dragonbra.javasteam.steam.CMClient
connect, connect, disconnect, getCellID, getConfiguration, getConnectionTimeout, getCurrentEndpoint, getDebugNetworkListener, getLocalIP, getPacketMsg, getServers, getServers, getSessionID, getSessionToken, getSteamID, getUniverse, isConnected, isExpectDisconnection, send, setDebugNetworkListener, setExpectDisconnection
-
-
-
-
Constructor Detail
-
SteamClient
public SteamClient()
Initializes a new instance of theSteamClientclass with the default configuration.
-
SteamClient
public SteamClient(SteamConfiguration configuration)
Initializes a new instance of theSteamClientclass 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.
-
onClientMsgReceived
protected boolean onClientMsgReceived(IPacketMsg packetMsg)
- Overrides:
onClientMsgReceivedin classCMClient
-
onClientConnected
protected void onClientConnected()
Description copied from class:CMClientCalled when the client is securely isConnected to Steam3.- Overrides:
onClientConnectedin classCMClient
-
onClientDisconnected
protected void onClientDisconnected(boolean userInitiated)
Description copied from class:CMClientCalled when the client is physically disconnected from Steam3.- Overrides:
onClientDisconnectedin classCMClient- Parameters:
userInitiated- whether the disconnect was initialized by the client
-
-