public PHPC(Uri URL, bool UseAuth, string Username = "******", string Password = "******") { this.URL = URL; NameValueCollection data = new NameValueCollection(); data = DataInjector.Foundation(data); string str = WebSocket.SendRequest(this.URL, data); if (str.ToLower().Contains("request;success")) { if (UseAuth) { throw new Exception("Authorization is not required for this server"); } this.UseAuth = UseAuth; this.Username = Username; this.Password = Password; } else { if (!str.ToLower().Contains("request;failure")) { throw new Exception($"Server returned an unknown response {str}"); } if (str.ToLower().Contains("(error0@1) = auth required")) { if (!UseAuth) { throw new Exception("Authorization is required for this server"); } data = DataInjector.AddAuth(data, Username, Password); str = WebSocket.SendRequest(this.URL, data); if (str.ToLower().Contains("request;failure")) { if (str.ToLower().Contains("(error1@1)")) { throw new Exception("Authorization failure, Incorrect username or password"); } throw new Exception($"Server returned an unknown response {str}"); } if (str.ToLower().Contains("request;success")) { this.UseAuth = UseAuth; this.Username = Username; this.Password = Password; } } else { if (str.ToLower().Contains("(error 2@2)")) { throw new Exception("The server does not support this client's version"); } throw new Exception($"Server returned an unknown response {str}"); } } }
public string SendRequest(Vodka Data) { NameValueCollection data = new NameValueCollection(); data = DataInjector.Foundation(data); if (this.UseAuth) { data = DataInjector.AddAuth(data, this.Username, this.Password); } data.Add("Request-Data", Vodka.Encode(Data)); return(WebSocket.SendRequest(this.URL, data)); }