diff --git a/package-lock.json b/package-lock.json index bb98160..b5e6e3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "vue-loading-overlay": "^5.0.3" }, "devDependencies": { - "@types/node": "^17.0.24", "@vitejs/plugin-vue": "^2.3.0", "typescript": "^4.5.4", "vite": "^2.9.0", @@ -158,12 +157,6 @@ "@types/lodash": "*" } }, - "node_modules/@types/node": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz", - "integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==", - "dev": true - }, "node_modules/@vitejs/plugin-vue": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", @@ -1947,12 +1940,6 @@ "@types/lodash": "*" } }, - "@types/node": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.24.tgz", - "integrity": "sha512-aveCYRQbgTH9Pssp1voEP7HiuWlD2jW2BO56w+bVrJn04i61yh6mRfoKO6hEYQD9vF+W8Chkwc6j1M36uPkx4g==", - "dev": true - }, "@vitejs/plugin-vue": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", diff --git a/package.json b/package.json index 7d96b9c..b69c53f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "version": "0.0.0", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "preview": "vite preview" }, diff --git a/src/App.vue b/src/App.vue index 8315cad..278381f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -44,7 +44,7 @@ const handleClick = (tab: TabsPaneContext, event: Event) => { } .el-tabs__item { - font-size: 25px; + font-size: 18px; } #app { diff --git a/src/env.d.ts b/src/env.d.ts index aafef95..76a9812 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,8 +1,8 @@ /// declare module '*.vue' { - import type { DefineComponent } from 'vue' - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types - const component: DefineComponent<{}, {}, any> - export default component + import type { DefineComponent } from 'vue' + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types + const component: DefineComponent<{}, {}, any> + export default component } diff --git a/src/main.ts b/src/main.ts index 26cc52c..cedd9e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,15 @@ -import '@popperjs/core'; -import 'bootstrap'; -import 'bootstrap/dist/css/bootstrap.min.css'; -import ElementPlus from 'element-plus'; -import 'element-plus/dist/index.css'; -import locale from 'element-plus/lib/locale/lang/zh-tw'; -import { createApp } from 'vue'; -import App from './App.vue'; +// 引入bootstrap组件库 +import "@popperjs/core"; +import "bootstrap"; +import "bootstrap/dist/css/bootstrap.min.css"; +// 引入Element-Plus组件库 +import ElementPlus from "element-plus"; +import "element-plus/dist/index.css"; +import locale from "element-plus/lib/locale/lang/zh-tw"; +import { createApp } from "vue"; +import App from "./App.vue"; +// // 引入弹窗组件v3popup +// import V3Popup from "@components/v3popup" - -createApp(App).use(ElementPlus, { locale }).mount('#app') +createApp(App).use(ElementPlus, { locale }).mount("#app"); +// createApp(App).use(ElementPlus, { locale }).use(V3Popup).mount("#app"); diff --git a/src/script/BJ_Casino_Data.ts b/src/script/BJ_Casino_Data.ts index bf14c6b..d6a864d 100644 --- a/src/script/BJ_Casino_Data.ts +++ b/src/script/BJ_Casino_Data.ts @@ -1,12 +1,12 @@ -import moment from 'moment'; -import CSMessage from './Base/CSMessage'; -import { AccountLoginRequest } from './Base/Request/AccountRequest'; -import { AppRankHistory, AppRankInfo } from './Base/Request/RankRequest'; -import './Engine/CatanEngine/CSharp/String'; -import { INetResponse } from './Engine/CatanEngine/NetManagerV2/Core/INetResponse'; -import { NetConnector } from './Engine/CatanEngine/NetManagerV2/NetConnector'; -import { NetManager } from './Engine/CatanEngine/NetManagerV2/NetManager'; -import { Tools } from './Tools'; +import moment from "moment"; +import CSMessage from "./Base/CSMessage"; +import { AccountLoginRequest } from "./Base/Request/AccountRequest"; +import { AppRankHistory, AppRankInfo } from "./Base/Request/RankRequest"; +import "./Engine/CatanEngine/CSharp/String"; +import { INetResponse } from "./Engine/CatanEngine/NetManagerV2/Core/INetResponse"; +import { NetConnector } from "./Engine/CatanEngine/NetManagerV2/NetConnector"; +import { NetManager } from "./Engine/CatanEngine/NetManagerV2/NetManager"; +import { Tools } from "./Tools"; export class BJ_Casino_Data { @@ -56,9 +56,9 @@ export class BJ_Casino_Data { //#region get set - public get RankMagnificationData(): any[] { return this._rankMagnificationData }; + public get RankMagnificationData(): any[] { return this._rankMagnificationData; } - public get RankWinMoneyData(): any[] { return this._rankWinMoneyData }; + public get RankWinMoneyData(): any[] { return this._rankWinMoneyData; } //#endregion @@ -72,11 +72,11 @@ export class BJ_Casino_Data { this.onLoad(); } - public async onLoad() { + public async onLoad(): Promise { // CoroutineV2.Single(this.aaa()).Start(); let self: this = this; - const URL = "https://game.online-bj.com"; - const Port = "9005"; + const URL: string = "https://game.online-bj.com"; + const Port: string = "9005"; await this.ConnectAsync(URL, +Port); // 取得帳號資料 let req: AccountLoginRequest = new AccountLoginRequest("ct00000691", "4lsAyoalajm7"); @@ -87,51 +87,7 @@ export class BJ_Casino_Data { return; } await this.SendRankData(); - return; - try { - // const URL = document.getElementById("URL").value; - // const Port = document.getElementById("Port").value; - - // const URL = "wss://game.online-bj.com"; - // const Port = "9005"; - const Account = { "p": 0, "device_info": ["Windows", "Windows"], "fcm_token": "", "a": "ct00000691", "pw": "4lsAyoalajm7", "ver": "1.3.0" }; - - // const URL = "ws://192.168.5.12"; - // const Port = "9487"; - - // const URL = "ws://220.134.195.1"; - // const Port = "19005"; - // const Account = { "p": 0, "device_info": ["Windows", "Windows"], "fcm_token": "", "a": "ct00002242", "pw": "n0tfHlVuEhpO", "ver": "1.3.0" }; - if (this._ws) { - this.AddLog("中斷上一個連線"); - this._ws.close(); - } - this._ws = new WebSocket(`${URL}:${Port}`);//连接服务器 - - //连接websocket - this._ws.onopen = function (event: any, AlarmMessage: any) { - self.AddLog("已經與服務器建立了連接,當前連接狀態:" + this.readyState); - self.SendData("account.login", Account); - }; - - //websocket传输数据 - this._ws.onmessage = this.OnWebSocketMessage.bind(this); - - //websocket关闭连接 - this._ws.onclose = function (event: any) { - self.AddLog("已經與服務器斷開連接,當前連接狀態:" + this.readyState); - }; - - //websocket连接异常 - this._ws.onerror = function (event: any) { - // alert("WebSocket异常!"); - self.AddLog("WebSocket異常!"); - }; - } catch (ex) { - // alert(ex.message); - this.AddLog(ex); - } - }; + } public *aaa(): IterableIterator { console.log("aaa"); } @@ -140,20 +96,20 @@ export class BJ_Casino_Data { //#region 網路相關 - /**連線(目前沒有重連機制) */ - public async ConnectAsync(host: string, port: number) { - var url = "https://api.ipify.org/?format=json"; - var xhr = new XMLHttpRequest(); + /** 連線(目前沒有重連機制) */ + public async ConnectAsync(host: string, port: number): Promise { + var url: string = "https://api.ipify.org/?format=json"; + var xhr: XMLHttpRequest = new XMLHttpRequest(); let ip: string = ""; - xhr.onreadystatechange = function () { - if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { + xhr.onreadystatechange = function (): void { + if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) { ip = JSON.parse(xhr.responseText)["ip"]; } }; xhr.open("GET", url, true); xhr.send(); console.log("[事件]準備連線..."); - while (ip == "") { + while (ip === "") { await Tools.Sleep(1); } this._conn = new NetConnector(host, port, ip); @@ -166,13 +122,13 @@ export class BJ_Casino_Data { console.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected)); } - private _onNetDisconnected() { + private _onNetDisconnected(): void { console.log("[事件] 收到連線中斷事件"); this._conn.OnDataReceived.RemoveAllCallbacks(); // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]); } - private _onNetDataReceived(resp: INetResponse) { + private _onNetDataReceived(resp: INetResponse): void { console.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`); // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]); } @@ -181,18 +137,18 @@ export class BJ_Casino_Data { //#region Custom - public async SendRankData() { + public async SendRankData(): Promise { this.SendRankMagnificationData(); this.SendRankWinMoneyData(); } - public async SendRankMagnificationData() { + public async SendRankMagnificationData(): Promise { let req: any = null; req = new AppRankInfo(12, 2); await req.SendAsync(true); let resp: INetResponse = req.Result; if (!resp.IsValid) { - if (resp.Status == 11) { + if (resp.Status === 11) { CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); } else { CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); @@ -202,13 +158,13 @@ export class BJ_Casino_Data { await this.RankMagnificationDataCallBack(resp.Data); } - public async SendRankWinMoneyData() { + public async SendRankWinMoneyData(): Promise { let req: any = null; req = new AppRankInfo(11, 2); await req.SendAsync(true); let resp: INetResponse = req.Result; if (!resp.IsValid) { - if (resp.Status == 11) { + if (resp.Status === 11) { CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); } else { CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); @@ -218,68 +174,18 @@ export class BJ_Casino_Data { await this.RankWinMoneyDataCallBack(resp.Data); } - public SendData(Method: string, Data: any) { - let json = [Method]; - if (Data != null && Data != undefined) { - json[1] = Data; - } - - let str = JSON.stringify(json); - if (str.length > 65535) { - this.AddLog("要傳的資料太大囉"); - throw new Error('要傳的資料太大囉'); - } - - if (Data != null && Data != undefined) { - this.AddLog(`[RPC] 傳送server資料: ${Method}(${JSON.stringify(Data).replace(/\\/g, "")})`); - } else { - this.AddLog(`[RPC] 傳送server資料: ${Method}()`); - } - - let strary = this.GetBytes(str); - let buffer = new Uint8Array(4 + strary.byteLength); - let u16ary = new Uint16Array(buffer.buffer, 0, 3); - u16ary[0] = strary.byteLength; - buffer[3] = 0x01; - buffer.set(strary, 4); - this._ws.send(buffer); - } - - public ResData(Status: any, Method: any, Data: any = null) { - // let document = parent ? parent.document : document; - switch (Method) { - case "account.login": { - this.SendData("rank.info", { "t": 12, "p": 2 }); - break; - } - - case "rank.info": { - this.RankMagnificationDataCallBack(Data); - break; - } - - case "rank.history": { - this.ParseRankMagnificationData(Data); - break; - } - - default: - break; - } - } - public async RankMagnificationDataCallBack(data: any) { - let id = +data["id"]; + let id: number = +data["id"]; this._nowSearchMagnificationID = id; this._nowContestID = id; this._nowContestDate = moment().format("MM/DD"); - for (let i = 0; i < this.ContestData.length; i++) { + for (let i: number = 0; i < this.ContestData.length; i++) { const contest: string = this.ContestData[i]; - let str = contest.split("~"); - let my = moment(this._nowContestDate); - let start = moment(str[0]); - let end = moment(str[1]); - let diff: number = my.diff(end, "days"); + let str: string[] = contest.split("~"); + let my: moment.Moment = this._getMomentFormString(this._nowContestDate); + let start: moment.Moment = this._getMomentFormString(str[0]); + let end: moment.Moment = this._getMomentFormString(str[1]); + let diff: number = my.diff(end, "day"); if (diff < 0) { this._nowContestIndex = i; this._nowContestStart = moment(start).format("MM/DD"); @@ -409,16 +315,16 @@ export class BJ_Casino_Data { //#region Get private _contestIDFormDate(date: string): number { - let my = moment(this._nowContestDate); - let target = moment(date); - let diffday: number = my.diff(target, "days"); + let my = this._getMomentFormString(this._nowContestDate); + let target = this._getMomentFormString(date); + let diffday: number = my.diff(target, "day"); let id = this._nowContestID - diffday; if (id < 0) { return 0; } else { return id; } - }; + } private _contestDateFormID(id: number): string { let my: number = this._nowContestID; @@ -427,9 +333,20 @@ export class BJ_Casino_Data { if (diffid < 0) { diffid = 0; } - let date: string = moment().subtract(diffid, "days").format("MM/DD"); + let date: string = moment().subtract(diffid, "day").format("MM/DD"); return date; - }; + } + + private _getMomentFormString(str: string): moment.Moment { + let data: string[] = str.split("/"); + let m: number = +data[0] - 1; + let d: number = +data[1]; + let date: Date = new Date(); + date.setMonth(m); + date.setDate(d); + let mymoment: moment.Moment = moment(date); + return mymoment; + } //#endregion @@ -472,68 +389,6 @@ export class BJ_Casino_Data { return Arr; } - //#endregion - - //#region WebSocke - - public OnWebSocketMessage(e: any) { - let self: this = this; - if (e.data instanceof ArrayBuffer) { - this.ParseRpcMessage(e.data); - } else if (e.data instanceof Blob) { - let reader = new FileReader(); - reader.onload = (e) => { - self.ParseRpcMessage(reader.result); reader.onload = null; - } - reader.readAsArrayBuffer(e.data); - } else { - this.AddLog(`未知的OnWebSocketMessage(e.data)類型: ${e.data}`); - throw new Error(`未知的OnWebSocketMessage(e.data)類型: ${e.data}`); - } - } - - - public ParseRpcMessage(buffer: any) { - let startIndex = 0, byteLength = buffer.byteLength; - while (startIndex + 4 < byteLength) { - let strlen = new DataView(buffer, startIndex, 3).getUint16(0, true); - let str = this.GetString(new Uint8Array(buffer, startIndex + 4, strlen)); - startIndex += strlen + 4; - - try { - let json = JSON.parse(str); - let method = json[0]; - let status = json[1][0]; - let data = json[1][1]; - - let resp = { - Method: method, - Status: status, - Data: data, - IsValid: method && status === 0 - }; - - if (data) { - this.AddLog(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}(${JSON.stringify(resp.Data)})`); - this.ResData(resp.Status, resp.Method, resp.Data); - } else { - this.AddLog(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}()`); - this.ResData(resp.Status, resp.Method); - } - } - catch - { - this.AddLog(`[RPC] 無法解析Server回應: ${str}`); - throw new Error(`[RPC] 無法解析Server回應: ${str}`); - } - } - } - - public seestate() { - // alert(ws.readyState); - this.AddLog(this._ws.readyState); - } - public Sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -545,70 +400,5 @@ export class BJ_Casino_Data { // textarea.scrollTop = textarea.scrollHeight; } - public GetBytes(str: any) { - let len = str.length, resPos = -1; - let resArr = new Uint8Array(len * 3); - for (let point = 0, nextcode = 0, i = 0; i !== len;) { - point = str.charCodeAt(i), i += 1; - if (point >= 0xD800 && point <= 0xDBFF) { - if (i === len) { - resArr[resPos += 1] = 0xef; - resArr[resPos += 1] = 0xbf; - resArr[resPos += 1] = 0xbd; - break; - } - - nextcode = str.charCodeAt(i); - if (nextcode >= 0xDC00 && nextcode <= 0xDFFF) { - point = (point - 0xD800) * 0x400 + nextcode - 0xDC00 + 0x10000; - i += 1; - if (point > 0xffff) { - resArr[resPos += 1] = (0x1e << 3) | (point >>> 18); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 12) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - continue; - } - } else { - resArr[resPos += 1] = 0xef; - resArr[resPos += 1] = 0xbf; - resArr[resPos += 1] = 0xbd; - continue; - } - } - if (point <= 0x007f) { - resArr[resPos += 1] = (0x0 << 7) | point; - } else if (point <= 0x07ff) { - resArr[resPos += 1] = (0x6 << 5) | (point >>> 6); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - } else { - resArr[resPos += 1] = (0xe << 4) | (point >>> 12); - resArr[resPos += 1] = (0x2 << 6) | ((point >>> 6) & 0x3f); - resArr[resPos += 1] = (0x2 << 6) | (point & 0x3f); - } - } - return resArr.subarray(0, resPos + 1); - } - - public GetString(array: any) { - let str = ""; - let i = 0, len = array.length; - while (i < len) { - let c = array[i++]; - switch (c >> 4) { - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: - str += String.fromCharCode(c); - break; - case 12: case 13: - str += String.fromCharCode(((c & 0x1F) << 6) | (array[i++] & 0x3F)); - break; - case 14: - str += String.fromCharCode(((c & 0x0F) << 12) | ((array[i++] & 0x3F) << 6) | ((array[i++] & 0x3F) << 0)); - break; - } - } - return str; - } - //#endregion }