internal void OnStartServer(bool allowNonZeroNetId)
{
if (this.m_IsServer)
{
return;
}
this.m_IsServer = true;
this.m_HasAuthority = !this.m_LocalPlayerAuthority;
this.m_Observers = new List <NetworkConnection>();
this.m_ObserverConnections = new HashSet <int>();
this.CacheBehaviours();
if (this.netId.IsEmpty())
{
this.m_NetId = NetworkIdentity.GetNextNetworkId();
}
else if (!allowNonZeroNetId)
{
if (!LogFilter.logError)
{
return;
}
Debug.LogError((object)("Object has non-zero netId " + (object)this.netId + " for " + (object)this.gameObject));
return;
}
if (LogFilter.logDev)
{
Debug.Log((object)("OnStartServer " + (object)this.gameObject + " GUID:" + (object)this.netId));
}
NetworkServer.instance.SetLocalObjectOnServer(this.netId, this.gameObject);
for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index)
{
NetworkBehaviour networkBehaviour = this.m_NetworkBehaviours[index];
try
{
networkBehaviour.OnStartServer();
}
catch (Exception ex)
{
Debug.LogError((object)("Exception in OnStartServer:" + ex.Message + " " + ex.StackTrace));
}
}
if (NetworkClient.active && NetworkServer.localClientActive)
{
ClientScene.SetLocalObject(this.netId, this.gameObject);
this.OnStartClient();
}
if (!this.m_HasAuthority)
{
return;
}
this.OnStartAuthority();
}