import { isTest, mainConfig } from './Config'; export var allBaseNet = { usa: '-z1-test.cebg.games', japan: '-z2-test.cebg.games', singapore: '-z3-test.cebg.games', turkey: '-z4-test.cebg.games', }; isDevEnv(); isExamining(); function isDevEnv() { return true; } function isExamining() { if (!isDevEnv() && isTest && mainConfig.packageid != 0) { return true; } else { return false; } } function getDevEnvUrlSuffix() { //'-test.kingsome.cn' return atob('LXRlc3Qua2luZ3NvbWUuY24='); } function getExaminingUrlSuffix() { return '-test.cebg.games'; } function getUrlSuffix() { let urlSuffix = '-z3-test.cebg.games'; if (isDevEnv()) { urlSuffix = getDevEnvUrlSuffix(); } else if (isExamining()) { urlSuffix = getExaminingUrlSuffix(); } return urlSuffix; } 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) + '&_version=' + encodeURIComponent(mainConfig.version) + '&_hotfixversion=' + encodeURIComponent(mainConfig.hotfixVersion) + '&_packageid=' + encodeURIComponent(mainConfig.packageid) ); } export function getNormalApiUrl(name) { return ( functionNet[name] + getUrlSuffix() + '/webapp/index.php?' + getCommonParam() ); } export function getExaminingUrl() { return ( functionNet['login'] + '-z3-test.cebg.games' + '/webapp/index.php?' + getCommonParam() ); } export function getRelationUrl() { return functionNet['relation'] + getUrlSuffix() + '/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' + getDevEnvUrlSuffix() + '/websocket'; } if (isExamining()) { return 'wss://game2006' + getExaminingUrlSuffix() + '/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