修为内置连接池
This commit is contained in:
parent
f1850ac37e
commit
48f465c35e
AxibugEmuOnline.Server
AxibugEmuOnline.Web
Common
Controllers
Properties/PublishProfiles
@ -1,202 +0,0 @@
|
|||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace AxibugEmuOnline.Server.Common
|
|
||||||
{
|
|
||||||
public static class SQLPool
|
|
||||||
{
|
|
||||||
static Queue<MySqlConnection> _ConQueue = new Queue<MySqlConnection>();
|
|
||||||
static Dictionary<MySqlConnection, Haoyue_PoolTime> _OutOfSQLPool = new Dictionary<MySqlConnection, Haoyue_PoolTime>();
|
|
||||||
static Dictionary<string, long> _DicSqlRunFunNum = new Dictionary<string, long>();
|
|
||||||
static Dictionary<string, long> _DicTimeOutSqlRunFunNum = new Dictionary<string, long>();
|
|
||||||
const int DefaultCount = 1;
|
|
||||||
const int MaxLimit = 5;
|
|
||||||
static readonly object _sync = new object();
|
|
||||||
static MySqlConnectionStringBuilder connBuilder;
|
|
||||||
|
|
||||||
public static void InitConnMgr()
|
|
||||||
{
|
|
||||||
connBuilder = new MySqlConnectionStringBuilder();
|
|
||||||
connBuilder.Database = Config.cfg.DBName;
|
|
||||||
connBuilder.Server = Config.cfg.DBIp;
|
|
||||||
connBuilder.UserID = Config.cfg.DBUname;
|
|
||||||
connBuilder.Password = Config.cfg.DBPwd;
|
|
||||||
connBuilder.Port = Config.cfg.DBPort;
|
|
||||||
//connBuilder.MinimumPoolSize = 40u;
|
|
||||||
//connBuilder.MaximumPoolSize = 100u;
|
|
||||||
connBuilder.Pooling = true;
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("SQLPool连接初始化....");
|
|
||||||
for (int i = 0; i < DefaultCount; i++)
|
|
||||||
{
|
|
||||||
MySqlConnection _conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
_ConQueue.Enqueue(_conn);
|
|
||||||
}
|
|
||||||
Console.WriteLine("SQLPool初始化完毕,连接数" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
public static MySqlConnection conn()
|
|
||||||
{
|
|
||||||
return new MySqlConnection(connBuilder.ConnectionString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MySqlConnection DequeueSQLConn(string FuncStr)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"[DequeueSQLConn]{FuncStr}");
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
if (_DicSqlRunFunNum.ContainsKey(FuncStr))
|
|
||||||
{
|
|
||||||
_DicSqlRunFunNum[FuncStr]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_DicSqlRunFunNum[FuncStr] = 1L;
|
|
||||||
}
|
|
||||||
MySqlConnection _conn = null;
|
|
||||||
if (_ConQueue.Count < 1)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]创建新的SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
_conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MySqlConnection temp = null;
|
|
||||||
while (_ConQueue.Count > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]取出一个SQLCount.Count>" + _ConQueue.Count);
|
|
||||||
temp = _ConQueue.Dequeue();
|
|
||||||
if (temp.State == System.Data.ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]已经断开SQLCount.Count>" + _ConQueue.Count);
|
|
||||||
temp.Dispose();
|
|
||||||
temp = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temp != null)
|
|
||||||
{
|
|
||||||
_conn = temp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]连接池全部已断开,重新创建连接");
|
|
||||||
_conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_OutOfSQLPool.Add(_conn, new Haoyue_PoolTime
|
|
||||||
{
|
|
||||||
time = time(),
|
|
||||||
FuncStr = FuncStr
|
|
||||||
});
|
|
||||||
|
|
||||||
return _conn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void EnqueueSQLConn(MySqlConnection BackConn)
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
if (_OutOfSQLPool.ContainsKey(BackConn))
|
|
||||||
{
|
|
||||||
_OutOfSQLPool.Remove(BackConn);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("出队遗漏的数据出现了!");
|
|
||||||
}
|
|
||||||
if (_ConQueue.Count > MaxLimit)
|
|
||||||
{
|
|
||||||
Console.WriteLine("已经不需要回收了,多余了,SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
BackConn.Close();
|
|
||||||
BackConn.Dispose();
|
|
||||||
BackConn = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ConQueue.Enqueue(BackConn);
|
|
||||||
Console.WriteLine("回收SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CheckPoolTimeOut()
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
long now = time();
|
|
||||||
List<MySqlConnection> removeTemp = new List<MySqlConnection>();
|
|
||||||
foreach (KeyValuePair<MySqlConnection, Haoyue_PoolTime> o2 in _OutOfSQLPool)
|
|
||||||
{
|
|
||||||
if (now - o2.Value.time >= 120)
|
|
||||||
{
|
|
||||||
if (_DicTimeOutSqlRunFunNum.ContainsKey(o2.Value.FuncStr))
|
|
||||||
{
|
|
||||||
_DicTimeOutSqlRunFunNum[o2.Value.FuncStr]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_DicTimeOutSqlRunFunNum[o2.Value.FuncStr] = 1L;
|
|
||||||
}
|
|
||||||
if (_ConQueue.Count > MaxLimit)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]" + o2.Value.FuncStr + "已经不需要回收了,多余了,SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
o2.Key.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]" + o2.Value.FuncStr + "回收SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
_ConQueue.Enqueue(o2.Key);
|
|
||||||
}
|
|
||||||
removeTemp.Add(o2.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removeTemp.Count() <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach (MySqlConnection o in removeTemp)
|
|
||||||
{
|
|
||||||
if (_OutOfSQLPool.ContainsKey(o))
|
|
||||||
{
|
|
||||||
_OutOfSQLPool.Remove(o);
|
|
||||||
Console.WriteLine("[超时回收]_OutOfSQLPool清理");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]_OutOfSQLPool清理异常???????");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("[超时回收]处理结束SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static long time()
|
|
||||||
{
|
|
||||||
return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
|
|
||||||
}
|
|
||||||
public static void GetPoolState()
|
|
||||||
{
|
|
||||||
Console.WriteLine("-----------------查询统计-----------------");
|
|
||||||
foreach (KeyValuePair<string, long> dic2 in _DicSqlRunFunNum)
|
|
||||||
{
|
|
||||||
Console.WriteLine(dic2.Key + ":" + dic2.Value);
|
|
||||||
}
|
|
||||||
Console.WriteLine("-----------------超时统计-----------------");
|
|
||||||
foreach (KeyValuePair<string, long> dic in _DicTimeOutSqlRunFunNum)
|
|
||||||
{
|
|
||||||
Console.WriteLine(dic.Key + ":" + dic.Value);
|
|
||||||
}
|
|
||||||
Console.WriteLine("------------------------------------------");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Haoyue_PoolTime
|
|
||||||
{
|
|
||||||
public long time { get; set; }
|
|
||||||
public string FuncStr { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
72
AxibugEmuOnline.Server/Common/SQLRUN.cs
Normal file
72
AxibugEmuOnline.Server/Common/SQLRUN.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
namespace AxibugEmuOnline.Server.Common
|
||||||
|
{
|
||||||
|
public static class SQLRUN
|
||||||
|
{
|
||||||
|
// 移除自定义队列和状态跟踪字典
|
||||||
|
private static Dictionary<string, long> _DicSqlRunFunNum = new Dictionary<string, long>();
|
||||||
|
private static Dictionary<string, long> _DicTimeOutSqlRunFunNum = new Dictionary<string, long>();
|
||||||
|
|
||||||
|
const int DefaultCount = 1;
|
||||||
|
const int MaxLimit = 10;
|
||||||
|
static readonly object _sync = new object();
|
||||||
|
static MySqlConnectionStringBuilder connBuilder;
|
||||||
|
|
||||||
|
public static void InitConnMgr()
|
||||||
|
{
|
||||||
|
// 配置 MySQL 内置连接池
|
||||||
|
connBuilder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Database = Config.cfg.DBName,
|
||||||
|
Server = Config.cfg.DBIp,
|
||||||
|
UserID = Config.cfg.DBUname,
|
||||||
|
Password = Config.cfg.DBPwd,
|
||||||
|
Port = Config.cfg.DBPort,
|
||||||
|
Pooling = true, // 启用内置连接池
|
||||||
|
MinimumPoolSize = DefaultCount, // 最小连接数
|
||||||
|
MaximumPoolSize = MaxLimit, // 最大连接数
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化时不手动创建连接,依赖连接池自动管理
|
||||||
|
Console.WriteLine("SQLPool初始化完成,连接池参数已配置");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MySqlConnection GetConn(string FuncStr)
|
||||||
|
{
|
||||||
|
lock (_sync)
|
||||||
|
{
|
||||||
|
IncrementFuncCall(FuncStr);
|
||||||
|
// 直接使用 MySQL 内置连接池获取连接
|
||||||
|
var conn = new MySqlConnection(connBuilder.ConnectionString);
|
||||||
|
conn.Open();
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetPoolState()
|
||||||
|
{
|
||||||
|
Console.WriteLine("-----------------查询统计-----------------");
|
||||||
|
foreach (var entry in _DicSqlRunFunNum)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"函数 {entry.Key} 调用次数: {entry.Value}");
|
||||||
|
}
|
||||||
|
Console.WriteLine("-----------------超时统计-----------------");
|
||||||
|
foreach (var entry in _DicTimeOutSqlRunFunNum)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"函数 {entry.Key} 超时次数: {entry.Value}");
|
||||||
|
}
|
||||||
|
Console.WriteLine("------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 私有方法(辅助统计逻辑)
|
||||||
|
private static void IncrementFuncCall(string funcStr)
|
||||||
|
{
|
||||||
|
_DicSqlRunFunNum[funcStr] = _DicSqlRunFunNum.ContainsKey(funcStr) ? _DicSqlRunFunNum[funcStr] + 1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,7 +24,7 @@ namespace AxibugEmuOnline.Server
|
|||||||
g_Log = new LogManager();
|
g_Log = new LogManager();
|
||||||
Config.LoadConfig();
|
Config.LoadConfig();
|
||||||
AESHelper.LoadKeyIVCfg(Config.cfg.AesKey, Config.cfg.AesIv);
|
AESHelper.LoadKeyIVCfg(Config.cfg.AesKey, Config.cfg.AesIv);
|
||||||
SQLPool.InitConnMgr();
|
SQLRUN.InitConnMgr();
|
||||||
g_Tick = new TickManager();
|
g_Tick = new TickManager();
|
||||||
g_ClientMgr = new ClientManager();
|
g_ClientMgr = new ClientManager();
|
||||||
g_ClientMgr.Init(45000, 120);
|
g_ClientMgr.Init(45000, 120);
|
||||||
|
@ -21,82 +21,83 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(_socket);
|
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(_socket);
|
||||||
Protobuf_Game_Mark_RESP respData = new Protobuf_Game_Mark_RESP();
|
Protobuf_Game_Mark_RESP respData = new Protobuf_Game_Mark_RESP();
|
||||||
|
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RecvGameMark");
|
using (MySqlConnection conn = SQLRUN.GetConn("RecvGameMark"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "SELECT id from rom_stars where uid = ?uid and romid = ?romid";
|
try
|
||||||
bool bHad = false;
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = "SELECT id from rom_stars where uid = ?uid and romid = ?romid";
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
bool bHad = false;
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
bHad = true;
|
while (reader.Read())
|
||||||
break;
|
{
|
||||||
|
bHad = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//收藏
|
//收藏
|
||||||
if (msg.Motion == 1)
|
if (msg.Motion == 1)
|
||||||
{
|
|
||||||
if (bHad)
|
|
||||||
{
|
{
|
||||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorRomAlreadyHadStar, ProtoBufHelper.Serizlize(respData));
|
if (bHad)
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
query = "INSERT INTO `haoyue_emu`.`rom_stars` (`uid`, `romid`) VALUES (?uid, ?romid);";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorRomAlreadyHadStar, ProtoBufHelper.Serizlize(respData));
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
return;
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
}
|
||||||
command.ExecuteNonQuery();
|
else
|
||||||
|
{
|
||||||
|
query = "INSERT INTO `haoyue_emu`.`rom_stars` (`uid`, `romid`) VALUES (?uid, ?romid);";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else//取消收藏
|
||||||
else//取消收藏
|
|
||||||
{
|
|
||||||
if (bHad)
|
|
||||||
{
|
{
|
||||||
query = "DELETE from rom_stars where uid = ?uid and romid = ?romid";
|
if (bHad)
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
query = "DELETE from rom_stars where uid = ?uid and romid = ?romid";
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
{
|
||||||
command.ExecuteNonQuery();
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorRomDontHadStar, ProtoBufHelper.Serizlize(respData));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
//更新收藏数
|
||||||
|
query = "update romlist set stars = (SELECT COUNT(id) from rom_stars where rom_stars.romid = ?romid) where romlist.id = ?romid";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorRomDontHadStar, ProtoBufHelper.Serizlize(respData));
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
return;
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//更新收藏数
|
|
||||||
query = "update romlist set stars = (SELECT COUNT(id) from rom_stars where rom_stars.romid = ?romid) where romlist.id = ?romid";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
respData.Stars = GetRomStart(msg.RomID);
|
respData.Stars = GetRomStart(msg.RomID);
|
||||||
respData.IsStar = CheckIsRomStar(msg.RomID, _c.UID) ? 1 : 0;
|
respData.IsStar = CheckIsRomStar(msg.RomID, _c.UID) ? 1 : 0;
|
||||||
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
respData.RomID = msg.RomID;
|
respData.RomID = msg.RomID;
|
||||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
|
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGameMark, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
|
||||||
}
|
}
|
||||||
@ -104,59 +105,61 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
public int GetRomStart(int RomId)
|
public int GetRomStart(int RomId)
|
||||||
{
|
{
|
||||||
int stars = 0;
|
int stars = 0;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("GetStart");
|
using (MySqlConnection conn = SQLRUN.GetConn("GetStart"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = $"SELECT `stars` FROM romlist where id = ?romid;";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = $"SELECT `stars` FROM romlist where id = ?romid;";
|
||||||
command.Parameters.AddWithValue("?RomID", RomId);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
// 执行查询并处理结果
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?RomID", RomId);
|
||||||
|
// 执行查询并处理结果
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
stars = reader.GetInt32(0);
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
stars = reader.GetInt32(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AppSrv.g_Log.Error(e);
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
return stars;
|
return stars;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckIsRomStar(int RomId, long uid)
|
public bool CheckIsRomStar(int RomId, long uid)
|
||||||
{
|
{
|
||||||
bool bhad = false;
|
bool bhad = false;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("CheckIsRomStart");
|
using (MySqlConnection conn = SQLRUN.GetConn("CheckIsRomStart"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = $"SELECT count(id) from rom_stars where uid = ?uid and romid = ?romid";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = $"SELECT count(id) from rom_stars where uid = ?uid and romid = ?romid";
|
||||||
command.Parameters.AddWithValue("?romid", RomId);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
|
||||||
// 执行查询并处理结果
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?romid", RomId);
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
// 执行查询并处理结果
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
bhad = reader.GetInt32(0) > 0;
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
bhad = reader.GetInt32(0) > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Error("CheckIsRomStar:" + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AppSrv.g_Log.Error("CheckIsRomStar:"+e);
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
return bhad;
|
return bhad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +169,8 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
return ptype;
|
return ptype;
|
||||||
|
|
||||||
ptype = RomPlatformType.Invalid;
|
ptype = RomPlatformType.Invalid;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("GetRomPlatformType");
|
using (MySqlConnection conn = SQLRUN.GetConn("GetRomPlatformType"))
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string query = "SELECT PlatformType from romlist where Id = ?RomID ";
|
string query = "SELECT PlatformType from romlist where Id = ?RomID ";
|
||||||
@ -188,12 +192,11 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
{
|
{
|
||||||
AppSrv.g_Log.Error(e);
|
AppSrv.g_Log.Error(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ptype == RomPlatformType.Invalid)
|
if (ptype == RomPlatformType.Invalid)
|
||||||
AppSrv.g_Log.Error($"RomID {RomID} 没找到平台配置");
|
AppSrv.g_Log.Error($"RomID {RomID} 没找到平台配置");
|
||||||
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
|
|
||||||
return ptype;
|
return ptype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,25 +79,26 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
bool bDone = false;
|
bool bDone = false;
|
||||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(socket);
|
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(socket);
|
||||||
Protobuf_Modify_NickName msg = ProtoBufHelper.DeSerizlize<Protobuf_Modify_NickName>(reqData);
|
Protobuf_Modify_NickName msg = ProtoBufHelper.DeSerizlize<Protobuf_Modify_NickName>(reqData);
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("ModifyNikeName");
|
using (MySqlConnection conn = SQLRUN.GetConn("ModifyNikeName"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "update users set nikename = ?nikename where uid = ?uid ";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = "update users set nikename = ?nikename where uid = ?uid ";
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?nikename", msg.NickName);
|
|
||||||
if (command.ExecuteNonQuery() > 0)
|
|
||||||
{
|
{
|
||||||
bDone = true;
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?nikename", msg.NickName);
|
||||||
|
if (command.ExecuteNonQuery() > 0)
|
||||||
|
{
|
||||||
|
bDone = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
|
|
||||||
if (bDone)
|
if (bDone)
|
||||||
{
|
{
|
||||||
@ -132,34 +133,15 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
{
|
{
|
||||||
uid = 0;
|
uid = 0;
|
||||||
bool bDone = true;
|
bool bDone = true;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("GetUidByDevice");
|
using (MySqlConnection conn = SQLRUN.GetConn("GetUidByDevice"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "SELECT uid from user_devices where device = ?deviceStr ";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = "SELECT uid from user_devices where device = ?deviceStr ";
|
||||||
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
|
||||||
// 执行查询并处理结果
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
uid = reader.GetInt64(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uid > 0)
|
|
||||||
{
|
|
||||||
AppSrv.g_Log.Info($"设备串:{deviceStr} 对应 UID:{uid}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
query = "INSERT INTO `haoyue_emu`.`users` (`nikename`, `regdate`,`lastlogindate`) VALUES (NULL,now(),now());SELECT LAST_INSERT_ID(); ";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
// 设置参数值
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
||||||
// 执行查询并处理结果
|
// 执行查询并处理结果
|
||||||
using (var reader = command.ExecuteReader())
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
@ -170,39 +152,59 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置默认名字
|
if (uid > 0)
|
||||||
query = "update users set nikename = ?nikename where uid = ?uid ";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
AppSrv.g_Log.Info($"设备串:{deviceStr} 对应 UID:{uid}");
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
}
|
||||||
command.Parameters.AddWithValue("?nikename", GetRandomNickName(uid));
|
else
|
||||||
if (command.ExecuteNonQuery() < 1)
|
{
|
||||||
|
query = "INSERT INTO `haoyue_emu`.`users` (`nikename`, `regdate`,`lastlogindate`) VALUES (NULL,now(),now());SELECT LAST_INSERT_ID(); ";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
bDone = false;
|
// 设置参数值
|
||||||
|
// 执行查询并处理结果
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
uid = reader.GetInt64(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置默认名字
|
||||||
|
query = "update users set nikename = ?nikename where uid = ?uid ";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
command.Parameters.AddWithValue("?nikename", GetRandomNickName(uid));
|
||||||
|
if (command.ExecuteNonQuery() < 1)
|
||||||
|
{
|
||||||
|
bDone = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query = "INSERT INTO `haoyue_emu`.`user_devices` (`device`, `devicetype`, `uid`) VALUES (?deviceStr, ?DeviceType, ?uid);";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
||||||
|
command.Parameters.AddWithValue("?DeviceType", (int)DeviceType);
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
if (command.ExecuteNonQuery() < 1)
|
||||||
|
bDone = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppSrv.g_Log.Info($"创建新账户,设备:{deviceStr},设备类型:{DeviceType.ToString()},是否成功:{bDone}");
|
||||||
}
|
}
|
||||||
|
|
||||||
query = "INSERT INTO `haoyue_emu`.`user_devices` (`device`, `devicetype`, `uid`) VALUES (?deviceStr, ?DeviceType, ?uid);";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
|
||||||
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
|
||||||
command.Parameters.AddWithValue("?DeviceType", (int)DeviceType);
|
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
|
||||||
if (command.ExecuteNonQuery() < 1)
|
|
||||||
bDone = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppSrv.g_Log.Info($"创建新账户,设备:{deviceStr},设备类型:{DeviceType.ToString()},是否成功:{bDone}");
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Error($"ex=>{e.ToString()}");
|
||||||
|
bDone = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AppSrv.g_Log.Error($"ex=>{e.ToString()}");
|
|
||||||
bDone = false;
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
|
|
||||||
if (uid <= 0)
|
if (uid <= 0)
|
||||||
bDone = false;
|
bDone = false;
|
||||||
@ -211,41 +213,42 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
|
|
||||||
public void UpdateUserData(long uid, ClientInfo _c, DeviceType deviceType)
|
public void UpdateUserData(long uid, ClientInfo _c, DeviceType deviceType)
|
||||||
{
|
{
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("UpdateUserData");
|
using (MySqlConnection conn = SQLRUN.GetConn("UpdateUserData"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "SELECT account,nikename,regdate,lastlogindate from users where uid = ?uid ";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = "SELECT account,nikename,regdate,lastlogindate from users where uid = ?uid ";
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
// 执行查询并处理结果
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
// 执行查询并处理结果
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
|
||||||
_c.Account = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);
|
_c.Account = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);
|
||||||
_c.NickName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
|
_c.NickName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
|
||||||
_c.LogInDT = DateTime.Now;
|
_c.LogInDT = DateTime.Now;
|
||||||
_c.RegisterDT = reader.IsDBNull(2) ? DateTime.Now : reader.GetDateTime(2);
|
_c.RegisterDT = reader.IsDBNull(2) ? DateTime.Now : reader.GetDateTime(2);
|
||||||
_c.LastLogInDT = reader.IsDBNull(3) ? DateTime.Now : reader.GetDateTime(3);
|
_c.LastLogInDT = reader.IsDBNull(3) ? DateTime.Now : reader.GetDateTime(3);
|
||||||
_c.deviceType = deviceType;
|
_c.deviceType = deviceType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
query = "update users set lastlogindate = now() where uid = ?uid ";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
query = "update users set lastlogindate = now() where uid = ?uid ";
|
catch (Exception e)
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static string GenToken(ClientInfo _c)
|
static string GenToken(ClientInfo _c)
|
||||||
|
@ -109,10 +109,9 @@ namespace AxibugEmuOnline.Server
|
|||||||
}
|
}
|
||||||
public void RoomLog(long uid, int platform, int RoomID, int RomID, RoomLogType state)
|
public void RoomLog(long uid, int platform, int RoomID, int RomID, RoomLogType state)
|
||||||
{
|
{
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RoomLog");
|
string query = "INSERT INTO `haoyue_emu`.`room_log` (`uid`, `platform`, `romid`,`roomid`, `state`) VALUES ( ?uid, ?platform, ?romid, ?roomid, ?state);";
|
||||||
try
|
using (MySqlConnection conn = SQLRUN.GetConn("RoomLog"))
|
||||||
{
|
{
|
||||||
string query = "INSERT INTO `haoyue_emu`.`room_log` (`uid`, `platform`, `romid`,`roomid`, `state`) VALUES ( ?uid, ?platform, ?romid, ?roomid, ?state);";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
// 设置参数值
|
// 设置参数值
|
||||||
@ -134,10 +133,6 @@ namespace AxibugEmuOnline.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -240,7 +235,7 @@ namespace AxibugEmuOnline.Server
|
|||||||
Data_RoomData newRoom = new Data_RoomData();
|
Data_RoomData newRoom = new Data_RoomData();
|
||||||
|
|
||||||
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(msg.GameRomID);
|
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(msg.GameRomID);
|
||||||
newRoom.Init(GetNewRoomID(), msg.GameRomID, msg.GameRomHash, _c.UID, false,ptype);
|
newRoom.Init(GetNewRoomID(), msg.GameRomID, msg.GameRomHash, _c.UID, false, ptype);
|
||||||
AddRoom(newRoom);
|
AddRoom(newRoom);
|
||||||
ErrorCode joinErrcode = ErrorCode.ErrorOk;
|
ErrorCode joinErrcode = ErrorCode.ErrorOk;
|
||||||
//加入
|
//加入
|
||||||
@ -844,7 +839,7 @@ namespace AxibugEmuOnline.Server
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新同步名单
|
/// 更新同步名单
|
||||||
@ -1291,7 +1286,7 @@ namespace AxibugEmuOnline.Server
|
|||||||
}
|
}
|
||||||
AppSrv.g_Log.Debug($"Join _c.UID->{_c.UID} RoomID->{RoomID}");
|
AppSrv.g_Log.Debug($"Join _c.UID->{_c.UID} RoomID->{RoomID}");
|
||||||
Dictionary<uint, (uint, GamePadType)> slotInfo = new Dictionary<uint, (uint, GamePadType)>();
|
Dictionary<uint, (uint, GamePadType)> slotInfo = new Dictionary<uint, (uint, GamePadType)>();
|
||||||
slotInfo[slotIdx] = (joyIdx,GamePadType.GlobalGamePad);
|
slotInfo[slotIdx] = (joyIdx, GamePadType.GlobalGamePad);
|
||||||
SetPlayerSlotData(_c, ref slotInfo);
|
SetPlayerSlotData(_c, ref slotInfo);
|
||||||
int newPlayerCount = GetPlayerCount();
|
int newPlayerCount = GetPlayerCount();
|
||||||
errcode = ErrorCode.ErrorOk;
|
errcode = ErrorCode.ErrorOk;
|
||||||
|
@ -28,11 +28,11 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
respData.SavDataList.Add(nulldata);
|
respData.SavDataList.Add(nulldata);
|
||||||
respData.SavDataList.Add(nulldata);
|
respData.SavDataList.Add(nulldata);
|
||||||
respData.SavDataList.Add(nulldata);
|
respData.SavDataList.Add(nulldata);
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RecvGameMark");
|
|
||||||
try
|
string query = "SELECT `id`,`uid`,`romid`, `savidx`, `savName`,`savNote`, `savUrl`,`savImgUrl`, `savDate` from user_gamesavedata where uid = ?uid and romid = ?romid";
|
||||||
|
bool bHad = false;
|
||||||
|
using (MySqlConnection conn = SQLRUN.GetConn("RecvGameMark"))
|
||||||
{
|
{
|
||||||
string query = "SELECT `id`,`uid`,`romid`, `savidx`, `savName`,`savNote`, `savUrl`,`savImgUrl`, `savDate` from user_gamesavedata where uid = ?uid and romid = ?romid";
|
|
||||||
bool bHad = false;
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
// 设置参数值
|
// 设置参数值
|
||||||
@ -60,12 +60,7 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
|
|
||||||
respData.RomID = msg.RomID;
|
respData.RomID = msg.RomID;
|
||||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGamesavGetGameSavList, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
|
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdGamesavGetGameSavList, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
|
||||||
@ -79,10 +74,10 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
ErrorCode errCode = ErrorCode.ErrorOk;
|
ErrorCode errCode = ErrorCode.ErrorOk;
|
||||||
respData.RomID = msg.RomID;
|
respData.RomID = msg.RomID;
|
||||||
bool bHad = false; string SavUrl = null; string SavImgUrl = null;
|
bool bHad = false; string SavUrl = null; string SavImgUrl = null;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RecvGameMark");
|
|
||||||
try
|
string query = "SELECT `savUrl`,`savImgUrl`, `savDate` from user_gamesavedata where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
||||||
|
using (MySqlConnection conn = SQLRUN.GetConn("RecvGameMark"))
|
||||||
{
|
{
|
||||||
string query = "SELECT `savUrl`,`savImgUrl`, `savDate` from user_gamesavedata where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
// 设置参数值
|
// 设置参数值
|
||||||
@ -98,44 +93,40 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bHad)
|
if (!bHad)
|
||||||
{
|
|
||||||
errCode = ErrorCode.ErrorRomDontHadSavedata;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool bDelSav = FileDelete(Path.Combine(Config.cfg.savDataPath, SavUrl));
|
|
||||||
bool bDelImg = FileDelete(Path.Combine(Config.cfg.savDataPath, SavImgUrl));
|
|
||||||
if (!bDelSav || !bDelImg)
|
|
||||||
{
|
{
|
||||||
errCode = ErrorCode.ErrorRomDontHadSavedata;
|
errCode = ErrorCode.ErrorRomDontHadSavedata;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
bool bDelSav = FileDelete(Path.Combine(Config.cfg.savDataPath, SavUrl));
|
||||||
|
bool bDelImg = FileDelete(Path.Combine(Config.cfg.savDataPath, SavImgUrl));
|
||||||
|
if (!bDelSav || !bDelImg)
|
||||||
{
|
{
|
||||||
string query = "delete from user_gamesavedata where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
errCode = ErrorCode.ErrorRomDontHadSavedata;
|
||||||
using (var command = new MySqlCommand(query, conn))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// 设置参数值
|
query = "delete from user_gamesavedata where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
|
||||||
if (command.ExecuteNonQuery() < 1)
|
|
||||||
{
|
{
|
||||||
AppSrv.g_Log.Error("删除即时存档,但是他并没有.");
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
|
if (command.ExecuteNonQuery() < 1)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Error("删除即时存档,但是他并没有.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
|
|
||||||
if (errCode == ErrorCode.ErrorOk)
|
if (errCode == ErrorCode.ErrorOk)
|
||||||
{
|
{
|
||||||
@ -174,7 +165,6 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
|
|
||||||
if (errCode == ErrorCode.ErrorOk)
|
if (errCode == ErrorCode.ErrorOk)
|
||||||
{
|
{
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RecvUpLoadGameSav");
|
|
||||||
byte[] StateRawData = msg.StateRaw.ToArray();
|
byte[] StateRawData = msg.StateRaw.ToArray();
|
||||||
byte[] ImgData = msg.SavImg.ToArray();
|
byte[] ImgData = msg.SavImg.ToArray();
|
||||||
GetNewRomPath(_c.UID, ptype, msg.RomID, msg.SavDataIdx, $"{msg.SavDataIdx}.axisav", out string rompath);
|
GetNewRomPath(_c.UID, ptype, msg.RomID, msg.SavDataIdx, $"{msg.SavDataIdx}.axisav", out string rompath);
|
||||||
@ -190,25 +180,27 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
" ( `uid`, `romid`, `savidx`, `savName`, `savNote`, `savUrl`, `savImgUrl`, `savDate`)" +
|
" ( `uid`, `romid`, `savidx`, `savName`, `savNote`, `savUrl`, `savImgUrl`, `savDate`)" +
|
||||||
" VALUES ( ?uid, ?romid, ?savidx, ?savName, ?savNote, ?savUrl, ?savImgUrl, ?savDate);";
|
" VALUES ( ?uid, ?romid, ?savidx, ?savName, ?savNote, ?savUrl, ?savImgUrl, ?savDate);";
|
||||||
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
|
using (MySqlConnection conn = SQLRUN.GetConn("RecvUpLoadGameSav"))
|
||||||
{
|
{
|
||||||
// 设置参数值
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
|
||||||
command.Parameters.AddWithValue("?romid", msg.RomID);
|
|
||||||
command.Parameters.AddWithValue("?savidx", msg.SavDataIdx);
|
|
||||||
command.Parameters.AddWithValue("?savName", msg.Name);
|
|
||||||
command.Parameters.AddWithValue("?savNote", msg.Note);
|
|
||||||
command.Parameters.AddWithValue("?savUrl", rompath);
|
|
||||||
command.Parameters.AddWithValue("?savImgUrl", imgpath);
|
|
||||||
command.Parameters.AddWithValue("?savDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
||||||
if (command.ExecuteNonQuery() < 1)
|
|
||||||
{
|
{
|
||||||
AppSrv.g_Log.Error("执行即时存档保存失败");
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||||
|
command.Parameters.AddWithValue("?romid", msg.RomID);
|
||||||
|
command.Parameters.AddWithValue("?savidx", msg.SavDataIdx);
|
||||||
|
command.Parameters.AddWithValue("?savName", msg.Name);
|
||||||
|
command.Parameters.AddWithValue("?savNote", msg.Note);
|
||||||
|
command.Parameters.AddWithValue("?savUrl", rompath);
|
||||||
|
command.Parameters.AddWithValue("?savImgUrl", imgpath);
|
||||||
|
command.Parameters.AddWithValue("?savDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
if (command.ExecuteNonQuery() < 1)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Error("执行即时存档保存失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -273,44 +265,45 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
bool bhad = false;
|
bool bhad = false;
|
||||||
protoData = default;
|
protoData = default;
|
||||||
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(romid);
|
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(romid);
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("GetProtobufMineGameSavInfo");
|
using (MySqlConnection conn = SQLRUN.GetConn("GetProtobufMineGameSavInfo"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "SELECT `id`,`uid`, `romid`, `savidx`, `savName`, `savNote`, `savUrl`, `savImgUrl`, `savDate` from `user_gamesavedata` where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = "SELECT `id`,`uid`, `romid`, `savidx`, `savName`, `savNote`, `savUrl`, `savImgUrl`, `savDate` from `user_gamesavedata` where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?romid", romid);
|
|
||||||
command.Parameters.AddWithValue("?savidx", savIdx);
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
// 设置参数值
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
command.Parameters.AddWithValue("?romid", romid);
|
||||||
|
command.Parameters.AddWithValue("?savidx", savIdx);
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
protoData = new Protobuf_Mine_GameSavInfo()
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
BHadSaveData = true,
|
protoData = new Protobuf_Mine_GameSavInfo()
|
||||||
SavID = reader.GetInt64(0),
|
{
|
||||||
Uid = reader.GetInt64(1),
|
BHadSaveData = true,
|
||||||
RomID = reader.GetInt32(2),
|
SavID = reader.GetInt64(0),
|
||||||
SavDataIdx = reader.GetInt32(3),
|
Uid = reader.GetInt64(1),
|
||||||
SavName = reader.GetString(4),
|
RomID = reader.GetInt32(2),
|
||||||
Note = reader.GetString(5),
|
SavDataIdx = reader.GetInt32(3),
|
||||||
SavUrl = reader.GetString(6),
|
SavName = reader.GetString(4),
|
||||||
SavImgUrl = reader.GetString(7),
|
Note = reader.GetString(5),
|
||||||
SavDate = reader.GetDateTime(8).ToString("yyyy-MM-dd HH:mm:ss"),
|
SavUrl = reader.GetString(6),
|
||||||
GamePlatformType = ptype
|
SavImgUrl = reader.GetString(7),
|
||||||
};
|
SavDate = reader.GetDateTime(8).ToString("yyyy-MM-dd HH:mm:ss"),
|
||||||
bhad = true;
|
GamePlatformType = ptype
|
||||||
break;
|
};
|
||||||
|
bhad = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
return bhad;
|
return bhad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,8 +311,7 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
{
|
{
|
||||||
bool bDone = false;
|
bool bDone = false;
|
||||||
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(romid);
|
RomPlatformType ptype = AppSrv.g_GameShareMgr.GetRomPlatformType(romid);
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("DeleteProtobufMineGameSavInfo");
|
using (MySqlConnection conn = SQLRUN.GetConn("DeleteProtobufMineGameSavInfo"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = "delete from `user_gamesavedata` where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
string query = "delete from `user_gamesavedata` where uid = ?uid and romid = ?romid and savidx = ?savidx";
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
@ -331,10 +323,6 @@ namespace AxibugEmuOnline.Server.Manager
|
|||||||
bDone = command.ExecuteNonQuery() > 0;
|
bDone = command.ExecuteNonQuery() > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
return bDone;
|
return bDone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,11 @@ namespace AxibugEmuOnline.Server
|
|||||||
AppSrv.g_GameShareMgr.RecvGameMark(null, null);
|
AppSrv.g_GameShareMgr.RecvGameMark(null, null);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "sql":
|
||||||
|
{
|
||||||
|
SQLRUN.GetPoolState();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("未知命令" + CommandStr);
|
Console.WriteLine("未知命令" + CommandStr);
|
||||||
break;
|
break;
|
||||||
@ -98,58 +103,59 @@ namespace AxibugEmuOnline.Server
|
|||||||
static void UpdateRomHash()
|
static void UpdateRomHash()
|
||||||
{
|
{
|
||||||
AppSrv.g_Log.Info("UpdateRomHash");
|
AppSrv.g_Log.Info("UpdateRomHash");
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("UpdateRomHash");
|
using (MySqlConnection conn = SQLRUN.GetConn("UpdateRomHash"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
List<(int id, string romurl, string name)> list = new List<(int id, string romurl, string name)>();
|
try
|
||||||
List<(int id, string romurl, string name)> Nonelist = new List<(int id, string romurl, string name)>();
|
|
||||||
|
|
||||||
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash` FROM romlist";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 执行查询并处理结果
|
List<(int id, string romurl, string name)> list = new List<(int id, string romurl, string name)>();
|
||||||
using (var reader = command.ExecuteReader())
|
List<(int id, string romurl, string name)> Nonelist = new List<(int id, string romurl, string name)>();
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
list.Add(
|
|
||||||
(reader.GetInt32(0),
|
|
||||||
!reader.IsDBNull(4) ? reader.GetString(4) : string.Empty,
|
|
||||||
!reader.IsDBNull(1) ? reader.GetString(1) : string.Empty
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i++)
|
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash` FROM romlist";
|
||||||
{
|
|
||||||
string rompath = Config.cfg.RomDir + "/" + list[i].romurl;
|
|
||||||
rompath = System.Net.WebUtility.UrlDecode(rompath);
|
|
||||||
if (!File.Exists(rompath))
|
|
||||||
{
|
|
||||||
Nonelist.Add(list[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string romhash = Helper.FileMD5Hash(rompath);
|
|
||||||
AppSrv.g_Log.Info($"第{i}个,Name->{list[i].name},Hash->{romhash}");
|
|
||||||
query = $"update romlist SET `Hash` = '{romhash}' where Id ={list[i].id}";
|
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
// 执行查询并处理结果
|
// 执行查询并处理结果
|
||||||
int reader = command.ExecuteNonQuery();
|
using (var reader = command.ExecuteReader())
|
||||||
if (reader > 0)
|
{
|
||||||
AppSrv.g_Log.Info($"第{i}个,处理成功");
|
while (reader.Read())
|
||||||
else
|
{
|
||||||
AppSrv.g_Log.Info($"第{i}个,处理失败");
|
list.Add(
|
||||||
|
(reader.GetInt32(0),
|
||||||
|
!reader.IsDBNull(4) ? reader.GetString(4) : string.Empty,
|
||||||
|
!reader.IsDBNull(1) ? reader.GetString(1) : string.Empty
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < list.Count; i++)
|
||||||
|
{
|
||||||
|
string rompath = Config.cfg.RomDir + "/" + list[i].romurl;
|
||||||
|
rompath = System.Net.WebUtility.UrlDecode(rompath);
|
||||||
|
if (!File.Exists(rompath))
|
||||||
|
{
|
||||||
|
Nonelist.Add(list[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
string romhash = Helper.FileMD5Hash(rompath);
|
||||||
|
AppSrv.g_Log.Info($"第{i}个,Name->{list[i].name},Hash->{romhash}");
|
||||||
|
query = $"update romlist SET `Hash` = '{romhash}' where Id ={list[i].id}";
|
||||||
|
using (var command = new MySqlCommand(query, conn))
|
||||||
|
{
|
||||||
|
// 执行查询并处理结果
|
||||||
|
int reader = command.ExecuteNonQuery();
|
||||||
|
if (reader > 0)
|
||||||
|
AppSrv.g_Log.Info($"第{i}个,处理成功");
|
||||||
|
else
|
||||||
|
AppSrv.g_Log.Info($"第{i}个,处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppSrv.g_Log.Info($"处理完毕,共{Nonelist.Count}个文件没有找到");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
AppSrv.g_Log.Info($"err:{e.ToString()}");
|
||||||
}
|
}
|
||||||
AppSrv.g_Log.Info($"处理完毕,共{Nonelist.Count}个文件没有找到");
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
AppSrv.g_Log.Info($"err:{e.ToString()}");
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
-->
|
-->
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<History>True|2025-01-09T06:39:17.5797829Z||;True|2025-01-09T14:39:05.6042660+08:00||;True|2025-01-09T14:33:09.1944386+08:00||;</History>
|
<History>True|2025-02-25T02:21:20.8779432Z||;False|2025-02-25T10:20:39.1249758+08:00||;False|2025-02-24T23:48:17.6638177+08:00||;True|2025-01-09T14:39:17.5797829+08:00||;True|2025-01-09T14:39:05.6042660+08:00||;True|2025-01-09T14:33:09.1944386+08:00||;</History>
|
||||||
<LastFailureDetails />
|
<LastFailureDetails />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
-->
|
-->
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<History>True|2025-01-13T08:07:43.4441316Z||;True|2025-01-09T15:02:05.2160606+08:00||;True|2025-01-09T14:48:42.5299550+08:00||;False|2025-01-09T14:48:02.6306184+08:00||;True|2025-01-09T14:17:00.2185117+08:00||;True|2025-01-08T23:13:47.7309044+08:00||;True|2025-01-08T13:32:52.0590130+08:00||;True|2025-01-08T13:31:56.8589678+08:00||;True|2025-01-07T13:54:02.0272718+08:00||;True|2025-01-07T10:47:36.6196477+08:00||;True|2025-01-07T01:21:34.5863249+08:00||;False|2025-01-07T01:20:39.5344134+08:00||;True|2025-01-07T00:21:47.4863058+08:00||;True|2025-01-07T00:16:42.7998249+08:00||;False|2025-01-07T00:16:02.8107509+08:00||;False|2025-01-02T15:36:18.1906464+08:00||;False|2025-01-02T15:36:06.5622643+08:00||;True|2024-12-27T18:24:49.7554320+08:00||;</History>
|
<History>True|2025-02-25T02:21:36.3766073Z||;True|2025-01-13T16:07:43.4441316+08:00||;True|2025-01-09T15:02:05.2160606+08:00||;True|2025-01-09T14:48:42.5299550+08:00||;False|2025-01-09T14:48:02.6306184+08:00||;True|2025-01-09T14:17:00.2185117+08:00||;True|2025-01-08T23:13:47.7309044+08:00||;True|2025-01-08T13:32:52.0590130+08:00||;True|2025-01-08T13:31:56.8589678+08:00||;True|2025-01-07T13:54:02.0272718+08:00||;True|2025-01-07T10:47:36.6196477+08:00||;True|2025-01-07T01:21:34.5863249+08:00||;False|2025-01-07T01:20:39.5344134+08:00||;True|2025-01-07T00:21:47.4863058+08:00||;True|2025-01-07T00:16:42.7998249+08:00||;False|2025-01-07T00:16:02.8107509+08:00||;False|2025-01-02T15:36:18.1906464+08:00||;False|2025-01-02T15:36:06.5622643+08:00||;True|2024-12-27T18:24:49.7554320+08:00||;</History>
|
||||||
<LastFailureDetails />
|
<LastFailureDetails />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
@ -1,202 +0,0 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
|
|
||||||
namespace AxibugEmuOnline.Web.Common
|
|
||||||
{
|
|
||||||
public static class SQLPool
|
|
||||||
{
|
|
||||||
static Queue<MySqlConnection> _ConQueue = new Queue<MySqlConnection>();
|
|
||||||
static Dictionary<MySqlConnection, Haoyue_PoolTime> _OutOfSQLPool = new Dictionary<MySqlConnection, Haoyue_PoolTime>();
|
|
||||||
static Dictionary<string, long> _DicSqlRunFunNum = new Dictionary<string, long>();
|
|
||||||
static Dictionary<string, long> _DicTimeOutSqlRunFunNum = new Dictionary<string, long>();
|
|
||||||
const int DefaultCount = 1;
|
|
||||||
const int MaxLimit = 5;
|
|
||||||
static readonly object _sync = new object();
|
|
||||||
static MySqlConnectionStringBuilder connBuilder;
|
|
||||||
|
|
||||||
public static void InitConnMgr()
|
|
||||||
{
|
|
||||||
connBuilder = new MySqlConnectionStringBuilder();
|
|
||||||
connBuilder.Database = Config.cfg.DBName;
|
|
||||||
connBuilder.Server = Config.cfg.DBIp;
|
|
||||||
connBuilder.UserID = Config.cfg.DBUname;
|
|
||||||
connBuilder.Password = Config.cfg.DBPwd;
|
|
||||||
connBuilder.Port = Config.cfg.DBPort;
|
|
||||||
//connBuilder.MinimumPoolSize = 40u;
|
|
||||||
//connBuilder.MaximumPoolSize = 100u;
|
|
||||||
connBuilder.Pooling = true;
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("SQLPool连接初始化....");
|
|
||||||
for (int i = 0; i < DefaultCount; i++)
|
|
||||||
{
|
|
||||||
MySqlConnection _conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
_ConQueue.Enqueue(_conn);
|
|
||||||
}
|
|
||||||
Console.WriteLine("SQLPool初始化完毕,连接数" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
public static MySqlConnection conn()
|
|
||||||
{
|
|
||||||
return new MySqlConnection(connBuilder.ConnectionString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MySqlConnection DequeueSQLConn(string FuncStr)
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
if (_DicSqlRunFunNum.ContainsKey(FuncStr))
|
|
||||||
{
|
|
||||||
_DicSqlRunFunNum[FuncStr]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_DicSqlRunFunNum[FuncStr] = 1L;
|
|
||||||
}
|
|
||||||
MySqlConnection _conn = null;
|
|
||||||
if (_ConQueue.Count < 1)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]创建新的SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
_conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MySqlConnection temp = null;
|
|
||||||
while (_ConQueue.Count > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]取出一个SQLCount.Count>" + _ConQueue.Count);
|
|
||||||
temp = _ConQueue.Dequeue();
|
|
||||||
if (temp.State == System.Data.ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]已经断开SQLCount.Count>" + _ConQueue.Count);
|
|
||||||
temp.Dispose();
|
|
||||||
temp = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temp != null)
|
|
||||||
{
|
|
||||||
_conn = temp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[DequeueSQLConn]连接池全部已断开,重新创建连接");
|
|
||||||
_conn = conn();
|
|
||||||
_conn.Open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_OutOfSQLPool.Add(_conn, new Haoyue_PoolTime
|
|
||||||
{
|
|
||||||
time = time(),
|
|
||||||
FuncStr = FuncStr
|
|
||||||
});
|
|
||||||
|
|
||||||
return _conn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void EnqueueSQLConn(MySqlConnection BackConn)
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
if (_OutOfSQLPool.ContainsKey(BackConn))
|
|
||||||
{
|
|
||||||
_OutOfSQLPool.Remove(BackConn);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("出队遗漏的数据出现了!");
|
|
||||||
}
|
|
||||||
if (_ConQueue.Count > MaxLimit)
|
|
||||||
{
|
|
||||||
Console.WriteLine("已经不需要回收了,多余了,SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
BackConn.Close();
|
|
||||||
BackConn.Dispose();
|
|
||||||
BackConn = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ConQueue.Enqueue(BackConn);
|
|
||||||
Console.WriteLine("回收SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CheckPoolTimeOut()
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
long now = time();
|
|
||||||
List<MySqlConnection> removeTemp = new List<MySqlConnection>();
|
|
||||||
foreach (KeyValuePair<MySqlConnection, Haoyue_PoolTime> o2 in _OutOfSQLPool)
|
|
||||||
{
|
|
||||||
if (now - o2.Value.time >= 120)
|
|
||||||
{
|
|
||||||
if (_DicTimeOutSqlRunFunNum.ContainsKey(o2.Value.FuncStr))
|
|
||||||
{
|
|
||||||
_DicTimeOutSqlRunFunNum[o2.Value.FuncStr]++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_DicTimeOutSqlRunFunNum[o2.Value.FuncStr] = 1L;
|
|
||||||
}
|
|
||||||
if (_ConQueue.Count > MaxLimit)
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]" + o2.Value.FuncStr + "已经不需要回收了,多余了,SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
o2.Key.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]" + o2.Value.FuncStr + "回收SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
_ConQueue.Enqueue(o2.Key);
|
|
||||||
}
|
|
||||||
removeTemp.Add(o2.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removeTemp.Count() <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foreach (MySqlConnection o in removeTemp)
|
|
||||||
{
|
|
||||||
if (_OutOfSQLPool.ContainsKey(o))
|
|
||||||
{
|
|
||||||
_OutOfSQLPool.Remove(o);
|
|
||||||
Console.WriteLine("[超时回收]_OutOfSQLPool清理");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("[超时回收]_OutOfSQLPool清理异常???????");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.WriteLine("[超时回收]处理结束SQLPool.Count>" + _ConQueue.Count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static long time()
|
|
||||||
{
|
|
||||||
return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
|
|
||||||
}
|
|
||||||
public static void GetPoolState()
|
|
||||||
{
|
|
||||||
Console.WriteLine("-----------------查询统计-----------------");
|
|
||||||
foreach (KeyValuePair<string, long> dic2 in _DicSqlRunFunNum)
|
|
||||||
{
|
|
||||||
Console.WriteLine(dic2.Key + ":" + dic2.Value);
|
|
||||||
}
|
|
||||||
Console.WriteLine("-----------------超时统计-----------------");
|
|
||||||
foreach (KeyValuePair<string, long> dic in _DicTimeOutSqlRunFunNum)
|
|
||||||
{
|
|
||||||
Console.WriteLine(dic.Key + ":" + dic.Value);
|
|
||||||
}
|
|
||||||
Console.WriteLine("------------------------------------------");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Haoyue_PoolTime
|
|
||||||
{
|
|
||||||
public long time { get; set; }
|
|
||||||
public string FuncStr { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
72
AxibugEmuOnline.Web/Common/SQLRUN.cs
Normal file
72
AxibugEmuOnline.Web/Common/SQLRUN.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
|
namespace AxibugEmuOnline.Web.Common
|
||||||
|
{
|
||||||
|
public static class SQLRUN
|
||||||
|
{
|
||||||
|
// 移除自定义队列和状态跟踪字典
|
||||||
|
private static Dictionary<string, long> _DicSqlRunFunNum = new Dictionary<string, long>();
|
||||||
|
private static Dictionary<string, long> _DicTimeOutSqlRunFunNum = new Dictionary<string, long>();
|
||||||
|
|
||||||
|
const int DefaultCount = 1;
|
||||||
|
const int MaxLimit = 10;
|
||||||
|
static readonly object _sync = new object();
|
||||||
|
static MySqlConnectionStringBuilder connBuilder;
|
||||||
|
|
||||||
|
public static void InitConnMgr()
|
||||||
|
{
|
||||||
|
// 配置 MySQL 内置连接池
|
||||||
|
connBuilder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Database = Config.cfg.DBName,
|
||||||
|
Server = Config.cfg.DBIp,
|
||||||
|
UserID = Config.cfg.DBUname,
|
||||||
|
Password = Config.cfg.DBPwd,
|
||||||
|
Port = Config.cfg.DBPort,
|
||||||
|
Pooling = true, // 启用内置连接池
|
||||||
|
MinimumPoolSize = DefaultCount, // 最小连接数
|
||||||
|
MaximumPoolSize = MaxLimit // 最大连接数
|
||||||
|
};
|
||||||
|
|
||||||
|
// 初始化时不手动创建连接,依赖连接池自动管理
|
||||||
|
Console.WriteLine("SQLPool初始化完成,连接池参数已配置");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MySqlConnection GetConn(string FuncStr)
|
||||||
|
{
|
||||||
|
lock (_sync)
|
||||||
|
{
|
||||||
|
IncrementFuncCall(FuncStr);
|
||||||
|
// 直接使用 MySQL 内置连接池获取连接
|
||||||
|
var conn = new MySqlConnection(connBuilder.ConnectionString);
|
||||||
|
conn.Open();
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetPoolState()
|
||||||
|
{
|
||||||
|
Console.WriteLine("-----------------查询统计-----------------");
|
||||||
|
foreach (var entry in _DicSqlRunFunNum)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"函数 {entry.Key} 调用次数: {entry.Value}");
|
||||||
|
}
|
||||||
|
Console.WriteLine("-----------------超时统计-----------------");
|
||||||
|
foreach (var entry in _DicTimeOutSqlRunFunNum)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"函数 {entry.Key} 超时次数: {entry.Value}");
|
||||||
|
}
|
||||||
|
Console.WriteLine("------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 私有方法(辅助统计逻辑)
|
||||||
|
private static void IncrementFuncCall(string funcStr)
|
||||||
|
{
|
||||||
|
_DicSqlRunFunNum[funcStr] = _DicSqlRunFunNum.ContainsKey(funcStr) ? _DicSqlRunFunNum[funcStr] + 1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -65,7 +65,7 @@ namespace AxibugEmuOnline.Web.Controllers
|
|||||||
|
|
||||||
Resp_GameList resp = new Resp_GameList();
|
Resp_GameList resp = new Resp_GameList();
|
||||||
resp.gameList = new List<Resp_RomInfo>();
|
resp.gameList = new List<Resp_RomInfo>();
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("RomList");
|
using (MySqlConnection conn = SQLRUN.GetConn("RomList"))
|
||||||
{
|
{
|
||||||
List<string> condition = new List<string>();
|
List<string> condition = new List<string>();
|
||||||
|
|
||||||
@ -168,7 +168,6 @@ namespace AxibugEmuOnline.Web.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
return new JsonResult(resp);
|
return new JsonResult(resp);
|
||||||
}
|
}
|
||||||
@ -200,7 +199,7 @@ namespace AxibugEmuOnline.Web.Controllers
|
|||||||
string searchPattern = $"%{SearchKey}%";
|
string searchPattern = $"%{SearchKey}%";
|
||||||
Resp_GameList resp = new Resp_GameList();
|
Resp_GameList resp = new Resp_GameList();
|
||||||
resp.gameList = new List<Resp_RomInfo>();
|
resp.gameList = new List<Resp_RomInfo>();
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("MarkList");
|
using (MySqlConnection conn = SQLRUN.GetConn("MarkList"))
|
||||||
{
|
{
|
||||||
string platformCond = "";
|
string platformCond = "";
|
||||||
if (Ptype > (int)RomPlatformType.Invalid && Ptype < (int)RomPlatformType.All)
|
if (Ptype > (int)RomPlatformType.Invalid && Ptype < (int)RomPlatformType.All)
|
||||||
@ -297,7 +296,6 @@ LIMIT ?offset, ?pageSize;";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
return new JsonResult(resp);
|
return new JsonResult(resp);
|
||||||
}
|
}
|
||||||
@ -313,7 +311,7 @@ LIMIT ?offset, ?pageSize;";
|
|||||||
|
|
||||||
string searchPattern = $"%{RomInfo}%";
|
string searchPattern = $"%{RomInfo}%";
|
||||||
Resp_RomInfo resp = new Resp_RomInfo();
|
Resp_RomInfo resp = new Resp_RomInfo();
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("NesRomList");
|
using (MySqlConnection conn = SQLRUN.GetConn("NesRomList"))
|
||||||
{
|
{
|
||||||
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash`,`playcount`,`stars`,`PlatformType`,`parentids` FROM romlist where id = ?romid;";
|
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash`,`playcount`,`stars`,`PlatformType`,`parentids` FROM romlist where id = ?romid;";
|
||||||
using (var command = new MySqlCommand(query, conn))
|
using (var command = new MySqlCommand(query, conn))
|
||||||
@ -347,7 +345,6 @@ LIMIT ?offset, ?pageSize;";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UID > 0)
|
if (UID > 0)
|
||||||
@ -385,24 +382,25 @@ LIMIT ?offset, ?pageSize;";
|
|||||||
public bool CheckIsRomStar(int RomId, long uid)
|
public bool CheckIsRomStar(int RomId, long uid)
|
||||||
{
|
{
|
||||||
bool bhad = false;
|
bool bhad = false;
|
||||||
MySqlConnection conn = SQLPool.DequeueSQLConn("CheckIsRomStart");
|
using (MySqlConnection conn = SQLRUN.GetConn("CheckIsRomStart"))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string query = $"SELECT count(0) from rom_stars where uid = ?uid and romid = ?romid";
|
try
|
||||||
using (var command = new MySqlCommand(query, conn))
|
|
||||||
{
|
{
|
||||||
// 设置参数值
|
string query = $"SELECT count(0) from rom_stars where uid = ?uid and romid = ?romid";
|
||||||
command.Parameters.AddWithValue("?romid", RomId);
|
using (var command = new MySqlCommand(query, conn))
|
||||||
command.Parameters.AddWithValue("?uid", uid);
|
{
|
||||||
// 执行查询并获取结果
|
// 设置参数值
|
||||||
bhad = (int)command.ExecuteScalar() > 0;
|
command.Parameters.AddWithValue("?romid", RomId);
|
||||||
|
command.Parameters.AddWithValue("?uid", uid);
|
||||||
|
// 执行查询并获取结果
|
||||||
|
bhad = (int)command.ExecuteScalar() > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//AppSrv.g_Log.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
//AppSrv.g_Log.Error(e);
|
|
||||||
}
|
|
||||||
SQLPool.EnqueueSQLConn(conn);
|
|
||||||
return bhad;
|
return bhad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<_PublishTargetUrl>G:\Sin365\AxibugEmuOnline\AxibugEmuOnline.Web\bin\Release\net8.0\publish\</_PublishTargetUrl>
|
<_PublishTargetUrl>G:\Sin365\AxibugEmuOnline\AxibugEmuOnline.Web\bin\Release\net8.0\publish\</_PublishTargetUrl>
|
||||||
<History>True|2025-02-05T03:59:16.6277678Z||;True|2025-02-05T11:57:28.8928988+08:00||;True|2025-01-23T14:10:54.0851574+08:00||;True|2025-01-23T13:21:13.2937446+08:00||;True|2025-01-23T13:15:40.1876887+08:00||;True|2025-01-13T15:57:42.8554189+08:00||;True|2025-01-13T15:56:16.9992929+08:00||;True|2025-01-09T15:00:13.8691822+08:00||;True|2025-01-09T14:47:16.4993283+08:00||;True|2025-01-09T14:47:09.3814423+08:00||;True|2025-01-09T14:38:36.2730244+08:00||;True|2025-01-08T13:35:26.6793825+08:00||;True|2025-01-07T10:37:18.6461694+08:00||;True|2024-09-12T14:18:38.6992653+08:00||;True|2024-09-12T14:08:58.4526827+08:00||;True|2024-08-22T14:13:06.3067002+08:00||;True|2024-08-14T10:33:10.9180984+08:00||;True|2024-08-13T18:28:27.5050523+08:00||;True|2024-08-13T18:25:47.6591234+08:00||;True|2024-08-13T18:25:17.5344107+08:00||;True|2024-08-13T17:46:23.4523329+08:00||;</History>
|
<History>True|2025-02-25T02:10:20.1998665Z||;True|2025-02-25T10:06:10.7381658+08:00||;True|2025-02-24T20:17:30.7705009+08:00||;True|2025-02-24T20:17:22.8138039+08:00||;True|2025-02-24T20:04:18.6428884+08:00||;True|2025-02-24T20:03:59.5011548+08:00||;True|2025-02-24T19:53:21.4793388+08:00||;True|2025-02-05T11:59:16.6277678+08:00||;True|2025-02-05T11:57:28.8928988+08:00||;True|2025-01-23T14:10:54.0851574+08:00||;True|2025-01-23T13:21:13.2937446+08:00||;True|2025-01-23T13:15:40.1876887+08:00||;True|2025-01-13T15:57:42.8554189+08:00||;True|2025-01-13T15:56:16.9992929+08:00||;True|2025-01-09T15:00:13.8691822+08:00||;True|2025-01-09T14:47:16.4993283+08:00||;True|2025-01-09T14:47:09.3814423+08:00||;True|2025-01-09T14:38:36.2730244+08:00||;True|2025-01-08T13:35:26.6793825+08:00||;True|2025-01-07T10:37:18.6461694+08:00||;True|2024-09-12T14:18:38.6992653+08:00||;True|2024-09-12T14:08:58.4526827+08:00||;True|2024-08-22T14:13:06.3067002+08:00||;True|2024-08-14T10:33:10.9180984+08:00||;True|2024-08-13T18:28:27.5050523+08:00||;True|2024-08-13T18:25:47.6591234+08:00||;True|2024-08-13T18:25:17.5344107+08:00||;True|2024-08-13T17:46:23.4523329+08:00||;</History>
|
||||||
<LastFailureDetails />
|
<LastFailureDetails />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user