/// <summary> /// Start connection to master /// </summary> private void ConnectToMaster() { // Start room connection to master if (!masterConnection.IsConnected) { masterConnection.Connect(masterIp, masterPort); } // Wait a result of client connection masterConnection.WaitForConnection((clientSocket) => { if (!clientSocket.IsConnected) { logger.Error("Failed to connect room server to master server"); } else { logger.Info("Room server is successfuly connected to master server"); // Start the server on next frame MsfTimer.WaitForEndOfFrame(() => { StartServer(roomOptions.RoomIp, roomOptions.RoomPort); }); } }, 4f); }
/// <summary> /// Starting connection to master server as client to be able to register room later after successful connection /// </summary> private void ConnectToMaster() { // Start client connection if (!masterConnection.IsConnected) { masterConnection.UseSsl = MstApplicationConfig.Instance.UseSecure || Mst.Args.UseSecure; masterConnection.Connect(masterIP, masterPort); } // Wait a result of client connection masterConnection.WaitForConnection((clientSocket) => { if (!clientSocket.IsConnected) { logger.Error("Failed to connect room client to master server"); } else { logger.Info($"Successfully connected to master {masterConnection.ConnectionIp}:{masterConnection.ConnectionPort}"); // For the test purpose only if (IsInTestMode()) { if (signInAsGuest) { // Sign in client as guest Mst.Client.Auth.SignInAsGuest(SignInCallback); } else { // Sign in client using credentials Mst.Client.Auth.SignInWithLoginAndPassword(username, password, SignInCallback); } } else { // If we have option with room id // this approach can be used when you have come to this scene from another one. // Set this option before this room client controller is connected to master server if (Mst.Options.Has(MstDictKeys.ROOM_ID)) { // Let's try to get access data for room we want to connect to GetRoomAccess(Mst.Options.AsInt(MstDictKeys.ROOM_ID)); } else { logger.Error($"You have no room id in this options: {Mst.Options}"); } } } }, 5f); }
/// <summary> /// Tries to get access data for room we want to connect to /// </summary> /// <param name="roomId"></param> private void GetRoomAccess(int roomId) { logger.Debug($"Getting access to room {roomId}"); Mst.Client.Rooms.GetAccess(roomId, (access, error) => { if (access == null) { logger.Error(error); OnAccessDiniedEvent?.Invoke(); return; } // Save gotten room access roomServerAccessInfo = access; // Let's set the IP before we start connection roomServerIp = roomServerAccessInfo.RoomIp; // Let's set the port before we start connection roomServerPort = roomServerAccessInfo.RoomPort; logger.Debug($"Access to room {roomId} received"); logger.Debug(access); logger.Debug("Connecting to room server..."); // Start client connection roomServerConnection.UseSsl = MstApplicationConfig.Instance.UseSecure || Mst.Args.UseSecure; roomServerConnection.Connect(roomServerIp, roomServerPort); // Wait a result of client connection roomServerConnection.WaitForConnection((clientSocket) => { if (!clientSocket.IsConnected) { logger.Error("Connection attempts to room server timed out"); return; } }, 4f); }); }