mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-04-20 19:19:39 +08:00
匹配房间功能 (#25)
* 匹配房间 第一部分 * elo匹配 * 设置匹配结束标记 * 传输的room对象错误 * 修复错误的UpdateRoom; 添加SQLMode开关 * 删除创建房间时重复的加入房间代码 * 添加在加入房间时检查是否存在房间 --------- Co-authored-by: yeziuku <yezi@wrss.org>
This commit is contained in:
parent
1b4f3ec912
commit
0ed458fb77
@ -1,17 +1,13 @@
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||
using Milimoe.FunGame.Server.Model;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Utility;
|
||||
using TFA = Milimoe.FunGame.Server.Utility.TFA;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Controllers
|
||||
{
|
||||
public class Authenticator : Core.Library.Common.Architecture.Authenticator
|
||||
{
|
||||
public TFA Login2FA = new();
|
||||
public TwoFactorAuthenticator Login2FA = new();
|
||||
|
||||
private readonly ServerModel Server;
|
||||
private readonly SQLHelper SQLHelper;
|
||||
@ -30,42 +26,6 @@ namespace Milimoe.FunGame.Server.Controllers
|
||||
{
|
||||
// 添加2FA二次验证等
|
||||
string username = (string)args[0];
|
||||
string code = Login2FA.GetTFACode(username);
|
||||
if (MailSender != null)
|
||||
{
|
||||
// 获取此账号的邮箱
|
||||
string email = "";
|
||||
SQLHelper.ExecuteDataSet(UserQuery.Select_IsExistUsername(username));
|
||||
if (SQLHelper.Success && SQLHelper.DataSet.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
email = Convert.ToString(SQLHelper.DataSet.Tables[0].Rows[0][UserQuery.Column_Email]) ?? "";
|
||||
}
|
||||
// 发送验证码
|
||||
if (email != "")
|
||||
{
|
||||
string ServerName = Config.ServerName;
|
||||
string Subject = $"[{ServerName}] FunGame 双重认证";
|
||||
string Body = $"亲爱的 {username}, <br/> 您正在登录[{ServerName}],为了保证安全性,需要进行邮箱验证,您的验证码是 {code} ,10分钟内有效,请及时输入!<br/><br/>{ServerName}<br/>{DateTimeUtility.GetDateTimeToString(TimeType.DateOnly)}";
|
||||
string[] To = new string[] { email };
|
||||
if (MailSender.Send(MailSender.CreateMail(Subject, Body, System.Net.Mail.MailPriority.Normal, true, To)) == MailSendResult.Success)
|
||||
{
|
||||
ServerHelper.WriteLine(Server.GetClientName() + $" 已向{email}发送验证码:{code}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerHelper.WriteLine(Server.GetClientName() + " 无法发送验证码");
|
||||
ServerHelper.WriteLine(MailSender.ErrorMsg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerHelper.WriteLine(Server.GetClientName() + $" 验证码为:{code},请服务器管理员告知此用户");
|
||||
}
|
||||
}
|
||||
else // 不使用MailSender的情况
|
||||
{
|
||||
ServerHelper.WriteLine(Server.GetClientName() + $" 验证码为:{code},请服务器管理员告知此用户");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -76,9 +36,9 @@ namespace Milimoe.FunGame.Server.Controllers
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Check2FA(string username, string code, out string msg)
|
||||
public bool Check2FA(string username, string code)
|
||||
{
|
||||
return Login2FA.Authenticate(username, code, out msg);
|
||||
return Login2FA.Authenticate(username, code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
public class DataRequestController
|
||||
{
|
||||
public ServerModel Server { get; }
|
||||
public MySQLHelper SQLHelper => Server.SQLHelper;
|
||||
public MySQLHelper SQLHelper => Server.SQLHelper ?? throw new MySQLConfigException();
|
||||
public MailSender? MailSender => Server.MailSender;
|
||||
public Authenticator Authenticator { get; }
|
||||
public DataRequestType LastRequest => _LastRequest;
|
||||
@ -67,6 +67,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
break;
|
||||
|
||||
case DataRequestType.Main_MatchRoom:
|
||||
MatchRoom(data, result);
|
||||
break;
|
||||
|
||||
case DataRequestType.Main_Chat:
|
||||
@ -180,6 +181,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
if (SQLHelper.Result == SQLResult.Success && SQLHelper.DataSet.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
room = Factory.GetRoom(SQLHelper.DataSet.Tables[0].Rows[0], user);
|
||||
Config.RoomList.AddRoom(room);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,13 +196,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
private void UpdateRoom(Hashtable ResultData)
|
||||
{
|
||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> UpdateRoom");
|
||||
Config.RoomList ??= new();
|
||||
Config.RoomList.Clear();
|
||||
DataSet DsRoomTemp = SQLHelper.ExecuteDataSet(RoomQuery.Select_Rooms);
|
||||
DataSet DsUserTemp = SQLHelper.ExecuteDataSet(UserQuery.Select_Users);
|
||||
List<Room> rooms = Factory.GetRooms(DsRoomTemp, DsUserTemp);
|
||||
Config.RoomList.AddRooms(rooms); // 更新服务器中的房间列表
|
||||
ResultData.Add("rooms", rooms); // 传RoomList
|
||||
ResultData.Add("rooms", Config.RoomList.ListRoom); // 传RoomList
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -217,7 +213,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
string roomid = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomid") ?? "-1";
|
||||
bool isMaster = DataRequest.GetHashtableJsonObject<bool>(RequestData, "isMaster");
|
||||
|
||||
if (roomid != "-1")
|
||||
if (roomid != "-1" && Config.RoomList.IsExist(roomid))
|
||||
{
|
||||
Config.RoomList.QuitRoom(roomid, Server.User);
|
||||
Room Room = Config.RoomList[roomid] ?? General.HallInstance;
|
||||
@ -276,9 +272,17 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
|
||||
if (roomid != "-1")
|
||||
{
|
||||
Config.RoomList.IntoRoom(roomid, Server.User);
|
||||
Server.IntoRoom(roomid);
|
||||
result = true;
|
||||
SQLHelper.ExecuteDataSet(RoomQuery.Select_IsExistRoom(roomid));
|
||||
if (SQLHelper.Success)
|
||||
{
|
||||
Config.RoomList.IntoRoom(roomid, Server.User);
|
||||
Server.IntoRoom(roomid);
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.RoomList.RemoveRoom(roomid);
|
||||
}
|
||||
}
|
||||
}
|
||||
ResultData.Add("result", result);
|
||||
@ -291,16 +295,25 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
/// <param name="ResultData"></param>
|
||||
private void MatchRoom(Hashtable RequestData, Hashtable ResultData)
|
||||
{
|
||||
bool result = false;
|
||||
string roomid = "-1";
|
||||
bool result = true;
|
||||
if (RequestData.Count >= 1)
|
||||
{
|
||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> MatchRoom");
|
||||
string roomtype_string = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomtype") ?? GameMode.All;
|
||||
User user = DataRequest.GetHashtableJsonObject<User>(RequestData, "master") ?? Factory.GetUser();
|
||||
bool iscancel = DataRequest.GetHashtableJsonObject<bool>(RequestData, "iscancel");
|
||||
if (!iscancel)
|
||||
{
|
||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> MatchRoom : Start");
|
||||
string roomtype_string = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomtype") ?? GameMode.All;
|
||||
User user = DataRequest.GetHashtableJsonObject<User>(RequestData, "matcher") ?? Factory.GetUser();
|
||||
Server.StartMatching(roomtype_string, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 取消匹配
|
||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> MatchRoom : Cancel");
|
||||
Server.StopMatching();
|
||||
}
|
||||
}
|
||||
ResultData.Add("result", result);
|
||||
ResultData.Add("roomid", roomid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -639,7 +652,7 @@ namespace Milimoe.FunGame.Server.Controller
|
||||
string password = DataRequest.GetHashtableJsonObject<string>(RequestData, UserQuery.Column_Password) ?? "";
|
||||
if (username.Trim() != "" && password.Trim() != "")
|
||||
{
|
||||
Server.SQLHelper.Execute(UserQuery.Update_Password(username, password));
|
||||
Server.SQLHelper?.Execute(UserQuery.Update_Password(username, password));
|
||||
if (SQLHelper.Success)
|
||||
{
|
||||
// 更新成功返回空值
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.SQLScript.Common;
|
||||
using Milimoe.FunGame.Server.Model;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Utility;
|
||||
@ -72,19 +71,14 @@ void StartServer()
|
||||
}
|
||||
ServerHelper.WriteLine("请输入 help 来获取帮助,输入 quit 关闭服务器。");
|
||||
|
||||
// 测试MySQL服务器连接
|
||||
if (TestSQLConnection() != SQLResult.Success)
|
||||
{
|
||||
Running = false;
|
||||
throw new SQLQueryException();
|
||||
}
|
||||
// 创建全局SQLHelper
|
||||
Config.InitSQLHelper();
|
||||
|
||||
// 创建监听
|
||||
ListeningSocket = ServerSocket.StartListening();
|
||||
|
||||
// 开始监听连接
|
||||
AddBannedList(ListeningSocket);
|
||||
Config.RoomList = new();
|
||||
ServerHelper.WriteLine("Listen -> " + Config.ServerPort);
|
||||
ServerHelper.WriteLine("服务器启动成功,开始监听 . . .");
|
||||
|
||||
@ -206,13 +200,6 @@ bool SendRefuseConnect(ClientSocket socket, string msg)
|
||||
}
|
||||
}
|
||||
|
||||
SQLResult TestSQLConnection()
|
||||
{
|
||||
MySQLHelper sql = new(ServerLoginLogs.Insert_ServerLoginLogs(Config.ServerName, Config.ServerKey));
|
||||
sql.Execute();
|
||||
return sql.Result;
|
||||
}
|
||||
|
||||
void AddBannedList(ServerSocket server)
|
||||
{
|
||||
string[] bans = Config.ServerBannedList.Split(',');
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Milimoe.FunGame.Core.Interface;
|
||||
using Milimoe.FunGame.Core.Interface.Base;
|
||||
using Milimoe.FunGame.Core.Interface.Base;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Utility;
|
||||
|
@ -28,7 +28,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
get => _Room;
|
||||
set => _Room = value;
|
||||
}
|
||||
public MySQLHelper SQLHelper { get; }
|
||||
public MySQLHelper? SQLHelper { get; }
|
||||
public MailSender? MailSender { get; }
|
||||
|
||||
/**
|
||||
@ -50,6 +50,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
private readonly DataRequestController DataRequestController;
|
||||
private long LoginTime;
|
||||
private long LogoutTime;
|
||||
private bool IsMatching;
|
||||
|
||||
public ServerModel(ServerSocket server, ClientSocket socket, bool running)
|
||||
{
|
||||
@ -57,7 +58,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
_Socket = socket;
|
||||
_Running = running;
|
||||
Token = socket.Token;
|
||||
SQLHelper = new(this);
|
||||
if (Config.SQLMode) SQLHelper = new(this);
|
||||
MailSender = SmtpHelper.GetMailSender();
|
||||
DataRequestController = new(this);
|
||||
}
|
||||
@ -109,29 +110,34 @@ namespace Milimoe.FunGame.Server.Model
|
||||
|
||||
public bool DataRequestHandler(ClientSocket socket, SocketObject SocketObject)
|
||||
{
|
||||
Hashtable result = new();
|
||||
DataRequestType type = DataRequestType.UnKnown;
|
||||
|
||||
if (SocketObject.Parameters.Length > 0)
|
||||
if (SQLHelper != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
type = SocketObject.GetParam<DataRequestType>(0);
|
||||
Hashtable data = SocketObject.GetParam<Hashtable>(1) ?? new();
|
||||
Hashtable result = new();
|
||||
DataRequestType type = DataRequestType.UnKnown;
|
||||
|
||||
SQLHelper.NewTransaction();
|
||||
result = DataRequestController.GetResultData(type, data);
|
||||
SQLHelper.Commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
if (SocketObject.Parameters.Length > 0)
|
||||
{
|
||||
ServerHelper.Error(e);
|
||||
SQLHelper.Rollback();
|
||||
return Send(socket, SocketMessageType.DataRequest, type, result);
|
||||
try
|
||||
{
|
||||
type = SocketObject.GetParam<DataRequestType>(0);
|
||||
Hashtable data = SocketObject.GetParam<Hashtable>(1) ?? new();
|
||||
|
||||
SQLHelper.NewTransaction();
|
||||
result = DataRequestController.GetResultData(type, data);
|
||||
SQLHelper.Commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ServerHelper.Error(e);
|
||||
SQLHelper.Rollback();
|
||||
return Send(socket, SocketMessageType.DataRequest, type, result);
|
||||
}
|
||||
}
|
||||
|
||||
return Send(socket, SocketMessageType.DataRequest, type, result);
|
||||
}
|
||||
|
||||
return Send(socket, SocketMessageType.DataRequest, type, result);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Send(ClientSocket socket, SocketMessageType type, params object[] objs)
|
||||
@ -207,7 +213,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
GetUsersCount();
|
||||
// CheckLogin
|
||||
LoginTime = DateTime.Now.Ticks;
|
||||
SQLHelper.Execute(UserQuery.Update_CheckLogin(UserName, _Socket?.ClientIP.Split(':')[0] ?? "127.0.0.1"));
|
||||
SQLHelper?.Execute(UserQuery.Update_CheckLogin(UserName, _Socket?.ClientIP.Split(':')[0] ?? "127.0.0.1"));
|
||||
}
|
||||
|
||||
public bool IsLoginKey(Guid key)
|
||||
@ -291,6 +297,90 @@ namespace Milimoe.FunGame.Server.Model
|
||||
return Send(socket, SocketMessageType.HeartBeat, "");
|
||||
}
|
||||
|
||||
public void StartMatching(string roomtype_string, User user)
|
||||
{
|
||||
IsMatching = true;
|
||||
ServerHelper.WriteLine(GetClientName() + " 开始匹配。类型:" + roomtype_string);
|
||||
TaskUtility.NewTask(async () =>
|
||||
{
|
||||
if (IsMatching)
|
||||
{
|
||||
RoomType roomtype = roomtype_string switch
|
||||
{
|
||||
GameMode.Mix => RoomType.Mix,
|
||||
GameMode.Team => RoomType.Team,
|
||||
GameMode.MixHasPass => RoomType.MixHasPass,
|
||||
GameMode.TeamHasPass => RoomType.TeamHasPass,
|
||||
_ => RoomType.All
|
||||
};
|
||||
Room room = await MatchingRoom(roomtype, user);
|
||||
if (IsMatching && Socket != null)
|
||||
{
|
||||
Send(Socket, SocketMessageType.MatchRoom, room);
|
||||
}
|
||||
IsMatching = false;
|
||||
}
|
||||
}).OnError(e =>
|
||||
{
|
||||
ServerHelper.Error(e);
|
||||
IsMatching = false;
|
||||
});
|
||||
}
|
||||
|
||||
public void StopMatching()
|
||||
{
|
||||
if (IsMatching)
|
||||
{
|
||||
ServerHelper.WriteLine(GetClientName() + " 取消了匹配。");
|
||||
IsMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Room> MatchingRoom(RoomType roomtype, User user)
|
||||
{
|
||||
int i = 1;
|
||||
int time = 0;
|
||||
while (IsMatching)
|
||||
{
|
||||
// 先列出符合条件的房间
|
||||
List<Room> targets = Config.RoomList.ListRoom.Where(r => r.RoomType == roomtype).ToList();
|
||||
|
||||
// 匹配Elo
|
||||
foreach (Room room in targets)
|
||||
{
|
||||
// 计算房间平均Elo
|
||||
List<User> players = Config.RoomList.GetPlayerList(room.Roomid);
|
||||
if (players.Count > 0)
|
||||
{
|
||||
decimal avgelo = players.Sum(u => u.Statistics.EloStats?[0] ?? 0M) / players.Count;
|
||||
decimal userelo = user.Statistics.EloStats?[0] ?? 0M;
|
||||
if (userelo >= avgelo - (300 * i) && userelo <= avgelo + (300 * i))
|
||||
{
|
||||
return room;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsMatching) break;
|
||||
|
||||
// 等待10秒
|
||||
await Task.Delay(10 * 1000);
|
||||
time += 10 * 1000;
|
||||
if (time >= 50 * 1000)
|
||||
{
|
||||
// 50秒后不再匹配Elo,直接返回第一个房间
|
||||
if (targets.Count > 0)
|
||||
{
|
||||
return targets[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return General.HallInstance;
|
||||
}
|
||||
|
||||
private void KickUser()
|
||||
{
|
||||
if (User.Id != 0)
|
||||
@ -321,8 +411,8 @@ namespace Milimoe.FunGame.Server.Model
|
||||
{
|
||||
LogoutTime = DateTime.Now.Ticks;
|
||||
int TotalMinutes = Convert.ToInt32((new DateTime(LogoutTime) - new DateTime(LoginTime)).TotalMinutes);
|
||||
SQLHelper.Execute(UserQuery.Update_GameTime(User.Username, TotalMinutes));
|
||||
if (SQLHelper.Result == SQLResult.Success)
|
||||
SQLHelper?.Execute(UserQuery.Update_GameTime(User.Username, TotalMinutes));
|
||||
if (SQLHelper?.Result == SQLResult.Success)
|
||||
{
|
||||
ServerHelper.WriteLine("OnlinePlayers: 玩家 " + User.Username + " 本次已游玩" + TotalMinutes + "分钟");
|
||||
}
|
||||
@ -384,7 +474,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
{
|
||||
// 每两小时触发一次SQL服务器的心跳查询,防止SQL服务器掉线
|
||||
Thread.Sleep(2 * 1000 * 3600);
|
||||
SQLHelper.ExecuteDataSet(UserQuery.Select_IsExistUsername(UserName));
|
||||
SQLHelper?.ExecuteDataSet(UserQuery.Select_IsExistUsername(UserName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,7 +482,7 @@ namespace Milimoe.FunGame.Server.Model
|
||||
{
|
||||
try
|
||||
{
|
||||
SQLHelper.Close();
|
||||
SQLHelper?.Close();
|
||||
MailSender?.Dispose();
|
||||
Socket?.Close();
|
||||
_Socket = null;
|
||||
|
@ -1,7 +1,14 @@
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.SQLScript.Common;
|
||||
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||
using Milimoe.FunGame.Core.Model;
|
||||
using Milimoe.FunGame.Server.Utility;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Others
|
||||
{
|
||||
@ -20,9 +27,59 @@ namespace Milimoe.FunGame.Server.Others
|
||||
public static int OnlinePlayerCount { get; set; } = 0; // 已连接的玩家数量
|
||||
public static int ConnectingPlayerCount { get; set; } = 0; // 正在连接的玩家数量
|
||||
public static Encoding DefaultEncoding { get; } = General.DefaultEncoding; // 默认传输字符集
|
||||
public static FunGameInfo.FunGame FunGameType { get; } = FunGameInfo.FunGame.FunGame_Server;
|
||||
public static Hashtable OrderList { get; } = new();
|
||||
public static RoomList RoomList { get; set; } = new();
|
||||
public static FunGameInfo.FunGame FunGameType { get; } = FunGameInfo.FunGame.FunGame_Server; // FunGame Runtime
|
||||
public static Hashtable OrderList { get; } = new(); // 服务器指令列表
|
||||
public static RoomList RoomList { get; } = new(); // 在线房间列表
|
||||
public static bool SQLMode { get; set; } = false; // 是否运行数据库模式
|
||||
public static SQLHelper SQLHelper
|
||||
{
|
||||
// 全局数据库连接器
|
||||
get
|
||||
{
|
||||
if (_SQLHelper is null) throw new MySQLConfigException();
|
||||
return _SQLHelper;
|
||||
}
|
||||
}
|
||||
|
||||
private static SQLHelper? _SQLHelper;
|
||||
|
||||
public static void InitSQLHelper()
|
||||
{
|
||||
try
|
||||
{
|
||||
_SQLHelper = new MySQLHelper("", false);
|
||||
if (((MySQLHelper)_SQLHelper).Connection != null)
|
||||
{
|
||||
SQLMode = true;
|
||||
ServerLogin();
|
||||
InitRoomList();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ServerHelper.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ServerLogin()
|
||||
{
|
||||
if (SQLMode)
|
||||
{
|
||||
SQLHelper.Execute(ServerLoginLogs.Insert_ServerLoginLogs(Config.ServerName, Config.ServerKey));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitRoomList()
|
||||
{
|
||||
if (SQLMode)
|
||||
{
|
||||
// 初始化服务器中的房间列表
|
||||
DataSet DsRoomTemp = SQLHelper.ExecuteDataSet(RoomQuery.Select_Rooms);
|
||||
DataSet DsUserTemp = SQLHelper.ExecuteDataSet(UserQuery.Select_Users);
|
||||
List<Room> rooms = Factory.GetRooms(DsRoomTemp, DsUserTemp);
|
||||
RoomList.AddRooms(rooms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class OfficialEmail
|
||||
|
@ -1,8 +1,8 @@
|
||||
using System.Collections;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Utility
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Model;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Model;
|
||||
using Milimoe.FunGame.Server.Utility.DataUtility;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Model;
|
||||
using Milimoe.FunGame.Server.Others;
|
||||
using Milimoe.FunGame.Server.Utility.DataUtility;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Utility
|
||||
{
|
||||
@ -38,7 +38,6 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
public override int Execute()
|
||||
{
|
||||
// _IsOneTime = true需要手动创建连接和关闭
|
||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||
_DataSet = new DataSet();
|
||||
_UpdateRows = MySQLManager.Execute(this, out _Result);
|
||||
@ -55,7 +54,6 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
public override int Execute(string Script)
|
||||
{
|
||||
// _IsOneTime = true需要手动创建连接和关闭
|
||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||
this.Script = Script;
|
||||
_DataSet = new DataSet();
|
||||
@ -72,7 +70,6 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
public override DataSet ExecuteDataSet()
|
||||
{
|
||||
// _IsOneTime = true需要手动创建连接和关闭
|
||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
||||
if (_IsOneTime) Close();
|
||||
@ -88,7 +85,6 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
public override DataSet ExecuteDataSet(string Script)
|
||||
{
|
||||
// _IsOneTime = true需要手动创建连接和关闭
|
||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||
this.Script = Script;
|
||||
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
||||
@ -103,7 +99,7 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
{
|
||||
// _IsOneTime = false需要手动调用此方法
|
||||
_Connection?.Close();
|
||||
ServerHelper.WriteLine($"{GetClientName()} 已释放MySQL连接");
|
||||
ServerHelper.WriteLine($"{(GetClientName() == string.Empty ? "" : GetClientName())}已释放MySQL连接");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -119,6 +115,7 @@ namespace Milimoe.FunGame.Server.Utility
|
||||
_IsOneTime = IsOneTime;
|
||||
CommandType = type;
|
||||
Parameters = parameters;
|
||||
_Connection = new MySQLConnection(out _ServerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Utility
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Milimoe.FunGame.Server.Model;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
|
||||
namespace Milimoe.FunGame.Server.Utility
|
||||
{
|
||||
public class TFA : Core.Api.Utility.TFA
|
||||
public class TFA : TwoFactorAuthenticator
|
||||
{
|
||||
public override bool IsAvailable(string username)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user