public static void ClientLoop(object threadContext) { ResetNetDiag(); if (Main.rand == null) { Main.rand = new Random((int) DateTime.Now.Ticks); } if (WorldGen.genRand == null) { WorldGen.genRand = new Random((int) DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player) Main.player[Main.myPlayer].clientClone(); for (int i = 0; i < 0xff; i++) { if (i != Main.myPlayer) { Main.player[i] = new Player(); } } Main.menuMode = 10; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "Connecting to " + serverIP; } Main.netMode = 1; disconnect = false; clientSock = new ClientSock(); clientSock.tcpClient.NoDelay = true; clientSock.readBuffer = new byte[0x400]; clientSock.writeBuffer = new byte[0x400]; bool flag = true; while (flag) { flag = false; try { clientSock.tcpClient.Connect(serverIP, serverPort); clientSock.networkStream = clientSock.tcpClient.GetStream(); flag = false; continue; } catch { if (!disconnect && Main.gameMenu) { flag = true; } continue; } } NetMessage.buffer[0x100].Reset(); for (int j = -1; !disconnect; j = clientSock.state) { if (clientSock.tcpClient.Connected) { if (NetMessage.buffer[0x100].checkBytes) { NetMessage.CheckBytes(0x100); } clientSock.active = true; if (clientSock.state == 0) { Main.statusText = "Found server"; clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f, 0); } if ((clientSock.state == 2) && (j != clientSock.state)) { Main.statusText = "Sending player data..."; } if ((clientSock.state == 3) && (j != clientSock.state)) { Main.statusText = "Requesting world information"; } if (clientSock.state == 4) { WorldGen.worldCleared = false; clientSock.state = 5; WorldGen.clearWorld(); } if ((clientSock.state == 5) && WorldGen.worldCleared) { clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float) Main.player[Main.myPlayer].SpawnY, 0f, 0f, 0); } if ((clientSock.state == 6) && (j != clientSock.state)) { Main.statusText = "Requesting tile data"; } if ((!clientSock.locked && !disconnect) && clientSock.networkStream.DataAvailable) { clientSock.locked = true; clientSock.networkStream.BeginRead(clientSock.readBuffer, 0, clientSock.readBuffer.Length, new AsyncCallback(clientSock.ClientReadCallBack), clientSock.networkStream); } if ((clientSock.statusMax > 0) && (clientSock.statusText != "")) { if (clientSock.statusCount >= clientSock.statusMax) { Main.statusText = clientSock.statusText + ": Complete!"; clientSock.statusText = ""; clientSock.statusMax = 0; clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { clientSock.statusText, ": ", (int) ((((float) clientSock.statusCount) / ((float) clientSock.statusMax)) * 100f), "%" }); } } Thread.Sleep(1); } else if (clientSock.active) { Main.statusText = "Lost connection"; disconnect = true; } } try { clientSock.networkStream.Close(); clientSock.networkStream = clientSock.tcpClient.GetStream(); } catch { } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[0x100].Reset(); if ((Main.menuMode == 15) && (Main.statusText == "Lost connection")) { Main.menuMode = 14; } if ((clientSock.statusText != "") && (clientSock.statusText != null)) { Main.statusText = "Lost connection"; } clientSock.statusCount = 0; clientSock.statusMax = 0; clientSock.statusText = ""; Main.netMode = 0; }
public static void ClientLoop(object threadContext) { Netplay.ResetNetDiag(); Main.ServerSideCharacter = false; if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } if (WorldGen.genRand == null) { WorldGen.genRand = new Random((int)DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); for (int i = 0; i < 255; i++) { if (i != Main.myPlayer) { Main.player[i] = new Player(); } } Main.menuMode = 10; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "Connecting to " + Netplay.serverIP; } Main.netMode = 1; Netplay.disconnect = false; Netplay.clientSock = new ClientSock(); Netplay.clientSock.tcpClient.NoDelay = true; Netplay.clientSock.readBuffer = new byte[1024]; Netplay.clientSock.writeBuffer = new byte[1024]; bool flag = true; while (flag) { flag = false; try { Netplay.clientSock.tcpClient.Connect(Netplay.serverIP, Netplay.serverPort); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); flag = false; } catch { if (!Netplay.disconnect && Main.gameMenu) { flag = true; } } } NetMessage.buffer[256].Reset(); int num = -1; while (!Netplay.disconnect) { if (Netplay.clientSock.tcpClient.Connected) { if (NetMessage.buffer[256].checkBytes) { NetMessage.CheckBytes(256); } Netplay.clientSock.active = true; if (Netplay.clientSock.state == 0) { Main.statusText = "Found server"; Netplay.clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f, 0); } if (Netplay.clientSock.state == 2 && num != Netplay.clientSock.state) { Main.statusText = "Sending player data..."; } if (Netplay.clientSock.state == 3 && num != Netplay.clientSock.state) { Main.statusText = "Requesting world information"; } if (Netplay.clientSock.state == 4) { WorldGen.worldCleared = false; Netplay.clientSock.state = 5; if (Main.cloudBGActive >= 1f) { Main.cloudBGAlpha = 1f; } else { Main.cloudBGAlpha = 0f; } Main.windSpeed = Main.windSpeedSet; Cloud.resetClouds(); Main.cloudAlpha = Main.maxRaining; WorldGen.clearWorld(); if (Main.mapEnabled) { Map.loadMap(); } } if (Netplay.clientSock.state == 5 && Main.loadMapLock) { float num2 = (float)Main.loadMapLastX / (float)Main.maxTilesX; Main.statusText = string.Concat(new object[] { Lang.gen[68], " ", (int)(num2 * 100f + 1f), "%" }); } else { if (Netplay.clientSock.state == 5 && WorldGen.worldCleared) { Netplay.clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0f, 0f, 0); } } if (Netplay.clientSock.state == 6 && num != Netplay.clientSock.state) { Main.statusText = "Requesting tile data"; } if (!Netplay.clientSock.locked && !Netplay.disconnect && Netplay.clientSock.networkStream.DataAvailable) { Netplay.clientSock.locked = true; Netplay.clientSock.networkStream.BeginRead(Netplay.clientSock.readBuffer, 0, Netplay.clientSock.readBuffer.Length, new AsyncCallback(Netplay.clientSock.ClientReadCallBack), Netplay.clientSock.networkStream); } if (Netplay.clientSock.statusMax > 0 && Netplay.clientSock.statusText != "") { if (Netplay.clientSock.statusCount >= Netplay.clientSock.statusMax) { Main.statusText = Netplay.clientSock.statusText + ": Complete!"; Netplay.clientSock.statusText = ""; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { Netplay.clientSock.statusText, ": ", (int)((float)Netplay.clientSock.statusCount / (float)Netplay.clientSock.statusMax * 100f), "%" }); } } Thread.Sleep(1); } else { if (Netplay.clientSock.active) { Main.statusText = "Lost connection"; Netplay.disconnect = true; } } num = Netplay.clientSock.state; } try { Netplay.clientSock.networkStream.Close(); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); } catch { } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[256].Reset(); if (Main.menuMode == 15 && Main.statusText == "Lost connection") { Main.menuMode = 14; } if (Netplay.clientSock.statusText != "" && Netplay.clientSock.statusText != null) { Main.statusText = "Lost connection"; } Netplay.clientSock.statusCount = 0; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusText = ""; Main.netMode = 0; }
public static void ClientLoop(object threadContext) { if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } if (WorldGen.genRand == null) { WorldGen.genRand = new Random((int)DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); Main.menuMode = 10; Main.menuMode = 14; Main.statusText = "Connecting to " + serverIP; Main.netMode = 1; disconnect = false; clientSock = new ClientSock(); clientSock.tcpClient.NoDelay = true; clientSock.readBuffer = new byte[0x400]; clientSock.writeBuffer = new byte[0x400]; try { clientSock.tcpClient.Connect(serverIP, serverPort); clientSock.networkStream = clientSock.tcpClient.GetStream(); } catch (Exception exception) { if (!disconnect && Main.gameMenu) { Main.menuMode = 15; Main.statusText = exception.ToString(); disconnect = true; } } NetMessage.buffer[9].Reset(); for (int i = -1; !disconnect; i = clientSock.state) { if (clientSock.tcpClient.Connected) { if (NetMessage.buffer[9].checkBytes) { NetMessage.CheckBytes(9); } clientSock.active = true; if (clientSock.state == 0) { Main.statusText = "Found server"; clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f); } if ((clientSock.state == 2) && (i != clientSock.state)) { Main.statusText = "Sending player data..."; } if ((clientSock.state == 3) && (i != clientSock.state)) { Main.statusText = "Requesting world information"; } if (clientSock.state == 4) { WorldGen.worldCleared = false; clientSock.state = 5; WorldGen.clearWorld(); } if ((clientSock.state == 5) && WorldGen.worldCleared) { clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0f, 0f); } if ((clientSock.state == 6) && (i != clientSock.state)) { Main.statusText = "Requesting tile data"; } if ((!clientSock.locked && !disconnect) && clientSock.networkStream.DataAvailable) { clientSock.locked = true; clientSock.networkStream.BeginRead(clientSock.readBuffer, 0, clientSock.readBuffer.Length, new AsyncCallback(clientSock.ClientReadCallBack), clientSock.networkStream); } if ((clientSock.statusMax > 0) && (clientSock.statusText != "")) { if (clientSock.statusCount >= clientSock.statusMax) { Main.statusText = clientSock.statusText + ": Complete!"; clientSock.statusText = ""; clientSock.statusMax = 0; clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { clientSock.statusText, ": ", (int)((((float)clientSock.statusCount) / ((float)clientSock.statusMax)) * 100f), "%" }); } } Thread.Sleep(1); } else if (clientSock.active) { Main.statusText = "Lost connection"; disconnect = true; } } try { clientSock.networkStream.Close(); clientSock.networkStream = clientSock.tcpClient.GetStream(); } catch { } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[9].Reset(); if ((Main.menuMode == 15) && (Main.statusText == "Lost connection")) { Main.menuMode = 14; } if ((clientSock.statusText != "") && (clientSock.statusText != null)) { Main.statusText = "Lost connection"; } clientSock.statusCount = 0; clientSock.statusMax = 0; clientSock.statusText = ""; Main.netMode = 0; }
public static void ClientLoop(object threadContext) { if (Main.rand == null) { System.DateTime now = System.DateTime.Now; Main.rand = new System.Random((int)now.Ticks); } if (WorldGen.genRand == null) { System.DateTime now = System.DateTime.Now; WorldGen.genRand = new System.Random((int)now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); Main.menuMode = 10; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "Connecting to " + Netplay.serverIP; } Main.netMode = 1; Netplay.disconnect = false; Netplay.clientSock = new ClientSock(); Netplay.clientSock.tcpClient.NoDelay = true; Netplay.clientSock.readBuffer = new byte[1024]; Netplay.clientSock.writeBuffer = new byte[1024]; bool flag = true; while (flag) { flag = false; try { Netplay.clientSock.tcpClient.Connect(Netplay.serverIP, Netplay.serverPort); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); flag = false; } catch { if (Netplay.disconnect || !Main.gameMenu) { Debug.WriteLine(" Exception normal: Player hit cancel before initiating a connection."); } else { flag = true; } } } NetMessage.buffer[256].Reset(); int num = -1; while (!Netplay.disconnect) { if (Netplay.clientSock.tcpClient.Connected) { if (NetMessage.buffer[256].checkBytes) { NetMessage.CheckBytes(256); } Netplay.clientSock.active = true; if (Netplay.clientSock.state == 0) { Main.statusText = "Found server"; Netplay.clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f); } if (Netplay.clientSock.state == 2 && num != Netplay.clientSock.state) { Main.statusText = "Sending player data..."; } if (Netplay.clientSock.state == 3 && num != Netplay.clientSock.state) { Main.statusText = "Requesting world information"; } if (Netplay.clientSock.state == 4) { WorldGen.worldCleared = false; Netplay.clientSock.state = 5; WorldGen.clearWorld(); } if (Netplay.clientSock.state == 5 && WorldGen.worldCleared) { Netplay.clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0f, 0f); } if (Netplay.clientSock.state == 6 && num != Netplay.clientSock.state) { Main.statusText = "Requesting tile data"; } if (!Netplay.clientSock.locked && !Netplay.disconnect && Netplay.clientSock.networkStream.DataAvailable) { Netplay.clientSock.locked = true; Netplay.clientSock.networkStream.BeginRead(Netplay.clientSock.readBuffer, 0, Netplay.clientSock.readBuffer.Length, new System.AsyncCallback(Netplay.clientSock.ClientReadCallBack), Netplay.clientSock.networkStream); } if (Netplay.clientSock.statusMax > 0 && Netplay.clientSock.statusText != "") { if (Netplay.clientSock.statusCount >= Netplay.clientSock.statusMax) { Main.statusText = Netplay.clientSock.statusText + ": Complete!"; Netplay.clientSock.statusText = ""; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { Netplay.clientSock.statusText, ": ", (int)((float)Netplay.clientSock.statusCount / (float)Netplay.clientSock.statusMax * 100f), "%" }); } } System.Threading.Thread.Sleep(1); } else { if (Netplay.clientSock.active) { Main.statusText = "Lost connection"; Netplay.disconnect = true; } } num = Netplay.clientSock.state; } try { Netplay.clientSock.networkStream.Close(); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); } catch { Debug.WriteLine(" Exception normal: Redundant closing of the TCP Client and/or Network Stream."); } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[256].Reset(); if (Main.menuMode == 15 && Main.statusText == "Lost connection") { Main.menuMode = 14; } if (Netplay.clientSock.statusText != "" && Netplay.clientSock.statusText != null) { Main.statusText = "Lost connection"; } Netplay.clientSock.statusCount = 0; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusText = ""; Main.netMode = 0; }
public static void ClientLoop(object threadContext) { Netplay.ResetNetDiag(); Main.ServerSideCharacter = false; if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } if (WorldGen.genRand == null) { WorldGen.genRand = new Random((int)DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); for (int i = 0; i < 255; i++) { if (i != Main.myPlayer) { Main.player[i] = new Player(); } } Main.menuMode = 10; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "Connecting to " + Netplay.serverIP; } Main.netMode = 1; Netplay.disconnect = false; Netplay.clientSock = new ClientSock(); Netplay.clientSock.tcpClient.NoDelay = true; Netplay.clientSock.readBuffer = new byte[1024]; Netplay.clientSock.writeBuffer = new byte[1024]; bool flag = true; while (flag) { flag = false; try { Netplay.clientSock.tcpClient.Connect(Netplay.serverIP, Netplay.serverPort); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); flag = false; } catch { if (!Netplay.disconnect && Main.gameMenu) { flag = true; } } } NetMessage.buffer[256].Reset(); int num = -1; while (!Netplay.disconnect) { if (Netplay.clientSock.tcpClient.Connected) { if (NetMessage.buffer[256].checkBytes) { NetMessage.CheckBytes(256); } Netplay.clientSock.active = true; if (Netplay.clientSock.state == 0) { Main.statusText = "Found server"; Netplay.clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f, 0); } if (Netplay.clientSock.state == 2 && num != Netplay.clientSock.state) { Main.statusText = "Sending player data..."; } if (Netplay.clientSock.state == 3 && num != Netplay.clientSock.state) { Main.statusText = "Requesting world information"; } if (Netplay.clientSock.state == 4) { WorldGen.worldCleared = false; Netplay.clientSock.state = 5; if (Main.cloudBGActive >= 1f) { Main.cloudBGAlpha = 1f; } else { Main.cloudBGAlpha = 0f; } Main.windSpeed = Main.windSpeedSet; Cloud.resetClouds(); Main.cloudAlpha = Main.maxRaining; WorldGen.clearWorld(); if (Main.mapEnabled) { Map.loadMap(); } } if (Netplay.clientSock.state == 5 && Main.loadMapLock) { float num2 = (float)Main.loadMapLastX / (float)Main.maxTilesX; Main.statusText = string.Concat(new object[] { Lang.gen[68], " ", (int)(num2 * 100f + 1f), "%" }); } else if (Netplay.clientSock.state == 5 && WorldGen.worldCleared) { Netplay.clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0f, 0f, 0); } if (Netplay.clientSock.state == 6 && num != Netplay.clientSock.state) { Main.statusText = "Requesting tile data"; } if (!Netplay.clientSock.locked && !Netplay.disconnect && Netplay.clientSock.networkStream.DataAvailable) { Netplay.clientSock.locked = true; Netplay.clientSock.networkStream.BeginRead(Netplay.clientSock.readBuffer, 0, Netplay.clientSock.readBuffer.Length, new AsyncCallback(Netplay.clientSock.ClientReadCallBack), Netplay.clientSock.networkStream); } if (Netplay.clientSock.statusMax > 0 && Netplay.clientSock.statusText != "") { if (Netplay.clientSock.statusCount >= Netplay.clientSock.statusMax) { Main.statusText = Netplay.clientSock.statusText + ": Complete!"; Netplay.clientSock.statusText = ""; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { Netplay.clientSock.statusText, ": ", (int)((float)Netplay.clientSock.statusCount / (float)Netplay.clientSock.statusMax * 100f), "%" }); } } Thread.Sleep(1); } else if (Netplay.clientSock.active) { Main.statusText = "Lost connection"; Netplay.disconnect = true; } num = Netplay.clientSock.state; } try { Netplay.clientSock.networkStream.Close(); if (Netplay.clientSock.tcpClient.Connected) { Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); } } catch { } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName, false, false); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[256].Reset(); if (Main.menuMode == 15 && Main.statusText == "Lost connection") { Main.menuMode = 14; } if (Netplay.clientSock.statusText != "" && Netplay.clientSock.statusText != null) { Main.statusText = "Lost connection"; } Netplay.clientSock.statusCount = 0; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusText = ""; Main.netMode = 0; }
public static void ClientLoop(object threadContext) { Netplay.ResetNetDiag(); if (Main.rand == null) { Main.rand = new Random((int)DateTime.Now.Ticks); } if (WorldGen.genRand == null) { WorldGen.genRand = new Random((int)DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); for (int i = 0; i < 255; i++) { if (i != Main.myPlayer) { Main.player[i] = new Player(); } } Main.menuMode = 10; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "正在连接到 " + Netplay.serverIP; } Main.netMode = 1; Netplay.disconnect = false; Netplay.clientSock = new ClientSock(); Netplay.clientSock.tcpClient.NoDelay = true; Netplay.clientSock.readBuffer = new byte[1024]; Netplay.clientSock.writeBuffer = new byte[1024]; bool flag = true; while (flag) { flag = false; try { Netplay.clientSock.tcpClient.Connect(Netplay.serverIP, Netplay.serverPort); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); flag = false; } catch { if (!Netplay.disconnect && Main.gameMenu) { flag = true; } } } NetMessage.buffer[256].Reset(); int num = -1; while (!Netplay.disconnect) { if (Netplay.clientSock.tcpClient.Connected) { if (NetMessage.buffer[256].checkBytes) { NetMessage.CheckBytes(256); } Netplay.clientSock.active = true; if (Netplay.clientSock.state == 0) { Main.statusText = "连接到服务器"; Netplay.clientSock.state = 1; NetMessage.SendData(1, -1, -1, "", 0, 0f, 0f, 0f, 0); } if (Netplay.clientSock.state == 2 && num != Netplay.clientSock.state) { Main.statusText = "发送角色数据..."; } if (Netplay.clientSock.state == 3 && num != Netplay.clientSock.state) { Main.statusText = "向服务器请求世界信息"; } if (Netplay.clientSock.state == 4) { WorldGen.worldCleared = false; Netplay.clientSock.state = 5; WorldGen.clearWorld(); } if (Netplay.clientSock.state == 5 && WorldGen.worldCleared) { Netplay.clientSock.state = 6; Main.player[Main.myPlayer].FindSpawn(); NetMessage.SendData(8, -1, -1, "", Main.player[Main.myPlayer].SpawnX, (float)Main.player[Main.myPlayer].SpawnY, 0f, 0f, 0); } if (Netplay.clientSock.state == 6 && num != Netplay.clientSock.state) { Main.statusText = "向服务器请求物块数据"; } if (!Netplay.clientSock.locked && !Netplay.disconnect && Netplay.clientSock.networkStream.DataAvailable) { Netplay.clientSock.locked = true; Netplay.clientSock.networkStream.BeginRead(Netplay.clientSock.readBuffer, 0, Netplay.clientSock.readBuffer.Length, new AsyncCallback(Netplay.clientSock.ClientReadCallBack), Netplay.clientSock.networkStream); } if (Netplay.clientSock.statusMax > 0 && Netplay.clientSock.statusText != "") { if (Netplay.clientSock.statusCount >= Netplay.clientSock.statusMax) { Main.statusText = Netplay.clientSock.statusText + ": 完成!"; Netplay.clientSock.statusText = ""; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusCount = 0; } else { Main.statusText = string.Concat(new object[] { Netplay.clientSock.statusText, ": ", (int)((float)Netplay.clientSock.statusCount / (float)Netplay.clientSock.statusMax * 100f), "%" }); } } Thread.Sleep(1); } else if (Netplay.clientSock.active) { Main.statusText = "失去连接"; Netplay.disconnect = true; } num = Netplay.clientSock.state; } try { Netplay.clientSock.networkStream.Close(); Netplay.clientSock.networkStream = Netplay.clientSock.tcpClient.GetStream(); } catch { } if (!Main.gameMenu) { Main.netMode = 0; Player.SavePlayer(Main.player[Main.myPlayer], Main.playerPathName); Main.gameMenu = true; Main.menuMode = 14; } NetMessage.buffer[256].Reset(); if (Main.menuMode == 15 && Main.statusText == "失去连接") { Main.menuMode = 14; } if (Netplay.clientSock.statusText != "" && Netplay.clientSock.statusText != null) { Main.statusText = "失去连接"; } Netplay.clientSock.statusCount = 0; Netplay.clientSock.statusMax = 0; Netplay.clientSock.statusText = ""; Main.netMode = 0; }