public LidgrenPunchThroughFacilitator(LidgrenNetworkTransporter transporter, ICoroutineScheduler coroutineScheduler, LidgrenNatPunchClient natPunchClient, float connectionAttemptTimeout, ConnectionIdPool connectionIdPool) { _connectionIdPool = connectionIdPool; _connectionRegistrationPool = new ObjectPool <ConnectionRegistration>(() => new ConnectionRegistration()); _punchAttempts = new Dictionary <NatPunchId, IPooledObject <ConnectionRegistration> >(); _connectionAttempts = new ArrayDictionary <ConnectionId, IPooledObject <ConnectionRegistration> >( connectionIdPool.MaxConnectionIds); _activeConnections = new ArrayDictionary <ConnectionId, IPooledObject <ConnectionRegistration> >( connectionIdPool.MaxConnectionIds); _cancelledAttempts = new ConnectionId[_connectionIdPool.MaxConnectionIds]; for (int i = 0; i < _cancelledAttempts.Length; i++) { _cancelledAttempts[i] = ConnectionId.NoConnection; } _transporter = transporter; _connectionAttemptTimeout = connectionAttemptTimeout; _connectionIdPool = connectionIdPool; _natPunchClient = natPunchClient; _transporter.RequestApproval += PassRequestApproval; _transporter.OnConnectionOpened += OnConnectionOpened; _transporter.OnConnectionClosed += OnConnectionClosed; _cleanupRoutine = coroutineScheduler.Run(PunchTimeoutCleanup()); }
public void JoinServer(IPEndPoint endPoint, int clientPort = -1, OnConnectionEstablished onEstablished = null, OnConnectionFailure onFailure = null, OnDisconnected onDisconnected = null) { Shutdown(); _isJoinInProgress = true; _isSingleplayer = false; _coroutineScheduler.Run(_networkClient.Join(endPoint, clientPort, (connectionId, endpoint) => { _authorityConnectionId = connectionId; _isJoinInProgress = false; if (onEstablished != null) { onEstablished(connectionId, endPoint); } }, onFailure, onDisconnected)); }
public IAwaitable Transition(StateId stateId, params object[] args) { if (_isTransitioning) { UnityEngine.Debug.LogWarning("Cannot transition to " + stateId + " while another transition is already active."); return(EmptyAwaitable.Default); } StateInstance newState = _states[stateId]; if (_stack.Count == 0) { return(_scheduler.Run(EnterNewState(newState, args))); } else { StateInstance oldState = _stack.Peek(); var isNormalTransition = oldState.Transitions.Contains(stateId); var isChildTransition = oldState.ChildTransitions.Contains(stateId); if (isNormalTransition) { return(_scheduler.Run(Transition(newState, args))); } else if (isChildTransition) { return(_scheduler.Run(TransitionToChild(oldState, newState, args))); } else { throw new Exception(string.Format( "Transition from state '{0}' to state '{1}' is not registered, transition failed", oldState.StateId, stateId)); } } }
public LidgrenNatPunchClient(ICoroutineScheduler coroutineScheduler, LidgrenNatFacilitatorConnection facilitatorConnection, IConnectionlessTransporter transporter) { _tempBuffer = new NetBuffer(); _transporter = transporter; _facilitatorConnection = facilitatorConnection; _natPunchAttempts = new Dictionary <NatPunchId, PunchAttempt>(); _natPunchRegistrations = new List <PunchAttempt>(); // _natPunchSessionCache = new RamjetCache<IPEndPoint, IPEndPoint>( // expireAfterAccess: _punchSessionCacheTimeout, expireAfterWrite: null); _facilitatorConnection.OnNatPunchSuccess += OnNatPunchSuccess; _facilitatorConnection.OnNatPunchFailure += OnNatPunchFailure; _cleanupRoutine = coroutineScheduler.Run(ConnectionTimeoutCleanup()); }
public LidgrenPunchThroughFacilitator(LidgrenNetworkTransporter transporter, ICoroutineScheduler coroutineScheduler, LidgrenNatPunchClient natPunchClient, float connectionAttemptTimeout) { _punchAttempts = new Dictionary <NatPunchId, ConnectionRegistration>(); _connectionAttempts = new Dictionary <ConnectionId, ConnectionRegistration>(); _connectionAttemptRegistrations = new List <ConnectionRegistration>(); _connections = new Dictionary <ConnectionId, ConnectionRegistration>(); _transporter = transporter; _connectionAttemptTimeout = connectionAttemptTimeout; _natPunchClient = natPunchClient; _transporter.OnConnectionOpened += OnConnectionOpened; _transporter.OnConnectionClosed += OnConnectionClosed; _cleanupRoutine = coroutineScheduler.Run(ConnectionTimeoutCleanup()); }
public LidgrenNatPunchClient(ICoroutineScheduler coroutineScheduler, LidgrenNatFacilitatorConnection facilitatorConnection) { _facilitatorConnection = facilitatorConnection; _punchAttemptPool = new ObjectPool <PunchAttempt>(() => new PunchAttempt()); { const int natpunchIdCount = 256; var punchIds = new NatPunchId[natpunchIdCount]; for (int i = 0; i < natpunchIdCount; i++) { punchIds[i] = new NatPunchId(Guid.NewGuid().ToString()); } _natPunchIds = CollectionUtil.LoopingEnumerator(punchIds); } _natPunchAttempts = new Dictionary <NatPunchId, IPooledObject <PunchAttempt> >(); _natPunchRegistrations = new List <IPooledObject <PunchAttempt> >(); _facilitatorConnection.OnNatPunchSuccess += OnNatPunchSuccess; _facilitatorConnection.OnNatPunchFailure += OnNatPunchFailure; _cleanupRoutine = coroutineScheduler.Run(ConnectionTimeoutCleanup()); }