1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-20 11:47:48 +00:00

Added more packet creators to the actor class. Made sendPacketQueue private to avoid confusion. Added zone stuff to test multiplayer.

This commit is contained in:
Filip Maj 2015-10-13 19:15:44 -04:00
parent 28b868e421
commit b17a86ba2c
6 changed files with 225 additions and 38 deletions

View file

@ -21,7 +21,7 @@ namespace FFXIVClassic_Lobby_Server
public Socket socket;
public byte[] buffer = new byte[0xffff];
public CircularBuffer<byte> incomingStream = new CircularBuffer<byte>(1024);
public BlockingCollection<BasePacket> sendPacketQueue = new BlockingCollection<BasePacket>(100);
private BlockingCollection<BasePacket> sendPacketQueue = new BlockingCollection<BasePacket>(100);
//Instance Stuff
public uint owner = 0;
@ -68,6 +68,7 @@ namespace FFXIVClassic_Lobby_Server
public void disconnect()
{
if (socket.Connected)
socket.Disconnect(false);
}
}

View file

@ -82,6 +82,7 @@
<Compile Include="packets\receive\StartScriptPacket.cs" />
<Compile Include="packets\send\actor\ActorDoEmotePacket.cs" />
<Compile Include="packets\send\actor\DeleteAllActorsPacket.cs" />
<Compile Include="packets\send\actor\DoBattleActionPacket.cs" />
<Compile Include="packets\send\actor\inventory\EquipmentChangePacket.cs" />
<Compile Include="packets\send\actor\inventory\InventoryBeginChangePacket.cs" />
<Compile Include="packets\send\actor\inventory\InventoryEndChangePacket.cs" />
@ -113,6 +114,7 @@
<Compile Include="packets\send\player\SetPlayerTitlePacket.cs" />
<Compile Include="packets\send\PongPacket.cs" />
<Compile Include="packets\send\QuitPacket.cs" />
<Compile Include="packets\send\SendMessagePacket.cs" />
<Compile Include="packets\send\SetMapPacket.cs" />
<Compile Include="packets\send\SetMusicPacket.cs" />
<Compile Include="packets\send\SetWeatherPacket.cs" />
@ -122,6 +124,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
<Compile Include="Zone.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View file

@ -17,6 +17,7 @@ using FFXIVClassic_Map_Server.packets.send.login;
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;
namespace FFXIVClassic_Lobby_Server
{
@ -26,6 +27,8 @@ namespace FFXIVClassic_Lobby_Server
List<ClientConnection> mConnections;
Boolean isAlive = true;
Zone inn = new Zone();
public PacketProcessor(Dictionary<uint, Player> playerList, List<ClientConnection> connectionList)
{
mPlayers = playerList;
@ -64,7 +67,7 @@ namespace FFXIVClassic_Lobby_Server
}
//Send packets
if (conn != null && conn.sendPacketQueue.Count != 0)
if (conn != null)
conn.flushQueuedSendPackets();
}
}
@ -110,8 +113,8 @@ namespace FFXIVClassic_Lobby_Server
}
}
client.sendPacketQueue.Add(init);
client.sendPacketQueue.Add(reply2);
client.queuePacket(init);
client.queuePacket(reply2);
break;
}
@ -295,6 +298,9 @@ namespace FFXIVClassic_Lobby_Server
client.queuePacket(reply10);
//client.queuePacket(reply11);
client.queuePacket(reply12);
inn.addActorToZone(player.getActor());
break;
//Chat Received
case 0x0003:
@ -304,26 +310,31 @@ namespace FFXIVClassic_Lobby_Server
case 0x00CA:
UpdatePlayerPositionPacket posUpdate = new UpdatePlayerPositionPacket(subpacket.data);
player.updatePlayerActorPosition(posUpdate.x, posUpdate.y, posUpdate.z, posUpdate.rot, posUpdate.moveState);
List<BasePacket> instanceUpdatePackets = player.updateInstance(inn.getActorsAroundActor(player.getActor(), 50));
foreach (BasePacket bp in instanceUpdatePackets)
client.queuePacket(bp);
break;
//Set Target
case 0x00CD:
subpacket.debugPrintSubPacket();
SetTargetPacket setTarget = new SetTargetPacket(subpacket.data);
player.setTarget(setTarget.actorID);
player.getActor().currentTarget = setTarget.actorID;
client.queuePacket(BasePacket.createPacket(SetActorTargetAnimatedPacket.buildPacket(player.actorID, player.actorID, setTarget.actorID), true, false));
break;
//Lock Target
case 0x00CC:
LockTargetPacket lockTarget = new LockTargetPacket(subpacket.data);
player.setLockedTarget(lockTarget.actorID);
player.getActor().currentLockedTarget = lockTarget.actorID;
break;
//Start Script
case 0x012D:
subpacket.debugPrintSubPacket();
//StartScriptPacket startScript = new StartScriptPacket(subpacket.data);
//client.queuePacket(new BasePacket("./packets/script/bed.bin"));
client.queuePacket(BasePacket.createPacket(ActorDoEmotePacket.buildPacket(player.actorID, player.getTargetedActor(), 137), true, false));
client.queuePacket(BasePacket.createPacket(ActorDoEmotePacket.buildPacket(player.actorID, player.getActor().currentTarget, 137), true, false));
break;
//Script Result
case 0x012E:
@ -354,9 +365,9 @@ namespace FFXIVClassic_Lobby_Server
{
packet.replaceActorID(entry.Value.actorID);
if (conn == 1 || conn == 3)
entry.Value.getConnection1().sendPacketQueue.Add(packet);
entry.Value.getConnection1().queuePacket(packet);
if (conn == 2 || conn == 3)
entry.Value.getConnection2().sendPacketQueue.Add(packet);
entry.Value.getConnection2().queuePacket(packet);
}
}

View file

@ -10,17 +10,45 @@ namespace FFXIVClassic_Map_Server
class Zone
{
public uint mapId;
public ushort weatherNormal, weatherCommon, weatherRare;
public ushort bgmDay, bgmNight, bgmBattle;
public int boundingGridSize = 200;
public int minX = -1000, minY = -1000, maxX = 1000, maxY = 1000;
private int numXBlocks, numYBlocks;
private int halfWidth, halfHeight;
private List<Actor>[,] actorBlock;
private Dictionary<Tuple<int, int>, List<Actor>> actorBlock = new Dictionary<Tuple<int, int>, List<Actor>>();
public Zone()
{
numXBlocks = (maxX - minX) / boundingGridSize;
numYBlocks = (maxY - minY) / boundingGridSize;
actorBlock = new List<Actor>[numXBlocks, numYBlocks];
halfWidth = numXBlocks / 2;
halfHeight = numYBlocks / 2;
}
#region Actor Management
public void addActorToZone(Actor actor)
{
int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionY / boundingGridSize;
gridX += halfWidth;
gridY += halfHeight;
//Boundries
if (gridX < 0)
gridX = 0;
if (gridX >= numXBlocks)
gridX = numXBlocks - 1;
if (gridY < 0)
gridY = 0;
if (gridY >= numYBlocks)
gridY = numYBlocks - 1;
lock (actorBlock)
actorBlock[Tuple.Create(gridX, gridY)].Add(actor);
actorBlock[gridX, gridY].Add(actor);
}
public void removeActorToZone(Actor actor)
@ -28,8 +56,21 @@ namespace FFXIVClassic_Map_Server
int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionY / boundingGridSize;
gridX += halfWidth;
gridY += halfHeight;
//Boundries
if (gridX < 0)
gridX = 0;
if (gridX >= numXBlocks)
gridX = numXBlocks - 1;
if (gridY < 0)
gridY = 0;
if (gridY >= numYBlocks)
gridY = numYBlocks - 1;
lock (actorBlock)
actorBlock[Tuple.Create(gridX, gridY)].Remove(actor);
actorBlock[gridX, gridY].Remove(actor);
}
public void updateActorPosition(Actor actor)
@ -37,17 +78,43 @@ namespace FFXIVClassic_Map_Server
int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionY / boundingGridSize;
gridX += halfWidth;
gridY += halfHeight;
//Boundries
if (gridX < 0)
gridX = 0;
if (gridX >= numXBlocks)
gridX = numXBlocks - 1;
if (gridY < 0)
gridY = 0;
if (gridY >= numYBlocks)
gridY = numYBlocks - 1;
int gridOldX = (int)actor.oldPositionX / boundingGridSize;
int gridOldY = (int)actor.oldPositionY / boundingGridSize;
gridOldX += halfWidth;
gridOldY += halfHeight;
//Boundries
if (gridOldX < 0)
gridOldX = 0;
if (gridOldX >= numXBlocks)
gridOldX = numXBlocks - 1;
if (gridOldY < 0)
gridOldY = 0;
if (gridOldY >= numYBlocks)
gridOldY = numYBlocks - 1;
//Still in same block
if (gridX == gridOldX && gridY == gridOldY)
return;
lock (actorBlock)
actorBlock[Tuple.Create(gridOldX, gridOldY)].Remove(actor);
actorBlock[gridOldX, gridOldY].Remove(actor);
lock (actorBlock)
actorBlock[Tuple.Create(gridX, gridY)].Add(actor);
actorBlock[gridX, gridY].Add(actor);
}
public List<Actor> getActorsAroundPoint(float x, float y, int checkDistance)
@ -55,18 +122,63 @@ namespace FFXIVClassic_Map_Server
int gridX = (int)x/boundingGridSize;
int gridY = (int)y/boundingGridSize;
gridX += halfWidth;
gridY += halfHeight;
//Boundries
if (gridX < 0)
gridX = 0;
if (gridX >= numXBlocks)
gridX = numXBlocks - 1;
if (gridY < 0)
gridY = 0;
if (gridY >= numYBlocks)
gridY = numYBlocks - 1;
List<Actor> result = new List<Actor>();
for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++)
{
for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++)
{
result.AddRange(actorBlock[Tuple.Create(gx, gy)]);
result.AddRange(actorBlock[gx, gy]);
}
}
return result;
}
public List<Actor> getActorsAroundActor(Actor actor, int checkDistance)
{
int gridX = (int)actor.positionX / boundingGridSize;
int gridY = (int)actor.positionY / boundingGridSize;
gridX += halfWidth;
gridY += halfHeight;
//Boundries
if (gridX < 0)
gridX = 0;
if (gridX >= numXBlocks)
gridX = numXBlocks - 1;
if (gridY < 0)
gridY = 0;
if (gridY >= numYBlocks)
gridY = numYBlocks - 1;
List<Actor> result = new List<Actor>();
for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++)
{
for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++)
{
result.AddRange(actorBlock[gx, gy]);
}
}
return result;
}
#endregion
}
}

View file

@ -41,16 +41,41 @@ namespace FFXIVClassic_Map_Server.dataobjects
public uint actorID;
public uint displayNameID;
public bool isNameplateVisible;
public bool isTargetable;
public uint displayNameID = 0xFFFFFFFF;
public string customDisplayName;
public uint nameplateIcon;
public uint modelID;
public uint[] appearanceIDs = new uint[0x1D];
public float positionX, positionY, positionZ;
public float oldPositionX, oldPositionY, oldPositionZ;
public float rotation;
public ushort moveState;
public uint currentTarget = 0xC0000000;
public uint currentLockedTarget = 0xC0000000;
public float positionX, positionY, positionZ, rotation;
public float oldPositionX, oldPositionY, oldPositionZ, oldRotation;
public ushort moveState, oldMoveState;
public uint currentState = SetActorStatePacket.STATE_PASSIVE;
public uint currentZoneID;
//Properties
public ushort curHP, curMP, curTP;
public ushort maxHP, maxMP, maxTP;
public byte currentJob;
public ushort currentLevel;
public ushort statSTR, statVIT, statDEX, statINT, statMIN, statPIE;
public ushort statAttack, statDefense, statAccuracy, statAttackMgkPotency, statHealingMgkPotency, statEnchancementMgkPotency, statEnfeeblingMgkPotency, statMgkAccuracy, statMgkEvasion;
public ushort resistFire, resistIce, resistWind, resistEarth, resistLightning, resistWater;
public uint currentEXP;
public ushort linkshellcrest;
public Actor(uint id)
{
@ -94,7 +119,7 @@ namespace FFXIVClassic_Map_Server.dataobjects
public SubPacket createStatePacket(uint playerActorID)
{
return SetActorStatePacket.buildPacket(playerActorID, actorID, SetActorStatePacket.STATE_PASSIVE);
return SetActorStatePacket.buildPacket(playerActorID, actorID, currentState);
}
public SubPacket createSpeedPacket(uint playerActorID)
@ -102,5 +127,33 @@ namespace FFXIVClassic_Map_Server.dataobjects
return SetActorSpeedPacket.buildPacket(playerActorID, actorID);
}
public SubPacket createSpawnPositonPacket(uint playerActorID, uint spawnType)
{
return SetActorPositionPacket.buildPacket(playerActorID, actorID, positionX, positionY, positionZ, rotation, spawnType);
}
public SubPacket createPositionUpdatePacket(uint playerActorID)
{
return MoveActorToPositionPacket.buildPacket(playerActorID, actorID, positionX, positionY, positionZ, rotation, moveState);
}
public SubPacket createScriptBindPacket(uint playerActorID)
{
return null;
}
public BasePacket createActorSpawnPackets(uint playerActorID)
{
List<SubPacket> subpackets = new List<SubPacket>();
subpackets.Add(AddActorPacket.buildPacket(playerActorID, actorID));
subpackets.Add(createSpeedPacket(playerActorID));
subpackets.Add(createSpawnPositonPacket(playerActorID, 0));
subpackets.Add(createAppearancePacket(playerActorID));
subpackets.Add(createNamePacket(playerActorID));
subpackets.Add(createStatePacket(playerActorID));
subpackets.Add(createScriptBindPacket(playerActorID));
return BasePacket.createPacket(subpackets, true, false);
}
}
}

View file

@ -1,5 +1,7 @@
using FFXIVClassic_Lobby_Server;
using FFXIVClassic_Lobby_Server.dataobjects;
using FFXIVClassic_Lobby_Server.packets;
using FFXIVClassic_Map_Server.packets.send.actor;
using System;
using System.Collections.Generic;
using System.Linq;
@ -15,12 +17,8 @@ namespace FFXIVClassic_Map_Server.dataobjects
ClientConnection conn1;
ClientConnection conn2;
public uint characterID = 0;
public uint actorID = 0;
private uint currentTarget = 0xC0000000;
private uint currentLockedTarget = 0xC0000000;
private uint currentZoneID = 0;
List<Actor> actorInstanceList = new List<Actor>();
@ -112,19 +110,28 @@ namespace FFXIVClassic_Map_Server.dataobjects
}
public void setTarget(uint actorID)
public List<BasePacket> updateInstance(List<Actor> list)
{
currentTarget = actorID;
List<BasePacket> basePackets = new List<BasePacket>();
List<SubPacket> posUpdateSubpackets = new List<SubPacket>();
for (int i = 0; i < list.Count; i++)
{
Actor actor = list[i];
if (actor.actorID == playerActor.actorID)
continue;
if (actorInstanceList.Contains(actor))
posUpdateSubpackets.Add(actor.createPositionUpdatePacket(playerActor.actorID));
else
basePackets.Add(actor.createActorSpawnPackets(playerActor.actorID));
}
public void setLockedTarget(uint actorID)
{
currentLockedTarget = actorID;
}
basePackets.Add(BasePacket.createPacket(posUpdateSubpackets, true, false));
public uint getTargetedActor()
{
return currentTarget;
return basePackets;
}
}
}