初次提交
commit
a214b95c82
@ -0,0 +1,22 @@
|
||||
# 忽略所有编译输出和构建工件
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# Visual Studio 文件
|
||||
.vs/
|
||||
*.user
|
||||
*.suo
|
||||
|
||||
# NuGet 包
|
||||
*.nupkg
|
||||
*.snupkg
|
||||
|
||||
# 忽略发布和部署文件
|
||||
*.publishsettings
|
||||
publish/
|
||||
|
||||
#一些功能标识文件
|
||||
.pkey
|
||||
.dblock
|
||||
server.yaml
|
||||
map_img.png
|
||||
@ -0,0 +1,81 @@
|
||||
namespace OMS.NET.Common
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
private readonly int _logLevel;
|
||||
private int logCount;
|
||||
private string logPath;
|
||||
private static readonly object LogLock = new();
|
||||
|
||||
private void WriteLog(string message)
|
||||
{
|
||||
lock (LogLock)
|
||||
{
|
||||
using var writer = new StreamWriter(this.logPath, true);
|
||||
writer.WriteLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
public Logger(int level)
|
||||
{
|
||||
_logLevel = level;
|
||||
this.logPath = GetNewLogFile();
|
||||
}
|
||||
|
||||
private string GetNewLogFile()
|
||||
{
|
||||
this.logCount = 0;
|
||||
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log", $"{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.log");
|
||||
if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log")))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"));
|
||||
}
|
||||
File.WriteAllText(path, "");
|
||||
return path;
|
||||
}
|
||||
|
||||
private void Log(string message, int level)
|
||||
{
|
||||
if (level <= this._logLevel)
|
||||
{
|
||||
string logtime = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss]");
|
||||
string leveltext = level switch
|
||||
{
|
||||
0 => "[ERROR]",
|
||||
1 => "[WARN]",
|
||||
2 => "[INFO]",
|
||||
3 => "[DEBUG]",
|
||||
_ => level.ToString(),
|
||||
};
|
||||
string logtext = leveltext + " " + logtime + " " + message;
|
||||
Console.WriteLine(logtext);
|
||||
if (logCount > 100000)
|
||||
{
|
||||
this.logPath = GetNewLogFile();
|
||||
}
|
||||
//File.AppendAllTextAsync(this.logPath, logtext);
|
||||
WriteLog(logtext);
|
||||
logCount++;
|
||||
}
|
||||
}
|
||||
public void Error(string message)
|
||||
{
|
||||
Log(message, 0);
|
||||
}
|
||||
|
||||
public void Warn(string message)
|
||||
{
|
||||
Log(message, 1);
|
||||
}
|
||||
|
||||
public void Info(string message)
|
||||
{
|
||||
Log(message, 2);
|
||||
}
|
||||
|
||||
public void Debug(string message)
|
||||
{
|
||||
Log(message, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OMS.NET.Common
|
||||
{
|
||||
public class Point
|
||||
{
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
}
|
||||
|
||||
public class Util
|
||||
{
|
||||
public static readonly JsonSerializerOptions options = new()
|
||||
{
|
||||
ReadCommentHandling = JsonCommentHandling.Skip, //允许注释
|
||||
AllowTrailingCommas = true,//允许尾随逗号
|
||||
//PropertyNamingPolicy = new InstructNamingPolicy(), // 属性名为定制转换
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // 忽略 null 值
|
||||
WriteIndented = true, // 美化输出
|
||||
PropertyNameCaseInsensitive = true,//属性名忽略大小写
|
||||
};
|
||||
|
||||
public static string DetailsToBase64(object obj)
|
||||
{
|
||||
string utf8 = JsonSerializer.Serialize(obj, options);
|
||||
return Convert.ToBase64String(Encoding.UTF8.GetBytes(utf8));
|
||||
}
|
||||
//===========================================================
|
||||
|
||||
public static List<Point> PointsFromBase64(string base64)
|
||||
{
|
||||
string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<List<Point>>(utf8, options) ?? new List<Point>();
|
||||
}
|
||||
|
||||
public static Point? PointFromBase64(string base64)
|
||||
{
|
||||
string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<Point>(utf8, options);
|
||||
}
|
||||
|
||||
//===========================================================
|
||||
public static List<KeyValuePair<string, string>> DetailsFromBase64(string base64)
|
||||
{
|
||||
string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<List<KeyValuePair<string, string>>>(utf8, options) ?? new List<KeyValuePair<string, string>>();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> MembersFromBase64(string base64)
|
||||
{
|
||||
string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<Dictionary<string, string>>(utf8, options) ?? new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public static List<long> OrderMembersFromBase64(string base64)
|
||||
{
|
||||
//string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<List<long>>(base64, options) ?? new List<long>();
|
||||
}
|
||||
|
||||
public static List<object> StructuresFromBase64(string base64)
|
||||
{
|
||||
string utf8 = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
|
||||
return JsonSerializer.Deserialize<List<object>>(utf8, options) ?? new List<object>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace OMS.NET.DbClass
|
||||
{
|
||||
public class AccountData
|
||||
{
|
||||
#region base
|
||||
public string UserEmail { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public int? MapLayer { get; set; }
|
||||
public string? DefaultA1 { get; set; }
|
||||
public string? SavePoint { get; set; }
|
||||
public string? UserQQ { get; set; }
|
||||
public string? HeadColor { get; set; }
|
||||
public int Mode { get; set; }
|
||||
public int Phase { get; set; }
|
||||
public string? Custom { get; set; }
|
||||
|
||||
public AccountData()
|
||||
{
|
||||
this.UserEmail = "";
|
||||
this.UserName = "";
|
||||
this.Password = "";
|
||||
this.Mode = 1;
|
||||
this.Phase = 1;
|
||||
//this.Custom = "";
|
||||
}
|
||||
#endregion
|
||||
public static void Add(AccountData accountData)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"INSERT INTO account_data (user_email, user_name, pass_word, map_layer, default_a1, save_point, user_qq, head_color, mode, phase, custom)
|
||||
VALUES (@UserEmail, @UserName, @Password, @MapLayer, @DefaultA1, @SavePoint, @UserQQ, @HeadColor, @Mode, @Phase, @Custom)";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@UserEmail", accountData.UserEmail);
|
||||
command.Parameters.AddWithValue("@UserName", accountData.UserName);
|
||||
command.Parameters.AddWithValue("@Password", accountData.Password);
|
||||
command.Parameters.AddWithValue("@MapLayer", accountData.MapLayer ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@DefaultA1", accountData.DefaultA1 ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@SavePoint", accountData.SavePoint ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@UserQQ", accountData.UserQQ ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@HeadColor", accountData.HeadColor ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Mode", accountData.Mode);
|
||||
command.Parameters.AddWithValue("@Phase", accountData.Phase);
|
||||
command.Parameters.AddWithValue("@Custom", accountData.Custom ?? (object)DBNull.Value);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void Update(AccountData accountData)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"UPDATE account_data SET user_name = @UserName, pass_word = @Password, map_layer = @MapLayer, default_a1 = @DefaultA1, save_point = @SavePoint, user_qq = @UserQQ, head_color = @HeadColor, mode = @Mode, phase = @Phase, custom = @Custom
|
||||
WHERE user_email = @UserEmail";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@UserEmail", accountData.UserEmail);
|
||||
command.Parameters.AddWithValue("@UserName", accountData.UserName);
|
||||
command.Parameters.AddWithValue("@Password", accountData.Password);
|
||||
command.Parameters.AddWithValue("@MapLayer", accountData.MapLayer ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@DefaultA1", accountData.DefaultA1 ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@SavePoint", accountData.SavePoint ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@UserQQ", accountData.UserQQ ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@HeadColor", accountData.HeadColor ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Mode", accountData.Mode);
|
||||
command.Parameters.AddWithValue("@Phase", accountData.Phase);
|
||||
command.Parameters.AddWithValue("@Custom", accountData.Custom ?? (object)DBNull.Value);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void Delete(string userEmail)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"DELETE FROM account_data WHERE user_email = @UserEmail";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@UserEmail", userEmail);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static AccountData? Get(string userEmail)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"SELECT user_email, user_name, pass_word, map_layer, default_a1, save_point, user_qq, head_color, mode, phase, custom
|
||||
FROM account_data WHERE user_email = @UserEmail";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@UserEmail", userEmail);
|
||||
using var reader = command.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new AccountData
|
||||
{
|
||||
UserEmail = reader.GetString("user_email"),
|
||||
UserName = reader.GetString("user_name"),
|
||||
Password = reader.GetString("pass_word"),
|
||||
MapLayer = reader["map_layer"] as int?,
|
||||
DefaultA1 = reader["default_a1"] as string,
|
||||
SavePoint = reader["save_point"] as string,
|
||||
UserQQ = reader["user_qq"] as string,
|
||||
HeadColor = reader["head_color"] as string,
|
||||
Mode = reader.GetInt32("mode"),
|
||||
Phase = reader.GetInt32("phase"),
|
||||
Custom = reader["custom"] as string,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace OMS.NET.DbClass
|
||||
{
|
||||
public class MapData
|
||||
{
|
||||
#region base
|
||||
public long Id { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Points { get; set; }
|
||||
public string Point { get; set; }
|
||||
public string? Color { get; set; }
|
||||
public int Phase { get; set; }
|
||||
public int? Width { get; set; }
|
||||
public string? ChildRelations { get; set; }
|
||||
public string? FatherRelations { get; set; }
|
||||
public string? ChildNodes { get; set; }
|
||||
public string? FatherNode { get; set; }
|
||||
public string? Details { get; set; }
|
||||
public string? Custom { get; set; }
|
||||
|
||||
public MapData()
|
||||
{
|
||||
this.Id = 0;
|
||||
this.Type = "";
|
||||
this.Points = "";
|
||||
this.Point = "";
|
||||
this.Phase = 1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static void Add(MapData mapData)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"INSERT INTO map_0_data (type, points, point, color, phase, width, child_relations, father_relations, child_nodes, father_node, details, custom)
|
||||
VALUES (@Type, @Points, @Point, @Color, @Phase, @Width, @ChildRelations, @FatherRelations, @ChildNodes, @FatherNode, @Details, @Custom)";
|
||||
using MySqlCommand command = new(query, connection);
|
||||
command.Parameters.AddWithValue("@Type", mapData.Type);
|
||||
command.Parameters.AddWithValue("@Points", mapData.Points);
|
||||
command.Parameters.AddWithValue("@Point", mapData.Point);
|
||||
command.Parameters.AddWithValue("@Color", mapData.Color ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Phase", mapData.Phase);
|
||||
command.Parameters.AddWithValue("@Width", mapData.Width ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@ChildRelations", mapData.ChildRelations ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@FatherRelations", mapData.FatherRelations ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@ChildNodes", mapData.ChildNodes ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@FatherNode", mapData.FatherNode ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Details", mapData.Details ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Custom", mapData.Custom ?? (object)DBNull.Value);
|
||||
command.ExecuteNonQuery();
|
||||
mapData.Id = command.LastInsertedId;
|
||||
}
|
||||
|
||||
public static int Update(MapData mapData)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"UPDATE map_0_data SET type = @Type, points = @Points, point = @Point, color = @Color, phase = @Phase, width = @Width,
|
||||
child_relations = @ChildRelations, father_relations = @FatherRelations, child_nodes = @ChildNodes, father_node = @FatherNode,
|
||||
details = @Details, custom = @Custom WHERE id = @Id";
|
||||
using MySqlCommand command = new(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", mapData.Id);
|
||||
command.Parameters.AddWithValue("@Type", mapData.Type);
|
||||
command.Parameters.AddWithValue("@Points", mapData.Points);
|
||||
command.Parameters.AddWithValue("@Point", mapData.Point);
|
||||
command.Parameters.AddWithValue("@Color", mapData.Color ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Phase", mapData.Phase);
|
||||
command.Parameters.AddWithValue("@Width", mapData.Width ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@ChildRelations", mapData.ChildRelations ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@FatherRelations", mapData.FatherRelations ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@ChildNodes", mapData.ChildNodes ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@FatherNode", mapData.FatherNode ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Details", mapData.Details ?? (object)DBNull.Value);
|
||||
command.Parameters.AddWithValue("@Custom", mapData.Custom ?? (object)DBNull.Value);
|
||||
return command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void Delete(long id)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"DELETE FROM map_0_data WHERE id = @Id";
|
||||
using MySqlCommand command = new(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", id);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static MapData? Get(long id)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"SELECT id, type, points, point, color, phase, width, child_relations, father_relations, child_nodes, father_node, details, custom
|
||||
FROM map_0_data WHERE id = @Id";
|
||||
using MySqlCommand command = new(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", id);
|
||||
using MySqlDataReader reader = command.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new MapData
|
||||
{
|
||||
Id = reader.GetInt64("id"),
|
||||
Type = reader.GetString("type"),
|
||||
Points = reader.GetString("points"),
|
||||
Point = reader.GetString("point"),
|
||||
Color = reader["color"] as string,
|
||||
Phase = reader.GetInt32("phase"),
|
||||
Width = reader["width"] as int?,
|
||||
ChildRelations = reader["child_relations"] as string,
|
||||
FatherRelations = reader["father_relations"] as string,
|
||||
ChildNodes = reader["child_nodes"] as string,
|
||||
FatherNode = reader["father_node"] as string,
|
||||
Details = reader["details"] as string,
|
||||
Custom = reader["custom"] as string
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<MapData> GetMapDataList()
|
||||
{
|
||||
List<MapData> mapDataList = new();
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"SELECT * FROM map_0_data";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
using var reader = command.ExecuteReader();
|
||||
if (reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var mapData = new MapData
|
||||
{
|
||||
Id = reader.GetInt64("id"),
|
||||
Type = reader.GetString("type"),
|
||||
Points = reader.GetString("points"),
|
||||
Point = reader.GetString("point"),
|
||||
Color = reader.IsDBNull(reader.GetOrdinal("color")) ? null : reader.GetString("color"),
|
||||
Phase = reader.GetInt32("phase"),
|
||||
Width = reader.IsDBNull(reader.GetOrdinal("width")) ? (int?)null : reader.GetInt32("width"),
|
||||
ChildRelations = reader.IsDBNull(reader.GetOrdinal("child_relations")) ? null : reader.GetString("child_relations"),
|
||||
FatherRelations = reader.IsDBNull(reader.GetOrdinal("father_relations")) ? null : reader.GetString("father_relations"),
|
||||
ChildNodes = reader.IsDBNull(reader.GetOrdinal("child_nodes")) ? null : reader.GetString("child_nodes"),
|
||||
FatherNode = reader.IsDBNull(reader.GetOrdinal("father_node")) ? null : reader.GetString("father_node"),
|
||||
Details = reader.IsDBNull(reader.GetOrdinal("details")) ? null : reader.GetString("details"),
|
||||
Custom = reader.IsDBNull(reader.GetOrdinal("custom")) ? null : reader.GetString("custom")
|
||||
};
|
||||
mapDataList.Add(mapData);
|
||||
}
|
||||
}
|
||||
|
||||
return mapDataList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace OMS.NET.DbClass
|
||||
{
|
||||
public class MapLayer
|
||||
{
|
||||
#region base
|
||||
public long Id { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Members { get; set; }
|
||||
public string Structure { get; set; }
|
||||
public int Phase { get; set; }
|
||||
|
||||
public MapLayer()
|
||||
{
|
||||
this.Id = 0;
|
||||
this.Type = "";
|
||||
this.Members = "";
|
||||
this.Structure = "";
|
||||
this.Phase = 1;
|
||||
}
|
||||
public MapLayer(long id, string type, string members, string structure, int phase)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
Members = members;
|
||||
Structure = structure;
|
||||
Phase = phase;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public static void Add(MapLayer mapLayer)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"INSERT INTO map_0_layer (type, members, structure, phase)
|
||||
VALUES (@Type, @Members, @Structure, @Phase)";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@Type", mapLayer.Type);
|
||||
command.Parameters.AddWithValue("@Members", mapLayer.Members);
|
||||
command.Parameters.AddWithValue("@Structure", mapLayer.Structure);
|
||||
command.Parameters.AddWithValue("@Phase", mapLayer.Phase);
|
||||
command.ExecuteNonQuery();
|
||||
mapLayer.Id = command.LastInsertedId;
|
||||
}
|
||||
|
||||
public static void Update(MapLayer mapLayer)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"UPDATE map_0_layer SET type = @Type, members = @Members, structure = @Structure, phase = @Phase
|
||||
WHERE id = @Id";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", mapLayer.Id);
|
||||
command.Parameters.AddWithValue("@Type", mapLayer.Type);
|
||||
command.Parameters.AddWithValue("@Members", mapLayer.Members);
|
||||
command.Parameters.AddWithValue("@Structure", mapLayer.Structure);
|
||||
command.Parameters.AddWithValue("@Phase", mapLayer.Phase);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static void Delete(long id)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"DELETE FROM map_0_layer WHERE id = @Id";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", id);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public static MapLayer? Get(long id)
|
||||
{
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
var query = @"SELECT id, type, members, structure, phase FROM map_0_layer WHERE id = @Id";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
command.Parameters.AddWithValue("@Id", id);
|
||||
using var reader = command.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new MapLayer
|
||||
{
|
||||
Id = reader.GetInt64("id"),
|
||||
Type = reader.GetString("type"),
|
||||
Members = reader.GetString("members"),
|
||||
Structure = reader.GetString("structure"),
|
||||
Phase = reader.GetInt32("phase")
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有MapLayer数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<MapLayer> GetMapLayerList()
|
||||
{
|
||||
List<MapLayer> mapLayerList = new();
|
||||
using MySqlConnection connection = new(GlobalArea.ConnectionStringWithDbName);
|
||||
connection.Open();
|
||||
string query = "SELECT * FROM map_0_layer";
|
||||
using var command = new MySqlCommand(query, connection);
|
||||
using var reader = command.ExecuteReader();
|
||||
if (reader.HasRows)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var mapLayer = new MapLayer
|
||||
{
|
||||
Id = reader.GetInt64("id"),
|
||||
Type = reader.GetString("type"),
|
||||
Members = reader.GetString("members"),
|
||||
Structure = reader.GetString("structure"),
|
||||
Phase = reader.GetInt32("phase")
|
||||
};
|
||||
mapLayerList.Add(mapLayer);
|
||||
}
|
||||
}
|
||||
return mapLayerList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定是否将指定字段编码成base64格式 ???
|
||||
/// </summary>
|
||||
public static void ProcessMapLayers(List<MapLayer> mapLayers, bool encode = false)
|
||||
{
|
||||
mapLayers.ForEach(mapLayer =>
|
||||
{
|
||||
if (encode)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
/// <summary>
|
||||
/// 广播指令的基类
|
||||
/// </summary>
|
||||
public class BroadcastInstuct : Instruct
|
||||
{
|
||||
public BroadcastInstuct()
|
||||
{
|
||||
this.Type = "broadcast";
|
||||
}
|
||||
}
|
||||
|
||||
public class SendCorrectInstuct : Instruct
|
||||
{
|
||||
public SendCorrectInstuct()
|
||||
{
|
||||
this.Type = "send_error";
|
||||
}
|
||||
}
|
||||
|
||||
public class SendErrorInstuct : Instruct
|
||||
{
|
||||
public SendErrorInstuct()
|
||||
{
|
||||
this.Type = "send_correct";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
using OMS.NET.DbClass;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetMapDataInstruct : Instruct
|
||||
{
|
||||
public GetMapDataInstruct()
|
||||
{
|
||||
this.Type = "get_mapData";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (GlobalArea.LoginCheckByID(wsid))
|
||||
{
|
||||
List<MapData> mapDatas = MapData.GetMapDataList().Where(m => m.Phase != 2).ToList();
|
||||
this.ResponseOrBroadcastInstructs.Add(new SendMapDataInstruct()
|
||||
{
|
||||
IsResponse = true,
|
||||
Data = mapDatas
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SendMapDataInstruct : Instruct
|
||||
{
|
||||
public SendMapDataInstruct()
|
||||
{
|
||||
this.Type = "send_mapData";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
using OMS.NET.DbClass;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetMapLayerInstruct : Instruct
|
||||
{
|
||||
public GetMapLayerInstruct()
|
||||
{
|
||||
this.Type = "get_mapLayer";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (GlobalArea.LoginCheckByID(wsid))
|
||||
{
|
||||
List<MapLayer> mapLayers = MapLayer.GetMapLayerList().Where(m => m.Phase != 2).ToList();
|
||||
this.ResponseOrBroadcastInstructs.Add(new SendMapLayerInstruct()
|
||||
{
|
||||
IsResponse = true,
|
||||
Data = mapLayers
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SendMapLayerInstruct : Instruct
|
||||
{
|
||||
public SendMapLayerInstruct()
|
||||
{
|
||||
this.Type = "send_mapLayer";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
using OMS.NET.DbClass;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetPresenceInstruct : Instruct
|
||||
{
|
||||
public GetPresenceInstruct()
|
||||
{
|
||||
this.Type = "get_presence";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (GlobalArea.LoginCheckByID(wsid))
|
||||
{
|
||||
//获取所有在线用户,移除重复
|
||||
List<string?> emails = GlobalArea.UserConnects.Where(u => u.UserEmail != null)
|
||||
.Select(u => u.UserEmail).Distinct().ToList();
|
||||
List<dynamic> allLoginUsers = new();
|
||||
emails.ForEach(email =>
|
||||
{
|
||||
AccountData accountData = GlobalArea.GetLoginAccountData(email)!;
|
||||
//由于是已登录用户,默认都能查询到值
|
||||
allLoginUsers.Add(new
|
||||
{
|
||||
userEmail = accountData.UserEmail,
|
||||
userQq = accountData.UserQQ,
|
||||
userName = accountData.UserName,
|
||||
headColor = accountData.HeadColor,
|
||||
});
|
||||
});
|
||||
this.ResponseOrBroadcastInstructs.Add(new SendPresenceInstruct()
|
||||
{
|
||||
IsResponse = true,
|
||||
Data = allLoginUsers,
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SendPresenceInstruct : Instruct
|
||||
{
|
||||
public SendPresenceInstruct()
|
||||
{
|
||||
this.Type = "send_presence";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetPublickeyInstruct : Instruct
|
||||
{
|
||||
public GetPublickeyInstruct()
|
||||
{
|
||||
this.Type = "get_publickey";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
this.ResponseOrBroadcastInstructs.Add(new PublickeyInstruct()
|
||||
{
|
||||
Data = GlobalArea.GetRsaPublickKey(),
|
||||
IsResponse = true
|
||||
});
|
||||
//Thread.Sleep(9000);//模拟耗时操作
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class PublickeyInstruct : Instruct
|
||||
{
|
||||
public PublickeyInstruct()
|
||||
{
|
||||
this.Type = "publickey";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetServerConfigInstruct : Instruct
|
||||
{
|
||||
public GetServerConfigInstruct()
|
||||
{
|
||||
this.Type = "get_serverConfig";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
this.ResponseOrBroadcastInstructs.Add(new SendServerConfigInstruct
|
||||
{
|
||||
IsResponse = true,
|
||||
Data = new
|
||||
{
|
||||
anonymous_login = bool.TryParse(GlobalArea.ServerConfig.AnonymousLogin, out bool booleanValue) && booleanValue,
|
||||
key = GlobalArea.ServerConfig.Key,
|
||||
url = GlobalArea.ServerConfig.Url,
|
||||
name = GlobalArea.ServerConfig.Name,
|
||||
online_number = GlobalArea.ConnectClientsCount,
|
||||
max_online = GlobalArea.ServerConfig.MaxUser,
|
||||
default_x = GlobalArea.ServerConfig.DefaultX,
|
||||
default_y = GlobalArea.ServerConfig.DefaultY,
|
||||
//以下在0.7会删除
|
||||
enable_base_map = GlobalArea.ServerConfig.EnableBase,
|
||||
//base_map_type= GlobalArea.ServerConfig.ServerConfigEnableBase,
|
||||
max_zoom = GlobalArea.ServerConfig.MaxZoom,
|
||||
min_zoom = GlobalArea.ServerConfig.MinZoom,
|
||||
default_zoom = GlobalArea.ServerConfig.DefaultZoom,
|
||||
base_map_url = GlobalArea.ServerConfig.BaseMapUrl
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SendServerConfigInstruct : Instruct
|
||||
{
|
||||
public SendServerConfigInstruct()
|
||||
{
|
||||
this.Type = "send_serverConfig";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
using System.Globalization;
|
||||
using WebSocketSharp;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetServerImgInstruct : Instruct
|
||||
{
|
||||
public GetServerImgInstruct()
|
||||
{
|
||||
this.Type = "get_serverImg";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (this.Time != null)
|
||||
{
|
||||
//时间解析
|
||||
string format = "yyyy-MM-dd HH:mm:ss";
|
||||
DateTime clientDateTime = DateTime.ParseExact(this.Time, format, CultureInfo.InvariantCulture);
|
||||
//Console.WriteLine("Converted DateTime: " + clientDateTime);
|
||||
string serverImgPath = GlobalArea.ServerConfig.Img;
|
||||
if (File.Exists(serverImgPath))
|
||||
{
|
||||
DateTime serverImgLastModified = File.GetLastWriteTime(serverImgPath);
|
||||
Instruct res = new SendServerConfigInstruct
|
||||
{
|
||||
IsResponse = true
|
||||
};
|
||||
if (serverImgLastModified > clientDateTime)
|
||||
{
|
||||
byte[] imageBytes = File.ReadAllBytes(serverImgPath);
|
||||
string imageFileType = GetImageFileType(imageBytes);
|
||||
string base64String = $"data:image/{imageFileType};base64," + Convert.ToBase64String(imageBytes);
|
||||
//Console.WriteLine("Base64 Encoded Image: " + base64String);
|
||||
res.Data = new
|
||||
{
|
||||
@string = base64String,
|
||||
time = serverImgLastModified.ToString(format),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Data = new
|
||||
{
|
||||
@string = ""
|
||||
};
|
||||
}
|
||||
this.ResponseOrBroadcastInstructs.Add(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static string GetImageFileType(byte[] imageBytes)
|
||||
{
|
||||
byte[] fileHeader = imageBytes.SubArray(0, 8);
|
||||
|
||||
// PNG 文件的文件头字节为 89 50 4E 47 0D 0A 1A 0A
|
||||
if (fileHeader[0] == 0x89 && fileHeader[1] == 0x50 && fileHeader[2] == 0x4E && fileHeader[3] == 0x47 &&
|
||||
fileHeader[4] == 0x0D && fileHeader[5] == 0x0A && fileHeader[6] == 0x1A && fileHeader[7] == 0x0A)
|
||||
{
|
||||
return "png";
|
||||
}
|
||||
|
||||
// JPEG 文件的文件头字节为 FF D8 FF
|
||||
if (fileHeader[0] == 0xFF && fileHeader[1] == 0xD8 && fileHeader[2] == 0xFF)
|
||||
{
|
||||
return "jpeg";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public class SendServerImgInstruct : Instruct
|
||||
{
|
||||
public SendServerImgInstruct()
|
||||
{
|
||||
this.Type = "send_serverImg";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
using OMS.NET.DbClass;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
public class GetUserDataInstruct : Instruct
|
||||
{
|
||||
public GetUserDataInstruct()
|
||||
{
|
||||
this.Type = "get_userData";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (GlobalArea.LoginCheckByID(wsid))
|
||||
{
|
||||
string userEmail = GlobalArea.UserConnects.First(u => u.ID == wsid).UserEmail!;
|
||||
AccountData accountData = GlobalArea.GetLoginAccountData(userEmail)!;
|
||||
this.ResponseOrBroadcastInstructs.Add(new SendUserDataInstruct()
|
||||
{
|
||||
IsResponse = true,
|
||||
Data = new
|
||||
{
|
||||
user_email = accountData.UserEmail,
|
||||
user_name = accountData.UserName,
|
||||
map_layer = accountData.MapLayer,
|
||||
default_a1 = accountData.DefaultA1,
|
||||
save_point = accountData.SavePoint,
|
||||
head_color = accountData.HeadColor,
|
||||
mode = accountData.Mode,
|
||||
phase = accountData.Phase,
|
||||
custom = accountData.Custom,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SendUserDataInstruct : Instruct
|
||||
{
|
||||
public SendUserDataInstruct()
|
||||
{
|
||||
this.Type = "send_userData";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
/// <summary>
|
||||
/// 声明json转换的命名策略
|
||||
/// </summary>
|
||||
class InstructNamingPolicy : JsonNamingPolicy
|
||||
{
|
||||
public override string ConvertName(string name)
|
||||
{
|
||||
return Convert(name);
|
||||
}
|
||||
|
||||
public static string Convert(string name) => name switch
|
||||
{
|
||||
"Type" => "type",
|
||||
"Class" => "class",
|
||||
"Conveyor" => "conveyor",
|
||||
"Time" => "time",
|
||||
"Data" => "data",
|
||||
_ => name,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实现依据type和class的值决定反序列化的对象类型
|
||||
/// </summary>
|
||||
class InstructConverter : JsonConverter<Instruct>
|
||||
{
|
||||
public override Instruct Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
using JsonDocument doc = JsonDocument.ParseValue(ref reader);
|
||||
JsonElement root = doc.RootElement;
|
||||
//Console.WriteLine(root.GetRawText());
|
||||
if (root.TryGetProperty("type", out JsonElement typeProperty))
|
||||
{
|
||||
string? typeValue = typeProperty.GetString();
|
||||
string? classValue = root.TryGetProperty("class", out JsonElement classProperty) ? classProperty.GetString() : null;
|
||||
Instruct? instruct = typeValue switch
|
||||
{
|
||||
//实现新指令需在这里添加反序列化类型,限定为客户端发过来的指令类型
|
||||
"get_publickey" => JsonSerializer.Deserialize<GetPublickeyInstruct>(root.GetRawText(), options),
|
||||
"get_serverImg" => JsonSerializer.Deserialize<GetServerImgInstruct>(root.GetRawText(), options),
|
||||
"get_serverConfig" => JsonSerializer.Deserialize<GetServerConfigInstruct>(root.GetRawText(), options),
|
||||
"login" => JsonSerializer.Deserialize<LoginInstruct>(root.GetRawText(), options),
|
||||
"test" => JsonSerializer.Deserialize<TestInstruct>(root.GetRawText(), options),
|
||||
"get_userData" => JsonSerializer.Deserialize<GetUserDataInstruct>(root.GetRawText(), options),
|
||||
"get_presence" => JsonSerializer.Deserialize<GetPresenceInstruct>(root.GetRawText(), options),
|
||||
"get_mapData" => JsonSerializer.Deserialize<GetMapDataInstruct>(root.GetRawText(), options),
|
||||
"get_mapLayer" => JsonSerializer.Deserialize<GetMapLayerInstruct>(root.GetRawText(), options),
|
||||
|
||||
//广播指令
|
||||
"broadcast" => classValue switch
|
||||
{
|
||||
//广播指令继承结构
|
||||
"" => JsonSerializer.Deserialize<BroadcastInstuct>(root.GetRawText(), options),
|
||||
_ => JsonSerializer.Deserialize<Instruct>(root.GetRawText(), options)
|
||||
},
|
||||
_ => null
|
||||
} ?? throw new JsonException("反序列化失败");
|
||||
return instruct;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonException("type property not found");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Instruct value, JsonSerializerOptions options)
|
||||
{
|
||||
//JsonSerializer.Serialize(writer, (object)value, options); 这个在Data是对象时导致了无限递归调用
|
||||
writer.WriteStartObject();
|
||||
writer.WriteString(InstructNamingPolicy.Convert(nameof(Instruct.Type)), value.Type);
|
||||
if (value.Class != null)
|
||||
{
|
||||
writer.WriteString(InstructNamingPolicy.Convert(nameof(Instruct.Class)), value.Class);
|
||||
}
|
||||
if (value.Conveyor != null)
|
||||
{
|
||||
writer.WriteString(InstructNamingPolicy.Convert(nameof(Instruct.Conveyor)), value.Conveyor);
|
||||
}
|
||||
if (value.Time != null)
|
||||
{
|
||||
writer.WriteString(InstructNamingPolicy.Convert(nameof(Instruct.Time)), value.Time);
|
||||
}
|
||||
if (value.Data != null)
|
||||
{
|
||||
writer.WritePropertyName(InstructNamingPolicy.Convert(nameof(Instruct.Data)));
|
||||
JsonSerializer.Serialize(writer, value.Data, value.Data.GetType(), options);
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
public class Instruct
|
||||
{
|
||||
public static readonly JsonSerializerOptions options = new()
|
||||
{
|
||||
ReadCommentHandling = JsonCommentHandling.Skip, //允许注释
|
||||
AllowTrailingCommas = true,//允许尾随逗号
|
||||
PropertyNamingPolicy = new InstructNamingPolicy(), // 属性名为定制转换
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // 忽略 null 值
|
||||
WriteIndented = true, // 美化输出
|
||||
//PropertyNameCaseInsensitive = true,//属性名忽略大小写
|
||||
Converters = { new InstructConverter() },
|
||||
};
|
||||
public string Type { get; set; }
|
||||
public string? Class { get; set; }
|
||||
public string? Conveyor { get; set; }
|
||||
public string? Time { get; set; }
|
||||
public dynamic? Data { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsResponse { get; set; } = false;
|
||||
[JsonIgnore]
|
||||
public bool IsBroadcast { get; set; } = false;
|
||||
[JsonIgnore]
|
||||
public List<Instruct> ResponseOrBroadcastInstructs { get; set; } = new();
|
||||
|
||||
public Instruct()
|
||||
{
|
||||
this.Type = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指令处理逻辑
|
||||
/// </summary>
|
||||
/// <returns>将耗时任务交给Task以不阻塞单个连接的多个请求</returns>
|
||||
public virtual Task Handler(string wsid)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task HandlerAndMeasure(string wsid)
|
||||
{
|
||||
Stopwatch stopWatch = new();
|
||||
stopWatch.Start();
|
||||
await Handler(wsid);
|
||||
stopWatch.Stop();
|
||||
GlobalArea.Log.Debug($"处理{this.GetType()}耗时:{stopWatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
}
|
||||
|
||||
public static Instruct? JsonStringParse(string jsonString)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<Instruct>(jsonString, options);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GlobalArea.Log.Error(ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
|
||||
using System.Text.Json;
|
||||
using OMS.NET.DbClass;
|
||||
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录指令
|
||||
/// </summary>
|
||||
public class LoginInstruct : Instruct
|
||||
{
|
||||
public LoginInstruct()
|
||||
{
|
||||
this.Type = "login";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (this.Data?.GetType() == typeof(JsonElement))
|
||||
{
|
||||
string email = this.Data.GetProperty("email").GetString();
|
||||
string password = this.Data.GetProperty("password").GetString();
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
GlobalArea.Log.Warn("登录信息不能为空!");
|
||||
return;
|
||||
}
|
||||
//能够获取到则说明客户端有发送数据过来
|
||||
Instruct res1 = new LoginStatusInstuct
|
||||
{
|
||||
Data = false,
|
||||
IsResponse = true
|
||||
};//默认为false
|
||||
//Console.WriteLine($"已获取到{email}:{password},解密测试{GlobalArea.DecryptFromBase64String(password)}");
|
||||
AccountData? accountData = AccountData.Get(email);
|
||||
GlobalArea.AddLoginAccountData(accountData);
|
||||
if (accountData != null)
|
||||
{
|
||||
//只能原文比较,密文每次都不一样,涉及随机性填充
|
||||
if (accountData.Password == GlobalArea.DecryptFromBase64String(password))
|
||||
{
|
||||
res1.Data = true;//登录成功则修改为true
|
||||
this.ResponseOrBroadcastInstructs.Add(res1);
|
||||
GlobalArea.Log.Info($"{accountData.UserEmail}:登录成功");
|
||||
GlobalArea.Login(wsid, accountData.UserEmail);
|
||||
GlobalArea.Log.Info($"当前登录用户数量: {GlobalArea.LoginUserCount}");
|
||||
this.ResponseOrBroadcastInstructs.Add(new Instruct
|
||||
{
|
||||
Type = "broadcast",
|
||||
Class = "logIn",
|
||||
Data = new
|
||||
{
|
||||
userEmail = accountData.UserEmail,
|
||||
userName = accountData.UserName,
|
||||
headColor = accountData.HeadColor,
|
||||
userQq = accountData.UserQQ,
|
||||
},
|
||||
IsBroadcast = true
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ResponseOrBroadcastInstructs.Add(res1);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginStatusInstuct : Instruct
|
||||
{
|
||||
public LoginStatusInstuct()
|
||||
{
|
||||
this.Type = "loginStatus";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于测试和代码复制
|
||||
/// </summary>
|
||||
public class PingInstuct : Instruct
|
||||
{
|
||||
public PingInstuct()
|
||||
{
|
||||
this.Type = "ping";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
this.ResponseOrBroadcastInstructs.Add(new PongInstuct()
|
||||
{
|
||||
IsResponse = true
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class PongInstuct : Instruct
|
||||
{
|
||||
public PongInstuct()
|
||||
{
|
||||
this.Type = "pong";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
namespace OMS.NET.Instructs
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于测试和代码复制
|
||||
/// </summary>
|
||||
public class TestInstruct : Instruct
|
||||
{
|
||||
public TestInstruct()
|
||||
{
|
||||
this.Type = "test";
|
||||
}
|
||||
|
||||
public override Task Handler(string wsid)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
//GlobalArea.UserConnects.Where(x => x.ID == wsid).First().UserEmail = "xxx@xx.com";//login
|
||||
GlobalArea.Log.Info("当前客户端连接数:" + GlobalArea.ConnectClientsCount);
|
||||
GlobalArea.Log.Info("当前登录用户数:" + GlobalArea.LoginUserCount);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
CREATE TABLE IF NOT EXISTS map_0_data (
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
type VARCHAR(12) NOT NULL,
|
||||
points MEDIUMTEXT NOT NULL,
|
||||
point VARCHAR(255) NOT NULL,
|
||||
color VARCHAR(255),
|
||||
phase INT(1) NOT NULL,
|
||||
width INT(11),
|
||||
child_relations MEDIUMTEXT,
|
||||
father_relations VARCHAR(255),
|
||||
child_nodes MEDIUMTEXT,
|
||||
father_node VARCHAR(255),
|
||||
details MEDIUMTEXT,
|
||||
custom MEDIUMTEXT,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS map_0_layer (
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
type VARCHAR(255) NOT NULL,
|
||||
members MEDIUMTEXT NOT NULL,
|
||||
structure MEDIUMTEXT NOT NULL,
|
||||
phase INT(1) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS account_data (
|
||||
user_email VARCHAR(255) NOT NULL,
|
||||
user_name VARCHAR(255) NOT NULL,
|
||||
pass_word VARCHAR(255) NOT NULL,
|
||||
map_layer INT(11),
|
||||
default_a1 VARCHAR(255),
|
||||
save_point MEDIUMTEXT,
|
||||
user_qq VARCHAR(255),
|
||||
head_color VARCHAR(6),
|
||||
mode INT(1) NOT NULL,
|
||||
phase INT(1) NOT NULL,
|
||||
custom MEDIUMTEXT,
|
||||
PRIMARY KEY (user_email)
|
||||
);
|
||||
Loading…
Reference in New Issue