387 lines
13 KiB
C#
387 lines
13 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
public class BFGateInfo
|
|
{
|
|
public string mainDomain;
|
|
public int mainPort;
|
|
public string chatDomain;
|
|
public int chatPort;
|
|
|
|
public BFGateInfo(string mainDomain, int mainPort, string chatDomain, int chatPort)
|
|
{
|
|
this.mainDomain = mainDomain;
|
|
this.mainPort = mainPort;
|
|
this.chatDomain = chatDomain;
|
|
this.chatPort = chatPort;
|
|
}
|
|
}
|
|
|
|
public class BFHttpsInfo
|
|
{
|
|
public string mainDomain;
|
|
public int mainPort;
|
|
public BFHttpsInfo(string mainDomain, int mainPort)
|
|
{
|
|
this.mainDomain = mainDomain;
|
|
this.mainPort = mainPort;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集群类型
|
|
/// </summary>
|
|
public enum ClusterType
|
|
{
|
|
None = 0,
|
|
Normal = 1,
|
|
Review = 2,
|
|
Test = 3,
|
|
}
|
|
|
|
[Serializable]
|
|
public class CombineURL
|
|
{
|
|
public int cluster_type;
|
|
public string ugate_addr;
|
|
public string vsn_addr;
|
|
public string upay_addr;
|
|
public string uchat_addr;
|
|
public string community_web_addr;
|
|
public string community_srv_addr;
|
|
public string aics_http_addr;
|
|
public string aics_ws_addr;
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("cluster_type:{0} ugate_addr:{1} vsn_addr:{2} upay_addr:{3} uchat_addr:{4} community_web_addr:{5} community_srv_addr:{6} aics_http_addr:{7} aics_ws_addr:{8}", cluster_type, ugate_addr, vsn_addr, upay_addr, uchat_addr, community_web_addr, community_srv_addr, aics_http_addr, aics_ws_addr);
|
|
}
|
|
}
|
|
|
|
public partial class BFPlatform
|
|
{
|
|
const String LoginCenterURL = "https://b5-entrance.bigfoot-studio.link";
|
|
static Dictionary<string, string> BFLoginCenterURLDict = new Dictionary<string, string>()
|
|
{
|
|
// dev
|
|
{"com.juzu.b5.dev", "http://game.juzugame.com:3000"},
|
|
{"com.juzu.b5.dev.android", "http://game.juzugame.com:3000"},
|
|
{"com.juzu.b5.dev.ios", "http://game.juzugame.com:3000"},
|
|
|
|
// release
|
|
{"com.juzu.b5.release.android", "http://game.juzugame.com:3000"},
|
|
{"com.juzu.b5.release.ios", "http://game.juzugame.com:3000"},
|
|
|
|
// gp
|
|
{"com.idle.ko.io", "https://b5-entrance.bigfoot-studio.link"},
|
|
};
|
|
|
|
//combine url解析的数据
|
|
static ClusterType clusterType;
|
|
|
|
static BFGateInfo _channelGate;
|
|
static BFHttpsInfo _vsnUrl;
|
|
|
|
//主链接
|
|
static string mainGateUrl;
|
|
static int mainGatePort;
|
|
|
|
//聊天链接
|
|
static string chatGateUrl;
|
|
static int chatGatePort;
|
|
|
|
//版本号
|
|
static string vsnHttpUrl;
|
|
static int vsnHttpPort;
|
|
|
|
//支付中心(包含port)
|
|
static string payUrl;
|
|
|
|
//客服(包含port)
|
|
static string aicsHttpUrl;//客服http地址
|
|
static string aicsWebSocketUrl;//客服webSocket地址
|
|
|
|
//社区(包含port)
|
|
static string communityWebUrl;//社区
|
|
static string communitySrvUrl;//社区红点
|
|
|
|
//登陆中心返回的信息齐全且格式正常
|
|
static bool isLoginCenterConfigValid;//请求的域名信息是否正确
|
|
|
|
/// <summary>
|
|
/// 解析json数据 获取cluter,gate,chat,vsn,pay的地址
|
|
/// </summary>
|
|
/// <param name="json"></param>
|
|
public static void InitUrlsFromLoginCenter(string json)
|
|
{
|
|
if (!string.IsNullOrEmpty(json))
|
|
{
|
|
CombineURL urls = JsonUtility.FromJson<CombineURL>(json);
|
|
|
|
BFLog.Log("C#解析后的urls:" + urls.ToString());
|
|
|
|
clusterType = (ClusterType)urls.cluster_type;
|
|
string tmpGateUrl = urls.ugate_addr;
|
|
string tmpChatUrl = urls.uchat_addr;
|
|
string tmpVsnUrl = urls.vsn_addr;
|
|
string tmpPayUrl = urls.upay_addr;
|
|
string tmpCommunityWebUrl = urls.community_web_addr;
|
|
string tmpCommunitySrvUrl = urls.community_srv_addr;
|
|
string tmpAicsHttpUrl = urls.aics_http_addr;
|
|
string tmpAicsWebSocketUrl = urls.aics_ws_addr;
|
|
|
|
bool clusterValid = clusterType != ClusterType.None;
|
|
bool gateValid = !string.IsNullOrEmpty(tmpGateUrl);
|
|
bool chatValid = !string.IsNullOrEmpty(tmpChatUrl);
|
|
bool vsnValid = !string.IsNullOrEmpty(tmpVsnUrl);
|
|
bool payValid = !string.IsNullOrEmpty(tmpPayUrl);
|
|
bool communityWebValid = !string.IsNullOrEmpty(tmpCommunityWebUrl);
|
|
bool communitySrvValid = !string.IsNullOrEmpty(tmpCommunitySrvUrl);
|
|
bool aicsHttpValid = !string.IsNullOrEmpty(tmpAicsHttpUrl);
|
|
bool aicsWebSocketValid = !string.IsNullOrEmpty(tmpAicsWebSocketUrl);
|
|
|
|
BFLog.Log(string.Format("check valid clusterValid:{0} gateValid:{1} chatValid:{2} vsnValid:{3} payValid:{4} communityWebValid:{5} communitySrvValid:{6} aicsHttpValid:{7} aicsWebSocketValid:{8}", clusterValid, gateValid, chatValid, vsnValid, payValid, communityWebValid, communitySrvValid, aicsHttpValid, aicsWebSocketValid));
|
|
|
|
//判断参数是否正常
|
|
if (clusterValid && gateValid && chatValid && vsnValid && payValid)
|
|
{
|
|
if (IsPublishChannel()) // 正式渠道不验证社区与客服地址
|
|
{
|
|
SetLoginCenterConfigValid(true);
|
|
}
|
|
else
|
|
{
|
|
if (communityWebValid && communitySrvValid && aicsHttpValid && aicsWebSocketValid)
|
|
{
|
|
SetLoginCenterConfigValid(true);
|
|
}
|
|
else
|
|
{
|
|
SetLoginCenterConfigValid(false);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SetLoginCenterConfigValid(false);
|
|
}
|
|
|
|
//拆分域名url与port
|
|
int gatePortIndex = tmpGateUrl.LastIndexOf(':');
|
|
int chatPortIndex = tmpChatUrl.LastIndexOf(':');
|
|
int vsnPortIndex = tmpVsnUrl.LastIndexOf(':');
|
|
|
|
string gatePortStr = tmpGateUrl.Substring(gatePortIndex + 1, tmpGateUrl.Length - gatePortIndex - 1);
|
|
string chatPortStr = tmpChatUrl.Substring(chatPortIndex + 1, tmpChatUrl.Length - chatPortIndex - 1);
|
|
string vsnPortStr = tmpVsnUrl.Substring(vsnPortIndex + 1, tmpVsnUrl.Length - vsnPortIndex - 1);
|
|
|
|
int gatePort = 0;
|
|
int chatPort = 0;
|
|
int vsnPort = 0;
|
|
int.TryParse(gatePortStr, out gatePort);
|
|
int.TryParse(chatPortStr, out chatPort);
|
|
int.TryParse(vsnPortStr, out vsnPort);
|
|
|
|
string tmpGateUrlWithoutPort = tmpGateUrl.Substring(0, gatePortIndex);
|
|
string tmpChatUrlWithoutPort = tmpChatUrl.Substring(0, chatPortIndex);
|
|
string tmpVsnUrlWithoutPort = tmpVsnUrl.Substring(0, vsnPortIndex);
|
|
|
|
mainGateUrl = tmpGateUrlWithoutPort;
|
|
mainGatePort = gatePort;
|
|
chatGateUrl = tmpChatUrlWithoutPort;
|
|
chatGatePort = chatPort;
|
|
vsnHttpUrl = tmpVsnUrlWithoutPort;
|
|
vsnHttpPort = vsnPort;
|
|
|
|
//暂时保留原格式
|
|
_channelGate = new BFGateInfo(mainGateUrl, mainGatePort, chatGateUrl, chatGatePort);
|
|
_vsnUrl = new BFHttpsInfo(vsnHttpUrl, vsnHttpPort);
|
|
|
|
payUrl = tmpPayUrl;
|
|
communityWebUrl = tmpCommunityWebUrl;
|
|
communitySrvUrl = tmpCommunitySrvUrl;
|
|
aicsHttpUrl = tmpAicsHttpUrl;
|
|
aicsWebSocketUrl = tmpAicsWebSocketUrl;
|
|
|
|
BFLog.Log("解析后的地址 gate:{0} gatePort:{1} chat:{2} chatPort:{3} vsn:{4} vsnPort:{5} payUrl:{6} communityWebUrl:{7} communitySrvUrl:{8} aicsHttpUrl:{9} aicsWebSocketUrl:{10}", mainGateUrl, gatePort, chatGateUrl, chatPort, vsnHttpUrl, vsnPort, payUrl, communityWebUrl, communitySrvUrl, aicsHttpUrl, aicsWebSocketUrl);
|
|
}
|
|
else
|
|
{
|
|
BFLog.LogError("GetUrlsFromLoginCenter Error,JSON is null or empty");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得集群类型 (1-普通,2-审核,3-测试)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ClusterType GetClusterType()
|
|
{
|
|
return clusterType;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 域名信息是否请求正确
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static bool IsLoginCenterConfigValid()
|
|
{
|
|
BFLog.Log("获取 Get IsLoginCenterConfigValid:" + isLoginCenterConfigValid);
|
|
|
|
return isLoginCenterConfigValid;
|
|
}
|
|
|
|
public static void SetLoginCenterConfigValid(bool valid)
|
|
{
|
|
BFLog.Log("设置 Set IsLoginCenterConfigValid:" + valid);
|
|
|
|
isLoginCenterConfigValid = valid;
|
|
}
|
|
|
|
static string identifier;
|
|
public static string Identifier
|
|
{
|
|
get
|
|
{
|
|
if (string.IsNullOrEmpty(identifier))
|
|
{
|
|
identifier = Application.identifier;
|
|
}
|
|
return identifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否是内网渠道
|
|
/// </summary>
|
|
public static bool IsDevChannel()
|
|
{
|
|
return Identifier == "com.juzu.b5.dev" ||
|
|
Identifier == "com.juzu.b5.dev.android" ||
|
|
Identifier == "com.juzu.b5.dev.ios";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否是外网测试渠道
|
|
/// </summary>
|
|
public static bool IsReleaseChannel()
|
|
{
|
|
return Identifier == "com.juzu.b5.release.android" ||
|
|
Identifier == "com.juzu.b5.release.ios";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否是正式发布渠道
|
|
/// </summary>
|
|
public static bool IsPublishChannel()
|
|
{
|
|
return !IsDevChannel() && !IsReleaseChannel();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前渠道gate信息
|
|
/// </summary>
|
|
public static BFGateInfo GetCurrentGateInfo()
|
|
{
|
|
return _channelGate;
|
|
}
|
|
/// <summary>
|
|
/// mainGate url(无port)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetMainGateURL()
|
|
{
|
|
return mainGateUrl;
|
|
}
|
|
/// <summary>
|
|
/// mainGate port
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static int GetMainGatePort()
|
|
{
|
|
return mainGatePort;
|
|
}
|
|
/// <summary>
|
|
/// chatGate url(无port)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetChatGateURL()
|
|
{
|
|
return chatGateUrl;
|
|
}
|
|
/// <summary>
|
|
/// chatGate port
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static int GetChatGatePort()
|
|
{
|
|
return chatGatePort;
|
|
}
|
|
|
|
public static BFHttpsInfo GetVsnHttpsInfo()
|
|
{
|
|
return _vsnUrl;
|
|
}
|
|
/// <summary>
|
|
/// 版本号url(无port)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetVsnHttpURL()
|
|
{
|
|
return vsnHttpUrl;
|
|
}
|
|
/// <summary>
|
|
/// 版本号port
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static int GetVsnHttpPort()
|
|
{
|
|
return vsnHttpPort;
|
|
}
|
|
|
|
public static string GetLoginCenterURL()
|
|
{
|
|
if (BFLoginCenterURLDict.TryGetValue(Identifier, out string url))
|
|
{
|
|
return url;
|
|
}
|
|
return LoginCenterURL;
|
|
}
|
|
|
|
public static string GetPayCenterURL()
|
|
{
|
|
return payUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 社区地址
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetCommunityWebURL()
|
|
{
|
|
return communityWebUrl;
|
|
}
|
|
/// <summary>
|
|
/// 社区红点地址
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetCommunitySrvURL()
|
|
{
|
|
return communitySrvUrl;
|
|
}
|
|
|
|
public static string GetAicsHttpURL()
|
|
{
|
|
return aicsHttpUrl;
|
|
}
|
|
|
|
public static string GetAicsWebSocketURL()
|
|
{
|
|
return aicsWebSocketUrl;
|
|
}
|
|
}
|
|
} |