public async Task <ConnectionStatus> Connect(IYield yield, ICoroutinesExecutor coroutinesExecutor, ServerConnectionInformation serverConnectionInformation)
        {
            var serverType = serverConnectionInformation.ServerType;

            if (IsConnected())
            {
                throw new ServerConnectionFailed($"A connection already exists with a {serverType} server.");
            }

            ConnectionInformation = serverConnectionInformation;

            var ip   = ConnectionInformation.PeerConnectionInformation.Ip;
            var port = ConnectionInformation.PeerConnectionInformation.Port;

            LogUtils.Log($"Connecting to a {serverType} server. IP: {ip} Port: {port}");

            var serverConnector      = new PhotonServerConnector(() => coroutinesExecutor);
            var networkConfiguration = NetworkConfiguration.GetInstance();
            var connectionDetails    = new ConnectionDetails(networkConfiguration.ConnectionProtocol, networkConfiguration.DebugLevel);

            ServerPeer = await serverConnector.ConnectAsync(yield, ConnectionInformation.PeerConnectionInformation, connectionDetails);

            if (ServerPeer == null)
            {
                return(ConnectionStatus.Failed);
            }

            SubscribeToDisconnectionNotifier();

            LogUtils.Log($"A {serverType} server has been connected: {ip}:{port}");

            serviceConnectionNotifier.Connection();
            return(ConnectionStatus.Succeed);
        }
        protected override void Setup()
        {
            LogUtils.Logger = CreateLogger();
            Config.Global   = CreateJsonConfiguration();

            var photonFiberProvider = new PhotonFiberProvider();
            var serverConnector     = new PhotonServerConnector(this, ApplicationName);

            application = CreateApplication(photonFiberProvider, serverConnector);
            application.Startup();
        }
示例#3
0
 public static PhotonServerConnector GetServerConnector()
 {
     if (m_photonServerConnector == null)
     {
         m_photonServerConnector = GameObject.FindObjectOfType <PhotonServerConnector>();
     }
     if (!m_photonServerConnector)
     {
         return(null);
     }
     return(m_photonServerConnector);
 }