[add] 同步
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -8,7 +8,6 @@ pnpm-debug.log* | |||||||
| lerna-debug.log* | lerna-debug.log* | ||||||
|  |  | ||||||
| node_modules | node_modules | ||||||
| dist |  | ||||||
| dist-ssr | dist-ssr | ||||||
| *.local | *.local | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | |||||||
|  | image: alpine:latest | ||||||
|  | pages: | ||||||
|  |   stage: deploy | ||||||
|  |   script: | ||||||
|  |   - mv -f ./dist/* public | ||||||
|  |   - ls -al | ||||||
|  |   artifacts: | ||||||
|  |     paths: | ||||||
|  |     - public | ||||||
|  |   only: | ||||||
|  |   - master | ||||||
							
								
								
									
										
											BIN
										
									
								
								dist/assets/ZenMaruGothic-Regular.2d389171.ttf
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								dist/assets/ZenMaruGothic-Regular.2d389171.ttf
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										55
									
								
								dist/assets/index.329c61fd.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								dist/assets/index.329c61fd.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										6
									
								
								dist/assets/index.5b40164e.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								dist/assets/index.5b40164e.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								dist/favicon.ico
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								dist/favicon.ico
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 264 KiB | 
							
								
								
									
										20
									
								
								dist/index.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								dist/index.html
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  |  | ||||||
|  | <head> | ||||||
|  |     <meta charset="UTF-8" /> | ||||||
|  |     <link rel="icon" href="./favicon.ico" /> | ||||||
|  |     <link href="./src/assets/ZenMaruGothic-Regular.ttf" rel="stylesheet"> | ||||||
|  |     <!-- <link href="https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic&display=swap" rel="stylesheet"> --> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||||||
|  |     <title>BJ_Casino_Rank</title> | ||||||
|  |   <script type="module" crossorigin src="./assets/index.329c61fd.js"></script> | ||||||
|  |   <link rel="stylesheet" href="./assets/index.5b40164e.css"> | ||||||
|  | </head> | ||||||
|  |  | ||||||
|  | <body> | ||||||
|  |     <div id="app"></div> | ||||||
|  |      | ||||||
|  | </body> | ||||||
|  |  | ||||||
|  | </html> | ||||||
							
								
								
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -18,6 +18,7 @@ | |||||||
|                 "vue-loading-overlay": "^5.0.3" |                 "vue-loading-overlay": "^5.0.3" | ||||||
|             }, |             }, | ||||||
|             "devDependencies": { |             "devDependencies": { | ||||||
|  |                 "@types/node": "^17.0.24", | ||||||
|                 "@vitejs/plugin-vue": "^2.3.0", |                 "@vitejs/plugin-vue": "^2.3.0", | ||||||
|                 "typescript": "^4.5.4", |                 "typescript": "^4.5.4", | ||||||
|                 "vite": "^2.9.0", |                 "vite": "^2.9.0", | ||||||
| @@ -157,6 +158,12 @@ | |||||||
|                 "@types/lodash": "*" |                 "@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": { |         "node_modules/@vitejs/plugin-vue": { | ||||||
|             "version": "2.3.1", |             "version": "2.3.1", | ||||||
|             "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", |             "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", | ||||||
| @@ -1940,6 +1947,12 @@ | |||||||
|                 "@types/lodash": "*" |                 "@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": { |         "@vitejs/plugin-vue": { | ||||||
|             "version": "2.3.1", |             "version": "2.3.1", | ||||||
|             "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", |             "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-2.3.1.tgz", | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
|     "private": true, |     "private": true, | ||||||
|     "version": "0.0.0", |     "version": "0.0.0", | ||||||
|     "scripts": { |     "scripts": { | ||||||
|         "dev": "vite --host", |         "dev": "vite", | ||||||
|         "build": "vite build", |         "build": "vite build", | ||||||
|         "preview": "vite preview" |         "preview": "vite preview" | ||||||
|     }, |     }, | ||||||
|   | |||||||
| @@ -44,7 +44,7 @@ const handleClick = (tab: TabsPaneContext, event: Event) => { | |||||||
| } | } | ||||||
|  |  | ||||||
| .el-tabs__item { | .el-tabs__item { | ||||||
|     font-size: 18px; |     font-size: 25px; | ||||||
| } | } | ||||||
|  |  | ||||||
| #app { | #app { | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								src/env.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								src/env.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -1,8 +1,8 @@ | |||||||
| /// <reference types="vite/client" /> | /// <reference types="vite/client" /> | ||||||
|  |  | ||||||
| declare module '*.vue' { | declare module '*.vue' { | ||||||
|     import type { DefineComponent } from 'vue' |   import type { DefineComponent } from 'vue' | ||||||
|     // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types |   // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types | ||||||
|     const component: DefineComponent<{}, {}, any> |   const component: DefineComponent<{}, {}, any> | ||||||
|     export default component |   export default component | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -1,15 +1,11 @@ | |||||||
| // 引入bootstrap组件库 | import '@popperjs/core'; | ||||||
| import "@popperjs/core"; | import 'bootstrap'; | ||||||
| import "bootstrap"; | import 'bootstrap/dist/css/bootstrap.min.css'; | ||||||
| import "bootstrap/dist/css/bootstrap.min.css"; | import ElementPlus from 'element-plus'; | ||||||
| // 引入Element-Plus组件库 | import 'element-plus/dist/index.css'; | ||||||
| import ElementPlus from "element-plus"; | import locale from 'element-plus/lib/locale/lang/zh-tw'; | ||||||
| import "element-plus/dist/index.css"; | import { createApp } from 'vue'; | ||||||
| import locale from "element-plus/lib/locale/lang/zh-tw"; | import App from './App.vue'; | ||||||
| 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 }).use(V3Popup).mount("#app"); | createApp(App).use(ElementPlus, { locale }).mount('#app') | ||||||
|   | |||||||
| @@ -1,12 +1,12 @@ | |||||||
| import moment from "moment"; | import moment from 'moment'; | ||||||
| import CSMessage from "./Base/CSMessage"; | import CSMessage from './Base/CSMessage'; | ||||||
| import { AccountLoginRequest } from "./Base/Request/AccountRequest"; | import { AccountLoginRequest } from './Base/Request/AccountRequest'; | ||||||
| import { AppRankHistory, AppRankInfo } from "./Base/Request/RankRequest"; | import { AppRankHistory, AppRankInfo } from './Base/Request/RankRequest'; | ||||||
| import "./Engine/CatanEngine/CSharp/String"; | import './Engine/CatanEngine/CSharp/String'; | ||||||
| import { INetResponse } from "./Engine/CatanEngine/NetManagerV2/Core/INetResponse"; | import { INetResponse } from './Engine/CatanEngine/NetManagerV2/Core/INetResponse'; | ||||||
| import { NetConnector } from "./Engine/CatanEngine/NetManagerV2/NetConnector"; | import { NetConnector } from './Engine/CatanEngine/NetManagerV2/NetConnector'; | ||||||
| import { NetManager } from "./Engine/CatanEngine/NetManagerV2/NetManager"; | import { NetManager } from './Engine/CatanEngine/NetManagerV2/NetManager'; | ||||||
| import { Tools } from "./Tools"; | import { Tools } from './Tools'; | ||||||
|  |  | ||||||
| export class BJ_Casino_Data { | export class BJ_Casino_Data { | ||||||
|  |  | ||||||
| @@ -56,9 +56,9 @@ export class BJ_Casino_Data { | |||||||
|  |  | ||||||
|     //#region get set |     //#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 |     //#endregion | ||||||
|  |  | ||||||
| @@ -72,11 +72,11 @@ export class BJ_Casino_Data { | |||||||
|         this.onLoad(); |         this.onLoad(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public async onLoad(): Promise<void> { |     public async onLoad() { | ||||||
|         // CoroutineV2.Single(this.aaa()).Start(); |         // CoroutineV2.Single(this.aaa()).Start(); | ||||||
|         let self: this = this; |         let self: this = this; | ||||||
|         const URL: string = "https://game.online-bj.com"; |         const URL = "https://game.online-bj.com"; | ||||||
|         const Port: string = "9005"; |         const Port = "9005"; | ||||||
|         await this.ConnectAsync(URL, +Port); |         await this.ConnectAsync(URL, +Port); | ||||||
|         // 取得帳號資料 |         // 取得帳號資料 | ||||||
|         let req: AccountLoginRequest = new AccountLoginRequest("ct00000691", "4lsAyoalajm7"); |         let req: AccountLoginRequest = new AccountLoginRequest("ct00000691", "4lsAyoalajm7"); | ||||||
| @@ -87,7 +87,51 @@ export class BJ_Casino_Data { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         await this.SendRankData(); |         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<any> { |     public *aaa(): IterableIterator<any> { | ||||||
|         console.log("aaa"); |         console.log("aaa"); | ||||||
|     } |     } | ||||||
| @@ -96,20 +140,20 @@ export class BJ_Casino_Data { | |||||||
|  |  | ||||||
|     //#region 網路相關 |     //#region 網路相關 | ||||||
|  |  | ||||||
|     /** 連線(目前沒有重連機制) */ |     /**連線(目前沒有重連機制) */ | ||||||
|     public async ConnectAsync(host: string, port: number): Promise<void> { |     public async ConnectAsync(host: string, port: number) { | ||||||
|         var url: string = "https://api.ipify.org/?format=json"; |         var url = "https://api.ipify.org/?format=json"; | ||||||
|         var xhr: XMLHttpRequest = new XMLHttpRequest(); |         var xhr = new XMLHttpRequest(); | ||||||
|         let ip: string = ""; |         let ip: string = ""; | ||||||
|         xhr.onreadystatechange = function (): void { |         xhr.onreadystatechange = function () { | ||||||
|             if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) { |             if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) { | ||||||
|                 ip = JSON.parse(xhr.responseText)["ip"]; |                 ip = JSON.parse(xhr.responseText)["ip"]; | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|         xhr.open("GET", url, true); |         xhr.open("GET", url, true); | ||||||
|         xhr.send(); |         xhr.send(); | ||||||
|         console.log("[事件]準備連線..."); |         console.log("[事件]準備連線..."); | ||||||
|         while (ip === "") { |         while (ip == "") { | ||||||
|             await Tools.Sleep(1); |             await Tools.Sleep(1); | ||||||
|         } |         } | ||||||
|         this._conn = new NetConnector(host, port, ip); |         this._conn = new NetConnector(host, port, ip); | ||||||
| @@ -122,13 +166,13 @@ export class BJ_Casino_Data { | |||||||
|         console.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected)); |         console.log(String.Format("[事件]連線狀態: {0}", NetManager.IsConnected)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private _onNetDisconnected(): void { |     private _onNetDisconnected() { | ||||||
|         console.log("[事件] 收到連線中斷事件"); |         console.log("[事件] 收到連線中斷事件"); | ||||||
|         this._conn.OnDataReceived.RemoveAllCallbacks(); |         this._conn.OnDataReceived.RemoveAllCallbacks(); | ||||||
|         // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]); |         // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private _onNetDataReceived(resp: INetResponse<any>): void { |     private _onNetDataReceived(resp: INetResponse<any>) { | ||||||
|         console.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`); |         console.log(`[事件] 收到server呼叫: ${resp.Method}(${JSON.stringify(resp.Data)}), 狀態: ${resp.Status}`); | ||||||
|         // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]); |         // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]); | ||||||
|     } |     } | ||||||
| @@ -137,18 +181,18 @@ export class BJ_Casino_Data { | |||||||
|  |  | ||||||
|     //#region Custom |     //#region Custom | ||||||
|  |  | ||||||
|     public async SendRankData(): Promise<void> { |     public async SendRankData() { | ||||||
|         this.SendRankMagnificationData(); |         this.SendRankMagnificationData(); | ||||||
|         this.SendRankWinMoneyData(); |         this.SendRankWinMoneyData(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public async SendRankMagnificationData(): Promise<void> { |     public async SendRankMagnificationData() { | ||||||
|         let req: any = null; |         let req: any = null; | ||||||
|         req = new AppRankInfo(12, 2); |         req = new AppRankInfo(12, 2); | ||||||
|         await req.SendAsync(true); |         await req.SendAsync(true); | ||||||
|         let resp: INetResponse<any> = req.Result; |         let resp: INetResponse<any> = req.Result; | ||||||
|         if (!resp.IsValid) { |         if (!resp.IsValid) { | ||||||
|             if (resp.Status === 11) { |             if (resp.Status == 11) { | ||||||
|                 CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); |                 CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); | ||||||
|             } else { |             } else { | ||||||
|                 CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); |                 CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); | ||||||
| @@ -158,13 +202,13 @@ export class BJ_Casino_Data { | |||||||
|         await this.RankMagnificationDataCallBack(resp.Data); |         await this.RankMagnificationDataCallBack(resp.Data); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public async SendRankWinMoneyData(): Promise<void> { |     public async SendRankWinMoneyData() { | ||||||
|         let req: any = null; |         let req: any = null; | ||||||
|         req = new AppRankInfo(11, 2); |         req = new AppRankInfo(11, 2); | ||||||
|         await req.SendAsync(true); |         await req.SendAsync(true); | ||||||
|         let resp: INetResponse<any> = req.Result; |         let resp: INetResponse<any> = req.Result; | ||||||
|         if (!resp.IsValid) { |         if (!resp.IsValid) { | ||||||
|             if (resp.Status === 11) { |             if (resp.Status == 11) { | ||||||
|                 CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); |                 CSMessage.NetError(resp.Method, resp.Status, "Rank 無資料"); | ||||||
|             } else { |             } else { | ||||||
|                 CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); |                 CSMessage.NetError(resp.Method, resp.Status, "Get RankInfo Fail"); | ||||||
| @@ -174,18 +218,68 @@ export class BJ_Casino_Data { | |||||||
|         await this.RankWinMoneyDataCallBack(resp.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) { |     public async RankMagnificationDataCallBack(data: any) { | ||||||
|         let id: number = +data["id"]; |         let id = +data["id"]; | ||||||
|         this._nowSearchMagnificationID = id; |         this._nowSearchMagnificationID = id; | ||||||
|         this._nowContestID = id; |         this._nowContestID = id; | ||||||
|         this._nowContestDate = moment().format("MM/DD"); |         this._nowContestDate = moment().format("MM/DD"); | ||||||
|         for (let i: number = 0; i < this.ContestData.length; i++) { |         for (let i = 0; i < this.ContestData.length; i++) { | ||||||
|             const contest: string = this.ContestData[i]; |             const contest: string = this.ContestData[i]; | ||||||
|             let str: string[] = contest.split("~"); |             let str = contest.split("~"); | ||||||
|             let my: moment.Moment = this._getMomentFormString(this._nowContestDate); |             let my = moment(this._nowContestDate); | ||||||
|             let start: moment.Moment = this._getMomentFormString(str[0]); |             let start = moment(str[0]); | ||||||
|             let end: moment.Moment = this._getMomentFormString(str[1]); |             let end = moment(str[1]); | ||||||
|             let diff: number = my.diff(end, "day"); |             let diff: number = my.diff(end, "days"); | ||||||
|             if (diff < 0) { |             if (diff < 0) { | ||||||
|                 this._nowContestIndex = i; |                 this._nowContestIndex = i; | ||||||
|                 this._nowContestStart = moment(start).format("MM/DD"); |                 this._nowContestStart = moment(start).format("MM/DD"); | ||||||
| @@ -315,16 +409,16 @@ export class BJ_Casino_Data { | |||||||
|     //#region Get |     //#region Get | ||||||
|  |  | ||||||
|     private _contestIDFormDate(date: string): number { |     private _contestIDFormDate(date: string): number { | ||||||
|         let my = this._getMomentFormString(this._nowContestDate); |         let my = moment(this._nowContestDate); | ||||||
|         let target = this._getMomentFormString(date); |         let target = moment(date); | ||||||
|         let diffday: number = my.diff(target, "day"); |         let diffday: number = my.diff(target, "days"); | ||||||
|         let id = this._nowContestID - diffday; |         let id = this._nowContestID - diffday; | ||||||
|         if (id < 0) { |         if (id < 0) { | ||||||
|             return 0; |             return 0; | ||||||
|         } else { |         } else { | ||||||
|             return id; |             return id; | ||||||
|         } |         } | ||||||
|     } |     }; | ||||||
|  |  | ||||||
|     private _contestDateFormID(id: number): string { |     private _contestDateFormID(id: number): string { | ||||||
|         let my: number = this._nowContestID; |         let my: number = this._nowContestID; | ||||||
| @@ -333,20 +427,9 @@ export class BJ_Casino_Data { | |||||||
|         if (diffid < 0) { |         if (diffid < 0) { | ||||||
|             diffid = 0; |             diffid = 0; | ||||||
|         } |         } | ||||||
|         let date: string = moment().subtract(diffid, "day").format("MM/DD"); |         let date: string = moment().subtract(diffid, "days").format("MM/DD"); | ||||||
|         return date; |         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 |     //#endregion | ||||||
|  |  | ||||||
| @@ -389,6 +472,68 @@ export class BJ_Casino_Data { | |||||||
|         return Arr; |         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) { |     public Sleep(ms: number) { | ||||||
|         return new Promise(resolve => setTimeout(resolve, ms)); |         return new Promise(resolve => setTimeout(resolve, ms)); | ||||||
|     } |     } | ||||||
| @@ -400,5 +545,70 @@ export class BJ_Casino_Data { | |||||||
|         // textarea.scrollTop = textarea.scrollHeight; |         // 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 |     //#endregion | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user