Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Text;
- using System.IO;
- using System.Collections.Generic;
- using Renci.SshNet;
- using System.Threading;
- public partial class _Default : System.Web.UI.Page
- {
- static protected SftpClient client = new SftpClient("longlostbro.com", "longlostbro", "***********");
- static protected SshClient ssh = new SshClient("longlostbro.com", "longlostbro", "***********");
- static protected string datasource = "button3";
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!client.IsConnected)
- {
- client.Connect();
- }
- LoadData(sender, e);
- }
- protected void Timer1_Tick(object sender, EventArgs e)
- {/*
- if (!ssh.IsConnected)
- ssh.Connect();
- ssh.RunCommand("screen -S server -p lobby -X stuff \'" + TextBox1.Text + "\n\'");
- GridView.DataSource = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log");
- GridView.DataBind();*/
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- if (!ssh.IsConnected)
- ssh.Connect();
- ssh.RunCommand("screen -S server -p lobby -X stuff \'" + TextBox1.Text + "\n\'");
- ssh.Disconnect();
- TextBox1.Text = "";
- Thread.Sleep(300);
- LoadData(sender, e);
- }
- protected void LoadPlayers()
- {
- if (!ssh.IsConnected)
- ssh.Connect();
- List<string> players = new List<string>();
- if (!client.IsConnected)
- {
- client.Connect();
- }
- int lines = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Count();
- List<string> playersRaw = new List<string>();
- ssh.RunCommand("screen -S server -p lobby -X stuff \'" + "/list" + "\n\'");//17
- ssh.Disconnect();
- Thread.Sleep(100);
- playersRaw.AddRange(client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Skip(lines + 2));
- //for (int i = 0; i < playersRaw.Count(); i++)
- //players.Add(playersRaw[i].Substring(16));
- client.Disconnect();
- foreach (var item in playersRaw)
- {
- players.Add(item.Substring(32).Substring(item.Substring(32).IndexOf(':') + 1));
- }
- ListBox1.DataSource = players;
- ListBox1.DataBind();
- }
- protected void LoadData(object sender, EventArgs e)
- {
- if (datasource == "button2")
- {
- Button2_Click(sender, e);
- }
- else if (datasource == "button4")
- {
- Button4_Click(sender, e);
- }
- else //(datasource == "button3")
- {
- Button3_Click(sender, e);
- }
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- List<string> templist = new List<string>();
- templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("ERROR")));
- templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("WARN")));
- datasource = "button2";
- GridView.DataSource = templist;
- GridView.DataBind();
- }
- protected void Button3_Click(object sender, EventArgs e)
- {
- datasource = "Button3";
- GridView.DataSource = client.ReadAllLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log");
- GridView.DataBind();
- }
- protected void Button4_Click(object sender, EventArgs e)
- {
- List<string> templist = new List<string>();
- templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("[GLOBAL]")));
- templist.AddRange(client.ReadLines(@"/home/longlostbro/servers/minecraft/Minecraft/logs/latest.log").Where(x => x.Contains("[Server]")));
- datasource = "button4";
- templist.Sort();
- GridView.DataSource = templist;
- GridView.DataBind();
- }
- protected void Button5_Click(object sender, EventArgs e)
- {
- LoadPlayers();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement