private RoomSession GetTerminatedSession() { var terminatedRoom = new RoomSession(mRealtimeManager, new NoopListener()); terminatedRoom.EnterState(new ShutdownState(terminatedRoom)); return(terminatedRoom); }
internal LeavingRoom(RoomSession session, NativeRealTimeRoom room, Action leavingCompleteCallback) { mSession = Misc.CheckNotNull(session); mRoomToLeave = Misc.CheckNotNull(room); mLeavingCompleteCallback = Misc.CheckNotNull(leavingCompleteCallback); }
private RoomSession GetTerminatedSession() { RoomSession roomSession = new RoomSession(mRealtimeManager, new NoopListener()); roomSession.EnterState(new ShutdownState(roomSession), false); return(roomSession); }
internal NativeRealtimeMultiplayerClient(NativeClient nativeClient, RealtimeManager manager) { mNativeClient = Misc.CheckNotNull(nativeClient); mRealtimeManager = Misc.CheckNotNull(manager); mCurrentSession = GetTerminatedSession(); PlayGamesHelperObject.AddPauseCallback(HandleAppPausing); }
public void CreateQuickGame(uint minOpponents, uint maxOpponents, uint variant, RealTimeMultiplayerListener listener) { lock (mSessionLock) { var newSession = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to create a new room without cleaning up the old one."); newSession.LeaveRoom(); return; } mCurrentSession = newSession; // We're holding the session lock, so no other threads could have torn down the session // in the meantime. using (var configBuilder = RealtimeRoomConfigBuilder.Create()) { var config = configBuilder.SetMinimumAutomatchingPlayers(minOpponents) .SetMaximumAutomatchingPlayers(maxOpponents) .SetVariant(variant) .Build(); using (config) { using (var helper = HelperForSession(newSession)) { newSession.StartRoomCreation(mNativeClient.GetUserId(), () => mRealtimeManager.CreateRoom(config, helper, newSession.HandleRoomResponse) ); } } } } }
public void LoadMore() { this.RoomSession = new RoomSession(this.ID, this); this.CommandCache = new CommandCache(this.ID, this); this.UserStats = new UserStats(this.ID); if (!this.UserStats.Fill(this.GetUserDataFactory().GetUserStats())) { using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient()) { dbClient.AddParamWithValue("userId", this.ID); dbClient.ExecuteQuery("INSERT INTO user_stats(user_id) VALUES(@userId)"); } } this.UserAchievements = new UserAchievements(this); this.InventoryManager = new InventoryManager(this.GetSession(), this.GetUserDataFactory()); this.SubscriptionManager = new SubscriptionManager(this.ID, this, this.GetUserDataFactory()); this.WardrobeManager = new WardrobeManager(this.ID, this, this.GetUserDataFactory()); this.BadgeManager = new BadgeManager(this.ID, this, this.GetUserDataFactory()); this.LoadFavouriteRooms(); this.LoadRooms(); this.LoadTags(); this.LoadIgnores(); this.LoadPets(); }
public RoomSessionsModel GetRoomSessions(int id) { RoomSessionsModel model = new RoomSessionsModel(); try { RoomSession roomSessions = dbContext.RoomSessions.FirstOrDefault(x => x.SectionID == id); try { model.SessionID = roomSessions.SessionID; model.ClassID = roomSessions.ClassID; model.SectionID = roomSessions.SectionID; //model.CourseID = roomSessions.CourseID; dbContext.SaveChanges(); } catch { throw new ApiException("This room session does not exist"); } } catch (Exception exception) { throw new Exception(exception.Message); } return(model); }
public Shell <bool> Bind([FromBody] Shell <uint> roomID) { uint pid = db.Get <uint>("SELECT pid FROM voa.process WHERE roomID={0}", roomID); var session = RoomSession.Open(roomID, pid); Response.Cookies.Append("session", session.ToString()); db.Execute("UPDATE voa.process SET isload=b'1' WHERE pid={0};", pid); return(true); }
public void AcceptFromInbox(RealTimeMultiplayerListener listener) { lock (mSessionLock) { RoomSession newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to accept invitation without cleaning up active session."); newRoom.LeaveRoom(); } else { mCurrentSession = newRoom; mCurrentSession.ShowingUI = true; mRealtimeManager.ShowRoomInboxUI(delegate(RealtimeManager.RoomInboxUIResponse response) { mCurrentSession.ShowingUI = false; if (response.ResponseStatus() != CommonErrorStatus.UIStatus.VALID) { Logger.d("User did not complete invitation screen."); newRoom.LeaveRoom(); } else { GooglePlayGames.Native.PInvoke.MultiplayerInvitation invitation = response.Invitation(); GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper = HelperForSession(newRoom); try { Logger.d("About to accept invitation " + invitation.Id()); newRoom.StartRoomCreation(mNativeClient.GetUserId(), delegate { mRealtimeManager.AcceptInvitation(invitation, helper, delegate(RealtimeManager.RealTimeRoomResponse acceptResponse) { using (invitation) { newRoom.HandleRoomResponse(acceptResponse); newRoom.SetInvitation(invitation.AsInvitation()); } }); }); } finally { if (helper != null) { ((IDisposable)helper).Dispose(); } } } }); } } }
private static RealTimeEventListenerHelper HelperForSession(RoomSession session) { return(RealTimeEventListenerHelper.Create() .SetOnDataReceivedCallback((room, participant, data, isReliable) => session.OnDataReceived(room, participant, data, isReliable)) .SetOnParticipantStatusChangedCallback((room, participant) => session.OnParticipantStatusChanged(room, participant)) .SetOnRoomConnectedSetChangedCallback((room) => session.OnConnectedSetChanged(room)) .SetOnRoomStatusChangedCallback((room) => session.OnRoomStatusChanged(room))); }
public void AcceptFromInbox(RealTimeMultiplayerListener listener) { lock (mSessionLock) { var newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to accept invitation without cleaning up " + "active session."); newRoom.LeaveRoom(); return; } // The user accepted an invitation from the inbox, this is now the current room. mCurrentSession = newRoom; mRealtimeManager.ShowRoomInboxUI( response => { if (response.ResponseStatus() != Status.UIStatus.VALID) { Logger.d("User did not complete invitation screen."); newRoom.LeaveRoom(); return; } // We are not cleaning up the invitation here to workaround a bug in the // C++ SDK where it holds a reference to un-owned memory rather than making a // copy. This is cleaned up after the callback comes back instead. var invitation = response.Invitation(); using (var helper = HelperForSession(newRoom)) { Logger.d("About to accept invitation " + invitation.Id()); newRoom.StartRoomCreation(mNativeClient.GetUserId(), () => mRealtimeManager.AcceptInvitation(invitation, helper, acceptResponse => { // Clean up the invitation here (see above comment). using (invitation) { newRoom.HandleRoomResponse(acceptResponse); } })); } }); } }
public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener) { lock (mSessionLock) { var newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to accept invitation without cleaning up " + "active session."); newRoom.LeaveRoom(); return; } mCurrentSession = newRoom; mRealtimeManager.FetchInvitations(response => { if (!response.RequestSucceeded()) { Logger.e("Couldn't load invitations."); newRoom.LeaveRoom(); return; } foreach (var invitation in response.Invitations()) { using (invitation) { if (invitation.Id().Equals(invitationId)) { using (var helper = HelperForSession(newRoom)) { newRoom.StartRoomCreation(mNativeClient.GetUserId(), () => mRealtimeManager.AcceptInvitation( invitation, helper, newRoom.HandleRoomResponse)); return; } } } } Logger.e("Room creation failed since we could not find invitation with ID " + invitationId); newRoom.LeaveRoom(); }); } }
public void CreateWithInvitationScreen(uint minOpponents, uint maxOppponents, uint variant, RealTimeMultiplayerListener listener) { lock (mSessionLock) { var newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to create a new room without cleaning up the old one."); newRoom.LeaveRoom(); return; } // The user attempted to create a room via the invitation screen, this is now the new // current room. mCurrentSession = newRoom; mRealtimeManager.ShowPlayerSelectUI(minOpponents, maxOppponents, true, response => { if (response.Status() != Status.UIStatus.VALID) { Logger.d("User did not complete invitation screen."); newRoom.LeaveRoom(); return; } using (var configBuilder = RealtimeRoomConfigBuilder.Create()) { configBuilder.SetVariant(variant); configBuilder.PopulateFromUIResponse(response); using (var config = configBuilder.Build()) { using (var helper = HelperForSession(newRoom)) { newRoom.StartRoomCreation(mNativeClient.GetUserId(), () => mRealtimeManager.CreateRoom(config, helper, newRoom.HandleRoomResponse)); } } } }); } }
public void CreateQuickGame(uint minOpponents, uint maxOpponents, uint variant, ulong exclusiveBitMask, RealTimeMultiplayerListener listener) { lock (mSessionLock) { RoomSession newSession = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to create a new room without cleaning up the old one."); newSession.LeaveRoom(); } else { mCurrentSession = newSession; Logger.d("QuickGame: Setting MinPlayersToStart = " + minOpponents); mCurrentSession.MinPlayersToStart = minOpponents; using (RealtimeRoomConfigBuilder realtimeRoomConfigBuilder = RealtimeRoomConfigBuilder.Create()) { RealtimeRoomConfig config = realtimeRoomConfigBuilder.SetMinimumAutomatchingPlayers(minOpponents).SetMaximumAutomatchingPlayers(maxOpponents).SetVariant(variant) .SetExclusiveBitMask(exclusiveBitMask) .Build(); using (config) { GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper = HelperForSession(newSession); try { newSession.StartRoomCreation(mNativeClient.GetUserId(), delegate { mRealtimeManager.CreateRoom(config, helper, newSession.HandleRoomResponse); }); } finally { if (helper != null) { ((IDisposable)helper).Dispose(); } } } } } } }
public void SaveRoomSessions(RoomSessionsModel model) { if (model == null) { throw new Exception("Invalid Value"); } if (string.IsNullOrEmpty(model.SessionID.ToString())) { throw new Exception("Please Select Session"); } if (string.IsNullOrEmpty(model.ClassID.ToString())) { throw new Exception("Please Select Class"); } if (string.IsNullOrEmpty(model.SectionID.ToString())) { throw new Exception("Please Select Section"); } if (string.IsNullOrEmpty(model.CourseID.ToString())) { throw new Exception("Please Select Course"); } try { foreach (var course in model.CourseID) { RoomSession roomSessions = new RoomSession(); roomSessions.SessionID = model.SessionID; roomSessions.ClassID = model.ClassID; roomSessions.SectionID = model.SectionID; roomSessions.CourseID = course; roomSessions.StartDate = DateTime.Now; dbContext.RoomSessions.Add(roomSessions); } dbContext.SaveChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } }
private static GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper HelperForSession(RoomSession session) { return(GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper.Create().SetOnDataReceivedCallback(delegate(NativeRealTimeRoom room, GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant, byte[] data, bool isReliable) { session.OnDataReceived(room, participant, data, isReliable); }).SetOnParticipantStatusChangedCallback(delegate(NativeRealTimeRoom room, GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant) { session.OnParticipantStatusChanged(room, participant); }) .SetOnRoomConnectedSetChangedCallback(delegate(NativeRealTimeRoom room) { session.OnConnectedSetChanged(room); }) .SetOnRoomStatusChangedCallback(delegate(NativeRealTimeRoom room) { session.OnRoomStatusChanged(room); })); }
internal RoomCreationPendingState(RoomSession session) { mContainingSession = Misc.CheckNotNull(session); }
internal BeforeRoomCreateStartedState(RoomSession session) { mContainingSession = Misc.CheckNotNull(session); }
internal MessagingEnabledState(RoomSession session, NativeRealTimeRoom room) { mSession = Misc.CheckNotNull(session); UpdateCurrentRoom(room); }
internal ConnectingState(NativeRealTimeRoom room, RoomSession session) : base(session, room) { mPercentPerParticipant = 80f / (float)(double)session.MinPlayersToStart; }
internal NativeRealtimeMultiplayerClient(NativeClient nativeClient, RealtimeManager manager) { mNativeClient = Misc.CheckNotNull(nativeClient); mRealtimeManager = Misc.CheckNotNull(manager); mCurrentSession = GetTerminatedSession(); }
public void CreateWithInvitationScreen(uint minOpponents, uint maxOppponents, uint variant, RealTimeMultiplayerListener listener) { lock (mSessionLock) { RoomSession newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to create a new room without cleaning up the old one."); newRoom.LeaveRoom(); } else { mCurrentSession = newRoom; mCurrentSession.ShowingUI = true; RealtimeRoomConfig config; GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper; mRealtimeManager.ShowPlayerSelectUI(minOpponents, maxOppponents, true, delegate(PlayerSelectUIResponse response) { mCurrentSession.ShowingUI = false; if (response.Status() != CommonErrorStatus.UIStatus.VALID) { Logger.d("User did not complete invitation screen."); newRoom.LeaveRoom(); } else { mCurrentSession.MinPlayersToStart = (uint)((int)response.MinimumAutomatchingPlayers() + response.Count() + 1); using (RealtimeRoomConfigBuilder realtimeRoomConfigBuilder = RealtimeRoomConfigBuilder.Create()) { realtimeRoomConfigBuilder.SetVariant(variant); realtimeRoomConfigBuilder.PopulateFromUIResponse(response); config = realtimeRoomConfigBuilder.Build(); try { helper = HelperForSession(newRoom); try { newRoom.StartRoomCreation(mNativeClient.GetUserId(), delegate { mRealtimeManager.CreateRoom(config, helper, newRoom.HandleRoomResponse); }); } finally { if (helper != null) { ((IDisposable)helper).Dispose(); } } } finally { if (config != null) { ((IDisposable)config).Dispose(); } } } } }); } } }
internal ConnectingState(NativeRealTimeRoom room, RoomSession session) : base(session, room) { mPercentPerParticipant = (100.0f - InitialPercentComplete) / (float)room.ParticipantCount(); }
internal ShutdownState(RoomSession session) { mSession = Misc.CheckNotNull(session); }
public static void SerializeRoomSession(RoomSession room) { string json = JsonConvert.SerializeObject(room); System.IO.File.WriteAllText("RoomSession_" + room.RoomCode + ".json", json); }
public void AcceptInvitation(string invitationId, RealTimeMultiplayerListener listener) { lock (mSessionLock) { RoomSession newRoom = new RoomSession(mRealtimeManager, listener); if (mCurrentSession.IsActive()) { Logger.e("Received attempt to accept invitation without cleaning up active session."); newRoom.LeaveRoom(); } else { mCurrentSession = newRoom; GooglePlayGames.Native.PInvoke.RealTimeEventListenerHelper helper; mRealtimeManager.FetchInvitations(delegate(RealtimeManager.FetchInvitationsResponse response) { if (!response.RequestSucceeded()) { Logger.e("Couldn't load invitations."); newRoom.LeaveRoom(); } else { using (IEnumerator <GooglePlayGames.Native.PInvoke.MultiplayerInvitation> enumerator = response.Invitations().GetEnumerator()) { GooglePlayGames.Native.PInvoke.MultiplayerInvitation invitation; while (enumerator.MoveNext()) { invitation = enumerator.Current; using (invitation) { if (invitation.Id().Equals(invitationId)) { mCurrentSession.MinPlayersToStart = invitation.AutomatchingSlots() + invitation.ParticipantCount(); Logger.d("Setting MinPlayersToStart with invitation to : " + mCurrentSession.MinPlayersToStart); helper = HelperForSession(newRoom); try { newRoom.StartRoomCreation(mNativeClient.GetUserId(), delegate { mRealtimeManager.AcceptInvitation(invitation, helper, newRoom.HandleRoomResponse); }); return; IL_011e:; } finally { if (helper != null) { ((IDisposable)helper).Dispose(); } } } } } } Logger.e("Room creation failed since we could not find invitation with ID " + invitationId); newRoom.LeaveRoom(); } }); } } }
internal ActiveState(NativeRealTimeRoom room, RoomSession session) : base(session, room) { }
internal AbortingRoomCreationState(RoomSession session) { mSession = Misc.CheckNotNull(session); }