/// <summary> /// 处理客户端发送的聊天信息 /// </summary> public void HandleSendChat(Unit unit, eChatType type, CharacterIdxOrName receiver, string content) { switch (type) { case eChatType.PRIVATE: //私聊 Unit target = null; if (receiver.IsIdxValid()) { // 不能对自己发送 if (receiver.char_idx == unit.char_idx) { return; } target = UnitManager.Instance.GetUnitByIdx(receiver.char_idx); } else { if (receiver.char_name == unit.char_name) { return; } target = UnitManager.Instance.GetUnitByName(receiver.char_name); } if (target != null) { //直接发给对方 ss2c.ChatRecv msg = PacketPools.Get(ss2c.msg.CHAT_RECV) as ss2c.ChatRecv; msg.type = type; msg.sender.Set(unit.char_idx, unit.char_name); msg.chat_content = content; ServerNetManager.Instance.SendProxy(target.client_uid, msg); } else { //告诉对方不在线 ss2c.ChatResult msg = PacketPools.Get(ss2c.msg.CHAT_RESULT) as ss2c.ChatResult; msg.error = eChatError.ERROR_DST_OFFLINE; ServerNetManager.Instance.SendProxy(unit.client_uid, msg); } break; case eChatType.GROUP: //组队聊天 break; case eChatType.GUILD: //军团聊天 break; } }
/// <summary> /// 处理客户端发送的聊天信息 /// </summary> public void HandleSendChat(Player player, eChatType type, CharacterIdxOrName receiver, string content) { //TODO:是否禁言 switch (type) { case eChatType.PRIVATE: //私聊 Player target = null; if (receiver.IsIdxValid()) { // 不能对自己发送 if (receiver.char_idx == player.char_idx) { return; } target = UnitManager.Instance.GetPlayerByIdx(receiver.char_idx); } else { if (receiver.char_name == player.char_name) { return; } target = UnitManager.Instance.GetPlayerByName(receiver.char_name); } if (target != null) { //如果本服玩家在线,直接发送 //检测是否在对方黑名单 if (RelationManager.Instance.HaveRelationFlag(player.char_idx, target.char_idx, eRelationFlag.Block)) { ss2c.ChatResult msg = PacketPools.Get(ss2c.msg.CHAT_RESULT) as ss2c.ChatResult; msg.error = eChatError.ERROR_DST_REFUSE; ServerNetManager.Instance.SendProxy(target.client_uid, msg); } else { //直接发给对方 ss2c.ChatRecv msg = PacketPools.Get(ss2c.msg.CHAT_RECV) as ss2c.ChatRecv; msg.type = type; msg.sender.Set(player.char_idx, player.char_name); msg.chat_content = content; ServerNetManager.Instance.SendProxy(player.client_uid, msg); } } else { //通过ws转发 ss2ws.ChatSend msg = PacketPools.Get(ss2ws.msg.CHAT_SEND) as ss2ws.ChatSend; msg.type = type; msg.sender.Set(player.char_idx, player.char_name); msg.receiver = receiver; msg.chat_content = content; ServerNetManager.Instance.Send2WS(msg); } break; case eChatType.WORLD: //世界聊天 { ss2c.ChatRecv msg = PacketPools.Get(ss2c.msg.CHAT_RECV) as ss2c.ChatRecv; msg.type = type; msg.sender.Set(player.char_idx, player.char_name); msg.chat_content = content; ServerNetManager.Instance.BroadcastProxyMsg(msg); } break; case eChatType.CURRENT: //当前聊天 break; case eChatType.GROUP: //组队聊天 break; case eChatType.GUILD: //军团聊天 break; case eChatType.INSTANCE: //战场聊天 break; } }
/// <summary> /// 聊天错误 /// </summary> private void OnChatError(PacketBase packet) { ss2c.ChatResult msg = packet as ss2c.ChatResult; }