FunGame-Server/FunGame.Server/Utilities/ConnectProperties.cs
milimoe 14ff58f4f4
为服务器统一数据访问连接 (#37)
* 添加 Web API 和 RESTful API 模式;
* 添加 SQLite 模式;
* 添加 ISocketMessageProcessor 和 ISocketListener<> 接口,用于统一数据访问;
* 重做了 ISocketModel;
* 完善了 WebSocket 的连接模式。
2024-10-04 12:39:15 +08:00

53 lines
2.0 KiB
C#

using Milimoe.FunGame.Core.Api.Utility;
namespace Milimoe.FunGame.Server.Utility
{
public class ConnectProperties
{
public static string Name { get; set; } = "";
public static string DataSource { get; set; } = "";
public static string Port { get; set; } = "";
public static string DataBase { get; set; } = "";
public static string User { get; set; } = "";
public static string Password { get; set; } = "";
/// <summary>
/// 读取MySQL服务器配置文件
/// </summary>
/// <returns></returns>
public static string GetConnectPropertiesForMySQL()
{
if (Name == "" && DataSource == "" && Port == "" && DataBase == "" && User == "" && Password == "")
{
if (INIHelper.ExistINIFile())
{
DataSource = INIHelper.ReadINI("MySQL", "DBServer");
Port = INIHelper.ReadINI("MySQL", "DBPort");
DataBase = INIHelper.ReadINI("MySQL", "DBName");
User = INIHelper.ReadINI("MySQL", "DBUser");
Password = INIHelper.ReadINI("MySQL", "DBPassword");
}
else ServerHelper.Error(new MySQLConfigException());
}
return "data source = " + DataSource + "; port = " + Port + "; database = " + DataBase + "; user = " + User + "; password = " + Password + "; charset = utf8mb4;";
}
/// <summary>
/// 读取SQLite服务器配置文件
/// </summary>
/// <returns></returns>
public static string GetConnectPropertiesForSQLite()
{
if (DataSource == "")
{
if (INIHelper.ExistINIFile())
{
DataSource = INIHelper.ReadINI("SQLite", "DataSource");
}
else ServerHelper.Error(new SQLServiceException());
}
return "data source=" + DataSource;
}
}
}