public void SetData(ReservationAllData allData) { this.allData = allData; data = new ReservationData() { ReservationId = allData.ReservationId, SenderName = allData.SenderName, SenderUid = allData.SenderUid, StartUTCTimeTick = allData.StartUTCTimeTick, }; }
public static async ETTask Add(long uid, ReservationAllData allData) { if (await IsExist(uid)) { Log.Error($"AddReservationDB 失敗! uid : {uid} 已經存在!"); return; } ReservationDB reservationDB = ComponentFactory.CreateWithId <ReservationDB>(IdGenerater.GenerateId()); reservationDB.uid = uid; reservationDB.allData = new MongoDB.Bson.BsonBinaryData(allData.ToByteArray()); await dbProxy.Save(reservationDB); }
public static async void Start(this ReservationComponent self) { var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); self.MemorySync = proxy.GetMemorySyncSolver <Reservation>(); self.MemorySync.onCreate += self.OnCreated; self.MemorySync.onWillDelete += self.OnWillDeleted; var reservations = await ReservationDataHelper.GetAll(); for (int i = 0; i < reservations.Count; i++) { if (reservations[i].allData == null) { await ReservationDataHelper.Remove(reservations[i].uid); continue; } // 解析預約 ReservationAllData allData = new ReservationAllData(); CodedInputStream codedInputStream = new CodedInputStream(reservations[i].allData.Bytes); allData.MergeFrom(codedInputStream); // 判斷是否過期 if (DateTime.UtcNow.Ticks > allData.AwakeUTCTimeTick) { await ReservationDataHelper.Remove(reservations[i].uid); continue; } // 實體化預約 await self.CreateReservation(allData); } }
private async ETVoid RunAsync(Session session, C2G_TeamReservationCreate message, Action <G2C_TeamReservationCreate> reply) { G2C_TeamReservationCreate response = new G2C_TeamReservationCreate(); try { //取得自身資料 Player player = session.GetComponent <SessionPlayerComponent>().Player; User user = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault()); if (user == null) { response.Error = ErrorCode.ERR_AccountDoesntExist; reply(response); return; } var reservationComponent = Game.Scene.GetComponent <ReservationComponent>(); var reservationList = reservationComponent.GetByUid(player.uid); if (reservationList?.OwnCount >= ReservationDataHelper.ReservationMaxCount) { response.Error = ErrorCode.ERR_ReservationIsFull; reply(response); return; } var reservationData = new ReservationAllData() { ReservationId = IdGenerater.GenerateId(), SenderName = user.name, SenderUid = player.uid, RoadSettingId = message.RoadSettingId, AwakeUTCTimeTick = message.StartUTCTimeTick - ReservationDataHelper.AwakeBeforeTimeTick, StartUTCTimeTick = message.StartUTCTimeTick, }; //邀請對象加入自己 reservationData.MemberUid.Add(player.uid); //邀請對象加入其他成員 if (message.MemberUid?.Count > 0) { reservationData.MemberUid.AddRange(message.MemberUid); } //寫入DB await ReservationDataHelper.Add(reservationData.ReservationId, reservationData); //建立預約資料實體 var newReservation = await reservationComponent.CreateReservation(reservationData); var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); //告知成員 for (int i = 0; i < reservationData.MemberUid?.Count; i++) { //告知對方 long targetMemberUid = reservationData.MemberUid[i]; Player reservationTarget = playerSync.Get <Player>(targetMemberUid); if (reservationTarget != null) { //在線上 廣播給指定玩家邀請訊息 G2C_TeamReservationAdd g2c_TeamReservationAdd = new G2C_TeamReservationAdd(); g2c_TeamReservationAdd.ReservationData = newReservation.data; GateMessageHelper.BroadcastTarget(g2c_TeamReservationAdd, new[] { targetMemberUid }); } // 推播 User u = await UserDataHelper.FindOneUser(targetMemberUid); var firebase = Game.Scene.GetComponent <FirebaseComponent>(); var lang = Game.Scene.GetComponent <LanguageComponent>(); //多國3-'{0}'預約了比賽並邀請你參加!預約時間為{1}。 var str = lang.GetString(u.language, 3L); //多國4-時。 var hourStr = lang.GetString(u.language, 4L); //多國5-分。 var minuteStr = lang.GetString(u.language, 5L); //多國6-秒。 var secondStr = lang.GetString(u.language, 6L); DateTime date = new DateTime(reservationData.StartUTCTimeTick); TimeSpan remainder = date - DateTime.UtcNow; string dateStr = string.Empty; List <string> list = new List <string>(); if (remainder.Hours > 0) { list.Add($"{remainder.Hours}{hourStr}"); } if (remainder.Minutes > 0) { list.Add($"{remainder.Minutes}{minuteStr}"); } //if (remainder.Seconds > 0) //{ // list.Add($"{remainder.Seconds}{secondStr}"); //} dateStr += string.Join(" ", list); await firebase.SendOneNotification(u.firebaseDeviceToken, string.Empty, string.Format(str, user.name, dateStr)); } //回傳資料 response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static async ETTask <Reservation> CreateReservation(this ReservationComponent self, ReservationAllData reservationData) { Reservation reservation = ComponentFactory.CreateWithId <Reservation>(reservationData.ReservationId); reservation.SetData(reservationData); await self.MemorySync.Create(reservation); reservation.IsInitialized = true; return(reservation); }