Terraria 1.3.5.3 Source Code
This commit is contained in:
commit
4b21dac4b6
503 changed files with 409032 additions and 0 deletions
14
Net/AddressType.cs
Normal file
14
Net/AddressType.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.AddressType
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public enum AddressType
|
||||
{
|
||||
Tcp,
|
||||
Steam,
|
||||
}
|
||||
}
|
106
Net/LegacyNetBufferPool.cs
Normal file
106
Net/LegacyNetBufferPool.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.LegacyNetBufferPool
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public class LegacyNetBufferPool
|
||||
{
|
||||
private const int SMALL_BUFFER_SIZE = 256;
|
||||
private const int MEDIUM_BUFFER_SIZE = 1024;
|
||||
private const int LARGE_BUFFER_SIZE = 16384;
|
||||
private static object bufferLock = new object();
|
||||
private static Queue<byte[]> _smallBufferQueue = new Queue<byte[]>();
|
||||
private static Queue<byte[]> _mediumBufferQueue = new Queue<byte[]>();
|
||||
private static Queue<byte[]> _largeBufferQueue = new Queue<byte[]>();
|
||||
private static int _smallBufferCount = 0;
|
||||
private static int _mediumBufferCount = 0;
|
||||
private static int _largeBufferCount = 0;
|
||||
private static int _customBufferCount = 0;
|
||||
|
||||
public static byte[] RequestBuffer(int size)
|
||||
{
|
||||
lock (LegacyNetBufferPool.bufferLock)
|
||||
{
|
||||
if (size <= 256)
|
||||
{
|
||||
if (LegacyNetBufferPool._smallBufferQueue.Count != 0)
|
||||
return LegacyNetBufferPool._smallBufferQueue.Dequeue();
|
||||
++LegacyNetBufferPool._smallBufferCount;
|
||||
return new byte[256];
|
||||
}
|
||||
if (size <= 1024)
|
||||
{
|
||||
if (LegacyNetBufferPool._mediumBufferQueue.Count != 0)
|
||||
return LegacyNetBufferPool._mediumBufferQueue.Dequeue();
|
||||
++LegacyNetBufferPool._mediumBufferCount;
|
||||
return new byte[1024];
|
||||
}
|
||||
if (size <= 16384)
|
||||
{
|
||||
if (LegacyNetBufferPool._largeBufferQueue.Count != 0)
|
||||
return LegacyNetBufferPool._largeBufferQueue.Dequeue();
|
||||
++LegacyNetBufferPool._largeBufferCount;
|
||||
return new byte[16384];
|
||||
}
|
||||
++LegacyNetBufferPool._customBufferCount;
|
||||
return new byte[size];
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] RequestBuffer(byte[] data, int offset, int size)
|
||||
{
|
||||
byte[] numArray = LegacyNetBufferPool.RequestBuffer(size);
|
||||
Buffer.BlockCopy((Array) data, offset, (Array) numArray, 0, size);
|
||||
return numArray;
|
||||
}
|
||||
|
||||
public static void ReturnBuffer(byte[] buffer)
|
||||
{
|
||||
int length = buffer.Length;
|
||||
lock (LegacyNetBufferPool.bufferLock)
|
||||
{
|
||||
if (length <= 256)
|
||||
LegacyNetBufferPool._smallBufferQueue.Enqueue(buffer);
|
||||
else if (length <= 1024)
|
||||
{
|
||||
LegacyNetBufferPool._mediumBufferQueue.Enqueue(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length > 16384)
|
||||
return;
|
||||
LegacyNetBufferPool._largeBufferQueue.Enqueue(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DisplayBufferSizes()
|
||||
{
|
||||
lock (LegacyNetBufferPool.bufferLock)
|
||||
{
|
||||
Main.NewText("Small Buffers: " + (object) LegacyNetBufferPool._smallBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._smallBufferCount);
|
||||
Main.NewText("Medium Buffers: " + (object) LegacyNetBufferPool._mediumBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._mediumBufferCount);
|
||||
Main.NewText("Large Buffers: " + (object) LegacyNetBufferPool._largeBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._largeBufferCount);
|
||||
Main.NewText("Custom Buffers: 0 queued of " + (object) LegacyNetBufferPool._customBufferCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PrintBufferSizes()
|
||||
{
|
||||
lock (LegacyNetBufferPool.bufferLock)
|
||||
{
|
||||
Console.WriteLine("Small Buffers: " + (object) LegacyNetBufferPool._smallBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._smallBufferCount);
|
||||
Console.WriteLine("Medium Buffers: " + (object) LegacyNetBufferPool._mediumBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._mediumBufferCount);
|
||||
Console.WriteLine("Large Buffers: " + (object) LegacyNetBufferPool._largeBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._largeBufferCount);
|
||||
Console.WriteLine("Custom Buffers: 0 queued of " + (object) LegacyNetBufferPool._customBufferCount);
|
||||
Console.WriteLine("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
Net/NetManager.cs
Normal file
82
Net/NetManager.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.NetManager
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Terraria.Localization;
|
||||
using Terraria.Net.Sockets;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public class NetManager
|
||||
{
|
||||
public static readonly NetManager Instance = new NetManager();
|
||||
private Dictionary<ushort, NetModule> _modules = new Dictionary<ushort, NetModule>();
|
||||
private ushort _moduleCount;
|
||||
|
||||
private NetManager()
|
||||
{
|
||||
}
|
||||
|
||||
public void Register<T>() where T : NetModule, new()
|
||||
{
|
||||
T obj = new T();
|
||||
NetManager.PacketTypeStorage<T>.Id = this._moduleCount;
|
||||
NetManager.PacketTypeStorage<T>.Module = obj;
|
||||
this._modules[this._moduleCount] = (NetModule) obj;
|
||||
++this._moduleCount;
|
||||
}
|
||||
|
||||
public NetModule GetModule<T>() where T : NetModule => (NetModule) NetManager.PacketTypeStorage<T>.Module;
|
||||
|
||||
public ushort GetId<T>() where T : NetModule => NetManager.PacketTypeStorage<T>.Id;
|
||||
|
||||
public void Read(BinaryReader reader, int userId)
|
||||
{
|
||||
ushort key = reader.ReadUInt16();
|
||||
if (!this._modules.ContainsKey(key))
|
||||
return;
|
||||
this._modules[key].Deserialize(reader, userId);
|
||||
}
|
||||
|
||||
public void Broadcast(NetPacket packet, int ignoreClient = -1)
|
||||
{
|
||||
for (int index = 0; index < 256; ++index)
|
||||
{
|
||||
if (index != ignoreClient && Netplay.Clients[index].IsConnected())
|
||||
this.SendData(Netplay.Clients[index].Socket, packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendToServer(NetPacket packet) => this.SendData(Netplay.Connection.Socket, packet);
|
||||
|
||||
public void SendToClient(NetPacket packet, int playerId) => this.SendData(Netplay.Clients[playerId].Socket, packet);
|
||||
|
||||
private void SendData(ISocket socket, NetPacket packet)
|
||||
{
|
||||
if (Main.netMode == 0)
|
||||
return;
|
||||
packet.ShrinkToFit();
|
||||
try
|
||||
{
|
||||
socket.AsyncSend(packet.Buffer.Data, 0, packet.Length, new SocketSendCallback(NetManager.SendCallback), (object) packet);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine(Language.GetTextValue("Error.ExceptionNormal", (object) Language.GetTextValue("Error.DataSentAfterConnectionLost")));
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendCallback(object state) => ((NetPacket) state).Recycle();
|
||||
|
||||
private class PacketTypeStorage<T> where T : NetModule
|
||||
{
|
||||
public static ushort Id;
|
||||
public static T Module;
|
||||
}
|
||||
}
|
||||
}
|
17
Net/NetModule.cs
Normal file
17
Net/NetModule.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.NetModule
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public abstract class NetModule
|
||||
{
|
||||
public abstract bool Deserialize(BinaryReader reader, int userId);
|
||||
|
||||
protected static NetPacket CreatePacket<T>(int maxSize) where T : NetModule => new NetPacket(NetManager.Instance.GetId<T>(), maxSize);
|
||||
}
|
||||
}
|
47
Net/NetPacket.cs
Normal file
47
Net/NetPacket.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.NetPacket
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.IO;
|
||||
using Terraria.DataStructures;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public struct NetPacket
|
||||
{
|
||||
private const int HEADER_SIZE = 5;
|
||||
public readonly ushort Id;
|
||||
public readonly CachedBuffer Buffer;
|
||||
|
||||
public int Length { get; private set; }
|
||||
|
||||
public BinaryWriter Writer => this.Buffer.Writer;
|
||||
|
||||
public BinaryReader Reader => this.Buffer.Reader;
|
||||
|
||||
public NetPacket(ushort id, int size)
|
||||
: this()
|
||||
{
|
||||
this.Id = id;
|
||||
this.Buffer = BufferPool.Request(size + 5);
|
||||
this.Length = size + 5;
|
||||
this.Writer.Write((ushort) (size + 5));
|
||||
this.Writer.Write((byte) 82);
|
||||
this.Writer.Write(id);
|
||||
}
|
||||
|
||||
public void Recycle() => this.Buffer.Recycle();
|
||||
|
||||
public void ShrinkToFit()
|
||||
{
|
||||
if (this.Length == (int) this.Writer.BaseStream.Position)
|
||||
return;
|
||||
this.Length = (int) this.Writer.BaseStream.Position;
|
||||
this.Writer.Seek(0, SeekOrigin.Begin);
|
||||
this.Writer.Write((ushort) this.Length);
|
||||
this.Writer.Seek(this.Length, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
}
|
19
Net/RemoteAddress.cs
Normal file
19
Net/RemoteAddress.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.RemoteAddress
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public abstract class RemoteAddress
|
||||
{
|
||||
public AddressType Type;
|
||||
|
||||
public abstract string GetIdentifier();
|
||||
|
||||
public abstract string GetFriendlyName();
|
||||
|
||||
public abstract bool IsLocalHost();
|
||||
}
|
||||
}
|
19
Net/ServerMode.cs
Normal file
19
Net/ServerMode.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.ServerMode
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
[Flags]
|
||||
public enum ServerMode : byte
|
||||
{
|
||||
None = 0,
|
||||
Lobby = 1,
|
||||
FriendsCanJoin = 2,
|
||||
FriendsOfFriends = 4,
|
||||
}
|
||||
}
|
36
Net/Sockets/ISocket.cs
Normal file
36
Net/Sockets/ISocket.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.ISocket
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public interface ISocket
|
||||
{
|
||||
void Close();
|
||||
|
||||
bool IsConnected();
|
||||
|
||||
void Connect(RemoteAddress address);
|
||||
|
||||
void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state = null);
|
||||
|
||||
void AsyncReceive(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketReceiveCallback callback,
|
||||
object state = null);
|
||||
|
||||
bool IsDataAvailable();
|
||||
|
||||
void SendQueuedPackets();
|
||||
|
||||
bool StartListening(SocketConnectionAccepted callback);
|
||||
|
||||
void StopListening();
|
||||
|
||||
RemoteAddress GetRemoteAddress();
|
||||
}
|
||||
}
|
92
Net/Sockets/SocialSocket.cs
Normal file
92
Net/Sockets/SocialSocket.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.SocialSocket
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Terraria.Social;
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public class SocialSocket : ISocket
|
||||
{
|
||||
private RemoteAddress _remoteAddress;
|
||||
|
||||
public SocialSocket()
|
||||
{
|
||||
}
|
||||
|
||||
public SocialSocket(RemoteAddress remoteAddress) => this._remoteAddress = remoteAddress;
|
||||
|
||||
void ISocket.Close()
|
||||
{
|
||||
if (this._remoteAddress == null)
|
||||
return;
|
||||
SocialAPI.Network.Close(this._remoteAddress);
|
||||
this._remoteAddress = (RemoteAddress) null;
|
||||
}
|
||||
|
||||
bool ISocket.IsConnected() => SocialAPI.Network.IsConnected(this._remoteAddress);
|
||||
|
||||
void ISocket.Connect(RemoteAddress address)
|
||||
{
|
||||
this._remoteAddress = address;
|
||||
SocialAPI.Network.Connect(address);
|
||||
}
|
||||
|
||||
void ISocket.AsyncSend(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketSendCallback callback,
|
||||
object state)
|
||||
{
|
||||
SocialAPI.Network.Send(this._remoteAddress, data, size);
|
||||
callback.BeginInvoke(state, (AsyncCallback) null, (object) null);
|
||||
}
|
||||
|
||||
private void ReadCallback(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketReceiveCallback callback,
|
||||
object state)
|
||||
{
|
||||
int size1;
|
||||
while ((size1 = SocialAPI.Network.Receive(this._remoteAddress, data, offset, size)) == 0)
|
||||
Thread.Sleep(1);
|
||||
callback(state, size1);
|
||||
}
|
||||
|
||||
void ISocket.AsyncReceive(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketReceiveCallback callback,
|
||||
object state)
|
||||
{
|
||||
new SocialSocket.InternalReadCallback(this.ReadCallback).BeginInvoke(data, offset, size, callback, state, (AsyncCallback) null, (object) null);
|
||||
}
|
||||
|
||||
void ISocket.SendQueuedPackets()
|
||||
{
|
||||
}
|
||||
|
||||
bool ISocket.IsDataAvailable() => SocialAPI.Network.IsDataAvailable(this._remoteAddress);
|
||||
|
||||
RemoteAddress ISocket.GetRemoteAddress() => this._remoteAddress;
|
||||
|
||||
bool ISocket.StartListening(SocketConnectionAccepted callback) => SocialAPI.Network.StartListening(callback);
|
||||
|
||||
void ISocket.StopListening() => SocialAPI.Network.StopListening();
|
||||
|
||||
private delegate void InternalReadCallback(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketReceiveCallback callback,
|
||||
object state);
|
||||
}
|
||||
}
|
10
Net/Sockets/SocketConnectionAccepted.cs
Normal file
10
Net/Sockets/SocketConnectionAccepted.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.SocketConnectionAccepted
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public delegate void SocketConnectionAccepted(ISocket client);
|
||||
}
|
10
Net/Sockets/SocketReceiveCallback.cs
Normal file
10
Net/Sockets/SocketReceiveCallback.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.SocketReceiveCallback
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public delegate void SocketReceiveCallback(object state, int size);
|
||||
}
|
10
Net/Sockets/SocketSendCallback.cs
Normal file
10
Net/Sockets/SocketSendCallback.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.SocketSendCallback
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public delegate void SocketSendCallback(object state);
|
||||
}
|
153
Net/Sockets/TcpSocket.cs
Normal file
153
Net/Sockets/TcpSocket.cs
Normal file
|
@ -0,0 +1,153 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.Sockets.TcpSocket
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using Terraria.Localization;
|
||||
|
||||
namespace Terraria.Net.Sockets
|
||||
{
|
||||
public class TcpSocket : ISocket
|
||||
{
|
||||
private byte[] _packetBuffer = new byte[1024];
|
||||
private int _packetBufferLength;
|
||||
private List<object> _callbackBuffer = new List<object>();
|
||||
private int _messagesInQueue;
|
||||
private TcpClient _connection;
|
||||
private TcpListener _listener;
|
||||
private SocketConnectionAccepted _listenerCallback;
|
||||
private RemoteAddress _remoteAddress;
|
||||
private bool _isListening;
|
||||
|
||||
public int MessagesInQueue => this._messagesInQueue;
|
||||
|
||||
public TcpSocket()
|
||||
{
|
||||
this._connection = new TcpClient();
|
||||
this._connection.NoDelay = true;
|
||||
}
|
||||
|
||||
public TcpSocket(TcpClient tcpClient)
|
||||
{
|
||||
this._connection = tcpClient;
|
||||
this._connection.NoDelay = true;
|
||||
IPEndPoint remoteEndPoint = (IPEndPoint) tcpClient.Client.RemoteEndPoint;
|
||||
this._remoteAddress = (RemoteAddress) new TcpAddress(remoteEndPoint.Address, remoteEndPoint.Port);
|
||||
}
|
||||
|
||||
void ISocket.Close()
|
||||
{
|
||||
this._remoteAddress = (RemoteAddress) null;
|
||||
this._connection.Close();
|
||||
}
|
||||
|
||||
bool ISocket.IsConnected() => this._connection != null && this._connection.Client != null && this._connection.Connected;
|
||||
|
||||
void ISocket.Connect(RemoteAddress address)
|
||||
{
|
||||
TcpAddress tcpAddress = (TcpAddress) address;
|
||||
this._connection.Connect(tcpAddress.Address, tcpAddress.Port);
|
||||
this._remoteAddress = address;
|
||||
}
|
||||
|
||||
private void ReadCallback(IAsyncResult result)
|
||||
{
|
||||
Tuple<SocketReceiveCallback, object> asyncState = (Tuple<SocketReceiveCallback, object>) result.AsyncState;
|
||||
asyncState.Item1(asyncState.Item2, this._connection.GetStream().EndRead(result));
|
||||
}
|
||||
|
||||
private void SendCallback(IAsyncResult result)
|
||||
{
|
||||
Tuple<SocketSendCallback, object> asyncState = (Tuple<SocketSendCallback, object>) result.AsyncState;
|
||||
try
|
||||
{
|
||||
this._connection.GetStream().EndWrite(result);
|
||||
asyncState.Item1(asyncState.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
((ISocket) this).Close();
|
||||
}
|
||||
}
|
||||
|
||||
void ISocket.SendQueuedPackets()
|
||||
{
|
||||
}
|
||||
|
||||
void ISocket.AsyncSend(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketSendCallback callback,
|
||||
object state)
|
||||
{
|
||||
this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), (object) new Tuple<SocketSendCallback, object>(callback, state));
|
||||
}
|
||||
|
||||
void ISocket.AsyncReceive(
|
||||
byte[] data,
|
||||
int offset,
|
||||
int size,
|
||||
SocketReceiveCallback callback,
|
||||
object state)
|
||||
{
|
||||
this._connection.GetStream().BeginRead(data, offset, size, new AsyncCallback(this.ReadCallback), (object) new Tuple<SocketReceiveCallback, object>(callback, state));
|
||||
}
|
||||
|
||||
bool ISocket.IsDataAvailable() => this._connection.GetStream().DataAvailable;
|
||||
|
||||
RemoteAddress ISocket.GetRemoteAddress() => this._remoteAddress;
|
||||
|
||||
bool ISocket.StartListening(SocketConnectionAccepted callback)
|
||||
{
|
||||
IPAddress address = IPAddress.Any;
|
||||
string ipString;
|
||||
if (Program.LaunchParameters.TryGetValue("-ip", out ipString) && !IPAddress.TryParse(ipString, out address))
|
||||
address = IPAddress.Any;
|
||||
this._isListening = true;
|
||||
this._listenerCallback = callback;
|
||||
if (this._listener == null)
|
||||
this._listener = new TcpListener(address, Netplay.ListenPort);
|
||||
try
|
||||
{
|
||||
this._listener.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ThreadPool.QueueUserWorkItem(new WaitCallback(this.ListenLoop));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ISocket.StopListening() => this._isListening = false;
|
||||
|
||||
private void ListenLoop(object unused)
|
||||
{
|
||||
while (this._isListening)
|
||||
{
|
||||
if (!Netplay.disconnect)
|
||||
{
|
||||
try
|
||||
{
|
||||
ISocket client = (ISocket) new TcpSocket(this._listener.AcceptTcpClient());
|
||||
Console.WriteLine(Language.GetTextValue("Net.ClientConnecting", (object) client.GetRemoteAddress()));
|
||||
this._listenerCallback(client);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
this._listener.Stop();
|
||||
}
|
||||
}
|
||||
}
|
35
Net/SteamAddress.cs
Normal file
35
Net/SteamAddress.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.SteamAddress
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using Steamworks;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public class SteamAddress : RemoteAddress
|
||||
{
|
||||
public readonly CSteamID SteamId;
|
||||
private string _friendlyName;
|
||||
|
||||
public SteamAddress(CSteamID steamId)
|
||||
{
|
||||
this.Type = AddressType.Steam;
|
||||
this.SteamId = steamId;
|
||||
}
|
||||
|
||||
public override string ToString() => "STEAM_0:" + ((ulong) this.SteamId.m_SteamID % 2UL).ToString() + ":" + ((ulong) (this.SteamId.m_SteamID - (76561197960265728L + this.SteamId.m_SteamID % 2L)) / 2UL).ToString();
|
||||
|
||||
public override string GetIdentifier() => this.ToString();
|
||||
|
||||
public override bool IsLocalHost() => Program.LaunchParameters.ContainsKey("-localsteamid") && Program.LaunchParameters["-localsteamid"].Equals(__nonvirtual (this.SteamId.m_SteamID.ToString()));
|
||||
|
||||
public override string GetFriendlyName()
|
||||
{
|
||||
if (this._friendlyName == null)
|
||||
this._friendlyName = SteamFriends.GetFriendPersonaName(this.SteamId);
|
||||
return this._friendlyName;
|
||||
}
|
||||
}
|
||||
}
|
31
Net/TcpAddress.cs
Normal file
31
Net/TcpAddress.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Decompiled with JetBrains decompiler
|
||||
// Type: Terraria.Net.TcpAddress
|
||||
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
|
||||
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
||||
|
||||
using System.Net;
|
||||
|
||||
namespace Terraria.Net
|
||||
{
|
||||
public class TcpAddress : RemoteAddress
|
||||
{
|
||||
public IPAddress Address;
|
||||
public int Port;
|
||||
|
||||
public TcpAddress(IPAddress address, int port)
|
||||
{
|
||||
this.Type = AddressType.Tcp;
|
||||
this.Address = address;
|
||||
this.Port = port;
|
||||
}
|
||||
|
||||
public override string GetIdentifier() => this.Address.ToString();
|
||||
|
||||
public override bool IsLocalHost() => this.Address.Equals((object) IPAddress.Loopback);
|
||||
|
||||
public override string ToString() => new IPEndPoint(this.Address, this.Port).ToString();
|
||||
|
||||
public override string GetFriendlyName() => this.ToString();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue