using System; using System.Drawing; using System.IO; using System.Net; using System.Runtime.CompilerServices; namespace TeslaConsole; [Serializable] public class Pod : IDisposable { [NonSerialized] private EventHandler mOnOnlineChanged; private Guid mId = Guid.NewGuid(); private IPAddress mIPAddress = IPAddress.Any; private IPAddress mGateway = IPAddress.Any; private IPAddress mDns = IPAddress.Any; private IPAddress mSubnet = IPAddress.Any; private string mHostName = ""; private byte[] mKey; private byte[] mMacAddress; private string mName; private string mPodArtPath; private HostType mHostType; private bool mOnline; [NonSerialized] private Image mPodArtImage; [NonSerialized] private MungaGame mMungaGame; public Guid ID { get { return mId; } set { mId = value; } } public bool IsLocal { get { if (mKey != null) { return mKey.Length > 0; } return false; } } public IPAddress IPAddress { get { return mIPAddress; } set { mIPAddress = value; } } public IPAddress DNS { get { return mDns; } set { mDns = value; } } public IPAddress Gateway { get { return mGateway; } set { mGateway = value; } } public IPAddress Subnet { get { return mSubnet; } set { mSubnet = value; } } public string HostName { get { return mHostName; } set { mHostName = value; } } public byte[] Key { get { return mKey; } set { mKey = value; } } public string Name { get { return mName; } set { mName = value; } } public byte[] MacAddress { get { return mMacAddress; } set { mMacAddress = value; } } public string PodArtFilePath { get { return mPodArtPath; } set { mPodArtPath = value; } } public HostType HostType { get { return mHostType; } set { mHostType = value; } } public Image PodArtImage { get { if (mPodArtImage == null) { try { if (mPodArtPath == null || !File.Exists(mPodArtPath)) { return null; } mPodArtImage = Image.FromFile(mPodArtPath); } catch { } } return mPodArtImage; } } public bool Online { get { return mOnline; } set { if (value != mOnline) { mOnline = value; if (mOnOnlineChanged != null) { mOnOnlineChanged(this, EventArgs.Empty); } } } } public MungaGame MungaGame { get { if (mMungaGame == null) { mMungaGame = new MungaGame(this); } return mMungaGame; } } public event EventHandler OnOnlineChanged { [MethodImpl(MethodImplOptions.Synchronized)] add { mOnOnlineChanged = (EventHandler)Delegate.Combine(mOnOnlineChanged, value); } [MethodImpl(MethodImplOptions.Synchronized)] remove { mOnOnlineChanged = (EventHandler)Delegate.Remove(mOnOnlineChanged, value); } } public Pod() { mMungaGame = new MungaGame(this); } public Pod Clone() { Pod pod = new Pod(); pod.mId = mId; pod.mIPAddress = mIPAddress; pod.mGateway = mGateway; pod.mDns = mDns; pod.mSubnet = mSubnet; pod.mHostName = mHostName; pod.mKey = mKey; pod.mMacAddress = mMacAddress; pod.mName = mName; pod.mPodArtPath = mPodArtPath; pod.mHostType = mHostType; pod.mOnline = mOnline; pod.mPodArtImage = mPodArtImage; pod.mMungaGame = mMungaGame; return pod; } public bool MacAddressEquals(byte[] macAddress) { if (mMacAddress == null) { return macAddress == null; } if (mMacAddress.Length != macAddress.Length) { return false; } for (int i = 0; i < macAddress.Length; i++) { if (mMacAddress[i] != macAddress[i]) { return false; } } return true; } ~Pod() { Dispose(); } public void Dispose() { if (mPodArtImage != null) { mPodArtImage.Dispose(); } } }