When i start the program, it simply freezes. I mean if i push any button, it doesn't work. Only button10 is working which is closing the form.
What is the problem here?
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 System.Diagnostics;
using System.IO;
using System.Threading;
namespace Samp_cpanel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Process p = new Process();
new bool running = false;
new bool loaded = false;
private void button1_Click(object sender, EventArgs e)
{
if (running == true)
{
MessageBox.Show("Server already running!", "Error!");
}
else
{
p.StartInfo.FileName = "samp-server.exe";
p.Start();
running = true;
Thread.Sleep(200);
Query.Query sQuery = new Query.Query("76.10.223.139", 7777);
sQuery.Send('i');
int count = sQuery.Recieve();
string[] info = sQuery.Store(count);
if (info.Length == 0)
{
hostname.Text = "The server is DOWN!";
}
else
{
Query.Query dQuery = new Query.Query("76.10.223.139", 7777);
dQuery.Send('c');
int c2 = dQuery.Recieve();
string[] pl = dQuery.Store(c2);
for (int i = 0; i < Convert.ToInt64(info[1])*2; i++)
{
ListViewItem lvi = new ListViewItem(pl[i]);
lvi.SubItems.Add(pl[i + 1]);
listView1.Items.Add(lvi);
i++;
}
hostname.Text = info[3];
players.Text = info[1] + " / " + info[2];
mapname.Text = info[5];
gmtext.Text = info[4];
}
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
p.Kill();
running = false;
}
catch { }
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
try
{
p.Kill();
p.Start();
}
catch { }
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = File.ReadAllText("server.cfg");
loaded = true;
}
private void button4_Click(object sender, EventArgs e)
{
if (loaded == false)
{
MessageBox.Show("You must load the cfg file", "Error!");
}
else
{
File.WriteAllText("server.cfg", textBox1.Text);
MessageBox.Show("The cfg file was totally edited", "Success!");
}
}
private void button6_Click(object sender, EventArgs e)
{
Query.RCONQuery jQuery = new Query.RCONQuery(textBox5.Text, Convert.ToInt16(textBox6.Text), textBox7.Text);
if (textBox2.Text == "")
{
if (textBox3.Text == "")
{
if (textBox4.Text == "")
{
}
else
{
jQuery.Send("mapname " + textBox4.Text);
}
}
else
{
jQuery.Send("gamemodetext " + textBox3.Text);
}
}
else
{
jQuery.Send("hostname " + textBox2.Text);
}
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
Query.Query cQuery = new Query.Query("127.0.0.1", 7777);
cQuery.Send('i');
int count = cQuery.Recieve();
string[] info = cQuery.Store(count);
if (info.Length == 0)
{
hostname.Text = "Serverul este DOWN!";
players.Text = "";
mapname.Text = "";
gmtext.Text = "";
}
else
{
hostname.Text = info[3];
players.Text = info[1] + " / " + info[2];
mapname.Text = info[5];
gmtext.Text = info[4];
}
}
private void button10_Click(object sender, EventArgs e)
{
this.Close();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}