private void handleLobby() { WL.RegisterWorld initPacket = new WL.RegisterWorld(Program.WorldName, Program.Password, Program.ID); stream.Write(initPacket.ToArray(), 0, initPacket.ToArray().Length); stream.Flush(); byte[] message = new byte[4096]; int bytesRead; while (true) { bytesRead = 0; try { bytesRead = stream.Read(message, 0, 4096); } catch { break; } if (bytesRead == 0) { break; } IPacket packet = null; switch (message[0]) { case (byte)OpCodes.LW_REGISTER_SUCCESS: packet = new RegisterSuccess(); break; case (byte)OpCodes.LW_ACCOUNT_ENTER: packet = new AccountEnter(); break; } packet.Write(message, 1, bytesRead - 1); packet.Handle(); } Log.Error("Lobby.Client", "Lobby Server disconnected! Reconnecting..."); client.Close(); stream.Dispose(); try { client = new TcpClient(); connect(address); stream = client.GetStream(); Log.Succes("Lobby.Client", "Reconnected!"); handleLobby(); } catch (Exception e) { Log.Error("Lobby.Client", "Failed to reconnect due to following exception:\n\n"); Console.WriteLine(e.ToString()); return; } }
private void handleLobby() { WL.RegisterWorld initPacket = new WL.RegisterWorld(Program.WorldName, Program.Password, Program.ID); stream.Write(initPacket.ToArray(), 0, initPacket.ToArray().Length); stream.Flush(); Byte[] message = new Byte[4096]; int bytesRead; while (true) { bytesRead = 0; try { bytesRead = stream.Read(message, 0, 4096); } catch { break; } if (bytesRead == 0) { break; } IPacket packet = null; switch (message[0]) { case (Byte)OpCodes.LW_REGISTER_SUCCESS: packet = new RegisterSuccess(); break; case (Byte)OpCodes.LW_ACCOUNT_ENTER: packet = new AccountEnter(); break; } packet.Write(message, 1, bytesRead - 1); packet.Handle(); } Log.Error("Lobby.Client", "Lobby Server disconnected! Reconnecting..."); client.Close(); stream.Dispose(); try { client = new TcpClient(); connect(address); stream = client.GetStream(); Log.Succes("Lobby.Client", "Reconnected!"); handleLobby(); } catch (Exception e) { Log.Error("Lobby.Client", "Failed to reconnect due to following exception:\n\n"); Console.WriteLine(e.ToString()); return; } }