예제 #1
0
		public RefreshStub Star(string clientID, string roomGuid, bool starred, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState)
		{
			WaitIfDevEnv();

			Guid guid = roomGuid.UnPackGuid();
			Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid);

			if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned)
				throw new LoginPermissionException();

			if (spec == null)
				throw new InvalidRoomException();

			if (!spec.IsStarrable)
				throw new Exception("This room is not starrable");

			StateStub state = null;
			foreach (StateStub ss in roomState)
			{
				if (ss.guid == roomGuid)
				{
					state = ss;
					break;
				}
			}

			#region Store the star room in the database, or delete the pin record.
			try
			{
				RoomPin rp = new RoomPin(Usr.Current.K, guid);
				rp.Starred = starred;
				rp.Update();
			}
			catch (BobNotFound)
			{
				if (!spec.IsDefaultRoom || spec.IsStarredByDefault != starred)
				{
					RoomPin rp = new RoomPin();
					rp.UsrK = Usr.Current.K;
					rp.RoomGuid = guid;
					rp.ListOrder = state != null ? state.listOrder : 0;
					rp.Pinned = true;
					rp.Starred = starred;
					rp.DateTime = DateTime.Now;
					rp.Update();
				}
			}
			#endregion

			storeRoomState(roomState, Usr.Current.K);

			lastActionTicks = resetLastActionAndSessionID(sessionID);

			Guid lastItemGuidReturned = Guid.Empty;
			Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid();

			ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);
			string chatItems = cs.GetLatest(Usr.Current.K, sessionID, false, lastItemGuid, ref lastItemGuidReturned);

			RefreshStub rs = new RefreshStub();
			rs.itemsJson = chatItems;
			rs.lastActionTicks = lastActionTicks;
			rs.lastItemGuidReturned = lastItemGuidReturned.Pack();
			return rs;
		}
예제 #2
0
		public RefreshStub RePin(string clientID, string roomGuid, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, StateStub[] roomState)
		{
			WaitIfDevEnv();

			Guid guid = roomGuid.UnPackGuid();
			Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(guid);

			if (Usr.Current == null || Usr.Current.IsSkeleton || Usr.Current.Banned)
				throw new LoginPermissionException();

			if (spec == null)
				throw new InvalidRoomException();

			if (!spec.CheckPermission(Usr.Current, false))
				throw new ReadPermissionException();

			StateStub state = null;
			foreach (StateStub ss in roomState)
			{
				if (ss.guid == roomGuid)
				{
					state = ss;
					break;
				}
			}

			storeRoomState(roomState, Usr.Current.K);

			lastActionTicks = resetLastActionAndSessionID(sessionID);
			RoomPin p = getOrCreateRoomPin(guid, state != null ? (int?)state.listOrder : null, Usr.Current.K);

			Guid lastItemGuidReturned = Guid.Empty;
			Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid();

			ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);
			string chatItems = cs.PinRoom(Usr.Current.K, sessionID, lastItemGuid, ref lastItemGuidReturned, guid);

			RefreshStub rs = new RefreshStub();
			rs.itemsJson = chatItems;
			rs.lastActionTicks = lastActionTicks;
			rs.lastItemGuidReturned = lastItemGuidReturned.Pack();
			return rs;
		}
예제 #3
0
		RefreshStub refreshPrivate(bool isFirstRequest, string lastItemGuidString, int sessionID, string lastActionTicks, string pageUrl, int usrK, StateStub[] roomState)
		{
			Guid lastItemGuidReturned = Guid.Empty;
			Guid lastItemGuid = lastItemGuidString.Length == 0 ? Guid.Empty : lastItemGuidString.UnPackGuid();
			if (usrK == 0)
				sessionID = 0;

			ChatLibrary.ChatServerInterface cs = (ChatLibrary.ChatServerInterface)Activator.GetObject(typeof(ChatLibrary.ChatServerInterface), Bobs.Vars.ChatServerAddress);
			string chatItems = cs.GetLatest(usrK, sessionID, isFirstRequest, lastItemGuid, ref lastItemGuidReturned);

			if (chatItems == "wrong session")
				throw new WrongSessionException();

			List<GuestRefreshStub> guestStubs = new List<GuestRefreshStub>();
			if (roomState != null)
			{
				foreach (StateStub ss in roomState)
				{
					if (ss.guest)
					{
						Guid g = ss.guid.UnPackGuid();
						Chat.RoomSpec spec = Chat.RoomSpec.FromGuid(g);
						if (!spec.MightFailReadPermissionCheck || Chat.Authenticate(ss.token, ss.tokenDateTimeTicks, g))
						{
							Guid guestLastItemGuidReturned = Guid.Empty;
							Guid guestLastItemGuid = ss.latestItem.Length == 0 ? Guid.Empty : ss.latestItem.UnPackGuid();
							string guestChatItems = cs.GetLatestGuest(usrK, isFirstRequest, guestLastItemGuid, ref guestLastItemGuidReturned, ss.guid.UnPackGuid());
							if (guestChatItems.Length > 0)
							{
								GuestRefreshStub guestStub = new GuestRefreshStub();
								guestStub.roomGuid = ss.guid;
								guestStub.itemsJson = guestChatItems;
								guestStub.lastItemGuidReturned = guestLastItemGuidReturned.Pack();
								guestStubs.Add(guestStub);
							}
						}
					}
				}
			}

			DateTime lastAction = new DateTime(long.Parse(lastActionTicks));
			if (lastAction < DateTime.Now.AddMinutes(-5))
				throw new TimeoutException();
			
			RefreshStub r = new RefreshStub();
			r.guestRefreshStubs = guestStubs.Count == 0 ? null : guestStubs.ToArray();
			r.itemsJson = chatItems;
			r.lastActionTicks = lastActionTicks;
			r.lastItemGuidReturned = lastItemGuidReturned.Pack();
			return r;
		}
예제 #4
0
		public void StoreUpdatedRoomListOrderSuccessCallback(RefreshStub s, object userContext, string methodName)
		{
			processItems(s.itemsJson, s.lastActionTicks, s.lastItemGuidReturned, methodName, s.guestRefreshStubs, "", false);

			continueProcessingCriticalRequestQueue();
		}
예제 #5
0
		public void RePinSuccessCallback(RefreshStub r, object userContext, string methodName)
		{
			processItems(r.itemsJson, r.lastActionTicks, r.lastItemGuidReturned, methodName, r.guestRefreshStubs, "", false);

			continueProcessingCriticalRequestQueue();
		}
예제 #6
0
		public void SendSuccessCallback(RefreshStub s, object userContext, string methodName)
		{
			if (s != null)
				processItems(s.itemsJson, s.lastActionTicks, s.lastItemGuidReturned, methodName, s.guestRefreshStubs, "", false);

			continueProcessingCriticalRequestQueue();
		}