public IEnumerator SetServer(NetConnection server, NetZone zone) { zone.Assigned = true; if (server != Socket.Self) { var setServerRequest = Socket.Request.Send <string>("AssignZone", server, zone); yield return(setServerRequest.WaitUntilDone); if (!setServerRequest.IsSuccessful) { zone.Assigned = false; yield break; } zone.PublicEndpoint = setServerRequest.Result; } else { NetZoneServer zoneServ = GetComponent <NetZoneServer>(); zoneServ.AssignZoneSelf(zone); } zone.Server = server; zone.ServerEndpoint = zone.Server.Endpoint; if (string.IsNullOrEmpty(zone.PublicEndpoint)) { zone.PublicEndpoint = zone.Server.Endpoint.ToString(); } ZoneAssigned(zone); NetLog.Info("Server assigned to zone. Endpoint: " + server.Endpoint); zone.Available = true; }
public IEnumerator SetServer(NetConnection server, NetZone zone) { zone.Assigned = true; if (server != Socket.Self) { var setServerRequest = Socket.Request.Send<string>("AssignZone", server, zone); yield return setServerRequest.WaitUntilDone; if (!setServerRequest.IsSuccessful) { zone.Assigned = false; yield break; } zone.PublicEndpoint = setServerRequest.Result; } else { NetZoneServer zoneServ = GetComponent<NetZoneServer>(); zoneServ.AssignZoneSelf(zone); } zone.Server = server; zone.ServerEndpoint = zone.Server.Endpoint; if (string.IsNullOrEmpty(zone.PublicEndpoint)) zone.PublicEndpoint = zone.Server.Endpoint.ToString(); ZoneAssigned(zone); NetLog.Info("Server assigned to zone. Endpoint: " + server.Endpoint); zone.Available = true; }
internal void ZoneAssigned(NetZone zone) { if (unassignedPeers.ContainsKey(zone.Server)) { unassignedPeers.Remove(zone.Server); } for (int i = 0; i < zones.Count; i++) { NetZone peerZone = zones[i]; if (zone == peerZone || peerZone.Server == null) { continue; } if (peerZone.Server == Socket.Self) { GetComponent <NetZoneServer>().AddPeerSelf(zone); } if (zone.Server != Socket.Self) { Socket.Send("AddPeer", zone.Server, peerZone); } if (peerZone.Server != Socket.Self) { Socket.Send("AddPeer", peerZone.Server, zone); } } }
/// <summary> Attempts to find a Zone for the provided position. </summary> public bool TryGetZone(Vector3 position, out NetZone zone) { NetZone closestZone = null; float closestDistance = float.MaxValue; foreach (NetZone z in zones) { if (!z.Assigned) { continue; } float distance = z.Distance(position); if (distance > z.HandoverMaxDistance) { continue; } if (distance > closestDistance) { continue; } closestZone = z; closestDistance = distance; } if (closestZone == null) { zone = null; return(false); } zone = closestZone; return(true); }
internal void AssignZoneSelf(NetZone zone) { if (ViewManager.GenerateViewId == null) ViewManager.GenerateViewId += AllocateViewId; NetLog.Info("Assigned to zone."); Debug.Log("Zone Position:" + zone.Position); self = zone; if (OnAssignment != null) OnAssignment(); }
private void RemovePeer(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) { return; } RemovePeerSelf(zone); }
internal void AddPeerSelf(NetZone zone) { if (peerLookup.ContainsKey(zone.ServerEndpoint)) peerLookup.Remove(zone.ServerEndpoint); peerLookup.Add(zone.ServerEndpoint, zone); if (peers.Contains(zone)) peers.Remove(zone); peers.Add(zone); if (Socket.EndpointConnected(zone.ServerEndpoint)) PeerConnected(Socket.EndpointToConnection(zone.ServerEndpoint)); }
private string AssignZone(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) { return(""); } AssignZoneSelf(zone); return(Socket.Address); }
/// <summary> Creates a Zone at the specified position. </summary> public NetZone CreateZone(Vector3 position) { if (!CanAllocateIdBlock()) { throw new Exception("Cannot Create Zone: Unable to allocate ViewID block, limit has been reached."); } var newZone = new NetZone(position, GetViewIdMin(), GetViewIdMax()); zones.Add(newZone); AssignServers(); return newZone; }
private void AddPeer(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) { return; } AddPeerSelf(zone); if (!Socket.EndpointConnected(zone.ServerEndpoint)) { Socket.ConnectToPeer(zone.ServerEndpoint); } }
internal void AssignZoneSelf(NetZone zone) { if (ViewManager.GenerateViewId == null) { ViewManager.GenerateViewId += AllocateViewId; } NetLog.Info("Assigned to zone."); self = zone; if (OnAssignment != null) { OnAssignment(); } }
private void StartHandoff(NetView view, NetZone peer) { view.SendCreatorData(peer.Server); view.Server = peer.Server; foreach (NetConnection connection in view.Controllers) { if (connection.View == view) { connection.InternalScope = view.Scope; } } ViewManager.DestroyView(view); }
/// <summary> Creates a Zone at the specified position. </summary> public NetZone CreateZone(Vector3 position) { if (!CanAllocateIdBlock()) { throw new Exception("Cannot Create Zone: Unable to allocate ViewID block, limit has been reached."); } var newZone = new NetZone(position, GetViewIdMin(), GetViewIdMax()); zones.Add(newZone); AssignServers(); return(newZone); }
private void PeerConnected(NetConnection connection) { if (!peerLookup.ContainsKey(connection.Endpoint)) { return; } NetZone peer = peerLookup[connection.Endpoint]; NetLog.Info("Connection is Zone Peer: " + peer); peer.Server = connection; connection.InternalScope = new NetScope(); connection.InternalScope.Position = peer.Position; connection.InternalScope.OutScopeDist = (int)(peer.HandoverMaxDistance * 1.25); connection.InternalScope.InScopeDist = peer.HandoverMaxDistance; }
private void IncrementalHandoffCheck() { int pos = incHandoffFrame * handoffBatchSize; for (int i = pos; i < pos + handoffBatchSize; i++) { if (i >= ViewManager.Views.Count) { break; } NetView view = ViewManager.Views[i]; if (view.Server != Socket.Self) { continue; } float dist = Vector3.Distance(view.Scope.Position, self.Position); if (dist < self.HandoverDistance) { continue; } for (int j = 0; j < peers.Count; j++) { NetZone peer = peers[j]; float peerDist = Vector3.Distance(view.Scope.Position, peer.Position); if (peerDist > peer.HandoverMinDistance && (dist < self.HandoverMaxDistance || dist < peerDist)) { continue; } StartHandoff(view, peer); break; } } incHandoffFrame++; if (incHandoffFrame != (Application.targetFrameRate * 2)) { return; } incHandoffFrame = 0; handoffBatchSize = (ViewManager.Views.Count / (Application.targetFrameRate * 2)) + 1; }
internal void AddPeerSelf(NetZone zone) { if (peerLookup.ContainsKey(zone.ServerEndpoint)) { peerLookup.Remove(zone.ServerEndpoint); } peerLookup.Add(zone.ServerEndpoint, zone); if (peers.Contains(zone)) { peers.Remove(zone); } peers.Add(zone); if (Socket.EndpointConnected(zone.ServerEndpoint)) { PeerConnected(Socket.EndpointToConnection(zone.ServerEndpoint)); } }
internal void RemovePeerSelf(NetZone zone) { NetLog.Info("Removing zone"); if (peerLookup.ContainsKey(zone.ServerEndpoint)) { peerLookup.Remove(zone.ServerEndpoint); } else if (peerLookup.ContainsValue(zone)) { NetLog.Warning("RemovePeer: Zone endpoint mismatch."); } if (peers.Contains(zone)) { peers.Remove(zone); } else { NetLog.Info("RemovePeer: Zone not in peer list."); } }
/// <summary> Attempts to find a Zone for the provided position. </summary> public bool TryGetZone(Vector3 position, out NetZone zone) { NetZone closestZone = null; float closestDistance = float.MaxValue; foreach (NetZone z in zones) { if (!z.Assigned) continue; float distance = z.Distance(position); if (distance > z.HandoverMaxDistance) continue; if (distance > closestDistance) continue; closestZone = z; closestDistance = distance; } if (closestZone == null) { zone = null; return false; } zone = closestZone; return true; }
internal void ZoneAssigned(NetZone zone) { if (unassignedPeers.ContainsKey(zone.Server)) unassignedPeers.Remove(zone.Server); for (int i = 0; i < zones.Count; i++) { NetZone peerZone = zones[i]; if (zone == peerZone || peerZone.Server == null) continue; if (peerZone.Server == Socket.Self) GetComponent<NetZoneServer>().AddPeerSelf(zone); if (zone.Server != Socket.Self) Socket.Send("AddPeer", zone.Server, peerZone); if (peerZone.Server != Socket.Self) Socket.Send("AddPeer", peerZone.Server, zone); } }
internal void RemovePeerSelf(NetZone zone) { NetLog.Info("Removing zone"); if (peerLookup.ContainsKey(zone.ServerEndpoint)) peerLookup.Remove(zone.ServerEndpoint); else if (peerLookup.ContainsValue(zone)) NetLog.Warning("RemovePeer: Zone endpoint mismatch."); if (peers.Contains(zone)) peers.Remove(zone); else NetLog.Info("RemovePeer: Zone not in peer list."); }
private void StartHandoff(NetView view, NetZone peer) { view.SendCreatorData(peer.Server); view.Server = peer.Server; foreach (NetConnection connection in view.Controllers) { if (connection.View == view) connection.InternalScope = view.Scope; } ViewManager.DestroyView(view); }
private string AssignZone(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) return ""; AssignZoneSelf(zone); return Socket.Address; }
private void AddPeer(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) return; AddPeerSelf(zone); if (!Socket.EndpointConnected(zone.ServerEndpoint)) Socket.ConnectToPeer(zone.ServerEndpoint); }
private void RemovePeer(NetZone zone, NetConnection connection) { if (!connection.IsPeer && !connection.IsServer) return; RemovePeerSelf(zone); }