/// <summary> /// use this method just for generating a new UID. /// </summary> /// <param name="_username_"></param> /// <param name="_socket_"></param> /// <returns></returns> public static async Task <UID> GenerateUID(StrongString _username_, IPlayerSocket _socket_) { int myIndex = Randomic.GetRandom(MIN_SERVER_INDEX, MAX_SERVER_INDEX); var _s = ThereIsServer.ServersInfo.ServerManager.Get_UID_Generation_Server(myIndex); StrongString _target = ServerManager.Generation_Location_Name; UID uid; ulong _value; for (var i = 0; ; i++) { var existing = await ThereIsServer.Actions.GetAllContentsByRef(_s, _target); if (existing.IsDeadCallBack || ThereIsServer.ServerSettings.HasConnectionClosed) { NoInternetConnectionSandBox.PrepareConnectionClosedSandBox(); return(null); } _value = existing.Decode().ToUInt64(); _value++; var _req = new DataBaseUpdateRequest(UID_MESSAGE, _value.ToString(UID_FORMAT), existing.Sha.GetStrong()); var _result = await ThereIsServer.Actions.UpdateDataOnce(_s, _target, _req); if (_result.IsDeadCallBack) { continue; } if (ThereIsServer.ServerSettings.HasConnectionClosed || i >= MAX_TRY) { return(null); } break; } //---------------------- uid = new UID(myIndex, _value, _socket_, _username_); _s = ThereIsServer.ServersInfo.ServerManager.Get_UID_Server(uid); _target = uid.GetValue() + UID_Lcation_Name; var _creation = new DataBaseCreation(UID_MESSAGE, QString.Parse(uid.GetForServer())); await ThereIsServer.Actions.CreateData(_s, _target, _creation); //---------------------- _s = ThereIsServer.ServersInfo.ServerManager.Get_UID_Server(_username_); _target = _username_ + USERNAME_TO_UID; _creation = new DataBaseCreation(UID_MESSAGE, QString.Parse(uid.GetValue())); await ThereIsServer.Actions.CreateData(_s, _target, _creation); //---------------------- return(uid); }