Compare commits
2 Commits
63d5ef6693
...
48dbe8785c
Author | SHA1 | Date | |
---|---|---|---|
48dbe8785c | |||
f26c11ac73 |
70
Server/LuaEngine/LuaEngine.cs
Normal file
70
Server/LuaEngine/LuaEngine.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using NLua;
|
||||
using System;
|
||||
|
||||
namespace PSO2SERVER.LuaEngine
|
||||
{
|
||||
public class LuaScriptEngine
|
||||
{
|
||||
private Lua lua;
|
||||
|
||||
public LuaScriptEngine()
|
||||
{
|
||||
// 初始化 LuaEngine 解释器
|
||||
lua = new Lua();
|
||||
}
|
||||
|
||||
// 执行 LuaEngine 脚本
|
||||
public void ExecuteScript(string script)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 执行传入的 LuaEngine 脚本
|
||||
lua.DoString(script);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error executing LuaEngine script: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// 执行并获取 LuaEngine 脚本结果
|
||||
public object ExecuteScriptWithResult(string script)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 执行 LuaEngine 脚本并返回结果
|
||||
return lua.DoString(script)[0];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error executing LuaEngine script: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 将 C# 对象传递给 LuaEngine 环境
|
||||
public void SetGlobalVariable(string name, object value)
|
||||
{
|
||||
lua[name] = value;
|
||||
}
|
||||
|
||||
// 获取 LuaEngine 环境中的全局变量
|
||||
public object GetGlobalVariable(string name)
|
||||
{
|
||||
return lua[name];
|
||||
}
|
||||
|
||||
// 使用 MethodBase 注册方法
|
||||
public void RegisterFunction(string luaFunctionName, object obj, string methodName)
|
||||
{
|
||||
var methodInfo = obj.GetType().GetMethod(methodName);
|
||||
lua.RegisterFunction(luaFunctionName, obj, methodInfo);
|
||||
}
|
||||
|
||||
// 清理 LuaEngine 解释器
|
||||
public void Dispose()
|
||||
{
|
||||
lua.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ using Newtonsoft.Json;
|
||||
using PSO2SERVER.Zone;
|
||||
using PSO2SERVER.Json;
|
||||
using PSO2SERVER.Models;
|
||||
using NLua;
|
||||
|
||||
namespace PSO2SERVER
|
||||
{
|
||||
@ -43,6 +44,9 @@ namespace PSO2SERVER
|
||||
public const int ServerShipListProtNums_NA = 6;
|
||||
public const int ServerShipListProt_NA = 13001;
|
||||
|
||||
public const string ServerBlockBalanceName = "Test";
|
||||
public const int ServerBlockBalanceProt = 12205;
|
||||
|
||||
public const string ServerSettingsKey = "Resources\\settings.txt";
|
||||
public const string ServerMemoryPacket = "Resources\\setMemoryPacket.bin"; //TODO
|
||||
|
||||
@ -94,6 +98,24 @@ namespace PSO2SERVER
|
||||
|
||||
//JsonTest.JsonReadTest();
|
||||
|
||||
//using (var state = new LuaEngine())
|
||||
//{
|
||||
// //Retrieving LuaEngine functions:
|
||||
// state.DoString(@"function ScriptFunc (val1, val2)
|
||||
// if val1 > val2 then
|
||||
// return val1 + 1
|
||||
// else
|
||||
// return val2 - 1
|
||||
// end
|
||||
// end
|
||||
// ");
|
||||
// var scriptFunc = state["ScriptFunc"] as LuaFunction;
|
||||
// var funcRes = scriptFunc.Call(3, 5).First();
|
||||
// Console.WriteLine($"Func result:{funcRes}");
|
||||
|
||||
// Console.ReadKey();
|
||||
//}
|
||||
|
||||
try
|
||||
{
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using PSO2SERVER.Models;
|
||||
using PSO2SERVER.Protocol.Packets;
|
||||
|
||||
namespace PSO2SERVER.Protocol.Handlers
|
||||
{
|
||||
[PacketHandlerAttr(0x31, 0x01)]
|
||||
public class NewTitlesRequest : PacketHandler
|
||||
{
|
||||
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
|
||||
{
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
|
||||
Logger.WriteHex(info, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using PSO2SERVER.Models;
|
||||
using PSO2SERVER.Protocol.Packets;
|
||||
|
||||
namespace PSO2SERVER.Protocol.Handlers
|
||||
{
|
||||
[PacketHandlerAttr(0x31, 0x03)]
|
||||
public class TitleListRequest : PacketHandler
|
||||
{
|
||||
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
|
||||
{
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
|
||||
Logger.WriteHex(info, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using PSO2SERVER.Models;
|
||||
using PSO2SERVER.Protocol.Packets;
|
||||
|
||||
namespace PSO2SERVER.Protocol.Handlers
|
||||
{
|
||||
[PacketHandlerAttr(0x31, 0x06)]
|
||||
public class TitleConditionRequest : PacketHandler
|
||||
{
|
||||
public struct GetTitleConditionPacket
|
||||
{
|
||||
/// Requested title ID.
|
||||
public uint title_id;
|
||||
}
|
||||
|
||||
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
|
||||
{
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
|
||||
Logger.WriteHex(info, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using PSO2SERVER.Models;
|
||||
using PSO2SERVER.Protocol.Packets;
|
||||
|
||||
namespace PSO2SERVER.Protocol.Handlers
|
||||
{
|
||||
[PacketHandlerAttr(0x31, 0x08)]
|
||||
public class PlayAchievementsRequest : PacketHandler
|
||||
{
|
||||
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
|
||||
{
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
|
||||
Logger.WriteHex(info, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using PSO2SERVER.Models;
|
||||
using PSO2SERVER.Protocol.Packets;
|
||||
|
||||
namespace PSO2SERVER.Protocol.Handlers
|
||||
{
|
||||
[PacketHandlerAttr(0x31, 0x0A)]
|
||||
public class ReceiveTitleRewardRequest : PacketHandler
|
||||
{
|
||||
public struct ReceiveTitleRewardRequestPacket
|
||||
{
|
||||
/// Requested title ID.
|
||||
public uint title_id;
|
||||
}
|
||||
|
||||
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
|
||||
{
|
||||
var info = string.Format("[<--] 接收到的数据 (hex): {0} 字节", data.Length);
|
||||
Logger.WriteHex(info, data);
|
||||
}
|
||||
}
|
||||
}
|
@ -106,7 +106,7 @@ namespace PSO2SERVER
|
||||
|
||||
private async Task DoBlockBalanceAsync(Socket socket)
|
||||
{
|
||||
var balancepacket = new BlockBalancePacket("test", 12205).GetPacketBytes();
|
||||
var balancepacket = new BlockBalancePacket(ServerApp.ServerBlockBalanceName, ServerApp.ServerBlockBalanceProt).GetPacketBytes();
|
||||
|
||||
await Task.Factory.FromAsync(
|
||||
(cb, state) => socket.BeginSend(balancepacket, 0, balancepacket.Length, SocketFlags.None, cb, state),
|
||||
|
@ -11,8 +11,9 @@ namespace PSO2SERVER
|
||||
{
|
||||
public static Server Instance { get; private set; }
|
||||
|
||||
private readonly SocketServer _server;
|
||||
public string _name { get; private set; }
|
||||
|
||||
private readonly SocketServer _server;
|
||||
public List<Client> Clients { get; private set; }
|
||||
public DateTime StartTime { get; private set; }
|
||||
public Timer PingTimer;
|
||||
@ -20,7 +21,8 @@ namespace PSO2SERVER
|
||||
public Server()
|
||||
{
|
||||
Clients = new List<Client>();
|
||||
_server = new SocketServer(12205);
|
||||
_name = ServerApp.ServerBlockBalanceName;
|
||||
_server = new SocketServer(ServerApp.ServerBlockBalanceProt);
|
||||
_server.NewClient += HandleNewClient;
|
||||
Instance = this;
|
||||
StartTime = DateTime.Now;
|
||||
|
@ -313,6 +313,7 @@
|
||||
<Compile Include="Json\JsonRead.cs" />
|
||||
<Compile Include="Json\QuestJson.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="LuaEngine\LuaEngine.cs" />
|
||||
<Compile Include="Models\BattleStats.cs" />
|
||||
<Compile Include="Models\BlockInfo.cs" />
|
||||
<Compile Include="Models\CharacterAdditionalStruct.cs" />
|
||||
@ -410,9 +411,14 @@
|
||||
<Compile Include="Protocol\Handlers\2B-SettingHandler\2B-01-SavePlayerSettings.cs" />
|
||||
<Compile Include="Protocol\Handlers\2B-SettingHandler\2B-00-SettingsRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\2F-SymbolHandler\2F-06-SymbolArtHandler.cs" />
|
||||
<Compile Include="Protocol\Handlers\31-TitleHandler\31-0A-ReceiveTitleRewardRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\31-TitleHandler\31-06-TitleConditionRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\31-TitleHandler\31-08-PlayAchievementsRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\31-TitleHandler\31-03-TitleListRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\34-UNK\34-72-UNK.cs" />
|
||||
<Compile Include="Protocol\Handlers\3B-ForgeHandler\3B-00-CharacterForgeInfoRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\0F-ItemHandler\0F-DA-UNK0FDA.cs" />
|
||||
<Compile Include="Protocol\Handlers\34-UNK\34-72-UNK.cs" />
|
||||
<Compile Include="Protocol\Handlers\31-TitleHandler\31-01-NewTitlesRequest.cs" />
|
||||
<Compile Include="Protocol\Handlers\48-UNK\48-16-UNK4816.cs" />
|
||||
<Compile Include="Protocol\Handlers\49-UNK\49-00-UNK4900.cs" />
|
||||
<Compile Include="Protocol\Handlers\4A-ARKSMisionsHandler\4A-0C-SetTrackedMission.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user