完善Room的构造函数和SQLScript (#65)

This commit is contained in:
milimoe 2023-12-02 01:19:02 +08:00 committed by GitHub
parent 10d9a257f8
commit a60b6d7b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View File

@ -13,9 +13,9 @@ namespace Milimoe.FunGame.Core.Api.Factory
return RoomFactory.Create();
}
public static Room Create(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, string Password = "")
public static Room Create(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, bool IsRank = false, string Password = "")
{
return new Room(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, Password);
return new Room(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, IsRank, Password);
}
}
}

View File

@ -72,11 +72,12 @@ namespace Milimoe.FunGame.Core.Api.Utility
/// <param name="GameMode">游戏模组</param>
/// <param name="GameMap"></param>
/// <param name="RoomState">房间状态</param>
/// <param name="IsRank"></param>
/// <param name="Password">房间密码</param>
/// <returns></returns>
public static Room GetRoom(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, string Password = "")
public static Room GetRoom(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, bool IsRank = false, string Password = "")
{
return RoomFactory.Create(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, Password);
return RoomFactory.Create(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, IsRank, Password);
}
/// <summary>
@ -98,8 +99,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
string GameMode = (string)DrRoom[RoomQuery.Column_GameMode];
string GameMap = (string)DrRoom[RoomQuery.Column_GameMap];
RoomState RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
bool IsRank = Convert.ToInt32(DrRoom[RoomQuery.Column_IsRank]) == 1;
string Password = (string)DrRoom[RoomQuery.Column_Password];
room = GetRoom(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, Password);
room = GetRoom(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, IsRank, Password);
}
return room;
}
@ -136,8 +138,9 @@ namespace Milimoe.FunGame.Core.Api.Utility
string GameMode = (string)DrRoom[RoomQuery.Column_GameMode];
string GameMap = (string)DrRoom[RoomQuery.Column_GameMap];
RoomState RoomState = (RoomState)Convert.ToInt32(DrRoom[RoomQuery.Column_RoomState]);
bool IsRank = Convert.ToInt32(DrRoom[RoomQuery.Column_IsRank]) == 1;
string Password = (string)DrRoom[RoomQuery.Column_Password];
list.Add(GetRoom(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, Password));
list.Add(GetRoom(Id, Roomid, CreateTime, RoomMaster, RoomType, GameMode, GameMap, RoomState, IsRank, Password));
}
}
return list;

View File

@ -235,7 +235,7 @@
</summary>
<returns></returns>
</member>
<member name="M:Milimoe.FunGame.Core.Api.Utility.Factory.GetRoom(System.Int64,System.String,System.Nullable{System.DateTime},Milimoe.FunGame.Core.Entity.User,Milimoe.FunGame.Core.Library.Constant.RoomType,System.String,System.String,Milimoe.FunGame.Core.Library.Constant.RoomState,System.String)">
<member name="M:Milimoe.FunGame.Core.Api.Utility.Factory.GetRoom(System.Int64,System.String,System.Nullable{System.DateTime},Milimoe.FunGame.Core.Entity.User,Milimoe.FunGame.Core.Library.Constant.RoomType,System.String,System.String,Milimoe.FunGame.Core.Library.Constant.RoomState,System.Boolean,System.String)">
<summary>
获取房间实例
</summary>
@ -247,6 +247,7 @@
<param name="GameMode">游戏模组</param>
<param name="GameMap"></param>
<param name="RoomState">房间状态</param>
<param name="IsRank"></param>
<param name="Password">房间密码</param>
<returns></returns>
</member>

View File

@ -24,14 +24,17 @@ namespace Milimoe.FunGame.Core.Entity
Statistics = new(this);
}
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, string Password = "")
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, string GameMode = "", string GameMap = "", RoomState RoomState = RoomState.Created, bool IsRank = false, string Password = "")
{
this.Id = Id;
this.Roomid = Roomid;
this.CreateTime = CreateTime ?? General.DefaultTime;
this.RoomMaster = RoomMaster ?? General.UnknownUserInstance;
this.RoomType = RoomType;
this.GameMode = GameMode;
this.GameMap = GameMap;
this.RoomState = RoomState;
this.IsRank = IsRank;
this.Password = Password;
Statistics = new(this);
}

View File

@ -66,6 +66,10 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter
room.RoomState = (RoomState)reader.GetInt64();
break;
case RoomQuery.Column_IsRank:
room.IsRank = reader.GetBoolean();
break;
case RoomQuery.Column_Password:
room.Password = reader.GetString() ?? "";
break;

View File

@ -12,18 +12,19 @@
public const string Column_GameMode = "GameMode";
public const string Column_GameMap = "GameMap";
public const string Column_RoomState = "RoomState";
public const string Column_IsRank = "IsRank";
public const string Column_HasPass = "HasPass";
public const string Column_Password = "Password";
public const string Select_Rooms = $"{Command_Select} {TableName}.{Command_All}, {UserQuery.TableName}.{UserQuery.Column_Username} {Command_As} {Column_RoomMasterName} " +
$"{Command_From} {TableName} {Command_LeftJoin} {UserQuery.TableName} {Command_On} {UserQuery.TableName}.{UserQuery.Column_UID} = {TableName}.{Column_RoomMaster}";
public static string Insert_CreateRoom(string RoomID, long RoomMaster, Library.Constant.RoomType RoomType, string GameMode, string GameMap, string Password)
public static string Insert_CreateRoom(string RoomID, long RoomMaster, Library.Constant.RoomType RoomType, string GameMode, string GameMap, bool IsRank, string Password)
{
Library.Constant.RoomState RoomState = Library.Constant.RoomState.Created;
DateTime NowTime = DateTime.Now;
bool HasPass = Password.Trim() != "";
return $"{Command_Insert} {Command_Into} {TableName} ({Column_RoomID}, {Column_CreateTime}, {Column_RoomMaster}, {Column_RoomType}, {Column_GameMode}, {Column_GameMap}, {Column_RoomState}, {Column_HasPass}, {Column_Password})" +
$" {Command_Values} ('{RoomID}', '{NowTime}', {RoomMaster}, {(int)RoomType}, '{GameMode}', '{GameMap}', {(int)RoomState}, {(HasPass ? 1 : 0)}, '{Password}')";
return $"{Command_Insert} {Command_Into} {TableName} ({Column_RoomID}, {Column_CreateTime}, {Column_RoomMaster}, {Column_RoomType}, {Column_GameMode}, {Column_GameMap}, {Column_RoomState}, {Column_IsRank}, {Column_HasPass}, {Column_Password})" +
$" {Command_Values} ('{RoomID}', '{NowTime}', {RoomMaster}, {(int)RoomType}, '{GameMode}', '{GameMap}', {(int)RoomState}, {(IsRank ? 1 : 0)}, {(HasPass ? 1 : 0)}, '{Password}')";
}
public static string Delete_Rooms(params string[] roomids)