public bool ProcessUsernameResponce(string data, string requestUri) { int id = int.Parse(requestUri.Substring(requestUri.LastIndexOf("=") + 1)); //username request response string suc = data.Substring(11, 5); if (suc == "false") { Premium = false; Logger.Error("Failed to get username, no premium for {0}", Username); return(true); } if (data.Contains("User not found")) { Logger.Error("Failed to get username, user not found (req:{0} using:{1})", id, Username); return(true); } else if (data.Contains("You need to be connected")) { Logger.Error("Failed to get username, you need to be connected for {0}", Username); return(true); } int startPos = data.IndexOf("\"username\":\"") + 1 + 11; int endPos = data.IndexOf("\"}}"); if (endPos == -1) { Logger.Error("Failed to get username, parsing error for {0}, response: {1}", Username, data); return(true); } string name = data.Substring(startPos, endPos - startPos); NicknamePacket packet = new NicknamePacket() { nickname = name, id = id }; OnEvent?.Invoke("nickname", packet); return(true); }
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); } }