private void AgentDropBoxRequest(MailPacket mail) { var role = ManagerMediator.RoleManager.GetRoleByClientId(mail.ClientId); if (role != null) { //TODO var boxId = Guid.NewGuid().ToString(); var stoc = new WatermelonGameProto.StoCDropBoxReply { BoxId = boxId, CouponsId = "test", Amount = 1000 }; ManagerMediator.Dispatcher.WriteAgentMail(new MailPacket { Id = (int)WatermelonGameProto.MessageId.StoCdropBoxReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); var dbRequest = new GameDBProto.SaveDropBoxRequest { RoleId = role.RoleId, CouponsId = "test", Amount = 1000 }; var dbMail = new MailPacket { Id = (int)GameDBProto.MessageId.SaveDropBoxRequestId, Content = dbRequest.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }; ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Role); } }
private void DBLoadConfigReply(MailPacket mail) { var replay = GameDBProto.LoadConfigReply.Parser.ParseFrom(mail.Content); FruitConfig = replay.FruitConfig.Unpack <WatermelonConfigProto.FruitConfig>(); TruntableConfig = replay.TruntableConfig.Unpack <WatermelonConfigProto.TruntableConfig>(); }
private void AgentGameOverRequest(MailPacket mail) { var role = ManagerMediator.RoleManager.GetRoleByClientId(mail.ClientId); if (role != null) { var score = _roleScoreDict.GetValueOrDefault(role.RoleId); _roleScoreDict[role.RoleId] = 0; var dbRequest = new GameDBProto.SaveRoleScoreRequest { RoleId = role.RoleId, Score = score }; var dbMail = new MailPacket { Id = (int)GameDBProto.MessageId.SaveRoleScoreRequestId, Content = dbRequest.ToByteArray(), UserId = role.UserId, ClientId = role.ClientId }; ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Role); } var stoc = new WatermelonGameProto.StoCGameOverReply(); ManagerMediator.Dispatcher.WriteAgentMail(new MailPacket { Id = (int)WatermelonGameProto.MessageId.StoCgameOverReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); }
private void AgentCombineFruitRequest(MailPacket mail) { var role = ManagerMediator.RoleManager.GetRoleByClientId(mail.ClientId); if (role != null) { var ctos = WatermelonGameProto.CtoSCombineFruitRequest.Parser.ParseFrom(mail.Content); var stoc = new WatermelonGameProto.StoCCombineFruitReply { }; var fruit = ManagerMediator.ConfigManager.FruitConfig.Items.GetValueOrDefault(ctos.CombineFruitId); if (fruit != null) { var score = _roleScoreDict.GetValueOrDefault(role.RoleId); score += fruit.Score; _roleScoreDict[role.RoleId] = score; stoc.Score = fruit.Score; } ManagerMediator.Dispatcher.WriteAgentMail(new MailPacket { Id = (int)WatermelonGameProto.MessageId.StoCcombineFruitReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); } }
public void BeforeLeaveGame(BeforeLeaveGameRequest request, long clientId) { var role = ManagerMediator.RoleManager.GetRoleByClientId(clientId); if (role != null) { if (_roleScoreDict.TryGetValue(role.RoleId, out var score)) { if (score > 0) { var dbRequest = new GameDBProto.SaveRoleScoreRequest { RoleId = role.RoleId, Score = score }; var dbMail = new MailPacket { Id = (int)GameDBProto.MessageId.SaveRoleScoreRequestId, Content = dbRequest.ToByteArray(), UserId = role.UserId, ClientId = role.ClientId }; ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Role); } _roleScoreDict.Remove(role.RoleId); } } }
private static void HandleCollect(GameSession session, PacketReader packet) { int id = packet.ReadInt(); packet.ReadInt(); // Get items and add to inventory List <Item> items = session.Player.Mailbox.Collect(id); if (items == null) { return; } foreach (Item item in items) { session.Player.Inventory.Remove(item.Uid, out Item removed); InventoryController.Add(session, item, true); // Item packet, not sure if this is only used for mail, it also doesn't seem to do anything session.Send(ItemPacket.ItemData(item)); } session.Send(MailPacket.CollectedAmount(id, DateTimeOffset.UtcNow.ToUnixTimeSeconds())); session.Send(MailPacket.CollectResponse(id, DateTimeOffset.UtcNow.ToUnixTimeSeconds())); }
private void DBEnterRoleReply(MailPacket mail) { var replay = GameDBProto.EnterRoleReply.Parser.ParseFrom(mail.Content); var stoc = new ClientServerProto.StoCEnterRoleReply { Result = new ClientServerProto.ReplayResult { ErrorCode = replay.Result.ErrorCode, ErrorInfo = replay.Result.ErrorInfo }, RoleId = replay.RoleId, NickName = replay.NickName }; Dispatcher.WriteAgentMail(new MailPacket { Id = (int)ClientServerProto.MessageId.StoCenterRoleReplyId, Content = stoc.ToByteArray(), Reserve = mail.Reserve, UserId = mail.UserId, ClientId = mail.ClientId }); _clientRoleDict.Add(mail.ClientId, replay.RoleId); var role = new Role { RoleId = replay.RoleId, NickName = replay.NickName, UserId = mail.UserId, ClientId = mail.ClientId }; AddItem(replay.RoleId, role); }
private void OnCreateDeskRequest(MailPacket mail) { var stoc = new ClientServerProto.StoCCreateDeskReply(); var roleId = ManagerMediator.RoleManager.GetRoleIdByClientId(mail.ClientId); var deskId = _room.GetRoleDesk(roleId); if (deskId == 0) { deskId = CreateRoleDesk(roleId, _room.GameType, _room.MaxRoleCount); stoc.DeskId = deskId; } else { stoc.Result = new ClientServerProto.ReplayResult { ErrorCode = 1, ErrorInfo = "already on desk" }; stoc.DeskId = deskId; } Dispatcher.WriteAgentMail(new MailPacket { Id = (int)ClientServerProto.MessageId.StoCcreateDeskReplyId, Content = stoc.ToByteArray(), Reserve = mail.Reserve, UserId = mail.UserId, ClientId = mail.ClientId }); }
private void PostLeaveGameMail(long userId, long clientId) { //退出游戏 var mail1 = new MailPacket { Id = (int)AgentGameProto.MessageId.BeforeLeaveGameRequestId, Content = new AgentGameProto.BeforeLeaveGameRequest { UserId = userId }.ToByteArray(), ClientId = clientId, UserId = userId }; Dispatcher.WriteInnerMail(mail1); var mail2 = new MailPacket { Id = (int)AgentGameProto.MessageId.LeaveGameRequestId, Content = new AgentGameProto.LeaveGameRequest { UserId = userId }.ToByteArray(), ClientId = clientId, UserId = userId }; Dispatcher.WriteInnerMail(mail2); }
private static void HandleSend(GameSession session, PacketReader packet) { string recipientName = packet.ReadUnicodeString(); string title = packet.ReadUnicodeString(); string body = packet.ReadUnicodeString(); if (recipientName == session.Player.Name) { session.Send(MailPacket.Error((byte)MailErrorCode.CannotMailYourself)); return; } if (!DatabaseManager.Characters.NameExists(recipientName)) { session.Send(MailPacket.Error((byte)MailErrorCode.CharacterNotFound)); return; } Player recipient = GameServer.Storage.GetPlayerByName(recipientName); if (recipient == null) { recipient = DatabaseManager.Characters.FindPartialPlayerByName(recipientName); } MailHelper.SendMail(MailType.Player, recipient.CharacterId, session.Player.CharacterId, session.Player.Name, title, body, "", "", null, 0, out Mail mail); session.Send(MailPacket.Send(mail)); }
private static void HandleCollect(GameSession session, PacketReader packet) { long id = packet.ReadLong(); Mail mail = session.Player.Mailbox.FirstOrDefault(x => x.Id == id); if (mail == null) { return; } if (mail.Items.Count == 0) { return; } foreach (Item item in mail.Items) { item.MailId = 0; InventoryController.Add(session, item, true); } mail.Items.Clear(); DatabaseManager.Mails.UpdateReadTime(mail); session.Send(MailPacket.Collect(mail)); session.Send(MailPacket.UpdateReadTime(mail)); }
private static void HandleOpen(GameSession session) { session.Player.Mailbox.ClearExpired(); session.Send(MailPacket.StartOpen()); session.Send(MailPacket.Open(session.Player.Mailbox.Box)); session.Send(MailPacket.EndOpen()); }
public bool WriteAgentMail(int id, byte[] content, long reserve, long userId) { var clientId = _agentClientIdProvider.GetUserClientId(userId); var mail = new MailPacket { Id = id, Content = content, Reserve = reserve, UserId = userId, ClientId = clientId }; return(WriteAgentMail(mail)); }
public bool TryWriteMail(MailPacket mail) { if (_mailChannel.Writer.TryWrite(mail)) { Interlocked.Increment(ref _totalMailCount); return(true); } return(false); }
private static void HandleRead(GameSession session, PacketReader packet) { int id = packet.ReadInt(); packet.ReadInt(); long timestamp = session.Player.Mailbox.Read(id); session.Send(MailPacket.Read(id, timestamp)); }
public void OnStartUp() { var dbRequest = new GameDBProto.LoadConfigRequest { }; var dbMail = new MailPacket { Id = (int)GameDBProto.MessageId.LoadConfigRequestId, Content = dbRequest.ToByteArray(), }; Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Other); }
public void OnDBMail(MailPacket mail) { switch (mail.Id) { case (int)GameDBProto.MessageId.GetRankReplyId: DBGetRankReply(mail); break; default: break; } }
public void OnAgentMail(MailPacket mail) { switch (mail.Id) { case (int)WatermelonGameProto.MessageId.CtoSgetConfigRequestId: OnGetConfigRequest(mail); break; default: break; } }
public void OnDBMail(MailPacket mail) { var roleId = ManagerMediator.RoleManager.GetRoleIdByClientId(mail.ClientId); var desk = _room.GetDesk(_room.GetRoleDesk(roleId)); if (desk != null) { if (desk.GameLogic is IDBMail dbMail) { dbMail.OnDBMail(mail); } } }
private static void HandleOpen(GameSession session) { session.Send(MailPacket.StartOpen()); IEnumerable <List <Mail> > packetCount = ResponseKeyHandler.SplitList(session.Player.Mailbox, 5); foreach (List <Mail> mails in packetCount) { session.Send(MailPacket.Open(mails)); } session.Send(MailPacket.EndOpen()); }
private void AgentGetRankRequest(MailPacket mail) { var dbRequest = new GameDBProto.GetRankRequest { }; var dbMail = new MailPacket { Id = (int)GameDBProto.MessageId.GetRankRequestId, Content = dbRequest.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }; ManagerMediator.Dispatcher.WriteDBMail(dbMail, DBMailQueueType.Other); }
public void OnAgentMail(MailPacket mail) { //_logger.LogDebug(mail.ToString()); switch (mail.Id) { case (int)ClientServerProto.MessageId.CtoStestNetwordDelayRequestId: OnTestNetwordDelayRequest(mail); break; default: break; } }
private void OnGetConfigRequest(MailPacket mail) { var stoc = new WatermelonGameProto.StoCGetConfigReply { FruitConfig = FruitConfig, TruntableConfig = TruntableConfig }; Dispatcher.WriteAgentMail(new MailPacket { Id = (int)WatermelonGameProto.MessageId.StoCgetConfigReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); }
private void OnLeaveRoomRequest(MailPacket mail) { PostLeaveGameMail(mail.UserId, mail.ClientId); var stoc = new ClientServerProto.StoCLeaveRoomReply(); Dispatcher.WriteAgentMail(new MailPacket { Id = (int)ClientServerProto.MessageId.StoCleaveRoomReplyId, Content = stoc.ToByteArray(), Reserve = mail.Reserve, UserId = mail.UserId, ClientId = mail.ClientId }); }
private static void HandleCollect(GameSession session, PacketReader packet) { long id = packet.ReadLong(); Mail mail = session.Player.Mailbox.FirstOrDefault(x => x.Id == id); if (mail == null) { return; } if (mail.Items.Count == 0 && mail.Mesos == 0 && mail.Merets == 0) { return; } if (mail.Items.Count > 0) { foreach (Item item in mail.Items) { item.MailId = 0; DatabaseManager.Items.Update(item); session.Player.Inventory.AddItem(session, item, true); } mail.Items.Clear(); session.Send(MailPacket.Collect(mail)); } if (mail.Mesos > 0) { if (!session.Player.Wallet.Meso.Modify(mail.Mesos)) { return; } mail.Mesos = 0; } if (mail.Merets > 0) { if (!session.Player.Account.Meret.Modify(mail.Merets)) { return; } mail.Merets = 0; } DatabaseManager.Mails.Update(mail); session.Send(MailPacket.UpdateReadTime(mail)); }
public bool WriteAgentMail(MailPacket mail) { var clientId = mail.ClientId; if (clientId == 0) { clientId = _agentClientIdProvider.GetUserClientId(mail.UserId); } var outgoMailQueue = _agentMailQueueRepository.TryGetOutgoMailQueue(clientId); if (outgoMailQueue != null) { return(outgoMailQueue.TryWriteMail(mail)); } return(false); }
private void OnTestNetwordDelayRequest(MailPacket mail) { var ticks = _userTick[mail.ClientId]; var currentTicks = Dispatcher.TicksProvider.TicksCache; var stoc = new ClientServerProto.StoCTestNetworkDelayReply { CurrentTicks = currentTicks, DelayTicks = currentTicks - ticks }; Dispatcher.WriteAgentMail(new MailPacket { Id = (int)ClientServerProto.MessageId.StoCtestNetworkDelayReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); }
public void OnAgentMail(MailPacket mail) { switch (mail.Id) { case (int)ClientServerProto.MessageId.CtoSjoinRoomRequestId: OnJoinRoomRequest(mail); break; case (int)ClientServerProto.MessageId.CtoSleaveRoomRequestId: OnLeaveRoomRequest(mail); break; case (int)ClientServerProto.MessageId.CtoScreateDeskRequestId: OnCreateDeskRequest(mail); break; case (int)ClientServerProto.MessageId.CtoSjoinDeskRequestId: OnJoinDeskRequest(mail); break; case (int)ClientServerProto.MessageId.CtoSleaveDeskRequestId: OnLeaveDeskRequest(mail); break; default: break; } var roleId = ManagerMediator.RoleManager.GetRoleIdByClientId(mail.ClientId); if (roleId > 0) { var deskId = _room.GetRoleDesk(roleId); if (deskId > 0) { var desk = _room.GetDesk(deskId); if (desk != null) { if (desk.GameLogic is IAgentMail agentMail) { agentMail.OnAgentMail(mail); } } } } }
public void OnAgentMail(MailPacket mail) { //_logger.LogDebug(mail.ToString()); switch (mail.Id) { case (int)ClientServerProto.MessageId.CtoSenterRoleRequestId: OnEnterRoleRequest(mail); break; case (int)ClientServerProto.MessageId.CtoSroleInfoRequestId: OnRoleInfoRequest(mail); break; default: break; } }
private void DBGetRankReply(MailPacket mail) { var replay = GameDBProto.GetRankReply.Parser.ParseFrom(mail.Content); var stoc = new WatermelonGameProto.StoCGetRankReply(); foreach (var item in replay.RoleScores) { stoc.RoleScores.Add(new WatermelonGameProto.RoleScore { RoleId = item.RoleId, NickName = item.NickName, Score = item.Score }); } ManagerMediator.Dispatcher.WriteAgentMail(new MailPacket { Id = (int)WatermelonGameProto.MessageId.StoCgetRankReplyId, Content = stoc.ToByteArray(), UserId = mail.UserId, ClientId = mail.ClientId }); }