コード例 #1
0
ファイル: MainWindow.cs プロジェクト: ReezeBL/MinecraftEmu
 private void PingServer(Object obj)
 {
     TcpClient Client = new TcpClient();
     CustomLib.putsc("Pinging server..\n", Color.Aquamarine);
     try
     {
         Client.Connect(IPAddress.Parse(textHost.Text), Convert.ToInt32(textPort.Text));
         BinaryWriter bwr = new BinaryWriter(Client.GetStream());
         BinaryReader br = new BinaryReader(Client.GetStream());
         PacketServerPing packet = new PacketServerPing(78, textHost.Text, Convert.ToInt32(textPort.Text));
         packet.Write(bwr);
         PacketDisconnect packet2 = new PacketDisconnect();
         if (br.ReadByte() != 255)
         {
             throw new IOException("Bad message");
         }
         packet2.Read(br);
         String message = packet2.getReason();
         message = message.Substring(2);
         String[] pars = message.Split("\0".ToCharArray());
         CustomLib.putsc("Server protocol: " + pars[1] + "\nServer version: " + pars[2] + "\nServer name: " + pars[3] + "\nServer online: " + pars[4] + "/" + pars[5] + "\n", Color.Aquamarine);
         Client.Close();
     }
     catch (SocketException ex)
     {
         CustomLib.putsc("Unable to connect to server!\n", Color.Aquamarine);
         Console.WriteLine(ex);
     }
     catch (IOException ex)
     {
         CustomLib.putsc("Error during processing data!\n", Color.Aquamarine);
         Console.WriteLine(ex);
     }
     catch (Exception ex)
     {
         Logger.WriteLog(ex);
         Console.WriteLine(ex);
     }
 }
コード例 #2
0
ファイル: PacketHandler.cs プロジェクト: ReezeBL/MinecraftEmu
 public void HandlePacketDisconnect(PacketDisconnect packet)
 {
     Console.WriteLine("Disconnected by server! Reason: " + packet.getReason());
     CustomLib.putsc("Disconnected by server! Reason: " + packet.getReason() + "\n", Color.Aquamarine);
     manager.Connected = false;
 }