diff --git a/HorseIsleServer/Installer/Windows/HISP-N00BS.tmp b/HorseIsleServer/Installer/Windows/HISP-N00BS.tmp deleted file mode 100644 index 0f0bb29..0000000 Binary files a/HorseIsleServer/Installer/Windows/HISP-N00BS.tmp and /dev/null differ diff --git a/HorseIsleServer/N00BS/HTTP/ContentServer.cs b/HorseIsleServer/N00BS/HTTP/ContentServer.cs index 3c8dd05..5640781 100644 --- a/HorseIsleServer/N00BS/HTTP/ContentServer.cs +++ b/HorseIsleServer/N00BS/HTTP/ContentServer.cs @@ -277,11 +277,11 @@ namespace HTTP e.AcceptSocket = null; } while (!ServerSocket.AcceptAsync(e)); } - public ContentServer() + public ContentServer(string ip) { 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.Bind(ep); ServerSocket.Listen(0x7fffffff); diff --git a/HorseIsleServer/N00BS/Program.cs b/HorseIsleServer/N00BS/Program.cs index 2aa2374..f7d7c75 100644 --- a/HorseIsleServer/N00BS/Program.cs +++ b/HorseIsleServer/N00BS/Program.cs @@ -1,165 +1,178 @@ -// An HTTP Server, and Horse Isle Server, Flash Player, in a single package -// Idea is to just be open and play. - -using HISP.Game; -using HISP.Game.Horse; -using HISP.Game.Items; -using HISP.Game.Services; -using HISP.Game.SwfModules; -using HISP.Security; -using HISP.Server; -using HTTP; -using System; -using System.Diagnostics; -using System.IO; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HISP -{ - public static class Program - { - private static LoadingForm lfrm; - public static string BaseDir; - private static ContentServer cs; - private static void addToList(string path) - { - string Name = path.Remove(0, Path.Combine(Directory.GetCurrentDirectory(), "client").Length); - Name = Name.Replace("\\", "/"); - - ContentItem ci = new ContentItem(Name, path); - cs.Contents.Add(ci); - - } - - public static void OnShutdown() - { - if(!Process.GetCurrentProcess().CloseMainWindow()) - Process.GetCurrentProcess().Close(); - } - - public static void StartLRFrm() - { - if (lfrm.ShowDialog() == DialogResult.Cancel) - { - GameServer.ShutdownServer(); - } - } - - public static void IncrementProgress() - { - if (lfrm.InvokeRequired) - { - lfrm.Invoke(() => - { - lfrm.StartProgress.Increment(1); - }); - } - else - { - lfrm.StartProgress.Increment(1); - } - } - - public static void Main(string[] args) - { +// An HTTP Server, and Horse Isle Server, Flash Player, in a single package +// Idea is to just be open and play. + +using HISP.Game; +using HISP.Game.Horse; +using HISP.Game.Items; +using HISP.Game.Services; +using HISP.Game.SwfModules; +using HISP.Security; +using HISP.Server; +using HTTP; +using System; +using System.Diagnostics; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace HISP +{ + public static class Program + { + public static Random rand = new Random(Guid.NewGuid().GetHashCode()); + private static LoadingForm lfrm; + public static string IP; + public static string BaseDir; + private static ContentServer cs; + private static void addToList(string path) + { + string Name = path.Remove(0, Path.Combine(Directory.GetCurrentDirectory(), "client").Length); + Name = Name.Replace("\\", "/"); + + ContentItem ci = new ContentItem(Name, path); + cs.Contents.Add(ci); + + } + + public static void OnShutdown() + { + if (!Process.GetCurrentProcess().CloseMainWindow()) + Process.GetCurrentProcess().Close(); + } + + public static void StartLRFrm() + { + if (lfrm.ShowDialog() == DialogResult.Cancel) + { + GameServer.ShutdownServer(); + } + } + + public static void IncrementProgress() + { + if (lfrm.InvokeRequired) + { + lfrm.Invoke(() => + { + lfrm.StartProgress.Increment(1); + }); + } + else + { + lfrm.StartProgress.Increment(1); + } + } + 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"); Directory.CreateDirectory(BaseDir); + IP = GenIP(); - lfrm = new LoadingForm(); - Task startForm = new Task(StartLRFrm); - startForm.Start(); - - ConfigReader.ConfigurationFileName = Path.Combine(BaseDir, "server.properties"); - ConfigReader.OpenConfig(); - ConfigReader.SqlLite = true; - ConfigReader.LogLevel = 0; - ConfigReader.BindIP = "127.0.0.1"; - ConfigReader.CrossDomainPolicyFile = Path.Combine(BaseDir, "CrossDomainPolicy.xml"); - ConfigReader.DatabaseName = Path.Combine(BaseDir, "game1.db"); - - IncrementProgress(); - Database.OpenDatabase(); - IncrementProgress(); - - if (Database.GetUsers().Length <= 0) - { - RegisterForm rfrm = new RegisterForm(); - if (rfrm.ShowDialog() == DialogResult.Cancel) - GameServer.ShutdownServer(); - - } - - // Start Web Server - try{ - cs = new ContentServer(); - string[] fileList = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),"client"), "*", SearchOption.AllDirectories); - foreach (string file in fileList) - addToList(file); - }catch(Exception e){ - MessageBox.Show("Web server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - IncrementProgress(); - - // Start HI1 Server - Logger.SetCallback(Console.WriteLine); - IncrementProgress(); - - Entry.SetShutdownCallback(OnShutdown); - IncrementProgress(); - - CrossDomainPolicy.GetPolicy(); - IncrementProgress(); - - GameDataJson.ReadGamedata(); - IncrementProgress(); - - Map.OpenMap(); - IncrementProgress(); - - World.ReadWorldData(); - IncrementProgress(); - - Treasure.Init(); - IncrementProgress(); - - DroppedItems.Init(); - IncrementProgress(); - - WildHorse.Init(); - IncrementProgress(); - - Drawingroom.LoadAllDrawingRooms(); - IncrementProgress(); - - Brickpoet.LoadPoetryRooms(); - IncrementProgress(); - - Multiroom.CreateMultirooms(); - IncrementProgress(); - - Auction.LoadAllAuctionRooms(); - IncrementProgress(); - - Item.DoSpecialCases(); - IncrementProgress(); - try{ - GameServer.StartServer(); - }catch(Exception e){ - MessageBox.Show("Horse Isle server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - IncrementProgress(); - - lfrm.DialogResult = DialogResult.OK; - - SystemTrayIcon stry = new SystemTrayIcon(); - stry.ShowDialog(); - - // Finally, shutdown server - GameServer.ShutdownServer(); - } - } -} + lfrm = new LoadingForm(); + Task startForm = new Task(StartLRFrm); + startForm.Start(); + + ConfigReader.ConfigurationFileName = Path.Combine(BaseDir, "server.properties"); + ConfigReader.OpenConfig(); + ConfigReader.SqlLite = true; + ConfigReader.LogLevel = 0; + ConfigReader.BindIP = IP; + ConfigReader.CrossDomainPolicyFile = Path.Combine(BaseDir, "CrossDomainPolicy.xml"); + ConfigReader.DatabaseName = Path.Combine(BaseDir, "game1.db"); + + IncrementProgress(); + Database.OpenDatabase(); + IncrementProgress(); + + + if (Database.GetUsers().Length <= 0) + { + RegisterForm rfrm = new RegisterForm(); + if (rfrm.ShowDialog() == DialogResult.Cancel) + GameServer.ShutdownServer(); + + } + + // Start Web Server + try{ + cs = new ContentServer(IP); + string[] fileList = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),"client"), "*", SearchOption.AllDirectories); + foreach (string file in fileList) + addToList(file); + }catch(Exception e){ + MessageBox.Show("Web server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + IncrementProgress(); + + // Start HI1 Server + Logger.SetCallback(Console.WriteLine); + IncrementProgress(); + + Entry.SetShutdownCallback(OnShutdown); + IncrementProgress(); + + CrossDomainPolicy.GetPolicy(); + IncrementProgress(); + + GameDataJson.ReadGamedata(); + IncrementProgress(); + + Map.OpenMap(); + IncrementProgress(); + + World.ReadWorldData(); + IncrementProgress(); + + Treasure.Init(); + IncrementProgress(); + + DroppedItems.Init(); + IncrementProgress(); + + WildHorse.Init(); + IncrementProgress(); + + Drawingroom.LoadAllDrawingRooms(); + IncrementProgress(); + + Brickpoet.LoadPoetryRooms(); + IncrementProgress(); + + Multiroom.CreateMultirooms(); + IncrementProgress(); + + Auction.LoadAllAuctionRooms(); + IncrementProgress(); + + Item.DoSpecialCases(); + IncrementProgress(); + try{ + GameServer.StartServer(); + }catch(Exception e){ + MessageBox.Show("Horse Isle server failed to start: "+e.Message, "Error starting web server", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + IncrementProgress(); + + lfrm.DialogResult = DialogResult.OK; + + SystemTrayIcon stry = new SystemTrayIcon(); + stry.ShowDialog(); + + // Finally, shutdown server + GameServer.ShutdownServer(); + } + } +} diff --git a/HorseIsleServer/N00BS/SystemTrayIcon.cs b/HorseIsleServer/N00BS/SystemTrayIcon.cs index b13468e..0fc9c28 100644 --- a/HorseIsleServer/N00BS/SystemTrayIcon.cs +++ b/HorseIsleServer/N00BS/SystemTrayIcon.cs @@ -1,71 +1,71 @@ -using HISP.Server; -using System; -using System.Diagnostics; +using HISP.Server; +using System; +using System.Diagnostics; using System.IO; -using System.Windows.Forms; - -namespace HISP -{ - public partial class SystemTrayIcon : Form - { - Process clientProcess = new Process(); - - public SystemTrayIcon() - { - InitializeComponent(); - disableSwearFilterToolStripMenuItem.Checked = !ConfigReader.BadWords; - disableCorrectionsToolStripMenuItem.Checked = !ConfigReader.DoCorrections; - disableNonvioChecksToolStripMenuItem.Checked = !ConfigReader.DoNonViolations; - disableSpamFilterToolStripMenuItem.Checked = !ConfigReader.EnableSpamFilter; - +using System.Windows.Forms; + +namespace HISP +{ + public partial class SystemTrayIcon : Form + { + Process clientProcess = new Process(); + + public SystemTrayIcon() + { + InitializeComponent(); + disableSwearFilterToolStripMenuItem.Checked = !ConfigReader.BadWords; + disableCorrectionsToolStripMenuItem.Checked = !ConfigReader.DoCorrections; + disableNonvioChecksToolStripMenuItem.Checked = !ConfigReader.DoNonViolations; + disableSpamFilterToolStripMenuItem.Checked = !ConfigReader.EnableSpamFilter; + allUsersSubscribedToolStripMenuItem.Checked = ConfigReader.AllUsersSubbed; - fixOfficalBugsToolStripMenuItem.Checked = ConfigReader.FixOfficalBugs; - } - - private void createNewUserToolStripMenuItem_Click(object sender, EventArgs e) - { - RegisterForm frm = new RegisterForm(); - frm.ShowDialog(); - } - - private void closeServerToolStripMenuItem_Click(object sender, EventArgs e) - { - this.Close(); - } - - private void SystemTrayIcon_Load(object sender, EventArgs e) - { - clientProcess.StartInfo.FileName = "flash.dll"; - clientProcess.StartInfo.Arguments = "http://127.0.0.1/horseisle.swf?SERVER=127.0.0.1&PORT=12321"; - - clientProcess.StartInfo.RedirectStandardOutput = true; - clientProcess.StartInfo.RedirectStandardError = true; - - clientProcess.EnableRaisingEvents = true; - clientProcess.Exited += clientExited; - clientProcess.Start(); - - } - - private void clientExited(object sender, EventArgs e) - { - if (this.InvokeRequired) - { - this.Invoke(() => - { - this.Close(); - }); - } - else - { - this.Close(); - } - } - - private void SystemTrayIcon_FormClosing(object sender, FormClosingEventArgs e) - { - HispNotifyIcon.Visible = false; - clientProcess.Kill(); + fixOfficalBugsToolStripMenuItem.Checked = ConfigReader.FixOfficalBugs; + } + + private void createNewUserToolStripMenuItem_Click(object sender, EventArgs e) + { + RegisterForm frm = new RegisterForm(); + frm.ShowDialog(); + } + + private void closeServerToolStripMenuItem_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void SystemTrayIcon_Load(object sender, EventArgs e) + { + clientProcess.StartInfo.FileName = "flash.dll"; + clientProcess.StartInfo.Arguments = "http://"+ Program.IP +"/horseisle.swf?SERVER="+ Program.IP +"&PORT=12321"; + + clientProcess.StartInfo.RedirectStandardOutput = true; + clientProcess.StartInfo.RedirectStandardError = true; + + clientProcess.EnableRaisingEvents = true; + clientProcess.Exited += clientExited; + clientProcess.Start(); + + } + + private void clientExited(object sender, EventArgs e) + { + if (this.InvokeRequired) + { + this.Invoke(() => + { + this.Close(); + }); + } + else + { + this.Close(); + } + } + + private void SystemTrayIcon_FormClosing(object sender, FormClosingEventArgs e) + { + HispNotifyIcon.Visible = false; + clientProcess.Kill(); } private void editServerPropertiesToolStripMenuItem_Click(object sender, EventArgs e) @@ -87,20 +87,20 @@ namespace HISP private void ModifyConfig(string okey, string value) { - string[] configFile = File.ReadAllLines(ConfigReader.ConfigurationFileName); - for (int i = 0; i < configFile.Length; i++) - { - string setting = configFile[i]; - - if (setting.Length < 1) - continue; - if (setting[0] == '#') - continue; - if (!setting.Contains("=")) - continue; - - string[] dataPair = setting.Split('='); - + string[] configFile = File.ReadAllLines(ConfigReader.ConfigurationFileName); + for (int i = 0; i < configFile.Length; i++) + { + string setting = configFile[i]; + + if (setting.Length < 1) + continue; + if (setting[0] == '#') + continue; + if (!setting.Contains("=")) + continue; + + string[] dataPair = setting.Split('='); + string key = dataPair[0]; if (key == okey) @@ -114,7 +114,7 @@ namespace HISP private void resetUserPasswordToolStripMenuItem_Click(object sender, EventArgs e) { - ResetForm frm = new ResetForm(); + ResetForm frm = new ResetForm(); frm.ShowDialog(); } @@ -165,5 +165,5 @@ namespace HISP ConfigReader.FixOfficalBugs = enab; } - } -} + } +}