StrixNetworkJoinRoom Method (String, Int32, String, Int64, String, RoomJoinEventHandler, FailureEventHandler, RequestConfig) |
Joins a match room.
Namespace:
SoftGear.Strix.Unity.Runtime
Assembly:
StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax public void JoinRoom(
string host,
int port,
string protocol,
long roomId,
string playerName,
RoomJoinEventHandler handler,
FailureEventHandler failureHandler,
RequestConfig config = null
)
Parameters
- host
- Type: SystemString
The address of the room server. Can be either URL, IPv4 address, or IPv6 address. - port
- Type: SystemInt32
The port number of the room server. Must be between 1 and 65535. - protocol
- Type: SystemString
Protocol used to connect to the room server. This parameter should be set to a value returned by protocol. - roomId
- Type: SystemInt64
An ID of the room on the room server. - playerName
- Type: SystemString
The name your player will have after joining the room. Can be left empty or null. - handler
- Type: SoftGear.Strix.Unity.Runtime.EventRoomJoinEventHandler
This callback is invoked when joining the room has completed successfully. - failureHandler
- Type: SoftGear.Strix.Unity.Runtime.EventFailureEventHandler
This callback is invoked in case of a failure. - config (Optional)
- Type: SoftGear.Strix.Client.Core.RequestRequestConfig
If not null, used to configure the request timeout. Default timeout is 30 seconds. See RequestConfig for more details.
Remarks
In order to join the room, you need to know the address of the room server (
host and
port), the
protocol, and the room ID.
Usually, you can get them from
SearchRoom results.
See
host,
port,
protocol, and
roomId.
playerName is optional and can be left empty or null.
If your setup makes use of an authorization server, use the
overload of this method that accepts
RoomJoinArgs and provide the authorization server URL through
authUrl.
Possible exception types in FailureEventArgs's cause:ErrorCodeException |
Strix error which can be further separated by an error code:
ConnectionError | Failed to send the request because of a connection error. | RequestTimeout | Server did not respond within the specified timeout interval. | NoSuchProperty | Could not find one of the properties to set. | RoomNotFound | Could not find the room with the given roomId. | AlreadyInRoom | You are already joined to the room you're trying to join. | RoomFullOfMembers | The room you're trying to join has no room for new members. | WrongRoomPassword | The room you're trying to join is password-protected and either you didn't provide any password or it didn't match. | RoomNotJoinable | Cannot join the room because its owner has made it non-joinable. | LockTimeout | | InvalidCredentialsType |
Credentials type does not match the server authentication configuration.
This can happen if, for example, the server is configured to authenticate by password instead of application ID.
On Strix Cloud this error should never occur since currently it always uses application ID authentication.
| InternalError |
Internal server error. This can be caused by a bug or some other problem on the server and should be reported to the developers.
| UnsupportedLibraryVersion |
Current client library is not supported by the server.
This can happen if the client version is too old.
To fix this error, update the Strix SDK to the latest version.
| InvalidApplicationIdToken |
Application ID token provided via applicationId does not match the one on the server.
Check if the application ID is the same as the one listed on Information tab of the Dashboard on the Strix Cloud web page.
|
|
SocketException | An error occurred when attempting to access the socket. |
WebException |
There has been an error when connecting to the authentication server.
It's either an HTTP error such as 404/Not Found, or a network error like failure to resolve a DNS entry, a socket error, etc.
|
ArgumentException |
When using an authentication server this error can happen if the server returns an invalid authorization token.
It could be an invalid UTF-8 string or an invalid JSON.
|
Exception |
This can happen if the address for the given host couldn't be resolved when establishing socket connection.
|
Examples
In this example we first connect to a master server to be able to perform a search on it.
After that we start searching for joinable match rooms (match rooms that have enough room for a new member).
We sort the rooms by member count in ascending order so that the first room in the resulting list will be the least crowded.
Then, if anything is found, we select the first room and try to join it.
Note: In order for this example to work, you need to have an active room registered on the master server, but since rooms are destroyed if there are no members left, you would need at least two clients.
You can create a match room from another game instance using
CreateRoom and then run this example.
Otherwise, the search will fail with no available rooms.
Also, make sure to change the placeholder values of
applicationId and
host to the real ones that can be found on the
Strix Cloud application information tab.
using SoftGear.Strix.Client.Core.Model.Manager.Filter;
using SoftGear.Strix.Unity.Runtime;
using System.Linq;
using UnityEngine;
public class StrixJoinRoomExample : MonoBehaviour
{
void Start()
{
var strixNetwork = StrixNetwork.instance;
strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
strixNetwork.ConnectMasterServer(
host: "0123456789abcdef01234567.game.strixcloud.net",
connectEventHandler: _ => {
Debug.Log("Connection established.");
strixNetwork.SearchJoinableRoom(
condition: null,
order: new Order("memberCount", OrderType.Ascending),
limit: 10,
offset: 0,
handler: searchResults => {
var foundRooms = searchResults.roomInfoCollection;
Debug.Log(foundRooms.Count + " rooms found.");
if (foundRooms.Count == 0) {
Debug.LogError("No joinable rooms found.");
return;
}
var roomInfo = foundRooms.First();
strixNetwork.JoinRoom(
host: roomInfo.host,
port: roomInfo.port,
protocol: roomInfo.protocol,
roomId: roomInfo.roomId,
playerName: "My Player Name",
handler: __ => Debug.Log("Room joined."),
failureHandler: joinError => Debug.LogError("Join failed. Reason: " + joinError.cause)
);
},
failureHandler: searchError => Debug.LogError("Search failed. Reason: " + searchError.cause)
);
},
errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)
);
}
}
See Also