ProtocolResponse IProcessMessageStrategy.Process(ProtocolRequest request) { ProtocolResponse response = new ProtocolResponse(request.Action); if (request.IsBulkQuery) { // now deserialize this string into a list of dictionaries for parsing List <Dictionary <string, object> > DataDictionary = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(request.Data); try { if (CheckConnection()) { foreach (var d in DataDictionary) { IDbCommand cmd = SqlUtility.CreateCommand(Connection, request.Action, d); List <object> results = SqlUtility.InvokeCommand(cmd, out string error); response.Error += error; if (results != null) { response.Data.Add(results); } } response.Result = true; } else { response.Result = false; response.Error = "Could not connect to MYSQL instance"; } } catch (Exception ex) { CatchException(ref ex, ref request, ref response); } finally { CloseConnection(); } } else { // now deserialize this string into a list of dictionaries for parsing Dictionary <string, object> DataDictionary = null; if (request.Type == JTokenType.Object) { DataDictionary = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object> >(request.Data); } else { DataDictionary = new Dictionary <string, object>(); } // special scenario - because we cant get the ip address of the game server from DCS, we'll get it from the socket sender object // and specially insert it as a parameter into the data dictionary // the other special scenario is the server description request can supply - this can contain harmful html, so we must sanitize the input if (request.Action == ACTION_GET_SERVERID) { DataDictionary.Add("IP", request.IPAddress); if (DataDictionary.ContainsKey("Description")) { try { string html = Convert.ToString(DataDictionary["Description"]); DataDictionary["Description"] = Utility.SanitizeHTML(html, ref Config); } catch (Exception ex) { Logger.Log("Error sanitizing ServerDescription html string (Action: " + request.Action + ") - " + ex.Message); response.Error = "Error sanitizing ServerDescription html string (Action: " + request.Action + ") - " + ex.Message; response.Result = false; return(response); } } // Check the API version that the game is using if (DataDictionary.ContainsKey("Version") && DataDictionary["Version"].ToString() != Config.VersionKey) { Logger.Log("Client Version Mismatch (Expected: " + Config.VersionKey + ", Got: " + DataDictionary["Version"] + ")"); response.Error = "Version mismatch - you are running an older version of KI - the latest version is [" + Config.Version + "] - Please update to the latest version"; response.Result = false; return(response); } else if (!DataDictionary.ContainsKey("Version")) { Logger.Log("Client Version Mismatch - Client did not provide version information"); response.Error = "Version mismatch - you are running an older version of KI - the latest version is [" + Config.Version + "] - Please update to the latest version"; response.Result = false; return(response); } } try { if (CheckConnection()) { IDbCommand cmd = SqlUtility.CreateCommand(Connection, request.Action, DataDictionary); List <object> results = SqlUtility.InvokeCommand(cmd, out string error); response.Error += error; if (results != null) { response.Data.Add(results); } response.Result = true; } else { response.Result = false; response.Error = "Could not connect to MYSQL instance"; } } catch (Exception ex) { CatchException(ref ex, ref request, ref response); } finally { CloseConnection(); } } return(response); }