updated to code in new snapshot.

This commit is contained in:
Bitl 2020-09-04 10:41:28 -07:00
parent ebba6ca013
commit 5c8f240693
5 changed files with 53 additions and 27 deletions

View File

@ -36,7 +36,8 @@ namespace NovetusCMD
try try
{ {
NetFuncs.StartUPnP(device,protocol,port); NetFuncs.StartUPnP(device,protocol,port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -52,7 +53,8 @@ namespace NovetusCMD
try try
{ {
NetFuncs.StopUPnP(device,protocol,port); NetFuncs.StopUPnP(device,protocol,port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -66,7 +68,8 @@ namespace NovetusCMD
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -83,7 +86,8 @@ namespace NovetusCMD
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -196,7 +200,7 @@ namespace NovetusCMD
LoadOverrideINIArgs(args); LoadOverrideINIArgs(args);
InitUPnP(); InitUPnP();
if (!GlobalVars.UserConfiguration.WebServer) if (GlobalVars.UserConfiguration.WebServer)
{ {
StartWebServer(); StartWebServer();
} }
@ -317,6 +321,7 @@ namespace NovetusCMD
if (CommandLine["map"] != null) if (CommandLine["map"] != null)
{ {
LocalVars.OverrideINI = true; LocalVars.OverrideINI = true;
GlobalVars.UserConfiguration.Map = CommandLine["map"];
GlobalVars.UserConfiguration.MapPath = CommandLine["map"]; GlobalVars.UserConfiguration.MapPath = CommandLine["map"];
GlobalFuncs.ConsolePrint("NovetusCMD will now launch the server with the map " + GlobalVars.UserConfiguration.MapPath, 4); GlobalFuncs.ConsolePrint("NovetusCMD will now launch the server with the map " + GlobalVars.UserConfiguration.MapPath, 4);
} }

View File

@ -5,6 +5,9 @@ using System.Windows.Forms;
using System.Diagnostics; using System.Diagnostics;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Linq;
#endregion #endregion
#region .NET Extentions #region .NET Extentions
@ -162,7 +165,7 @@ public static class NETExt
} }
#endregion #endregion
#region Exeption Helpers #region Exception Helpers
//https://github.com/AlexMelw/EasySharp/blob/master/NHelpers/ExceptionsDealing/Extensions/ExceptionExtensions.cs //https://github.com/AlexMelw/EasySharp/blob/master/NHelpers/ExceptionsDealing/Extensions/ExceptionExtensions.cs
/// <summary> /// <summary>
/// Gets the entire stack trace consisting of exception's footprints (File, Method, LineNumber) /// Gets the entire stack trace consisting of exception's footprints (File, Method, LineNumber)
@ -209,5 +212,15 @@ public static class NETExt
return stackTraceFootprints; return stackTraceFootprints;
} }
#endregion #endregion
#region DirectoryInfo Extensions
public static IEnumerable<FileInfo> GetFilesByExtensions(this DirectoryInfo dir, params string[] extensions)
{
if (extensions == null)
throw new ArgumentNullException("extensions");
IEnumerable<FileInfo> files = dir.EnumerateFiles();
return files.Where(f => extensions.Contains(f.Extension));
}
#endregion
} }
#endregion #endregion

View File

@ -9,19 +9,19 @@ using System.Windows.Forms;
#region Tree Node Helper #region Tree Node Helper
public static class TreeNodeHelper public static class TreeNodeHelper
{ {
public static void ListDirectory(TreeView treeView, string path, string filter = ".*") public static void ListDirectory(TreeView treeView, string path, string[] filter)
{ {
treeView.Nodes.Clear(); treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path); var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo, filter)); treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo, filter));
} }
public static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo, string filter = ".*") public static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo, string[] filter)
{ {
var directoryNode = new TreeNode(directoryInfo.Name); var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories()) foreach (var directory in directoryInfo.GetDirectories())
directoryNode.Nodes.Add(CreateDirectoryNode(directory, filter)); directoryNode.Nodes.Add(CreateDirectoryNode(directory, filter));
foreach (var file in directoryInfo.GetFiles("*" + filter)) foreach (var file in directoryInfo.GetFilesByExtensions(filter))
directoryNode.Nodes.Add(new TreeNode(file.Name)); directoryNode.Nodes.Add(new TreeNode(file.Name));
return directoryNode; return directoryNode;
} }

View File

@ -54,7 +54,8 @@ namespace NovetusLauncher
try try
{ {
NetFuncs.StartUPnP(device, protocol, port); NetFuncs.StartUPnP(device, protocol, port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -70,7 +71,8 @@ namespace NovetusLauncher
try try
{ {
NetFuncs.StopUPnP(device, protocol, port); NetFuncs.StopUPnP(device, protocol, port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -84,7 +86,8 @@ namespace NovetusLauncher
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3, richTextBox1);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -101,7 +104,8 @@ namespace NovetusLauncher
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3, richTextBox1);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -260,8 +264,8 @@ namespace NovetusLauncher
break; break;
case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]: case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]:
string mapdir = GlobalPaths.MapsDir; string mapdir = GlobalPaths.MapsDir;
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); string[] fileexts = new string[] { ".rbxl", ".rbxlx"};
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts);
TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes);
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes);
treeView1.Focus(); treeView1.Focus();
@ -419,7 +423,7 @@ namespace NovetusLauncher
ReadConfigValues(true); ReadConfigValues(true);
InitUPnP(); InitUPnP();
StartDiscord(); StartDiscord();
if (!GlobalVars.UserConfiguration.WebServer) if (GlobalVars.UserConfiguration.WebServer)
{ {
StartWebServer(); StartWebServer();
} }
@ -1070,8 +1074,8 @@ namespace NovetusLauncher
treeView1.Nodes.Clear(); treeView1.Nodes.Clear();
_fieldsTreeCache.Nodes.Clear(); _fieldsTreeCache.Nodes.Clear();
string mapdir = GlobalPaths.MapsDir; string mapdir = GlobalPaths.MapsDir;
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); string[] fileexts = new string[] { ".rbxl", ".rbxlx" };
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts);
TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes);
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes);
treeView1.Focus(); treeView1.Focus();

View File

@ -58,7 +58,8 @@ namespace NovetusLauncher
try try
{ {
NetFuncs.StartUPnP(device, protocol, port); NetFuncs.StartUPnP(device, protocol, port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -74,7 +75,8 @@ namespace NovetusLauncher
try try
{ {
NetFuncs.StopUPnP(device, protocol, port); NetFuncs.StopUPnP(device, protocol, port);
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + device.GetExternalIP() + "' (" + protocol.ToString() + ")", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3, richTextBox1);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -88,7 +90,8 @@ namespace NovetusLauncher
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' registered.", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3, richTextBox1);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -105,7 +108,8 @@ namespace NovetusLauncher
try try
{ {
INatDevice device = args.Device; INatDevice device = args.Device;
GlobalFuncs.ConsolePrint("UPnP: Device '" + device.GetExternalIP() + "' disconnected.", 3, richTextBox1); string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString());
GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3, richTextBox1);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort);
StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.WebServerPort);
@ -264,8 +268,8 @@ namespace NovetusLauncher
break; break;
case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]: case TabPage pg4 when pg4 == tabControl1.TabPages["tabPage4"]:
string mapdir = GlobalPaths.MapsDir; string mapdir = GlobalPaths.MapsDir;
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); string[] fileexts = new string[] { ".rbxl", ".rbxlx" };
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts);
TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes); TreeNodeHelper.CopyNodes(treeView1.Nodes, _fieldsTreeCache.Nodes);
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes);
treeView1.Focus(); treeView1.Focus();
@ -451,7 +455,7 @@ namespace NovetusLauncher
ReadConfigValues(true); ReadConfigValues(true);
InitUPnP(); InitUPnP();
StartDiscord(); StartDiscord();
if (!GlobalVars.UserConfiguration.WebServer) if (GlobalVars.UserConfiguration.WebServer)
{ {
StartWebServer(); StartWebServer();
} }
@ -1143,8 +1147,8 @@ namespace NovetusLauncher
treeView1.Nodes.Clear(); treeView1.Nodes.Clear();
_fieldsTreeCache.Nodes.Clear(); _fieldsTreeCache.Nodes.Clear();
string mapdir = GlobalPaths.MapsDir; string mapdir = GlobalPaths.MapsDir;
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxl"); string[] fileexts = new string[] { ".rbxl", ".rbxlx" };
TreeNodeHelper.ListDirectory(treeView1, mapdir, ".rbxlx"); TreeNodeHelper.ListDirectory(treeView1, mapdir, fileexts);
TreeNodeHelper.CopyNodes(treeView1.Nodes,_fieldsTreeCache.Nodes); TreeNodeHelper.CopyNodes(treeView1.Nodes,_fieldsTreeCache.Nodes);
treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes); treeView1.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, treeView1.Nodes);
treeView1.Focus(); treeView1.Focus();