public void Close() { if (this.opened || this.opening || this.reopening) { this.opened = false; this.opening = false; this.reopening = false; 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.SteamMatchMakingService = null; } if (!this.disposing) { this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Closed, this)); } this.hosting = false; } if (Session.lobbyCreatedCallback != null) { Session.lobbyCreatedCallback = null; if (this.lobbyCreatedCallResult != null) { this.lobbyCreatedCallResult.Dispose(); this.lobbyCreatedCallResult = null; } } Session.lobbyCreatedCallback = null; }
public void Open(Steamworks.SteamID steamIDLobby) { if (this.opened) { throw new InvalidOperationException("The session is already opened; consider closing it first or calling 'Reopen' instead."); } this.SteamMatchMakingService = Services.GetService <ISteamMatchMakingService>(); if (this.SteamMatchMakingService == null) { throw new InvalidOperationException("Cannot find the steam match making service."); } if (!steamIDLobby.IsValid) { throw new ArgumentException("The steamIDLobby is not valid."); } this.SteamIDLobby = steamIDLobby; this.opened = false; this.opening = true; this.reopening = true; this.hosting = false; this.SessionMode = SessionMode.Public; 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; this.OnSessionChange(new SessionChangeEventArgs(SessionChangeAction.Opening, this)); this.SteamMatchMakingService.SteamMatchMaking.JoinLobby(steamIDLobby); }
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; } } }
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; } } }