Beispiel #1
0
 public static void Initialize(Main main)
 {
     if (!Directory.Exists("ServerPlugins"))
     {
         Directory.CreateDirectory("ServerPlugins");
     }
     AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
     List<FileInfo> files = new DirectoryInfo("ServerPlugins").GetFiles("*.dll").ToList();
     files.AddRange(new DirectoryInfo("ServerPlugins").GetFiles("*.dll-plugin"));
     for (int i = 0; i < files.Count; i++)
     {
         FileInfo fileInfo = files[i];
         try
         {
             string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name);
             Assembly assembly;
             if (!LoadedAssemblies.TryGetValue(fileNameWithoutExtension, out assembly))
             {
                 assembly = Assembly.Load(File.ReadAllBytes(fileInfo.FullName));
                 LoadedAssemblies.Add(fileNameWithoutExtension, assembly);
             }
             Type[] types = assembly.GetTypes();
             for (int j = 0; j < types.Length; j++)
             {
                 Type type = types[j];
                 if (type.BaseType == typeof (TerrariaPlugin)) // Mono has this as a TODO.
                 {
                     if (Compatible(type))
                     {
                         Plugins.Add(new PluginContainer((TerrariaPlugin) Activator.CreateInstance(type, new object[]
                                                                                                             {
                                                                                                                 main
                                                                                                             })));
                     }
                     else
                     {
                         Console.WriteLine("Outdated plugin: {0} ({1})", fileInfo.Name, type);
                         File.AppendAllText("ErrorLog.txt", string.Format("Outdated plugin: {0} ({1})\n", fileInfo.Name, type));
                     }
                 }
             }
         }
         catch (Exception innerException)
         {
             if (innerException is TargetInvocationException)
             {
                 innerException = (innerException).InnerException;
             }
             else if (innerException is ReflectionTypeLoadException)
             {
                 var exception = (ReflectionTypeLoadException) innerException;
             }
             AppendLog(fileInfo.Name, innerException);
             Console.WriteLine("Plugin {0} failed to load", fileInfo.Name);
         }
     }
     IOrderedEnumerable<PluginContainer> orderedEnumerable =
         from x in Plugins
         orderby x.Plugin.Order , x.Plugin.Name
         select x;
     foreach (PluginContainer current in orderedEnumerable)
     {
         current.Initialize();
         Console.WriteLine("{0} v{1} ({2}) initiated.", current.Plugin.Name, current.Plugin.Version, current.Plugin.Author);
     }
 }
Beispiel #2
0
 public TShock(Main game)
     : base(game)
 {
     Config = new ConfigFile();
     Order = 0;
 }
Beispiel #3
0
 private static void Main(string[] args)
 {
     try
     {
         Game = new Main();
         for (int i = 0; i < args.Length; i++)
         {
             switch (args[i].ToLower())
             {
                 case "-config":
                     i++;
                     Game.LoadDedConfig(args[i]);
                     break;
                 case "-port":
                     i++;
                     try
                     {
                         int serverPort = Convert.ToInt32(args[i]);
                         Netplay.serverPort = serverPort;
                     }
                     catch
                     {
                     }
                     break;
                 case "-world":
                     i++;
                     Game.SetWorld(args[i]);
                     break;
                 case "-worldname":
                     i++;
                     Game.SetWorldName(args[i]);
                     break;
                 case "-autoshutdown":
                     Game.autoShut();
                     break;
                 case "-autocreate":
                     i++;
                     string newOpt = args[i];
                     Game.autoCreate(newOpt);
                     break;
                 case "-ip":
                     IPAddress ip;
                     if (IPAddress.TryParse(args[++i], out ip))
                     {
                         Netplay.serverListenIP = ip;
                         Console.Write("Using IP: {0}", ip);
                     }
                     else
                         Console.WriteLine("Bad IP: {0}", args[i]);
                     break;
                 case "-connperip":
                     int limit;
                     if (int.TryParse(args[++i], out limit))
                     {
                         Netplay.connectionLimit = limit;
                         Console.WriteLine("Each IP is now limited to {0} connections", limit);
                     }
                     else
                     Console.WriteLine("Bad int for -connperip");
                     break;
                 case "-killinactivesocket":
                     Netplay.killInactive = true;
                     break;
             }
         }
         if (Environment.OSVersion.Platform == PlatformID.Unix)
             Toaria.Main.SavePath = "Terraria";
         else
             Toaria.Main.SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "My Games", "Terraria");
         Toaria.Main.WorldPath = Path.Combine(Toaria.Main.SavePath, "Worlds");
         Toaria.Main.PlayerPath = Path.Combine(Toaria.Main.SavePath, "Players");
         Initialize(Game);
         Game.DedServ();
         DeInitialize();
     }
     catch (Exception value)
     {
         try
         {
             using (var streamWriter = new StreamWriter("crashlog.txt", true))
             {
                 streamWriter.WriteLine(DateTime.Now);
                 streamWriter.WriteLine(value);
                 streamWriter.WriteLine("");
             }
             Console.WriteLine("Server crash: " + DateTime.Now);
             Console.WriteLine(value);
             Console.WriteLine("");
             Console.WriteLine("Please send crashlog.txt to [email protected]");
         }
         catch
         {
         }
     }
 }