Connect() public method

public Connect ( string serverAddress, ServerConnection, type ) : bool
serverAddress string
type ServerConnection,
return bool
Example #1
0
 public static bool ConnectUsingSettings(string gameVersion)
 {
     if (PhotonServerSettings == null)
     {
         Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: PhotonServerSettings");
         return(false);
     }
     SwitchToProtocol(PhotonServerSettings.Protocol);
     networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
     {
         offlineMode = true;
         return(true);
     }
     if (offlineMode)
     {
         Debug.LogWarning("ConnectUsingSettings() disabled the offline mode. No longer offline.");
     }
     offlineMode                     = false;
     isMessageQueueRunning           = true;
     networkingPeer.IsInitialConnect = true;
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.SelfHosted)
     {
         networkingPeer.IsUsingNameServer   = false;
         networkingPeer.MasterServerAddress = PhotonServerSettings.ServerAddress + ":" + PhotonServerSettings.ServerPort;
         return(networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer));
     }
     if (PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
     {
         return(ConnectToBestCloudServer(gameVersion));
     }
     return(networkingPeer.ConnectToRegionMaster(PhotonServerSettings.PreferredRegion));
 }
Example #2
0
    public static bool ConnectToMaster(string masterServerAddress, int port, string appID, string gameVersion)
    {
        string url = string.Empty;

        if (networkingPeer.TransportProtocol >= ConnectionProtocol.WebSocket)
        {
            url = "ws";
            if (networkingPeer.UsedProtocol == ConnectionProtocol.WebSocketSecure)
            {
                url += "s";
            }
            url += "://";
        }
        masterServerAddress = url + masterServerAddress;
        if (networkingPeer.PeerState != PeerStateValue.Disconnected)
        {
            Debug.LogWarning("ConnectToMaster() failed. Can only connect while in state 'Disconnected'. Current state: " + networkingPeer.PeerState);
            return(false);
        }
        if (offlineMode)
        {
            offlineMode = false;
            Debug.LogWarning("ConnectToMaster() disabled the offline mode. No longer offline.");
        }
        if (!isMessageQueueRunning)
        {
            isMessageQueueRunning = true;
            Debug.LogWarning("ConnectToMaster() enabled isMessageQueueRunning. Needs to be able to dispatch incoming messages.");
        }
        networkingPeer.SetApp(appID, gameVersion);
        networkingPeer.IsUsingNameServer   = false;
        networkingPeer.IsInitialConnect    = true;
        networkingPeer.MasterServerAddress = masterServerAddress + ":" + port;
        return(networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer));
    }
    public static bool ConnectToMaster(string masterServerAddress, int port, string appID, string gameVersion)
    {
        //PhotonNetwork.SwitchToProtocol((ExitGames.Client.Photon.ConnectionProtocol) PlayerPrefs.GetInt("TCPProtocol", (int)ExitGames.Client.Photon.ConnectionProtocol.WebSocket));

        if (networkingPeer.PeerState != PeerStateValue.Disconnected)
        {
            Debug.LogWarning("ConnectToMaster() failed. Can only connect while in state 'Disconnected'. Current state: " + networkingPeer.PeerState);
            return(false);
        }
        if (offlineMode)
        {
            offlineMode = false;
            Debug.LogWarning("ConnectToMaster() disabled the offline mode. No longer offline.");
        }
        if (!isMessageQueueRunning)
        {
            isMessageQueueRunning = true;
            Debug.LogWarning("ConnectToMaster() enabled isMessageQueueRunning. Needs to be able to dispatch incoming messages.");
        }
        networkingPeer.SetApp(appID, gameVersion);
        networkingPeer.IsUsingNameServer   = false;
        networkingPeer.IsInitialConnect    = true;
        networkingPeer.MasterServerAddress = masterServerAddress + ":" + port;
        return(networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer));
    }
Example #4
0
    /// <summary>
    /// Connect to the photon server
    /// </summary>
    /// <param name="serverAddress"></param>
    /// <param name="port"></param>
    /// <param name="uniqueGameID"></param>
    public static void Connect(string serverAddress, int port, string uniqueGameID)
    {
        if (port <= 0)
        {
            Debug.LogError("Aborted Connect: invalid port: " + port);
            return;
        }

        if (serverAddress.Length <= 2)
        {
            Debug.LogError("Aborted Connect: invalid serverAddress: " + serverAddress);
            return;
        }

        if (networkingPeer.PeerState != PeerStateValue.Disconnected)
        {
            Debug.LogWarning("Connect() only works when disconnected. Current state: " + networkingPeer.PeerState);
            return;
        }

        if (offlineMode)
        {
            offlineMode = false; // Cleanup offline mode
            Debug.LogWarning("Shut down offline mode due to a connect attempt");
        }

        if (!isMessageQueueRunning)
        {
            isMessageQueueRunning = true;
            Debug.LogWarning("Forced enabling of isMessageQueueRunning because of a Connect()");
        }

        serverAddress = serverAddress + ":" + port;

        //Debug.Log("Connecting to: " + serverAddress + " app: " + uniqueGameID);
        networkingPeer.Connect(serverAddress, uniqueGameID, 0);
    }