mirror of
https://github.com/islehorse/HISP.git
synced 2025-05-09 21:05:07 +12:00
Allow HISP Noobs to run even w a web server already running
This commit is contained in:
parent
62e1a7a122
commit
994dc382c8
4 changed files with 260 additions and 247 deletions
HorseIsleServer
Binary file not shown.
|
@ -277,11 +277,11 @@ namespace HTTP
|
||||||
e.AcceptSocket = null;
|
e.AcceptSocket = null;
|
||||||
} while (!ServerSocket.AcceptAsync(e));
|
} while (!ServerSocket.AcceptAsync(e));
|
||||||
}
|
}
|
||||||
public ContentServer()
|
public ContentServer(string ip)
|
||||||
{
|
{
|
||||||
|
|
||||||
WriteDebugOutput("Listening for connections on port 80.");
|
WriteDebugOutput("Listening for connections on port 80.");
|
||||||
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80);
|
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), 80);
|
||||||
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
ServerSocket.Bind(ep);
|
ServerSocket.Bind(ep);
|
||||||
ServerSocket.Listen(0x7fffffff);
|
ServerSocket.Listen(0x7fffffff);
|
||||||
|
|
|
@ -1,165 +1,178 @@
|
||||||
// An HTTP Server, and Horse Isle Server, Flash Player, in a single package
|
// An HTTP Server, and Horse Isle Server, Flash Player, in a single package
|
||||||
// Idea is to just be open and play.
|
// Idea is to just be open and play.
|
||||||
|
|
||||||
using HISP.Game;
|
using HISP.Game;
|
||||||
using HISP.Game.Horse;
|
using HISP.Game.Horse;
|
||||||
using HISP.Game.Items;
|
using HISP.Game.Items;
|
||||||
using HISP.Game.Services;
|
using HISP.Game.Services;
|
||||||
using HISP.Game.SwfModules;
|
using HISP.Game.SwfModules;
|
||||||
using HISP.Security;
|
using HISP.Security;
|
||||||
using HISP.Server;
|
using HISP.Server;
|
||||||
using HTTP;
|
using HTTP;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace HISP
|
namespace HISP
|
||||||
{
|
{
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
private static LoadingForm lfrm;
|
public static Random rand = new Random(Guid.NewGuid().GetHashCode());
|
||||||
public static string BaseDir;
|
private static LoadingForm lfrm;
|
||||||
private static ContentServer cs;
|
public static string IP;
|
||||||
private static void addToList(string path)
|
public static string BaseDir;
|
||||||
{
|
private static ContentServer cs;
|
||||||
string Name = path.Remove(0, Path.Combine(Directory.GetCurrentDirectory(), "client").Length);
|
private static void addToList(string path)
|
||||||
Name = Name.Replace("\\", "/");
|
{
|
||||||
|
string Name = path.Remove(0, Path.Combine(Directory.GetCurrentDirectory(), "client").Length);
|
||||||
ContentItem ci = new ContentItem(Name, path);
|
Name = Name.Replace("\\", "/");
|
||||||
cs.Contents.Add(ci);
|
|
||||||
|
ContentItem ci = new ContentItem(Name, path);
|
||||||
}
|
cs.Contents.Add(ci);
|
||||||
|
|
||||||
public static void OnShutdown()
|
}
|
||||||
{
|
|
||||||
if(!Process.GetCurrentProcess().CloseMainWindow())
|
public static void OnShutdown()
|
||||||
Process.GetCurrentProcess().Close();
|
{
|
||||||
}
|
if (!Process.GetCurrentProcess().CloseMainWindow())
|
||||||
|
Process.GetCurrentProcess().Close();
|
||||||
public static void StartLRFrm()
|
}
|
||||||
{
|
|
||||||
if (lfrm.ShowDialog() == DialogResult.Cancel)
|
public static void StartLRFrm()
|
||||||
{
|
{
|
||||||
GameServer.ShutdownServer();
|
if (lfrm.ShowDialog() == DialogResult.Cancel)
|
||||||
}
|
{
|
||||||
}
|
GameServer.ShutdownServer();
|
||||||
|
}
|
||||||
public static void IncrementProgress()
|
}
|
||||||
{
|
|
||||||
if (lfrm.InvokeRequired)
|
public static void IncrementProgress()
|
||||||
{
|
{
|
||||||
lfrm.Invoke(() =>
|
if (lfrm.InvokeRequired)
|
||||||
{
|
{
|
||||||
lfrm.StartProgress.Increment(1);
|
lfrm.Invoke(() =>
|
||||||
});
|
{
|
||||||
}
|
lfrm.StartProgress.Increment(1);
|
||||||
else
|
});
|
||||||
{
|
}
|
||||||
lfrm.StartProgress.Increment(1);
|
else
|
||||||
}
|
{
|
||||||
}
|
lfrm.StartProgress.Increment(1);
|
||||||
|
}
|
||||||
public static void Main(string[] args)
|
}
|
||||||
{
|
public static string GetOctlet()
|
||||||
|
{
|
||||||
|
return rand.Next(0, 255).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GenIP()
|
||||||
|
{
|
||||||
|
return "127" + "." + GetOctlet() + "." + GetOctlet() + "." + GetOctlet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
BaseDir = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "HISP", "N00BS");
|
BaseDir = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "HISP", "N00BS");
|
||||||
Directory.CreateDirectory(BaseDir);
|
Directory.CreateDirectory(BaseDir);
|
||||||
|
IP = GenIP();
|
||||||
|
|
||||||
lfrm = new LoadingForm();
|
lfrm = new LoadingForm();
|
||||||
Task startForm = new Task(StartLRFrm);
|
Task startForm = new Task(StartLRFrm);
|
||||||
startForm.Start();
|
startForm.Start();
|
||||||
|
|
||||||
ConfigReader.ConfigurationFileName = Path.Combine(BaseDir, "server.properties");
|
ConfigReader.ConfigurationFileName = Path.Combine(BaseDir, "server.properties");
|
||||||
ConfigReader.OpenConfig();
|
ConfigReader.OpenConfig();
|
||||||
ConfigReader.SqlLite = true;
|
ConfigReader.SqlLite = true;
|
||||||
ConfigReader.LogLevel = 0;
|
ConfigReader.LogLevel = 0;
|
||||||
ConfigReader.BindIP = "127.0.0.1";
|
ConfigReader.BindIP = IP;
|
||||||
ConfigReader.CrossDomainPolicyFile = Path.Combine(BaseDir, "CrossDomainPolicy.xml");
|
ConfigReader.CrossDomainPolicyFile = Path.Combine(BaseDir, "CrossDomainPolicy.xml");
|
||||||
ConfigReader.DatabaseName = Path.Combine(BaseDir, "game1.db");
|
ConfigReader.DatabaseName = Path.Combine(BaseDir, "game1.db");
|
||||||
|
|
||||||
IncrementProgress();
|
IncrementProgress();
|
||||||
Database.OpenDatabase();
|
Database.OpenDatabase();
|
||||||
IncrementProgress();
|
IncrementProgress();
|
||||||
|
|
||||||
if (Database.GetUsers().Length <= 0)
|
|
||||||
{
|
if (Database.GetUsers().Length <= 0)
|
||||||
RegisterForm rfrm = new RegisterForm();
|
{
|
||||||
if (rfrm.ShowDialog() == DialogResult.Cancel)
|
RegisterForm rfrm = new RegisterForm();
|
||||||
GameServer.ShutdownServer();
|
if (rfrm.ShowDialog() == DialogResult.Cancel)
|
||||||
|
GameServer.ShutdownServer();
|
||||||
}
|
|
||||||
|
}
|
||||||
// Start Web Server
|
|
||||||
try{
|
// Start Web Server
|
||||||
cs = new ContentServer();
|
try{
|
||||||
string[] fileList = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),"client"), "*", SearchOption.AllDirectories);
|
cs = new ContentServer(IP);
|
||||||
foreach (string file in fileList)
|
string[] fileList = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),"client"), "*", SearchOption.AllDirectories);
|
||||||
addToList(file);
|
foreach (string file in fileList)
|
||||||
}catch(Exception e){
|
addToList(file);
|
||||||
MessageBox.Show("Web server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}catch(Exception e){
|
||||||
return;
|
MessageBox.Show("Web server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
IncrementProgress();
|
|
||||||
|
IncrementProgress();
|
||||||
// Start HI1 Server
|
|
||||||
Logger.SetCallback(Console.WriteLine);
|
// Start HI1 Server
|
||||||
IncrementProgress();
|
Logger.SetCallback(Console.WriteLine);
|
||||||
|
IncrementProgress();
|
||||||
Entry.SetShutdownCallback(OnShutdown);
|
|
||||||
IncrementProgress();
|
Entry.SetShutdownCallback(OnShutdown);
|
||||||
|
IncrementProgress();
|
||||||
CrossDomainPolicy.GetPolicy();
|
|
||||||
IncrementProgress();
|
CrossDomainPolicy.GetPolicy();
|
||||||
|
IncrementProgress();
|
||||||
GameDataJson.ReadGamedata();
|
|
||||||
IncrementProgress();
|
GameDataJson.ReadGamedata();
|
||||||
|
IncrementProgress();
|
||||||
Map.OpenMap();
|
|
||||||
IncrementProgress();
|
Map.OpenMap();
|
||||||
|
IncrementProgress();
|
||||||
World.ReadWorldData();
|
|
||||||
IncrementProgress();
|
World.ReadWorldData();
|
||||||
|
IncrementProgress();
|
||||||
Treasure.Init();
|
|
||||||
IncrementProgress();
|
Treasure.Init();
|
||||||
|
IncrementProgress();
|
||||||
DroppedItems.Init();
|
|
||||||
IncrementProgress();
|
DroppedItems.Init();
|
||||||
|
IncrementProgress();
|
||||||
WildHorse.Init();
|
|
||||||
IncrementProgress();
|
WildHorse.Init();
|
||||||
|
IncrementProgress();
|
||||||
Drawingroom.LoadAllDrawingRooms();
|
|
||||||
IncrementProgress();
|
Drawingroom.LoadAllDrawingRooms();
|
||||||
|
IncrementProgress();
|
||||||
Brickpoet.LoadPoetryRooms();
|
|
||||||
IncrementProgress();
|
Brickpoet.LoadPoetryRooms();
|
||||||
|
IncrementProgress();
|
||||||
Multiroom.CreateMultirooms();
|
|
||||||
IncrementProgress();
|
Multiroom.CreateMultirooms();
|
||||||
|
IncrementProgress();
|
||||||
Auction.LoadAllAuctionRooms();
|
|
||||||
IncrementProgress();
|
Auction.LoadAllAuctionRooms();
|
||||||
|
IncrementProgress();
|
||||||
Item.DoSpecialCases();
|
|
||||||
IncrementProgress();
|
Item.DoSpecialCases();
|
||||||
try{
|
IncrementProgress();
|
||||||
GameServer.StartServer();
|
try{
|
||||||
}catch(Exception e){
|
GameServer.StartServer();
|
||||||
MessageBox.Show("Horse Isle server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}catch(Exception e){
|
||||||
return;
|
MessageBox.Show("Horse Isle server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
return;
|
||||||
IncrementProgress();
|
}
|
||||||
|
IncrementProgress();
|
||||||
lfrm.DialogResult = DialogResult.OK;
|
|
||||||
|
lfrm.DialogResult = DialogResult.OK;
|
||||||
SystemTrayIcon stry = new SystemTrayIcon();
|
|
||||||
stry.ShowDialog();
|
SystemTrayIcon stry = new SystemTrayIcon();
|
||||||
|
stry.ShowDialog();
|
||||||
// Finally, shutdown server
|
|
||||||
GameServer.ShutdownServer();
|
// Finally, shutdown server
|
||||||
}
|
GameServer.ShutdownServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
using HISP.Server;
|
using HISP.Server;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace HISP
|
namespace HISP
|
||||||
{
|
{
|
||||||
public partial class SystemTrayIcon : Form
|
public partial class SystemTrayIcon : Form
|
||||||
{
|
{
|
||||||
Process clientProcess = new Process();
|
Process clientProcess = new Process();
|
||||||
|
|
||||||
public SystemTrayIcon()
|
public SystemTrayIcon()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
disableSwearFilterToolStripMenuItem.Checked = !ConfigReader.BadWords;
|
disableSwearFilterToolStripMenuItem.Checked = !ConfigReader.BadWords;
|
||||||
disableCorrectionsToolStripMenuItem.Checked = !ConfigReader.DoCorrections;
|
disableCorrectionsToolStripMenuItem.Checked = !ConfigReader.DoCorrections;
|
||||||
disableNonvioChecksToolStripMenuItem.Checked = !ConfigReader.DoNonViolations;
|
disableNonvioChecksToolStripMenuItem.Checked = !ConfigReader.DoNonViolations;
|
||||||
disableSpamFilterToolStripMenuItem.Checked = !ConfigReader.EnableSpamFilter;
|
disableSpamFilterToolStripMenuItem.Checked = !ConfigReader.EnableSpamFilter;
|
||||||
|
|
||||||
allUsersSubscribedToolStripMenuItem.Checked = ConfigReader.AllUsersSubbed;
|
allUsersSubscribedToolStripMenuItem.Checked = ConfigReader.AllUsersSubbed;
|
||||||
fixOfficalBugsToolStripMenuItem.Checked = ConfigReader.FixOfficalBugs;
|
fixOfficalBugsToolStripMenuItem.Checked = ConfigReader.FixOfficalBugs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewUserToolStripMenuItem_Click(object sender, EventArgs e)
|
private void createNewUserToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
RegisterForm frm = new RegisterForm();
|
RegisterForm frm = new RegisterForm();
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeServerToolStripMenuItem_Click(object sender, EventArgs e)
|
private void closeServerToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SystemTrayIcon_Load(object sender, EventArgs e)
|
private void SystemTrayIcon_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
clientProcess.StartInfo.FileName = "flash.dll";
|
clientProcess.StartInfo.FileName = "flash.dll";
|
||||||
clientProcess.StartInfo.Arguments = "http://127.0.0.1/horseisle.swf?SERVER=127.0.0.1&PORT=12321";
|
clientProcess.StartInfo.Arguments = "http://"+ Program.IP +"/horseisle.swf?SERVER="+ Program.IP +"&PORT=12321";
|
||||||
|
|
||||||
clientProcess.StartInfo.RedirectStandardOutput = true;
|
clientProcess.StartInfo.RedirectStandardOutput = true;
|
||||||
clientProcess.StartInfo.RedirectStandardError = true;
|
clientProcess.StartInfo.RedirectStandardError = true;
|
||||||
|
|
||||||
clientProcess.EnableRaisingEvents = true;
|
clientProcess.EnableRaisingEvents = true;
|
||||||
clientProcess.Exited += clientExited;
|
clientProcess.Exited += clientExited;
|
||||||
clientProcess.Start();
|
clientProcess.Start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clientExited(object sender, EventArgs e)
|
private void clientExited(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (this.InvokeRequired)
|
if (this.InvokeRequired)
|
||||||
{
|
{
|
||||||
this.Invoke(() =>
|
this.Invoke(() =>
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SystemTrayIcon_FormClosing(object sender, FormClosingEventArgs e)
|
private void SystemTrayIcon_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
HispNotifyIcon.Visible = false;
|
HispNotifyIcon.Visible = false;
|
||||||
clientProcess.Kill();
|
clientProcess.Kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editServerPropertiesToolStripMenuItem_Click(object sender, EventArgs e)
|
private void editServerPropertiesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -87,20 +87,20 @@ namespace HISP
|
||||||
|
|
||||||
private void ModifyConfig(string okey, string value)
|
private void ModifyConfig(string okey, string value)
|
||||||
{
|
{
|
||||||
string[] configFile = File.ReadAllLines(ConfigReader.ConfigurationFileName);
|
string[] configFile = File.ReadAllLines(ConfigReader.ConfigurationFileName);
|
||||||
for (int i = 0; i < configFile.Length; i++)
|
for (int i = 0; i < configFile.Length; i++)
|
||||||
{
|
{
|
||||||
string setting = configFile[i];
|
string setting = configFile[i];
|
||||||
|
|
||||||
if (setting.Length < 1)
|
if (setting.Length < 1)
|
||||||
continue;
|
continue;
|
||||||
if (setting[0] == '#')
|
if (setting[0] == '#')
|
||||||
continue;
|
continue;
|
||||||
if (!setting.Contains("="))
|
if (!setting.Contains("="))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string[] dataPair = setting.Split('=');
|
string[] dataPair = setting.Split('=');
|
||||||
|
|
||||||
string key = dataPair[0];
|
string key = dataPair[0];
|
||||||
|
|
||||||
if (key == okey)
|
if (key == okey)
|
||||||
|
@ -114,7 +114,7 @@ namespace HISP
|
||||||
|
|
||||||
private void resetUserPasswordToolStripMenuItem_Click(object sender, EventArgs e)
|
private void resetUserPasswordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ResetForm frm = new ResetForm();
|
ResetForm frm = new ResetForm();
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,5 +165,5 @@ namespace HISP
|
||||||
ConfigReader.FixOfficalBugs = enab;
|
ConfigReader.FixOfficalBugs = enab;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue