void initialise() { if (View.InitGo.Value == "0") return; serverTicksAtPageLoad = getRelevantDigits(View.InitLastActionTicks.Value); clientTicksAtPageLoad = getRelevantDigits(new DateTime().GetTime().ToString()); StreamList = View.StreamList; Instance = this; UsrK = int.ParseInvariant(View.InitUsrK.Value); LoggedIn = UsrK > 0; ClientID = View.InitClientID.Value; LastActionTicks = View.InitLastActionTicks.Value; SessionID = Math.Round(Math.Random() * 10000); SystemMessagesRoomGuid = View.InitSystemMessagesRoomGuid.Value; InboxUpdatesRoomGuid = View.InitInboxUpdatesRoomGuid.Value; BuddyStreamRoomGuid = View.InitBuddyStreamRoomGuid.Value; PublicStreamRoomGuid = "ARAFAAAAAAUAAAAANdfH9w"; PrivateChatRequestsRoomGuid = "ARIFAAAAAAUAAAAAO3ZY0A"; lastKeyDown = -1; chatClientIsPaused = false; State = new StateStub[0]; RoomsListOrder = new Array(); Popups = new PopupArea(View); #region Add dom events DomEvent.AddHandler(View.TextBox, "focus", new DomEventHandler(textBoxFocus)); DomEvent.AddHandler(View.TextBox, "blur", new DomEventHandler(textBoxBlur)); DomEvent.AddHandler(View.TextBox, "keypress", new DomEventHandler(textBoxKeyPress)); DomEvent.AddHandler(View.TextBox, "keydown", new DomEventHandler(textBoxKeyDown)); DomEvent.AddHandler(View.OuterMain, "keydown", new DomEventHandler(outerKeyDown)); DomEvent.AddHandler(View.RoomsMain, "click", new DomEventHandler(roomListClick)); DomEvent.AddHandler(View.RoomsMain, "mousedown", new DomEventHandler(roomListMouseDown)); if (LoggedIn) { DomEvent.AddHandler(View.PrivateChatDrop, "change", new DomEventHandler(privateChatDropChange)); } DomEvent.AddHandler(View.WrongSessionResumeLink, "click", new DomEventHandler(resumeLinkClick)); DomEvent.AddHandler(View.TimeoutResumeLink, "click", new DomEventHandler(resumeLinkClick)); DomEvent.AddHandler(View.DeleteArchiveAnchor, "click", new DomEventHandler(deleteArchive)); #endregion #region Create rooms Rooms = new Dictionary(); selectedRoomGuid = ""; for (int i = 0; i < View.RoomList.ChildNodes.Length + View.RoomPrivateList.ChildNodes.Length + View.RoomGuestList.ChildNodes.Length; i++) { DOMElement child = null; if (i < View.RoomList.ChildNodes.Length) child = View.RoomList.ChildNodes[i]; else if (i < View.RoomList.ChildNodes.Length + View.RoomPrivateList.ChildNodes.Length) child = View.RoomPrivateList.ChildNodes[i - View.RoomList.ChildNodes.Length]; else child = View.RoomGuestList.ChildNodes[i - View.RoomList.ChildNodes.Length - View.RoomPrivateList.ChildNodes.Length]; if (child.NodeType == DOMElementType.Element && child.ClassName.StartsWith("ChatClientRoomHolder")) { Room r = new Room(this, View); r.InitialiseFromElement(child, State); initialiseRoomEvents(r); if (r.Selected) { if (selectedRoomGuid.Length > 0) r.Selected = false; else selectedRoomGuid = r.Guid; } Rooms[r.Guid] = r; RoomsListOrder[RoomsListOrder.Length] = r.Guid; r.SetListOrder(RoomsListOrder.Length - 1); } } #endregion #region LatestTopPhoto if (View.InitTopPhoto.Value.Length > 0 && Rooms["AQEFAAAAAAUAAAAAvVaVmQ"] != null) { string[] topPhotoParts = View.InitTopPhoto.Value.Split(','); TopPhoto p = new TopPhoto( new TopPhotoStub( "", ItemType.TopPhoto, "", "AQEFAAAAAAUAAAAAvVaVmQ", int.ParseInvariant(topPhotoParts[0]), topPhotoParts[1], topPhotoParts[2], topPhotoParts[3], int.ParseInvariant(topPhotoParts[4]), int.ParseInvariant(topPhotoParts[5]), topPhotoParts[6], int.ParseInvariant(topPhotoParts[7]), int.ParseInvariant(topPhotoParts[8])), this); ((Room)Rooms["AQEFAAAAAAUAAAAAvVaVmQ"]).AddItem(p, null); } #endregion updateDraggable(); #region Initialise server Server = new ServerClass(this, SessionID, LastActionTicks, State); Server.GotItems = new EventHandler(gotItems); Server.GotNoItems = new EventHandler(gotNoItems); Server.GotWrongSessionException = new EventHandler(gotWrongSessionException); Server.GotTimeoutException = new EventHandler(gotTimeoutException); Server.GotGenericException = new EventHandler(gotGenericException); Server.GotRoom = new GotRoomHandler(gotRoom); Server.GotNewPhotoRoom = new GotRoomHandler(gotNewPhotoRoom); Server.GotRoomState = new EventHandler(gotRoomState); Server.ShowLoadingIcon = new EventHandler(showLoadingIcon); Server.HideLoadingIcon = new EventHandler(hideLoadingIcon); Server.GotMoreInfo = new EventHandler(gotRoomMoreInfoHtml); Server.GotArchiveItems = new EventHandler(gotRoomArchiveItems); Server.DebugPrint = new EventHandler(debugEventHandler); Server.DoneDeleteArchive = new EventHandler(doneDeleteArchive); Server.Start(); #endregion if (selectedRoomGuid.Length == 0 && RoomsListOrder.Length > 0) SelectedRoom = (Room)Rooms[(string)RoomsListOrder[0]]; debug("Controller started successfully."); }
bool gotRoom(object o, EventArgs e) { GotRoomEventArgs a = (GotRoomEventArgs)e; object ob = Rooms[a.RoomStub.guid]; if (ob == null) { Room r = new Room(this, View); r.InitialiseFromStub(a.RoomStub, a.RoomStub.guest ? View.RoomGuestList : a.RoomStub.isPrivateChatRoom ? View.RoomPrivateList : View.RoomList, State); initialiseRoomEvents(r); Rooms[r.Guid] = r; RoomsListOrder[RoomsListOrder.Length] = r.Guid; r.SetListOrder(RoomsListOrder.Length - 1); SelectedRoom = r; updateDraggable(); if (a.RoomStub.guest) updateRoomGuestListVisibility(true); else if (a.RoomStub.isPrivateChatRoom) updateRoomPrivateListVisibility(true); return false; } else { Room r = (Room)ob; if (!r.Pinned) r.Pinned = true; SelectedRoom = r; return true; } }
bool gotNewPhotoRoom(object o, EventArgs e) { GotRoomEventArgs a = (GotRoomEventArgs)e; bool newRoomShouldBeSelected = removeAllUnPinnedGuestPhotoRoomsExceptSpecified(a.RoomStub.guid); object ob = Rooms[a.RoomStub.guid]; if (ob == null) { Room r = new Room(this, View); r.InitialiseFromStub(a.RoomStub, a.RoomStub.isPrivateChatRoom ? View.RoomPrivateList : a.RoomStub.guest ? View.RoomGuestList : View.RoomList, State); initialiseRoomEvents(r); Rooms[r.Guid] = r; RoomsListOrder[RoomsListOrder.Length] = r.Guid; r.SetListOrder(RoomsListOrder.Length - 1); if (newRoomShouldBeSelected) setSelectedRoom(r, false); updateDraggable(); updateRoomUI(); return false; } else { Room r = (Room)ob; if (newRoomShouldBeSelected) setSelectedRoom(r, false); return true; } }