Let ServerPacket Handle the writting of packet data.

This commit is contained in:
hondacrx
2017-07-06 11:01:31 -04:00
parent a6b30c73e4
commit 210a2958ff
18 changed files with 73 additions and 80 deletions
+31 -14
View File
@@ -29,13 +29,13 @@ namespace Game.Network
_worldPacket = worldPacket;
}
public abstract void Read();
public void Dispose()
{
_worldPacket.Dispose();
}
public abstract void Read();
public ClientOpcodes GetOpcode() { return (ClientOpcodes)_worldPacket.GetOpcode(); }
public void LogPacket(WorldSession session)
@@ -46,7 +46,7 @@ namespace Game.Network
protected WorldPacket _worldPacket;
}
public abstract class ServerPacket : IDisposable
public abstract class ServerPacket
{
public ServerPacket(ServerOpcodes opcode)
{
@@ -60,15 +60,21 @@ namespace Game.Network
_worldPacket = new WorldPacket(opcode);
}
public void Dispose()
public void Clear()
{
_worldPacket.Dispose();
_worldPacket.Clear();
buffer = null;
}
public void Clear() { _worldPacket.Clear(); }
public ServerOpcodes GetOpcode() { return (ServerOpcodes)_worldPacket.GetOpcode(); }
public uint GetSize() { return _worldPacket.GetSize(); }
public byte[] GetData() { return _worldPacket.GetData(); }
public ServerOpcodes GetOpcode()
{
return (ServerOpcodes)_worldPacket.GetOpcode();
}
public byte[] GetData()
{
return buffer;
}
public void LogPacket(WorldSession session)
{
@@ -77,10 +83,21 @@ namespace Game.Network
public abstract void Write();
public void WritePacketData()
{
if (buffer != null)
return;
Write();
buffer = _worldPacket.GetData();
_worldPacket.Dispose();
}
public ConnectionType GetConnection() { return connectionType; }
byte[] buffer;
ConnectionType connectionType;
protected WorldPacket _worldPacket;
}
@@ -88,12 +105,12 @@ namespace Game.Network
{
public WorldPacket(ServerOpcodes opcode = ServerOpcodes.None)
{
Opcode = (uint)opcode;
this.opcode = (uint)opcode;
}
public WorldPacket(byte[] data, uint opcode) : base(data)
{
Opcode = opcode;
this.opcode = opcode;
}
public ObjectGuid ReadPackedGuid()
@@ -201,9 +218,9 @@ namespace Game.Network
WriteFloat(o);
}
public uint GetOpcode() { return Opcode; }
public uint GetOpcode() { return opcode; }
uint Opcode;
uint opcode;
}
public class ServerPacketHeader
+5 -8
View File
@@ -250,21 +250,18 @@ namespace Game.Network
return true;
}
public void SendPacket(ServerPacket packet, bool writePacket = true)
public void SendPacket(ServerPacket packet)
{
if (!IsOpen())
return;
packet.LogPacket(_worldSession);
if (writePacket)
packet.Write();
uint packetSize = packet.GetSize();
ServerOpcodes opcode = packet.GetOpcode();
packet.WritePacketData();
var data = packet.GetData();
packet.Dispose();
uint packetSize = (uint)data.Length;
ServerOpcodes opcode = packet.GetOpcode();
PacketLog.Write(data, opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType);
if (packetSize > 0x400 && worldCrypt.IsInitialized)
@@ -602,7 +599,7 @@ namespace Game.Network
//else
//{
// transfer_aborted when/if we get map node redirection
// SendPacket(*WorldPackets.Auth.ResumeComms().Write());
// SendPacket(*WorldPackets.Auth.ResumeComms());
//}
}