mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-04-22 03:59:36 +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.Transmittal;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
|
||||||
using Milimoe.FunGame.Server.Model;
|
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
|
namespace Milimoe.FunGame.Server.Controllers
|
||||||
{
|
{
|
||||||
public class Authenticator : Core.Library.Common.Architecture.Authenticator
|
public class Authenticator : Core.Library.Common.Architecture.Authenticator
|
||||||
{
|
{
|
||||||
public TFA Login2FA = new();
|
public TwoFactorAuthenticator Login2FA = new();
|
||||||
|
|
||||||
private readonly ServerModel Server;
|
private readonly ServerModel Server;
|
||||||
private readonly SQLHelper SQLHelper;
|
private readonly SQLHelper SQLHelper;
|
||||||
@ -30,42 +26,6 @@ namespace Milimoe.FunGame.Server.Controllers
|
|||||||
{
|
{
|
||||||
// 添加2FA二次验证等
|
// 添加2FA二次验证等
|
||||||
string username = (string)args[0];
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -76,9 +36,9 @@ namespace Milimoe.FunGame.Server.Controllers
|
|||||||
return true;
|
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 class DataRequestController
|
||||||
{
|
{
|
||||||
public ServerModel Server { get; }
|
public ServerModel Server { get; }
|
||||||
public MySQLHelper SQLHelper => Server.SQLHelper;
|
public MySQLHelper SQLHelper => Server.SQLHelper ?? throw new MySQLConfigException();
|
||||||
public MailSender? MailSender => Server.MailSender;
|
public MailSender? MailSender => Server.MailSender;
|
||||||
public Authenticator Authenticator { get; }
|
public Authenticator Authenticator { get; }
|
||||||
public DataRequestType LastRequest => _LastRequest;
|
public DataRequestType LastRequest => _LastRequest;
|
||||||
@ -67,6 +67,7 @@ namespace Milimoe.FunGame.Server.Controller
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DataRequestType.Main_MatchRoom:
|
case DataRequestType.Main_MatchRoom:
|
||||||
|
MatchRoom(data, result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DataRequestType.Main_Chat:
|
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)
|
if (SQLHelper.Result == SQLResult.Success && SQLHelper.DataSet.Tables[0].Rows.Count > 0)
|
||||||
{
|
{
|
||||||
room = Factory.GetRoom(SQLHelper.DataSet.Tables[0].Rows[0], user);
|
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)
|
private void UpdateRoom(Hashtable ResultData)
|
||||||
{
|
{
|
||||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> UpdateRoom");
|
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> UpdateRoom");
|
||||||
Config.RoomList ??= new();
|
ResultData.Add("rooms", Config.RoomList.ListRoom); // 传RoomList
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -217,7 +213,7 @@ namespace Milimoe.FunGame.Server.Controller
|
|||||||
string roomid = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomid") ?? "-1";
|
string roomid = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomid") ?? "-1";
|
||||||
bool isMaster = DataRequest.GetHashtableJsonObject<bool>(RequestData, "isMaster");
|
bool isMaster = DataRequest.GetHashtableJsonObject<bool>(RequestData, "isMaster");
|
||||||
|
|
||||||
if (roomid != "-1")
|
if (roomid != "-1" && Config.RoomList.IsExist(roomid))
|
||||||
{
|
{
|
||||||
Config.RoomList.QuitRoom(roomid, Server.User);
|
Config.RoomList.QuitRoom(roomid, Server.User);
|
||||||
Room Room = Config.RoomList[roomid] ?? General.HallInstance;
|
Room Room = Config.RoomList[roomid] ?? General.HallInstance;
|
||||||
@ -275,11 +271,19 @@ namespace Milimoe.FunGame.Server.Controller
|
|||||||
string roomid = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomid") ?? "-1";
|
string roomid = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomid") ?? "-1";
|
||||||
|
|
||||||
if (roomid != "-1")
|
if (roomid != "-1")
|
||||||
|
{
|
||||||
|
SQLHelper.ExecuteDataSet(RoomQuery.Select_IsExistRoom(roomid));
|
||||||
|
if (SQLHelper.Success)
|
||||||
{
|
{
|
||||||
Config.RoomList.IntoRoom(roomid, Server.User);
|
Config.RoomList.IntoRoom(roomid, Server.User);
|
||||||
Server.IntoRoom(roomid);
|
Server.IntoRoom(roomid);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Config.RoomList.RemoveRoom(roomid);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ResultData.Add("result", result);
|
ResultData.Add("result", result);
|
||||||
}
|
}
|
||||||
@ -291,16 +295,25 @@ namespace Milimoe.FunGame.Server.Controller
|
|||||||
/// <param name="ResultData"></param>
|
/// <param name="ResultData"></param>
|
||||||
private void MatchRoom(Hashtable RequestData, Hashtable ResultData)
|
private void MatchRoom(Hashtable RequestData, Hashtable ResultData)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = true;
|
||||||
string roomid = "-1";
|
|
||||||
if (RequestData.Count >= 1)
|
if (RequestData.Count >= 1)
|
||||||
{
|
{
|
||||||
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(SocketMessageType.DataRequest) + "] " + Server.GetClientName() + " -> MatchRoom");
|
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;
|
string roomtype_string = DataRequest.GetHashtableJsonObject<string>(RequestData, "roomtype") ?? GameMode.All;
|
||||||
User user = DataRequest.GetHashtableJsonObject<User>(RequestData, "master") ?? Factory.GetUser();
|
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("result", result);
|
||||||
ResultData.Add("roomid", roomid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -639,7 +652,7 @@ namespace Milimoe.FunGame.Server.Controller
|
|||||||
string password = DataRequest.GetHashtableJsonObject<string>(RequestData, UserQuery.Column_Password) ?? "";
|
string password = DataRequest.GetHashtableJsonObject<string>(RequestData, UserQuery.Column_Password) ?? "";
|
||||||
if (username.Trim() != "" && password.Trim() != "")
|
if (username.Trim() != "" && password.Trim() != "")
|
||||||
{
|
{
|
||||||
Server.SQLHelper.Execute(UserQuery.Update_Password(username, password));
|
Server.SQLHelper?.Execute(UserQuery.Update_Password(username, password));
|
||||||
if (SQLHelper.Success)
|
if (SQLHelper.Success)
|
||||||
{
|
{
|
||||||
// 更新成功返回空值
|
// 更新成功返回空值
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using Milimoe.FunGame.Core.Api.Utility;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using Milimoe.FunGame.Core.Library.SQLScript.Common;
|
|
||||||
using Milimoe.FunGame.Server.Model;
|
using Milimoe.FunGame.Server.Model;
|
||||||
using Milimoe.FunGame.Server.Others;
|
using Milimoe.FunGame.Server.Others;
|
||||||
using Milimoe.FunGame.Server.Utility;
|
using Milimoe.FunGame.Server.Utility;
|
||||||
@ -72,19 +71,14 @@ void StartServer()
|
|||||||
}
|
}
|
||||||
ServerHelper.WriteLine("请输入 help 来获取帮助,输入 quit 关闭服务器。");
|
ServerHelper.WriteLine("请输入 help 来获取帮助,输入 quit 关闭服务器。");
|
||||||
|
|
||||||
// 测试MySQL服务器连接
|
// 创建全局SQLHelper
|
||||||
if (TestSQLConnection() != SQLResult.Success)
|
Config.InitSQLHelper();
|
||||||
{
|
|
||||||
Running = false;
|
|
||||||
throw new SQLQueryException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建监听
|
// 创建监听
|
||||||
ListeningSocket = ServerSocket.StartListening();
|
ListeningSocket = ServerSocket.StartListening();
|
||||||
|
|
||||||
// 开始监听连接
|
// 开始监听连接
|
||||||
AddBannedList(ListeningSocket);
|
AddBannedList(ListeningSocket);
|
||||||
Config.RoomList = new();
|
|
||||||
ServerHelper.WriteLine("Listen -> " + Config.ServerPort);
|
ServerHelper.WriteLine("Listen -> " + Config.ServerPort);
|
||||||
ServerHelper.WriteLine("服务器启动成功,开始监听 . . .");
|
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)
|
void AddBannedList(ServerSocket server)
|
||||||
{
|
{
|
||||||
string[] bans = Config.ServerBannedList.Split(',');
|
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.Core.Library.Common.Network;
|
||||||
using Milimoe.FunGame.Server.Others;
|
using Milimoe.FunGame.Server.Others;
|
||||||
using Milimoe.FunGame.Server.Utility;
|
using Milimoe.FunGame.Server.Utility;
|
||||||
|
@ -28,7 +28,7 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
get => _Room;
|
get => _Room;
|
||||||
set => _Room = value;
|
set => _Room = value;
|
||||||
}
|
}
|
||||||
public MySQLHelper SQLHelper { get; }
|
public MySQLHelper? SQLHelper { get; }
|
||||||
public MailSender? MailSender { get; }
|
public MailSender? MailSender { get; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +50,7 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
private readonly DataRequestController DataRequestController;
|
private readonly DataRequestController DataRequestController;
|
||||||
private long LoginTime;
|
private long LoginTime;
|
||||||
private long LogoutTime;
|
private long LogoutTime;
|
||||||
|
private bool IsMatching;
|
||||||
|
|
||||||
public ServerModel(ServerSocket server, ClientSocket socket, bool running)
|
public ServerModel(ServerSocket server, ClientSocket socket, bool running)
|
||||||
{
|
{
|
||||||
@ -57,7 +58,7 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
_Socket = socket;
|
_Socket = socket;
|
||||||
_Running = running;
|
_Running = running;
|
||||||
Token = socket.Token;
|
Token = socket.Token;
|
||||||
SQLHelper = new(this);
|
if (Config.SQLMode) SQLHelper = new(this);
|
||||||
MailSender = SmtpHelper.GetMailSender();
|
MailSender = SmtpHelper.GetMailSender();
|
||||||
DataRequestController = new(this);
|
DataRequestController = new(this);
|
||||||
}
|
}
|
||||||
@ -108,6 +109,8 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool DataRequestHandler(ClientSocket socket, SocketObject SocketObject)
|
public bool DataRequestHandler(ClientSocket socket, SocketObject SocketObject)
|
||||||
|
{
|
||||||
|
if (SQLHelper != null)
|
||||||
{
|
{
|
||||||
Hashtable result = new();
|
Hashtable result = new();
|
||||||
DataRequestType type = DataRequestType.UnKnown;
|
DataRequestType type = DataRequestType.UnKnown;
|
||||||
@ -134,6 +137,9 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
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)
|
public bool Send(ClientSocket socket, SocketMessageType type, params object[] objs)
|
||||||
{
|
{
|
||||||
// 发送消息给客户端
|
// 发送消息给客户端
|
||||||
@ -207,7 +213,7 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
GetUsersCount();
|
GetUsersCount();
|
||||||
// CheckLogin
|
// CheckLogin
|
||||||
LoginTime = DateTime.Now.Ticks;
|
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)
|
public bool IsLoginKey(Guid key)
|
||||||
@ -291,6 +297,90 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
return Send(socket, SocketMessageType.HeartBeat, "");
|
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()
|
private void KickUser()
|
||||||
{
|
{
|
||||||
if (User.Id != 0)
|
if (User.Id != 0)
|
||||||
@ -321,8 +411,8 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
{
|
{
|
||||||
LogoutTime = DateTime.Now.Ticks;
|
LogoutTime = DateTime.Now.Ticks;
|
||||||
int TotalMinutes = Convert.ToInt32((new DateTime(LogoutTime) - new DateTime(LoginTime)).TotalMinutes);
|
int TotalMinutes = Convert.ToInt32((new DateTime(LogoutTime) - new DateTime(LoginTime)).TotalMinutes);
|
||||||
SQLHelper.Execute(UserQuery.Update_GameTime(User.Username, TotalMinutes));
|
SQLHelper?.Execute(UserQuery.Update_GameTime(User.Username, TotalMinutes));
|
||||||
if (SQLHelper.Result == SQLResult.Success)
|
if (SQLHelper?.Result == SQLResult.Success)
|
||||||
{
|
{
|
||||||
ServerHelper.WriteLine("OnlinePlayers: 玩家 " + User.Username + " 本次已游玩" + TotalMinutes + "分钟");
|
ServerHelper.WriteLine("OnlinePlayers: 玩家 " + User.Username + " 本次已游玩" + TotalMinutes + "分钟");
|
||||||
}
|
}
|
||||||
@ -384,7 +474,7 @@ namespace Milimoe.FunGame.Server.Model
|
|||||||
{
|
{
|
||||||
// 每两小时触发一次SQL服务器的心跳查询,防止SQL服务器掉线
|
// 每两小时触发一次SQL服务器的心跳查询,防止SQL服务器掉线
|
||||||
Thread.Sleep(2 * 1000 * 3600);
|
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
|
try
|
||||||
{
|
{
|
||||||
SQLHelper.Close();
|
SQLHelper?.Close();
|
||||||
MailSender?.Dispose();
|
MailSender?.Dispose();
|
||||||
Socket?.Close();
|
Socket?.Close();
|
||||||
_Socket = null;
|
_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.Constant;
|
||||||
|
using Milimoe.FunGame.Core.Library.SQLScript.Common;
|
||||||
|
using Milimoe.FunGame.Core.Library.SQLScript.Entity;
|
||||||
using Milimoe.FunGame.Core.Model;
|
using Milimoe.FunGame.Core.Model;
|
||||||
|
using Milimoe.FunGame.Server.Utility;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Server.Others
|
namespace Milimoe.FunGame.Server.Others
|
||||||
{
|
{
|
||||||
@ -20,9 +27,59 @@ namespace Milimoe.FunGame.Server.Others
|
|||||||
public static int OnlinePlayerCount { get; set; } = 0; // 已连接的玩家数量
|
public static int OnlinePlayerCount { get; set; } = 0; // 已连接的玩家数量
|
||||||
public static int ConnectingPlayerCount { get; set; } = 0; // 正在连接的玩家数量
|
public static int ConnectingPlayerCount { get; set; } = 0; // 正在连接的玩家数量
|
||||||
public static Encoding DefaultEncoding { get; } = General.DefaultEncoding; // 默认传输字符集
|
public static Encoding DefaultEncoding { get; } = General.DefaultEncoding; // 默认传输字符集
|
||||||
public static FunGameInfo.FunGame FunGameType { get; } = FunGameInfo.FunGame.FunGame_Server;
|
public static FunGameInfo.FunGame FunGameType { get; } = FunGameInfo.FunGame.FunGame_Server; // FunGame Runtime
|
||||||
public static Hashtable OrderList { get; } = new();
|
public static Hashtable OrderList { get; } = new(); // 服务器指令列表
|
||||||
public static RoomList RoomList { get; set; } = 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
|
public static class OfficialEmail
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
using Milimoe.FunGame.Core.Api.Utility;
|
||||||
using Milimoe.FunGame.Core.Entity;
|
using Milimoe.FunGame.Core.Entity;
|
||||||
using Milimoe.FunGame.Server.Others;
|
using Milimoe.FunGame.Server.Others;
|
||||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Server.Utility
|
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 Milimoe.FunGame.Core.Model;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Server.Utility.DataUtility
|
namespace Milimoe.FunGame.Server.Utility.DataUtility
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using Milimoe.FunGame.Core.Model;
|
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.Model;
|
||||||
|
using Milimoe.FunGame.Server.Others;
|
||||||
|
using Milimoe.FunGame.Server.Utility.DataUtility;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Server.Utility
|
namespace Milimoe.FunGame.Server.Utility
|
||||||
{
|
{
|
||||||
@ -38,7 +38,6 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
public override int Execute()
|
public override int Execute()
|
||||||
{
|
{
|
||||||
// _IsOneTime = true需要手动创建连接和关闭
|
// _IsOneTime = true需要手动创建连接和关闭
|
||||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
|
||||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||||
_DataSet = new DataSet();
|
_DataSet = new DataSet();
|
||||||
_UpdateRows = MySQLManager.Execute(this, out _Result);
|
_UpdateRows = MySQLManager.Execute(this, out _Result);
|
||||||
@ -55,7 +54,6 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
public override int Execute(string Script)
|
public override int Execute(string Script)
|
||||||
{
|
{
|
||||||
// _IsOneTime = true需要手动创建连接和关闭
|
// _IsOneTime = true需要手动创建连接和关闭
|
||||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
|
||||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||||
this.Script = Script;
|
this.Script = Script;
|
||||||
_DataSet = new DataSet();
|
_DataSet = new DataSet();
|
||||||
@ -72,7 +70,6 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
public override DataSet ExecuteDataSet()
|
public override DataSet ExecuteDataSet()
|
||||||
{
|
{
|
||||||
// _IsOneTime = true需要手动创建连接和关闭
|
// _IsOneTime = true需要手动创建连接和关闭
|
||||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
|
||||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||||
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
||||||
if (_IsOneTime) Close();
|
if (_IsOneTime) Close();
|
||||||
@ -88,7 +85,6 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
public override DataSet ExecuteDataSet(string Script)
|
public override DataSet ExecuteDataSet(string Script)
|
||||||
{
|
{
|
||||||
// _IsOneTime = true需要手动创建连接和关闭
|
// _IsOneTime = true需要手动创建连接和关闭
|
||||||
if (_IsOneTime) _Connection = new MySQLConnection(out _ServerInfo);
|
|
||||||
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
ServerHelper.WriteLine("SQLQuery -> " + Script);
|
||||||
this.Script = Script;
|
this.Script = Script;
|
||||||
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
_DataSet = MySQLManager.ExecuteDataSet(this, out _Result, out _UpdateRows);
|
||||||
@ -103,7 +99,7 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
{
|
{
|
||||||
// _IsOneTime = false需要手动调用此方法
|
// _IsOneTime = false需要手动调用此方法
|
||||||
_Connection?.Close();
|
_Connection?.Close();
|
||||||
ServerHelper.WriteLine($"{GetClientName()} 已释放MySQL连接");
|
ServerHelper.WriteLine($"{(GetClientName() == string.Empty ? "" : GetClientName())}已释放MySQL连接");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -119,6 +115,7 @@ namespace Milimoe.FunGame.Server.Utility
|
|||||||
_IsOneTime = IsOneTime;
|
_IsOneTime = IsOneTime;
|
||||||
CommandType = type;
|
CommandType = type;
|
||||||
Parameters = parameters;
|
Parameters = parameters;
|
||||||
|
_Connection = new MySQLConnection(out _ServerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Server.Utility
|
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
|
namespace Milimoe.FunGame.Server.Utility
|
||||||
{
|
{
|
||||||
public class TFA : Core.Api.Utility.TFA
|
public class TFA : TwoFactorAuthenticator
|
||||||
{
|
{
|
||||||
public override bool IsAvailable(string username)
|
public override bool IsAvailable(string username)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user