Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DedServ()

void Terraria.Main.DedServ ( )
inline

Definition at line 4819 of file Main.cs.

4820 {
4821 NeverSleep();
4822 rand = new UnifiedRandom();
4823 if (autoShutdown)
4824 {
4825 string lpWindowName = (Console.Title = "terraria" + rand.Next(int.MaxValue));
4826 if (Platform.IsWindows)
4827 {
4829 if (intPtr != IntPtr.Zero)
4830 {
4831 ShowWindow(intPtr, 0);
4832 }
4833 }
4834 }
4835 else
4836 {
4837 Console.Title = "Terraria Server " + versionNumber2;
4838 }
4839 dedServ = true;
4840 showSplash = false;
4841 Initialize();
4842 while (worldPathName == null || worldPathName == "")
4843 {
4844 bool flag = true;
4845 while (flag)
4846 {
4847 LoadWorlds();
4849 Console.WriteLine("");
4850 for (int i = 0; i < WorldList.Count; i++)
4851 {
4852 Console.WriteLine(i + 1 + "\t\t" + WorldList[i].Name);
4853 }
4854 string textValue = Language.GetTextValue("CLI.NewWorld_Command");
4855 string textValue2 = Language.GetTextValue("CLI.DeleteWorld_Example");
4856 int num = (Math.Max(newWorldName.Length, textValue2.Length) + 1) / 8 + 1;
4857 textValue = textValue + new string('\t', num - textValue.Length / 8) + Language.GetTextValue("CLI.NewWorld_Description");
4858 textValue2 = textValue2 + new string('\t', num - textValue2.Length / 8) + Language.GetTextValue("CLI.DeleteWorld_Description");
4859 Console.WriteLine(textValue);
4861 Console.WriteLine("");
4862 Console.Write(Language.GetTextValue("CLI.ChooseWorld"));
4863 string text2 = ReadLineInput();
4864 if (text2 == null)
4865 {
4866 text2 = "";
4867 }
4868 try
4869 {
4870 Console.Clear();
4871 }
4872 catch
4873 {
4874 }
4875 if (text2.StartsWith(Language.GetTextValue("CLI.DeleteWorld_Command") + " "))
4876 {
4877 try
4878 {
4879 int length = Language.GetTextValue("CLI.DeleteWorld_Command").Length;
4880 int num2 = Convert.ToInt32(text2.Substring(length + 1)) - 1;
4881 if (num2 < WorldList.Count)
4882 {
4884 Console.WriteLine("");
4885 Console.WriteLine(Language.GetTextValue("CLI.DeleteConfirmation", WorldList[num2].Name));
4886 Console.Write("({0}/{1}): ", Language.GetTextValue("CLI.ShortYes"), Language.GetTextValue("CLI.ShortNo"));
4887 if (ReadLineInput().ToLower() == Language.GetTextValue("CLI.ShortYes").ToLower())
4888 {
4890 }
4891 }
4892 }
4893 catch
4894 {
4895 }
4896 try
4897 {
4898 Console.Clear();
4899 }
4900 catch
4901 {
4902 }
4903 continue;
4904 }
4905 if (text2 == "n" || text2 == "N")
4906 {
4907 bool flag2 = true;
4908 while (flag2)
4909 {
4911 Console.WriteLine("");
4912 Console.WriteLine("1\t" + Language.GetTextValue("UI.WorldSizeSmall"));
4913 Console.WriteLine("2\t" + Language.GetTextValue("UI.WorldSizeMedium"));
4914 Console.WriteLine("3\t" + Language.GetTextValue("UI.WorldSizeLarge"));
4915 Console.WriteLine("");
4916 Console.Write(Language.GetTextValue("CLI.ChooseSize"));
4917 string value = ReadLineInput();
4918 try
4919 {
4920 switch (Convert.ToInt32(value))
4921 {
4922 case 1:
4923 maxTilesX = 4200;
4924 maxTilesY = 1200;
4925 flag2 = false;
4926 break;
4927 case 2:
4928 maxTilesX = 6400;
4929 maxTilesY = 1800;
4930 flag2 = false;
4931 break;
4932 case 3:
4933 maxTilesX = 8400;
4934 maxTilesY = 2400;
4935 flag2 = false;
4936 break;
4937 }
4938 }
4939 catch
4940 {
4941 }
4942 try
4943 {
4944 Console.Clear();
4945 }
4946 catch
4947 {
4948 }
4949 }
4950 flag2 = true;
4951 while (flag2)
4952 {
4954 Console.WriteLine("");
4955 Console.WriteLine("1\t" + Language.GetTextValue("UI.Normal"));
4956 Console.WriteLine("2\t" + Language.GetTextValue("UI.Expert"));
4957 Console.WriteLine("3\t" + Language.GetTextValue("UI.Master"));
4958 Console.WriteLine("4\t" + Language.GetTextValue("UI.Creative"));
4959 Console.WriteLine("");
4960 Console.Write(Language.GetTextValue("CLI.ChooseDifficulty"));
4961 string value = ReadLineInput();
4962 try
4963 {
4964 switch (Convert.ToInt32(value))
4965 {
4966 case 1:
4967 GameMode = 0;
4968 flag2 = false;
4969 break;
4970 case 2:
4971 GameMode = 1;
4972 flag2 = false;
4973 break;
4974 case 3:
4975 GameMode = 2;
4976 flag2 = false;
4977 break;
4978 case 4:
4979 GameMode = 3;
4980 flag2 = false;
4981 break;
4982 }
4983 }
4984 catch
4985 {
4986 }
4987 try
4988 {
4989 Console.Clear();
4990 }
4991 catch
4992 {
4993 }
4994 }
4995 flag2 = true;
4996 while (flag2)
4997 {
4999 Console.WriteLine("");
5000 Console.WriteLine("1\t" + Language.GetTextValue("CLI.Random"));
5001 Console.WriteLine("2\t" + Language.GetTextValue("CLI.Corrupt"));
5002 Console.WriteLine("3\t" + Language.GetTextValue("CLI.Crimson"));
5003 Console.WriteLine("");
5004 Console.Write(Language.GetTextValue("CLI.ChooseEvil"));
5005 string value = ReadLineInput();
5006 try
5007 {
5008 switch (Convert.ToInt32(value))
5009 {
5010 case 1:
5011 WorldGen.WorldGenParam_Evil = -1;
5012 flag2 = false;
5013 break;
5014 case 2:
5015 WorldGen.WorldGenParam_Evil = 0;
5016 flag2 = false;
5017 break;
5018 case 3:
5019 WorldGen.WorldGenParam_Evil = 1;
5020 flag2 = false;
5021 break;
5022 }
5023 }
5024 catch
5025 {
5026 }
5027 try
5028 {
5029 Console.Clear();
5030 }
5031 catch
5032 {
5033 }
5034 }
5035 flag2 = true;
5037 while (flag2)
5038 {
5039 Console.WriteLine("");
5040 Console.Write(Language.GetTextValue("CLI.EnterWorldName"));
5042 if (newWorldName != null && newWorldName != "" && newWorldName != " ")
5043 {
5044 if (newWorldName.Length >= 27)
5045 {
5046 Console.WriteLine("");
5047 Console.WriteLine(Language.GetTextValue("CLI.WorldNameLengthTooLong", 26));
5048 continue;
5049 }
5050 flag2 = false;
5051 try
5052 {
5053 Console.Clear();
5054 }
5055 catch
5056 {
5057 }
5058 }
5059 else
5060 {
5061 try
5062 {
5063 Console.Clear();
5064 }
5065 catch
5066 {
5067 }
5069 }
5070 }
5071 string text3 = "";
5072 flag2 = true;
5074 while (flag2)
5075 {
5076 Console.WriteLine("");
5077 Console.Write(Language.GetTextValue("CLI.EnterSeed"));
5078 text3 = ReadLineInput();
5079 if (text3 != null)
5080 {
5081 if (text3.Length >= 40)
5082 {
5083 Console.WriteLine("");
5084 Console.WriteLine(Language.GetTextValue("CLI.SeedLengthTooLong", 39));
5085 continue;
5086 }
5087 flag2 = false;
5088 try
5089 {
5090 Console.Clear();
5091 }
5092 catch
5093 {
5094 }
5095 }
5096 else
5097 {
5098 text3 = "";
5099 }
5100 }
5103 text3 = text3.Trim();
5104 if (text3.Length == 0)
5105 {
5106 ActiveWorldFileData.SetSeedToRandom();
5107 }
5108 else
5109 {
5110 ActiveWorldFileData.SetSeed(text3);
5111 }
5113 menuMode = 10;
5115 Task task = WorldGen.CreateNewWorld(generationProgress);
5116 flag2 = false;
5117 while (menuMode == 10)
5118 {
5119 if (oldStatusText != statusText && !WorldGen.drunkWorldGen)
5120 {
5123 }
5124 }
5125 try
5126 {
5127 Console.Clear();
5128 }
5129 catch
5130 {
5131 }
5132 while (!task.IsCompleted)
5133 {
5134 statusText = string.Format("{0:0.0%} - " + generationProgress.Message + " - {1:0.0%}", generationProgress.TotalProgress, generationProgress.Value);
5136 {
5138 string value2 = statusText;
5139 if (WorldGen.notTheBees && !WorldGen.getGoodWorldGen)
5140 {
5141 value2 = string.Format("{0:0.0%} - " + Language.GetTextValue("UI.WorldGenEasterEgg_GeneratingBees") + " - {1:0.0%}", generationProgress.TotalProgress, generationProgress.Value);
5142 }
5144 }
5145 }
5146 continue;
5147 }
5148 try
5149 {
5150 int num3 = Convert.ToInt32(text2);
5151 num3--;
5152 if (num3 < 0 || num3 >= WorldList.Count)
5153 {
5154 continue;
5155 }
5156 bool flag3 = true;
5157 while (flag3)
5158 {
5160 Console.WriteLine("");
5161 Console.Write(Language.GetTextValue("CLI.SetInitialMaxPlayers"));
5162 string text4 = ReadLineInput();
5163 try
5164 {
5165 if (text4 == "")
5166 {
5167 text4 = "16";
5168 }
5169 int num4 = Convert.ToInt32(text4);
5170 if (num4 <= 255 && num4 >= 1)
5171 {
5173 flag3 = false;
5174 }
5175 flag3 = false;
5176 }
5177 catch
5178 {
5179 }
5180 try
5181 {
5182 Console.Clear();
5183 }
5184 catch
5185 {
5186 }
5187 }
5188 flag3 = true;
5189 while (flag3)
5190 {
5192 Console.WriteLine("");
5193 Console.Write(Language.GetTextValue("CLI.SetInitialPort"));
5194 string text5 = ReadLineInput();
5195 try
5196 {
5197 if (text5 == "")
5198 {
5199 text5 = "7777";
5200 }
5201 int num5 = Convert.ToInt32(text5);
5202 if (num5 <= 65535)
5203 {
5204 Netplay.ListenPort = num5;
5205 flag3 = false;
5206 }
5207 }
5208 catch
5209 {
5210 }
5211 try
5212 {
5213 Console.Clear();
5214 }
5215 catch
5216 {
5217 }
5218 }
5219 flag3 = true;
5220 while (flag3)
5221 {
5223 Console.WriteLine("");
5224 Console.Write(Language.GetTextValue("CLI.AutomaticPortForward", Language.GetTextValue("CLI.ShortYes"), Language.GetTextValue("CLI.ShortNo")));
5225 string text6 = ReadLineInput();
5226 try
5227 {
5228 if (text6 == "" || text6.ToLower() == Language.GetTextValue("CLI.ShortYes").ToLower() || text6.ToLower() == Language.GetTextValue("CLI.Yes").ToLower())
5229 {
5230 Netplay.UseUPNP = true;
5231 flag3 = false;
5232 }
5233 else if (text6.ToLower() == Language.GetTextValue("CLI.ShortNo").ToLower() || text6.ToLower() == Language.GetTextValue("CLI.No").ToLower())
5234 {
5235 Netplay.UseUPNP = false;
5236 flag3 = false;
5237 }
5238 }
5239 catch
5240 {
5241 }
5242 try
5243 {
5244 Console.Clear();
5245 }
5246 catch
5247 {
5248 }
5249 }
5251 Console.WriteLine("");
5252 Console.Write(Language.GetTextValue("CLI.EnterServerPassword"));
5253 Netplay.ServerPassword = ReadLineInput();
5255 flag = false;
5256 try
5257 {
5258 Console.Clear();
5259 }
5260 catch
5261 {
5262 }
5263 }
5264 catch
5265 {
5266 }
5267 }
5268 }
5269 try
5270 {
5271 Console.Clear();
5272 }
5273 catch
5274 {
5275 }
5276 Task task2 = WorldGen.serverLoadWorld();
5278 Console.WriteLine("");
5279 while (!task2.IsCompleted)
5280 {
5282 {
5283 if (AutogenProgress.TotalProgress != 0.0)
5284 {
5285 statusText = string.Format("{0:0.0%} - " + AutogenProgress.Message + " - {1:0.0%}", AutogenProgress.TotalProgress, AutogenProgress.Value);
5286 }
5288 {
5291 }
5292 }
5293 }
5294 try
5295 {
5297 {
5298 Console.Clear();
5299 }
5300 }
5301 catch
5302 {
5303 }
5304 if (WorldGen.loadFailed || !WorldGen.loadSuccess)
5305 {
5307 if (!autoShutdown)
5308 {
5309 Console.ReadKey();
5310 }
5312 return;
5313 }
5315 Console.WriteLine("");
5316 Console.WriteLine(Language.GetTextValue("CLI.ListeningOnPort", Netplay.ListenPort));
5317 Console.WriteLine(Language.GetTextValue("CLI.HelpHint"));
5318 Console.WriteLine("");
5319 Console.Title = "Terraria Server: " + worldName;
5321 if (!autoShutdown)
5322 {
5323 startDedInput();
5324 }
5325 stopwatch.Start();
5326 double num6 = 16.666666666666668;
5327 double num7 = 0.0;
5328 int num8 = 0;
5329 new Stopwatch().Start();
5330 Netplay.StartServer();
5331 gameMenu = false;
5332 while (!Netplay.Disconnect)
5333 {
5334 double totalMilliseconds = stopwatch.Elapsed.TotalMilliseconds;
5335 if (totalMilliseconds + num7 >= num6)
5336 {
5337 num8++;
5339 stopwatch.Reset();
5340 stopwatch.Start();
5342 {
5345 }
5346 if (Netplay.HasClients)
5347 {
5348 Update(new GameTime());
5349 }
5350 else if (saveTime.IsRunning)
5351 {
5352 saveTime.Stop();
5353 }
5354 if (Main.OnTickForThirdPartySoftwareOnly != null)
5355 {
5356 Main.OnTickForThirdPartySoftwareOnly();
5357 }
5358 double num9 = stopwatch.Elapsed.TotalMilliseconds + num7;
5359 if (num9 < num6)
5360 {
5361 int num10 = (int)(num6 - num9) - 1;
5362 if (num10 > 1)
5363 {
5364 Thread.Sleep(num10 - 1);
5365 if (!Netplay.HasClients)
5366 {
5367 num7 = 0.0;
5368 Thread.Sleep(10);
5369 }
5370 }
5371 }
5372 }
5373 Thread.Sleep(0);
5374 }
5375 if (Netplay.SaveOnServerExit)
5376 {
5377 Console.WriteLine(Language.GetTextValue("Net.ServerSavingOnExit"));
5379 }
5381 }
static bool IsWindows
Definition Platform.cs:19
static void Write(string format, object? arg0)
Definition Console.cs:850
static void WriteLine()
Definition Console.cs:733
static ConsoleKeyInfo ReadKey()
Definition Console.cs:514
static void Clear()
Definition Console.cs:602
static int ToInt32(object? value)
Definition Convert.cs:1320
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void Sleep(int millisecondsTimeout)
Definition Thread.cs:658
static void ProcessSpecialWorldSeeds(string processedSeed)
static WorldFileData CreateMetadata(string name, bool cloudSave, int GameMode)
Definition WorldFile.cs:523
static void SaveWorld()
Definition WorldFile.cs:780
static Exception LastThrownLoadException
Definition WorldFile.cs:183
static string GetTextValue(string key)
Definition Language.cs:15
static string versionNumber
Definition Main.cs:303
static List< WorldFileData > WorldList
Definition Main.cs:1944
static void WriteFancyWorldLoadErrorToConsole()
Definition Main.cs:5383
static int maxTilesY
Definition Main.cs:1116
static bool autoShutdown
Definition Main.cs:2277
static string ReadLineInput()
Definition Main.cs:5710
static WorldFileData ActiveWorldFileData
Definition Main.cs:1946
static void LoadWorlds()
Definition Main.cs:3642
static IntPtr FindWindow(string lpClassName, string lpWindowName)
void YouCanSleepNow()
Definition Main.cs:4811
static string oldStatusText
Definition Main.cs:2273
static string versionNumber2
Definition Main.cs:305
static bool dedServ
Definition Main.cs:1226
static void EraseWorld(int i)
Definition Main.cs:4437
static Stopwatch saveTime
Definition Main.cs:986
static bool ShowWindow(IntPtr hWnd, int nCmdShow)
static string worldPathName
Definition Main.cs:2837
static void startDedInput()
Definition Main.cs:5389
static string worldName
Definition Main.cs:1260
static int maxTilesX
Definition Main.cs:1114
void SetNetPlayers(int mPlayers)
Definition Main.cs:4750
static int GameMode
Definition Main.cs:2685
static bool showSplash
Definition Main.cs:740
void NeverSleep()
Definition Main.cs:4803
static string newWorldName
Definition Main.cs:2393
static UnifiedRandom rand
Definition Main.cs:1387
static GenerationProgress AutogenProgress
Definition Main.cs:982
static int menuMode
Definition Main.cs:2379
static bool gameMenu
Definition Main.cs:1926
override void Initialize()
Definition Main.cs:5873
static string statusText
Definition Main.cs:1258
static Terraria.Social.Base.CloudSocialModule Cloud
Definition SocialAPI.cs:18
static readonly IntPtr Zero
Definition IntPtr.cs:18

References Terraria.Main.ActiveWorldFileData, Terraria.Main.AutogenProgress, Terraria.Main.autoShutdown, System.Console.Clear(), Terraria.Social.SocialAPI.Cloud, Terraria.IO.WorldFile.CreateMetadata(), Terraria.WorldGen.CreateNewWorld(), Terraria.Main.dedServ, Terraria.Netplay.Disconnect, Terraria.WorldGen.drunkWorldGen, Terraria.Main.EraseWorld(), Terraria.Main.FindWindow(), Terraria.Main.gameMenu, Terraria.Main.GameMode, Terraria.WorldGen.getGoodWorldGen, Terraria.Localization.Language.GetTextValue(), Terraria.Netplay.HasClients, System.Text.RegularExpressions.i, Terraria.Main.Initialize(), ReLogic.OS.Platform.IsWindows, Terraria.IO.WorldFile.LastThrownLoadException, System.length, Terraria.Netplay.ListenPort, Terraria.WorldGen.loadFailed, Terraria.WorldGen.loadSuccess, Terraria.Main.LoadWorlds(), System.Math.Max(), Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, System.Reflection.MaxValue, Terraria.Main.menuMode, System.Reflection.Name, Terraria.Main.NeverSleep(), Terraria.Main.newWorldName, Terraria.WorldGen.notTheBees, Terraria.Main.oldStatusText, Terraria.Main.OnTickForThirdPartySoftwareOnly, Terraria.GameContent.UI.States.UIWorldCreation.ProcessSpecialWorldSeeds(), Terraria.Main.rand, System.Console.ReadKey(), Terraria.Main.ReadLineInput(), Terraria.Netplay.SaveOnServerExit, Terraria.Main.saveTime, Terraria.IO.WorldFile.SaveWorld(), Terraria.WorldGen.serverLoadWorld(), Terraria.Main.SetNetPlayers(), Terraria.Main.showSplash, Terraria.Main.ShowWindow(), System.Threading.Thread.Sleep(), System.Diagnostics.Stopwatch.Start(), Terraria.Main.startDedInput(), Terraria.Netplay.StartServer(), Terraria.Main.statusText, System.task, System.Convert.ToInt32(), Microsoft.Xna.Framework.Update, System.value, Terraria.Main.versionNumber, Terraria.Main.versionNumber2, Terraria.Main.WorldList, Terraria.Main.worldName, Terraria.Main.worldPathName, System.Console.Write(), Terraria.Main.WriteFancyWorldLoadErrorToConsole(), System.Console.WriteLine(), Terraria.Main.YouCanSleepNow(), and System.IntPtr.Zero.