1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-21 12:17:46 +00:00

Added command and script packets. Finished the SetActorProperty packet. Fixed bug with manually send packets from console.

This commit is contained in:
Filip Maj 2015-11-27 00:42:35 -05:00
parent ba68546cc9
commit 0a6b005a0c
9 changed files with 198 additions and 43 deletions

View file

@ -38,7 +38,8 @@ namespace FFXIVClassic_Lobby_Server
while (sendPacketQueue.Count > 0) while (sendPacketQueue.Count > 0)
{ {
BasePacket packet = sendPacketQueue.Take(); BasePacket packet = sendPacketQueue.Take();
byte[] packetBytes = packet.getPacketBytes(); byte[] packetBytes = packet.getPacketBytes();
byte[] buffer = new byte[0xffff]; byte[] buffer = new byte[0xffff];
Array.Copy(packetBytes, buffer, packetBytes.Length); Array.Copy(packetBytes, buffer, packetBytes.Length);

View file

@ -76,9 +76,10 @@
<Compile Include="PacketProcessor.cs" /> <Compile Include="PacketProcessor.cs" />
<Compile Include="packets\BasePacket.cs" /> <Compile Include="packets\BasePacket.cs" />
<Compile Include="packets\receive\HandshakePacket.cs" /> <Compile Include="packets\receive\HandshakePacket.cs" />
<Compile Include="packets\receive\script\CommandStartRequestPacket.cs" />
<Compile Include="packets\receive\script\ScriptResultPacket.cs" />
<Compile Include="packets\receive\SetTargetPacket.cs" /> <Compile Include="packets\receive\SetTargetPacket.cs" />
<Compile Include="packets\receive\LockTargetPacket.cs" /> <Compile Include="packets\receive\LockTargetPacket.cs" />
<Compile Include="packets\receive\EndScriptPacket.cs" />
<Compile Include="packets\receive\StartScriptPacket.cs" /> <Compile Include="packets\receive\StartScriptPacket.cs" />
<Compile Include="packets\send\actor\ActorDoEmotePacket.cs" /> <Compile Include="packets\send\actor\ActorDoEmotePacket.cs" />
<Compile Include="packets\send\actor\DeleteAllActorsPacket.cs" /> <Compile Include="packets\send\actor\DeleteAllActorsPacket.cs" />
@ -93,6 +94,7 @@
<Compile Include="packets\send\actor\inventory\EquipmentSetupPacket.cs" /> <Compile Include="packets\send\actor\inventory\EquipmentSetupPacket.cs" />
<Compile Include="packets\send\actor\RemoveActorPacket.cs" /> <Compile Include="packets\send\actor\RemoveActorPacket.cs" />
<Compile Include="packets\send\actor\SetActorNamePacket.cs" /> <Compile Include="packets\send\actor\SetActorNamePacket.cs" />
<Compile Include="packets\send\actor\SetActorPropetyPacket.cs" />
<Compile Include="packets\send\actor\SetActorSpeedPacket.cs" /> <Compile Include="packets\send\actor\SetActorSpeedPacket.cs" />
<Compile Include="packets\send\actor\SetActorStatePacket.cs" /> <Compile Include="packets\send\actor\SetActorStatePacket.cs" />
<Compile Include="packets\send\actor\SetActorTargetAnimatedPacket.cs" /> <Compile Include="packets\send\actor\SetActorTargetAnimatedPacket.cs" />
@ -114,6 +116,8 @@
<Compile Include="packets\send\player\SetPlayerTitlePacket.cs" /> <Compile Include="packets\send\player\SetPlayerTitlePacket.cs" />
<Compile Include="packets\send\PongPacket.cs" /> <Compile Include="packets\send\PongPacket.cs" />
<Compile Include="packets\send\QuitPacket.cs" /> <Compile Include="packets\send\QuitPacket.cs" />
<Compile Include="packets\send\script\ScriptEndPacket.cs" />
<Compile Include="packets\send\script\ScriptStartPacket.cs" />
<Compile Include="packets\send\SendMessagePacket.cs" /> <Compile Include="packets\send\SendMessagePacket.cs" />
<Compile Include="packets\send\SetMapPacket.cs" /> <Compile Include="packets\send\SetMapPacket.cs" />
<Compile Include="packets\send\SetMusicPacket.cs" /> <Compile Include="packets\send\SetMusicPacket.cs" />
@ -123,6 +127,7 @@
<Compile Include="packets\receive\UpdatePlayerPositionPacket.cs" /> <Compile Include="packets\receive\UpdatePlayerPositionPacket.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScriptParamReader.cs" />
<Compile Include="Server.cs" /> <Compile Include="Server.cs" />
<Compile Include="Zone.cs" /> <Compile Include="Zone.cs" />
</ItemGroup> </ItemGroup>
@ -130,9 +135,7 @@
<None Include="App.config" /> <None Include="App.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="packets\send\script\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.

View file

@ -18,6 +18,7 @@ using FFXIVClassic_Map_Server.packets.send.Actor.inventory;
using FFXIVClassic_Map_Server.packets.send.Actor; using FFXIVClassic_Map_Server.packets.send.Actor;
using FFXIVClassic_Map_Server.packets.send.actor; using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server; using FFXIVClassic_Map_Server;
using FFXIVClassic_Map_Server.packets.send.script;
namespace FFXIVClassic_Lobby_Server namespace FFXIVClassic_Lobby_Server
{ {
@ -263,6 +264,9 @@ namespace FFXIVClassic_Lobby_Server
case 0x0003: case 0x0003:
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
break; break;
//Unknown
case 0x0007:
break;
//Update Position //Update Position
case 0x00CA: case 0x00CA:
//Update Position //Update Position
@ -291,14 +295,14 @@ namespace FFXIVClassic_Lobby_Server
//Start Script //Start Script
case 0x012D: case 0x012D:
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
//StartScriptPacket startScript = new StartScriptPacket(subpacket.data); CommandStartRequestPacket commandStart = new CommandStartRequestPacket(subpacket.data);
//client.queuePacket(new BasePacket("./packets/script/bed.bin"));
client.queuePacket(BasePacket.createPacket(ActorDoEmotePacket.buildPacket(player.actorID, player.getActor().currentTarget, 137), true, false)); client.queuePacket(BasePacket.createPacket(ActorDoEmotePacket.buildPacket(player.actorID, player.getActor().currentTarget, 137), true, false));
break; break;
//Script Result //Script Result
case 0x012E: case 0x012E:
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
processScriptResult(subpacket); ScriptResultPacket scriptResult = new ScriptResultPacket(subpacket.data);
break; break;
case 0x012F: case 0x012F:
subpacket.debugPrintSubPacket(); subpacket.debugPrintSubPacket();
@ -311,16 +315,12 @@ namespace FFXIVClassic_Lobby_Server
} }
} }
} }
} }
public void sendPacket(string path, int conn) public void sendPacket(string path, int conn)
{ {
if (mPlayers.Count == 0)
return;
BasePacket packet = new BasePacket(path); BasePacket packet = new BasePacket(path);
foreach (KeyValuePair<uint, Player> entry in mPlayers) foreach (KeyValuePair<uint, Player> entry in mPlayers)
{ {
packet.replaceActorID(entry.Value.actorID); packet.replaceActorID(entry.Value.actorID);

View file

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server
{
class ScriptParamReader
{
List<int> types = new List<int>();
List<Object> values = new List<Object>();
public ScriptParamReader(BinaryReader reader)
{
while (true)
{
byte code = reader.ReadByte();
switch (code)
{
case 0x0: //INT32
types.Add(6);
values.Add(reader.ReadUInt32());
break;
case 0x1: //????
continue;
case 0x2: //Null Termed String
types.Add(2);
List<byte> list = new List<byte>();
while(true){
byte readByte = reader.ReadByte();
if (readByte == 0)
break;
list.Add(readByte);
}
values.Add(Encoding.ASCII.GetString(list.ToArray()));
break;
case 0x4: //BYTE
types.Add(4);
values.Add(reader.ReadByte());
break;
case 0x5: //NULL???
types.Add(5);
values.Add(new Object());
continue;
case 0x6: //INT32
types.Add(6);
values.Add(reader.ReadUInt32());
break;
case 0xF: //End
return;
}
}
}
public int getType(int index)
{
return types[index];
}
public Object getValue(int index)
{
return values[index];
}
public int getCount()
{
return values.Count;
}
}
}

View file

@ -53,7 +53,70 @@ namespace FFXIVClassic_Lobby_Server.common
DateTime unixEpoch = new DateTime(1970, 1, 1); DateTime unixEpoch = new DateTime(1970, 1, 1);
unixTimeStamp = (UInt32)(zuluTime.Subtract(unixEpoch)).TotalSeconds; unixTimeStamp = (UInt32)(zuluTime.Subtract(unixEpoch)).TotalSeconds;
return unixTimeStamp; return 0x55555555;
//return unixTimeStamp;
}
public static uint MurmurHash2(string key, uint seed)
{
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
byte[] data = Encoding.ASCII.GetBytes(key);
const uint m = 0x5bd1e995;
const int r = 24;
int len = key.Length;
int dataIndex = len - 4;
// Initialize the hash to a 'random' value
uint h = seed ^ (uint)len;
// Mix 4 bytes at a time into the hash
while (len >= 4)
{
h *= m;
uint k = (uint)BitConverter.ToInt32(data, dataIndex);
k = ((k >> 24) & 0xff) | // move byte 3 to byte 0
((k << 8) & 0xff0000) | // move byte 1 to byte 2
((k >> 8) & 0xff00) | // move byte 2 to byte 1
((k << 24) & 0xff000000); // byte 0 to byte 3
k *= m;
k ^= k >> r;
k *= m;
h ^= k;
dataIndex -= 4;
len -= 4;
}
// Handle the last few bytes of the input array
switch (len)
{
case 3:
h ^= (uint)data[2] << 16; goto case 2;
case 2:
h ^= (uint)data[0] << 8; goto case 1;
case 1:
h ^= data[1];
h *= m;
break;
};
// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
} }
} }

View file

@ -71,7 +71,7 @@ namespace FFXIVClassic_Map_Server.dataobjects
public ClientConnection getConnection2() public ClientConnection getConnection2()
{ {
return conn1; return conn2;
} }
public Actor getActor() public Actor getActor()
@ -136,7 +136,8 @@ namespace FFXIVClassic_Map_Server.dataobjects
} }
} }
basePackets.Add(BasePacket.createPacket(posUpdateSubpackets, true, false)); if (posUpdateSubpackets.Count > 0)
basePackets.Add(BasePacket.createPacket(posUpdateSubpackets, true, false));
return basePackets; return basePackets;
} }

View file

@ -9,13 +9,16 @@ namespace FFXIVClassic_Map_Server.packets.send.script
{ {
class CommandStartRequestPacket class CommandStartRequestPacket
{ {
bool invalidPacket = false; public const ushort OPCODE = 0x012E;
public const uint PACKET_SIZE = 0x78;
public bool invalidPacket = false;
public uint actorID; public uint actorID;
public uint scriptOwnerActorID; public uint scriptOwnerActorID;
public uint val1; public uint val1;
public uint val2; public uint val2;
public string callbackName; public ScriptParamReader reader;
public CommandStartRequestPacket(byte[] data) public CommandStartRequestPacket(byte[] data)
{ {
@ -30,14 +33,8 @@ namespace FFXIVClassic_Map_Server.packets.send.script
val2 = binReader.ReadUInt32(); val2 = binReader.ReadUInt32();
binReader.ReadByte(); binReader.ReadByte();
while (true) binReader.BaseStream.Seek(0x31, SeekOrigin.Begin);
{ reader = new ScriptParamReader(binReader);
byte inByte = binReader.ReadByte();
if (inByte == 0)
break;
callbackName += (char)inByte;
}
} }
catch (Exception){ catch (Exception){
invalidPacket = true; invalidPacket = true;

View file

@ -9,14 +9,16 @@ namespace FFXIVClassic_Map_Server.packets.send.script
{ {
class ScriptResultPacket class ScriptResultPacket
{ {
bool invalidPacket = false; public const ushort OPCODE = 0x012E;
public const uint PACKET_SIZE = 0xD8;
public bool invalidPacket = false;
public uint actorID; public uint actorID;
public uint scriptOwnerActorID;
public uint val1; public uint val1;
public uint val2; public uint val2;
public uint val3; ScriptParamReader reader;
public uint val4;
public uint val5;
public ScriptResultPacket(byte[] data) public ScriptResultPacket(byte[] data)
{ {
@ -26,11 +28,11 @@ namespace FFXIVClassic_Map_Server.packets.send.script
{ {
try{ try{
actorID = binReader.ReadUInt32(); actorID = binReader.ReadUInt32();
scriptOwnerActorID = binReader.ReadUInt32();
val1 = binReader.ReadUInt32(); val1 = binReader.ReadUInt32();
val2 = binReader.ReadUInt32(); val2 = binReader.ReadUInt32();
val3 = binReader.ReadUInt32(); binReader.ReadByte();
val4 = binReader.ReadUInt32(); reader = new ScriptParamReader(binReader);
val5 = binReader.ReadUInt32();
} }
catch (Exception){ catch (Exception){
invalidPacket = true; invalidPacket = true;

View file

@ -66,14 +66,12 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
private ushort runningByteTotal = 0; private ushort runningByteTotal = 0;
private byte[] data = new byte[PACKET_SIZE - 0x20]; private byte[] data = new byte[PACKET_SIZE - 0x20];
private string script;
private MemoryStream mem; private MemoryStream mem;
private BinaryWriter binWriter; private BinaryWriter binWriter;
public SetActorPropetyPacket(string script) public SetActorPropetyPacket()
{ {
this.script = script;
mem = new MemoryStream(data); mem = new MemoryStream(data);
binWriter = new BinaryWriter(mem); binWriter = new BinaryWriter(mem);
binWriter.Seek(1, SeekOrigin.Begin); binWriter.Seek(1, SeekOrigin.Begin);
@ -87,7 +85,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
public bool addByte(uint id, byte value) public bool addByte(uint id, byte value)
{ {
if (runningByteTotal + 6 + Encoding.ASCII.GetByteCount(script) > MAXBYTES) if (runningByteTotal + 6 > MAXBYTES)
return false; return false;
binWriter.Write((byte)1); binWriter.Write((byte)1);
@ -100,7 +98,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
public bool addShort(uint id, ushort value) public bool addShort(uint id, ushort value)
{ {
if (runningByteTotal + 7 + Encoding.ASCII.GetByteCount(script) > MAXBYTES) if (runningByteTotal + 7 > MAXBYTES)
return false; return false;
binWriter.Write((byte)2); binWriter.Write((byte)2);
@ -113,7 +111,7 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
public bool addInt(uint id, uint value) public bool addInt(uint id, uint value)
{ {
if (runningByteTotal + 9 + Encoding.ASCII.GetByteCount(script) > MAXBYTES) if (runningByteTotal + 9 > MAXBYTES)
return false; return false;
binWriter.Write((byte)4); binWriter.Write((byte)4);
@ -124,11 +122,29 @@ namespace FFXIVClassic_Map_Server.packets.send.actor
return true; return true;
} }
public bool addBuffer(uint id, byte[] buffer)
{
if (runningByteTotal + 5 + buffer.Length > MAXBYTES)
return false;
binWriter.Write((byte)buffer.Length);
binWriter.Write((UInt32)id);
binWriter.Write(buffer);
runningByteTotal += (ushort)(5 + buffer.Length);
return true;
}
public void setTarget(string target)
{
binWriter.Write((byte)(0x82 + target.Length));
binWriter.Write(target);
runningByteTotal += (ushort)(1 + target.Length);
}
public SubPacket buildPacket(uint playerActorID, uint actorID) public SubPacket buildPacket(uint playerActorID, uint actorID)
{ {
binWriter.Write((ushort)00);
binWriter.Write(Encoding.ASCII.GetBytes(script));
binWriter.Seek(0, SeekOrigin.Begin); binWriter.Seek(0, SeekOrigin.Begin);
binWriter.Write((byte)runningByteTotal); binWriter.Write((byte)runningByteTotal);