Skip to content

Commit

Permalink
Merge pull request #109 from sebastian-heinz/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
alborrajo authored Oct 28, 2022
2 parents d153f15 + f934eeb commit 66053ba
Show file tree
Hide file tree
Showing 246 changed files with 160,606 additions and 7,613 deletions.
25 changes: 24 additions & 1 deletion Arrowgene.Ddon.Cli/Command/ServerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using Arrowgene.Ddon.Database;
Expand Down Expand Up @@ -31,6 +32,28 @@ public class ServerCommand : ICommand

public CommandResultType Run(CommandParameter parameter)
{
Logger.Info("*** NOTICE ***");
Logger.Info("This software is and always will be free of charge available at:");
Logger.Info("https://github.com/sebastian-heinz/Arrowgene.DragonsDogmaOnline");
Logger.Info($"***{Environment.NewLine}");

Logger.Info("*** WARNING ***");
Logger.Info("This software listens on ports for incoming requests and processes them,");
Logger.Info("serves files via http/https protocol and exposes APIs.");
Logger.Info("All of the above happens with no to limited authentication required.");
Logger.Info("Please be aware that it may expose or put your system at risk");
Logger.Info($"***{Environment.NewLine}");

Logger.Info($"Startup: {DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)}");
Logger.Info($"OS: {Environment.OSVersion}");
Logger.Info($"x64 OS: {Environment.Is64BitOperatingSystem}");
Logger.Info($"Processors: {Environment.ProcessorCount}");
Logger.Info($".NET Version: {Environment.Version}");
Logger.Info($"x64 Process: {Environment.Is64BitProcess}");
Logger.Info($"CurrentDirectory: {Environment.CurrentDirectory}");
Logger.Info($"ApplicationDirectory: {Util.ExecutingDirectory()}");
Logger.Info($"RelativeApplicationDirectory: {Util.RelativeExecutingDirectory()}");

bool isService = parameter.Switches.Contains("--service");

if (_setting == null)
Expand Down Expand Up @@ -112,7 +135,7 @@ public CommandResultType Run(CommandParameter parameter)
waitHandle.WaitOne();
return CommandResultType.Exit;
}

return CommandResultType.Completed;
}

Expand Down
6 changes: 5 additions & 1 deletion Arrowgene.Ddon.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal class Program
PacketId.S2C_CONNECTION_PING_RES,
PacketId.C2L_PING_REQ,
PacketId.L2C_PING_RES,
PacketId.S2C_LOBBY_LOBBY_DATA_MSG_NTC,
};

private static void Main(string[] args)
Expand Down Expand Up @@ -371,8 +372,11 @@ private void LogProviderOnLogWrite(object sender, LogWriteEventArgs e)
Console.ForegroundColor = consoleColor;
Console.WriteLine(text);
Console.ResetColor();

// TODO perhaps some buffering and only flush after X logs
string filePath = Path.Combine(_logDir.FullName, $"{log.DateTime:yyyy-MM-dd}.log.txt");
File.AppendAllText(filePath, text);
using StreamWriter sw = new StreamWriter(filePath, append: true);
sw.WriteLine(text);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Arrowgene.Ddon.Cli/Setting.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Runtime.Serialization;
using Arrowgene.Ddon.Database;
using Arrowgene.Ddon.GameServer;
using Arrowgene.Ddon.LoginServer;
using Arrowgene.Ddon.Shared;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Ddon.WebServer;

namespace Arrowgene.Ddon.Cli
Expand Down
426 changes: 236 additions & 190 deletions Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql

Large diffs are not rendered by default.

42 changes: 39 additions & 3 deletions Arrowgene.Ddon.Database/IDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Arrowgene.Ddon.Database.Model;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Model;

namespace Arrowgene.Ddon.Database
Expand All @@ -23,16 +24,51 @@ public interface IDatabase

// Character
bool CreateCharacter(Character character);
public bool UpdateCharacter(Character character);
public Character SelectCharacter(uint characterId);
bool UpdateCharacter(Character character);
Character SelectCharacter(uint characterId);
List<Character> SelectCharactersByAccountId(int accountId);
public bool DeleteCharacter(uint characterId);
bool DeleteCharacter(uint characterId);

bool UpdateCharacterBaseInfo(Character character);

// CustomSkills
bool InsertEquippedCustomSkill(uint characterId, CustomSkill skill);
bool ReplaceEquippedCustomSkill(uint characterId, CustomSkill skill);
bool UpdateEquippedCustomSkill(uint characterId, JobId oldJob, byte oldSlotNo, CustomSkill skill);
bool DeleteEquippedCustomSkill(uint characterId, JobId job, byte slotNo);

// Abilities
bool InsertEquippedAbility(uint characterId, Ability skill);
bool ReplaceEquippedAbility(uint characterId, Ability skill);
bool ReplaceEquippedAbilities(uint characterId, JobId equippedToJob, List<Ability> abilities);
bool UpdateEquippedAbility(uint characterId, JobId oldEquippedToJob, byte oldSlotNo, Ability skill);
bool DeleteEquippedAbility(uint characterId, JobId equippedToJob, byte slotNo);
bool DeleteEquippedAbilities(uint characterId, JobId equippedToJob);

// Shortcut
bool InsertShortcut(uint characterId, CDataShortCut shortcut);
bool ReplaceShortcut(uint characterId, CDataShortCut shortcut);
bool UpdateShortcut(uint characterId, uint oldPageNo, uint oldButtonNo, CDataShortCut updatedShortcut);
bool DeleteShortcut(uint characterId, uint pageNo, uint buttonNo);

// CommunicationShortcut
bool InsertCommunicationShortcut(uint characterId, CDataCommunicationShortCut communicationShortcut);
bool ReplaceCommunicationShortcut(uint characterId, CDataCommunicationShortCut communicationShortcut);
bool UpdateCommunicationShortcut(uint characterId, uint oldPageNo, uint oldButtonNo, CDataCommunicationShortCut updatedCommunicationShortcut);
bool DeleteCommunicationShortcut(uint characterId, uint pageNo, uint buttonNo);

// GameToken
bool SetToken(GameToken token);
GameToken SelectTokenByAccountId(int accountId);
GameToken SelectToken(string tokenStr);
bool DeleteTokenByAccountId(int accountId);
bool DeleteToken(string token);

// Connections
bool InsertConnection(Connection connection);
List<Connection> SelectConnectionsByAccountId(int accountId);
bool DeleteConnection(int serverId, int accountId);
bool DeleteConnectionsByAccountId(int accountId);
bool DeleteConnectionsByServerId(int serverId);
}
}
5 changes: 2 additions & 3 deletions Arrowgene.Ddon.Database/Model/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public class Account
public string MailToken { get; set; }
public string PasswordToken { get; set; }
public string LoginToken { get; set; }

public DateTime LoginTokenCreated { get; set; }
public DateTime? LoginTokenCreated { get; set; }
public bool MailVerified { get; set; }
public DateTime? MailVerifiedAt { get; set; }
public AccountStateType State { get; set; }
public DateTime? LastLogin { get; set; }
public DateTime? LastAuthentication { get; set; }
public DateTime Created { get; set; }

public Account()
Expand Down
16 changes: 16 additions & 0 deletions Arrowgene.Ddon.Database/Model/Connection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Arrowgene.Ddon.Database.Model
{
public class Connection
{
public int ServerId { get; set; }
public int AccountId { get; set; }
public ConnectionType Type { get; set; }
public DateTime Created { get; set; }

public Connection()
{
}
}
}
8 changes: 8 additions & 0 deletions Arrowgene.Ddon.Database/Model/ConnectionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Arrowgene.Ddon.Database.Model
{
public enum ConnectionType
{
LoginServer,
GameServer,
}
}
6 changes: 5 additions & 1 deletion Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ public static string BuildQueryInsert(params string[][] fieldLists)
return sb.ToString();
}

protected override void Exception(Exception ex)
protected override void Exception(Exception ex, string query)
{
Logger.Exception(ex);
if (query != null)
{
Logger.Error($"Exception during query: {query}");
}
}
}
}
36 changes: 15 additions & 21 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@ public abstract partial class DdonSqlDb<TCon, TCom> : SqlDb<TCon, TCom>
where TCon : DbConnection
where TCom : DbCommand
{
private const string SqlInsertAccount =
"INSERT INTO `account` (`name`, `normal_name`, `hash`, `mail`, `mail_verified`, `mail_verified_at`, `mail_token`, `password_token`, `login_token`, `login_token_created`, `state`, `last_login`, `created`) VALUES (@name, @normal_name, @hash, @mail, @mail_verified, @mail_verified_at, @mail_token, @password_token, @login_token, @login_token_created, @state, @last_login, @created);";

private const string SqlSelectAccountById =
"SELECT `id`, `name`, `normal_name`, `hash`, `mail`, `mail_verified`, `mail_verified_at`, `mail_token`, `password_token`, `login_token`, `login_token_created`, `state`, `last_login`, `created` FROM `account` WHERE `id`=@id;";

private const string SqlSelectAccountByName =
"SELECT `id`, `name`, `normal_name`, `hash`, `mail`, `mail_verified`, `mail_verified_at`, `mail_token`, `password_token`, `login_token`, `login_token_created`, `state`, `last_login`, `created` FROM `account` WHERE `normal_name`=@normal_name;";

private const string SqlSelectAccountByLoginToken =
"SELECT `id`, `name`, `normal_name`, `hash`, `mail`, `mail_verified`, `mail_verified_at`, `mail_token`, `password_token`, `login_token`, `login_token_created`, `state`, `last_login`, `created` FROM `account` WHERE `login_token`=@login_token;";

private const string SqlUpdateAccount =
"UPDATE `account` SET `name`=@name, `normal_name`=@normal_name, `hash`=@hash, `mail`=@mail, `mail_verified`=@mail_verified, `mail_verified_at`=@mail_verified_at, `mail_token`=@mail_token, `password_token`=@password_token, `login_token`=@login_token, `login_token_created`=@login_token_created, `state`=@state, `last_login`=@last_login, `created`=@created WHERE `id`=@id;";

private const string SqlDeleteAccount =
"DELETE FROM `account` WHERE `id`=@id;";
private static readonly string[] AccountFields = new string[]
{
"name", "normal_name", "hash", "mail", "mail_verified", "mail_verified_at", "mail_token", "password_token", "login_token", "login_token_created", "state", "last_login", "created"
};

private static readonly string SqlInsertAccount = $"INSERT INTO `account` ({BuildQueryField(AccountFields)}) VALUES ({BuildQueryInsert(AccountFields)});";
private static readonly string SqlSelectAccountById = $"SELECT `id`, {BuildQueryField(AccountFields)} FROM `account` WHERE `id`=@id;";
private static readonly string SqlSelectAccountByName = $"SELECT `id`, {BuildQueryField(AccountFields)} FROM `account` WHERE `normal_name`=@normal_name;";
private static readonly string SqlSelectAccountByLoginToken = $"SELECT `id`, {BuildQueryField(AccountFields)} FROM `account` WHERE `login_token`=@login_token;";
private static readonly string SqlUpdateAccount = $"UPDATE `account` SET {BuildQueryUpdate(AccountFields)} WHERE `id`=@id;";
private const string SqlDeleteAccount = "DELETE FROM `account` WHERE `id`=@id;";

public Account CreateAccount(string name, string mail, string hash)
{
Expand All @@ -48,7 +42,7 @@ public Account CreateAccount(string name, string mail, string hash)
AddParameter(command, "@login_token", account.LoginToken);
AddParameter(command, "@login_token_created", account.LoginTokenCreated);
AddParameterEnumInt32(command, "@state", account.State);
AddParameter(command, "@last_login", account.LastLogin);
AddParameter(command, "@last_login", account.LastAuthentication);
AddParameter(command, "@created", account.Created);
}, out long autoIncrement);
if (rowsAffected <= NoRowsAffected || autoIncrement <= NoAutoIncrement)
Expand Down Expand Up @@ -120,7 +114,7 @@ public bool UpdateAccount(Account account)
AddParameter(command, "@login_token", account.LoginToken);
AddParameter(command, "@login_token_created", account.LoginTokenCreated);
AddParameterEnumInt32(command, "@state", account.State);
AddParameter(command, "@last_login", account.LastLogin);
AddParameter(command, "@last_login", account.LastAuthentication);
AddParameter(command, "@created", account.Created);
AddParameter(command, "@id", account.Id);
});
Expand All @@ -147,9 +141,9 @@ private Account ReadAccount(DbDataReader reader)
account.MailToken = GetStringNullable(reader, "mail_token");
account.PasswordToken = GetStringNullable(reader, "password_token");
account.LoginToken = GetStringNullable(reader, "login_token");
account.LoginTokenCreated = GetDateTime(reader, "login_token_created");
account.LoginTokenCreated = GetDateTimeNullable(reader, "login_token_created");
account.State = (AccountStateType) GetInt32(reader, "state");
account.LastLogin = GetDateTimeNullable(reader, "last_login");
account.LastAuthentication = GetDateTimeNullable(reader, "last_login");
account.Created = GetDateTime(reader, "created");
return account;
}
Expand Down
Loading

0 comments on commit 66053ba

Please sign in to comment.