Exemplo n.º 1
0
        private MessageStatus SendFileMessage(Message mesg)
        {
            if (mesg.To is Member)
            {
                Member to = mesg.To as Member;
                if (!Online.ContainsKey(to.Id))
                {
                    return MessageStatus.Failed;
                }

                ChatEventHandler handler = Online[to.Id] as ChatEventHandler;
                ChatterService service = handler.Target as ChatterService;

                if (!service.friends.ContainsKey(member.Id))
                {
                    return MessageStatus.Refuse;
                }

                FileMessage fm = mesg as FileMessage;
                TCPHolePunching tcpServer = new TCPHolePunching(this,service, fm.Guid) ;
                var serverEndPoint = tcpServer.GetServerEndPoint();
                if (serverEndPoint == null)
                {
                    throw (new Exception("TCP打洞:Server Endpoint 初始化失败"));
                }

                fm.EndPoint = new MyEndPoint() { Address = serverEndPoint.Address.ToString(), Port = serverEndPoint.Port };
                mesg = fm;
                service.callback.OnSendMessage(mesg);





                return MessageStatus.OK;
            }
            else
            {
                throw new Exception("not support user type ");
            }
        }
Exemplo n.º 2
0
        private MessageStatus SendTextMessage(Message mesg)
        {



            if (mesg.To is Member)
            {
                Member to = mesg.To as Member;
                if (!Online.ContainsKey(to.Id))
                {
                    return MessageStatus.Failed;
                }

                ChatEventHandler handler = Online[to.Id] as ChatEventHandler;
                ChatterService service = handler.Target as ChatterService;

                if (!service.friends.ContainsKey(member.Id))
                {
                    return MessageStatus.Refuse;
                }

                service.callback.OnSendMessage(mesg);



                return MessageStatus.OK;
            }
            else
            {
                throw new Exception("not support user type ");
            }
        }
Exemplo n.º 3
0
        public MessageStatus SendMesg(Message mesg)
        {

            try
            {
                if (mesg is TextMessage)
                {
                    return SendTextMessage(mesg);
                }

                else if (mesg is FileMessage)
                {
                    return SendFileMessage(mesg);
                }
                else if (mesg is CommandMessage)
                {
                    return SendTextMessage(mesg);
                }
                else if (mesg is AudioMessage)
                {
                    return SendAudioMessage(mesg);
                }

                else
                {
                    throw new Exception("not suppor message type");
                }
            }


            catch (Exception ex)
            {
                MyLogger.Logger.Error("转发信息出错", ex);
                return MessageStatus.Failed;
            }


        }