Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class HuntSysUI : IConquerAIWebUI
- {
- public string Name { get { return "Hunter System"; } }
- public string Page { get { return "/huntsys.html"; } }
- public void RenderUI(UriQuery urlQuery, HttpListenerContext context, HttpListenerRequest request, HttpListenerResponse response, StreamWriter output)
- {
- //
- // update fields / handle input, etc.
- //
- string value;
- if (urlQuery.TryGetField("quality", out value))
- HunterSettings.MinQuality = (LootQuality)Math.Max(int.Parse(value), (int)LootQuality.Refined);
- if (urlQuery.TryGetField("bless", out value))
- HunterSettings.MinBless = Math.Min(7, Math.Max(int.Parse(value), 1));
- if (urlQuery.TryGetField("tradeadd", out value))
- HunterSettings.TradeAddItems = (value == "on");
- if (urlQuery.TryGetField("usetraders", out value))
- HunterSettings.UseTraders = (value == "on");
- if (urlQuery.TryGetField("username", out value))
- {
- string password, server, profile, action;
- if (urlQuery.TryGetField("password", out password) &&
- urlQuery.TryGetField("server", out server) &&
- urlQuery.TryGetField("profile", out profile))
- {
- HunterSettings.AddHunter(value, password, server, profile);
- HttpServer.LogMessage("Attempting to add hunter... {0}, {1}", value, server);
- }
- else if (urlQuery.TryGetField("action", out action))
- {
- LoginData ld;
- COFarmerClient inst;
- switch (action)
- {
- case "disconnect":
- if (HunterSettings.TryGetStandaloneData(value, out ld))
- HunterSettings.DisconnectStandalone(ld);
- else if (HunterSettings.TryGetCliented(value, out inst))
- HunterSettings.DisconnectClient(inst);
- break;
- case "remove":
- if (HunterSettings.TryGetStandaloneData(value, out ld))
- HunterSettings.RemoveStandalone(ld);
- else if (HunterSettings.TryGetCliented(value, out inst))
- HunterSettings.RemoveClient(inst);
- break;
- case "stop":
- if (HunterSettings.TryGetStandaloneData(value, out ld))
- HunterSettings.StopStandalone(ld);
- else if (HunterSettings.TryGetCliented(value, out inst))
- HunterSettings.StopClient(inst); ;
- break;
- case "start":
- if (HunterSettings.TryGetStandaloneData(value, out ld))
- HunterSettings.StartStandalone(ld);
- else if (HunterSettings.TryGetCliented(value, out inst))
- HunterSettings.StartClient(inst);
- break;
- }
- }
- }
- //
- //
- //
- // render left side panel
- // min quality, bless, trade +, use traders
- var sb = new StringBuilder();
- sb.AppendLine("<form>");
- var minQuality = new StringBuilder();
- minQuality.Append(new HtmlForm.RadioButton("quality", "6", HunterSettings.MinQuality == LootQuality.Refined) + " Refined<br>");
- minQuality.Append(new HtmlForm.RadioButton("quality", "7", HunterSettings.MinQuality == LootQuality.Unique) + " Unique<br>");
- minQuality.Append(new HtmlForm.RadioButton("quality", "8", HunterSettings.MinQuality == LootQuality.Elite) + " Elite<br>");
- minQuality.Append(new HtmlForm.RadioButton("quality", "9", HunterSettings.MinQuality == LootQuality.Super) + " Super");
- var minBless = new StringBuilder();
- minBless.Append(new HtmlForm.RadioButton("bless", "1", HunterSettings.MinBless < 3) + " -1 %<br>");
- minBless.Append(new HtmlForm.RadioButton("bless", "3", HunterSettings.MinBless == 3) + " -3 %<br>");
- minBless.Append(new HtmlForm.RadioButton("bless", "5", HunterSettings.MinBless == 5) + " -5 %<br>");
- minBless.Append(new HtmlForm.RadioButton("bless", "7", HunterSettings.MinBless > 5) + " -7 %");
- var table = new HtmlTable();
- table.AddRow(new HtmlTable.Row("Trade Min. Quality", minQuality));
- table.AddRow(new HtmlTable.Row("Trade Min. Bless", minBless));
- table.AddRow(new HtmlTable.Row("Trade Add Items", new HtmlForm.CheckBox("tradeadd", HunterSettings.TradeAddItems)));
- table.AddRow(new HtmlTable.Row("Use Traders", new HtmlForm.CheckBox("usetraders", HunterSettings.UseTraders)));
- table.AddRow(new HtmlTable.Row(new HtmlForm.SubmitButton("Apply Changes")));
- sb.AppendLine(table.ToString());
- sb.AppendLine(new HtmlForm.Hidden("token", HttpServer.Token).ToString());
- sb.AppendLine("</form>");
- // to-do render logged in client list...
- string frmtOptions = "<form method='post'>" +
- " <input type='hidden' name='token' value='" + HttpServer.Token + "' />" +
- " <input type='hidden' name='username' value='{0}' />" +
- " <input type='submit' value='start' name='action' />" +
- " <input type='submit' value='stop' name='action' />" +
- " <input type='submit' value='remove' name='action' />" +
- " <input type='submit' value='disconnect' name='action' />" +
- "</form>";
- var clientTable = new HtmlTable();
- clientTable.Tags["border"] = "2";
- clientTable.AddRow(new HtmlTable.Row("<b>Account</b>", "<b>Server</b>", "<b>Name</b>", "<b>Status</b>", "<b>Options</b>"));
- foreach (var client in HunterSettings.Cliented)
- {
- foreach (var set in HunterSettings.ClientHunters)
- {
- if (client.Username == set.Item2)
- {
- clientTable.AddRow(new HtmlTable.Row(client.Username, client.Server, client.Name, client.Hunting ? "Hunting" : "Not hunting.", string.Format(frmtOptions, client.Username)));
- break;
- }
- }
- }
- var accountedFor = new List<string>();
- foreach (var client in HunterSettings.StandaloneClients)
- {
- LoginData ld;
- if (HunterSettings.TryGetStandaloneData(client.Username, out ld))
- {
- accountedFor.Add(ld.User);
- clientTable.AddRow(new HtmlTable.Row(client.Username, ld.Server, client.Name, client.Hunting ? "Hunting" : "Not hunting.", string.Format(frmtOptions, client.Username)));
- break;
- }
- }
- foreach (var account in HunterSettings.StandaloneHunters)
- {
- if (!accountedFor.Contains(account.Item2.User))
- {
- var ld = account.Item2;
- clientTable.AddRow(new HtmlTable.Row(ld.User, ld.Server, "Not logged in", "Disconnected", string.Format(frmtOptions, ld.User)));
- }
- }
- // create the UI for adding an account to hunt sys
- var accountUI = new StringBuilder();
- accountUI.AppendLine("<form method='post'>");
- var accountUITable = new HtmlTable();
- accountUITable.AddRow(new HtmlTable.Row("Username: ", new HtmlForm.Text("username")));
- accountUITable.AddRow(new HtmlTable.Row("Password: ", new HtmlForm.Text("password")));
- accountUITable.AddRow(new HtmlTable.Row("Server: ", new HtmlForm.Text("server")));
- accountUITable.AddRow(new HtmlTable.Row("Profile: ", new HtmlForm.Text("profile")));
- accountUITable.AddRow(new HtmlTable.Row(new HtmlForm.SubmitButton("Add Account")));
- accountUI.AppendLine(accountUITable.ToString());
- accountUI.AppendLine("</form>");
- HttpServer.RenderUI(request, output, accountUI, sb, clientTable);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement