public Server() { Servers = new List <Slave>(); clients = new List <Client>(); Online = false; listen = new TcpListener(IPAddress.Any, Properties.Settings.Default.Port); MCModUpdaterExceptionHandler.RegisterExceptionHandler(new ExceptionHandler()); }
public void UpdateGame() { try { State = EnumState.CHECKING_CACHE; Progress = 5; // Get a list of URLs to download from LoadJarURLs(); // Create the bin directory if it doesn't exist if (!Directory.Exists(Properties.Settings.Default.MinecraftPath + "/bin")) { Directory.CreateDirectory(Properties.Settings.Default.MinecraftPath + "/bin"); } string binDir = Properties.Settings.Default.MinecraftPath + "/bin"; if (this.latestVersion != null) { string versionFile = Path.Combine(binDir, "version"); bool cacheAvailable = false; if (!forceUpdate && File.Exists(versionFile) && (latestVersion.Equals("-1") || latestVersion.Equals(File.ReadAllText(versionFile)))) { cacheAvailable = true; Progress = 90; } if ((forceUpdate) || (!cacheAvailable)) { shouldUpdate = true; if (this.shouldUpdate) { WriteVersionFile(versionFile, latestVersion); try { DownloadJars(); } catch (WebException e) { throw new Exception("An error occurred when downloading packages.", e); } ExtractNatives(); Progress = 100; } } } } catch (WebException e) { MCModUpdaterExceptionHandler.HandleException(this, new Exception("An error occurred when trying to download Minecraft.", e)); return; } }
public static void Init() { TaskManager.ExceptionRaised += new TaskManagerError(TaskManager_ExceptionRaised); Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!MCModUpdaterExceptionHandler.RegisterExceptionHandler(new ExceptionHandlerLiaison())) { MessageBox.Show("Error"); } }
public Server() { MinecraftModUpdater.Logger.LogEvent += new LogEventDelegate(Logger_LogEvent); System.Diagnostics.Process.GetCurrentProcess().Exited += new EventHandler(Server_Exited); Config.Load(); logFile = File.AppendText(Config.LogFile); logFile.AutoFlush = true; Mods = new List <Mod>(); Clients = new List <Client>(); TcpServer = new TcpListener(IPAddress.Any, Config.Port); ModImages = new Dictionary <Mod, Image>(); Administrators = new List <string>(); MCModUpdaterExceptionHandler.RegisterExceptionHandler(new ExceptionHandler()); SelfUpdate(); Administrators.AddRange(File.ReadAllLines("administrators.txt")); LoadMods(); if (File.Exists(Config.ModsPath + "/assets/server_background.png")) { BackgroundImage = Image.FromFile(Config.ModsPath + "/assets/server_background.png"); } }
/// <summary> /// Reads the next packet in the stream. /// </summary> /// <param name="Stream">The stream to read from</param> /// <returns>A fully read packet.</returns> public static Packet ReadPacket(ModUpdaterNetworkStream Stream) { Type Packet = null; Packet p = null; if (Stream.Disposed) { return(null); } try { PacketId id = PacketId.Disconnect; try { id = (PacketId)Stream.ReadNetworkByte(); } catch (MalformedPacketException) { return(null); } if (!Map.ContainsValue(id)) { Stream.Flush(); return(null); } MinecraftModUpdater.Logger.Log(Logger.Level.Debug, string.Format("Read packet {0}", id.ToString())); foreach (var v in Map) { if (v.Value == id) { Packet = v.Key; } } p = (Packet)Packet.GetConstructor(new Type[] { }).Invoke(null); p.Timestamp = new UnixTime(Stream.ReadLong()).ToDateTime(); p.Read(Stream); lastRecived = p; } catch (MalformedPacketException e) { throw new MalformedPacketException(e.Message, e); } catch (Exception e) { MCModUpdaterExceptionHandler.HandleException(p, e); } return(p); }
/// <summary> /// Handles receving of packets. This method should never be called from outside of this class. /// </summary> private void Recv() { PacketId id; Packet p; try { p = Packet.ReadPacket(Stream); id = Packet.GetPacketId(p); PacketBacklog.Add(p); if (id == PacketId.EncryptionStatus) { EncryptionStatusPacket pa = p as EncryptionStatusPacket; Stream.IV = pa.EncryptionIV; Stream.Key = pa.EncryptionKey; Stream.Encrypted = pa.Encrypt; return; } else if (id == PacketId.Disconnect) { Stop(); } lock (eventLock) { foreach (var ph in EventHandler.ToArray()) { if (ph.Key == id) { ph.Value.Invoke(p); } } } } catch (MalformedPacketException e) { MCModUpdaterExceptionHandler.HandleException(this, e); } }