private HttpRequest GetRequest(ChatAction act) { var data = act.Data; if (act.RequiresFKey) { var roomUrl = $"https://{Host}/rooms/{RoomId}"; if (data == null) { data = new Dictionary <string, object> { ["fkey"] = FKeyAccessor.GetAsync(roomUrl, auth[Host]).Result }; } else { data["fkey"] = FKeyAccessor.GetAsync(roomUrl, auth[Host]).Result; } } var req = new HttpRequest { Verb = act.RequestMethod, Endpoint = act.Endpoint, Data = data }; if (act.RequiresAuthCookies) { req.Cookies = auth[Host]; } return(req); }
private void HandleReconnectFailure() { if (dispose) { return; } if ((DateTime.UtcNow - lastReconnectFailure).TotalSeconds < reconnectWait * 2) { reconnectWait += 10; reconnectWait = Math.Min(reconnectWait, 100); } else { reconnectWait = 10; } lastReconnectFailure = DateTime.UtcNow; Thread.Sleep(reconnectWait * 1000); FKeyAccessor.ClearCache(); Auth.InvalidateHostCache(Host); WebSocket = GetWebSocket(); EventRouter.SetWebSocket(WebSocket); }
private string GetBaseWebSocketUrl() { var response = new HttpRequest { Verb = RestSharp.Method.POST, Endpoint = $"https://{Host}/ws-auth", Cookies = Auth[Host], Data = new Dictionary <string, object> { ["roomid"] = RoomId, ["fkey"] = FKeyAccessor.GetAsync($"https://{Host}/rooms/{RoomId}", Auth[Host]).Result } }.SendAsync().Result; if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Failed to get base WebSocket URL."); } var data = JObject.Parse(response.Content); return(data.Value <string>("url")); }
private int GetGlobalEventCount() { var response = new HttpRequest { Verb = RestSharp.Method.POST, Endpoint = $"https://{Host}/chats/{RoomId}/events", Cookies = Auth[Host], Data = new Dictionary <string, object> { ["mode"] = "events", ["msgCount"] = 0, ["fkey"] = FKeyAccessor.GetAsync($"https://{Host}/rooms/{RoomId}", Auth[Host]).Result } }.SendAsync().Result; if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Failed to get global chat event count."); } var data = JObject.Parse(response.Content); return(data.Value <int>("time")); }