/// <summary> /// Fires when room server send message about access validation result /// </summary> /// <param name="conn"></param> /// <param name="msg"></param> protected virtual void ValidateRoomAccessResultHandler(ValidateRoomAccessResultMessage msg) { if (msg.Status != ResponseStatus.Success) { logger.Error(msg.Error); OnAccessDenied(); OnAccessDiniedEvent?.Invoke(); return; } logger.Debug("Access to server room is successfully validated"); OnAccessGranted(); OnAccessGrantedEvent?.Invoke(); }
/// <summary> /// Fires when client connected to room server /// </summary> protected virtual void OnClientConnectedToRoomServer() { logger.Info("We have successfully connected to the room server"); roomServerConnection.RemoveConnectionListener(OnClientConnectedToRoomServer); roomServerConnection.SendMessage((short)MstMessageCodes.ValidateRoomAccessRequest, roomServerAccessInfo.Token, (status, response) => { // If access denied if (status != ResponseStatus.Success) { logger.Error(response.AsString()); OnAccessDiniedEvent?.Invoke(); return; } // If access granted OnAccessGrantedEvent?.Invoke(); }); }
/// <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); }); }