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:
@@ -25,13 +25,13 @@ namespace Framework.Networking
|
||||
|
||||
public class AsyncAcceptor
|
||||
{
|
||||
public AsyncAcceptor(string ip, int port)
|
||||
public bool Start(string ip, int port)
|
||||
{
|
||||
var bindIP = IPAddress.None;
|
||||
IPAddress bindIP;
|
||||
if (!IPAddress.TryParse(ip, out bindIP))
|
||||
{
|
||||
Log.outError(LogFilter.Network, "Server can't be started: Invalid IP-Address ({0})", ip);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -42,7 +42,10 @@ namespace Framework.Networking
|
||||
catch (SocketException ex)
|
||||
{
|
||||
Log.outException(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async void AsyncAcceptSocket(SocketAcceptDelegate mgrHandler)
|
||||
|
||||
@@ -27,7 +27,12 @@ namespace Framework.Networking
|
||||
{
|
||||
Contract.Assert(threadCount > 0);
|
||||
|
||||
Acceptor = new AsyncAcceptor(bindIp, port);
|
||||
Acceptor = new AsyncAcceptor();
|
||||
if (!Acceptor.Start(bindIp, port))
|
||||
{
|
||||
Log.outError(LogFilter.Network, "StartNetwork failed to Start AsyncAcceptor");
|
||||
return false;
|
||||
}
|
||||
|
||||
_threadCount = threadCount;
|
||||
_threads = new NetworkThread<TSocketType>[GetNetworkThreadCount()];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -140,7 +140,7 @@ PacketLogFile = "CypherCore.pkt"
|
||||
#
|
||||
|
||||
Appender.Console = 1,3,0
|
||||
Appender.Server = 2,2,0
|
||||
Appender.Server = 2,1,0
|
||||
Appender.GM = 2,2,0,gm/gm_{0}.log
|
||||
Appender.DBErrors = 2,4,0,DBErrors.log
|
||||
|
||||
@@ -167,7 +167,7 @@ Logger.ServerLoading = 3,Console Server
|
||||
Logger.Commands = 3,Console GM
|
||||
Logger.Sql = 3,Console DBErrors
|
||||
Logger.SqlUpdates = 3,Console Server
|
||||
Logger.Network = 1,Console Server
|
||||
Logger.Network = 3,Console Server
|
||||
|
||||
#Logger.Achievement=3,Console Server
|
||||
#Logger.AreaTrigger=3,Console Server
|
||||
|
||||
Reference in New Issue
Block a user