Ejemplo n.º 1
0
 private static void InnerClientLoop()
 {
     try
     {
         NetMessage.buffer[256].Reset();
         int num = -1;
         while (!Disconnect)
         {
             if (Connection.Socket.IsConnected())
             {
                 Connection.IsActive = true;
                 if (Connection.State == 0)
                 {
                     Main.statusText  = Language.GetTextValue("Net.FoundServer");
                     Connection.State = 1;
                     NetMessage.SendData(1);
                 }
                 if (Connection.State == 2 && num != Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.SendingPlayerData");
                 }
                 if (Connection.State == 3 && num != Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.RequestingWorldInformation");
                 }
                 if (Connection.State == 4)
                 {
                     WorldGen.worldCleared = false;
                     Connection.State      = 5;
                     if (Main.cloudBGActive >= 1f)
                     {
                         Main.cloudBGAlpha = 1f;
                     }
                     else
                     {
                         Main.cloudBGAlpha = 0f;
                     }
                     Main.windSpeedCurrent = Main.windSpeedTarget;
                     Cloud.resetClouds();
                     Main.cloudAlpha = Main.maxRaining;
                     WorldGen.clearWorld();
                     if (Main.mapEnabled)
                     {
                         Main.Map.Load();
                     }
                 }
                 if (Connection.State == 5 && Main.loadMapLock)
                 {
                     float num2 = (float)Main.loadMapLastX / (float)Main.maxTilesX;
                     Main.statusText = Lang.gen[68].Value + " " + (int)(num2 * 100f + 1f) + "%";
                 }
                 else if (Connection.State == 5 && WorldGen.worldCleared)
                 {
                     Connection.State = 6;
                     Main.player[Main.myPlayer].FindSpawn();
                     NetMessage.SendData(8, -1, -1, null, Main.player[Main.myPlayer].SpawnX, Main.player[Main.myPlayer].SpawnY);
                 }
                 if (Connection.State == 6 && num != Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.RequestingTileData");
                 }
                 if (!Connection.IsReading && !Disconnect && Connection.Socket.IsDataAvailable())
                 {
                     Connection.IsReading = true;
                     Connection.Socket.AsyncReceive(Connection.ReadBuffer, 0, Connection.ReadBuffer.Length, Connection.ClientReadCallBack);
                 }
                 if (Connection.StatusMax > 0 && Connection.StatusText != "")
                 {
                     if (Connection.StatusCount >= Connection.StatusMax)
                     {
                         Main.statusText        = Language.GetTextValue("Net.StatusComplete", Connection.StatusText);
                         Connection.StatusText  = "";
                         Connection.StatusMax   = 0;
                         Connection.StatusCount = 0;
                     }
                     else
                     {
                         Main.statusText = Connection.StatusText + ": " + (int)((float)Connection.StatusCount / (float)Connection.StatusMax * 100f) + "%";
                     }
                 }
                 Thread.Sleep(1);
             }
             else if (Connection.IsActive)
             {
                 Main.statusText = Language.GetTextValue("Net.LostConnection");
                 Disconnect      = true;
             }
             num = Connection.State;
         }
         try
         {
             Connection.Socket.Close();
         }
         catch
         {
         }
         if (!Main.gameMenu)
         {
             Main.gameMenu = true;
             Main.SwitchNetMode(0);
             MapHelper.noStatusText = true;
             Player.SavePlayer(Main.ActivePlayerFileData);
             Player.ClearPlayerTempInfo();
             Main.ActivePlayerFileData.StopPlayTimer();
             SoundEngine.StopTrackedSounds();
             MapHelper.noStatusText = false;
             Main.menuMode          = 14;
         }
         NetMessage.buffer[256].Reset();
         if (Main.menuMode == 15 && Main.statusText == Language.GetTextValue("Net.LostConnection"))
         {
             Main.menuMode = 14;
         }
         if (Connection.StatusText != "" && Connection.StatusText != null)
         {
             Main.statusText = Language.GetTextValue("Net.LostConnection");
         }
         Connection.StatusCount = 0;
         Connection.StatusMax   = 0;
         Connection.StatusText  = "";
         Main.SwitchNetMode(0);
     }
     catch (Exception value)
     {
         try
         {
             using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", append: true))
             {
                 streamWriter.WriteLine(DateTime.Now);
                 streamWriter.WriteLine(value);
                 streamWriter.WriteLine("");
             }
         }
         catch
         {
         }
         Disconnect = true;
     }
     if (Netplay.OnDisconnect != null)
     {
         Netplay.OnDisconnect();
     }
 }
Ejemplo n.º 2
0
 private static void InnerClientLoop()
 {
     try
     {
         NetMessage.buffer[256].Reset();
         int num1 = -1;
         while (!Netplay.Disconnect)
         {
             if (Netplay.Connection.Socket.IsConnected())
             {
                 Netplay.Connection.IsActive = true;
                 if (Netplay.Connection.State == 0)
                 {
                     Main.statusText          = Language.GetTextValue("Net.FoundServer");
                     Netplay.Connection.State = 1;
                     NetMessage.SendData(1, -1, -1, (NetworkText)null, 0, 0.0f, 0.0f, 0.0f, 0, 0, 0);
                 }
                 if (Netplay.Connection.State == 2 && num1 != Netplay.Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.SendingPlayerData");
                 }
                 if (Netplay.Connection.State == 3 && num1 != Netplay.Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.RequestingWorldInformation");
                 }
                 if (Netplay.Connection.State == 4)
                 {
                     WorldGen.worldCleared    = false;
                     Netplay.Connection.State = 5;
                     Main.cloudBGAlpha        = (double)Main.cloudBGActive < 1.0 ? 0.0f : 1f;
                     Main.windSpeedCurrent    = Main.windSpeedTarget;
                     Cloud.resetClouds();
                     Main.cloudAlpha = Main.maxRaining;
                     WorldGen.clearWorld();
                     if (Main.mapEnabled)
                     {
                         Main.Map.Load();
                     }
                 }
                 if (Netplay.Connection.State == 5 && Main.loadMapLock)
                 {
                     float num2 = (float)Main.loadMapLastX / (float)Main.maxTilesX;
                     Main.statusText = Lang.gen[68].Value + " " + (object)(int)((double)num2 * 100.0 + 1.0) + "%";
                 }
                 else if (Netplay.Connection.State == 5 && WorldGen.worldCleared)
                 {
                     Netplay.Connection.State = 6;
                     Main.player[Main.myPlayer].FindSpawn();
                     NetMessage.SendData(8, -1, -1, (NetworkText)null, Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0.0f, 0.0f, 0, 0, 0);
                 }
                 if (Netplay.Connection.State == 6 && num1 != Netplay.Connection.State)
                 {
                     Main.statusText = Language.GetTextValue("Net.RequestingTileData");
                 }
                 if (!Netplay.Connection.IsReading && !Netplay.Disconnect && Netplay.Connection.Socket.IsDataAvailable())
                 {
                     Netplay.Connection.IsReading = true;
                     Netplay.Connection.Socket.AsyncReceive(Netplay.Connection.ReadBuffer, 0, Netplay.Connection.ReadBuffer.Length, new SocketReceiveCallback(Netplay.Connection.ClientReadCallBack), (object)null);
                 }
                 if (Netplay.Connection.StatusMax > 0 && Netplay.Connection.StatusText != "")
                 {
                     if (Netplay.Connection.StatusCount >= Netplay.Connection.StatusMax)
                     {
                         Main.statusText = Language.GetTextValue("Net.StatusComplete", (object)Netplay.Connection.StatusText);
                         Netplay.Connection.StatusText  = "";
                         Netplay.Connection.StatusMax   = 0;
                         Netplay.Connection.StatusCount = 0;
                     }
                     else
                     {
                         Main.statusText = Netplay.Connection.StatusText + ": " + (object)(int)((double)Netplay.Connection.StatusCount / (double)Netplay.Connection.StatusMax * 100.0) + "%";
                     }
                 }
                 Thread.Sleep(1);
             }
             else if (Netplay.Connection.IsActive)
             {
                 Main.statusText    = Language.GetTextValue("Net.LostConnection");
                 Netplay.Disconnect = true;
             }
             num1 = Netplay.Connection.State;
         }
         try
         {
             Netplay.Connection.Socket.Close();
         }
         catch
         {
         }
         if (!Main.gameMenu)
         {
             Main.gameMenu = true;
             Main.SwitchNetMode(0);
             MapHelper.noStatusText = true;
             Player.SavePlayer(Main.ActivePlayerFileData, false);
             Player.ClearPlayerTempInfo();
             Main.ActivePlayerFileData.StopPlayTimer();
             SoundEngine.StopTrackedSounds();
             MapHelper.noStatusText = false;
             Main.menuMode          = 14;
         }
         NetMessage.buffer[256].Reset();
         if (Main.menuMode == 15 && Main.statusText == Language.GetTextValue("Net.LostConnection"))
         {
             Main.menuMode = 14;
         }
         if (Netplay.Connection.StatusText != "" && Netplay.Connection.StatusText != null)
         {
             Main.statusText = Language.GetTextValue("Net.LostConnection");
         }
         Netplay.Connection.StatusCount = 0;
         Netplay.Connection.StatusMax   = 0;
         Netplay.Connection.StatusText  = "";
         Main.SwitchNetMode(0);
     }
     catch (Exception ex)
     {
         try
         {
             using (StreamWriter streamWriter = new StreamWriter("client-crashlog.txt", true))
             {
                 streamWriter.WriteLine((object)DateTime.Now);
                 streamWriter.WriteLine((object)ex);
                 streamWriter.WriteLine("");
             }
         }
         catch
         {
         }
         Netplay.Disconnect = true;
     }
     if (Netplay.OnDisconnect == null)
     {
         return;
     }
     Netplay.OnDisconnect();
 }