Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Tamir.SharpSsh;
- using System.Collections;
- using System.IO;
- namespace mc_connect
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public class Util
- {
- /// <summary>
- /// Get input from the user
- /// </summary>
- ///
- public static SshConnectionInfo GetInput()
- {
- string sFilename = @"server.txt";
- string sContent = "";
- StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
- sContent = myFile.ReadToEnd();
- myFile.Close();
- string[] words = sContent.Split(':');
- SshConnectionInfo info = new SshConnectionInfo();
- info.Host = words[0];
- info.User = words[1];
- info.Pass = words[2];
- return info;
- }
- }
- public struct SshConnectionInfo
- {
- public string Host;
- public string User;
- public string Pass;
- public string IdentityFile;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- string sFilename = @"server.txt";
- string sContent = "";
- StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
- sContent = myFile.ReadToEnd();
- myFile.Close();
- string[] words = sContent.Split(':');
- SshConnectionInfo input = Util.GetInput();
- SshExec exec = new SshExec(input.Host, input.User);
- if (input.Pass != null) exec.Password = input.Pass;
- if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
- exec.Connect();
- //Command der ausgeführt wird
- string[] path = words[3].Split('/');
- string cd = string.Empty;
- foreach (string x in path)
- {
- cd = cd + "cd " + x + "&&";
- }
- exec.RunCommand(cd + "screen -dmSL mcserver java -Xincgc -Xmx3000m -jar craftbukkit.jar ");
- exec.Close();
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- SshConnectionInfo input = Util.GetInput();
- SshExec exec = new SshExec(input.Host, input.User);
- if (input.Pass != null) exec.Password = input.Pass;
- if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
- exec.Connect();
- //Command der ausgeführt wird
- exec.RunCommand("screen -r mcserver -X quit");
- exec.Close();
- }
- void fillinforms()
- {
- string sFilename = @"server.txt";
- string sContent = "";
- StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
- sContent = myFile.ReadToEnd();
- myFile.Close();
- string[] words = sContent.Split(':');
- for (int i = 0; i < words.Length; i++)
- {
- string x = words[i];
- switch (i)
- {
- case 0:
- textBox2.Text = x;
- break;
- case 1:
- textBox1.Text = x;
- break;
- case 2:
- textBox4.Text = x;
- break;
- case 3:
- textBox3.Text = x;
- break;
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- fillinforms();
- }
- private void tabPage2_Click(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- //build the string for txt
- string write = string.Empty;
- write = textBox2.Text + ":" + textBox1.Text + ":" + textBox4.Text + ":" + textBox3.Text;
- StreamWriter myFile = new StreamWriter("server.txt");
- myFile.Write(write);
- myFile.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement