<%@ Page Language="C#"%> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.Common" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Data.Odbc" %> <% // Copying the message parameters string sender = Request.QueryString["sender"]; string messagedata = Request.QueryString["messagedata"]; string messageid = Request.QueryString["messageid"]; // Converting the message datra to lowercase string data = messagedata.ToLower(); // The country names containing more parts will be considered as one word data = Regex.Replace(data, "united(.|..|...)states", "unitedstates"); data = Regex.Replace(data, "south(.|..|...)africa", "southafrica"); data = Regex.Replace(data, "korea(.|..|...)republic", "korearepublic"); data = Regex.Replace(data, "korea(.|..|...)dpr", "koreadpr"); data = Regex.Replace(data, "new(.|..|...)zealand", "newzealand"); // Checking the match for the pre-defined message format bool match = Regex.IsMatch(data, "([0-9]{1,2})([^a-zA-Z0-9]{1,3})([a-zA-Z]*)([^a-zA-Z0-9]{1,3})([a-zA-Z]*)([^a-zA-Z0-9]{1,3})([0-9]{1,3})([^a-zA-Z0-9]{1,3})([0-9]{1,3})"); // If it not matches, then the message will be treated as an invalid message. if (!match) { bool connectedToDb; string connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=bets;User=root;Password=qwe123;Option=4;"; OdbcConnection oc = new OdbcConnection(connectionString); oc.Open(); string insertSQL = "insert into bets(`sender`,`originalmsg`,`formatted_msg`,`match_number`,`team1`,`team2`,`time_of_bet`,`msgid`) values ('" + sender + "','" + messagedata + "','invalid','0','invalid','invalid',now(),'" + messageid + "');"; OdbcCommand command = new OdbcCommand(insertSQL, oc); command.ExecuteNonQuery(); oc.Close(); } else { // Replacing the special characters into semicolon. data = data.Replace('-', ';'); data = data.Replace('.', ';'); data = data.Replace(',', ';'); data = data.Replace('_', ';'); data = data.Replace('<', ';'); data = data.Replace('>', ';'); data = data.Replace('#', ';'); data = data.Replace('&', ';'); data = data.Replace('@', ';'); data = data.Replace('{', ';'); data = data.Replace('}', ';'); data = data.Replace(':', ';'); data = data.Replace('*', ';'); data = data.Replace('\'', ';'); data = data.Replace('\\', ';'); data = data.Replace('"', ';'); data = data.Replace('+', ';'); data = data.Replace('!', ';'); data = data.Replace('%', ';'); data = data.Replace('/', ';'); data = data.Replace('=', ';'); data = data.Replace('|', ';'); data = data.Replace('[', ';'); data = data.Replace(']', ';'); data = data.Replace('(', ';'); data = data.Replace(')', ';'); data = data.Replace('÷', ';'); // Splitting the message by semicolons, and removing the incidental duplicate semicolons string[] Splitted = data.Split(';', ' '); string FormattedBet = ""; for (int i = 0; i <= Splitted.Length - 1; i++) { if (Splitted[i] != "") { FormattedBet = FormattedBet + (Splitted[i] + ";"); } } // Bet variable will contain the processed message, in an array string[] Bet = FormattedBet.Split(';'); bool connectedToDb; try { string connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Database=bets;User=root;Password=qwe123;Option=4;"; OdbcConnection oc = new OdbcConnection(connectionString); oc.Open(); connectedToDb = true; try { // Ensuring the possibility for the team names could be swithable. string team1; string team2; if ((Bet[1].Substring(0, 3).CompareTo(Bet[2].Substring(0, 3))) < 0) { team1 = Bet[1].Trim() + ";" + Bet[3].Trim(); team2 = Bet[2].Trim() + ";" + Bet[4].Trim(); } else { team1 = Bet[2].Trim() + ";" + Bet[4].Trim(); team2 = Bet[1].Trim() + ";" + Bet[3].Trim(); } // Assembling the SQL query, and inserting the bet. string insertSQL = "insert into bets(`sender`,`originalmsg`,`formatted_msg`,`match_number`,`team1`,`team2`,`time_of_bet`,`msgid`) values ('" + sender + "','" + messagedata + "','" + FormattedBet + "','" + Bet[0].Trim() + "','" + team1 + "','" + team2 + "',now(),'" + messageid + "');"; OdbcCommand command = new OdbcCommand(insertSQL, oc); command.ExecuteNonQuery(); oc.Close(); } catch (Exception z) { string errCode = z.Message; Response.Write(errCode); } } catch (Exception e) { string respmsg = "Cannot connect to database." + e.Message; connectedToDb = false; Response.Write(respmsg); } } %>