private void HandleProvideRoomAccessCheck(IIncommingMessage message) { var data = message.Deserialize(new RoomAccessProvideCheckPacket()); var roomController = _roomsPlugin.GetRoomController(data.RoomId); if (roomController == null) { message.Respond("There's no room controller with room id " + data.RoomId, ResponseStatus.NotHandled); return; } var accessProvider = roomController._accessProvider ?? DefaultAccessProvider; var isProviderDone = false; var requester = new UsernameAndPeerIdPacket() { PeerId = data.PeerId, Username = data.Username }; // Invoke the access provider accessProvider.Invoke(requester, (access, error) => { // In case provider timed out if (isProviderDone) { return; } isProviderDone = true; if (access == null) { // If access is not provided message.Respond(error ?? "", ResponseStatus.Failed); return; } message.Respond(access, ResponseStatus.Success); if (Logger.IsLogging(LogLevel.Trace)) { Logger.Trace("Room controller gave address to peer " + data.PeerId + ":" + access); } }); // Timeout the access provider AppTimer.AfterSeconds(_roomsPlugin.AccessProviderTimeout, () => { if (!isProviderDone) { isProviderDone = true; message.Respond("Timed out", ResponseStatus.Timeout); Logger.Error("Access provider took longer than " + _roomsPlugin.AccessProviderTimeout + " seconds to provide access. " + "If it's intended, increase the threshold at Msf.Server.Rooms.AccessProviderTimeout"); } }); }