Core/Network: Changed AsyncAcceptor to have a start method that returns false if it can't start the network.
Core/Logging: Cleaned up network logging.
This commit is contained in:
@@ -49,7 +49,7 @@ public class PacketLog
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(byte[] data, ClientOpcodes opcode, IPAddress address, uint port, ConnectionType connectionType)
|
||||
public static void Write(byte[] data, uint opcode, IPAddress address, uint port, ConnectionType connectionType, bool isClientPacket)
|
||||
{
|
||||
if (!CanLog())
|
||||
return;
|
||||
@@ -58,7 +58,7 @@ public class PacketLog
|
||||
{
|
||||
using (var writer = new BinaryWriter(File.Open(FullPath, FileMode.Append), Encoding.ASCII))
|
||||
{
|
||||
writer.Write("CMSG".ToCharArray());
|
||||
writer.Write(isClientPacket ? 0x47534d43 : 0x47534d53);
|
||||
writer.Write((uint)connectionType);
|
||||
writer.Write(Time.GetMSTime());
|
||||
|
||||
@@ -72,36 +72,7 @@ public class PacketLog
|
||||
writer.Write(data.Length + 4);
|
||||
writer.Write(SocketIPBytes);
|
||||
writer.Write(port);
|
||||
writer.Write((uint)opcode);
|
||||
writer.Write(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(byte[] data, ServerOpcodes opcode, IPAddress address, uint port, ConnectionType connectionType)
|
||||
{
|
||||
if (!CanLog())
|
||||
return;
|
||||
|
||||
lock (syncObj)
|
||||
{
|
||||
using (var writer = new BinaryWriter(File.Open(FullPath, FileMode.Append), Encoding.ASCII))
|
||||
{
|
||||
writer.Write("SMSG".ToCharArray());
|
||||
writer.Write((uint)connectionType);
|
||||
writer.Write(Time.GetMSTime());
|
||||
|
||||
writer.Write(20);
|
||||
byte[] SocketIPBytes = new byte[16];
|
||||
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
Buffer.BlockCopy(address.GetAddressBytes(), 0, SocketIPBytes, 0, 4);
|
||||
else
|
||||
Buffer.BlockCopy(address.GetAddressBytes(), 0, SocketIPBytes, 0, 16);
|
||||
|
||||
writer.Write(data.Length + 4);
|
||||
writer.Write(SocketIPBytes);
|
||||
writer.Write(port);
|
||||
writer.Write((uint)opcode);
|
||||
writer.Write(opcode);
|
||||
writer.Write(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +161,8 @@ namespace Game.Network
|
||||
|
||||
var data = new byte[size];
|
||||
Buffer.BlockCopy(GetReceiveBuffer(), 6, data, 0, size);
|
||||
|
||||
PacketLog.Write(data, opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType, true);
|
||||
if (!ProcessPacket(new WorldPacket(data, opcode)))
|
||||
{
|
||||
CloseSocket();
|
||||
@@ -191,7 +193,6 @@ namespace Game.Network
|
||||
bool ProcessPacket(WorldPacket packet)
|
||||
{
|
||||
ClientOpcodes opcode = (ClientOpcodes)packet.GetOpcode();
|
||||
PacketLog.Write(packet.GetData(), opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -272,14 +273,13 @@ namespace Game.Network
|
||||
return;
|
||||
|
||||
packet.LogPacket(_worldSession);
|
||||
|
||||
packet.WritePacketData();
|
||||
|
||||
var data = packet.GetData();
|
||||
uint packetSize = (uint)data.Length;
|
||||
ServerOpcodes opcode = packet.GetOpcode();
|
||||
PacketLog.Write(data, opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType);
|
||||
PacketLog.Write(data, (uint)opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType, false);
|
||||
|
||||
uint packetSize = (uint)data.Length;
|
||||
if (packetSize > 0x400 && worldCrypt.IsInitialized)
|
||||
{
|
||||
ByteBuffer buffer = new ByteBuffer();
|
||||
@@ -398,6 +398,7 @@ namespace Game.Network
|
||||
hmac.Process(_serverChallenge, 16);
|
||||
hmac.Finish(AuthCheckSeed, 16);
|
||||
|
||||
|
||||
// Check that Key and account name are the same on client and server
|
||||
if (!hmac.Digest.Compare(authSession.Digest))
|
||||
{
|
||||
@@ -406,6 +407,7 @@ namespace Game.Network
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Sha256 keyData = new Sha256();
|
||||
keyData.Finish(account.game.SessionKey, account.game.SessionKey.Length);
|
||||
|
||||
|
||||
@@ -36,7 +36,13 @@ namespace Game.Network
|
||||
if (!base.StartNetwork(bindIp, port, threadCount))
|
||||
return false;
|
||||
|
||||
_instanceAcceptor = new AsyncAcceptor(bindIp, WorldConfig.GetIntValue(WorldCfg.PortInstance));
|
||||
_instanceAcceptor = new AsyncAcceptor();
|
||||
if (!_instanceAcceptor.Start(bindIp, WorldConfig.GetIntValue(WorldCfg.PortInstance)))
|
||||
{
|
||||
Log.outError(LogFilter.Network, "StartNetwork failed to start instance AsyncAcceptor");
|
||||
return false;
|
||||
}
|
||||
|
||||
_instanceAcceptor.AsyncAcceptSocket(OnSocketOpen);
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user