rendered paste bodyusing System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AscentCP.Properties;
namespace AscentCP
{
public partial class AscentCP : Form
{
const int ERROR_FILE_NOT_FOUND = 2;
const int ERROR_ACCESS_DENIED = 5;
Process logonProcess = new Process();
Process worldProcess = new Process();
public AscentCP()
{
InitializeComponent();
}
void logonProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
EventHandler eh = delegate {
lock (this.logonServerOutput) { this.logonServerOutput.AppendText(e.Data + "\n"); }
};
this.logonServerOutput.Invoke(eh);
}
void logonProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
EventHandler eh = delegate {
lock (this.logonServerOutput) { this.logonServerOutput.AppendText(e.Data + "\n"); }
};
this.logonServerOutput.Invoke(eh);
}
void worldProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
EventHandler eh = delegate {
lock (this.worldServerOutput) { this.worldServerOutput.AppendText(e.Data + "\n"); }
};
this.worldServerOutput.Invoke(eh);
}
void worldProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
EventHandler eh = delegate {
lock (this.worldServerOutput) { this.worldServerOutput.AppendText(e.Data + "\n"); }
};
this.worldServerOutput.Invoke(eh);
}
private void startServerButton_Click(object sender, EventArgs e)
{
if (!File.Exists(Settings.Default.logonServer))
{
MessageBox.Show("Logon Server not found at : " + Settings.Default.logonServer + "\n\nEdit your AscentCP.exe.config file with the correct path!", "Logon Server Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
else if (!File.Exists(Settings.Default.worldServer))
{
MessageBox.Show("World Server not found at : " + Settings.Default.worldServer + "\n\nEdit your AscentCP.exe.config file with the correct path!", "World Server Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
else
{
try
{
logonProcess.StartInfo.FileName = Settings.Default.logonServer;
logonProcess.StartInfo.Verb = "Open";
logonProcess.StartInfo.CreateNoWindow = true;
logonProcess.StartInfo.UseShellExecute = false;
logonProcess.StartInfo.RedirectStandardOutput = true;
logonProcess.StartInfo.RedirectStandardError = true;
logonProcess.OutputDataReceived += new DataReceivedEventHandler(logonProcess_OutputDataReceived);
logonProcess.ErrorDataReceived += new DataReceivedEventHandler(logonProcess_ErrorDataReceived);
logonProcess.Start();
logonProcess.BeginOutputReadLine();
logonProcess.BeginErrorReadLine();
worldProcess.StartInfo.FileName = Settings.Default.worldServer;
worldProcess.StartInfo.Verb = "Open";
worldProcess.StartInfo.CreateNoWindow = true;
worldProcess.StartInfo.UseShellExecute = false;
worldProcess.StartInfo.RedirectStandardOutput = true;
worldProcess.StartInfo.RedirectStandardError = true;
worldProcess.OutputDataReceived += new DataReceivedEventHandler(worldProcess_OutputDataReceived);
worldProcess.ErrorDataReceived += new DataReceivedEventHandler(worldProcess_ErrorDataReceived);
worldProcess.Start();
worldProcess.BeginOutputReadLine();
worldProcess.BeginErrorReadLine();
this.statusLabel.Text = "Online";
this.statusLabel.ForeColor = System.Drawing.Color.Green;
this.startServerButton.Enabled = false;
this.stopServerButton.Enabled = true;
}
catch (Win32Exception err)
{
if (err.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
MessageBox.Show("Server files not found.\n\nEdit your AscentCP.exe.config file with the correct path!", "Server Files Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
else if (err.NativeErrorCode == ERROR_ACCESS_DENIED)
{
MessageBox.Show(err.Message + ".\n\nYou do not have the permission to run the Ascent Logon/World Server.", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}
}
private void stopServerButton_Click(object sender, EventArgs e)
{
try
{
if (!logonProcess.HasExited)
{
logonProcess.Kill();
}
if (!worldProcess.HasExited)
{
worldProcess.Kill();
}
this.statusLabel.Text = "Offline";
this.statusLabel.ForeColor = System.Drawing.Color.Maroon;
this.stopServerButton.Enabled = false;
this.startServerButton.Enabled = true;
lock (this.logonServerOutput) { this.logonServerOutput.AppendText("Logon server stopped ...\n\n"); }
lock (this.worldServerOutput) { this.worldServerOutput.AppendText("World server stopped ...\n\n"); }
}
catch (Exception)
{
Application.Exit();
}
}
private void AscentCP_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (!logonProcess.HasExited)
{
logonProcess.Kill();
}
if (!worldProcess.HasExited)
{
worldProcess.Kill();
}
}
catch (Exception)
{
Application.Exit();
}
}
private void AscentCP_Load(object sender, EventArgs e)
{
this.stopServerButton.Enabled = false;
}
}
}