pubgv3/assets/scripts/BaseNet.js
guoqing.zhu 7d1b9146dd update
2022-05-30 19:46:41 +08:00

187 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// game2006api-z1-test.xxx.xx
// game2006-z1-test.xxx.xx
// game2006-z1-test-1.xxx.xx
// -z1-test.cebg.gamesusa
// -z2-test.cebg.gamesjp
// -z3-test.cebg.gamessg
// -z4-test.cebg.gamestk
// game2006-z1-test-n1.cebg.games
// https://game2006ap-test.kingsome.cn
export var allBaseNet = {
usa: '-z1-test.cebg.games',
japan: '-z2-test.cebg.games',
singapore: '-z3-test.cebg.games',
turkey: '-z4-test.cebg.games',
};
isDevEnv();
function isDevEnv() {
return true
// var toreturn = false
// if(cc.debug){
// return true;
// }
// return false
}
if (isDevEnv()) {
allBaseNet = {
usa: '-test.kingsome.cn',
japan: '-test.kingsome.cn',
singapore: '-test.kingsome.cn',
turkey: '-test-kingsome.cn',
};
}
const netIdHash = (function () {
const result = {};
for (let key in allBaseNet) {
const url = allBaseNet[key];
const zid = extractZid(url);
result[zid] = {
name: key,
url: url,
};
}
return result;
})();
const functionNet = {
login: 'https://login', //
service: 'https://service', //
gamelog: 'https://gamelog', //
cloud: 'https://cloud', //
gamemail: 'https://gamemail',
notify: 'https://notify',
stat: 'https://stat', //
relation: 'wss://relation', //
//game
gameapi: 'https://game2006api',
game: 'wss://game2006',
};
function getCommonParam() {
let os = '';
if (cc.sys.os == cc.sys.OS_ANDROID) {
os = 'android';
} else if (cc.sys.os == cc.sys.OS_IOS) {
os = 'ios';
} else {
os = cc.sys.os;
}
return (
'_net=' +
encodeURIComponent(localStorage.getItem('currentNet')) +
'&_os=' +
encodeURIComponent(os)
);
}
export function getNormalApiUrl(name) {
return (
functionNet[name] +
(isDevEnv() ? '-test.kingsome.cn' : '-z3-test.cebg.games') +
'/webapp/index.php?' +
getCommonParam()
);
}
export function getExaminingUrl() {
return (
functionNet['login'] +
(isDevEnv() ? '-test.kingsome.cn' : '-z3-test.cebg.games') +
'/webapp/index.php?' +
getCommonParam()
);
}
export function getRelationUrl() {
return (
functionNet['relation'] +
(isDevEnv() ? '-test.kingsome.cn' : '-z3-test.cebg.games') +
'/friend/websocket'
);
}
export function getNodeUrl() {
return (
functionNet['game'].replace('wss://', 'https://') +
localStorage.getItem('currentNet') +
'/webapp/index.php?' +
getCommonParam()
);
}
export function extractZid(url) {
if (isDevEnv()) {
return 3;
} else {
return Number(url[2]);
}
}
export function getZViewName(zid) {
switch (zid) {
case 1:
{
return 'USA';
}
break;
case 2:
{
return 'Japan';
}
break;
case 3:
{
return 'Singapore';
}
break;
case 4:
{
return 'Turkey';
}
break;
default:
{
return '';
}
break;
}
}
export function getCurrentZid() {
try {
return extractZid(localStorage.getItem('currentNet'));
} catch (err) {
return 0;
}
}
function getZUrl(zid) {
return netIdHash[zid]['url'];
}
function getZName(zid) {
return netIdHash[zid]['name'];
}
export function getGameServer(teamUuid) {
if (isDevEnv()) {
return 'wss://game2006-test.kingsome.cn/websocket';
}
const nodeId = teamUuid ? teamUuid.split('_')[0] : cc.SDKManage.NodeId;
const zid = teamUuid
? teamUuid.split('_')[1]
: extractZid(localStorage.getItem('currentNet'));
let urls = teamUuid ? getZUrl(zid) : localStorage.getItem('currentNet');
urls = urls.split('.');
urls[0] += '-n' + nodeId;
return functionNet['game'] + urls.join('.') + '/websocket';
}
// game2006 -z1-test-n1 .cebg.games