private void DoMapRequest()
{
bool Extended = Info.Contains("mbs-");
int CustomMapId = 700;
// Check if the player exists
Rows = Database.Query("SELECT name FROM player WHERE id=@P0", Pid);
if (Rows.Count == 0)
{
Response.WriteResponseStart(false);
Response.WriteHeaderLine("asof", "err");
Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp(), "Player Doesnt Exist");
Response.Send();
return;
}
else
{
Response.WriteResponseStart();
Response.WriteHeaderLine("asof");
Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp());
}
// Build individual headers, so they can group together in response
Dictionary<int, string> Mtm = new Dictionary<int, string>();
Dictionary<int, string> Mwn = new Dictionary<int, string>();
Dictionary<int, string> Mls = new Dictionary<int, string>();
Dictionary<int, string> Mbs = new Dictionary<int, string>();
Dictionary<int, string> Mws = new Dictionary<int, string>();
// Add player data
List<string> Head = new List<string>();
List<string> Body = new List<string>();
Head.Add("pid");
Head.Add("nick");
Body.Add(Pid.ToString());
Body.Add(Rows[0]["name"].ToString().Trim());
// Begin headers
for (int i = 0; i < 7; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 10; i < 13; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 100; i < 106; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 110; i < 130; i += 10)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 200; i < 203; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 300; i < 308; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
for (int i = 601; i < 604; i++)
{
Mtm.Add(i, "0");
Mwn.Add(i, "0");
Mls.Add(i, "0");
if (Extended)
{
Mbs.Add(i, "0");
Mws.Add(i, "0");
}
}
// Fetch all user map data
string Where = (Info.Contains("cmap-"))
? String.Format("WHERE id={0}", Pid)
: String.Format("WHERE id={0} AND mapid < {1}", Pid, CustomMapId);
foreach (Dictionary<string, object> Row in Database.QueryReader(String.Format("SELECT * FROM maps {0}", Where)))
{
int Id = Int32.Parse(Row["mapid"].ToString());
if (Id > CustomMapId)
{
Mtm.Add(Id, Row["time"].ToString());
Mwn.Add(Id, Row["win"].ToString());
Mls.Add(Id, Row["loss"].ToString());
if (Extended)
{
Mbs.Add(Id, Row["best"].ToString());
Mws.Add(Id, Row["worst"].ToString());
}
}
else
{
Mtm[Id] = Row["time"].ToString();
Mwn[Id] = Row["win"].ToString();
Mls[Id] = Row["loss"].ToString();
if (Extended)
{
Mbs[Id] = Row["best"].ToString();
Mws[Id] = Row["worst"].ToString();
}
}
}
// Send Response
foreach (KeyValuePair<int, string> Item in Mtm)
{
Head.Add("mtm-" + Item.Key);
Body.Add(Item.Value);
}
foreach (KeyValuePair<int, string> Item in Mwn)
{
Head.Add("mwn-" + Item.Key);
Body.Add(Item.Value);
}
foreach (KeyValuePair<int, string> Item in Mls)
{
Head.Add("mls-" + Item.Key);
Body.Add(Item.Value);
}
if (Extended)
{
foreach (KeyValuePair<int, string> Item in Mbs)
{
Head.Add("mbs-" + Item.Key);
Body.Add(Item.Value);
}
foreach (KeyValuePair<int, string> Item in Mws)
{
Head.Add("mws-" + Item.Key);
Body.Add(Item.Value);
}
}
// Send Response
Response.WriteHeaderLine(Head);
Response.WriteDataLine(Body);
Response.Send();
}