public bool SectionRange(int size, int firstX, int firstY) { for (int i = 0; i < 4; i++) { int x = firstX; int y = firstY; switch (i) { case 1: x += size; break; case 2: y += size; break; case 3: x += size; y += size; break; } int sectionX = Netplay.GetSectionX(x); int sectionY = Netplay.GetSectionY(y); if (this.tileSection[sectionX, sectionY]) { return(true); } } return(false); }
private static void ClientLoopSetup(RemoteAddress address) { Netplay.ResetNetDiag(); Main.ServerSideCharacter = false; if (Main.rand == null) { Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks); } Main.player[Main.myPlayer].hostile = false; Main.clientPlayer = (Player)Main.player[Main.myPlayer].clientClone(); for (int index = 0; index < (int)byte.MaxValue; ++index) { if (index != Main.myPlayer) { Main.player[index] = new Player(); } } Main.netMode = 1; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = Language.GetTextValue("Net.ConnectingTo", (object)address.GetFriendlyName()); } Netplay.disconnect = false; Netplay.Connection = new RemoteServer(); Netplay.Connection.ReadBuffer = new byte[1024]; }
private static void OpenPort() { Netplay.portForwardIP = Netplay.GetLocalIPAddress(); Netplay.portForwardPort = Netplay.ListenPort; if (Netplay.upnpnat == null) { Netplay.upnpnat = (UPnPNAT)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("AE1E00AA-3FD5-403C-8A27-2BBDC30CD0E1"))); Netplay.mappings = Netplay.upnpnat.StaticPortMappingCollection; } if (Netplay.mappings == null) { return; } foreach (IStaticPortMapping mapping in Netplay.mappings) { if (mapping.InternalPort == Netplay.portForwardPort && mapping.InternalClient == Netplay.portForwardIP && mapping.Protocol == "TCP") { Netplay.portForwardOpen = true; } } if (Netplay.portForwardOpen) { return; } // ISSUE: reference to a compiler-generated method Netplay.mappings.Add(Netplay.portForwardPort, "TCP", Netplay.portForwardPort, Netplay.portForwardIP, true, "Terraria Server"); Netplay.portForwardOpen = true; }
private static void OpenPort(int port) { string localIpAddress = Netplay.GetLocalIPAddress(); if (Netplay._upnpnat == null) { Netplay._upnpnat = (UPnPNAT)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("AE1E00AA-3FD5-403C-8A27-2BBDC30CD0E1"))); Netplay._mappings = Netplay._upnpnat.StaticPortMappingCollection; } if (Netplay._mappings == null) { return; } bool flag = false; foreach (IStaticPortMapping mapping in Netplay._mappings) { if (mapping.InternalPort == port && mapping.InternalClient == localIpAddress && mapping.Protocol == "TCP") { flag = true; } } if (flag) { return; } // ISSUE: reference to a compiler-generated method Netplay._mappings.Add(port, "TCP", port, localIpAddress, true, "Terraria Server"); }
// Token: 0x06000140 RID: 320 RVA: 0x00029B00 File Offset: 0x00027D00 public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { int sectionX = Netplay.GetSectionX((int)(position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(position.Y / 16f)); int num = 0; for (int i = sectionX - fluff; i < sectionX + fluff + 1; i++) { for (int j = sectionY - fluff; j < sectionY + fluff + 1; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.Clients[playerIndex].TileSections[i, j]) { num++; } } } if (num > 0) { int num2 = num; NetMessage.SendData(9, playerIndex, -1, Lang.inter[44].ToNetworkText(), num2, 0f, 0f, 0f, 0, 0, 0); Netplay.Clients[playerIndex].StatusText2 = Language.GetTextValue("Net.IsReceivingTileData"); Netplay.Clients[playerIndex].StatusMax += num2; for (int k = sectionX - fluff; k < sectionX + fluff + 1; k++) { for (int l = sectionY - fluff; l < sectionY + fluff + 1; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.Clients[playerIndex].TileSections[k, l]) { NetMessage.SendSection(playerIndex, k, l, false); NetMessage.SendData(11, playerIndex, -1, null, k, (float)l, (float)k, (float)l, 0, 0, 0); } } } } }
public bool SectionRange(int size, int firstX, int firstY) { for (int i = 0; i < 4; i++) { int num = firstX; int num2 = firstY; if (i == 1) { num += size; } if (i == 2) { num2 += size; } if (i == 3) { num += size; num2 += size; } int sectionX = Netplay.GetSectionX(num); int sectionY = Netplay.GetSectionY(num2); if (this.tileSection[sectionX, sectionY]) { return(true); } } return(false); }
public static void SetRemoteIPAsync(string remoteAddress, Action successCallBack) { try { IPAddress address; if (IPAddress.TryParse(remoteAddress, out address)) { Netplay.ServerIP = address; Netplay.ServerIPText = address.ToString(); successCallBack(); } else { Netplay.InvalidateAllOngoingIPSetAttempts(); Dns.BeginGetHostAddresses(remoteAddress, new AsyncCallback(Netplay.SetRemoteIPAsyncCallback), (object)new Netplay.SetRemoteIPRequestInfo() { RequestId = Netplay._currentRequestId, SuccessCallback = successCallBack, RemoteAddress = remoteAddress }); } } catch (Exception ex) { } }
private static void CleanupServer() { Netplay.StopListening(); try { Netplay.ClosePort(Netplay.ListenPort); } catch { } for (int index = 0; index < 256; ++index) { Netplay.Clients[index].Reset(); } if (Main.menuMode != 15) { Main.netMode = 0; Main.menuMode = 10; WorldFile.SaveWorld(); Main.menuMode = 0; } else { Main.netMode = 0; } Main.myPlayer = 0; }
public bool SectionRange(int size, int firstX, int firstY) { for (int index = 0; index < 4; ++index) { int x = firstX; int y = firstY; if (index == 1) { x += size; } if (index == 2) { y += size; } if (index == 3) { x += size; y += size; } if (this.TileSections[Netplay.GetSectionX(x), Netplay.GetSectionY(y)]) { return(true); } } return(false); }
private static void ClientLoopSetup(RemoteAddress address) { 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.netMode = 1; Main.menuMode = 14; if (!Main.autoPass) { Main.statusText = "Connecting to " + address.GetFriendlyName(); } Netplay.disconnect = false; Netplay.Connection = new RemoteServer(); Netplay.Connection.ReadBuffer = new byte[1024]; }
private static void OnConnectionAccepted(ISocket client) { int num = Netplay.FindNextOpenClientSlot(); if (num != -1) { Netplay.Clients[num].Socket = client; Netplay.Clients[num].sendQueue.StartThread(); Console.WriteLine(client.GetRemoteAddress() + " is connecting to slot {0}...", num); } else { using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { writer.Write((short)0); writer.Write((byte)2); writer.Write("Server is full."); short position = (short)writer.BaseStream.Position; writer.BaseStream.Position = 0L; writer.Write((short)position); byte[] data = stream.ToArray(); client.AsyncSend(data, 0, data.Length, delegate { }); } } client.Close(); } }
public static void SocialClientLoop(object threadContext) { ISocket socket = (ISocket)threadContext; Netplay.ClientLoopSetup(socket.GetRemoteAddress()); Netplay.Connection.Socket = socket; }
public static void CheckSection(int who, Vector2 position) { int sectionX = Netplay.GetSectionX((int)(position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(position.Y / 16f)); int num = 0; for (int i = sectionX - 1; i < sectionX + 2; i++) { for (int j = sectionY - 1; j < sectionY + 2; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[i, j]) { num++; } } } if (num > 0) { int num2 = num * 150; NetMessage.SendData(9, who, -1, "Receiving tile data", num2, 0f, 0f, 0f, 0); Netplay.serverSock[who].statusText2 = "is receiving tile data"; Netplay.serverSock[who].statusMax += num2; for (int k = sectionX - 1; k < sectionX + 2; k++) { for (int l = sectionY - 1; l < sectionY + 2; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[k, l]) { NetMessage.SendSection(who, k, l); NetMessage.SendData(11, who, -1, "", k, (float)l, (float)k, (float)l, 0); } } } } }
public static void TcpClientLoop(object threadContext) { Netplay.ClientLoopSetup((RemoteAddress) new TcpAddress(Netplay.ServerIP, Netplay.ListenPort)); Main.menuMode = 14; bool flag = true; while (flag) { flag = false; try { Netplay.Connection.Socket.Connect((RemoteAddress) new TcpAddress(Netplay.ServerIP, Netplay.ListenPort)); flag = false; } catch { if (!Netplay.disconnect) { if (Main.gameMenu) { flag = true; } } } } Netplay.InnerClientLoop(); }
private static void JoinSession() { session = Netplay.availableSessions[selectedSession]; Netplay.StopFindingSessions(); UI.main.SetMenu(MenuMode.NETPLAY); UI.main.statusText = Lang.menu[80]; Netplay.StartClient(); }
public static void StartBroadCasting() { if (Netplay.broadcastThread != null) { Netplay.StopBroadCasting(); } Netplay.broadcastThread = new Thread(new ThreadStart(Netplay.BroadcastThread)); Netplay.broadcastThread.Start(); }
public static void StartServer() { Netplay.InitializeServer(); Netplay._serverThread = new Thread(new ThreadStart(Netplay.ServerLoop)) { IsBackground = true, Name = "Server Loop Thread" }; Netplay._serverThread.Start(); }
// Token: 0x06000159 RID: 345 RVA: 0x0002AA6C File Offset: 0x00028C6C private static void OnConnectionAccepted(ISocket client) { int num = Netplay.FindNextOpenClientSlot(); if (num != -1) { Netplay.Clients[num].Reset(); Netplay.Clients[num].Socket = client; Console.WriteLine(Language.GetTextValue("Net.ClientConnecting", client.GetRemoteAddress())); } if (Netplay.FindNextOpenClientSlot() == -1) { Netplay.StopListening(); } }
private static void OnConnectionAccepted(ISocket client) { int nextOpenClientSlot = Netplay.FindNextOpenClientSlot(); if (nextOpenClientSlot != -1) { Netplay.Clients[nextOpenClientSlot].Socket = client; Console.WriteLine((string)(object)client.GetRemoteAddress() + (object)" is connecting..."); } if (Netplay.FindNextOpenClientSlot() != -1) { return; } Netplay.StopListening(); }
private static void ServerLoop() { int num = 0; Netplay.StartBroadCasting(); while (!Netplay.Disconnect) { Netplay.StartListeningIfNeeded(); Netplay.UpdateConnectedClients(); num = (num + 1) % 10; Thread.Sleep(num == 0 ? 1 : 0); } Netplay.StopBroadCasting(); Netplay.CleanupServer(); }
private static void OnConnectionAccepted(ISocket client) { int num = Netplay.FindNextOpenClientSlot(); if (num != -1) { Netplay.Clients[num].Reset(); Netplay.Clients[num].Socket = client; Console.WriteLine(client.GetRemoteAddress() + " is connecting..."); } if (Netplay.FindNextOpenClientSlot() == -1) { Netplay.StopListening(); } }
private static void OnConnectionAccepted(ISocket client) { var nextOpenClientSlot = Netplay.FindNextOpenClientSlot(); if (nextOpenClientSlot != -1) { Netplay.Clients[nextOpenClientSlot].Reset(); Netplay.Clients[nextOpenClientSlot].Socket = client; Console.WriteLine(Language.GetTextValue("Net.ClientConnecting", (object)client.GetRemoteAddress())); } if (Netplay.FindNextOpenClientSlot() != -1) { return; } Netplay.StopListening(); }
public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { int index1 = playerIndex; int sectionX = Netplay.GetSectionX((int)((double)position.X / 16.0)); int sectionY = Netplay.GetSectionY((int)((double)position.Y / 16.0)); int num = 0; for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (int index3 = sectionY - fluff; index3 < sectionY + fluff + 1; ++index3) { if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, index3]) { ++num; } } } if (num <= 0) { return; } int number = num; NetMessage.SendData(9, index1, -1, Lang.inter[44].ToNetworkText(), number, 0.0f, 0.0f, 0.0f, 0, 0, 0); Netplay.Clients[index1].StatusText2 = Language.GetTextValue("Net.IsReceivingTileData"); Netplay.Clients[index1].StatusMax += number; RemoteClient._pendingSectionFraming.Clear(); for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (int index3 = sectionY - fluff; index3 < sectionY + fluff + 1; ++index3) { if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, index3]) { NetMessage.SendSection(index1, index2, index3, false); RemoteClient._pendingSectionFraming.Add(new Point(index2, index3)); } } } foreach (Point point in RemoteClient._pendingSectionFraming) { NetMessage.SendData(11, index1, -1, (NetworkText)null, point.X, (float)point.Y, (float)point.X, (float)point.Y, 0, 0, 0); } }
public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { var index1 = playerIndex; var sectionX = Netplay.GetSectionX((int)((double)position.X / 16.0)); var sectionY1 = Netplay.GetSectionY((int)((double)position.Y / 16.0)); var num = 0; for (var index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (var index3 = sectionY1 - fluff; index3 < sectionY1 + fluff + 1; ++index3) { if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, index3]) { ++num; } } } if (num <= 0) { return; } var number = num; NetMessage.SendData(9, index1, -1, Lang.inter[44].ToNetworkText(), number, 0.0f, 0.0f, 0.0f, 0, 0, 0); Netplay.Clients[index1].StatusText2 = Language.GetTextValue("Net.IsReceivingTileData"); Netplay.Clients[index1].StatusMax += number; for (var index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (var sectionY2 = sectionY1 - fluff; sectionY2 < sectionY1 + fluff + 1; ++sectionY2) { if (index2 >= 0 && index2 < Main.maxSectionsX && (sectionY2 >= 0 && sectionY2 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, sectionY2]) { NetMessage.SendSection(index1, index2, sectionY2, false); NetMessage.SendData(11, index1, -1, (NetworkText)null, index2, (float)sectionY2, (float)index2, (float)sectionY2, 0, 0, 0); } } } }
private static void InitializeServer() { Netplay.ResetNetDiag(); if (Main.rand == null) { Main.rand = new UnifiedRandom((int)DateTime.Now.Ticks); } Main.myPlayer = (int)byte.MaxValue; Netplay.ServerIP = IPAddress.Any; Main.menuMode = 14; Main.statusText = Lang.menu[8].Value; Main.netMode = 2; Netplay.Disconnect = false; for (int index = 0; index < 256; ++index) { Netplay.Clients[index] = new RemoteClient(); Netplay.Clients[index].Reset(); Netplay.Clients[index].Id = index; Netplay.Clients[index].ReadBuffer = new byte[1024]; } Netplay.TcpListener = (ISocket) new TcpSocket(); if (!Netplay.Disconnect) { if (!Netplay.StartListening()) { Main.menuMode = 15; Main.statusText = Language.GetTextValue("Error.TriedToRunServerTwice"); Netplay.Disconnect = true; } Main.statusText = Language.GetTextValue("CLI.ServerStarted"); } if (!Netplay.UseUPNP) { return; } try { Netplay.OpenPort(Netplay.ListenPort); } catch (Exception ex) { } }
public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { int sectionX = Netplay.GetSectionX((int)(position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(position.Y / 16f)); int num = 0; for (int i = sectionX - fluff; i < sectionX + fluff + 1; i++) { for (int j = sectionY - fluff; j < sectionY + fluff + 1; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.Clients[playerIndex].TileSections[i, j]) { num++; } } } if (num <= 0) { return; } int num2 = num; NetMessage.SendData(9, playerIndex, -1, Lang.inter[44].ToNetworkText(), num2); Netplay.Clients[playerIndex].StatusText2 = Language.GetTextValue("Net.IsReceivingTileData"); Netplay.Clients[playerIndex].StatusMax += num2; _pendingSectionFraming.Clear(); for (int k = sectionX - fluff; k < sectionX + fluff + 1; k++) { for (int l = sectionY - fluff; l < sectionY + fluff + 1; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.Clients[playerIndex].TileSections[k, l]) { NetMessage.SendSection(playerIndex, k, l); _pendingSectionFraming.Add(new Point(k, l)); } } } foreach (Point item in _pendingSectionFraming) { NetMessage.SendData(11, playerIndex, -1, null, item.X, item.Y, item.X, item.Y); } }
private static void OnConnectionAccepted(ISocket client) { int nextOpenClientSlot = Netplay.FindNextOpenClientSlot(); if (nextOpenClientSlot != -1) { Netplay.Clients[nextOpenClientSlot].Reset(); Netplay.Clients[nextOpenClientSlot].Socket = client; } else { lock (Netplay.fullBuffer) Netplay.KickClient(client, NetworkText.FromKey("CLI.ServerIsFull")); } if (Netplay.FindNextOpenClientSlot() != -1) { return; } Netplay.StopListening(); Netplay.IsListening = false; }
public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { int num = playerIndex; int sectionX = Netplay.GetSectionX((int)(position.X / 16f)); int sectionY = Netplay.GetSectionY((int)(position.Y / 16f)); int num1 = 0; for (int i = sectionX - fluff; i < sectionX + fluff + 1; i++) { for (int j = sectionY - fluff; j < sectionY + fluff + 1; j++) { if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.Clients[num].TileSections[i, j]) { num1++; } } } if (num1 > 0) { int num2 = num1; Netplay.Clients[num].StatusText2 = "is receiving tile data"; RemoteClient clients = Netplay.Clients[num]; clients.StatusMax = clients.StatusMax + num2; NetMessage.SendData(9, num, -1, Lang.inter[44], num2, 0f, 0f, 0f, 0, 0, 0); for (int k = sectionX - fluff; k < sectionX + fluff + 1; k++) { for (int l = sectionY - fluff; l < sectionY + fluff + 1; l++) { if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.Clients[num].TileSections[k, l]) { NetMessage.SendSection(num, k, l, false); NetMessage.SendData(11, num, -1, "", k, (float)l, (float)k, (float)l, 0, 0, 0); } } } } }
public static void CheckSection(int playerIndex, Vector2 position, int fluff = 1) { int index1 = playerIndex; int sectionX = Netplay.GetSectionX((int)((double)position.X / 16.0)); int sectionY1 = Netplay.GetSectionY((int)((double)position.Y / 16.0)); int num = 0; for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (int index3 = sectionY1 - fluff; index3 < sectionY1 + fluff + 1; ++index3) { if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, index3]) { ++num; } } } if (num <= 0) { return; } int number = num; NetMessage.SendData(9, index1, -1, Lang.inter[44], number, 0.0f, 0.0f, 0.0f, 0, 0, 0); Netplay.Clients[index1].StatusText2 = "is receiving tile data"; Netplay.Clients[index1].StatusMax += number; for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2) { for (int sectionY2 = sectionY1 - fluff; sectionY2 < sectionY1 + fluff + 1; ++sectionY2) { if (index2 >= 0 && index2 < Main.maxSectionsX && (sectionY2 >= 0 && sectionY2 < Main.maxSectionsY) && !Netplay.Clients[index1].TileSections[index2, sectionY2]) { NetMessage.SendSection(index1, index2, sectionY2, false); NetMessage.SendData(11, index1, -1, "", index2, (float)sectionY2, (float)index2, (float)sectionY2, 0, 0, 0); } } } }
private static void ClosePort(int port) { string localIpAddress = Netplay.GetLocalIPAddress(); bool flag = false; if (Netplay._mappings == null) { return; } foreach (IStaticPortMapping mapping in Netplay._mappings) { if (mapping.InternalPort == port && mapping.InternalClient == localIpAddress && mapping.Protocol == "TCP") { flag = true; } } if (flag) { return; } // ISSUE: reference to a compiler-generated method Netplay._mappings.Remove(port, "TCP"); }