Getting Room and Room Member Information¶
You can get current room information using the room
property of the StrixNetwork
singleton.
If you are not joined to any room, the property should return null
.
Room Properties¶
The room
property has the following fields which can be read using the getters listed in the table below.
Name |
Type |
Description |
Getter |
---|---|---|---|
name |
string |
The name given to the room by the room owner. |
GetName() |
capacity |
int |
The maximum number of members the room can currently hold.
The check is performed only when a new client tries to join the room.
If this property is changed in the course of a game and the current number of members exceeds the new value,
existing members will not be kicked.
|
GetCapacity() |
password |
string |
This field will be empty when referring to room properties.
If set up, the new clients must provide a matching password when joining the room.
In case the password doesn’t match or is not provided, the client will be rejected.
If set empty, anyone can join the room.
|
GetPassword() |
state |
int |
State of the room, expressed by an integer value.
The game implementor defines what particular state each value represents.
|
GetState() |
isJoinable |
bool |
If set to false, new members are not allowed to join the room. |
GetIsJoinable() |
key1-key8 |
double |
Custom property values. |
GetKey1()-GetKey8() |
stringKey |
string |
Custom string property value. |
GetStringKey() |
memberCount |
int |
The number of room members currently present in the room. |
GetMemberCount() |
properties |
Dictionary <string, object> |
Additional custom property values. |
GetProperties() |
Room Member Properties¶
Current Player¶
You can retrieve the following properties from the selfRoomMember
value on the network instance:
Name |
Type |
Description |
Getter |
---|---|---|---|
uid |
UID |
Unique identifier of the room member. |
GetUid() |
primaryKey |
long |
Primary key identifier of the room member in the server database. |
GetPrimaryKey() |
roomId |
long |
The ID of the room this member belongs to. |
GetRoomId() |
name |
string |
The name of the room member. |
GetName() |
properties |
Dictionary <string, object> |
Additional custom property values. |
GetProperties() |
All Room Members¶
There are two collections of room members available on the network instance:
roomMembers
A dictionary where the keys are the IDs of the members.
sortedRoomMembers
A list where all room members are sorted by their primary key.
You can retrieve the same properties from each room member as above.
When you’re joined to a room, you can always check if you are the room owner by inspecting the isRoomOwner
property on the StrixNetwork
singleton.
Note
Although all the fields listed above have setters in addition to getters, they are only used by the Strix SDK itself and should not be called by the end user. Setting these fields will only do so locally.
Code Example¶
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;
class GettingRoomInfoSample : MonoBehaviour
{
void Start()
{
var strixNetwork = StrixNetwork.instance;
// This is a placeholder value. Change this to your application ID
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
// First we connect to the master server
strixNetwork.ConnectMasterServer(
// This is a placeholder value. Change this to your master hostname
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
host: "000000000000000000000000.game.strixcloud.net",
connectEventHandler: _ => {
Debug.Log("Connection established.");
// After we've connected to the master server we can create a room
strixNetwork.CreateRoom(
roomProperties: new RoomProperties
{
name = "Athens",
password = "66e3f2nk",
capacity = 20,
key1 = 3.2,
state = 12,
stringKey = "Tokyo"
},
memberProperties: new RoomMemberProperties
{
name = "Artemis"
},
handler: createRoomResult => {
var room = strixNetwork.room;
Debug.Log(
"Room name: " + room.GetName() // Name of the room should be the same we've set up when creating it, namely Athens
+ "\nRoom capacity: " + room.GetCapacity() // The capacity should be 20
+ "\nRoom password: " + room.GetPassword() // Even though we've set up a password we shouldn't be able to read it so it should be empty
+ "\nRoom state: " + room.GetState() // The state we've set up earlier. Should be 12
+ "\nRoom is joinable: " + room.GetIsJoinable() // Since we didn't specify it when creating the room, it should be joinable by default
+ "\nRoom's key1: " + room.GetKey1() // The key we've set up earlier. Should be 3.2
+ "\nRoom's string key: " + room.GetStringKey() // The string key we've set up earlier. Should be "Tokyo"
+ "\nRoom's member count: " + room.GetMemberCount() // Should be 1, since we are currently the only member
);
var roomMember = strixNetwork.selfRoomMember;
Debug.Log(
"Room member name: " + roomMember.GetName() // Name of the member should be the same we've set up when creating the room, namely Artemis
);
},
failureHandler: createRoomError => Debug.LogError("Could not create room. Reason: " + createRoomError.cause)
);
},
errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)
);
}
}
Note
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.