コード例 #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);
 }
コード例 #2
0
 public Slave(HandshakePacket p, PacketHandler ph)
 {
     Name = p.Name;
     Address = IPAddress.Parse(p.Address);
     Port = p.Port;
     PacketHandler = ph;
 }
コード例 #3
0
 public void Start()
 {
     Address = IPAddress.Loopback;
     try
     {
         string direction = "";
         WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
         using (WebResponse response = request.GetResponse())
         {
             using (StreamReader stream = new StreamReader(response.GetResponseStream()))
             {
                 direction = stream.ReadToEnd();
             }
         }
         int first = direction.IndexOf("Address: ") + 9;
         int last = direction.LastIndexOf("</body>");
         direction = direction.Substring(first, last - first);
         Address = IPAddress.Parse(direction);
     }
     catch (Exception e) { MinecraftModUpdater.Logger.Log(e); }
     MinecraftModUpdater.Logger.Log(Logger.Level.Info,"Server IP Address is: " + Address.ToString());
     TcpServer.Start();
     Online = true;
     TaskManager.AddAsyncTask(delegate { SimpleConsoleInputHandler(); });
     TaskManager.AddAsyncTask(delegate
     {
         if (Config.MasterServer != "")
         {
             Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             string ip = Config.MasterServer.Split(':')[0].Trim();
             int port = int.Parse(Config.MasterServer.Split(':')[1].Trim());
             ConnectionHandler.ConnectTo(s, ip, port);
             PacketHandler ph = new PacketHandler(s);
             ph.Start();
             Thread.Sleep(1000);
             Packet.Send(new HandshakePacket { Name = Config.ServerName, Port = Config.Port, Address = Address.ToString(), Type = HandshakePacket.SessionType.Server }, ph.Stream);
         }
     }, ThreadRole.Delayed, 1000);
     TaskManager.AddAsyncTask(delegate
     {
         string ver;
         bool api;
         if (Extras.CheckForUpdate("server", Program.Version, out ver, out api))
         {
             if (!api)
                 MinecraftModUpdater.Logger.Log(Logger.Level.Info,"Version {0} is now available for Minecraft Mod Updater.", ver);
             else
                 MinecraftModUpdater.Logger.Log(Logger.Level.Info,"Version {0} is now available for Minecraft Mod Updater API.", ver);
         }
     });
     Receive();
 }
コード例 #4
0
 public Client(Server s, PacketHandler p)
 {
     Server = s;
     ph = p;
     ph.Start();
     ph.RegisterPacketHandler(PacketId.Handshake, Handle);
 }
コード例 #5
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);
     }
 }