diff --git a/index.html b/index.html index 756baf9..5529195 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,7 @@ -
+
diff --git a/src/Common/DataReceived/MainControlData.ts b/src/Common/DataReceived/MainControlData.ts index d37e05a..04b26ce 100644 --- a/src/Common/DataReceived/MainControlData.ts +++ b/src/Common/DataReceived/MainControlData.ts @@ -1,23 +1,9 @@ +import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import CSSettingsV3 from "@/FormTable/CSSettingsV3"; -import { confirmModalObj } from "@/UI/MessageBox/ConfirmModalContext"; -import { modalObj } from "@/UIControl/ModalContext"; -import { Cocos } from "@/assets/VueScript/Cocos"; -import { CommonEventCallBack, JackpotPoolCallBack } from "@/assets/VueScript/CocosVueScript"; -import GameData_Cocos from "@/assets/VueScript/share/GameData_Cocos"; -import { chatLog, chatMessage, setChatBanTime } from "@/components/ModalContent/ChatRoomModal/chatUtils"; -import Config from "@/define/Config"; -import Player from "@/modules/player"; -import UserData from "@/modules/player/UserData"; -import { State } from "@/modules/player/define/data"; -import { ILineShareData, ModalContentType } from "@/types"; -import { CommonEventType } from "@/utils"; -import { NumberEx } from "@/utils/Number/NumberEx"; -import { activityComSync, backpackInfo, friendAllowList, friendDenyList, profileInfo, txnCenter, txnNew, txnTrade, txnUserAdd, vipInfo } from "@/utils/setRPCData"; +import { gameSync } from "@/utils/setRPCData"; import MainControl from "../MainControl/MainControl"; import CSMessage from "../Message/CSMessage"; -import CSResource from "../ResourceItem/CSResource"; -import IResourceItem from "../ResourceItem/IResourceItem"; export default class MainControlData { @@ -46,7 +32,7 @@ export default class MainControlData { private _disconnectErrorType: number = null; constructor() { - Player.DataReceivedEvent.AddCallback(this._dataReceivedEvent, this); + MainControl.DataReceivedEvent.AddCallback(this._dataReceivedEvent, this); } private _dataReceivedEvent(param: any[] = null): void { let type: MainControl.DataType = param[0]; @@ -67,139 +53,8 @@ export default class MainControlData { private _serverData(resp: INetResponse): void { if (resp.IsValid) { switch (resp.Method) { - case "activity_com.sync": { - activityComSync(resp.Data); - break; - } - case "backpack.info": { - backpackInfo(resp.Data); - break; - } - case "chat.ban": { - setChatBanTime(resp.Data); - break; - } - case "chat.message": { - chatMessage(resp.Data); - break; - } - case "chat.log": { - chatLog(resp.Data); - break; - } - case "friend.allow_list": { - friendAllowList(resp.Data); - break; - } - case "friend.deny_list": { - friendDenyList(resp.Data); - break; - } - case "game.share": { - const { openLineShareGame } = confirmModalObj; - const data: ILineShareData = { - slotID: resp.Data[0], - winMilt: resp.Data[1] - }; - openLineShareGame(data); - break; - } case "game.sync": { - Cocos.VicKing_Bridge.InGameGetUUID = true; - break; - } - case "jackpot.get": { - const { handleOpen, setModalType } = modalObj; - const playerData: State = Player.data.getState(); - playerData.account.jackpotGet.push(...resp.Data); - Player.data.setState(playerData); - setModalType(ModalContentType.jackpot); - handleOpen(); - break; - } - case "jackpot.pool": { - const playerData: State = Player.data.getState(); - if (!Config.IsVite || MainControl.Instance.IsInGame) { - for (let i = 0; i < playerData.game.jackpotPool.length; i++) { - const oldJpData: [gameId: number, maxJPId: number, jp: number] = playerData.game.jackpotPool[i]; - let newJpData: [gameId: number, maxJPId: number, jp: number] = null; - for (let j = 0; j < resp.Data.length; j++) { - const [gameId, maxJPId, jp] = resp.Data[j]; - if (gameId === oldJpData[0]) { - newJpData = resp.Data[j]; - break; - } - } - if (!newJpData) { - JackpotPoolCallBack.DispatchCallback(oldJpData[0], 0); - } - } - } - playerData.game.jackpotPool = resp.Data; - Player.data.setState(playerData); - if (!Config.IsVite || MainControl.Instance.IsInGame) { - for (let i = 0; i < playerData.game.jackpotPool.length; i++) { - const jpData: [gameId: number, maxJPId: number, jp: number] = playerData.game.jackpotPool[i]; - JackpotPoolCallBack.DispatchCallback(jpData[0], jpData[2]); - } - } else { - Cocos.CocosEventListener.DispatchCallback(GameData_Cocos.CELT.UpdateJPPool, null); - } - break; - } - case "maintain.info": { - const playerData: State = Player.data.getState(); - if (resp.Data) { - resp.Data[3] = NumberEx.plus(MainControl.Instance.NowTime, resp.Data[3]); - playerData.maintain = resp.Data; - CommonEventCallBack.DispatchCallback(CommonEventType.Maintenance, null); - } else { - playerData.maintain = undefined; - } - Player.data.setState(playerData); - break; - } - case "profile.info": { - profileInfo(resp.Data); - break; - } - case "resource.update": { - const resourceItems: IResourceItem[] = CSResource.GetResourceItemsFromServer(resp.Data); - UserData.DoResUpdate(resourceItems); - break; - } - case "resource.bankruptcy": { - Cocos.CocosEventListener.DispatchCallback(GameData_Cocos.CELT.Bankruptcy, null); - break; - } - case "system.disconnect": { - this._disconnectErrorType = +resp.Data["c"]; - break; - } - case "txn.new": { - txnNew(resp.Data); - break; - } - case "txn.center": { - txnCenter(resp.Data); - break; - } - case "txn.trade": { - txnTrade(resp.Data); - break; - } - case "txn.user_add": { - txnUserAdd(resp.Data); - break; - } - case "vip.info": { - vipInfo(resp.Data); - break; - } - case "vip.level": { - const playerData: State = Player.data.getState(); - playerData.vip.level = resp.Data; - Player.data.setState(playerData); + CoroutineV2.Single(gameSync()).Start(); break; } default: @@ -207,10 +62,9 @@ export default class MainControlData { } } else { switch (resp.Method) { - case "chat.log": { - chatLog([null, null]); - break; - } + // case "": { + // break; + // } default: break; } diff --git a/src/Common/Message/CSMessage.ts b/src/Common/Message/CSMessage.ts index 9229721..22b1669 100644 --- a/src/Common/Message/CSMessage.ts +++ b/src/Common/Message/CSMessage.ts @@ -1,8 +1,4 @@ -import CSSettingsV3 from "@/FormTable/CSSettingsV3"; -import { IConfirmMessageData } from "@/UI/MessageBox/ConfirmMessage"; -import { confirmModalObj } from "@/UI/MessageBox/ConfirmModalContext"; -import { StringFormKey } from "@/define/formkey"; - +import { IConfirmMessageData, modalObj } from "@/UIControl/ModalContext"; /** 訊息框相關 */ export default class CSMessage { @@ -10,7 +6,7 @@ export default class CSMessage { /** 一個按鈕的訊息框 */ public static CreateYesMsg(content: string, yesCallback: () => void = null, enterStr: string = null, title: string = null, textAlign: "center" | "left" | "right" = null) { - enterStr = enterStr ? enterStr : CSSettingsV3.prototype.CommonString(StringFormKey.String.Confirm); + enterStr = enterStr ? enterStr : "確認"; let data: IConfirmMessageData = { title: title, content: content, @@ -19,14 +15,14 @@ export default class CSMessage { enterStr: enterStr, textAlign: textAlign }; - const { openOtherConfirm } = confirmModalObj; - openOtherConfirm(data); + const { handleOpen } = modalObj; + handleOpen(data); } /** 兩個按鈕的訊息框 */ public static CreateYesNoMsg(content: string, yesCallback: () => void = null, noCallback: () => void = null, enterStr: string = null, title: string = null, cancelStr: string = null, textAlign: "center" | "left" | "right" = null) { - enterStr = enterStr ? enterStr : CSSettingsV3.prototype.CommonString(StringFormKey.String.Confirm); - cancelStr = cancelStr ? cancelStr : CSSettingsV3.prototype.CommonString(StringFormKey.String.Cancel); + enterStr = enterStr ? enterStr : "確認"; + cancelStr = cancelStr ? cancelStr : "取消"; let data: IConfirmMessageData = { title: title, content: content, @@ -37,8 +33,8 @@ export default class CSMessage { cancelStr: cancelStr, textAlign: textAlign }; - const { openOtherConfirm } = confirmModalObj; - openOtherConfirm(data); + const { handleOpen } = modalObj; + handleOpen(data); } /** 網路錯誤訊息 */ diff --git a/src/Engine/CatanEngine/NetManagerV2/NetConnector.ts b/src/Engine/CatanEngine/NetManagerV2/NetConnector.ts index 43d8636..6e0f06d 100644 --- a/src/Engine/CatanEngine/NetManagerV2/NetConnector.ts +++ b/src/Engine/CatanEngine/NetManagerV2/NetConnector.ts @@ -82,9 +82,9 @@ export class NetConnector { // if (CC_DEBUG && NetConfig.ShowServerLog) { if (NetConfig.ShowServerLog) { if (req.Data != null && req.Data != undefined && !Number.isNaN(req.Data)) { - console.debug(`[RPC] 傳送server資料: ${req.Method}(${JSON.stringify(req.Data)})`); + console.log(`[RPC] 傳送server資料: ${req.Method}(${JSON.stringify(req.Data)})`); } else { - console.debug(`[RPC] 傳送server資料: ${req.Method}()`); + console.log(`[RPC] 傳送server資料: ${req.Method}()`); } } @@ -185,9 +185,9 @@ export class NetConnector { // if (CC_DEBUG && NetConfig.ShowServerLog) { if (NetConfig.ShowServerLog) { if (data) { - console.debug(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}(${JSON.stringify(resp.Data)})`); + console.log(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}(${JSON.stringify(resp.Data)})`); } else { - console.debug(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}()`); + console.log(`[RPC] 收到server呼叫:(${resp.Status}): ${resp.Method}()`); } } diff --git a/src/Engine/CatanEngine/NetManagerV2/NetManagerSD.ts b/src/Engine/CatanEngine/NetManagerV2/NetManagerSD.ts new file mode 100644 index 0000000..8d77590 --- /dev/null +++ b/src/Engine/CatanEngine/NetManagerV2/NetManagerSD.ts @@ -0,0 +1,54 @@ +import { INetRequest } from "./Core/INetRequest"; +import { NetConnector } from "./NetConnector"; + +export class NetManagerSD { + static get IsConnected() { + return this._connector && this._connector.IsConnected; + } + + static get HasInit() { + return this._connector != null; + } + + private static _connector: NetConnector; + + static Initialize(connector: NetConnector) { + this._connector = connector; + } + + static ConnectAsync() { + this.CheckConnector(); + return this._connector.ConnectAsync(); + } + + /** + * 斷線 + */ + static Disconnect() { + this.CheckConnector(); + this._connector.Disconnect(); + } + + /** + * 傳送資料給Server, 不等待回應 + * @param req + */ + static Send(req: INetRequest) { + this.CheckConnector(); + this._connector.Send(req); + } + + /** + * 傳送資料給Server, 並等待回應 + * @param req + */ + static SendAsync(req: INetRequest, mask: boolean) { + this.CheckConnector(); + return this._connector.SendAsync(req, mask); + } + + private static CheckConnector() { + if (!this._connector) throw new Error("請先呼叫CasinoNetManager.Initialize()初始化connector"); + } + +} \ No newline at end of file diff --git a/src/Engine/CatanEngine/NetManagerV2/NetRequest.ts b/src/Engine/CatanEngine/NetManagerV2/NetRequest.ts index 669342a..87333c9 100644 --- a/src/Engine/CatanEngine/NetManagerV2/NetRequest.ts +++ b/src/Engine/CatanEngine/NetManagerV2/NetRequest.ts @@ -1,5 +1,5 @@ -import { VueNetConnector } from "@/assets/VueScript/Net/VueNetConnector"; import { INetRequest } from "./Core/INetRequest"; +import { NetManager } from "./NetManager"; export abstract class NetRequest implements INetRequest { abstract get Method(): string; @@ -11,18 +11,11 @@ export abstract class NetRequest implements INetRequest; - /** - * 在大廳呼叫Cocos會收到SERVER主動通知 - * 在大廳呼叫Cocos會收到SERVER主動通知 - * 在大廳呼叫Cocos會收到SERVER主動通知 - */ SendAsync(mask: boolean = false): Iterator { - // return NetManager.SendAsync(this, mask); - return VueNetConnector.SendAsync(this, mask); + return NetManager.SendAsync(this, mask); } Send() { - // NetManager.Send(this); - VueNetConnector.Send(this); + NetManager.Send(this); } } diff --git a/src/Engine/CatanEngine/NetManagerV2/NetRequestSD.ts b/src/Engine/CatanEngine/NetManagerV2/NetRequestSD.ts new file mode 100644 index 0000000..959c8a2 --- /dev/null +++ b/src/Engine/CatanEngine/NetManagerV2/NetRequestSD.ts @@ -0,0 +1,21 @@ +import { INetRequest } from "./Core/INetRequest"; +import { NetManagerSD } from "./NetManagerSD"; + +export abstract class NetRequestSD implements INetRequest { + abstract get Method(): string; + + get MethodBack(): string { + return this.Method; + } + + Data: TResquest; + Result: import("./Core/INetResponse").INetResponse; + + SendAsync(mask: boolean = false): Iterator { + return NetManagerSD.SendAsync(this, mask); + } + + Send() { + NetManagerSD.Send(this); + } +} diff --git a/src/UI/Lobby.tsx b/src/UI/Lobby.tsx index 7efbbb7..f4d305e 100644 --- a/src/UI/Lobby.tsx +++ b/src/UI/Lobby.tsx @@ -1,11 +1,9 @@ -import MainControl from "@/Common/MainControl/MainControl"; -import CSMessage from "@/Common/Message/CSMessage"; -import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; -import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import { useGameItems } from "@/context/GameItemsContext"; -import { CommonAccountResponse, LineLoginRequest } from "@/define/Request/RegisterRequest"; +import { Layout } from "antd"; import { useEffect } from "react"; import { useNavigate } from "react-router-dom"; +import Player from "./Lobby/Player"; +import SlotList from "./Lobby/SlotList"; const Lobby = () => { const { player, setPlayer } = useGameItems(); @@ -17,30 +15,6 @@ const Lobby = () => { navigate(`/`); return; } - CoroutineV2.Single(onStart()).Start(); - } - - function* onStart() { - yield* MainControl.Instance.ConnectAsync(); - - } - function* registerLineLogin() { - let req: LineLoginRequest = new LineLoginRequest(token); - yield req.SendAsync(true); - let resp: INetResponse = req.Result; - if (!resp.IsValid) { - //取得帳號失敗直接斷開SOCKET - if (resp.Status != 12) { - const msg: string = "Line Info Error. Error Code:" + req.Result.Status; - CSMessage.CreateYesMsg(msg); - return; - } - console.warn("LINE帳號無綁定"); - return; - } - // yield* this.ServerAccountLogin(resp.Data.id, resp.Data.pw); - - return; } useEffect(() => { @@ -48,7 +22,10 @@ const Lobby = () => { }, []); return ( - <>Lobby + + + {} + ); }; diff --git a/src/UI/Lobby/Player.tsx b/src/UI/Lobby/Player.tsx new file mode 100644 index 0000000..2d5dabd --- /dev/null +++ b/src/UI/Lobby/Player.tsx @@ -0,0 +1,35 @@ +import { CurrencyManager } from "@/FormTableExt/Manage/Currency/CurrencyManager"; +import { useGameItems } from "@/context/GameItemsContext"; +import { useEffect } from "react"; + +const Player = () => { + const { player } = useGameItems(); + const { aId, name, m } = player; + + function onLoad() { + } + + useEffect(() => { + onLoad(); + }, []); + + return ( +
+

aId: {aId}

+

暱稱: {name}

+

金幣: {CurrencyManager.GetNumberWithComma(m)}

+
+ ); +}; + +export default Player; + +const siderStyle: React.CSSProperties = { + fontSize: "1rem", + color: "#000000", + display: "flex", + textAlign: "left", + flexDirection: "column", + justifyContent: "center", + width: "20%" +}; \ No newline at end of file diff --git a/src/UI/Lobby/SDGame.tsx b/src/UI/Lobby/SDGame.tsx new file mode 100644 index 0000000..5052e0c --- /dev/null +++ b/src/UI/Lobby/SDGame.tsx @@ -0,0 +1,145 @@ +import CSMessage from "@/Common/Message/CSMessage"; +import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; +import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; +import { NetConnector } from "@/Engine/CatanEngine/NetManagerV2/NetConnector"; +import { NetManagerSD } from "@/Engine/CatanEngine/NetManagerV2/NetManagerSD"; +import { useGameItems } from "@/context/GameItemsContext"; +import SlotBase from "@/define/Game/Base/SlotBase"; +import { SDAccountLoginRequest } from "@/define/Request/AccountRequest"; +import { SlotInRequest } from "@/define/Request/SlotRequest"; +import { Button, Flex } from "antd"; +import { useEffect, useState } from "react"; + +const SDGame = (props: ISDGame) => { + const { gameUrl, onClickSlotOut } = props; + const { player, setPlayer } = useGameItems(); + const { gameData } = useGameItems(); + const { nowSlotId } = gameData; + const [slotId, setSlotId] = useState(undefined); + const [slotData, setSlotData] = useState(undefined); + let conn: NetConnector = undefined; + + function* onLoad(): IterableIterator { + const url: URL = new URL(gameUrl); + const queryParameters: URLSearchParams = new URLSearchParams(url.search); + const token: string = queryParameters.get("token"); + const slotid: number = +queryParameters.get("slotid"); + const host: string = queryParameters.get("host"); + const port: number = 9005; + + setSlotId(slotid); + conn = new NetConnector("https://" + host, port); + conn.OnDataReceived.AddCallback(onNetDataReceived); + conn.OnDisconnected.AddCallback(onNetDisconnected); + NetManagerSD.Initialize(conn); + console.log("[SDsocket] connecting..."); + yield NetManagerSD.ConnectAsync(); + yield* login(token); + yield* slotIn(slotid); + } + + function* login(token: string): IterableIterator { + const req = new SDAccountLoginRequest(token); + yield req.SendAsync(true); + const resp = req.Result; + if (!resp.IsValid) { + CSMessage.NetError(resp.Method, resp.Status, "SD Account Login Fail"); + return; + } + } + + function* slotIn(slotid: number): IterableIterator { + let req: SlotInRequest = new SlotInRequest(slotid); + yield req.SendAsync(true); + let resp: INetResponse = req.Result; + if (resp.IsValid) { + setSlotData(resp.Data); + } + } + + async function OnclickSpin() { + let slot: any; + const slotGroup: typeof import("../../define/Game/Base/Slot") = await import(/* @vite-ignore */`../../define/Game/Base/Slot`); + try { + slot = slotGroup[`Slot${slotId}`]; + } catch (error) { + // + } + if (!slot) { + slot = slotGroup.SlotBase; + } + const slotClass: SlotBase = new slot(slotId); + // this.IsSpin.value = true; + CoroutineV2.Single(spin(slotClass)).Start(); + } + + function* spin(slotClass: SlotBase): IterableIterator { + yield* slotClass.Spin(20); + // await Tools.Sleep(this.SpinDelay.value * 1000); + // if (this.IsSpin.value && this._bj_Casino_Bot.LobbyScript.IsSlotIn.value) { + // this.Spin(); + // } else { + // this.IsRun = false; + // } + } + + /**RPC回傳.若協定錯誤斷線.原因也會在這裡收到 */ + function onNetDataReceived(resp: INetResponse) { + // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.ServerData, resp]); + } + + /**只要連線中斷不管主被動都會走到這裡 */ + function onNetDisconnected() { + console.warn("[socket] Disconnected"); + conn.OnDataReceived.RemoveAllCallbacks(); + // MainControl.DataReceivedEvent.DispatchCallback([MainControl.DataType.NetDisconnected]); + } + + useEffect(() => { + CoroutineV2.Single(onLoad()).Start(); + }, []); + + return (<> +
+ +
+ Bet: 20 +

+ + +

+
+
+ Log +
+
+
+ ); +}; + +export default SDGame; + +interface ISDGame { + gameUrl: string; + onClickSlotOut: () => void; +} + +const siderStyle: React.CSSProperties = { + fontSize: "1rem", + color: "#000000", + display: "flex", + textAlign: "left", + flexDirection: "column", + justifyContent: "center", + width: "100%" +}; + +const controlStyle: React.CSSProperties = { + fontSize: "1rem", + display: "flex", + textAlign: "left", + flexDirection: "column", + justifyContent: "center", + lineHeight: "30px", + width: "30%" +}; \ No newline at end of file diff --git a/src/UI/Lobby/SlotList.tsx b/src/UI/Lobby/SlotList.tsx new file mode 100644 index 0000000..0fc6617 --- /dev/null +++ b/src/UI/Lobby/SlotList.tsx @@ -0,0 +1,93 @@ +import CSMessage from "@/Common/Message/CSMessage"; +import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; +import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; +import CSSettingsV3 from "@/FormTable/CSSettingsV3"; +import BusinessTypeSetting from "@/_BusinessTypeSetting/BusinessTypeSetting"; +import Image from "@/components/Image/Image"; +import { useGameItems } from "@/context/GameItemsContext"; +import { GameLaunchRequest, GameLeaveRequest, RpcGameLaunchResponse } from "@/define/Request/GameRequest"; +import { SlotData } from "@/define/gameData"; +import { Button, Flex } from "antd"; +import { useEffect, useState } from "react"; +import SDGame from "./SDGame"; + +const SlotList = () => { + const { gameData, setGameData } = useGameItems(); + const { slotData, slotList, nowSlotId } = gameData; + const [isGameIn, setIsGameIn] = useState(false); + const [gameUrl, setGameUrl] = useState(""); + + function onLoad() { + + } + + function* onClickSlotIn(slotId: number): IterableIterator { + const data: SlotData = slotData[slotId]; + const [componyID] = data; + const req: GameLaunchRequest = new GameLaunchRequest(componyID, slotId); + yield req.SendAsync(); + const resp: INetResponse = req.Result; + if (!resp.IsValid) { + if (resp.Status === 18) { + CSMessage.CreateYesMsg(CSSettingsV3.prototype.CommonString(16)); + } + return; + } + setIsGameIn(true); + const url: string = resp.Data; + setGameData({ + ...gameData, + nowSlotId: slotId + }); + if (componyID === 2) { + setGameUrl(url); + } + else { + window.open(url, "_blank"); + } + } + + function onClickSlotOut() { + const gameLeaveReq: GameLeaveRequest = new GameLeaveRequest(nowSlotId); + gameLeaveReq.Send(); + setGameUrl(""); + setIsGameIn(false); + } + + useEffect(() => { + onLoad(); + }, []); + + return (<> + {isGameIn + ? <>{gameUrl + ? + : + + } + + :
+ + {slotList.map((slotId: number, index: number) => + { CoroutineV2.Single(onClickSlotIn(slotId)).Start(); }} style={{ cursor: "pointer" }} /> + )} + +
+ } + ); +}; + +export default SlotList; + +const contentStyle: React.CSSProperties = { + fontSize: "1rem", + minHeight: 120, + lineHeight: "120px", + color: "#000000", + display: "flex", + textAlign: "center", + flexDirection: "column", + justifyContent: "center", + width: "100%" +}; \ No newline at end of file diff --git a/src/UI/Login.tsx b/src/UI/Login.tsx index 6331eb6..7f0722f 100644 --- a/src/UI/Login.tsx +++ b/src/UI/Login.tsx @@ -1,5 +1,11 @@ +import MainControl from "@/Common/MainControl/MainControl"; +import CSMessage from "@/Common/Message/CSMessage"; +import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; +import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import { BusinessEnum } from "@/_BusinessTypeSetting/BusinessTypeSetting"; import { useGameItems } from "@/context/GameItemsContext"; +import { AccountLoginRequest } from "@/define/Request/AccountRequest"; +import { CommonAccountResponse, LineLoginRequest } from "@/define/Request/RegisterRequest"; import { Button, Cascader } from "antd"; import TextArea from "antd/es/input/TextArea"; import React, { useState } from "react"; @@ -17,7 +23,7 @@ const Login = () => { const serverType: typeof BusinessEnum.ServerType = BusinessEnum.ServerType; const [type, setType] = useState(BusinessEnum.ServerType.Internal_Dev); const [isLogin, setIsLogin] = useState(false); - const [token, SetToken] = useState(""); + const [token, SetToken] = useState("eyJhbGciOiJIUzI1NiJ9.Am-dhpCRUo9iBHYJ0kro12-zUlOyNAVOw9poXEkUV14hvkL2RPxVqqtrsYbS9_aoKep4EOFYROFTbv6MfVai7gomKdr07XkmTtADtkbchkfm-yuGXVzW1mYabf646_U66MnvXX2PHS-ATXDYYx5He9PJ-5lF9g5BmhtxUYPW98w.MGUUrFQbBeUBPDJeoKMilbqbg6IkwEqbu2oyJVSmw6M"); const options: Option[] = []; for (let i = 0, names: string[] = Object.keys(serverType); i < names.length; i++) { const key: string = names[i]; @@ -29,11 +35,59 @@ const Login = () => { } } - async function login() { + async function onClickLogin() { + if (!token) { + CSMessage.CreateYesMsg("請輸入token"); + return; + } setIsLogin(true); await onLoad(type); + CoroutineV2.Single(login()).Start(); + } + + function* login() { + yield* MainControl.Instance.ConnectAsync(); + yield* registerLineLogin(); + } + + function* registerLineLogin() { + let req: LineLoginRequest = new LineLoginRequest(token); + yield req.SendAsync(true); + let resp: INetResponse = req.Result; + if (!resp.IsValid) { + //取得帳號失敗直接斷開SOCKET + if (resp.Status != 12) { + const msg: string = "Line Info Error. Error Code:" + req.Result.Status; + CSMessage.CreateYesMsg(msg); + setIsLogin(false); + return; + } + console.warn("LINE帳號無綁定"); + setIsLogin(false); + return; + } + yield* serverAccountLogin(resp.Data.id, resp.Data.pw); + } + + /** 遊戲帳號登入取得玩家資料.統一登入時在刪除需要刪除的資料 */ + function* serverAccountLogin(a: string, pw: string, partner: string = null): IterableIterator { + let hasAP: boolean = (a && a != "null" && a != "undefined" && pw && pw != "null" && pw != "undefined"); + if (!hasAP) { + CSMessage.CreateYesMsg("沒有帳號或密碼.請確認回傳接值."); + setIsLogin(false); + return; + } + let req: AccountLoginRequest = new AccountLoginRequest(a, pw, partner); + yield req.SendAsync(true); + let resp: INetResponse = req.Result; + if (!resp.IsValid) { + CSMessage.CreateYesMsg("Login Account Error! Error Code : " + resp.Status); + setIsLogin(false); + return; + } setPlayer({ ...player, + ...resp.Data, token: token }); navigate(`/lobby/`); @@ -45,9 +99,9 @@ const Login = () => {
setType(+v[0])} />
-