예제 #1
0
        /// <summary>
        ///     Connect to a network game (connect to the game's P2P server).
        /// </summary>
        /// <param name="p2pServerEndPoint">Pass null to delay connection and use side-channel verification</param>
        public void ConnectToGame(INetworkApplication networkApplication, string playerName, byte[] playerData,
                                  IPEndPoint p2pServerEndPoint,
                                  ulong sideChannelId, int sideChannelToken)
        {
            if (networkApplication == null)
            {
                throw new ArgumentNullException("networkApplication");
            }

            if (peerManager != null)
            {
                throw new InvalidOperationException("Already running");
            }

            LocalisedDisconnectReason = null;

            NetworkApplication = networkApplication;
            var p2pClient = new P2PClient(this, playerName, playerData, sideChannelId, sideChannelToken);

            if (p2pServerEndPoint != null)
            {
                p2pClient.ConnectImmediate(p2pServerEndPoint);
            }
            peerManager = p2pClient;
        }