コード例 #1
0
        //A true return signals that the server is up and running
        public bool InitializeServer()
        {
            NewPlayerList = new List <string>();
            NewDataList   = new List <DataPacket>();
            DcdPlayerList = new List <string>();

            PrivateServer = new Microsoft.DirectX.DirectPlay.Server();
            bool setupSuccess = true;

            // Check to see if we can create a TCP/IP connection
            if (!IsServiceProviderValid(Address.ServiceProviderTcpIp))
            {
                setupSuccess = false;
            }
            else
            {
                // Create a new address for our local machine
                Address deviceAddress = new Address();
                deviceAddress.ServiceProvider = Address.ServiceProviderTcpIp;
                deviceAddress.AddComponent(Address.KeyPort, ServerInfo.DataPort);

                // Set up an application description
                ApplicationDescription desc = new ApplicationDescription();
                desc.SessionName     = "MDX Book Server Session";
                desc.GuidApplication = ServerInfo.ApplicationGuid;
                desc.Flags           = SessionFlags.ClientServer | SessionFlags.NoDpnServer;

                try
                {
                    // Host a new session on the Server
                    PrivateServer.Host(desc, deviceAddress);
                }
                catch
                {
                    setupSuccess = false;
                }
            }

            //Attach all handlers
            PrivateServer.PlayerCreated   += new PlayerCreatedEventHandler(OnPlayerCreated);
            PrivateServer.PlayerDestroyed += new PlayerDestroyedEventHandler(OnPlayerDestroyed);
            PrivateServer.Receive         += new ReceiveEventHandler(OnDataReceive);

            return(setupSuccess);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: timdetering/AirplaneWar
        protected void StartServer()
        {
            // create a direct play server connection
            dps = new DPlay.Server();
            DPlay.ApplicationDescription appdesc = new DPlay.ApplicationDescription();
            appdesc.GuidApplication = new Guid("B32DD425-DB33-4f9c-972F-C68269C409F6");
            appdesc.MaxPlayers      = 0;
            appdesc.SessionName     = "AWarServer";
            appdesc.Flags           = DPlay.SessionFlags.ClientServer | DPlay.SessionFlags.NoDpnServer;

            DPlay.Address dpa = new DPlay.Address("192.168.1.5", 895);

            // Add our event handlers
            //		dps.PlayerDestroyed += new PlayerDestroyedEventHandler(this.DestroyPlayerMsg);
            //		dps.Receive += new DPlay.ReceiveEventHandler(this.Receive);

            //		dps.Receive+=new DPlay.ReceiveEventHandler(this.Receive);
            //		dps.IndicateConnect+=new DPlay.IndicateConnectEventHandler(this.ConnectComplete);

            dps.Receive += new DPlay.ReceiveEventHandler(this.DataReceivedMsg);

            dps.Host(appdesc, dpa);
        }