暂存
This commit is contained in:
parent
501b0d9f8f
commit
be5d3618ef
@ -136,22 +136,23 @@ namespace PSO2SERVER
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
sendName = $"{name} ({typeA:X}-{typeB:X})";
|
||||
sendName = $"0x{typeA:X2} - 0x{typeB:X2} ({name})";
|
||||
}
|
||||
else
|
||||
{
|
||||
sendName = $"{typeA:X}-{typeB:X}";
|
||||
sendName = $"0x{typeA:X2} - 0x{typeB:X2}";
|
||||
}
|
||||
|
||||
Logger.Write($"[接收] 数据 {sendName} (Flags {(PacketFlags)flags1}) ({blob.Length} 字节)");
|
||||
Logger.Write($"[接收] 数据包 {sendName} (Flags {(PacketFlags)flags1}) ({blob.Length} 字节)");
|
||||
|
||||
if (Logger.VerbosePackets)
|
||||
{
|
||||
var info = string.Format("[接收] {0:X}-{1:X} 数据包:", typeA, typeB);
|
||||
var info = string.Format("[接收] 0x{0:X2} - 0x{1:X2} 数据包:", typeA, typeB);
|
||||
Logger.WriteHex(info, blob);
|
||||
LogPacket(false, typeA, typeB, flags1, flags2, blob);
|
||||
}
|
||||
|
||||
LogPacket(false, typeA, typeB, flags1, flags2, blob);
|
||||
|
||||
OutputArc4?.TransformBlock(blob, 0, blob.Length, blob, 0);
|
||||
|
||||
try
|
||||
@ -197,11 +198,11 @@ namespace PSO2SERVER
|
||||
string packetName;
|
||||
if (handler != null)
|
||||
{
|
||||
packetName = $"{handler.GetType().Name} ({typeA:X}-{typeB:X})";
|
||||
packetName = $"0x{typeA:X2} - 0x{typeB:X2} ({handler.GetType().Name})";
|
||||
}
|
||||
else
|
||||
{
|
||||
packetName = $"{typeA:X}-{typeB:X}";
|
||||
packetName = $"0x{typeA:X2} - 0x{typeB:X2}";
|
||||
}
|
||||
Logger.Write($"[发送] 数据包 {packetName} (Flags {(PacketFlags)flags1}) ({size + 8} 字节)");
|
||||
var packet = new byte[size];
|
||||
@ -213,16 +214,17 @@ namespace PSO2SERVER
|
||||
for (var i = 0; i < size; i++)
|
||||
dataTrimmed[i] = data[i];
|
||||
|
||||
var info = string.Format("[发送] {0:X}-{1:X} 数据:", typeA, typeB);
|
||||
var info = string.Format("[发送] 0x{0:X2} - 0x{1:X2} 数据包:", typeA, typeB);
|
||||
Logger.WriteHex(info, dataTrimmed);
|
||||
LogPacket(true, typeA, typeB, flags1, flags2, packet);
|
||||
}
|
||||
|
||||
LogPacket(true, typeA, typeB, flags1, flags2, packet);
|
||||
|
||||
if (handler != null)
|
||||
handler.HandlePacket(this, flags1, packet, 0, size);
|
||||
else
|
||||
{
|
||||
Logger.WriteWarning("[!!!] 未解析数据包 {0:X}-{1:X} - (Flags {2}) ({3} 字节)", typeA,
|
||||
Logger.WriteWarning("[未解析] 0x{0:X2} - 0x{1:X2} (未解析数据包) (Flags {2}) ({3} 字节)", typeA,
|
||||
typeB, (PacketFlags)flags1, size);
|
||||
LogUnkClientPacket(typeA, typeB, flags1, flags2, packet);
|
||||
}
|
||||
@ -234,19 +236,18 @@ namespace PSO2SERVER
|
||||
{
|
||||
// Check for and create packets directory if it doesn't exist
|
||||
var packetPath = string.Format(
|
||||
"packets/{0}-{1}/0x{2:X2} - 0x{3:X2}",
|
||||
_server.StartTime.ToShortDateString().Replace('/', '-'),
|
||||
_server.StartTime.ToShortTimeString().Replace(':', '-').Replace('/', '-'),
|
||||
typeA, typeB
|
||||
"packets/{0}/0x{1:X2} - 0x{2:X2}"
|
||||
, _server.StartTime.ToShortDateString().Replace('/', '-')
|
||||
, typeA, typeB
|
||||
);
|
||||
|
||||
if (!Directory.Exists(packetPath))
|
||||
Directory.CreateDirectory(packetPath);
|
||||
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}-{4}.bin"
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}.bin"
|
||||
, packetPath
|
||||
, typeA, typeB
|
||||
, _packetId++
|
||||
//, _packetId++
|
||||
, fromClient ? "C" : "S"
|
||||
);
|
||||
|
||||
@ -267,18 +268,17 @@ namespace PSO2SERVER
|
||||
{
|
||||
// Check for and create packets directory if it doesn't exist
|
||||
var packetPath = string.Format(
|
||||
"UnkClientPackets/{0}-{1}/0x{2:X2} - 0x{3:X2}",
|
||||
_server.StartTime.ToShortDateString().Replace('/', '-'),
|
||||
_server.StartTime.ToShortTimeString().Replace(':', '-').Replace('/', '-'),
|
||||
typeA, typeB
|
||||
"UnkClientPackets/{0}/0x{1:X2} - 0x{2:X2}"
|
||||
, _server.StartTime.ToShortDateString().Replace('/', '-')
|
||||
, typeA, typeB
|
||||
);
|
||||
if (!Directory.Exists(packetPath))
|
||||
Directory.CreateDirectory(packetPath);
|
||||
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}-{4}.bin"
|
||||
var filename = string.Format("{0}/0x{1:X2}-0x{2:X2}-{3}.bin"
|
||||
, packetPath
|
||||
, typeA, typeB
|
||||
, _packetId++
|
||||
//, _packetId++
|
||||
, "C-unk"
|
||||
);
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
|
||||
// memset packet - Enables menus
|
||||
// Also holds event items and likely other stuff too
|
||||
var memSetPacket = File.ReadAllBytes("Resources/setMemoryPacket.bin");
|
||||
var memSetPacket = File.ReadAllBytes(ServerApp.ServerMemoryPacket);
|
||||
context.SendPacket(memSetPacket);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
}
|
||||
else // We're all good!
|
||||
{
|
||||
// Insert new player into database
|
||||
// 直接插入新账户至数据库
|
||||
user = new Player
|
||||
{
|
||||
Username = username.ToLower(),
|
||||
@ -84,7 +84,6 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
{
|
||||
if(password == "")
|
||||
{
|
||||
|
||||
error = "密码为空.";
|
||||
user = null;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
PackedData theFlags = (PackedData)dataFlags;
|
||||
|
||||
// Debug
|
||||
Logger.WriteInternal("[MOV] Movement 数据包来自 {0} 包含 {1} 数据.", context.Character.Name, theFlags);
|
||||
//Logger.WriteInternal("[移动] Movement 数据包来自 {0} 包含 {1} 数据.", context.Character.Name, theFlags);
|
||||
|
||||
// TODO: Maybe do this better someday
|
||||
FullMovementData dstData = new FullMovementData();
|
||||
@ -129,8 +129,8 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
}
|
||||
|
||||
|
||||
Logger.WriteInternal("[MOV] 玩家 {0} 移动中 (坐标:{1}, {2}, {3})", context.Character.Name, context.CurrentLocation.PosX,
|
||||
context.CurrentLocation.PosY, context.CurrentLocation.PosZ);
|
||||
//Logger.WriteInternal("[移动] 玩家 {0} 移动中 (坐标: X{1}, Y{2}, Z{3})", context.Character.Name, context.CurrentLocation.PosX,
|
||||
//context.CurrentLocation.PosY, context.CurrentLocation.PosZ);
|
||||
|
||||
foreach (var c in Server.Instance.Clients)
|
||||
{
|
||||
@ -163,9 +163,9 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
PacketWriter writer = new PacketWriter();
|
||||
writer.WriteStruct(movData);
|
||||
|
||||
Logger.WriteInternal("[MOV] 玩家 {0} 停止移动 (坐标:{1}, {2}, {3})", context.Character.Name,
|
||||
Helper.FloatFromHalfPrecision(movData.currentPos.x), Helper.FloatFromHalfPrecision(movData.currentPos.y),
|
||||
Helper.FloatFromHalfPrecision(movData.currentPos.z));
|
||||
//Logger.WriteInternal("[移动] 玩家 {0} 停止移动 (坐标:{1}, {2}, {3})", context.Character.Name,
|
||||
// Helper.FloatFromHalfPrecision(movData.currentPos.x), Helper.FloatFromHalfPrecision(movData.currentPos.y),
|
||||
// Helper.FloatFromHalfPrecision(movData.currentPos.z));
|
||||
|
||||
foreach (var c in Server.Instance.Clients)
|
||||
{
|
||||
@ -201,7 +201,7 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
byte[] final = reader.ReadBytes(4);
|
||||
|
||||
|
||||
Logger.WriteInternal("[ACT] {0} 发送动作 {1}", context.Character.Name, command);
|
||||
//Logger.WriteInternal("[动作] {0} 发送动作 {1}", context.Character.Name, command);
|
||||
|
||||
foreach (var c in Server.Instance.Clients)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PSO2SERVER.Packets.Handlers
|
||||
{
|
||||
@ -27,27 +27,33 @@ namespace PSO2SERVER.Packets.Handlers
|
||||
|
||||
public static void LoadPacketHandlers()
|
||||
{
|
||||
var classes = from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where
|
||||
t.IsClass && t.Namespace == "PSO2SERVER.Packets.Handlers" &&
|
||||
t.IsSubclassOf(typeof (PacketHandler))
|
||||
select t;
|
||||
var handlers = (from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.IsClass && t.Namespace == "PSO2SERVER.Packets.Handlers" &&
|
||||
t.IsSubclassOf(typeof(PacketHandler))
|
||||
let attrs = (PacketHandlerAttr[])t.GetCustomAttributes(typeof(PacketHandlerAttr), false)
|
||||
where attrs.Length > 0
|
||||
select new
|
||||
{
|
||||
Type = attrs[0].Type,
|
||||
Subtype = attrs[0].Subtype,
|
||||
HandlerType = t
|
||||
}).ToList();
|
||||
|
||||
foreach (var t in classes.ToList())
|
||||
// Sort handlers by Type and Subtype
|
||||
handlers = handlers.OrderBy(h => h.Type).ThenBy(h => h.Subtype).ToList();
|
||||
|
||||
foreach (var handler in handlers)
|
||||
{
|
||||
var attrs = (Attribute[]) t.GetCustomAttributes(typeof (PacketHandlerAttr), false);
|
||||
Logger.WriteInternal("[数据] 数据包 0x{0:X2} - 0x{1:X2} 处理已载入 {2} ."
|
||||
, handler.Type
|
||||
, handler.Subtype
|
||||
, handler.HandlerType.Name
|
||||
);
|
||||
|
||||
if (attrs.Length > 0)
|
||||
ushort packetTypeUShort = Helper.PacketTypeToUShort(handler.Type, handler.Subtype);
|
||||
if (!Handlers.ContainsKey(packetTypeUShort))
|
||||
{
|
||||
var attr = (PacketHandlerAttr) attrs[0];
|
||||
Logger.WriteInternal("[数据] 数据包 0x{0:X2} - 0x{1:X2} {2} 处理已载入 ."
|
||||
, attr.Type
|
||||
, attr.Subtype
|
||||
, t.Name
|
||||
);
|
||||
if (!Handlers.ContainsKey(Helper.PacketTypeToUShort(attr.Type, attr.Subtype)))
|
||||
Handlers.Add(Helper.PacketTypeToUShort(attr.Type, attr.Subtype),
|
||||
(PacketHandler) Activator.CreateInstance(t));
|
||||
Handlers.Add(packetTypeUShort, (PacketHandler)Activator.CreateInstance(handler.HandlerType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ namespace PSO2SERVER
|
||||
public const int ServerShipListProt = 12099;
|
||||
|
||||
public const string ServerSettingsKey = "Resources\\settings.txt";
|
||||
public const string ServerMemoryPacket = "Resources\\setMemoryPacket.bin";
|
||||
|
||||
// 密钥BLOB格式
|
||||
public const string ServerPrivateKeyBlob = "key\\privateKey.blob";
|
||||
@ -197,9 +198,9 @@ namespace PSO2SERVER
|
||||
|
||||
await InitializeDatabaseAsync();
|
||||
|
||||
await InitializeQueryServers(QueryMode.AuthList, ServerShipProt, ServerShipProtNums); // Assuming this is synchronous
|
||||
await InitializeQueryServers(QueryMode.AuthList, "认证", ServerShipProt, ServerShipProtNums);
|
||||
|
||||
await InitializeQueryServers(QueryMode.ShipList, ServerShipListProt, ServerShipListProtNums); // Assuming this is synchronous
|
||||
await InitializeQueryServers(QueryMode.ShipList, "舰船", ServerShipListProt, ServerShipListProtNums);
|
||||
|
||||
Logger.WriteInternal("服务器启动完成 " + DateTime.Now);
|
||||
|
||||
@ -222,18 +223,27 @@ namespace PSO2SERVER
|
||||
|
||||
private async Task InitializeDatabaseAsync()
|
||||
{
|
||||
Logger.WriteInternal("[DBC] 载入数据库...");
|
||||
await Task.Run(() =>
|
||||
try
|
||||
{
|
||||
Logger.WriteInternal("[DBC] 载入数据库...");
|
||||
using (var db = new ServerEf())
|
||||
{
|
||||
db.TestDatabaseConnection();
|
||||
db.SetupDB();
|
||||
await Task.Run(() =>
|
||||
{
|
||||
db.TestDatabaseConnection();
|
||||
db.SetupDB();
|
||||
});
|
||||
Logger.WriteInternal("[DBC] 数据库初始化完成。");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteException("[DBC] 数据库初始化异常", ex);
|
||||
throw; // 重新抛出异常,或者根据需要处理它
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InitializeQueryServers(QueryMode queryMode, int port, int portnums)
|
||||
public async Task InitializeQueryServers(QueryMode queryMode, string portname, int port, int portnums)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
@ -244,21 +254,12 @@ namespace PSO2SERVER
|
||||
{
|
||||
for (var i = 0; i < portnums; i++)
|
||||
{
|
||||
QueryServers.Add(new QueryServer(queryMode, "舰船", port + (100 * i)));
|
||||
QueryServers.Add(new QueryServer(queryMode, portname, port + (100 * i)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//private void InitializeQueryServers()
|
||||
//{
|
||||
// for (var i = 0; i < 10; i++)
|
||||
// {
|
||||
// QueryServers.Add(new QueryServer(QueryMode.ShipList, "舰船", 12099 + (100 * i)));
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
private static void Exit(object sender, EventArgs e)
|
||||
{
|
||||
// Save the configuration
|
||||
|
@ -31,7 +31,7 @@ namespace PSO2SERVER
|
||||
_port = port;
|
||||
var queryTask = Task.Run(() => RunAsync());
|
||||
RunningServers.Add(queryTask);
|
||||
Logger.WriteInternal("[监听] 开始监听" + desc + "端口 " + port);
|
||||
Logger.WriteInternal("[监听] 监听" + desc + "端口 " + port);
|
||||
}
|
||||
|
||||
private async Task RunAsync()
|
||||
|
Loading…
Reference in New Issue
Block a user