- 移除旧版全局变量定义,采用Vue Router管理页面跳转 - 新增配置文件统一管理游戏名称和注册码设置 -优化加载条逻辑,使用onMounted确保DOM元素正确获取 - 添加服务端配置接口,动态加载游戏配置信息 - 升级依赖包,引入vue-router支持单页应用 - 调整项目结构,分离服务器端代码至独立目录 - 配置Vite代理转发API请求到本地开发服务器 - 更新package.json脚本命令,支持前后端联合调试 - 引入pnpm workspace管理模式,提升多包协作效率
493 lines
15 KiB
JavaScript
493 lines
15 KiB
JavaScript
let host = window.location.hostname || '100.88.157.105';
|
||
let port = 80;
|
||
|
||
const account = getQueryString('account'),
|
||
token = getQueryString('token'),
|
||
noLogin = !account || !token;
|
||
|
||
if (noLogin) {
|
||
setTimeout(function () {
|
||
loadBarClear();
|
||
loadBarFull();
|
||
setTimeout(function () {
|
||
window.location.href = '/login';
|
||
}, randomRange(250, 500));
|
||
}, 1e3);
|
||
}
|
||
|
||
window['gameName'] = '夜风冰雪';
|
||
window['gameLogo'] = 'LOGO6';
|
||
|
||
// 请勿更改
|
||
window['game'] = 'YFBX';
|
||
window['pf'] = 'yfbx';
|
||
window['pfID'] = 10001;
|
||
|
||
window['userInfo'] = {
|
||
'account': account,
|
||
'token': token,
|
||
'openID': md5(account + window['game'] + window['pfID']).toUpperCase(),
|
||
'cm': 1,
|
||
'adult': 0
|
||
};
|
||
|
||
// 检测 Tampermonkey 插件
|
||
function checkTampermonkey() {
|
||
setTimeout(() => {
|
||
const TampermonkeyVars = ["unsafeWindow", "GM_info"]
|
||
if (!TampermonkeyVars.every(e => typeof window[e] == 'undefined')) {
|
||
// 如果检测到 Tampermonkey 插件,执行以下代码
|
||
alert('检测到您正在使用 Tampermonkey 插件,本网站禁止使用此类插件!');
|
||
// 可以选择阻止页面访问或其他操作
|
||
window.location.href = '/login'; // 将用户重定向到空白页
|
||
} else checkTampermonkey()
|
||
}, 5000)
|
||
}
|
||
|
||
checkTampermonkey()
|
||
|
||
// 游戏个性设置: 设备/版本/界面/NPC参数
|
||
window['device'] = 0; // 客户端设备(一般无需更改): 0=自适应, 1=PC端界面, 2=移动端界面
|
||
window['gameMode'] = 0; // 版本玩法: 0=三职业, 1=单职业(游戏内仅出现战士职业装备)
|
||
window['uiStyle'] = 1; // 血球特效: 0=默认, 1=龙头动态火焰特效
|
||
window['npcStyle'] = 1; // NPC特效: 0=默认, 1=微变版本NPC动态特效
|
||
window['specialId'] = 2; // 打金服ID
|
||
window['withdraw'] = {'sid': 1, 'type': 3, 'ratio': 10000}; // 提现
|
||
|
||
window['isShowGongGao'] = true;
|
||
window['isAutoShowGongGao'] = !getCookie('auto_show_notice') ? (setCookie('auto_show_notice', 1, 1), true) : false;
|
||
window['isMicro'] = window['pfID'];
|
||
window['selectServer'] = true;
|
||
window['fontFamily'] = 'Arial';
|
||
window['loginType'] = 1; // 登录类型 0:测试 1:正式
|
||
window['loginWay'] = 1;
|
||
|
||
window['isReport'] = 0; // 是否上报后台
|
||
window['isReportPF'] = 0; // 是否上报渠道
|
||
window['isDisablePay'] = 0; // 是否关闭充值
|
||
window['loginView'] = 'app.MainLoginView';
|
||
|
||
// 相关URL
|
||
window['webHost'] = host;
|
||
window['serviceListdUrl'] = '/server';
|
||
window['setServiceListdUrl'] = '/server';
|
||
window['payUrl'] = '/pay';
|
||
window['apiUrl'] = '/api';
|
||
window['orderUrl'] = '/api?act=order';
|
||
window['reportUrl'] = '/api?act=report'; // 上报接口
|
||
window['errorReportUrl'] = '/api?act=report&do=error';// 错误上报接口
|
||
window['checkUrl'] = '/api?act=check'; // 验证URL
|
||
window['versionUrl'] = '/api?act=version'; // 请求客户端版本
|
||
window['getActorInfoUrl'] = '/api?act=actor';
|
||
window['roleInfoUrl'] = '/api?act=role';
|
||
window['gongGaoUrl'] = '/notice.txt';
|
||
|
||
// 客服信息
|
||
window['kfQQ'] = '123456';
|
||
window['kfWX'] = '123456';
|
||
window['kfQQUrl'] = 'https://127.0.0.1';
|
||
window['kfQQGroupUrl'] = 'https://127.0.0.1';
|
||
|
||
window['gameVerTxt1'] = '审批文号:新广出审[2022]007号 出版物号:ISBN 001-1-0001-0001-1 著作权人:XX信息科技有限公司';
|
||
window['gameVerTxt2'] = '出版单位:XX信息科技有限公司 运营单位:XX信息科技有限公司';
|
||
window['gameVerTxt3'] = '健康游戏忠告:抵制不良游戏,拒绝盗版游戏。注意自我保护,谨防受骗上当。适度游戏益脑,沉迷游戏伤身。合理安排时间,享受健康生活。';
|
||
|
||
window['publicRes'] = 'https://cdn-cq-res.kubbo.cn/';
|
||
const arr = ['loading_1_jpg', 'loading_1_jpg', 'mp_jzjm_png', 'mp_jzjm2_png'];
|
||
window['gameLoadImg'] = !getCookie('first_loading') ? (setCookie('first_loading', 1), arr[0]) : arr[randomRange(0, 4)];
|
||
window['version1'] = 'zjt1_png';
|
||
window['version2'] = 'zjt2_png';
|
||
window['version3'] = 'zjt3_png';
|
||
|
||
window['resVersion'] = '1';
|
||
window['thmVersion'] = '1';
|
||
window['tableVersion'] = '1.2.80';
|
||
window['mainVersion'] = '1.2.2';
|
||
|
||
window['isDebug'] = false;
|
||
const isJsDebug = false;
|
||
|
||
// 设置标题
|
||
//document.title = window['gameName'];
|
||
|
||
function reporting(type, result) {
|
||
if (noLogin) return;
|
||
|
||
if (window['isReport'] && window['reportUrl']) {
|
||
let loginType = window['loginWay'] ? 1 : 0;
|
||
let msgInfo = {
|
||
type: type,
|
||
counter: window['pfID'],
|
||
env: window['game'] + '|' + loginType,
|
||
time: Date.parse(new Date().toString()) / 1000,
|
||
result: result
|
||
};
|
||
|
||
msgInfo['data'] = {
|
||
uid: window['userInfo']['uid'],
|
||
serverAlias: window['userInfo']['server']
|
||
};
|
||
|
||
const str = JSON.stringify(msgInfo);
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.onreadystatechange = function () { //服务器返回值的处理函数,此处使用匿名函数进行实现
|
||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||
//
|
||
}
|
||
};
|
||
xhr.open('GET', window['reportUrl'] + '&msg=' + str, true); //提交get请求到服务器
|
||
xhr.send(null);
|
||
}
|
||
}
|
||
|
||
function onerrorFunction(error, uid) {
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.open('POST', window['checkUrl'] + window.location.search, true);//提交get请求到服务器
|
||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||
let params = 'pfID=' + window['pfID'] + '&uid=' + uid + '&error=' + error;
|
||
xhr.open('GET', window['errorReportUrl'] + '&' + params, true);//提交get请求到服务器
|
||
xhr.send(null);
|
||
}
|
||
|
||
window.onerror = function (message, url, line) {
|
||
let str = "Message : " + message + "\nURL : " + url + "\nLine Number : " + line;
|
||
this.onerrorFunction(str, 0);
|
||
alert(str);
|
||
}
|
||
|
||
//1.平台参数格式化
|
||
if (!noLogin) {
|
||
if (window['loginType']) {
|
||
switch (window['pfID']) {
|
||
case 10001:
|
||
var urlData = window.location.search;
|
||
if (urlData.indexOf('?') != -1) {
|
||
urlData = urlData.substr(1);
|
||
var strs = urlData.split('&');
|
||
for (var i = 0; i < strs.length; i++) {
|
||
window['userInfo'][strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
// 测试
|
||
}
|
||
} else {
|
||
var urlData = window.location.search;
|
||
if (urlData.indexOf('?') != -1) {
|
||
urlData = urlData.substr(1);
|
||
var strs = urlData.split('&');
|
||
for (var i = 0; i < strs.length; i++) {
|
||
window['userInfo'][strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//2.登录验证
|
||
function loginFunction() {
|
||
//alert('维护中');
|
||
//return;
|
||
|
||
if (noLogin) return;
|
||
|
||
// window['userInfo']['serverInfo'] = serverInfo;
|
||
//1.平台验证
|
||
if (window['loginType']) {
|
||
switch (window['pfID']) {
|
||
case 10001:
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.onreadystatechange = function () { // 服务器返回值的处理函数,此处使用匿名函数进行实现
|
||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||
//console.log(xhr.responseText);
|
||
const obj = JSON.parse(xhr.responseText);
|
||
//验证成功
|
||
if (0 == obj.code) {
|
||
reporting(10001, 1);
|
||
start();
|
||
} else {
|
||
loadError = true;
|
||
reporting(10001, 0);
|
||
const errorMsg = obj.msg ? obj.msg : '通行证验证失败!',
|
||
label = document.getElementById('label');
|
||
if (label) {
|
||
const linkHtml = '<span class="font_small"><a onClick="window.history.back()" class="link_color">点击返回</a> / <a onClick="window.location.reload()" class="link_color">尝试刷新</a></span>';
|
||
label.innerHTML = errorMsg + linkHtml;
|
||
} else {
|
||
alert(filterHTML(errorMsg));
|
||
}
|
||
}
|
||
}
|
||
};
|
||
xhr.open('GET', window['checkUrl'] + '&do=verify&' + window.location.search.substr(1), true); //提交get请求到服务器
|
||
xhr.send(null);
|
||
break;
|
||
}
|
||
} else {
|
||
reporting(10001, 1);
|
||
start();
|
||
// window['checkFunction']();//检测上报
|
||
// window['checkSuccess']();
|
||
}
|
||
}
|
||
|
||
//3.支付
|
||
function payFunction(param) {
|
||
console.log(param);
|
||
window.open('./pay/?productId=' + param.productId + '&productName=' + param.productName + '&amount=' + param.amount + '&actorid=' + param.gameExtra + '&serverId=' + param.serverId, '_blank');
|
||
}
|
||
|
||
//4.工具类
|
||
function callJsFunction(msg) {
|
||
if (msg && msg['type']) {
|
||
switch (msg['type']) {
|
||
case 'showGame':
|
||
showGame();
|
||
break;
|
||
case 'showLoadProgress':
|
||
showLoadProgress(msg['progress'], msg['des']);
|
||
break;
|
||
default:
|
||
//测试
|
||
}
|
||
}
|
||
}
|
||
|
||
let jobAry = ['', '战士', '法师', '战士']
|
||
|
||
function ReportingFunction(msg) {
|
||
if (msg && msg) {
|
||
if (msg['type'] == 12 || msg['type'] == 1000) { //等级上报
|
||
//创建xhr对象
|
||
let reportingUrl = window['reportUrl'];
|
||
reportingUrl += '&do=' + encodeURIComponent('game_profile');
|
||
reportingUrl += '&udbid=' + encodeURIComponent(1024009155 + '');
|
||
reportingUrl += '&gam=' + encodeURIComponent(window['game'] + '');
|
||
reportingUrl += '&pas=';
|
||
reportingUrl += '&gse=' + encodeURIComponent('s1');
|
||
reportingUrl += '&pro=' + encodeURIComponent('logingame');
|
||
reportingUrl += '&ya_appid=' + encodeURIComponent('udblogin');
|
||
let json_data = {
|
||
game_event: msg['type'] == 12 ? 'new_role' : 'level_change',
|
||
role_name: msg.data['roleName'],
|
||
role_level: msg.data['level'] + '',
|
||
fight_cap: '',
|
||
sex: msg.data['sex'] > 0 ? 'f' : 'm',
|
||
job: jobAry[msg.data['job']],
|
||
partner: '',
|
||
equip: msg.data['guildName']
|
||
}
|
||
json_data = JSON.stringify(json_data);
|
||
reportingUrl += '&json_data=' + encodeURIComponent(json_data);
|
||
// json_data = { "role_level": "11", "role_name": "s1.虞鹏天", "game_event": "level_change", "fight_cap": "1371", "job": "1" }
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.onreadystatechange = function () { //服务器返回值的处理函数,此处使用匿名函数进行实现
|
||
if (xhr.readyState == 4 && xhr.status == 200) { //
|
||
//var obj = JSON.parse(xhr.responseText);
|
||
}
|
||
};
|
||
xhr.open('GET', reportingUrl, true); //提交get请求到服务器
|
||
xhr.send(null);
|
||
}
|
||
}
|
||
}
|
||
|
||
//6.屏蔽右键
|
||
document.onkeydown = function () {
|
||
// var e = window.event || arguments[0];
|
||
//F12
|
||
// if (e.keyCode == 123) {
|
||
// return false;
|
||
// //Ctrl+Shift+I
|
||
// } else if ((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
|
||
// return false;
|
||
// //Shift+F10
|
||
// } else if ((e.shiftKey) && (e.keyCode == 121)) {
|
||
// return false;
|
||
// //Ctrl+U
|
||
// } else if ((e.ctrlKey) && (e.keyCode == 85)) {
|
||
// return false;
|
||
// }
|
||
};
|
||
|
||
/**
|
||
* 反馈
|
||
*/
|
||
function feedbackFunction(info) {
|
||
removeIfram();
|
||
let msgInfo = {
|
||
act: 'feedback',
|
||
game: window['game'],
|
||
platform: window['pf'],
|
||
server: window['userInfo']['server'],
|
||
uid: info['uid'],
|
||
rolename: info['rolename'],
|
||
ts: Date.parse(new Date().toString()) / 1000
|
||
};
|
||
msgInfo['sign'] = new md5().hex_md5((msgInfo.game + msgInfo.platform + msgInfo.server + msgInfo.uid + msgInfo.rolename + msgInfo.ts + 123456));
|
||
let param = '';
|
||
for (let key in msgInfo) {
|
||
param += key + '=' + msgInfo[key] + '&'
|
||
}
|
||
param = param.substring(0, param.length - 1)
|
||
let srcStr = '/api?' + param;
|
||
const div = document.createElement('div');
|
||
div.id = 'iframDiv';
|
||
div.innerHTML = '<iframe id="main" scrolling="no" noresize="true" frameborder="0" style="width: 90%;height: 90%;padding-left:5%;padding-top:2%;" src=' + srcStr + '></iframe>';
|
||
// div.style = 'position: relative; width:100%; height:100%;background: rgba(0, 0, 0, 0.5);';
|
||
div.style.position = 'relative';
|
||
div.style.width = '100%';
|
||
div.style.height = '100%';
|
||
div.style.background = 'rgba(0, 0, 0, 0.5)';
|
||
document.body.appendChild(div);
|
||
//创建关闭按钮
|
||
let div2 = document.createElement('div');
|
||
div2.id = 'btnDiv';
|
||
div2.innerHTML = '<img id="closeImg" src="static/img/close_btn.jpg?v=1" height="50" width="50" />'
|
||
// div2.style = 'position: absolute;right:0px;top:0px;width:50px;height:50px';
|
||
div2.style.position = 'absolute';
|
||
div2.style.right = '0px';
|
||
div2.style.top = '0px';
|
||
div2.style.width = '50px';
|
||
div2.style.height = '50px';
|
||
div.appendChild(div2);
|
||
const closeImg = document.getElementById('closeImg');
|
||
closeImg.onclick = removeIfram;
|
||
// onloadFunction();
|
||
}
|
||
|
||
// 防沉迷
|
||
function IdCardFunction() {
|
||
window.open();
|
||
}
|
||
|
||
function addQQGrp() {
|
||
window.open(window['kfQQGroupUrl']);
|
||
}
|
||
|
||
//下载YY游戏大厅
|
||
function downYYGameHallFun() {
|
||
window.open();
|
||
}
|
||
|
||
//开通会员
|
||
function openYYVip() {
|
||
window.open();
|
||
}
|
||
|
||
//开超玩会员
|
||
function openChaoWanVip() {
|
||
window.open();
|
||
}
|
||
|
||
function removeIfram() {
|
||
let div = document.getElementById('iframDiv');
|
||
if (div) {
|
||
document.body.removeChild(div);
|
||
}
|
||
div = document.getElementById('btnDiv');
|
||
if (div) {
|
||
document.body.removeChild(div);
|
||
}
|
||
}
|
||
|
||
document.oncontextmenu = () => false;
|
||
|
||
//加载项目工程
|
||
const loadScript = function (list, callback) {
|
||
let loaded = 0;
|
||
const loadNext = function () {
|
||
loadSingleScript(list[loaded], function () {
|
||
loaded++;
|
||
if (loaded >= list.length) {
|
||
callback();
|
||
} else {
|
||
loadNext();
|
||
}
|
||
});
|
||
};
|
||
loadNext();
|
||
};
|
||
|
||
let loadTimes = 0;
|
||
let jsScr = '';
|
||
|
||
window['loadScript'] = loadScript;
|
||
|
||
var loadSingleScript = function (src, callback) {
|
||
if (jsScr != src) {
|
||
loadTimes = 0;
|
||
}
|
||
|
||
if (src.indexOf('lib') > -1 || src.indexOf('main') > -1) {
|
||
const mainSuffix = getQueryString('mainSuffix');
|
||
if (mainSuffix) {
|
||
src = src.replace('.js', mainSuffix + '.js');
|
||
}
|
||
src += '?v=' + (isJsDebug ? Math.random() : window['mainVersion']);
|
||
}
|
||
|
||
jsScr = src;
|
||
|
||
const s = document.createElement('script');
|
||
s.type = 'text/javascript';
|
||
s.async = false;
|
||
s.src = src;
|
||
|
||
s.addEventListener('load', function () {
|
||
s.parentNode.removeChild(s);
|
||
s.removeEventListener('load', arguments.callee, false);
|
||
callback();
|
||
}, false);
|
||
|
||
s.addEventListener('error', function () {
|
||
s.parentNode.removeChild(s);
|
||
s.removeEventListener('load', arguments.callee, false);
|
||
loadTimes++;
|
||
if (loadTimes > 5) {
|
||
alert("主程序文件加载失败,请检测网络刷新游戏!\n " + src);
|
||
} else {
|
||
setTimeout(function () {
|
||
loadSingleScript(src, callback);
|
||
}, 2000);
|
||
}
|
||
}, false);
|
||
document.body.appendChild(s);
|
||
};
|
||
|
||
//开始启动游戏
|
||
function start() {
|
||
//alert('维护中');
|
||
//return;
|
||
|
||
const xhr = new XMLHttpRequest();
|
||
xhr.open('GET', './manifest.json?v=1.1.1.2', true); // '?v=' + Math.random()
|
||
|
||
xhr.addEventListener('load', function () {
|
||
const manifest = JSON.parse(xhr.response);
|
||
const list = manifest.initial.concat(manifest.game);
|
||
window['gameAppJS'] = manifest['gameAppJS'];
|
||
loadScript(list, function () {
|
||
egret.runEgret({
|
||
renderMode: 'webgl',
|
||
audioType: 0,
|
||
calculateCanvasScaleFactor: function (context) {
|
||
const backingStore = context.backingStorePixelRatio ||
|
||
context.webkitBackingStorePixelRatio ||
|
||
context.mozBackingStorePixelRatio ||
|
||
context.msBackingStorePixelRatio ||
|
||
context.oBackingStorePixelRatio ||
|
||
context.backingStorePixelRatio || 1;
|
||
return (window.devicePixelRatio || 1) / backingStore;
|
||
}
|
||
});
|
||
});
|
||
});
|
||
xhr.send(null);
|
||
}
|
||
|
||
//上报
|
||
reporting(10000, 1);
|
||
|
||
loginFunction();
|