示例#1
0
    public PlayClass(GameClass Game)
    {
        this.game = Game;

        //Initialize our peer to peer network object
        peerObject = new Peer();


        // Set up our event handlers (We only need events for the ones we care about)
        peerObject.PlayerCreated     += new PlayerCreatedEventHandler(PlayerCreated);
        peerObject.PlayerDestroyed   += new PlayerDestroyedEventHandler(PlayerDestroyed);
        peerObject.Receive           += new ReceiveEventHandler(game.DataReceived);
        peerObject.SessionTerminated += new SessionTerminatedEventHandler(SessionTerminated);

        // use the DirectPlay connection wizard to create our join sessions
        Connect = new ConnectWizard(peerObject, AppGuid, "Spacewar3D");
        Connect.StartWizard();

        inSession = Connect.InSession;

        if (inSession)
        {
            isHost = Connect.IsHost;
        }
    }
示例#2
0
文件: wfChat.cs 项目: sjk7/DX90SDK
        /// <summary>
        /// Constuctor
        /// </summary>
        public ChatPeer()
        {
            try
            {
                // Load the icon from our resources
                System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
                this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            }
            catch
            {
                // It's no big deal if we can't load our icons, but try to load the embedded one
                try { this.Icon = new System.Drawing.Icon(this.GetType(), "directx.ico"); }
                catch {}
            }

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            peerObject = new Peer();
            // First set up our event handlers (We only need events for the ones we care about)
            peerObject.PlayerCreated     += new PlayerCreatedEventHandler(this.PlayerCreated);
            peerObject.PlayerDestroyed   += new PlayerDestroyedEventHandler(this.PlayerDestroyed);
            peerObject.HostMigrated      += new HostMigratedEventHandler(this.HostMigrated);
            peerObject.Receive           += new ReceiveEventHandler(this.DataReceived);
            peerObject.SessionTerminated += new SessionTerminatedEventHandler(this.SessionTerminated);
            connectWizard = new ConnectWizard(peerObject, localApplicationGuid, "Chat Peer");

            connectWizard.DefaultPort = DefaultPort;
            if (connectWizard.StartWizard())
            {
                // Great we've connected (or joined)..  Now we can start the sample
                // Are we the host?
                if (connectWizard.IsHost)
                {
                    this.Text += " (HOST)";
                }
            }
            else
            {
                // We obviously didn't want to start a session
                this.Dispose();
            }
        }
    public PlayClass(GameClass parent)
    {
        this.parent = parent;
        this.peerObject = peerObject;
        this.message = new MessageDelegate(parent.MessageArrived);

        peerObject = new Peer();
        // First set up our event handlers (We only need events for the ones we care about)
        peerObject.PlayerCreated += new PlayerCreatedEventHandler(this.PlayerCreated);
        peerObject.PlayerDestroyed += new PlayerDestroyedEventHandler(this.PlayerDestroyed);
        peerObject.HostMigrated += new HostMigratedEventHandler(this.HostMigrated);
        peerObject.Receive += new ReceiveEventHandler(this.DataReceived);
        peerObject.SessionTerminated += new SessionTerminatedEventHandler(this.SessionTerminated);

        Connect = new ConnectWizard(peerObject, AppGuid, "Step2");
        if (!Connect.StartWizard()) {
            MessageBox.Show("DirectPlay initialization was incomplete. Application will terminate.");
            throw new DirectXException();
        }
    }
    public PlayClass(GameClass parent)
    {
        this.parent     = parent;
        this.peerObject = peerObject;
        this.message    = new MessageDelegate(parent.MessageArrived);

        peerObject = new Peer();
        // First set up our event handlers (We only need events for the ones we care about)
        peerObject.PlayerCreated     += new PlayerCreatedEventHandler(this.PlayerCreated);
        peerObject.PlayerDestroyed   += new PlayerDestroyedEventHandler(this.PlayerDestroyed);
        peerObject.HostMigrated      += new HostMigratedEventHandler(this.HostMigrated);
        peerObject.Receive           += new ReceiveEventHandler(this.DataReceived);
        peerObject.SessionTerminated += new SessionTerminatedEventHandler(this.SessionTerminated);

        Connect = new ConnectWizard(peerObject, AppGuid, "Step2");
        if (!Connect.StartWizard())
        {
            MessageBox.Show("DirectPlay initialization was incomplete. Application will terminate.");
            throw new DirectXException();
        }
    }
    public PlayClass(GameClass Game)
    {
        this.game = Game;

        //Initialize our peer to peer network object
        peerObject = new Peer();

        // Set up our event handlers (We only need events for the ones we care about)
        peerObject.PlayerCreated += new PlayerCreatedEventHandler(PlayerCreated);
        peerObject.PlayerDestroyed += new PlayerDestroyedEventHandler(PlayerDestroyed);
        peerObject.Receive += new ReceiveEventHandler(game.DataReceived);
        peerObject.SessionTerminated += new SessionTerminatedEventHandler(SessionTerminated);

        // use the DirectPlay connection wizard to create our join sessions
        Connect = new ConnectWizard(peerObject, AppGuid, "Spacewar3D");
        Connect.StartWizard();

        inSession = Connect.InSession;

        if (inSession) {
            isHost = Connect.IsHost;
        }
    }
示例#6
0
        public NETPlayer(GameWorld gameworld)
        {
            //
            // TODO: Add constructor logic here
            //
            game       = gameworld;
            peerObject = new Peer();

            peerObject.PlayerCreated     += new PlayerCreatedEventHandler(game.PlayerCreated);
            peerObject.PlayerDestroyed   += new PlayerDestroyedEventHandler(game.PlayerDestroyed);
            peerObject.Receive           += new ReceiveEventHandler(game.DataReceived);
            peerObject.SessionTerminated += new SessionTerminatedEventHandler(SessionTerminated);

            Connect = new ConnectWizard(peerObject, AppGuid, "Helikopter");
            Connect.StartWizard();

            inSession = Connect.InSession;

            if (inSession)
            {
                isHost = Connect.IsHost;
            }
        }
示例#7
0
        /// <summary>
        /// Constructor
        /// </summary>
        public VoiceConnect()
        {
            InitializeComponent();

            try
            {
                //set up state members
                playerList = new ArrayList();

                //create the peer
                peerObject = new Peer();

                //create the voice client and attach message handlers
                client = new Voice.Client(peerObject);
                client.HostMigrated  += new Voice.VoiceHostMigratedEventHandler(VoiceHostMigrated);
                client.PlayerCreated += new Voice.VoicePlayerCreatedEventHandler(VoicePlayerCreated);
                client.PlayerDeleted += new Voice.VoicePlayerDeletedEventHandler(VoicePlayerDeleted);
                client.SessionLost   += new Voice.SessionLostEventHandler(VoiceSessionLost);
                client.PlayerStarted += new Voice.PlayerStartedEventHandler(PlayerStarted);
                client.PlayerStopped += new Voice.PlayerStoppedEventHandler(PlayerStopped);
                client.RecordStarted += new Voice.RecordStartedEventHandler(RecordStarted);
                client.RecordStopped += new Voice.RecordStoppedEventHandler(RecordStopped);


                //session was not lobby launched -- using connection wizard
                playWizard             = new ConnectWizard(peerObject, g_guidApp, "VoiceConnect");
                playWizard.DefaultPort = DefaultPort;

                //create the voice wizard
                voiceSettings = new VoiceWizard();

                if (playWizard.StartWizard())
                {
                    if (playWizard.IsHost)
                    {
                        this.Text += " (HOST)";

                        //create the voice server
                        server = new Voice.Server(peerObject);

                        //init the voice server
                        voiceSettings.InitVoiceHost(peerObject, server, client, this);
                    }
                    else
                    {
                        //connection to another host was successful
                        voiceSettings.InitVoiceClient(peerObject, client, this);
                    }
                }
                else
                {
                    this.Dispose();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                //allow exception to fall though and exit.
                this.Close();
            }
        }
        /*public void Host(string sessionName)
        {
            Address hostAddress = new Address();
            hostAddress.ServiceProvider = Address.ServiceProviderTcpIp;
            // Select TCP/IP service provider

            ApplicationDescription dpApp = new ApplicationDescription();
            dpApp.Flags = SessionFlags.FastSigned;
            dpApp.GuidApplication = Guid.NewGuid();     // Set the application GUID
            dpApp.SessionName = sessionName;            // Optional Session Name

            peer.Host(dpApp, hostAddress, HostFlags.OkToQueryForAddressing);
        }*/
        public bool DoWizzard()
        {
            ConnectWizard connectWizard = new ConnectWizard(peer, new Guid("ED48D6E8-91D1-4cf6-9ED3-CB427F76F17D"), "Tglrf");
            connectWizard.DefaultPort = 10293;
            return connectWizard.StartWizard();
        }