private void UpdateCookiesFromPage(HttpResponseMessage page) { IEnumerable <string> values; if (page.Headers.TryGetValues("Set-Cookie", out values)) { bool changed = false; foreach (string s in values) { if (s.StartsWith("authToken")) { string[] data = s.Split('=', ';'); if (data[1] != authToken) { changed = true; authToken = data[1]; } } else if (s.StartsWith("PHPSESSID")) { string[] data = s.Split('=', ';'); if (data[1] != phpSessId) { changed = true; phpSessId = data[1]; } } } if (changed) { TokenPacket packet = new TokenPacket() { authToken = authToken, phpSessId = phpSessId }; OnEvent("tokens", packet); } } }
public void ProcessEvent(string type, EventArgs args) { if (type == "chat.user.message") { var message = args as ChatMessagePacket; if (message.chat != "0" && message.chat != DataExchange.CanvasId.ToString()) { return; } string formatted = String.Format("{0}: ", message.username); if (!String.IsNullOrWhiteSpace(message.guild)) { formatted = formatted.Insert(0, String.Format("<{0}>", message.guild)); } if (message.admin) { formatted = formatted.Insert(0, "[🔧]"); } if (message.mod) { formatted = formatted.Insert(0, "[🔨]"); } if (message.icon == "mvp-moderator") { formatted = formatted.Insert(0, "[mvp]"); } if (message.premium) { formatted = formatted.Insert(0, "[💎]"); } if (message.boardId != DataExchange.CanvasId) { formatted = formatted.Insert(0, "[" + message.boardId.ToString() + "]"); } int boardId = message.boardId; if (!palette.ContainsKey(boardId)) { boardId = 7; } Color color = palette[boardId][message.color]; ChatType chatType = ChatType.Global; switch (message.chatType) { case "channel": if (message.chat == "0") { chatType = ChatType.Global; } else { chatType = ChatType.Local; } break; case "guild": chatType = ChatType.Guild; break; case "whisper": chatType = ChatType.Whispers; break; } DataExchange.PushChatMessage(formatted, message.message, chatType, System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B)); } else if (type == "pixels") { PixelPacket pixel = args as PixelPacket; int boardId = pixel.boardId; if (!palette.ContainsKey(boardId)) { boardId = 7; } Color actualColor = palette[boardId][pixel.color]; DataExchange.PushPixel(pixel.x, pixel.y, actualColor, pixel.boardId, pixel.userId, pixel.instantPixel); } else if (type == "manager.status") { UserStatusData data = args as UserStatusData; DataExchange.PushUserStatus(data); } else if (type == "manager.taskenable") { TaskEnableStateData data = args as TaskEnableStateData; DataExchange.PushTaskEnabledState(data); } else if (type == "nickname") { NicknamePacket data = args as NicknamePacket; DataExchange.PushNewUsername(data.id, data.nickname); } else if (type == "tokens") { TokenPacket data = args as TokenPacket; DataExchange.PushTokens(data.phpSessId, data.authToken, data.id); } }