Advertisement
Guest User

Untitled

a guest
Feb 25th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.66 KB | None | 0 0
  1.     internal class HuntSysUI : IConquerAIWebUI
  2.     {
  3.         public string Name { get { return "Hunter System"; } }
  4.         public string Page { get { return "/huntsys.html"; } }
  5.  
  6.         public void RenderUI(UriQuery urlQuery, HttpListenerContext context, HttpListenerRequest request, HttpListenerResponse response, StreamWriter output)
  7.         {
  8.             //
  9.             // update fields / handle input, etc.
  10.             //
  11.             string value;
  12.             if (urlQuery.TryGetField("quality", out value))
  13.                 HunterSettings.MinQuality = (LootQuality)Math.Max(int.Parse(value), (int)LootQuality.Refined);
  14.             if (urlQuery.TryGetField("bless", out value))
  15.                 HunterSettings.MinBless = Math.Min(7, Math.Max(int.Parse(value), 1));
  16.             if (urlQuery.TryGetField("tradeadd", out value))
  17.                 HunterSettings.TradeAddItems = (value == "on");
  18.             if (urlQuery.TryGetField("usetraders", out value))
  19.                 HunterSettings.UseTraders = (value == "on");
  20.             if (urlQuery.TryGetField("username", out value))
  21.             {
  22.                 string password, server, profile, action;
  23.                 if (urlQuery.TryGetField("password", out password) &&
  24.                     urlQuery.TryGetField("server", out server) &&
  25.                     urlQuery.TryGetField("profile", out profile))
  26.                 {
  27.                     HunterSettings.AddHunter(value, password, server, profile);
  28.                     HttpServer.LogMessage("Attempting to add hunter... {0}, {1}", value, server);
  29.                 }
  30.                 else if (urlQuery.TryGetField("action", out action))
  31.                 {
  32.                     LoginData ld;
  33.                     COFarmerClient inst;
  34.                     switch (action)
  35.                     {
  36.                         case "disconnect":
  37.                             if (HunterSettings.TryGetStandaloneData(value, out ld))
  38.                                 HunterSettings.DisconnectStandalone(ld);
  39.                             else if (HunterSettings.TryGetCliented(value, out inst))
  40.                                 HunterSettings.DisconnectClient(inst);
  41.                             break;
  42.                         case "remove":
  43.                             if (HunterSettings.TryGetStandaloneData(value, out ld))
  44.                                 HunterSettings.RemoveStandalone(ld);
  45.                             else if (HunterSettings.TryGetCliented(value, out inst))
  46.                                 HunterSettings.RemoveClient(inst);
  47.                             break;
  48.                         case "stop":
  49.                             if (HunterSettings.TryGetStandaloneData(value, out ld))
  50.                                 HunterSettings.StopStandalone(ld);
  51.                             else if (HunterSettings.TryGetCliented(value, out inst))
  52.                                 HunterSettings.StopClient(inst); ;
  53.                             break;
  54.                         case "start":
  55.                             if (HunterSettings.TryGetStandaloneData(value, out ld))
  56.                                 HunterSettings.StartStandalone(ld);
  57.                             else if (HunterSettings.TryGetCliented(value, out inst))
  58.                                 HunterSettings.StartClient(inst);
  59.                             break;
  60.                     }
  61.                 }
  62.             }
  63.             //
  64.             //
  65.             //
  66.  
  67.             // render left side panel
  68.             // min quality, bless, trade +, use traders
  69.             var sb = new StringBuilder();
  70.             sb.AppendLine("<form>");
  71.  
  72.             var minQuality = new StringBuilder();
  73.             minQuality.Append(new HtmlForm.RadioButton("quality", "6", HunterSettings.MinQuality == LootQuality.Refined) + " Refined<br>");
  74.             minQuality.Append(new HtmlForm.RadioButton("quality", "7", HunterSettings.MinQuality == LootQuality.Unique) + " Unique<br>");
  75.             minQuality.Append(new HtmlForm.RadioButton("quality", "8", HunterSettings.MinQuality == LootQuality.Elite) + " Elite<br>");
  76.             minQuality.Append(new HtmlForm.RadioButton("quality", "9", HunterSettings.MinQuality == LootQuality.Super) + " Super");
  77.  
  78.             var minBless = new StringBuilder();
  79.             minBless.Append(new HtmlForm.RadioButton("bless", "1", HunterSettings.MinBless < 3) + " -1 %<br>");
  80.             minBless.Append(new HtmlForm.RadioButton("bless", "3", HunterSettings.MinBless == 3) + " -3 %<br>");
  81.             minBless.Append(new HtmlForm.RadioButton("bless", "5", HunterSettings.MinBless == 5) + " -5 %<br>");
  82.             minBless.Append(new HtmlForm.RadioButton("bless", "7", HunterSettings.MinBless > 5) + " -7 %");
  83.  
  84.             var table = new HtmlTable();
  85.             table.AddRow(new HtmlTable.Row("Trade Min. Quality", minQuality));
  86.             table.AddRow(new HtmlTable.Row("Trade Min. Bless", minBless));
  87.             table.AddRow(new HtmlTable.Row("Trade Add Items", new HtmlForm.CheckBox("tradeadd", HunterSettings.TradeAddItems)));
  88.             table.AddRow(new HtmlTable.Row("Use Traders", new HtmlForm.CheckBox("usetraders", HunterSettings.UseTraders)));
  89.             table.AddRow(new HtmlTable.Row(new HtmlForm.SubmitButton("Apply Changes")));
  90.  
  91.             sb.AppendLine(table.ToString());
  92.             sb.AppendLine(new HtmlForm.Hidden("token", HttpServer.Token).ToString());
  93.             sb.AppendLine("</form>");
  94.  
  95.             // to-do render logged in client list...
  96.             string frmtOptions = "<form method='post'>" +
  97.                                    " <input type='hidden' name='token' value='" + HttpServer.Token + "' />" +
  98.                                    " <input type='hidden' name='username' value='{0}' />" +
  99.                                    " <input type='submit' value='start' name='action' />" +
  100.                                    " <input type='submit' value='stop' name='action' />" +
  101.                                    " <input type='submit' value='remove' name='action' />" +
  102.                                    " <input type='submit' value='disconnect' name='action' />" +
  103.                                    "</form>";
  104.  
  105.             var clientTable = new HtmlTable();
  106.             clientTable.Tags["border"] = "2";
  107.             clientTable.AddRow(new HtmlTable.Row("<b>Account</b>", "<b>Server</b>", "<b>Name</b>", "<b>Status</b>", "<b>Options</b>"));
  108.             foreach (var client in HunterSettings.Cliented)
  109.             {
  110.                 foreach (var set in HunterSettings.ClientHunters)
  111.                 {
  112.                     if (client.Username == set.Item2)
  113.                     {
  114.                         clientTable.AddRow(new HtmlTable.Row(client.Username, client.Server, client.Name, client.Hunting ? "Hunting" : "Not hunting.", string.Format(frmtOptions, client.Username)));
  115.                         break;
  116.                     }
  117.                 }
  118.             }
  119.             var accountedFor = new List<string>();
  120.             foreach (var client in HunterSettings.StandaloneClients)
  121.             {
  122.                 LoginData ld;
  123.                 if (HunterSettings.TryGetStandaloneData(client.Username, out ld))
  124.                 {
  125.                     accountedFor.Add(ld.User);
  126.                     clientTable.AddRow(new HtmlTable.Row(client.Username, ld.Server, client.Name, client.Hunting ? "Hunting" : "Not hunting.", string.Format(frmtOptions, client.Username)));
  127.                     break;
  128.                 }
  129.             }
  130.             foreach (var account in HunterSettings.StandaloneHunters)
  131.             {
  132.                 if (!accountedFor.Contains(account.Item2.User))
  133.                 {
  134.                     var ld = account.Item2;
  135.                     clientTable.AddRow(new HtmlTable.Row(ld.User, ld.Server, "Not logged in", "Disconnected", string.Format(frmtOptions, ld.User)));
  136.                 }
  137.             }
  138.  
  139.             // create the UI for adding an account to hunt sys
  140.             var accountUI = new StringBuilder();
  141.             accountUI.AppendLine("<form method='post'>");
  142.             var accountUITable = new HtmlTable();
  143.             accountUITable.AddRow(new HtmlTable.Row("Username: ", new HtmlForm.Text("username")));
  144.             accountUITable.AddRow(new HtmlTable.Row("Password: ", new HtmlForm.Text("password")));
  145.             accountUITable.AddRow(new HtmlTable.Row("Server: ", new HtmlForm.Text("server")));
  146.             accountUITable.AddRow(new HtmlTable.Row("Profile: ", new HtmlForm.Text("profile")));
  147.             accountUITable.AddRow(new HtmlTable.Row(new HtmlForm.SubmitButton("Add Account")));
  148.             accountUI.AppendLine(accountUITable.ToString());
  149.             accountUI.AppendLine("</form>");
  150.  
  151.             HttpServer.RenderUI(request, output, accountUI, sb, clientTable);
  152.         }
  153.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement