Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Tamir.SharpSsh;
  10. using System.Collections;
  11. using System.IO;
  12.  
  13. namespace mc_connect
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20.  
  21.  
  22. }
  23.  
  24. public class Util
  25. {
  26. /// <summary>
  27. /// Get input from the user
  28. /// </summary>
  29. ///
  30.  
  31. public static SshConnectionInfo GetInput()
  32. {
  33. string sFilename = @"server.txt";
  34. string sContent = "";
  35. StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
  36. sContent = myFile.ReadToEnd();
  37. myFile.Close();
  38.  
  39. string[] words = sContent.Split(':');
  40.  
  41.  
  42. SshConnectionInfo info = new SshConnectionInfo();
  43.  
  44. info.Host = words[0];
  45.  
  46. info.User = words[1];
  47.  
  48. info.Pass = words[2];
  49.  
  50.  
  51.  
  52.  
  53. return info;
  54. }
  55.  
  56. }
  57.  
  58. public struct SshConnectionInfo
  59. {
  60. public string Host;
  61. public string User;
  62. public string Pass;
  63. public string IdentityFile;
  64. }
  65.  
  66.  
  67.  
  68. private void button1_Click(object sender, EventArgs e)
  69. {
  70.  
  71. }
  72.  
  73. private void button2_Click(object sender, EventArgs e)
  74. {
  75.  
  76.  
  77. }
  78.  
  79. private void button1_Click_1(object sender, EventArgs e)
  80. {
  81. string sFilename = @"server.txt";
  82. string sContent = "";
  83. StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
  84. sContent = myFile.ReadToEnd();
  85. myFile.Close();
  86. string[] words = sContent.Split(':');
  87.  
  88.  
  89. SshConnectionInfo input = Util.GetInput();
  90. SshExec exec = new SshExec(input.Host, input.User);
  91. if (input.Pass != null) exec.Password = input.Pass;
  92. if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
  93.  
  94.  
  95. exec.Connect();
  96.  
  97. //Command der ausgeführt wird
  98.  
  99. string[] path = words[3].Split('/');
  100.  
  101. string cd = string.Empty;
  102.  
  103. foreach (string x in path)
  104. {
  105. cd = cd + "cd " + x + "&&";
  106.  
  107.  
  108. }
  109.  
  110. exec.RunCommand(cd + "screen -dmSL mcserver java -Xincgc -Xmx3000m -jar craftbukkit.jar ");
  111.  
  112.  
  113.  
  114. exec.Close();
  115.  
  116. }
  117.  
  118. private void button2_Click_1(object sender, EventArgs e)
  119. {
  120. SshConnectionInfo input = Util.GetInput();
  121. SshExec exec = new SshExec(input.Host, input.User);
  122. if (input.Pass != null) exec.Password = input.Pass;
  123. if (input.IdentityFile != null) exec.AddIdentityFile(input.IdentityFile);
  124.  
  125.  
  126. exec.Connect();
  127.  
  128. //Command der ausgeführt wird
  129.  
  130. exec.RunCommand("screen -r mcserver -X quit");
  131.  
  132.  
  133.  
  134. exec.Close();
  135. }
  136.  
  137. void fillinforms()
  138. {
  139. string sFilename = @"server.txt";
  140. string sContent = "";
  141. StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
  142. sContent = myFile.ReadToEnd();
  143. myFile.Close();
  144. string[] words = sContent.Split(':');
  145.  
  146.  
  147. for (int i = 0; i < words.Length; i++)
  148. {
  149. string x = words[i];
  150. switch (i)
  151. {
  152. case 0:
  153. textBox2.Text = x;
  154. break;
  155. case 1:
  156. textBox1.Text = x;
  157. break;
  158. case 2:
  159. textBox4.Text = x;
  160. break;
  161. case 3:
  162. textBox3.Text = x;
  163. break;
  164. }
  165.  
  166.  
  167.  
  168. }
  169. }
  170.  
  171. private void Form1_Load(object sender, EventArgs e)
  172. {
  173. fillinforms();
  174.  
  175.  
  176. }
  177.  
  178. private void tabPage2_Click(object sender, EventArgs e)
  179. {
  180.  
  181. }
  182.  
  183. private void button3_Click(object sender, EventArgs e)
  184. {
  185. //build the string for txt
  186.  
  187. string write = string.Empty;
  188.  
  189. write = textBox2.Text + ":" + textBox1.Text + ":" + textBox4.Text + ":" + textBox3.Text;
  190.  
  191. StreamWriter myFile = new StreamWriter("server.txt");
  192. myFile.Write(write);
  193. myFile.Close();
  194.  
  195.  
  196. }
  197.  
  198.  
  199.  
  200.  
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement