Hi, this is a little help that can help. ; )
the function reports if the client that connects is considered the Master client of the room.
Master Client (from photonengine)
Master Client is a “special” client per room. In absence of custom server code, it can be made responsible for handling logic that should only be executed by one client in a room (e.g. starting a match when everyone is ready). A new Master Client is automatically assigned when the former leaves. Unless explicitly set, the Master Client is the actor (player) with the least actor number among the active actors.
Starts from example found in photon SDK (photon_corona_plugin_sample) where you create the class: client
…
local client = LoadBalancingClient.new(appInfo.ServerAddress, appInfo.AppId, appInfo.AppVersion)
…
function client:checkInit()
--return "S" slave or "M" master
local nrMaster = 0
local result = "S"
if self:isJoinedToRoom() then
nrMaster = self:myRoomMasterActorNr()
for actorNr, actor in pairs(client:myRoomActors()) do
if actor.actorNr == nrMaster and actor.isLocal == true then
--I'm master
result = "M"
break
else
--I'm slave
end
end
end
return result
end
…
I think is better call also other 2 instances to have updated the state
…
function client:onActorJoin(actor)
self:checkInit()
endfunction client:onActorLeave(actor)
self:checkInit()
end
…
I think the code should be better: avoid the ‘for’ loop.
But I’m not able to write a better one.
If someone can help is appreciate.
Renato