05-26-2017, 02:28 PM
логи сервера authClientConnection
Код:
26.05.2017 16:20:08 - Send 65 bytes
26.05.2017 16:20:09 - Received = 81
26.05.2017 16:20:09 - PacketId = 34048 Lenght = 2048
26.05.2017 16:20:09 - |--------------------------------------------------------------------------|
| 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |
|--------------------------------------------------------------------------|
| 0000: 00 85 03 91 00 87 80 0B 80 04 83 83 98 99 19 9A ................
| 0010: 1A 9B 00 18 99 19 9A 1A 9B 00 20 46 AE 22 AC 3B .......... F.".;
| 0020: 80 00 00 3F 80 00 00 80 00 00 00 00 00 00 00 1B ...?............
| 0030: 9C 99 98 1C 18 1C 18 9B 99 9C B1 9A B0 B3 32 30 ..............20
| 0040: 9B 98 B3 1B 33 1A B0 98 31 B1 B2 18 98 1C 9C ....3...1......
|--------------------------------------------------------------------------|
Код:
private int clan_id;
private string login;
//public ClientConnection network = new ClientConnection();
public delegate void MethodContainer(ClientConnection session);
public event MethodContainer OnDisconnected;
public TcpClient Client { get; set; }
private readonly Logger Log = new Logger();
public Account Account { get; set; }
byte[] buffer = new byte[2048];
public NetworkStream Stream { get; set; }
public int Id { get; set; }
public byte[] RemoteIPAddress { get; set; }
public int RemoteUdpPort { get; set; }
public int getClan()
{
return clan_id;
}
public string getLogin()
{
return login;
}
public Account getPlayer()
{
return Account;
}
public void setClan(int clan_id)
{
this.clan_id = clan_id;
}
public void setLogin(string lo)
{
login = lo;
}
public int getCryptKey()
{
return 0x74c2;
}
public void setPlayer(Account p)
{
Account = p;
}
public void Accept(TcpClient client)
{
Stream = client.GetStream();
SendPacket(new PROTOCOL_BASE_CONNECT_ACK());
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, null);
}
public void BeginRead(IAsyncResult asyncResult)
{
int received = Stream.EndRead(asyncResult);
Log.Info("Received = {0}", received);
while (received >= 6)
{
int length = BitConverter.ToUInt16(buffer, 0) & 0x7FFF;
//byte[] temp = new byte[length + 2];
byte[] temp = new byte[length + 2];
Array.Copy(buffer, 2, temp, 0, temp.Length);
int bits = Id % 7 + 1;
BitShift.Unshift(temp, bits);
byte[] opcode = new byte[] { temp[0], temp[1] };
RecvOpcode packet = (RecvOpcode)BitConverter.ToUInt16(opcode, 0);
Type t = Type.GetType("PB.Auth.Network.Receive." + packet.ToString());
Log.Info("PacketId = {0} Lenght = {1}", BitConverter.ToUInt16(opcode, 0), buffer.Length);
if (t != null)
{
ReceivePacket clientpacket = (ReceivePacket)Activator.CreateInstance(t);
clientpacket.Client = this;
clientpacket.Process(buffer);
}
else
{
// Log.Warn("");
Log.Warn(temp.ToHex());
}
received -= length + 4;
Array.Copy(buffer, length + 4, buffer, 0, received); // << Копируем оставшиеся данные в начало буфера
}
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, null);
}
public void SendPacket(SendPacket packet)
{
packet.Client = this;
packet.WriteImpl();
byte[] data = packet.ToByteArray();
byte[] lenght = BitConverter.GetBytes((short)data.Length);
byte[] opcode = BitConverter.GetBytes(Convert.ToInt16((int)Enum.Parse(typeof(SendOpcode), packet.GetType().Name)));
byte[] buff = new byte[data.Length + 4];
Array.Copy(lenght, 0, buff, 0, lenght.Length);
Array.Copy(opcode, 0, buff, 2, opcode.Length);
Array.Copy(data, 0, buff, 4, data.Length);
Stream.Write(buff, 0, buff.Length);
Log.Warn("Send {0} bytes", buff.Length);
}
}
}