mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-23 21:27:46 +00:00
Removed NLua and replaced it with MoonSharp. Scripting for NPCs has been implemented, but still have to test a lot.
This commit is contained in:
parent
74be19c51d
commit
300748668f
27 changed files with 22603 additions and 136 deletions
|
@ -41,8 +41,8 @@
|
||||||
<HintPath>..\packages\Dapper.1.42\lib\net45\Dapper.dll</HintPath>
|
<HintPath>..\packages\Dapper.1.42\lib\net45\Dapper.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="KeraLua">
|
<Reference Include="MoonSharp.Interpreter">
|
||||||
<HintPath>..\packages\NLua.1.3.2.1\lib\net45\KeraLua.dll</HintPath>
|
<HintPath>..\packages\MoonSharp.1.2.1.0\lib\net40-client\MoonSharp.Interpreter.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MySql.Data, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
<Reference Include="MySql.Data, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\MySql.Data.6.9.7\lib\net45\MySql.Data.dll</HintPath>
|
<HintPath>..\packages\MySql.Data.6.9.7\lib\net45\MySql.Data.dll</HintPath>
|
||||||
|
@ -52,9 +52,6 @@
|
||||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="NLua">
|
|
||||||
<HintPath>..\packages\NLua.1.3.2.1\lib\net45\NLua.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
@ -103,6 +100,7 @@
|
||||||
<Compile Include="lua\LuaEngine.cs" />
|
<Compile Include="lua\LuaEngine.cs" />
|
||||||
<Compile Include="lua\LuaEvent.cs" />
|
<Compile Include="lua\LuaEvent.cs" />
|
||||||
<Compile Include="lua\LuaParam.cs" />
|
<Compile Include="lua\LuaParam.cs" />
|
||||||
|
<Compile Include="lua\LuaNpc.cs" />
|
||||||
<Compile Include="lua\LuaPlayer.cs" />
|
<Compile Include="lua\LuaPlayer.cs" />
|
||||||
<Compile Include="PacketProcessor.cs" />
|
<Compile Include="PacketProcessor.cs" />
|
||||||
<Compile Include="packets\BasePacket.cs" />
|
<Compile Include="packets\BasePacket.cs" />
|
||||||
|
@ -231,7 +229,7 @@
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
xcopy /s /y "D:\Coding\FFXIV Related\ffxiv-classic-map-server\packages\NLua.1.3.2.1\lib\native\*.*" "$(TargetDir)"</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|
|
@ -32,6 +32,7 @@ using FFXIVClassic_Map_Server.packets.send.events;
|
||||||
using FFXIVClassic_Map_Server.lua;
|
using FFXIVClassic_Map_Server.lua;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using FFXIVClassic_Map_Server.common.EfficientHashTables;
|
using FFXIVClassic_Map_Server.common.EfficientHashTables;
|
||||||
|
using FFXIVClassic_Map_Server.Actors;
|
||||||
|
|
||||||
namespace FFXIVClassic_Lobby_Server
|
namespace FFXIVClassic_Lobby_Server
|
||||||
{
|
{
|
||||||
|
@ -223,12 +224,12 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
player.eventCurrentStarter = eventStart.eventStarter;
|
player.eventCurrentStarter = eventStart.eventStarter;
|
||||||
|
|
||||||
//Is it a static actor? If not look in the player's instance
|
//Is it a static actor? If not look in the player's instance
|
||||||
//Actor ownerActor = findActor(player, player.eventCurrentOwner);
|
Actor ownerActor = mServer.GetWorldManager().GetActorInWorld(player.eventCurrentOwner);
|
||||||
|
|
||||||
//if (ownerActor == null)
|
if (ownerActor == null)
|
||||||
// break;
|
break;
|
||||||
|
|
||||||
//luaEngine.doEventStart(player, ownerActor, eventStart);
|
mServer.GetLuaEngine().doActorOnEventStarted(player.getActor(), ownerActor);
|
||||||
|
|
||||||
//Log.debug(String.Format("\n===Event START===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nEvent Starter: {4}\nParams: {5}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.val1, eventStart.val2, eventStart.eventStarter, LuaParamReader.dumpParams(eventStart.luaParams)));
|
//Log.debug(String.Format("\n===Event START===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nEvent Starter: {4}\nParams: {5}", eventStart.actorID, eventStart.scriptOwnerActorID, eventStart.val1, eventStart.val2, eventStart.eventStarter, LuaParamReader.dumpParams(eventStart.luaParams)));
|
||||||
break;
|
break;
|
||||||
|
@ -238,12 +239,12 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
EventUpdatePacket eventUpdate = new EventUpdatePacket(subpacket.data);
|
EventUpdatePacket eventUpdate = new EventUpdatePacket(subpacket.data);
|
||||||
Log.debug(String.Format("\n===Event UPDATE===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nFunction ID: 0x{4:X}\nParams: {5}", eventUpdate.actorID, eventUpdate.scriptOwnerActorID, eventUpdate.val1, eventUpdate.val2, eventUpdate.step, LuaUtils.dumpParams(eventUpdate.luaParams)));
|
Log.debug(String.Format("\n===Event UPDATE===\nSource Actor: 0x{0:X}\nCaller Actor: 0x{1:X}\nVal1: 0x{2:X}\nVal2: 0x{3:X}\nFunction ID: 0x{4:X}\nParams: {5}", eventUpdate.actorID, eventUpdate.scriptOwnerActorID, eventUpdate.val1, eventUpdate.val2, eventUpdate.step, LuaUtils.dumpParams(eventUpdate.luaParams)));
|
||||||
|
|
||||||
/*Actor updateOwnerActor = findActor(player, player.eventCurrentOwner);
|
Actor updateOwnerActor = mServer.GetWorldManager().GetActorInWorld(player.eventCurrentOwner);
|
||||||
if (updateOwnerActor == null)
|
if (updateOwnerActor == null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
luaEngine.doEventUpdated(player, updateOwnerActor, eventUpdate);
|
mServer.GetLuaEngine().doActorOnEventUpdated(player.getActor(), updateOwnerActor, eventUpdate);
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
case 0x012F:
|
case 0x012F:
|
||||||
subpacket.debugPrintSubPacket();
|
subpacket.debugPrintSubPacket();
|
||||||
|
|
|
@ -25,17 +25,29 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
public const int BUFFER_SIZE = 0x400;
|
public const int BUFFER_SIZE = 0x400;
|
||||||
public const int BACKLOG = 100;
|
public const int BACKLOG = 100;
|
||||||
|
|
||||||
|
private static Server mSelf;
|
||||||
|
|
||||||
private Socket mServerSocket;
|
private Socket mServerSocket;
|
||||||
|
|
||||||
private Dictionary<uint,ConnectedPlayer> mConnectedPlayerList = new Dictionary<uint,ConnectedPlayer>();
|
private Dictionary<uint,ConnectedPlayer> mConnectedPlayerList = new Dictionary<uint,ConnectedPlayer>();
|
||||||
private List<ClientConnection> mConnectionList = new List<ClientConnection>();
|
private List<ClientConnection> mConnectionList = new List<ClientConnection>();
|
||||||
private LuaEngine luaEngine = new LuaEngine();
|
private LuaEngine mLuaEngine = new LuaEngine();
|
||||||
private WorldManager mWorldManager;
|
private WorldManager mWorldManager;
|
||||||
private StaticActors mStaticActors = new StaticActors();
|
private StaticActors mStaticActors = new StaticActors();
|
||||||
private PacketProcessor mProcessor;
|
private PacketProcessor mProcessor;
|
||||||
private Thread mProcessorThread;
|
private Thread mProcessorThread;
|
||||||
private Thread mGameThread;
|
private Thread mGameThread;
|
||||||
|
|
||||||
|
public Server()
|
||||||
|
{
|
||||||
|
mSelf = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Server getServer()
|
||||||
|
{
|
||||||
|
return mSelf;
|
||||||
|
}
|
||||||
|
|
||||||
#region Socket Handling
|
#region Socket Handling
|
||||||
public bool startServer()
|
public bool startServer()
|
||||||
{
|
{
|
||||||
|
@ -353,6 +365,11 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LuaEngine GetLuaEngine()
|
||||||
|
{
|
||||||
|
return mLuaEngine;
|
||||||
|
}
|
||||||
|
|
||||||
public WorldManager GetWorldManager()
|
public WorldManager GetWorldManager()
|
||||||
{
|
{
|
||||||
return mWorldManager;
|
return mWorldManager;
|
||||||
|
|
|
@ -361,6 +361,17 @@ namespace FFXIVClassic_Map_Server
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Actor GetActorInWorld(uint charId)
|
||||||
|
{
|
||||||
|
foreach (Zone zone in zoneList.Values)
|
||||||
|
{
|
||||||
|
Actor a = zone.FindActorInZone(charId);
|
||||||
|
if (a != null)
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Player GetPCInWorld(uint charId)
|
public Player GetPCInWorld(uint charId)
|
||||||
{
|
{
|
||||||
foreach (Zone zone in zoneList.Values)
|
foreach (Zone zone in zoneList.Values)
|
||||||
|
|
|
@ -248,6 +248,13 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public Actor FindActorInZone(uint id)
|
||||||
|
{
|
||||||
|
if (!mActorList.ContainsKey(id))
|
||||||
|
return null;
|
||||||
|
return mActorList[id];
|
||||||
|
}
|
||||||
|
|
||||||
public Player FindPCInZone(string name)
|
public Player FindPCInZone(string name)
|
||||||
{
|
{
|
||||||
foreach (Actor a in mActorList.Values)
|
foreach (Actor a in mActorList.Values)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using FFXIVClassic_Lobby_Server.common;
|
using FFXIVClassic_Lobby_Server.common;
|
||||||
using FFXIVClassic_Lobby_Server.packets;
|
using FFXIVClassic_Lobby_Server.packets;
|
||||||
using FFXIVClassic_Map_Server.actors;
|
using FFXIVClassic_Map_Server.actors;
|
||||||
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Map_Server.lua;
|
using FFXIVClassic_Map_Server.lua;
|
||||||
using FFXIVClassic_Map_Server.packets.send.actor;
|
using FFXIVClassic_Map_Server.packets.send.actor;
|
||||||
using FFXIVClassic_Map_Server.utils;
|
using FFXIVClassic_Map_Server.utils;
|
||||||
|
@ -43,7 +44,15 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||||
|
|
||||||
public override SubPacket createScriptBindPacket(uint playerActorId)
|
public override SubPacket createScriptBindPacket(uint playerActorId)
|
||||||
{
|
{
|
||||||
List<LuaParam> lParams = LuaUtils.createLuaParamList("/Chara/Npc/Populace/PopulaceStandard", false, false, false, false, false, 0xF47F6, false, false, 0, 1, "TEST");
|
List<LuaParam> lParams;
|
||||||
|
|
||||||
|
LuaEngine lua = Server.getServer().GetLuaEngine();
|
||||||
|
Player player = Server.getServer().GetWorldManager().GetPCInWorld(playerActorId);
|
||||||
|
lParams = lua.doActorOnInstantiate(player, this);
|
||||||
|
|
||||||
|
if (lParams == null)
|
||||||
|
lParams = LuaUtils.createLuaParamList("/Chara/Npc/Populace/PopulaceStandard", false, false, false, false, false, 0xF47F6, false, false, 0, 1, "TEST");
|
||||||
|
|
||||||
return ActorInstantiatePacket.buildPacket(actorId, playerActorId, actorName, className, lParams);
|
return ActorInstantiatePacket.buildPacket(actorId, playerActorId, actorName, className, lParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ using FFXIVClassic_Map_Server.lua;
|
||||||
using FFXIVClassic_Map_Server.packets.send;
|
using FFXIVClassic_Map_Server.packets.send;
|
||||||
using FFXIVClassic_Map_Server.packets.send.actor;
|
using FFXIVClassic_Map_Server.packets.send.actor;
|
||||||
using FFXIVClassic_Map_Server.packets.send.Actor.inventory;
|
using FFXIVClassic_Map_Server.packets.send.Actor.inventory;
|
||||||
|
using FFXIVClassic_Map_Server.packets.send.events;
|
||||||
using FFXIVClassic_Map_Server.packets.send.list;
|
using FFXIVClassic_Map_Server.packets.send.list;
|
||||||
using FFXIVClassic_Map_Server.packets.send.login;
|
using FFXIVClassic_Map_Server.packets.send.login;
|
||||||
using FFXIVClassic_Map_Server.packets.send.player;
|
using FFXIVClassic_Map_Server.packets.send.player;
|
||||||
|
@ -588,5 +589,43 @@ namespace FFXIVClassic_Map_Server.Actors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void queuePacket(BasePacket packet)
|
||||||
|
{
|
||||||
|
playerSession.queuePacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queuePacket(SubPacket packet)
|
||||||
|
{
|
||||||
|
playerSession.queuePacket(packet, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(uint logType, string sender, string message)
|
||||||
|
{
|
||||||
|
queuePacket(SendMessagePacket.buildPacket(actorId, actorId, logType, sender, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logout()
|
||||||
|
{
|
||||||
|
queuePacket(LogoutPacket.buildPacket(actorId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quitGame()
|
||||||
|
{
|
||||||
|
queuePacket(QuitPacket.buildPacket(actorId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runEventFunction(string functionName, params object[] parameters)
|
||||||
|
{
|
||||||
|
List<LuaParam> lParams = LuaUtils.createLuaParamList(parameters);
|
||||||
|
queuePacket(RunEventFunctionPacket.buildPacket(actorId, playerSession.eventCurrentOwner, playerSession.eventCurrentStarter, functionName, lParams));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endEvent()
|
||||||
|
{
|
||||||
|
SubPacket p = EndEventPacket.buildPacket(actorId, playerSession.eventCurrentOwner, playerSession.eventCurrentStarter);
|
||||||
|
p.debugPrintSubPacket();
|
||||||
|
queuePacket(p);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@ using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Map_Server.packets.receive.events;
|
using FFXIVClassic_Map_Server.packets.receive.events;
|
||||||
using FFXIVClassic_Map_Server.packets.send;
|
using FFXIVClassic_Map_Server.packets.send;
|
||||||
using FFXIVClassic_Map_Server.packets.send.events;
|
using FFXIVClassic_Map_Server.packets.send.events;
|
||||||
using NLua;
|
using MoonSharp.Interpreter;
|
||||||
|
using MoonSharp.Interpreter.Interop;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -17,59 +18,129 @@ namespace FFXIVClassic_Map_Server.lua
|
||||||
class LuaEngine
|
class LuaEngine
|
||||||
{
|
{
|
||||||
const string FILEPATH_COMMANDS = "./scripts/command/{0}.lua";
|
const string FILEPATH_COMMANDS = "./scripts/command/{0}.lua";
|
||||||
const string FILEPATH_EVENTS = "./scripts/talk/{0}.lua";
|
const string FILEPATH_NPCS = "./scripts/zones/{0}/npcs/{1}.lua";
|
||||||
|
|
||||||
Lua lstate = new Lua();
|
|
||||||
|
|
||||||
public LuaEngine()
|
public LuaEngine()
|
||||||
{
|
{
|
||||||
|
UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LuaParam> doActorOnInstantiate(Player player, Actor target)
|
||||||
|
{
|
||||||
|
string luaPath;
|
||||||
|
|
||||||
|
if (target is Npc)
|
||||||
|
{
|
||||||
|
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||||
|
if (File.Exists(luaPath))
|
||||||
|
{
|
||||||
|
Script script = new Script();
|
||||||
|
script.DoFile(luaPath);
|
||||||
|
DynValue result = script.Call(script.Globals["onInstantiate"], player, target);
|
||||||
|
List<LuaParam> lparams = LuaUtils.createLuaParamList(result);
|
||||||
|
return lparams;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<SubPacket> sendError = new List<SubPacket>();
|
||||||
|
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||||
|
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||||
|
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void doEventStart(ConnectedPlayer player, Actor target, EventStartPacket packet)
|
public void doActorOnEventStarted(Player player, Actor target)
|
||||||
{
|
{
|
||||||
string luaPath;
|
string luaPath;
|
||||||
|
|
||||||
if (target is Command)
|
if (target is Command)
|
||||||
|
{
|
||||||
luaPath = String.Format(FILEPATH_COMMANDS, target.getName());
|
luaPath = String.Format(FILEPATH_COMMANDS, target.getName());
|
||||||
|
if (File.Exists(luaPath))
|
||||||
|
{
|
||||||
|
Script script = new Script();
|
||||||
|
script.DoFile(luaPath);
|
||||||
|
DynValue result = script.Call(script.Globals["onEventStarted"], player, target);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<SubPacket> sendError = new List<SubPacket>();
|
||||||
|
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||||
|
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||||
|
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (target is Npc)
|
else if (target is Npc)
|
||||||
luaPath = String.Format(FILEPATH_EVENTS, target.getName());
|
|
||||||
else
|
|
||||||
luaPath = "";
|
|
||||||
|
|
||||||
if (File.Exists(luaPath))
|
|
||||||
{
|
{
|
||||||
lstate.DoFile(luaPath);
|
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||||
var eventStarted = lstate["eventStarted"] as LuaFunction;
|
if (File.Exists(luaPath))
|
||||||
eventStarted.Call(new LuaPlayer(player), player.eventCurrentOwner, LuaUtils.createLuaParamObjectList(packet.luaParams));
|
{
|
||||||
}
|
Script script = new Script();
|
||||||
else
|
script.DoFile(luaPath);
|
||||||
{
|
DynValue result = script.Call(script.Globals["onEventStarted"], player, target);
|
||||||
List<SubPacket> sendError = new List<SubPacket>();
|
}
|
||||||
sendError.Add(EndEventPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter));
|
else
|
||||||
sendError.Add(SendMessagePacket.buildPacket(player.actorID, player.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "ERROR: Could not find script for event"));
|
{
|
||||||
player.queuePacket(BasePacket.createPacket(sendError, true, false));
|
List<SubPacket> sendError = new List<SubPacket>();
|
||||||
|
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||||
|
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||||
|
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doEventUpdated(ConnectedPlayer player, Actor target, EventUpdatePacket packet)
|
public void doActorOnEventUpdated(Player player, Actor target, EventUpdatePacket eventUpdate)
|
||||||
{
|
{
|
||||||
string luaPath = String.Format(FILEPATH_EVENTS, ((Command)target).getName());
|
string luaPath;
|
||||||
|
|
||||||
if (File.Exists(luaPath))
|
if (target is Command)
|
||||||
{
|
{
|
||||||
lstate.DoFile(luaPath);
|
luaPath = String.Format(FILEPATH_COMMANDS, target.getName());
|
||||||
var eventStarted = lstate["eventUpdated"] as LuaFunction;
|
if (File.Exists(luaPath))
|
||||||
eventStarted.Call(new LuaPlayer(player), player.eventCurrentOwner, packet.step, LuaUtils.createLuaParamObjectList(packet.luaParams));
|
{
|
||||||
|
Script script = new Script();
|
||||||
|
script.DoFile(luaPath);
|
||||||
|
DynValue result = script.Call(script.Globals["onEventUpdate"], player, target, eventUpdate.step, eventUpdate.luaParams);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<SubPacket> sendError = new List<SubPacket>();
|
||||||
|
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||||
|
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||||
|
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (target is Npc)
|
||||||
{
|
{
|
||||||
List<SubPacket> sendError = new List<SubPacket>();
|
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||||
sendError.Add(EndEventPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter));
|
if (File.Exists(luaPath))
|
||||||
sendError.Add(SendMessagePacket.buildPacket(player.actorID, player.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "ERROR: Could not find script for event"));
|
{
|
||||||
player.queuePacket(BasePacket.createPacket(sendError, true, false));
|
Script script = new Script();
|
||||||
|
script.DoFile(luaPath);
|
||||||
|
|
||||||
|
//Have to do this to combine LuaParams
|
||||||
|
List<Object> objects = new List<Object>();
|
||||||
|
objects.Add(player);
|
||||||
|
objects.Add(target);
|
||||||
|
objects.Add(eventUpdate.step);
|
||||||
|
objects.AddRange(LuaUtils.createLuaParamObjectList(eventUpdate.luaParams));
|
||||||
|
|
||||||
|
//Run Script
|
||||||
|
DynValue result = script.Call(script.Globals["onEventUpdate"], objects.ToArray());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<SubPacket> sendError = new List<SubPacket>();
|
||||||
|
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||||
|
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||||
|
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
FFXIVClassic Map Server/lua/LuaNpc.cs
Normal file
27
FFXIVClassic Map Server/lua/LuaNpc.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using FFXIVClassic_Map_Server.Actors;
|
||||||
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
|
using FFXIVClassic_Map_Server.packets.send;
|
||||||
|
using FFXIVClassic_Map_Server.packets.send.events;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FFXIVClassic_Map_Server.lua
|
||||||
|
{
|
||||||
|
|
||||||
|
[MoonSharpUserData]
|
||||||
|
class LuaNpc
|
||||||
|
{
|
||||||
|
private Npc npc;
|
||||||
|
|
||||||
|
public LuaNpc(Npc npc)
|
||||||
|
{
|
||||||
|
this.npc = npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
using FFXIVClassic_Map_Server.dataobjects;
|
using FFXIVClassic_Map_Server.Actors;
|
||||||
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Map_Server.packets.send;
|
using FFXIVClassic_Map_Server.packets.send;
|
||||||
using FFXIVClassic_Map_Server.packets.send.events;
|
using FFXIVClassic_Map_Server.packets.send.events;
|
||||||
using NLua;
|
using MoonSharp.Interpreter;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -10,23 +11,24 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FFXIVClassic_Map_Server.lua
|
namespace FFXIVClassic_Map_Server.lua
|
||||||
{
|
{
|
||||||
|
[MoonSharpUserData]
|
||||||
class LuaPlayer
|
class LuaPlayer
|
||||||
{
|
{
|
||||||
private ConnectedPlayer player;
|
private Player player;
|
||||||
|
|
||||||
public LuaPlayer(ConnectedPlayer player)
|
public LuaPlayer(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMusic(ushort musicID, ushort playMode)
|
public void setMusic(ushort musicID, ushort playMode)
|
||||||
{
|
{
|
||||||
player.queuePacket(SetMusicPacket.buildPacket(player.actorID, musicID, playMode), true, false);
|
player.playerSession.queuePacket(SetMusicPacket.buildPacket(player.actorId, musicID, playMode), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWeather(uint weatherID)
|
public void setWeather(uint weatherID)
|
||||||
{
|
{
|
||||||
player.queuePacket(SetWeatherPacket.buildPacket(player.actorID, weatherID), true, false);
|
player.playerSession.queuePacket(SetWeatherPacket.buildPacket(player.actorId, weatherID), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getParameter(string paramName)
|
public void getParameter(string paramName)
|
||||||
|
@ -51,23 +53,23 @@ namespace FFXIVClassic_Map_Server.lua
|
||||||
|
|
||||||
public void logout()
|
public void logout()
|
||||||
{
|
{
|
||||||
player.queuePacket(LogoutPacket.buildPacket(player.actorID), true, false);
|
player.playerSession.queuePacket(LogoutPacket.buildPacket(player.actorId), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void quitGame()
|
public void quitGame()
|
||||||
{
|
{
|
||||||
player.queuePacket(QuitPacket.buildPacket(player.actorID), true, false);
|
player.playerSession.queuePacket(QuitPacket.buildPacket(player.actorId), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runEvent(string functionName, params object[] parameters)
|
public void runEvent(string functionName, params object[] parameters)
|
||||||
{
|
{
|
||||||
List<LuaParam> lParams = LuaUtils.createLuaParamList(parameters);
|
List<LuaParam> lParams = LuaUtils.createLuaParamList(parameters);
|
||||||
player.queuePacket(RunEventFunctionPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter, functionName, lParams), true, false);
|
// player.playerSession.queuePacket(RunEventFunctionPacket.buildPacket(player.actorId, player.eventCurrentOwner, player.eventCurrentStarter, functionName, lParams), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endEvent()
|
public void endEvent()
|
||||||
{
|
{
|
||||||
player.queuePacket(EndEventPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter), true, false);
|
// player.playerSession.queuePacket(EndEventPacket.buildPacket(player.actorId, player.eventCurrentOwner, player.eventCurrentStarter), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using FFXIVClassic_Map_Server.Actors;
|
using FFXIVClassic_Map_Server.Actors;
|
||||||
using FFXIVClassic_Map_Server.dataobjects;
|
using FFXIVClassic_Map_Server.dataobjects;
|
||||||
using FFXIVClassic_Map_Server.lua;
|
using FFXIVClassic_Map_Server.lua;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -190,6 +191,23 @@ namespace FFXIVClassic_Map_Server
|
||||||
return luaParams;
|
return luaParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<LuaParam> createLuaParamList(DynValue fromScript)
|
||||||
|
{
|
||||||
|
List<LuaParam> luaParams = new List<LuaParam>();
|
||||||
|
|
||||||
|
if (fromScript.Type == DataType.Tuple)
|
||||||
|
{
|
||||||
|
foreach (DynValue d in fromScript.Tuple)
|
||||||
|
{
|
||||||
|
addToList(d, luaParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addToList(fromScript, luaParams);
|
||||||
|
|
||||||
|
return luaParams;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<LuaParam> createLuaParamList(params object[] list)
|
public static List<LuaParam> createLuaParamList(params object[] list)
|
||||||
{
|
{
|
||||||
List<LuaParam> luaParams = new List<LuaParam>();
|
List<LuaParam> luaParams = new List<LuaParam>();
|
||||||
|
@ -209,6 +227,37 @@ namespace FFXIVClassic_Map_Server
|
||||||
return luaParams;
|
return luaParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addToList(DynValue d, List<LuaParam> luaParams)
|
||||||
|
{
|
||||||
|
if (d.Type == DataType.Number)
|
||||||
|
{
|
||||||
|
luaParams.Add(new LuaParam(0x0, (uint)d.Number));
|
||||||
|
}
|
||||||
|
else if (d.Type == DataType.Number)
|
||||||
|
{
|
||||||
|
luaParams.Add(new LuaParam(0x0, (int)d.Number));
|
||||||
|
}
|
||||||
|
else if (d.Type == DataType.String)
|
||||||
|
{
|
||||||
|
luaParams.Add(new LuaParam(0x2, (string)d.String));
|
||||||
|
}
|
||||||
|
else if (d.Type == DataType.Boolean)
|
||||||
|
{
|
||||||
|
if (d.Boolean)
|
||||||
|
luaParams.Add(new LuaParam(0x3, null));
|
||||||
|
else
|
||||||
|
luaParams.Add(new LuaParam(0x4, null));
|
||||||
|
}
|
||||||
|
else if (d.Type == DataType.Nil)
|
||||||
|
{
|
||||||
|
luaParams.Add(new LuaParam(0x5, null));
|
||||||
|
}
|
||||||
|
else if (d.Type == DataType.Table)
|
||||||
|
{
|
||||||
|
//luaParams.Add(new LuaParam(0x6, ((Actor)o).actorId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void addToList(object o, List<LuaParam> luaParams)
|
private static void addToList(object o, List<LuaParam> luaParams)
|
||||||
{
|
{
|
||||||
if (o is uint)
|
if (o is uint)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Cyotek.CircularBuffer" version="1.0.0.0" targetFramework="net45" />
|
<package id="Cyotek.CircularBuffer" version="1.0.0.0" targetFramework="net45" />
|
||||||
<package id="Dapper" version="1.42" targetFramework="net45" />
|
<package id="Dapper" version="1.42" targetFramework="net45" />
|
||||||
|
<package id="MoonSharp" version="1.2.1.0" targetFramework="net45" />
|
||||||
<package id="MySql.Data" version="6.9.7" targetFramework="net45" />
|
<package id="MySql.Data" version="6.9.7" targetFramework="net45" />
|
||||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
||||||
<package id="NLua" version="1.3.2.1" targetFramework="net45" />
|
|
||||||
</packages>
|
</packages>
|
|
@ -23,8 +23,8 @@ namespace FFXIVClassic_Map_Server.packets.send.events
|
||||||
using (BinaryWriter binWriter = new BinaryWriter(mem))
|
using (BinaryWriter binWriter = new BinaryWriter(mem))
|
||||||
{
|
{
|
||||||
binWriter.Write((UInt32)playerActorID);
|
binWriter.Write((UInt32)playerActorID);
|
||||||
binWriter.Write((UInt32)eventOwnerActorID);
|
binWriter.Write((UInt32)0);
|
||||||
binWriter.Write((Byte)0);
|
binWriter.Write((Byte)1);
|
||||||
binWriter.Write(Encoding.ASCII.GetBytes(eventStarter), 0, Encoding.ASCII.GetByteCount(eventStarter) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(eventStarter));
|
binWriter.Write(Encoding.ASCII.GetBytes(eventStarter), 0, Encoding.ASCII.GetByteCount(eventStarter) >= 0x20 ? 0x20 : Encoding.ASCII.GetByteCount(eventStarter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
packages/MoonSharp.1.2.1.0/MoonSharp.1.2.1.0.nupkg
vendored
Normal file
BIN
packages/MoonSharp.1.2.1.0/MoonSharp.1.2.1.0.nupkg
vendored
Normal file
Binary file not shown.
7437
packages/MoonSharp.1.2.1.0/lib/net35-client/MoonSharp.Interpreter.xml
vendored
Normal file
7437
packages/MoonSharp.1.2.1.0/lib/net35-client/MoonSharp.Interpreter.xml
vendored
Normal file
File diff suppressed because it is too large
Load diff
7437
packages/MoonSharp.1.2.1.0/lib/net40-client/MoonSharp.Interpreter.xml
vendored
Normal file
7437
packages/MoonSharp.1.2.1.0/lib/net40-client/MoonSharp.Interpreter.xml
vendored
Normal file
File diff suppressed because it is too large
Load diff
7437
packages/MoonSharp.1.2.1.0/lib/portable-net4+sl5+wp8+win8/MoonSharp.Interpreter.xml
vendored
Normal file
7437
packages/MoonSharp.1.2.1.0/lib/portable-net4+sl5+wp8+win8/MoonSharp.Interpreter.xml
vendored
Normal file
File diff suppressed because it is too large
Load diff
BIN
packages/NLua.1.3.2.1/NLua.1.3.2.1.nupkg
vendored
BIN
packages/NLua.1.3.2.1/NLua.1.3.2.1.nupkg
vendored
Binary file not shown.
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
$nativePath = $(Join-Path $installPath "lib\native\*.*")
|
|
||||||
$LibLuaPostBuildCmd = "
|
|
||||||
xcopy /s /y `"$nativePath`" `"`$(TargetDir)`""
|
|
12
packages/NLua.1.3.2.1/tools/net35/install.ps1
vendored
12
packages/NLua.1.3.2.1/tools/net35/install.ps1
vendored
|
@ -1,12 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
|
|
||||||
# Append our post build command if it's not already there
|
|
||||||
if (!$currentPostBuildCmd.Contains($LibLuaPostBuildCmd)) {
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value += $LibLuaPostBuildCmd
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
# Remove our post build command from it (if it's there)
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($LibLuaPostBuildCmd, "")
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
$nativePath = $(Join-Path $installPath "lib\native\*.*")
|
|
||||||
$LibLuaPostBuildCmd = "
|
|
||||||
xcopy /s /y `"$nativePath`" `"`$(TargetDir)`""
|
|
12
packages/NLua.1.3.2.1/tools/net40/install.ps1
vendored
12
packages/NLua.1.3.2.1/tools/net40/install.ps1
vendored
|
@ -1,12 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
|
|
||||||
# Append our post build command if it's not already there
|
|
||||||
if (!$currentPostBuildCmd.Contains($LibLuaPostBuildCmd)) {
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value += $LibLuaPostBuildCmd
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
# Remove our post build command from it (if it's there)
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($LibLuaPostBuildCmd, "")
|
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
$nativePath = $(Join-Path $installPath "lib\native\*.*")
|
|
||||||
$LibLuaPostBuildCmd = "
|
|
||||||
xcopy /s /y `"$nativePath`" `"`$(TargetDir)`""
|
|
12
packages/NLua.1.3.2.1/tools/net45/install.ps1
vendored
12
packages/NLua.1.3.2.1/tools/net45/install.ps1
vendored
|
@ -1,12 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
|
|
||||||
# Append our post build command if it's not already there
|
|
||||||
if (!$currentPostBuildCmd.Contains($LibLuaPostBuildCmd)) {
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value += $LibLuaPostBuildCmd
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
param($installPath, $toolsPath, $package, $project)
|
|
||||||
|
|
||||||
. (Join-Path $toolsPath "GetLibLuaPostBuildCmd.ps1")
|
|
||||||
|
|
||||||
# Get the current Post Build Event cmd
|
|
||||||
$currentPostBuildCmd = $project.Properties.Item("PostBuildEvent").Value
|
|
||||||
|
|
||||||
# Remove our post build command from it (if it's there)
|
|
||||||
$project.Properties.Item("PostBuildEvent").Value = $currentPostBuildCmd.Replace($LibLuaPostBuildCmd, "")
|
|
Loading…
Add table
Reference in a new issue