-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from sebastian-heinz/develop
New release
- Loading branch information
Showing
1,540 changed files
with
841,037 additions
and
67,965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using Arrowgene.Ddon.Database; | ||
using Arrowgene.Ddon.Database.Sql.Core.Migration; | ||
using Arrowgene.Ddon.Shared; | ||
using Arrowgene.Logging; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Reflection; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Arrowgene.Ddon.Cli.Command | ||
{ | ||
public class DbMigrationCommand : ICommand | ||
{ | ||
private static readonly ILogger Logger = LogProvider.Logger<Logger>(typeof(ServerCommand)); | ||
|
||
public string Key => "dbmigration"; | ||
|
||
public string Description => $"Commandline tool to update the database\n\n" + | ||
$"usage:\n" + | ||
$"{Key}\n"; | ||
|
||
public CommandResultType Run(CommandParameter parameter) | ||
{ | ||
|
||
string settingPath = Path.Combine(Util.ExecutingDirectory(), "Files/Arrowgene.Ddon.config.json"); | ||
Setting settings = Setting.LoadFromFile(settingPath); | ||
if (settings == null) | ||
{ | ||
return CommandResultType.Exit; | ||
} | ||
|
||
DatabaseSetting dbSettings = settings.DatabaseSetting; | ||
if (dbSettings == null) | ||
{ | ||
return CommandResultType.Exit; | ||
} | ||
|
||
IDatabase database = DdonDatabaseBuilder.Build(dbSettings); | ||
if (database == null) | ||
{ | ||
return CommandResultType.Exit; | ||
} | ||
|
||
// Instance all implementations of IMigrationStrategy located in the Migration namespace | ||
// supplying the adequate arguments to the constructor | ||
DatabaseMigrator migrator = new DatabaseMigrator(typeof(IMigrationStrategy).Assembly.GetTypes() | ||
.Where(type => type != typeof(IMigrationStrategy) && typeof(IMigrationStrategy).IsAssignableFrom(type) && type.Namespace == typeof(IMigrationStrategy).Namespace) | ||
.Select(type => InstanceMigrationStrategy(type, dbSettings)) | ||
.ToList()); | ||
|
||
// TODO: Warn that migration is destructive | ||
bool result = database.MigrateDatabase(migrator, DdonDatabaseBuilder.Version); | ||
|
||
// TODO: Better logging | ||
if(result) | ||
{ | ||
Logger.Info($"Successfully migrated the database to version '{DdonDatabaseBuilder.Version}'."); | ||
} | ||
else | ||
{ | ||
Logger.Error("Failed to migrate the database."); | ||
} | ||
|
||
return CommandResultType.Exit; | ||
} | ||
|
||
public void Shutdown() | ||
{ | ||
} | ||
|
||
private IMigrationStrategy InstanceMigrationStrategy(Type type, DatabaseSetting databaseSetting) | ||
{ | ||
foreach(ConstructorInfo constructorInfo in type.GetConstructors()) | ||
{ | ||
List<object> parameters = new List<object>(); | ||
foreach (var constructorParam in constructorInfo.GetParameters()) | ||
{ | ||
if(constructorParam.ParameterType == typeof(DatabaseSetting)) | ||
{ | ||
parameters.Add(databaseSetting); | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if(parameters.Count == constructorInfo.GetParameters().Length) | ||
{ | ||
return (IMigrationStrategy) constructorInfo.Invoke(parameters.ToArray()); | ||
} | ||
} | ||
|
||
throw new MissingMethodException("No suitable constructor found in "+type.Name); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Arrowgene.Ddon.Cli/Command/Packet/PacketCommandException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class PacketCommandException : Exception | ||
{ | ||
public PacketCommandException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public PacketCommandException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class PacketCommandOptions | ||
{ | ||
private static string ByteDumpSwitch => "--byte-dump"; | ||
private static string ByteDumpHeaderSwitch => "--byte-dump-header"; | ||
private static string ByteDumpPrefixSwitch => "--byte-dump-prefix"; | ||
private static string Utf8StringDumpSwitch => "--utf8-dump"; | ||
private static string StructureDumpSwitch => "--structure-dump"; | ||
private static string PacketIncludeFilterSwitch => "--packet-include-filter"; | ||
private static string ExportDecryptedPacketsSwitch => "--export-decrypted-packets"; | ||
|
||
public bool AddByteDump { get; } | ||
public bool AddByteDumpHeader { get; } | ||
public string ByteDumpSeparator { get; } | ||
public string ByteDumpPrefix { get; } | ||
public bool AddUtf8StringDump { get; } | ||
public bool AddStructureDump { get; } | ||
public string StructureDumpFormat { get; } | ||
public string PacketIncludeFilter { get; } | ||
public bool ExportDecryptedPackets { get; } | ||
|
||
public PacketCommandOptions(bool addByteDump = false, bool addByteDumpHeader = false, string byteDumpSeparator = "", string byteDumpPrefix = "", bool addUtf8StringDump = false, | ||
bool addStructureDump = false, string structureDumpFormat = "", string packetIncludeFilter = "", bool exportDecryptedPackets = false) | ||
{ | ||
AddByteDump = addByteDump; | ||
AddByteDumpHeader = addByteDumpHeader; | ||
ByteDumpSeparator = byteDumpSeparator; | ||
ByteDumpPrefix = byteDumpPrefix; | ||
AddUtf8StringDump = addUtf8StringDump; | ||
AddStructureDump = addStructureDump; | ||
StructureDumpFormat = structureDumpFormat; | ||
PacketIncludeFilter = packetIncludeFilter; | ||
ExportDecryptedPackets = exportDecryptedPackets; | ||
} | ||
|
||
public PacketCommandOptions(CommandParameter parameters) : this(parameters.Switches, parameters.SwitchMap) | ||
{ | ||
} | ||
|
||
private PacketCommandOptions(List<string> parameterSwitches, Dictionary<string, string> parameterSwitchMap) | ||
{ | ||
AddByteDump = parameterSwitches.Contains(ByteDumpSwitch) || parameterSwitchMap.ContainsKey(ByteDumpSwitch); | ||
AddByteDumpHeader = parameterSwitches.Contains(ByteDumpHeaderSwitch) || parameterSwitchMap.ContainsKey(ByteDumpHeaderSwitch); | ||
ByteDumpSeparator = parameterSwitchMap.GetValueOrDefault(ByteDumpSwitch, ""); | ||
ByteDumpPrefix = parameterSwitchMap.GetValueOrDefault(ByteDumpPrefixSwitch, ""); | ||
AddUtf8StringDump = parameterSwitches.Contains(Utf8StringDumpSwitch) || parameterSwitchMap.ContainsKey(Utf8StringDumpSwitch); | ||
AddStructureDump = parameterSwitches.Contains(StructureDumpSwitch) || parameterSwitchMap.ContainsKey(StructureDumpSwitch); | ||
StructureDumpFormat = parameterSwitchMap.GetValueOrDefault(StructureDumpSwitch, "JSON").ToLowerInvariant(); | ||
PacketIncludeFilter = parameterSwitchMap.GetValueOrDefault(PacketIncludeFilterSwitch, ""); | ||
ExportDecryptedPackets = parameterSwitches.Contains(ExportDecryptedPacketsSwitch) || parameterSwitchMap.ContainsKey(ExportDecryptedPacketsSwitch); | ||
} | ||
|
||
public static string GetUsage() | ||
{ | ||
return | ||
$"[{ByteDumpSwitch}[=,]] [{ByteDumpHeaderSwitch}] [{ByteDumpPrefixSwitch}=0x] [{Utf8StringDumpSwitch}] [{StructureDumpSwitch}[=JSON|YAML]] [{PacketIncludeFilterSwitch}=11.21.2,S2C_QUEST_QUEST_PROGRESS_RES,...]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Arrowgene.Ddon.Cli.Command.Packet | ||
{ | ||
public enum PacketServerType : ushort | ||
{ | ||
Login = 52100, | ||
Game = 52000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using Arrowgene.Ddon.Shared.Network; | ||
|
||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class PcapPacket | ||
{ | ||
public PacketServerType PacketServerType { get; set; } | ||
public PacketSource Source { get; set; } | ||
public string TimeStamp { get; set; } | ||
public uint Index { get; set; } | ||
public uint Packet { get; set; } | ||
public byte[] Data { get; set; } | ||
public List<IPacket> ResolvedPackets { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class YamlFile | ||
{ | ||
public List<YamlPeer> peers; | ||
public List<YamlPacket> packets; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class YamlPacket | ||
{ | ||
public uint packet; | ||
public uint peer; | ||
public uint index; | ||
public string timestamp; | ||
public string data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Arrowgene.Ddon.Cli.Command.Packet; | ||
|
||
public class YamlPeer | ||
{ | ||
public uint peer; | ||
public string host; | ||
public ushort port; | ||
} |
Oops, something went wrong.