﻿// Decompiled with JetBrains decompiler
// Type: Wb.Lpw.Platform.Protocol.LocationInfo
// Assembly: Wb.Lpw.Protocol, Version=2.13.83.0, Culture=neutral, PublicKeyToken=null
// MVID: A621984F-C936-438B-B744-D121BF336087
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\Wb.Lpw.Protocol.dll

using System;
using System.Collections.Generic;
using System.Text;

namespace Wb.Lpw.Platform.Protocol
{
  [Serializable]
  public class LocationInfo : ICloneable
  {
    public long ServerId;
    public string PrivateIp;
    public string PublicIp;
    public int? PublicPort;
    public string ApplicationName;
    public int Capacity;
    public int PlayersCount;
    public bool IsFull;
    public ServerState ServerState;
    public ServerType ServerType;
    public string WorkspaceId;

    public LocationInfo()
    {
    }

    public LocationInfo(long serverId, string privateIp, string publicIp, int? publicPort, string applicationName, int capacity, int playersCount, bool isFull, ServerState serverState, ServerType serverType, string workspaceId)
    {
      this.ServerId = serverId;
      this.PrivateIp = privateIp;
      this.PublicIp = publicIp;
      this.PublicPort = publicPort;
      this.ApplicationName = applicationName;
      this.Capacity = capacity;
      this.PlayersCount = playersCount;
      this.IsFull = isFull;
      this.ServerState = serverState;
      this.ServerType = serverType;
      this.WorkspaceId = workspaceId;
    }

    public string GetServiceEventUri()
    {
      return string.Format("http://{0}:8100/{1}/ServiceEvents", (object) this.PrivateIp, (object) this.ApplicationName);
    }

    public string GetPhotonUriAsClient()
    {
      if (this.ApplicationName.Contains("Front"))
        return string.Format("photon://{0}:{1}/{2}", (object) this.PublicIp, (object) 4531, (object) this.ApplicationName);
      return string.Format("photon://{0}:{1}/{2}", (object) this.PublicIp, (object) (this.PublicPort ?? 5055), (object) this.ApplicationName);
    }

    public string GetPhotonUriAsGameServer()
    {
      return string.Format("photon://{0}:{1}/{2}", (object) this.PrivateIp, (object) 4560, (object) this.ApplicationName);
    }

    public string GetPhotonUriAsFrontServer()
    {
      return string.Format("photon://{0}:{1}/{2}", (object) this.PrivateIp, (object) 4545, (object) this.ApplicationName);
    }

    public string GetPhotonUriAsControlServer()
    {
      return string.Format("photon://{0}:{1}/{2}", (object) this.PrivateIp, (object) 4530, (object) this.ApplicationName);
    }

    public override string ToString()
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append(string.Format("ServerId({0}) ", (object) this.ServerId));
      stringBuilder.Append(string.Format("PublicIp({0}) ", (object) this.PublicIp));
      stringBuilder.Append(string.Format("PublicPort({0}) ", (object) this.PublicPort));
      stringBuilder.Append(string.Format("PrivateIp({0}) ", (object) this.PrivateIp));
      stringBuilder.Append(string.Format("ApplicationName({0}) ", (object) this.ApplicationName));
      stringBuilder.Append(string.Format("Capacity({0}) ", (object) this.Capacity));
      stringBuilder.Append(string.Format("IsFull({0}) ", (object) (bool) (this.IsFull ? 1 : 0)));
      stringBuilder.Append(string.Format("ServerState({0}) ", (object) this.ServerState));
      stringBuilder.Append(string.Format("PlayersCount({0}) ", (object) this.PlayersCount));
      return stringBuilder.ToString();
    }

    public object Clone()
    {
      return (object) new LocationInfo(this.ServerId, this.PrivateIp, this.PublicIp, this.PublicPort, this.ApplicationName, this.Capacity, this.PlayersCount, this.IsFull, this.ServerState, this.ServerType, this.WorkspaceId);
    }

    public static LocationInfo Deserialize(Dictionary<byte, object> parameters)
    {
      long serverId = (long) parameters[(byte) 1];
      string privateIp = (string) parameters[(byte) 2];
      string publicIp = (string) parameters[(byte) 3];
      string applicationName = (string) parameters[(byte) 4];
      int capacity = (int) parameters[(byte) 5];
      int playersCount = (int) parameters[(byte) 6];
      bool isFull = (bool) parameters[(byte) 7];
      ServerState serverState = (ServerState) parameters[(byte) 8];
      ServerType serverType = (ServerType) parameters[(byte) 9];
      string workspaceId = (string) parameters[(byte) 10];
      int? publicPort = new int?();
      if (parameters.ContainsKey((byte) 11))
        publicPort = new int?((int) parameters[(byte) 11]);
      return new LocationInfo(serverId, privateIp, publicIp, publicPort, applicationName, capacity, playersCount, isFull, serverState, serverType, workspaceId);
    }

    public static Dictionary<byte, object> Serialize(LocationInfo instance)
    {
      Dictionary<byte, object> dictionary = new Dictionary<byte, object>();
      dictionary.Add((byte) 1, (object) instance.ServerId);
      dictionary.Add((byte) 2, (object) instance.PrivateIp);
      dictionary.Add((byte) 3, (object) instance.PublicIp);
      dictionary.Add((byte) 4, (object) instance.ApplicationName);
      dictionary.Add((byte) 5, (object) instance.Capacity);
      dictionary.Add((byte) 6, (object) instance.PlayersCount);
      dictionary.Add((byte) 7, (object) (bool) (instance.IsFull ? 1 : 0));
      dictionary.Add((byte) 8, (object) instance.ServerState);
      dictionary.Add((byte) 9, (object) instance.ServerType);
      dictionary.Add((byte) 10, (object) instance.WorkspaceId);
      if (instance.PublicPort.HasValue)
        dictionary.Add((byte) 11, (object) instance.PublicPort);
      return dictionary;
    }
  }
}
