Advertisement
Guest User

ScrollWAjax.aspx.cs

a guest
Jun 24th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Configuration;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Xml.Linq;
  12. using System.Text;
  13. using System.IO;
  14. using System.Collections.Generic;
  15. using Renci.SshNet;
  16. using System.Threading;
  17.  
  18. public partial class _Default : System.Web.UI.Page
  19. {
  20.     static protected SftpClient client = new SftpClient("longlostbro.com", "longlostbro", "***********");
  21.     static protected SshClient ssh = new SshClient("longlostbro.com", "longlostbro", "***********");
  22.     static protected string datasource = "button3";
  23.     protected void Page_Load(object sender, EventArgs e)
  24.     {
  25.         if (!client.IsConnected)
  26.         {
  27.             client.Connect();
  28.         }
  29.         LoadData(sender, e);
  30.     }
  31.     protected void Timer1_Tick(object sender, EventArgs e)
  32.     {/*
  33.         if (!ssh.IsConnected)
  34.             ssh.Connect();
  35.         ssh.RunCommand("screen -S server -p lobby -X stuff \'" + TextBox1.Text + "\n\'");
  36.         GridView.DataSource = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log");
  37.         GridView.DataBind();*/
  38.     }
  39.     protected void Button1_Click(object sender, EventArgs e)
  40.     {
  41.         if (!ssh.IsConnected)
  42.             ssh.Connect();
  43.         ssh.RunCommand("screen -S server -p lobby -X stuff \'" + TextBox1.Text + "\n\'");
  44.         ssh.Disconnect();
  45.         TextBox1.Text = "";
  46.         Thread.Sleep(300);
  47.         LoadData(sender, e);
  48.     }
  49.     protected void LoadPlayers()
  50.     {
  51.         if (!ssh.IsConnected)
  52.             ssh.Connect();
  53.         List<string> players = new List<string>();
  54.         if (!client.IsConnected)
  55.         {
  56.             client.Connect();
  57.         }
  58.         int lines = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Count();
  59.         List<string> playersRaw = new List<string>();
  60.         ssh.RunCommand("screen -S server -p lobby -X stuff \'" + "/list" + "\n\'");//17
  61.         ssh.Disconnect();
  62.         Thread.Sleep(100);
  63.         playersRaw.AddRange(client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Skip(lines + 2));
  64.         //for (int i = 0; i < playersRaw.Count(); i++)
  65.         //players.Add(playersRaw[i].Substring(16));
  66.         client.Disconnect();
  67.         foreach (var item in playersRaw)
  68.         {
  69.             players.Add(item.Substring(32).Substring(item.Substring(32).IndexOf(':') + 1));
  70.         }
  71.         ListBox1.DataSource = players;
  72.         ListBox1.DataBind();
  73.  
  74.     }
  75.     protected void LoadData(object sender, EventArgs e)
  76.     {
  77.  
  78.         if (datasource == "button2")
  79.         {
  80.             Button2_Click(sender, e);
  81.         }
  82.         else if (datasource == "button4")
  83.         {
  84.             Button4_Click(sender, e);
  85.         }
  86.         else //(datasource == "button3")
  87.         {
  88.             Button3_Click(sender, e);
  89.         }
  90.     }
  91.     protected void Button2_Click(object sender, EventArgs e)
  92.     {
  93.         List<string> templist = new List<string>();
  94.         templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("ERROR")));
  95.         templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("WARN")));
  96.         datasource = "button2";
  97.         GridView.DataSource = templist;
  98.         GridView.DataBind();
  99.     }
  100.     protected void Button3_Click(object sender, EventArgs e)
  101.     {
  102.         datasource = "Button3";
  103.         GridView.DataSource = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log");
  104.         GridView.DataBind();
  105.     }
  106.     protected void Button4_Click(object sender, EventArgs e)
  107.     {
  108.         List<string> templist = new List<string>();
  109.         templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("[GLOBAL]")));
  110.         templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("[Server]")));
  111.         datasource = "button4";
  112.         templist.Sort();
  113.         GridView.DataSource = templist;
  114.         GridView.DataBind();
  115.     }
  116.     protected void Button5_Click(object sender, EventArgs e)
  117.     {
  118.         LoadPlayers();
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement