Пример #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;
        }
Пример #2
0
        /// <summary>
        /// Start a network game (as the P2P server).
        /// </summary>
        /// <param name="gameName">The user-visible name of the game.</param>
        /// <param name="respondToDiscovery">Set to true if on LAN, otherwise don't care.</param>
        /// <param name="openToInternet">Set to false if on LAN, true if on Internet.</param>
        public void StartGame(INetworkApplication networkApplication, string playerName, byte[] playerData, string gameName, bool openToInternet,
                              bool sideChannelAuth, ulong sideChannelId)
        {
            if (networkApplication == null)
            {
                throw new ArgumentNullException("networkApplication");
            }

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

            LocalisedDisconnectReason = null;

            this.NetworkApplication = networkApplication;
            peerManager             = new P2PServer(this, playerName, playerData, gameName, openToInternet, sideChannelAuth, sideChannelId);

            networkApplication.StartOnServer();
        }