2021-03-17 18:14:48 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace DutyContent
|
|
|
|
|
{
|
|
|
|
|
class DcConfig
|
|
|
|
|
{
|
|
|
|
|
public static bool PluginEnable { get; set; }
|
|
|
|
|
public static string PluginPath { get; set; }
|
|
|
|
|
public static string DataPath { get; set; }
|
|
|
|
|
public static string PacketPath { get; set; }
|
|
|
|
|
public static string ConfigPath { get; set; }
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static PacketConfig Packet = new PacketConfig();
|
|
|
|
|
public static DutyConfig Duty = new DutyConfig();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static ConnectionList Connections = new ConnectionList();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static string Language { get; set; } = "";
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static void SaveConfig(string filename = null)
|
|
|
|
|
{
|
|
|
|
|
if (filename == null)
|
|
|
|
|
filename = ConfigPath;
|
|
|
|
|
|
|
|
|
|
using (var sw = new StreamWriter(filename, false, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("# DutyContent configuration: {0}", DateTime.Now.ToString());
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
|
|
sw.WriteLine("# config");
|
|
|
|
|
sw.WriteLine("Language={0}", Language);
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
|
|
Duty.InternalSaveStream(sw);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static void LoadConfig(string filename = null)
|
|
|
|
|
{
|
|
|
|
|
if (filename == null)
|
|
|
|
|
filename = ConfigPath;
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
SaveConfig(filename);
|
|
|
|
|
|
|
|
|
|
var db = new ThirdParty.LineDb(filename, Encoding.UTF8, false);
|
|
|
|
|
|
|
|
|
|
Language = db["Language"];
|
|
|
|
|
|
|
|
|
|
Duty.InternalReadFromDb(db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static void Load()
|
|
|
|
|
{
|
|
|
|
|
Packet.Load();
|
|
|
|
|
LoadConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static void ReadLanguage(bool is_in_init = false)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(DcConfig.Language))
|
|
|
|
|
{
|
|
|
|
|
if (!is_in_init)
|
|
|
|
|
MesgLog.Initialize(Properties.Resources.DefaultMessage);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string filename = Path.Combine(DcConfig.DataPath, $"DcLang-{DcConfig.Language}.txt");
|
|
|
|
|
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
MesgLog.LoadFile(filename);
|
|
|
|
|
else
|
|
|
|
|
MesgLog.Initialize(Properties.Resources.DefaultMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public class PacketConfig
|
|
|
|
|
{
|
|
|
|
|
// Packet
|
2021-06-03 08:55:55 +02:00
|
|
|
|
public string Version { get; set; } = "5.55 HotFix";
|
|
|
|
|
public ushort OpFate { get; set; } = 858;
|
|
|
|
|
public ushort OpDuty { get; set; } = 271;
|
|
|
|
|
public ushort OpMatch { get; set; } = 220;
|
|
|
|
|
public ushort OpInstance { get; set; } = 923;
|
|
|
|
|
public ushort OpSouthernBozja { get; set; } = 584;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public void Save(string filename = null)
|
|
|
|
|
{
|
|
|
|
|
if (filename == null)
|
|
|
|
|
filename = PacketPath;
|
|
|
|
|
|
|
|
|
|
using (var sw = new StreamWriter(filename, false, Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("# DutyPacket configuration: {0}", DateTime.Now.ToString());
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
|
|
sw.WriteLine("# packet");
|
|
|
|
|
sw.WriteLine("Version={0}", Version);
|
|
|
|
|
sw.WriteLine("OpFate={0}", OpFate);
|
|
|
|
|
sw.WriteLine("OpDuty={0}", OpDuty);
|
|
|
|
|
sw.WriteLine("OpMatch={0}", OpMatch);
|
|
|
|
|
sw.WriteLine("OpInstance={0}", OpInstance);
|
|
|
|
|
sw.WriteLine("OpSouthernBozja={0}", OpSouthernBozja);
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public void Load(string filename = null)
|
|
|
|
|
{
|
|
|
|
|
if (filename == null)
|
|
|
|
|
filename = PacketPath;
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
Save(filename);
|
|
|
|
|
|
|
|
|
|
var db = new ThirdParty.LineDb(filename, Encoding.UTF8, false);
|
|
|
|
|
|
|
|
|
|
Version = db["Version"];
|
|
|
|
|
OpFate = ThirdParty.Converter.ToUshort(db["OpFate"], OpFate);
|
|
|
|
|
OpDuty = ThirdParty.Converter.ToUshort(db["OpDuty"], OpDuty);
|
|
|
|
|
OpMatch = ThirdParty.Converter.ToUshort(db["OpMatch"], OpMatch);
|
|
|
|
|
OpInstance = ThirdParty.Converter.ToUshort(db["OpInstance"], OpInstance);
|
|
|
|
|
OpSouthernBozja = ThirdParty.Converter.ToUshort(db["OpSouthernBozja"], OpSouthernBozja);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public class DutyConfig
|
|
|
|
|
{
|
|
|
|
|
public string Language { get; set; } = "English";
|
|
|
|
|
public int ActiveFate { get; set; } = 0;
|
|
|
|
|
public string LogFontFamily { get; set; } = "Microsoft Sans Serif";
|
|
|
|
|
public float LogFontSize { get; set; } = 12.0f;
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
public bool EnableOverlay { get; set; }
|
2021-03-20 19:43:05 +01:00
|
|
|
|
public Point OverlayLocation { get; set; } = new Point(0, 0);
|
|
|
|
|
public bool OverlayClickThru { get; set; }
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
public bool EnableSound { get; set; }
|
|
|
|
|
public string SoundInstanceFile { get; set; }
|
|
|
|
|
public int SoundInstanceVolume { get; set; } = 100;
|
|
|
|
|
public string SoundFateFile { get; set; }
|
|
|
|
|
public int SoundFateVolume { get; set; } = 100;
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
public bool UseNotifyLine { get; set; }
|
|
|
|
|
public string NotifyLineToken { get; set; }
|
|
|
|
|
public bool UseNotifyTelegram { get; set; }
|
|
|
|
|
public string NotifyTelegramId { get; set; }
|
|
|
|
|
public string NotifyTelegramToken { get; set; }
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
public bool UsePing { get; set; }
|
|
|
|
|
public Color[] PingColors { get; set; } = new Color[4]
|
|
|
|
|
{
|
|
|
|
|
Color.FromArgb(0xFF, 0x00, 0x00, 0x40),
|
|
|
|
|
Color.FromArgb(0xFF, 0x40, 0x00, 0x80),
|
|
|
|
|
Color.FromArgb(0xFF, 0x80, 0x40, 0x00),
|
|
|
|
|
Color.FromArgb(0xFF, 0xDD, 0xA0, 0xDD),
|
|
|
|
|
};
|
2021-03-24 10:18:34 +01:00
|
|
|
|
public bool PingGraph { get; set; }
|
2021-03-27 14:34:19 +01:00
|
|
|
|
public string PingDefAddr { get; set; }
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public bool EnableNotify => UseNotifyLine || UseNotifyTelegram;
|
|
|
|
|
|
|
|
|
|
//
|
2021-03-20 19:43:05 +01:00
|
|
|
|
public FateSelection[] Fates { get; set; } = new FateSelection[4]
|
2021-03-17 18:14:48 +01:00
|
|
|
|
{
|
|
|
|
|
new FateSelection(0),
|
|
|
|
|
new FateSelection(1),
|
|
|
|
|
new FateSelection(2),
|
|
|
|
|
new FateSelection(3),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
internal void InternalSaveStream(StreamWriter sw)
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("# duty");
|
|
|
|
|
sw.WriteLine("DutyLanguage={0}", Language);
|
|
|
|
|
sw.WriteLine("DutyActiveFate={0}", ActiveFate);
|
|
|
|
|
sw.WriteLine("DutyFate0={0}", Fates[0].Line);
|
|
|
|
|
sw.WriteLine("DutyFate1={0}", Fates[1].Line);
|
|
|
|
|
sw.WriteLine("DutyFate2={0}", Fates[2].Line);
|
|
|
|
|
sw.WriteLine("DutyFate3={0}", Fates[3].Line);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine("DutyLogFontFamily={0}", LogFontFamily);
|
|
|
|
|
sw.WriteLine("DutyLogFontSize={0}", LogFontSize);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine("DutyEnableOverlay={0}", EnableOverlay);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
sw.WriteLine("DutyOverlayLocationX={0}", OverlayLocation.X);
|
|
|
|
|
sw.WriteLine("DutyOverlayLocationY={0}", OverlayLocation.Y);
|
|
|
|
|
sw.WriteLine("DutyOverlayClickThru={0}", OverlayClickThru);
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine("DutyEnableSound={0}", EnableSound);
|
|
|
|
|
sw.WriteLine("DutySoundInstanceFile={0}", SoundInstanceFile);
|
|
|
|
|
sw.WriteLine("DutySoundInstanceVolume={0}", SoundInstanceVolume);
|
|
|
|
|
sw.WriteLine("DutySoundFateFile={0}", SoundFateFile);
|
|
|
|
|
sw.WriteLine("DutySoundFateVolume={0}", SoundFateVolume);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine("DutyUseNotifyLine={0}", UseNotifyLine);
|
|
|
|
|
sw.WriteLine("DutyNotifyLineToken={0}", NotifyLineToken);
|
|
|
|
|
sw.WriteLine("DutyUseNotifyTelegram={0}", UseNotifyTelegram);
|
|
|
|
|
sw.WriteLine("DutyNotifyTelegramId={0}", NotifyTelegramId);
|
|
|
|
|
sw.WriteLine("DutyNotifyTelegramToken={0}", NotifyTelegramToken);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
sw.WriteLine("DutyUsePing={0}", UsePing);
|
|
|
|
|
sw.WriteLine("DutyPingColor0={0:X}", PingColors[0].ToArgb());
|
|
|
|
|
sw.WriteLine("DutyPingColor1={0:X}", PingColors[1].ToArgb());
|
|
|
|
|
sw.WriteLine("DutyPingColor2={0:X}", PingColors[2].ToArgb());
|
|
|
|
|
sw.WriteLine("DutyPingColor3={0:X}", PingColors[3].ToArgb());
|
2021-03-24 10:18:34 +01:00
|
|
|
|
sw.WriteLine("DutyPingGraph={0}", PingGraph);
|
2021-03-27 14:34:19 +01:00
|
|
|
|
sw.WriteLine("DutyPingDefAddr={0}", PingDefAddr);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
internal void InternalReadFromDb(ThirdParty.LineDb db)
|
|
|
|
|
{
|
|
|
|
|
Language = db["DutyLanguage"];
|
|
|
|
|
ActiveFate = ThirdParty.Converter.ToInt(db["DutyActiveFate"]);
|
|
|
|
|
Fates[0].Line = db["DutyFate0"];
|
|
|
|
|
Fates[1].Line = db["DutyFate1"];
|
|
|
|
|
Fates[2].Line = db["DutyFate2"];
|
|
|
|
|
Fates[3].Line = db["DutyFate3"];
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
LogFontFamily = db.Get("DutyLogFontFamily", LogFontFamily);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
LogFontSize = ThirdParty.Converter.ToFloat(db["DutyLogFontSize"], LogFontSize);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
EnableOverlay = ThirdParty.Converter.ToBool(db["DutyEnableOverlay"]);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
OverlayLocation = new Point(
|
|
|
|
|
ThirdParty.Converter.ToInt(db["DutyOverlayLocationX"]),
|
|
|
|
|
ThirdParty.Converter.ToInt(db["DutyOverlayLocationY"]));
|
|
|
|
|
OverlayClickThru = ThirdParty.Converter.ToBool(db["DutyOverlayClickThru"]);
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
EnableSound = ThirdParty.Converter.ToBool(db["DutyEnableSound"]);
|
|
|
|
|
SoundInstanceFile = db["DutySoundInstanceFile"];
|
|
|
|
|
SoundFateFile = db["DutySoundFateFile"];
|
|
|
|
|
SoundInstanceVolume = ThirdParty.Converter.ToInt(db["DutySoundInstanceVolume"], 100);
|
|
|
|
|
SoundFateVolume = ThirdParty.Converter.ToInt(db["DutySoundFateVolume"], 100);
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
UseNotifyLine = ThirdParty.Converter.ToBool(db["DutyUseNotifyLine"]);
|
|
|
|
|
NotifyLineToken = db["DutyNotifyLineToken"];
|
|
|
|
|
UseNotifyTelegram = ThirdParty.Converter.ToBool(db["DutyUseNotifyTelegram"]);
|
|
|
|
|
NotifyTelegramId = db["DutyNotifyTelegramId"];
|
|
|
|
|
NotifyTelegramToken = db["DutyNotifyTelegramToken"];
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
UsePing = ThirdParty.Converter.ToBool(db["DutyUsePing"]);
|
|
|
|
|
PingColors[0] = ThirdParty.Converter.ToColorArgb(db["DutyPingColor0"], PingColors[0]);
|
|
|
|
|
PingColors[1] = ThirdParty.Converter.ToColorArgb(db["DutyPingColor1"], PingColors[1]);
|
|
|
|
|
PingColors[2] = ThirdParty.Converter.ToColorArgb(db["DutyPingColor2"], PingColors[2]);
|
|
|
|
|
PingColors[3] = ThirdParty.Converter.ToColorArgb(db["DutyPingColor3"], PingColors[3]);
|
2021-03-24 10:18:34 +01:00
|
|
|
|
PingGraph = ThirdParty.Converter.ToBool(db["DutyPingGraph"]);
|
2021-03-27 14:34:19 +01:00
|
|
|
|
PingDefAddr = db.Get("DutyPingDefAddr", string.Empty);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public class FateSelection
|
|
|
|
|
{
|
|
|
|
|
public HashSet<int> Selected { get; } = new HashSet<int>();
|
|
|
|
|
public string Line { get; set; }
|
|
|
|
|
public int Index { get; set; }
|
|
|
|
|
|
|
|
|
|
public FateSelection(int index)
|
|
|
|
|
{
|
|
|
|
|
Index = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MakeSelects(bool clear = false)
|
|
|
|
|
{
|
|
|
|
|
if (clear)
|
|
|
|
|
Selected.Clear();
|
|
|
|
|
|
|
|
|
|
var ss = Line.Split('|');
|
|
|
|
|
foreach (var s in ss)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(s) && ThirdParty.Converter.TryInt(s, out int i))
|
|
|
|
|
Selected.Add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MakeLine()
|
|
|
|
|
{
|
|
|
|
|
Line = string.Join("|", Selected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public class ConnectionList
|
|
|
|
|
{
|
|
|
|
|
public List<ThirdParty.NativeMethods.TcpRow> Conns = new List<ThirdParty.NativeMethods.TcpRow>();
|
|
|
|
|
|
2021-03-20 19:43:05 +01:00
|
|
|
|
public ThirdParty.NativeMethods.TcpRow[] CopyConnection()
|
2021-03-17 18:14:48 +01:00
|
|
|
|
{
|
2021-03-20 19:43:05 +01:00
|
|
|
|
ThirdParty.NativeMethods.TcpRow[] ret;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
2021-03-20 19:43:05 +01:00
|
|
|
|
lock (Conns)
|
|
|
|
|
ret = Conns.ToArray();
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetConnections(Process process)
|
|
|
|
|
{
|
2021-03-17 18:14:48 +01:00
|
|
|
|
var size = 0;
|
2021-03-20 19:43:05 +01:00
|
|
|
|
ThirdParty.NativeMethods.GetExtendedTcpTable(IntPtr.Zero, ref size, true, AddressFamily.InterNetwork, 4);
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
var buff = Marshal.AllocHGlobal(size);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-03-20 19:43:05 +01:00
|
|
|
|
var ret = ThirdParty.NativeMethods.GetExtendedTcpTable(buff, ref size, true, AddressFamily.InterNetwork, 4);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
{
|
|
|
|
|
var tbl = Marshal.PtrToStructure<ThirdParty.NativeMethods.TcpTable>(buff);
|
|
|
|
|
var ptr = (IntPtr)((long)buff + Marshal.SizeOf(tbl.entries));
|
|
|
|
|
|
2021-03-20 19:43:05 +01:00
|
|
|
|
var rows = new ThirdParty.NativeMethods.TcpRow[tbl.entries];
|
|
|
|
|
var rcnt = 0;
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
for (var i = 0; i < tbl.entries; i++)
|
|
|
|
|
{
|
|
|
|
|
var row = Marshal.PtrToStructure<ThirdParty.NativeMethods.TcpRow>(ptr);
|
|
|
|
|
|
|
|
|
|
if (!IPAddress.IsLoopback(row.RemoteAddress) &&
|
|
|
|
|
process.Id == row.owningPid)
|
2021-03-20 19:43:05 +01:00
|
|
|
|
rows[rcnt++] = row;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
ptr = (IntPtr)((long)ptr + Marshal.SizeOf(row));
|
|
|
|
|
}
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
lock (Conns)
|
|
|
|
|
{
|
|
|
|
|
Conns.Clear();
|
|
|
|
|
for (var i = 0; i < rcnt; i++)
|
|
|
|
|
Conns.Add(rows[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lock (Conns)
|
|
|
|
|
Conns.Clear();
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (buff != null)
|
|
|
|
|
Marshal.FreeHGlobal(buff);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|