Allow HISP Noobs to run even w a web server already running

This commit is contained in:
SilicaAndPina 2022-03-19 15:46:44 +13:00
parent 62e1a7a122
commit 994dc382c8
4 changed files with 260 additions and 247 deletions

View file

@ -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);

View file

@ -19,7 +19,9 @@ 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)
@ -34,7 +36,7 @@ namespace HISP
public static void OnShutdown()
{
if(!Process.GetCurrentProcess().CloseMainWindow())
if (!Process.GetCurrentProcess().CloseMainWindow())
Process.GetCurrentProcess().Close();
}
@ -60,11 +62,21 @@ namespace HISP
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);
@ -74,7 +86,7 @@ namespace HISP
ConfigReader.OpenConfig();
ConfigReader.SqlLite = true;
ConfigReader.LogLevel = 0;
ConfigReader.BindIP = "127.0.0.1";
ConfigReader.BindIP = IP;
ConfigReader.CrossDomainPolicyFile = Path.Combine(BaseDir, "CrossDomainPolicy.xml");
ConfigReader.DatabaseName = Path.Combine(BaseDir, "game1.db");
@ -82,6 +94,7 @@ namespace HISP
Database.OpenDatabase();
IncrementProgress();
if (Database.GetUsers().Length <= 0)
{
RegisterForm rfrm = new RegisterForm();
@ -92,7 +105,7 @@ namespace HISP
// Start Web Server
try{
cs = new ContentServer();
cs = new ContentServer(IP);
string[] fileList = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(),"client"), "*", SearchOption.AllDirectories);
foreach (string file in fileList)
addToList(file);

View file

@ -36,7 +36,7 @@ namespace HISP
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.Arguments = "http://"+ Program.IP +"/horseisle.swf?SERVER="+ Program.IP +"&PORT=12321";
clientProcess.StartInfo.RedirectStandardOutput = true;
clientProcess.StartInfo.RedirectStandardError = true;