Exemplo n.º 1
0
        /// <summary>
        /// 发送聊天
        /// </summary>
        private void OnChatSend(PacketBase packet)
        {
            ss2ws.ChatSend msg  = packet as ss2ws.ChatSend;
            Unit           unit = UnitManager.Instance.GetUnitByIdx(msg.sender.char_idx);

            if (unit != null)
            {
                ChatManager.Instance.HandleSendChat(unit, msg.type, msg.receiver, msg.chat_content);
            }
        }
Exemplo n.º 2
0
        /// <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;
            }
        }