コード例 #1
0
ファイル: Service.asmx.cs プロジェクト: davelondon/dontstayin
		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;
		}
コード例 #2
0
ファイル: Server.cs プロジェクト: davelondon/dontstayin
		void processItems(string itemsJson, string lastActionTicks, string lastItemGuidReturned, string methodName, GuestRefreshStub[] guestRefreshStubs, string pinResultRoomGuid, bool excludeItemsFromPinnedRoom)
		{

			ItemStub[] itemStubArray = (ItemStub[])Script.Eval(" [ " + itemsJson + " ] ");//Newest last

			Array itemsArray = new Array();

			for (int i = 0; i < itemStubArray.Length; i++) //Newest last
			{
				//If we pin a room, and the returned room is already pinned, we want to skip any items in the already pinned room
				if (!excludeItemsFromPinnedRoom || itemStubArray[i].roomGuid != pinResultRoomGuid)
				{
					Item item = Item.Create(itemStubArray[i], Controller, RequestIndex, false, 1);
					itemsArray[itemsArray.Length] = item;
				}
			}

			Item[] items = (Item[])itemsArray;//Newest last

			if (items.Length > 0 && lastItemGuidReturned.Length > 0)
				LastItemGuid = lastItemGuidReturned;

			if (lastActionTicks.Length > 0)
				LastActionTicks = lastActionTicks;

			if (guestRefreshStubs != null)
			{
				for (int i = 0; i < guestRefreshStubs.Length; i++)
				{
					GuestRefreshStub g = (GuestRefreshStub)guestRefreshStubs[i];
					if (g.itemsJson.Length > 0)
					{
						ItemStub[] guestItemStubArray = (ItemStub[])Script.Eval(" [ " + g.itemsJson + " ] ");
						for (int j = 0; j < guestItemStubArray.Length; j++)
						{
							Item item = Item.Create(guestItemStubArray[j], Controller, RequestIndex, true, 1);
							items[items.Length] = item;
						}
						//update state...
						if (g.lastItemGuidReturned.Length > 0)
						{
							for (int k = 0; k < roomState.Length; k++)
							{
								StateStub ss = (StateStub)roomState[k];
								if (ss.guid == g.roomGuid)
								{
									ss.latestItem = g.lastItemGuidReturned;
									break;
								}
							}
						}
					}
				}
			}

			if (items.Length > 0)
			{
				if (GotItems != null)
					GotItems(this, new GotItemsEventArgs(items, RequestIndex));
			}
			else
			{
				if (GotNoItems != null)
					GotNoItems(this, new GotNoItemsEventArgs(RequestIndex));
			}

			RequestIndex++;
		}