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.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DutyContent
|
|
|
|
|
{
|
|
|
|
|
class DcConfig
|
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public static int PluginTag => 15;
|
2021-06-18 14:08:43 +02:00
|
|
|
|
public static Version PluginVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
public static bool PluginEnable { get; set; }
|
|
|
|
|
public static string PluginPath { get; set; }
|
|
|
|
|
public static string DataPath { 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; } = "";
|
2021-06-14 18:16:06 +02:00
|
|
|
|
public static bool DataRemoteUpdate { get; set; } = true; // true = use remote update
|
2021-06-23 14:07:40 +02:00
|
|
|
|
public static int LastUpdatedPlugin { get; set; } = 0;
|
2021-06-19 14:07:01 +02:00
|
|
|
|
public static string UiFontFamily { get; set; } = "Microsoft Sans Serif";
|
2021-06-23 14:07:40 +02:00
|
|
|
|
public static bool StatusBar { get; set; } = false;
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public static bool DebugEnable { get; set; } = false;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
2021-06-19 14:07:01 +02:00
|
|
|
|
//
|
2021-06-14 11:45:49 +02:00
|
|
|
|
public static string BuildDataFileName(string header, string context, string ext)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(DataPath, $"{header}-{context}.{ext}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static string BuildDutyFileName(string language)
|
|
|
|
|
{
|
|
|
|
|
return BuildDataFileName("DcDuty", language, "json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static string BuildLangFileName(string language)
|
|
|
|
|
{
|
|
|
|
|
return BuildDataFileName("DcLang", language, "txt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static string BuildPacketFileName(string set)
|
|
|
|
|
{
|
|
|
|
|
return BuildDataFileName("DcPacket", set, "config");
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
//
|
|
|
|
|
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);
|
2021-06-14 18:16:06 +02:00
|
|
|
|
sw.WriteLine("DataRemoteUpdate={0}", DataRemoteUpdate);
|
2021-06-23 14:07:40 +02:00
|
|
|
|
sw.WriteLine("LastUpdatedPlugin={0}", LastUpdatedPlugin);
|
2021-06-19 14:07:01 +02:00
|
|
|
|
sw.WriteLine("UiFontFamily={0}", UiFontFamily);
|
2021-06-23 14:07:40 +02:00
|
|
|
|
sw.WriteLine("StatusBar={0}", StatusBar);
|
2021-08-14 16:35:53 +02:00
|
|
|
|
sw.WriteLine("DebugEnable={0}", DebugEnable);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
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"];
|
2021-06-14 18:16:06 +02:00
|
|
|
|
DataRemoteUpdate = ThirdParty.Converter.ToBool(db["DataRemoteUpdate"], DataRemoteUpdate);
|
2021-06-23 14:07:40 +02:00
|
|
|
|
LastUpdatedPlugin = ThirdParty.Converter.ToInt(db["LastUpdatedPlugin"]);
|
2021-06-19 14:07:01 +02:00
|
|
|
|
UiFontFamily = db.Get("UiFontFamily", UiFontFamily);
|
2021-06-23 14:07:40 +02:00
|
|
|
|
StatusBar = ThirdParty.Converter.ToBool(db["StatusBar"], StatusBar);
|
2021-08-14 16:35:53 +02:00
|
|
|
|
DebugEnable = ThirdParty.Converter.ToBool(db["DebugEnable"], DebugEnable);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
Duty.InternalReadFromDb(db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static void ReadLanguage(bool is_in_init = false)
|
|
|
|
|
{
|
2021-06-14 11:45:49 +02:00
|
|
|
|
if (string.IsNullOrWhiteSpace(Language))
|
2021-03-17 18:14:48 +01:00
|
|
|
|
{
|
|
|
|
|
if (!is_in_init)
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Locale.Initialize(Properties.Resources.DefaultMessage);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-14 11:45:49 +02:00
|
|
|
|
string filename = BuildLangFileName(Language);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
if (File.Exists(filename))
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Locale.LoadFile(filename);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
else
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Locale.Initialize(Properties.Resources.DefaultMessage);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 11:45:49 +02:00
|
|
|
|
public static bool ReadPacket(string set = null)
|
|
|
|
|
{
|
|
|
|
|
if (set == null)
|
|
|
|
|
set = Duty.PacketSet;
|
|
|
|
|
else if (!Duty.PacketSet.Equals(set))
|
|
|
|
|
Duty.PacketSet = set;
|
|
|
|
|
|
|
|
|
|
var filename = BuildPacketFileName(set);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
filename = BuildPacketFileName(set = PacketConfig.DefaultSetNameGlobal);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
filename = BuildPacketFileName(set = PacketConfig.DefaultSetNameCustom);
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Logger.E(27, " ");
|
2021-06-14 11:45:49 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Duty.PacketSet.Equals(set))
|
|
|
|
|
Duty.PacketSet = set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load. if file not exist, create new one with default value
|
|
|
|
|
Packet.Load(filename);
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Logger.Write(Packet.GetInformation());
|
2021-06-14 11:45:49 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
//
|
|
|
|
|
public class PacketConfig
|
|
|
|
|
{
|
|
|
|
|
// Packet
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public long Version { get; set; } = 2005580;
|
|
|
|
|
public string Description { get; set; } = "5.58 (JP/NA/EU/OC)";
|
|
|
|
|
public ushort OpFate { get; set; } = 788;
|
|
|
|
|
public ushort OpDuty { get; set; } = 676;
|
|
|
|
|
public ushort OpMatch { get; set; } = 428;
|
|
|
|
|
public ushort OpInstance { get; set; } = 234;
|
|
|
|
|
public ushort OpCe { get; set; } = 269;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
2021-06-14 11:45:49 +02:00
|
|
|
|
// packet version structure
|
|
|
|
|
// 0 - Service area (1:Custom, 2:Global, 3:Korea)
|
|
|
|
|
// 1 - Reserved. Must be 0
|
|
|
|
|
// 2 - Expansion version
|
|
|
|
|
// 3
|
|
|
|
|
// 4 - Update version
|
|
|
|
|
// 5
|
|
|
|
|
// 6 - HotFix or packet version
|
|
|
|
|
|
|
|
|
|
public readonly static string DefaultSetNameCustom = "Custom";
|
|
|
|
|
public readonly static string DefaultSetNameGlobal = "Global";
|
|
|
|
|
|
|
|
|
|
public PacketConfig()
|
|
|
|
|
{
|
|
|
|
|
// nothing to do
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PacketConfig(DateTime dt, PacketConfig right = null)
|
|
|
|
|
{
|
|
|
|
|
// for custom
|
2021-06-14 18:16:06 +02:00
|
|
|
|
Version = ThirdParty.Converter.ToLong($"1{dt:yyMMdd}");
|
|
|
|
|
Description = $"Custom ({dt:d})";
|
2021-06-14 11:45:49 +02:00
|
|
|
|
|
|
|
|
|
if (right != null)
|
|
|
|
|
{
|
|
|
|
|
OpFate = right.OpFate;
|
|
|
|
|
OpDuty = right.OpDuty;
|
|
|
|
|
OpMatch = right.OpMatch;
|
|
|
|
|
OpInstance = right.OpInstance;
|
2021-08-14 16:35:53 +02:00
|
|
|
|
OpCe = right.OpCe;
|
2021-06-14 11:45:49 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpFate = 0;
|
|
|
|
|
OpDuty = 0;
|
|
|
|
|
OpMatch = 0;
|
|
|
|
|
OpInstance = 0;
|
2021-08-14 16:35:53 +02:00
|
|
|
|
OpCe = 0;
|
2021-06-14 11:45:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 16:35:53 +02:00
|
|
|
|
//
|
|
|
|
|
public string GetInformation()
|
|
|
|
|
{
|
|
|
|
|
return Locale.Text(29, Version, Description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return GetInformation();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
//
|
2021-06-14 11:45:49 +02:00
|
|
|
|
public bool Save(string filename)
|
2021-03-17 18:14:48 +01:00
|
|
|
|
{
|
|
|
|
|
if (filename == null)
|
2021-06-14 11:45:49 +02:00
|
|
|
|
return false;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
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);
|
2021-06-14 11:45:49 +02:00
|
|
|
|
sw.WriteLine("Description={0}", Description);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine("OpFate={0}", OpFate);
|
|
|
|
|
sw.WriteLine("OpDuty={0}", OpDuty);
|
|
|
|
|
sw.WriteLine("OpMatch={0}", OpMatch);
|
|
|
|
|
sw.WriteLine("OpInstance={0}", OpInstance);
|
2021-08-14 16:35:53 +02:00
|
|
|
|
sw.WriteLine("OpSouthernBozja={0}", OpCe);
|
2021-03-17 18:14:48 +01:00
|
|
|
|
sw.WriteLine();
|
|
|
|
|
}
|
2021-06-14 11:45:49 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 18:16:06 +02:00
|
|
|
|
private void InternalParseString(ThirdParty.LineDb db)
|
|
|
|
|
{
|
|
|
|
|
Version = ThirdParty.Converter.ToLong(db["Version"]);
|
|
|
|
|
Description = db["Description"];
|
|
|
|
|
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);
|
2021-08-14 16:35:53 +02:00
|
|
|
|
OpCe = ThirdParty.Converter.ToUshort(db["OpSouthernBozja"], OpCe);
|
2021-06-14 18:16:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 18:14:48 +01:00
|
|
|
|
//
|
|
|
|
|
public void Load(string filename = null)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(filename))
|
|
|
|
|
Save(filename);
|
|
|
|
|
|
|
|
|
|
var db = new ThirdParty.LineDb(filename, Encoding.UTF8, false);
|
2021-06-14 18:16:06 +02:00
|
|
|
|
InternalParseString(db);
|
|
|
|
|
}
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
2021-06-14 18:16:06 +02:00
|
|
|
|
//
|
|
|
|
|
public static PacketConfig ParseString(string ctx)
|
|
|
|
|
{
|
|
|
|
|
var pk = new PacketConfig();
|
|
|
|
|
var db = new ThirdParty.LineDb(ctx, false);
|
|
|
|
|
pk.InternalParseString(db);
|
|
|
|
|
return pk;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public class DutyConfig
|
|
|
|
|
{
|
|
|
|
|
public string Language { get; set; } = "English";
|
|
|
|
|
public int ActiveFate { get; set; } = 0;
|
2021-06-14 11:45:49 +02:00
|
|
|
|
public string PacketSet { get; set; } = "Global";
|
2021-03-17 18:14:48 +01:00
|
|
|
|
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-06-20 14:31:05 +02:00
|
|
|
|
public bool UseNotifyDiscordWebhook { get; set; }
|
|
|
|
|
public string NotifyDiscordWebhookUrl { get; set; }
|
|
|
|
|
public bool NotifyDiscordWebhookTts { 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-08-14 16:35:53 +02:00
|
|
|
|
public bool PingShowLoss { get; set; }
|
2021-03-27 14:34:19 +01:00
|
|
|
|
public string PingDefAddr { get; set; }
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public int PingGraphType { get; set; }
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
//
|
2021-06-20 14:31:05 +02:00
|
|
|
|
public bool EnableNotify => UseNotifyLine || UseNotifyTelegram || UseNotifyDiscordWebhook;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
|
|
|
|
//
|
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-06-14 11:45:49 +02:00
|
|
|
|
sw.WriteLine("DutypPacketSet={0}", PacketSet);
|
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-06-20 14:31:05 +02:00
|
|
|
|
sw.WriteLine("DutyUseNotifyDiscordWebhook={0}", UseNotifyDiscordWebhook);
|
|
|
|
|
sw.WriteLine("DutyNotifyDiscordWebhookUrl={0}", NotifyDiscordWebhookUrl);
|
|
|
|
|
sw.WriteLine("DutyNotifyDiscordWebhookTts={0}", NotifyDiscordWebhookTts);
|
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-08-14 16:35:53 +02:00
|
|
|
|
sw.WriteLine("DutyPingShowLoss={0}", PingShowLoss);
|
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-08-14 16:35:53 +02:00
|
|
|
|
sw.WriteLine("DutyPingGraphType={0}", PingGraphType);
|
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-06-14 11:45:49 +02:00
|
|
|
|
PacketSet = db.Get("DutypPacketSet", PacketSet);
|
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-06-20 14:31:05 +02:00
|
|
|
|
UseNotifyDiscordWebhook = ThirdParty.Converter.ToBool(db["DutyUseNotifyDiscordWebhook"]);
|
|
|
|
|
NotifyDiscordWebhookUrl = db["DutyNotifyDiscordWebhookUrl"];
|
|
|
|
|
NotifyDiscordWebhookTts = ThirdParty.Converter.ToBool(db["DutyNotifyDiscordWebhookTts"]);
|
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-08-14 16:35:53 +02:00
|
|
|
|
PingShowLoss = ThirdParty.Converter.ToBool(db["DutyPingShowLoss"]);
|
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-08-14 16:35:53 +02:00
|
|
|
|
PingGraphType = ThirdParty.Converter.ToInt(db["PingGraphType"]);
|
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
|
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public SortedSet<ThirdParty.NativeMethods.TcpRow> Conns = new SortedSet<ThirdParty.NativeMethods.TcpRow>();
|
|
|
|
|
|
|
|
|
|
public int Count => Conns.Count;
|
2021-03-17 18:14:48 +01:00
|
|
|
|
|
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)
|
2021-08-14 16:35:53 +02:00
|
|
|
|
{
|
|
|
|
|
ret = new ThirdParty.NativeMethods.TcpRow[Conns.Count];
|
|
|
|
|
Conns.CopyTo(ret);
|
|
|
|
|
}
|
2021-03-20 19:43:05 +01:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 16:35:53 +02:00
|
|
|
|
public void BuildConnections(Process process)
|
2021-03-20 19:43:05 +01:00
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|