private static void ShowErrorMessage(BenchmarkClientComponent self, int errorCode) { string err = $"Session ErrorCode : {errorCode}"; self.UserLog(err); Log.Error(err); }
public static async void Awake(this BenchmarkClientComponent self, BenchmarkClientComponent.ClientSetting clientSetting) { try { self.networkComponent = clientSetting.networkComponent; self.ipEndPoint = clientSetting.ipEndPoint; self.testPlayerSetting = clientSetting.testPlayerSetting; self.stateMachine = new StateMachine <BenchmarkClientComponent>(); self.robotMode = clientSetting.robotMode; self.roadSettingId = clientSetting.roadSettingId; self.IsFromPool = false; //self.InitializeStateMachine(); /****************/ await self.SignIn(self.testPlayerSetting.DeviceUniqueIdentifier); //設定玩家資料 TestPlayerDataComponent playerDataComponent = self.session.AddComponent <TestPlayerDataComponent>(); playerDataComponent.testPlayerSetting = clientSetting.testPlayerSetting; self.Init(); } catch (Exception e) { Console.WriteLine($"Msg:{e.Message}, Stack:{e.StackTrace}"); } }
/****************/ private static async ETTask SignIn(this BenchmarkClientComponent self, string deviceUniqueIdentifier) { string secret = CryptographyHelper.AESEncrypt(deviceUniqueIdentifier); var signInResult = await UserUtility.SignIn(() => { //連接Realm self.ConnectRealm(); return(self.session); }, address => { //斷開Realm self.session.Dispose(); //連接Gate self.ConnectGate(address); return(self.session); }, new C2R_Authentication() { Info = new AuthenticationInfo { Language = 10, Secret = secret, FirebaseDeviceToken = string.Empty, Type = AuthenticationType.Guest, } }); self.userName = signInResult.playerBaseInfo.Name; //self.UserLog(signInResult.playerBaseInfo.Name); }
public static void Destroy(this BenchmarkClientComponent self) { if (self.session != null) { self.session.Dispose(); self.session = null; } }
private static void InitializeStateMachine(this BenchmarkClientComponent self) { self.stateMachine.SetTarget(self); //create states. //self.login = self.stateMachine.CreateState<LoginState>(); //self.roaming = self.stateMachine.CreateState<LoginState>(); //change to defaule state. self.stateMachine.ChangeState(self.login); }
public static void PrintMessage(this BenchmarkClientComponent self) { if (self.components.Count != 0) { for (int i = 0; i < self.components.Count; i++) { string msg = self.components[i].GetMessage(); self.UserLog($"{msg}, Ping:{self.currentPing}, Name:{self.userName}"); } } }
private static void AttachPingComponent(BenchmarkClientComponent self) { var pingComponent = self.session.AddComponent <ETModel.Share.PingComponent, long, Action <Exception> >(BenchmarkClientComponent.pingWaitMilisec, ex => { HandleException(self, ex); }); pingComponent.onPingChanged += ping => { self.currentPing = ping; //self.UserLog($"Ping : {ping}"); }; self.session.ErrorCallback += (channel, error) => { AChannelError(self, channel, error); }; }
public static void Update(this BenchmarkClientComponent self) { //self.stateMachine.UpdateState(); if (self.components.Count != 0) { for (int i = 0; i < self.components.Count; i++) { self.components[i].Update(); } } }
private static void HandleException(BenchmarkClientComponent self, Exception ex) { if (ex.InnerException is RpcException rpcEx) { ShowErrorMessage(self, rpcEx.Error); } else { string err = $"Message:{ex.InnerException.Message}\r\n{ex.InnerException.StackTrace}"; self.UserLog(err); Log.Error(err); } }
public void Awake() { parent = GetParent <BenchmarkClientComponent>(); timerComponent = Game.Scene.GetComponent <TimerComponent>(); session = parent.session; benchmarkComponent = Game.Scene.GetComponent <BenchmarkComponent>(); mapUnitBotModule = parent.GetComponent <MapUnitBotModule>(); state = State.CreateOrEnterRoom; //_nowSpeed = random.Next(5, 30); _nowSpeed = 1; //while (!IsDisposed) //{ // await timerComponent.WaitForSecondAsync(5); // Console.WriteLine($"Name:{parent.userName}, State:{state}"); //} }
public async void Awake() { parent = GetParent <BenchmarkClientComponent>(); timerComponent = Game.Scene.GetComponent <TimerComponent>(); session = parent.session; mapUnitBotModule = parent.GetComponent <MapUnitBotModule>(); L2C_RoamingGetList l2C_RoamingGetList = await RoamingUtility.GetMapList(session); if (l2C_RoamingGetList.Error != ErrorCode.ERR_Success) { Console.WriteLine($"To get roaming road list Failed"); return; } var info = l2C_RoamingGetList.Infos.FirstOrDefault(e => e.RoadSettingId == parent.roadSettingId); long roomId = info != null ? info.RoomId : 0L; L2C_RoamingEnter l2C_RoamingEnter = await RoamingUtility.EnterRoamingRoom(session, roomId); if (l2C_RoamingEnter.Error != ErrorCode.ERR_Success) { Console.WriteLine($"To enter roaming room[{roomId}] Failed. Error:{l2C_RoamingEnter.Error}"); return; } //記錄自身MapUnitId mapUnitId = l2C_RoamingEnter.SelfInfo.MapUnitId; //記錄自身MapUnitInfo mapUnitBotModule.mapUnitInfos.TryAdd(mapUnitId, new MapUnitBotModule.MapUnitData { mapUnitInfo = l2C_RoamingEnter.SelfInfo, m2C_MapUnitUpdate = null, }); _nowSpeed = random.Next(5, 30); mapUnitBotModule.EnableGame(true); }
public static void Init(this BenchmarkClientComponent self) { self.components.Clear(); switch (self.robotMode) { case BenchmarkClientComponent.RobotMode.Roaming: self.RemoveComponent <RoamingBotModule>(); self.RemoveComponent <MapUnitBotModule>(); self.AddComponent <MapUnitBotModule>(); self.components.Add(self.AddComponent <RoamingBotModule>()); break; case BenchmarkClientComponent.RobotMode.Party: self.RemoveComponent <PartyBotModule>(); self.RemoveComponent <MapUnitBotModule>(); self.AddComponent <MapUnitBotModule>(); self.components.Add(self.AddComponent <PartyBotModule>()); break; default: throw new Exception($"clientSetting.robotMode:{self.robotMode} is not defined!"); } self.UserLog("Reset client"); }
public static void UserLog(this BenchmarkClientComponent self, string message) { Console.WriteLine($"User[{self.testPlayerSetting.DeviceUniqueIdentifier}]> {message}"); }
private static void AChannelError(BenchmarkClientComponent self, AChannel aChannel, int errorCode) { ShowErrorMessage(self, errorCode); }
private static void ConnectGate(this BenchmarkClientComponent self, string address) { self.session = self.networkComponent.Create(address); AttachPingComponent(self); }
private static void ConnectRealm(this BenchmarkClientComponent self) { self.session = self.networkComponent.Create(self.ipEndPoint); AttachPingComponent(self); }