ClusterJoinOrCreateRequest Class |
Namespace: Sfs2X.Requests.Cluster
public class ClusterJoinOrCreateRequest : BaseRequest
Name | Description | |
---|---|---|
ClusterJoinOrCreateRequest(MatchExpression) |
See ClusterJoinOrCreateRequest(MatchExpression, List<string>, RoomSettings) constructor.
| |
ClusterJoinOrCreateRequest(RoomSettings) |
See ClusterJoinOrCreateRequest(MatchExpression, List<string>, RoomSettings) constructor.
| |
ClusterJoinOrCreateRequest(MatchExpression, ListString) |
See ClusterJoinOrCreateRequest(MatchExpression, List<string>, RoomSettings) constructor.
| |
ClusterJoinOrCreateRequest(MatchExpression, ListString, RoomSettings) |
Creates a new ClusterJoinOrCreateRequest instance.
|
void SomeMethod() { sfsLobby.AddEventListener(SFSClusterEvent.CONNECTION_REQUIRED, OnGameNodeConnectionRequired); // Create a matching expression to find a Darts game with a "maxBet" variable less than 100 MatchExpression exp = new MatchExpression("type", StringMatch.EQUALS, "Darts").And("maxBet", NumberMatch.LESS_THAN, 100); // Set the Room settings to create a new game Room if one is not found ClusterRoomSettings settings = new ClusterRoomSettings("NewRoom__" + new System.Random().Next()); settings.GroupId = "games"; settings.IsPublic = true; settings.IsGame = true; settings.MaxUsers = 10; settings.MinPlayersToStartGame = 2; // Search (or create) and join a public game within the "games" Group sfsLobby.Send(new ClusterJoinOrCreateRequest(exp, new List<string>(){"games"}, settings)); } void OnGameNodeConnectionRequired(BaseEvent evt) { // Retrieve connection settings ConfigData cfg = (ConfigData)evt.Params["configData"]; // Retrieve and save login details gameUsername = (string)evt.Params["userName"]; gamePassword = (string)evt.Params["password"]; // Initialize SmartFox client used to connect to the cluster game node sfsGame = new SmartFox(); // Add event listeners sfsGame.AddEventListener(SFSEvent.CONNECTION, OnGameNodeConnection); sfsGame.AddEventListener(SFSEvent.LOGIN, OnGameNodeLogin); sfsGame.AddEventListener(SFSEvent.ROOM_JOIN, OnGameRoomJoin); // Establish a connection to the game node; a game room will be joined automatically after login sfsGame.Connect(cfg); } void OnGameNodeConnection(BaseEvent evt) { if ((bool)evt.Params["success"]) { // Login sfsGame.Send(new LoginRequest(gameUsername, gamePassword)); } } void OnGameNodeLogin(BaseEvent evt) { // Nothing to do; a game Room-autojoin is triggered by the server } void OnGameRoomJoin(BaseEvent evt) { Console.WriteLine("Successfully joined Room: " + (Room)evt.Params["room"]); // .Net / Unity System.Diagnostics.Debug.WriteLine("Successfully joined Room: " + (Room)evt.Params["room"]); // UWP }