07-29-2017, 06:33 PM
Заходишь на сервер переходишь на гейм сервер выходишь с него
потом снова заходишь на сервер авторизации все хорошо, переходишь в гейм и гейм сервер отказывается читать или подключать клиент не видит не чего NetworkManager молчит но после клика в консоль все начинает работать как исправить помогите мне пожалуйста
[SRC="csharp"] public TcpClient Client { get; set; }
public NetworkStream Stream { get; set; }
public Account Account { get; set; }
public string Login { get; set; }// незнаю нахуй пусть будет пригодиться!
public int Id { get; set; }
byte[] buffer = new byte[2048];
public int ChannelId { get; set; }
public int channel_id = -1;
public int player_id = 0;
public void setChannelId(int id)
{
ChannelId = Id;
}
public void Accept(TcpClient client)
{
Client = client;
Stream = client.GetStream();
ChannelId = -1;
SendPacket(new PROTOCOL_BASE_CONNECTION_ACK(this));
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, null);
}
public void BeginRead(IAsyncResult asyncResult)
{
try
{
int received = Stream.EndRead(asyncResult);
if (received != 0)
{
while (received >= 6)
{
int length = BitConverter.ToUInt16(buffer, 0) & 0x7FFF;
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("Server.Game.Network.packets.client." + packet.ToString());
if (t != null)
{
if (packet.ToString() != "PROTOCOL_LOBBY_GET_ROOMLIST_REQ") { Logger.Info("[Packet Handler] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.ToString()); }
//Logger.Info("[Packet Handler] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.ToString());
ReceivePacket clientpacket = (ReceivePacket)Activator.CreateInstance(t);
clientpacket.Client = this;
clientpacket.Process(temp);
ThreadManager.runNewThread(new Thread(new ThreadStart(clientpacket.RunImpl)));
}
else
{
Logger.Info("[Packet Handler] Receive unk packet {0}", BitConverter.ToInt16(opcode, 0));
Logger.Trace(temp.ToHex());
}
received -= length + 4;
Array.Copy(buffer, length + 4, buffer, 0, received); // << Копируем оставшиеся данные в начало буфера
}
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, Stream);
}
else
{
Close();
}
}
catch (IOException)
{
Close();
}
catch (Exception ex)
{
Close();
}
}
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);
if (packet.GetType().Name != "PROTOCOL_LOBBY_GET_ROOMLIST_ACK") { Logger.Info("[SendPacket] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.GetType().Name); }
//Logger.Info("[SendPacket] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.GetType().Name);
}
public void Close()
{
NetworkManager.Instance.removeClient(this);
}
public Account restoreAccount(string acc)
{
Account account = AccountManager.getInstance().get(acc);
if (account == null)
{
return null;
}
account.setConnected(true);
this.setAccount(account.player_id);
return account;
}
public void setAccount(int id)
{
this.player_id = id;
}
}
}
[/SRC]
вот скрин консоли с клиентом https://hostingkartinok.com/show-image.p...5ad58cd6c1
потом снова заходишь на сервер авторизации все хорошо, переходишь в гейм и гейм сервер отказывается читать или подключать клиент не видит не чего NetworkManager молчит но после клика в консоль все начинает работать как исправить помогите мне пожалуйста
[SRC="csharp"] public TcpClient Client { get; set; }
public NetworkStream Stream { get; set; }
public Account Account { get; set; }
public string Login { get; set; }// незнаю нахуй пусть будет пригодиться!
public int Id { get; set; }
byte[] buffer = new byte[2048];
public int ChannelId { get; set; }
public int channel_id = -1;
public int player_id = 0;
public void setChannelId(int id)
{
ChannelId = Id;
}
public void Accept(TcpClient client)
{
Client = client;
Stream = client.GetStream();
ChannelId = -1;
SendPacket(new PROTOCOL_BASE_CONNECTION_ACK(this));
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, null);
}
public void BeginRead(IAsyncResult asyncResult)
{
try
{
int received = Stream.EndRead(asyncResult);
if (received != 0)
{
while (received >= 6)
{
int length = BitConverter.ToUInt16(buffer, 0) & 0x7FFF;
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("Server.Game.Network.packets.client." + packet.ToString());
if (t != null)
{
if (packet.ToString() != "PROTOCOL_LOBBY_GET_ROOMLIST_REQ") { Logger.Info("[Packet Handler] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.ToString()); }
//Logger.Info("[Packet Handler] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.ToString());
ReceivePacket clientpacket = (ReceivePacket)Activator.CreateInstance(t);
clientpacket.Client = this;
clientpacket.Process(temp);
ThreadManager.runNewThread(new Thread(new ThreadStart(clientpacket.RunImpl)));
}
else
{
Logger.Info("[Packet Handler] Receive unk packet {0}", BitConverter.ToInt16(opcode, 0));
Logger.Trace(temp.ToHex());
}
received -= length + 4;
Array.Copy(buffer, length + 4, buffer, 0, received); // << Копируем оставшиеся данные в начало буфера
}
Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, Stream);
}
else
{
Close();
}
}
catch (IOException)
{
Close();
}
catch (Exception ex)
{
Close();
}
}
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);
if (packet.GetType().Name != "PROTOCOL_LOBBY_GET_ROOMLIST_ACK") { Logger.Info("[SendPacket] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.GetType().Name); }
//Logger.Info("[SendPacket] Receive {1} packet opcode {0}", BitConverter.ToInt16(opcode, 0), packet.GetType().Name);
}
public void Close()
{
NetworkManager.Instance.removeClient(this);
}
public Account restoreAccount(string acc)
{
Account account = AccountManager.getInstance().get(acc);
if (account == null)
{
return null;
}
account.setConnected(true);
this.setAccount(account.player_id);
return account;
}
public void setAccount(int id)
{
this.player_id = id;
}
}
}
[/SRC]
вот скрин консоли с клиентом https://hostingkartinok.com/show-image.p...5ad58cd6c1