[fix] 場次計算判斷錯誤
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										4
									
								
								dist/index.html
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								dist/index.html
									
									
									
									
										vendored
									
									
								
							| @@ -8,8 +8,8 @@ | ||||
|     <!-- <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"> | ||||
|   <script type="module" crossorigin src="./assets/index.3ff2df8d.js"></script> | ||||
|   <link rel="stylesheet" href="./assets/index.ea1c5c11.css"> | ||||
| </head> | ||||
|  | ||||
| <body> | ||||
|   | ||||
							
								
								
									
										172
									
								
								src/components/v3popup.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										172
									
								
								src/components/v3popup.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,172 @@ | ||||
| <template> | ||||
|     <div ref="elRef" v-show="opened" class="vui__popup" :class="{ 'vui__popup-closed': closeCls }" :id="id"> | ||||
|  | ||||
|         <!-- //蒙层 --> | ||||
|         <div v-if="JSON.parse(shade)" class="vui__overlay" @click="shadeClicked" :style="{ opacity }"></div> | ||||
|         <div class="vui__wrap"> | ||||
|             <div class="vui__wrap-section"> | ||||
|                 <div class="vui__wrap-child" | ||||
|                     :class="['anim-' + anim, type && 'popupui__' + type, round && 'round', position]" | ||||
|                     :style="[popupStyle]"> | ||||
|                     <div v-if="title" class="vui__wrap-tit" v-html="title"></div> | ||||
|                     <div v-if="type == 'toast' && icon" class="vui__toast-icon" :class="['vui__toast-' + icon]" | ||||
|                         v-html="toastIcon[icon]"></div> | ||||
|  | ||||
|                     <!-- 判断插槽是否存在 --> | ||||
|                     <template v-if="$slots.content"> | ||||
|                         <div class="vui__wrap-cnt"> | ||||
|                             <slot name="content" /> | ||||
|                         </div> | ||||
|                     </template> | ||||
|                     <template v-else> | ||||
|                         <div v-if="content" class="vui__wrap-cnt" v-html="content"></div> | ||||
|                     </template> | ||||
|  | ||||
|                     <slot /> | ||||
|                     <div v-if="btns" class="vui__wrap-btns"> | ||||
|                         <span v-for="(btn, index) in btns" :key="index" class="btn" :style="btn.style" | ||||
|                             @click="btnClicked($event, index)" v-html="btn.text"></span> | ||||
|                     </div> | ||||
|                     <span v-if="xclose" class="vui__xclose" :class="xposition" :style="{ 'color': xcolor }" | ||||
|                         @click="close"></span> | ||||
|  | ||||
|                 </div> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|     </div> | ||||
| </template> | ||||
|  | ||||
| /** | ||||
| * @Desc Vue3自定义弹出层组件V3Popup | ||||
| * @Time andy by 2020-12 | ||||
| * @About Q:282310962 wx:xy190310 | ||||
| */ | ||||
| <script> | ||||
| import { onMounted, ref, reactive, watch, toRefs, nextTick } from 'vue' | ||||
| let $index = 0, $locknum = 0, $timer = {} | ||||
| export default { | ||||
|     props: { | ||||
|         // 接收父组件v-model值,如果v-model:open,则这里需写open: {...} | ||||
|         modelValue: { type: Boolean, default: false }, | ||||
|         // 标识符,相同ID共享一个实例 | ||||
|         id: { | ||||
|             type: String, default: '' | ||||
|         }, | ||||
|         title: String, | ||||
|         content: String, | ||||
|         type: String, | ||||
|         popupStyle: String, | ||||
|         icon: String, | ||||
|         shade: { type: [Boolean, String], default: true }, | ||||
|         shadeClose: { type: [Boolean, String], default: true }, | ||||
|         opacity: { type: [Number, String], default: '' }, | ||||
|         round: Boolean, | ||||
|         xclose: Boolean, | ||||
|         xposition: { type: String, default: 'right' }, | ||||
|         xcolor: { type: String, default: '#333' }, | ||||
|         anim: { type: String, default: 'scaleIn' }, | ||||
|         position: String, | ||||
|         follow: { type: Array, default: null }, | ||||
|         time: { type: [Number, String], default: 0 }, | ||||
|         zIndex: { type: [Number, String], default: '8080' }, | ||||
|         teleport: [String, Object], | ||||
|         btns: { | ||||
|             type: Array, default: null | ||||
|         }, | ||||
|         onSuccess: { type: Function, default: null }, | ||||
|         onEnd: { type: Function, default: null }, | ||||
|     }, | ||||
|     emits: [ | ||||
|         'update:modelValue' | ||||
|     ], | ||||
|     setup(props, context) { | ||||
|         const elRef = ref(null) | ||||
|  | ||||
|         const data = reactive({ | ||||
|             opened: false, | ||||
|             closeCls: '', | ||||
|             toastIcon: { | ||||
|                 ... | ||||
| } | ||||
|         }) | ||||
|  | ||||
|         onMounted(() => { | ||||
| ... | ||||
| }) | ||||
|  | ||||
|     // 监听弹层v-model | ||||
|     watch(() => props.modelValue, (val) => { | ||||
|         if (val) { | ||||
|             open() | ||||
|         } else { | ||||
|             close() | ||||
|         } | ||||
|     }) | ||||
|  | ||||
| // 打开弹层 | ||||
| const open = () => { | ||||
|     if (data.opened) return | ||||
|     data.opened = true | ||||
|     typeof props.onSuccess === 'function' && props.onSuccess() | ||||
|  | ||||
|     const dom = elRef.value | ||||
|     dom.style.zIndex = getZIndex() + 1 | ||||
|  | ||||
| ... | ||||
|  | ||||
| // 倒计时 | ||||
| if (props.time) { | ||||
|     $index++ | ||||
|     // 避免重复操作 | ||||
|     if ($timer[$index] !== null) clearTimeout($timer[$index]) | ||||
|     $timer[$index] = setTimeout(() => { | ||||
|         close() | ||||
|     }, parseInt(props.time) * 1000) | ||||
| } | ||||
|  | ||||
| // 长按|右键菜单 | ||||
| if (props.follow) { | ||||
| ... | ||||
| } | ||||
| } | ||||
|  | ||||
| // 关闭弹层 | ||||
| const close = () => { | ||||
|     if (!data.opened) return | ||||
|  | ||||
|     data.closeCls = true | ||||
|     setTimeout(() => { | ||||
| ... | ||||
|  | ||||
|         context.emit('update:modelValue', false) | ||||
| typeof props.onEnd === 'function' && props.onEnd() | ||||
| }, 200) | ||||
| } | ||||
|  | ||||
| // 点击遮罩层 | ||||
| const shadeClicked = () => { | ||||
|     if (JSON.parse(props.shadeClose)) { | ||||
|         close() | ||||
|     } | ||||
| } | ||||
| // 按钮事件 | ||||
| const btnClicked = (e, index) => { | ||||
|     let btn = props.btns[index]; | ||||
|     if (!btn.disabled) { | ||||
|         typeof btn.click === 'function' && btn.click(e) | ||||
|     } | ||||
| } | ||||
|  | ||||
| ... | ||||
|  | ||||
| return { | ||||
|     ...toRefs(data), | ||||
|     elRef, | ||||
|     close, | ||||
|     shadeClicked, | ||||
|     btnClicked, | ||||
| } | ||||
| } | ||||
| } | ||||
| </script> | ||||
| @@ -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<void> { | ||||
|         // 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<any> { | ||||
|         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<void> { | ||||
|         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<any>) { | ||||
|     private _onNetDataReceived(resp: INetResponse<any>): 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<void> { | ||||
|         this.SendRankMagnificationData(); | ||||
|         this.SendRankWinMoneyData(); | ||||
|     } | ||||
|  | ||||
|     public async SendRankMagnificationData() { | ||||
|     public async SendRankMagnificationData(): Promise<void> { | ||||
|         let req: any = null; | ||||
|         req = new AppRankInfo(12, 2); | ||||
|         await req.SendAsync(true); | ||||
|         let resp: INetResponse<any> = 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<void> { | ||||
|         let req: any = null; | ||||
|         req = new AppRankInfo(11, 2); | ||||
|         await req.SendAsync(true); | ||||
|         let resp: INetResponse<any> = 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,69 +174,19 @@ 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"); | ||||
|             if (diff < 0) { | ||||
|             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"); | ||||
|                 this._nowContestEnd = moment(end).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 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user