forked from rojo-rbx/rojo
Don't remind to sync if the lock is claimed (#833)
If the sync lock is claimed in Team Create, the user cannot sync. Therefore, a sync reminder notification is unhelpful as it is calling to an invalid action.
This commit is contained in:
@@ -136,6 +136,7 @@ function App:init()
|
||||
and self.serveSession == nil
|
||||
and Settings:get("syncReminder")
|
||||
and self:getLastSyncTimestamp()
|
||||
and (self:isSyncLockAvailable())
|
||||
then
|
||||
self:addNotification("You've previously synced this place. Would you like to reconnect?", 300, {
|
||||
Connect = {
|
||||
@@ -283,12 +284,39 @@ function App:getHostAndPort()
|
||||
return host, port
|
||||
end
|
||||
|
||||
function App:isSyncLockAvailable()
|
||||
if #Players:GetPlayers() == 0 then
|
||||
-- Team Create is not active, so no one can be holding the lock
|
||||
return true
|
||||
end
|
||||
|
||||
local lock = ServerStorage:FindFirstChild("__Rojo_SessionLock")
|
||||
if not lock then
|
||||
-- No lock is made yet, so it is available
|
||||
return true
|
||||
end
|
||||
|
||||
if lock.Value and lock.Value ~= Players.LocalPlayer and lock.Value.Parent then
|
||||
-- Someone else is holding the lock
|
||||
return false, lock.Value
|
||||
end
|
||||
|
||||
-- The lock exists, but is not claimed
|
||||
return true
|
||||
end
|
||||
|
||||
function App:claimSyncLock()
|
||||
if #Players:GetPlayers() == 0 then
|
||||
Log.trace("Skipping sync lock because this isn't in Team Create")
|
||||
return true
|
||||
end
|
||||
|
||||
local isAvailable, priorOwner = self:isSyncLockAvailable()
|
||||
if not isAvailable then
|
||||
Log.trace("Skipping sync lock because it is already claimed")
|
||||
return false, priorOwner
|
||||
end
|
||||
|
||||
local lock = ServerStorage:FindFirstChild("__Rojo_SessionLock")
|
||||
if not lock then
|
||||
lock = Instance.new("ObjectValue")
|
||||
@@ -300,11 +328,6 @@ function App:claimSyncLock()
|
||||
return true
|
||||
end
|
||||
|
||||
if lock.Value and lock.Value ~= Players.LocalPlayer and lock.Value.Parent then
|
||||
Log.trace("Found existing sync lock owned by {}", lock.Value)
|
||||
return false, lock.Value
|
||||
end
|
||||
|
||||
lock.Value = Players.LocalPlayer
|
||||
Log.trace("Claimed existing sync lock")
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user