public static T Load <T>(string fileName) where T : ProtoBuf.IExtensible { TextAsset textAsset = null; if (GameManager.Instance.ResFrom == ResourceFrom.Origin) { string protoPath = "ConfigData/" + fileName; textAsset = Resources.Load(protoPath) as TextAsset; } else { textAsset = ResourceManager.GetInstance().LoadText("assetbundle/data/" + fileName, fileName); if (null == textAsset) { Debug.LogError("prototool bundle 加载失败, 没有对应的资源: " + fileName); } } T t = default(T); try { t = ProtoTool.DeSerialize <T>(textAsset.bytes); } catch (ProtoException) { Debug.LogError(string.Format("解析配表:<color=red>{0}</color>出错,请相关人员检查配表!", fileName)); } catch (Exception) { Debug.LogError(string.Format("解析配表:<color=red>{0}</color>出错,未知异常!", fileName)); } return(t); }
public static T Load<T>(string fileName)where T:ProtoBuf.IExtensible { TextAsset textAsset = null; #if PC_RUN_ANDROID || PC_RUN_IOS textAsset = ResourceManager.GetInstance().LoadText("ConfigData/" + fileName, fileName); if (null == textAsset) { CommonTools.MustLog("prototool bundle 加载失败, 没有对应的资源: " + fileName); } #else if(Application.isEditor || !Application.isMobilePlatform){ string protoPath = "ConfigData/"+fileName; textAsset = XFramework.AssetBundlePacker.ResourcesManager.Load<TextAsset>(protoPath) as TextAsset; }else{ //textAsset = ResourceManager.LoadText("ConfigData/" + fileName, fileName); //if (null == textAsset) //{ // ///CommonTools.MustLog("prototool bundle 加载失败, 没有对应的资源: " + fileName); ////} string protoPath = "ConfigData/" + fileName; textAsset = XFramework.AssetBundlePacker.ResourcesManager.Load<TextAsset>(protoPath) as TextAsset; } #endif T t = default(T); try { t = ProtoTool.DeSerialize<T>(textAsset.bytes); } catch (ProtoException proex) { Debug.LogError(string.Format("解析配表:<color=red>{0}</color>出错,请相关人员检查配表! + ex:"+proex.Message, fileName)); } catch (Exception ex) { Debug.LogError(string.Format("解析配表:<color=red>{0}</color>出错,未知异常!exception:{1}", fileName,ex.Message)); } return t; }
private void OffLine() { Receive <Tcp.Received>(received => { if (!Sender.Equals(_tcpActorRef)) { _log.Error($"link error close link!"); Sender.Tell(Tcp.Close.Instance); return; } var aMsg = ProtoTool.DeSerialize <AMsg>(received.Data.ToArray()); var aMsgType = aMsg.type; if (aMsgType == AMsg.Type.RequestMsg) { var aMsgRequestMsg = aMsg.requestMsg; switch (aMsgRequestMsg.head) { case RequestMsg.Head.LoginRequest: var aMsgLoginRequest = aMsgRequestMsg.loginRequest; var accountId = aMsgLoginRequest.accountId; var password = aMsgLoginRequest.Password; if (!Tools.CheckAccountIdOk(accountId)) { var loginResponse = new LoginResponse() { reason = LoginResponse.Reason.NoGoodAccount, Nickname = "" }; var msg = new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.LoginResponse, loginResponse = loginResponse } }; Sender.Tell(GenTcpWrite(msg)); } else if (!Tools.CheckPasswordOk(password)) { var loginResponse = new LoginResponse() { reason = LoginResponse.Reason.NoGoodPassword, Nickname = "" }; var msg = new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.LoginResponse, loginResponse = loginResponse } }; Sender.Tell(GenTcpWrite(msg)); } else { _accountId = accountId; FamousActors.MongodbAccountActor.Tell(aMsgLoginRequest); } Become(LoginDoing); break; case RequestMsg.Head.FixAccountPasswordRequest: var aMsgFixAccountPasswordRequest = aMsgRequestMsg.fixAccountPasswordRequest; if (!Tools.CheckAccountIdOk(aMsgFixAccountPasswordRequest.accountId)) { var loginResponse = new FixAccountPasswordResponse { reason = FixAccountPasswordResponse.Reason.NoGoodAccountId }; var msg = new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.FixAccountPasswordResponse, fixAccountPasswordResponse = loginResponse } }; Sender.Tell(GenTcpWrite(msg)); } else if (!Tools.CheckPasswordOk(aMsgFixAccountPasswordRequest.newPassword) || !Tools.CheckPasswordOk(aMsgFixAccountPasswordRequest.oldPassword)) { var loginResponse = new FixAccountPasswordResponse { reason = FixAccountPasswordResponse.Reason.NoGoodPassword }; var msg = new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.FixAccountPasswordResponse, fixAccountPasswordResponse = loginResponse } }; Sender.Tell(GenTcpWrite(msg)); } else { FamousActors.MongodbAccountActor.Tell(aMsgFixAccountPasswordRequest); } break; default: _tcpActorRef.Tell(Tcp.Close.Instance); throw new ArgumentOutOfRangeException(); } } }); Receive <FixAccountPasswordResponse>(response => { var genTcpWrite = GenTcpWrite(new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg { head = ResponseMsg.Head.FixAccountPasswordResponse, fixAccountPasswordResponse = response } } ); _tcpActorRef.Tell(genTcpWrite); }); NormalAccident(); }
private void OnLine() { FamousActors.MongodbPlayerStatusActor.Tell(new InitStatus(_accountId)); // ICancelable scheduleTellRepeatedlyCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( // TimeSpan.FromMinutes(10), // TimeSpan.FromMinutes(10), // Self, SavePlayerDB.Instance // , ActorRefs.Nobody); void ReallyLoginOk() { _temp.bankBaseResponse = Tools.GenBankBaseResponseByPlayBank(_myWallet); _temp.charactersGetResponse = Tools.GenCharactersGetResponseByPlayerCharacters(_myCharacters); var aMsg = new AMsg { type = AMsg.Type.ResponseMsg, responseMsg = { head = ResponseMsg.Head.LoginResponse, loginResponse = _temp } }; _tcpActorRef.Tell(GenTcpWrite(aMsg)); } Receive <PlayerStatus>(status => { _myWallet = status.PlayerBank; _myGames = status.PlayerGames; _myCharacters = status.PlayerCharacters; ReallyLoginOk(); }); Receive <ErrorResponse>(response => _tcpActorRef.Tell(GenTcpWrite( new AMsg { type = AMsg.Type.ResponseMsg, responseMsg = { head = ResponseMsg.Head.ErrorResponse, errorResponse = response } } )) ); Receive <Tcp.ConnectionClosed>(closed => { OffLineSave(OutReason.Drop); _log.Info($"Stopped, remote connection [{_remote}] closed"); Context.Stop(Self); }); Receive <Terminated>(terminated => { OffLineSave(OutReason.Drop); _log.Info($"Stopped, remote connection [{_remote}] died"); Context.Stop(Self); }); Receive <LogoutResponse>(response => { _tcpActorRef.Tell(GenTcpWrite(new AMsg { type = AMsg.Type.ResponseMsg, responseMsg = { head = ResponseMsg.Head.LogoutResponse, logoutResponse = response } })); }); Receive <Tcp.Received>(received => { var aMsg = ProtoTool.DeSerialize <AMsg>(received.Data.ToArray()); var aMsgType = aMsg.type; if (aMsgType == AMsg.Type.RequestMsg && _gameState == GameState.Online && _accountId != null) { var aMsgRequestMsg = aMsg.requestMsg; switch (aMsgRequestMsg.head) { case RequestMsg.Head.BankBaseRequest: var genBankBaseResponseByPlayBank = Tools.GenBankBaseResponseByPlayBank(_myWallet); Sender.Tell(GenTcpWrite(new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.BankBaseResponse, bankBaseResponse = genBankBaseResponseByPlayBank } })); break; case RequestMsg.Head.BankItemAllRequest: var genBankItemAllResponseByPlayBank = Tools.GenBankItemResponseByPlayBank(_myWallet); Sender.Tell(GenTcpWrite(new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.BankItemResponse, bankItemResponse = genBankItemAllResponseByPlayBank } })); break; case RequestMsg.Head.BankItemCustomRequest: var genBankItemResponseByPlayBank = Tools.GenBankItemResponseByPlayBank(_myWallet, aMsgRequestMsg.bankCustomItemRequest.itemIds); Sender.Tell(GenTcpWrite(new AMsg() { type = AMsg.Type.ResponseMsg, responseMsg = new ResponseMsg() { head = ResponseMsg.Head.BankItemResponse, bankItemResponse = genBankItemResponseByPlayBank } })); break; case RequestMsg.Head.LogoutRequest: OffLineSave(OutReason.LogOut); _gameState = GameState.OffLine; Become(OffLine); break; default: _tcpActorRef.Tell(Tcp.Close.Instance); throw new ArgumentOutOfRangeException(); } } else { _tcpActorRef.Tell(Tcp.Close.Instance); throw new ArgumentOutOfRangeException(); } }); }