Ejemplo n.º 1
0
 public void Connect()
 {
     CurrentStep = ProgressStep.ConnectingToMinecraft;
     Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     try
     {
         Socket.Connect(Server.IPAddress, Server.Port);
     }
     catch (SocketException)
     {
         FailureMessage = "Connection Failed.";
         CurrentStep = ProgressStep.LoginFailed;
     }
     PacketHandler = new PacketHandler(Socket);
     PacketHandler.Start();
     string reason = "";
     CurrentStep = ProgressStep.LoggingIn;
     if (!Login(ref reason))
     {
         FailureMessage = reason;
         CurrentStep = ProgressStep.LoginFailed;
         return;
     }
     CurrentStep = ProgressStep.Connecting;
     PacketHandler.RegisterPacketHandler(PacketId.ModList, ModListPacketHandler);
     PacketHandler.RegisterPacketHandler(PacketId.AdminFileInfo, AdminFileInfoPacketHandler);
     PacketHandler.RegisterPacketHandler(PacketId.Metadata, MetadataPacketHandler);
     Packet.Send(new HandshakePacket { Type = HandshakePacket.SessionType.Admin, Username = username }, PacketHandler.Stream);
 }
Ejemplo n.º 2
0
 public Client(Server s, PacketHandler p)
 {
     Server = s;
     ph = p;
     ph.Start();
     ph.RegisterPacketHandler(PacketId.Handshake, Handle);
 }
Ejemplo n.º 3
0
 private void Connect()
 {
     Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket = s;
     Debug.Assert("Creating Objects.");
     try
     {
         string srv = Server.Address;
         int port = Server.Port;
         if (srv == LocalAddress.ToString()) srv = "127.0.0.1";
         ConnectionHandler.ConnectTo(s, srv, port);
         SplashScreen.GetScreen().Progress.PerformStep();
     }
     catch (SocketException ex)
     {
         Debug.Assert(ex);
         MessageBox.Show("There was an error while connecting to the update server.  I will now self destruct.");
         Thread.Sleep(1000);
         SplashScreen.UpdateStatusTextWithStatus("Boom!!!", TypeOfMessage.Error);
         Thread.Sleep(5000);
         SplashScreen.UpdateStatusTextWithStatus("That was a joke, by the way.", TypeOfMessage.Warning);
         Thread.Sleep(1000);
         SplashScreen.CloseSplashScreen();
         Thread.Sleep(3000);
         Close();
         return;
     }
     catch (Exception ex)
     {
         ExceptionHandler.HandleException(ex, this);
     }
     modImages = new ImageList();
     modImages.ImageSize = new Size(230, 180);
     modImages.ColorDepth = ColorDepth.Depth32Bit;
     SplashScreen.GetScreen().Progress.PerformStep();
     TaskManager.AddAsyncTask(delegate
     {
         while (s.Connected) ;
         if (!warnDisconnect) return;
         if (SplashScreen.GetScreen() != null)
         {
             SplashScreen.UpdateStatusTextWithStatus("Lost connection to server.", TypeOfMessage.Error);
             Thread.Sleep(5000);
         }
         else MessageBox.Show("Lost connection to server.");
         Program.RunOnUIThread(delegate
         {
             Close();
         });
     });
     MinecraftModUpdater.Logger.Log(Logger.Level.Info, "Logging started.");
     ph = new PacketHandler(s);
     ph.Start();
     for (int i = 0; i < 10; i++)
     {
         TaskManager.SpawnTaskThread(ThreadRole.Standard);
     }
     TaskManager.AddAsyncTask(delegate
     {
         ph.RegisterPacketHandler(PacketId.Metadata, ph_Metadata);
         ph.RegisterPacketHandler(PacketId.ModInfo, ph_ModInfo);
         ph.RegisterPacketHandler(PacketId.ModList, ph_ModList);
         ph.RegisterPacketHandler(PacketId.AllDone, ph_AllDone);
         ph.RegisterPacketHandler(PacketId.NextDownload, ph_NextDownload);
         ph.RegisterPacketHandler(PacketId.FilePart, ph_FilePart);
         ph.RegisterPacketHandler(PacketId.Image, ph_Image);
         Debug.Assert("Packet Handlers registered.");
         SplashScreen.GetScreen().Progress.PerformStep();
     });
     if ((new LoginForm()).ShowDialog() != DialogResult.OK)
     {
         MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Login failed");
         SplashScreen.UpdateStatusTextWithStatus("Your login failed.", TypeOfMessage.Error);
         Thread.Sleep(2000);
         SplashScreen.CloseSplashScreen();
         Thread.Sleep(400);
         Close();
         return;
     }
     Thread.Sleep(1000);
     SplashScreen.UpdateStatusText("Connected to server.  Retreving Mod List.");
     Packet.Send(new HandshakePacket { Username = ProgramOptions.Username }, ph.Stream);
     Debug.Assert("Sent Handshake Packet.");
     Thread.Sleep(100);
     for (int i = 0; i < 5; i++)
     {
         SplashScreen.GetScreen().Progress.Value += 1;
         Thread.Sleep(20);
     }
 }