예제 #1
0
        public void Reopen(SessionMode sessionMode, int maximumNumberOfLobbyMembers = 16)
        {
            if (!this.opened)
            {
                Diagnostics.LogWarning("The session is not opened, therefore it cannot be reopened. Please consider calling 'Open' instead.");
                return;
            }
            if (!this.hosting)
            {
                Diagnostics.LogWarning("Only the host is supposed to reopen its own session.");
                return;
            }
            Diagnostics.Log("Changing session mode from '{0}' to '{1}'...", new object[]
            {
                this.SessionMode,
                sessionMode
            });
            if (sessionMode != this.SessionMode)
            {
                this.opened    = false;
                this.opening   = true;
                this.reopening = true;
                this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Reopening, this));
                SessionMode sessionMode2 = this.SessionMode;
                this.SessionMode = sessionMode;
                this.SetLobbyData("SessionMode", sessionMode.ToString(), true);
                this.SetLobbyData("Owner", this.SteamIDUser, true);
                switch (this.SessionMode)
                {
                case SessionMode.Single:
                    if (this.SteamMatchMakingService != null)
                    {
                        this.SteamMatchMakingService.SteamLobbyChatMsg     -= this.SteamMatchMakingService_SteamLobbyChatMsg;
                        this.SteamMatchMakingService.SteamLobbyChatUpdate  -= this.SteamMatchMakingService_SteamLobbyChatUpdate;
                        this.SteamMatchMakingService.SteamLobbyDataUpdate  -= this.SteamMatchMakingService_SteamLobbyDataUpdate;
                        this.SteamMatchMakingService.SteamLobbyEnter       -= this.SteamMatchMakingService_SteamLobbyEnter;
                        this.SteamMatchMakingService.SteamLobbyGameCreated -= this.SteamMatchMakingService_SteamLobbyGameCreated;
                        this.SteamMatchMakingService.SteamLobbyInvite      -= this.SteamMatchMakingService_SteamLobbyInvite;
                        this.SteamMatchMakingService.SteamLobbyKicked      -= this.SteamMatchMakingService_SteamLobbyKicked;
                        ISteamClientService service = Services.GetService <ISteamClientService>();
                        Diagnostics.Assert(service != null);
                        service.ClientSteamServersDisconnected  -= this.ISteamClientService_ClientSteamServersDisconnected;
                        service.ClientSteamServerConnectFailure -= this.ISteamClientService_ClientSteamServerConnectFailure;
                        service.ClientP2PSessionConnectFail     -= this.ISteamClientService_ClientP2PSessionConnectFail;
                        if (this.SteamIDLobby != null)
                        {
                            this.SteamMatchMakingService.SteamMatchMaking.LeaveLobby(this.SteamIDLobby);
                            this.SteamIDLobby = null;
                        }
                    }
                    this.opened    = true;
                    this.opening   = false;
                    this.reopening = false;
                    this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Reopened, this));
                    break;

                case SessionMode.Private:
                case SessionMode.Protected:
                case SessionMode.Public:
                    if (sessionMode2 == SessionMode.Single)
                    {
                        this.SteamMatchMakingService = Services.GetService <ISteamMatchMakingService>();
                        if (this.SteamMatchMakingService == null)
                        {
                            throw new InvalidOperationException("Cannot find the steam match making service.");
                        }
                        if (maximumNumberOfLobbyMembers < 1)
                        {
                            throw new ArgumentOutOfRangeException("The maximum number of lobby members should be greater that zero.");
                        }
                        this.MaximumNumberOfLobbyMembers = maximumNumberOfLobbyMembers;
                        this.SteamMatchMakingService.SteamLobbyChatMsg     += this.SteamMatchMakingService_SteamLobbyChatMsg;
                        this.SteamMatchMakingService.SteamLobbyChatUpdate  += this.SteamMatchMakingService_SteamLobbyChatUpdate;
                        this.SteamMatchMakingService.SteamLobbyDataUpdate  += this.SteamMatchMakingService_SteamLobbyDataUpdate;
                        this.SteamMatchMakingService.SteamLobbyEnter       += this.SteamMatchMakingService_SteamLobbyEnter;
                        this.SteamMatchMakingService.SteamLobbyGameCreated += this.SteamMatchMakingService_SteamLobbyGameCreated;
                        this.SteamMatchMakingService.SteamLobbyInvite      += this.SteamMatchMakingService_SteamLobbyInvite;
                        this.SteamMatchMakingService.SteamLobbyKicked      += this.SteamMatchMakingService_SteamLobbyKicked;
                        ISteamClientService service2 = Services.GetService <ISteamClientService>();
                        Diagnostics.Assert(service2 != null);
                        service2.ClientSteamServersDisconnected  += this.ISteamClientService_ClientSteamServersDisconnected;
                        service2.ClientSteamServerConnectFailure += this.ISteamClientService_ClientSteamServerConnectFailure;
                        service2.ClientP2PSessionConnectFail     += this.ISteamClientService_ClientP2PSessionConnectFail;
                        Steamworks.SteamMatchMaking.ELobbyType lobbyType = this.SessionMode.ToSteamMatchMakingLobbyType();
                        ulong steamAPICall = this.SteamMatchMakingService.SteamMatchMaking.CreateLobby(lobbyType, 1);
                        if (Session.lobbyCreatedCallback != null)
                        {
                            Session.lobbyCreatedCallback = null;
                            if (this.lobbyCreatedCallResult != null)
                            {
                                this.lobbyCreatedCallResult.Dispose();
                                this.lobbyCreatedCallResult = null;
                            }
                        }
                        Session.lobbyCreatedCallback = new Steamworks.LobbyCreatedCallback(this.Steamworks_LobbyCreated);
                        this.lobbyCreatedCallResult  = new Steamworks.CallResult(Steamworks.SteamAPI_RegisterLobbyCreatedDelegate(steamAPICall, Session.lobbyCreatedCallback));
                    }
                    else
                    {
                        this.SteamMatchMakingService.SteamMatchMaking.SetLobbyType(this.SteamIDLobby, this.SessionMode.ToSteamMatchMakingLobbyType());
                        if (this.MaximumNumberOfLobbyMembers > 1)
                        {
                            this.SteamMatchMakingService.SteamMatchMaking.SetLobbyMemberLimit(this.SteamIDLobby, this.MaximumNumberOfLobbyMembers);
                        }
                        this.opened    = true;
                        this.opening   = false;
                        this.reopening = false;
                        this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Reopened, this));
                    }
                    break;
                }
            }
        }
예제 #2
0
        public static void Main()
        {
            // <Snippet0>
            Uri         baseAddress = new Uri("http://localhost:8001/Simple");
            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            serviceHost.AddServiceEndpoint(
                typeof(ICalculator),
                new WSHttpBinding(),
                "CalculatorServiceObject");

            // Enable Mex
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

            smb.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(smb);

            serviceHost.Open();

            // <Snippet1>
            ContractDescription cd0 = new ContractDescription("ICalculator");
            // </Snippet1>
            // <Snippet2>
            ContractDescription cd1 = new ContractDescription("ICalculator", "http://www.tempuri.org");
            // </Snippet2>
            // <Snippet13>
            ContractDescription cd2 = ContractDescription.GetContract(typeof(ICalculator));
            // </Snippet13>
            // <Snippet14>
            CalculatorService   calcSvc = new CalculatorService();
            ContractDescription cd3     = ContractDescription.GetContract(typeof(ICalculator), calcSvc);
            // </Snippet14>
            // <Snippet15>
            ContractDescription cd4 = ContractDescription.GetContract(typeof(ICalculator), typeof(CalculatorService));
            // </Snippet15>
            ContractDescription cd = serviceHost.Description.Endpoints[0].Contract;

            Console.WriteLine("Displaying information for contract: {0}", cd.Name.ToString());

            // <Snippet3>
            KeyedByTypeCollection <IContractBehavior> behaviors = cd.Behaviors;

            Console.WriteLine("\tDisplay all behaviors:");
            foreach (IContractBehavior behavior in behaviors)
            {
                Console.WriteLine("\t\t" + behavior.ToString());
            }
            // </Snippet3>

            // <Snippet4>
            Type type = cd.CallbackContractType;
            // </Snippet4>

            // <Snippet5>
            string configName = cd.ConfigurationName;

            Console.WriteLine("\tConfiguration name: {0}", configName);
            // </Snippet5>

            // <Snippet6>
            Type contractType = cd.ContractType;

            Console.WriteLine("\tContract type: {0}", contractType.ToString());
            // </Snippet6>

            // <Snippet7>
            bool hasProtectionLevel = cd.HasProtectionLevel;

            if (hasProtectionLevel)
            {
                // <Snippet11>
                ProtectionLevel protectionLevel = cd.ProtectionLevel;
                Console.WriteLine("\tProtection Level: {0}", protectionLevel.ToString());
                // </Snippet11>
            }
            // </Snippet7>


            // <Snippet8>
            string name = cd.Name;

            Console.WriteLine("\tName: {0}", name);
            // </Snippet8>

            // <Snippet9>
            string namespc = cd.Namespace;

            Console.WriteLine("\tNamespace: {0}", namespc);
            // </Snippet9>

            // <Snippet10>
            OperationDescriptionCollection odc = cd.Operations;

            Console.WriteLine("\tDisplay Operations:");
            foreach (OperationDescription od in odc)
            {
                Console.WriteLine("\t\t" + od.Name);
            }
            // </Snippet10>

            // <Snippet12>
            SessionMode sm = cd.SessionMode;

            Console.WriteLine("\tSessionMode: {0}", sm.ToString());
            // </Snippet12>

            // <Snippet16>
            Collection <ContractDescription> inheretedContracts = cd.GetInheritedContracts();

            Console.WriteLine("\tInherited Contracts:");
            foreach (ContractDescription contractdescription in inheretedContracts)
            {
                Console.WriteLine("\t\t" + contractdescription.Name);
            }
            // </Snippet16>

            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            serviceHost.Close();
            // </Snippet0>
        }
예제 #3
0
        public void Open(SessionMode sessionMode, int maximumNumberOfLobbyMembers = 16)
        {
            if (this.opened)
            {
                throw new InvalidOperationException("The session is already opened; consider closing it first or calling 'Reopen' instead.");
            }
            this.opening     = true;
            this.reopening   = false;
            this.hosting     = true;
            this.SessionMode = sessionMode;
            this.SetLobbyData("SessionMode", sessionMode.ToString(), true);
            this.SetLobbyData("Owner", this.SteamIDUser, true);
            this.SetLobbyData("Version", Amplitude.Unity.Framework.Application.Version.ToLong(), true);
            this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Opening, this));
            switch (this.SessionMode)
            {
            case SessionMode.Single:
                this.opened    = true;
                this.opening   = false;
                this.reopening = false;
                this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Opened, this));
                break;

            case SessionMode.Private:
            case SessionMode.Protected:
            case SessionMode.Public:
            {
                if (maximumNumberOfLobbyMembers < 1)
                {
                    throw new ArgumentOutOfRangeException("The maximum number of lobby members should be greater that zero.");
                }
                this.MaximumNumberOfLobbyMembers = maximumNumberOfLobbyMembers;
                this.SteamMatchMakingService     = Services.GetService <ISteamMatchMakingService>();
                if (this.SteamMatchMakingService == null)
                {
                    throw new InvalidOperationException("Cannot find the steam match making service.");
                }
                this.SteamMatchMakingService.SteamLobbyChatMsg     += this.SteamMatchMakingService_SteamLobbyChatMsg;
                this.SteamMatchMakingService.SteamLobbyChatUpdate  += this.SteamMatchMakingService_SteamLobbyChatUpdate;
                this.SteamMatchMakingService.SteamLobbyDataUpdate  += this.SteamMatchMakingService_SteamLobbyDataUpdate;
                this.SteamMatchMakingService.SteamLobbyEnter       += this.SteamMatchMakingService_SteamLobbyEnter;
                this.SteamMatchMakingService.SteamLobbyGameCreated += this.SteamMatchMakingService_SteamLobbyGameCreated;
                this.SteamMatchMakingService.SteamLobbyInvite      += this.SteamMatchMakingService_SteamLobbyInvite;
                this.SteamMatchMakingService.SteamLobbyKicked      += this.SteamMatchMakingService_SteamLobbyKicked;
                ISteamClientService service = Services.GetService <ISteamClientService>();
                Diagnostics.Assert(service != null);
                service.ClientSteamServersDisconnected  += this.ISteamClientService_ClientSteamServersDisconnected;
                service.ClientSteamServerConnectFailure += this.ISteamClientService_ClientSteamServerConnectFailure;
                service.ClientP2PSessionConnectFail     += this.ISteamClientService_ClientP2PSessionConnectFail;
                Steamworks.SteamMatchMaking.ELobbyType lobbyType = this.SessionMode.ToSteamMatchMakingLobbyType();
                ulong steamAPICall = this.SteamMatchMakingService.SteamMatchMaking.CreateLobby(lobbyType, 1);
                if (Session.lobbyCreatedCallback != null)
                {
                    Session.lobbyCreatedCallback = null;
                    if (this.lobbyCreatedCallResult != null)
                    {
                        this.lobbyCreatedCallResult.Dispose();
                        this.lobbyCreatedCallResult = null;
                    }
                }
                Session.lobbyCreatedCallback = new Steamworks.LobbyCreatedCallback(this.Steamworks_LobbyCreated);
                this.lobbyCreatedCallResult  = new Steamworks.CallResult(Steamworks.SteamAPI_RegisterLobbyCreatedDelegate(steamAPICall, Session.lobbyCreatedCallback));
                break;
            }
            }
        }