protected async ETTask RunAsync(Session session, C2G_TeamInviteRefuse message, Action <G2C_TeamInviteRefuse> reply) { G2C_TeamInviteRefuse response = new G2C_TeamInviteRefuse(); 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 inviteComponent = Game.Scene.GetComponent <InviteComponent>(); var invite = inviteComponent.GetByInviteId(message.InviteId); if (invite == null) { response.Error = ErrorCode.ERR_InviteIdNotFind; reply(response); return; } if (invite.data.ReceiverUid != player?.uid) { response.Error = ErrorCode.ERR_InviteNotSelf; reply(response); return; } //告知對方拒絕邀請 var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); Player senderTarget = playerSync.Get <Player>(invite.data.SenderUid); if (senderTarget != null) { G2C_TeamInviteTargerRefuse g2c_TeamInviteTargerRefuse = new G2C_TeamInviteTargerRefuse(); g2c_TeamInviteTargerRefuse.RefuseUid = player.uid; GateMessageHelper.BroadcastTarget(g2c_TeamInviteTargerRefuse, invite.data.SenderUid); } //刪除該邀請 await inviteComponent.DestroyByInviteId(message.InviteId); //回傳資料 response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
private async ETTask RunAsync(Player player, C2L_AddRelationship message, Action <L2C_AddRelationship> reply) { L2C_AddRelationship response = new L2C_AddRelationship(); try { long uid = player.uid; //Apply var relationshipApply = await RelationshipDataHelper.AddRelationshipApply(uid, message.Uid); if (relationshipApply == null) { response.Error = ErrorCode.ERR_RelationshipApplyInfo_AddFailed; reply(response); return; } response.Error = ErrorCode.ERR_Success; reply(response); // 確認玩家是在線,在線的話傳送好友資訊 var relationshipApplyInfo = RelationshipApply.ConvertToRelationshipApplyInfo(relationshipApply); var uidUser = await UserDataHelper.FindOneUser(uid); var receiverUidUser = await UserDataHelper.FindOneUser(message.Uid); var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); Player target = playerSync.Get <Player>(message.Uid); if (target != null) { var notifyRelationshipState_SenderNotRequested = new L2C_NotifyRelationshipApplyState() { AddApplyInfo = relationshipApplyInfo, IsRequested = false, }; GateMessageHelper.BroadcastTarget(notifyRelationshipState_SenderNotRequested, message.Uid); } //傳給自己更新Apply列表 var notifyRelationshipState_SenderIsRequested = new L2C_NotifyRelationshipApplyState() { AddApplyInfo = relationshipApplyInfo, IsRequested = true, }; GateMessageHelper.BroadcastTarget(notifyRelationshipState_SenderIsRequested, uid); // 推播告知receiverUser var firebase = Game.Scene.GetComponent <FirebaseComponent>(); var lang = Game.Scene.GetComponent <LanguageComponent>(); // 7 = {0}向你發出好友邀請! var body = lang.GetString(receiverUidUser.language, 7); await firebase.SendOneNotification(receiverUidUser.firebaseDeviceToken, string.Empty, string.Format(body, uidUser.name)); } catch (Exception e) { ReplyError(response, e, reply); } }
public override async void Run(long uid, long configId, int count) { var lobbyComponent = Game.Scene.GetComponent <LobbyComponent>(); if (lobbyComponent == null) { Console.WriteLine($"The command needs to use lobbyComponent"); return; } if (uid <= 0) { Console.WriteLine($"uid:{uid} <= 0 is invalid"); return; } if (!EquipmentDataHelper.TryGetEquipmentConfig(configId, out CharacterConfig characterConfig)) { Console.WriteLine($"configId:{configId} is invalid"); return; } if (count <= 0) { Console.WriteLine($"count:{count} <= 0 is invalid"); return; } var result = await EquipmentDataHelper.DeleteEquipment(uid, new List <EquipmentInfo> { new EquipmentInfo { Id = 0, ConfigId = configId, Count = count } }, EquipmentDataHelper.EquipmentFrom.System, (int)EquipmentDataHelper.SystemUid.Console, true); if (result.error == ErrorCode.ERR_Success) { GateMessageHelper.BroadcastTarget(new L2C_OnEquipmentsDeleted { FromUid = (int)EquipmentDataHelper.SystemUid.Console, EquipmentInfoList = result.equipmentInfos, UserBagInfo = result.userBagInfo, }, uid); Console.WriteLine($"ok"); } else { Console.WriteLine($"error code: {result.error}"); } }
public static void DisconnectSession(long uid, int disconnectInfo) { Log.Info($"SendForceDisconnect Start, uid:{uid}, disconnectInfo:{disconnectInfo}"); G2C_ForceDisconnect message = new G2C_ForceDisconnect() { DisconnectInfo = disconnectInfo }; GateMessageHelper.BroadcastTarget(message, uid); Log.Info($"SendForceDisconnect End, uid:{uid}, disconnectInfo:{disconnectInfo}"); }
protected async ETTask RunAsync(Session session, C2G_TeamInviteRefuseAll message, Action <G2C_TeamInviteRefuseAll> reply) { G2C_TeamInviteRefuseAll response = new G2C_TeamInviteRefuseAll(); 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 inviteComponent = Game.Scene.GetComponent <InviteComponent>(); var inviteList = inviteComponent.GetByUid(player.uid); var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); for (int i = 0; i < inviteList.Count; i++) { //告知對方拒絕邀請 Player senderTarget = playerSync.Get <Player>(inviteList[i].data.SenderUid); if (senderTarget != null) { G2C_TeamInviteTargerRefuse g2c_TeamInviteTargerRefuse = new G2C_TeamInviteTargerRefuse(); g2c_TeamInviteTargerRefuse.RefuseUid = player.uid; GateMessageHelper.BroadcastTarget(g2c_TeamInviteTargerRefuse, inviteList[i].data.SenderUid); } } //刪除自身全部邀請 await inviteComponent.DestroyByUid(player.uid); //回傳資料 response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public async override void Run(long messageId) { StartConfig startConfig = Game.Scene.GetComponent <StartConfigComponent>().StartConfig; if (!appTypes.Contains(startConfig.AppType)) { Log.Warning($"not supported server type on event: {typeof(Event_MessageTip).Name}!"); return; } var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var messageTipSetting = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(MessageTipSetting), messageId) as MessageTipSetting; if (messageTipSetting != null) { foreach (var playerData in playerSync.Data) { var uid = playerData.Key; var user = await UserDataHelper.FindOneUser(uid); var tipContent = string.Empty; switch (user.language) { //SystemLanguage.English default: case 10: tipContent = messageTipSetting.en_context; break; //SystemLanguage.ChineseTraditional case 41: tipContent = messageTipSetting.zh_tw_context; break; } GateMessageHelper.BroadcastTarget(new G2C_MessageTip() { TipContent = tipContent }, uid); } } }
private static async void SaveUserAndBroadcastTarget(MapUnit mapUnit, User user, BsonDocument log) { await UserDataHelper.UpsertUser(user, DBLog.LogType.UpdateUserRideTotalRecord, log); // 如果玩家在線上 告知該玩家異動紀錄 var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); Player selfPlayer = playerSync.Get <Player>(mapUnit.Uid); if (selfPlayer != null) { PlayerRideTotalInfo playerRideTotalInfo = await UserDataHelper.QueryUserRideAllRecord(user); G2C_UpdatePlayerRideTotalInfo g2c_UpdatePlayerRideInfo = new G2C_UpdatePlayerRideTotalInfo() { TotalInfo = playerRideTotalInfo, }; GateMessageHelper.BroadcastTarget(g2c_UpdatePlayerRideInfo, mapUnit.Uid); } }
private async ETTask RunAsync(Player player, C2L_RemoveRelationship message, Action <L2C_RemoveRelationship> reply) { L2C_RemoveRelationship response = new L2C_RemoveRelationship(); try { long uid = player.uid; await RelationshipDataHelper.RemoveRelationship(uid, message.Uid); response.Error = ErrorCode.ERR_Success; reply(response); L2C_NotifyRelationshipState notifyRelationshipState = new L2C_NotifyRelationshipState(); RelationshipSimpleInfo info = new RelationshipSimpleInfo(); { info.Uid = uid; } notifyRelationshipState.Info = info; GateMessageHelper.BroadcastTarget(notifyRelationshipState, message.Uid); } catch (Exception e) { ReplyError(response, e, reply); } }
private async ETTask RunAsync(Player player, C2L_RefuseRelationshipApply message, Action <L2C_RefuseRelationshipApply> reply) { L2C_RefuseRelationshipApply response = new L2C_RefuseRelationshipApply(); try { long uid = player.uid; //尋找指定RelationshipApplyInfo var targetApplyInfo = await RelationshipDataHelper.GetRelationshipApplyInfoByApplyId(message.ApplyId); //判斷是否存在RelationshipApplyInfo if (targetApplyInfo == null) { response.Error = ErrorCode.ERR_RelationshipApplyInfo_NotFind; reply(response); return; } //判斷是否為申請目標 if (targetApplyInfo.ReceiverUid != uid) { response.Error = ErrorCode.ERR_RelationshipApplyInfo_NotReceiver; reply(response); return; } // 刪除關係申請 await RelationshipDataHelper.RemoveRelationship(targetApplyInfo.ApplyId); // 傳送senderUser更新申請列表 var notifyRelationshipApplyStateIsRequested = new L2C_NotifyRelationshipApplyState() { DeleteApplyId = message.ApplyId, IsRequested = true, }; GateMessageHelper.BroadcastTarget(notifyRelationshipApplyStateIsRequested, targetApplyInfo.SenderUid); // 傳送receiverUser更新申請列表 var notifyRelationshipApplyStateNotRequested = new L2C_NotifyRelationshipApplyState() { DeleteApplyId = message.ApplyId, IsRequested = false, }; GateMessageHelper.BroadcastTarget(notifyRelationshipApplyStateNotRequested, targetApplyInfo.ReceiverUid); var uidUser = await UserDataHelper.FindOneUser(uid); var senderUser = await UserDataHelper.FindOneUser(targetApplyInfo.SenderUid); // 推播告知senderUser var firebase = Game.Scene.GetComponent <FirebaseComponent>(); var lang = Game.Scene.GetComponent <LanguageComponent>(); // 8 = {0}拒絕你的好友邀請! var body = lang.GetString(senderUser.language, 8); await firebase.SendOneNotification(senderUser.firebaseDeviceToken, string.Empty, string.Format(body, uidUser.name)); response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(MapUnit mapUnit, C2M_TeamInvite message, Action <M2C_TeamInvite> reply) { await ETTask.CompletedTask; M2C_TeamInvite response = new M2C_TeamInvite(); try { if (mapUnit.Room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } if (mapUnit.Room.Type != RoomType.Team) { response.Error = ErrorCode.ERR_RoonTypeError; reply(response); return; } if (mapUnit.Room.State != RoomState.Start) { response.Error = ErrorCode.ERR_RoomTeamStateCanNotInvite; reply(response); return; } User user = await UserDataHelper.FindOneUser(mapUnit.Uid); if (user == null) { response.Error = ErrorCode.ERR_AccountDoesntExist; reply(response); return; } // 建立邀請 InviteData inviteData = new InviteData() { SenderName = user.name, SenderUid = mapUnit.Uid, ReceiverUid = message.ReceiverUid, TeamRoomId = mapUnit.Room.Id, RoadSettingId = mapUnit.Room.info.RoadSettingId }; var player = CacheExHelper.GetFromCache <Player>(mapUnit.Uid); var lobbySession = SessionHelper.GetLobbySession(player.lobbyAppId); L2M_CreateInvite l2M_CreateInvite = (L2M_CreateInvite)await lobbySession.Call(new M2L_CreateInvite { InviteInfo = inviteData, }); if (l2M_CreateInvite.Error != ErrorCode.ERR_Success) { response.Error = ErrorCode.ERR_InviteIdNotFind; reply(response); return; } Invite inviteEntity = BsonSerializer.Deserialize <Invite>(l2M_CreateInvite.Json); CacheExHelper.WriteInCache(inviteEntity, out inviteEntity); // 告知對方 Player inviteTarget = CacheExHelper.GetFromCache <Player>(message.ReceiverUid); if (inviteTarget != null) { //在線上 廣播給指定玩家邀請訊息 G2C_TeamInviteReceiver g2c_TeamInviteReceiver = new G2C_TeamInviteReceiver(); g2c_TeamInviteReceiver.InviteId = inviteEntity.Id; g2c_TeamInviteReceiver.SenderName = inviteEntity.data.SenderName; GateMessageHelper.BroadcastTarget(g2c_TeamInviteReceiver, message.ReceiverUid); } // 推播 User u = await UserDataHelper.FindOneUser(message.ReceiverUid); var firebase = Game.Scene.GetComponent <FirebaseComponent>(); var lang = Game.Scene.GetComponent <LanguageComponent>(); // 多國2-'{0}'邀請你一起組隊! var body = lang.GetString(u.language, 2L); await firebase.SendOneNotification(u.firebaseDeviceToken, string.Empty, string.Format(body, user.name)); response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
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); } }
private async ETTask RunAsync(Player player, C2L_AcceptRelationshipApply message, Action <L2C_AcceptRelationshipApply> reply) { L2C_AcceptRelationshipApply response = new L2C_AcceptRelationshipApply(); try { long uid = player.uid; //尋找指定RelationshipApplyInfo var targetApplyInfo = await RelationshipDataHelper.GetRelationshipApplyInfoByApplyId(message.ApplyId); //判斷是否存在RelationshipApplyInfo if (targetApplyInfo == null) { response.Error = ErrorCode.ERR_RelationshipApplyInfo_NotFind; reply(response); return; } //判斷是否為申請目標 if (targetApplyInfo.ReceiverUid != uid) { response.Error = ErrorCode.ERR_RelationshipApplyInfo_NotReceiver; reply(response); return; } //建立關係 var relationship = await RelationshipDataHelper.AddRelationship(targetApplyInfo.SenderUid, targetApplyInfo.ReceiverUid); if (relationship == null) { response.Error = ErrorCode.ERR_AddRelationshipRepeatedly; reply(response); return; } var receiverUser = await UserDataHelper.FindOneUser(targetApplyInfo.ReceiverUid); // 刪除關係申請 await RelationshipDataHelper.RemoveRelationship(targetApplyInfo.ApplyId); // 確認senderUser在線, 傳送更新訊息 var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var senderUser = await UserDataHelper.FindOneUser(targetApplyInfo.SenderUid); var senderPlayer = playerSync.Get <Player>(targetApplyInfo.SenderUid); if (senderPlayer != null) { // 更新好友列表 var notifyRelationshipState_Sender = new L2C_NotifyRelationshipState() { Info = new RelationshipSimpleInfo { DisconnectTime = 0, Location = receiverUser.location, Mileage = receiverUser.playerRideTotalInfo.Mileage, Name = receiverUser.name, RelationshipType = relationship.relationshipType, Uid = uid } }; GateMessageHelper.BroadcastTarget(notifyRelationshipState_Sender, targetApplyInfo.SenderUid); // 更新申請列表 var notifyRelationshipApplyStateIsRequested = new L2C_NotifyRelationshipApplyState() { DeleteApplyId = message.ApplyId, IsRequested = true, }; GateMessageHelper.BroadcastTarget(notifyRelationshipApplyStateIsRequested, targetApplyInfo.SenderUid); } // 推播告知senderUser var firebase = Game.Scene.GetComponent <FirebaseComponent>(); var lang = Game.Scene.GetComponent <LanguageComponent>(); // 1 = {0}接受你的好友邀請! var body = lang.GetString(senderUser.language, 1); await firebase.SendOneNotification(senderUser.firebaseDeviceToken, string.Empty, string.Format(body, receiverUser.name)); response.Error = ErrorCode.ERR_Success; reply(response); // 傳送receiverUser更新申請列表 var notifyRelationshipApplyStateNotRequested = new L2C_NotifyRelationshipApplyState() { DeleteApplyId = message.ApplyId, IsRequested = false, }; GateMessageHelper.BroadcastTarget(notifyRelationshipApplyStateNotRequested, targetApplyInfo.ReceiverUid); } catch (Exception e) { ReplyError(response, e, reply); } }