Exemplo n.º 1
0
 private void tcpClient_PacketReceived(object sender, TcpSessionEventArgs e)
 {
     PacketReceivedDelegate outdelegate = new PacketReceivedDelegate(PacketReceived);
     this.BeginInvoke(outdelegate, e.Data);
 }
Exemplo n.º 2
0
 private void tcpClient_PacketReceived(object sender, TcpSessionEventArgs e)
 {
     object obj = Factory.CreateInstanceObject(e.Data);
     ImageFileMsg fileMsg = obj as ImageFileMsg;
     if (fileMsg!=null )//如果收到的消息对像不为空
     {
         if (fileMsg.type == type.New)//服务器允许上传文件
         { OnFileTransmitBefore(); }//触发文件传输前事件
         else if (fileMsg.type == type.set)
         { TCPSendFile(fileMsg); }//发送文件到服务器
         else if (fileMsg.type == type.get)
         { ReceivedFileBlock(fileMsg); }
         else if (fileMsg.type == type.over)//文件传输结束
         {
             Console.WriteLine("over!");
             OnFileTransmitted();//触发文件传输完成事件
         }
     }
 }
Exemplo n.º 3
0
        private void fileSession_PacketReceived(object sender, TcpSessionEventArgs e)
        {
            if (e.Data.Length < 2) return;
            TCPServerSession Session = sender as TCPServerSession;
            if (DateTime.Now > Session.ConnectTime.AddSeconds(20))
            {//如果客户端连接服务器的时间大于20秒,则视为非法攻击,断开联接
                Session.Disconnect();
                Session.Dispose();
            }

            object obj = Factory.CreateInstanceObject(e.Data);
            if (obj != null)//如果收到的消息对像不为空
            {
                if (obj is ImageFileMsg)//文件传输
                    onFileTransmit(obj as ImageFileMsg, Session);
            }
            else //收到非法消息
                OnBadCommand(Session);
        }
Exemplo n.º 4
0
        /// <summary>
        /// TCP连接数据包到达事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void messageSession_PacketReceived(object sender, TcpSessionEventArgs e)
        {
            Console.WriteLine(e.Data);
            if (e.Data.Length < 2) return;

            TCPServerSession Session = sender as TCPServerSession;

            object obj = Factory.CreateInstanceObject(e.Data);
            if (obj != null)//如果收到的消息对像不为空
            {
                if (obj is Auth)//登录请求
                {
                    if (Login != null)
                        Login(this, new MsgServerEventArgs(Session, e.Data, obj, null));
                }
                else if (Session.IsAuthenticated)//如果提供其他服务客户端必须是已经进行验证后
                {
                    UserVcard RequestUser = Session.Tag as UserVcard;//获得请求用户
                    if (RequestUser == null) return;//如果用户为空,退出

                    if (obj is Message)//请求转发消息
                    {
                        if (Message != null)
                            Message(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is Presence)//请求在线状态
                    {
                        if ((obj as Presence).type == type.set)//设置在线状态
                        {
                            if (Presence != null)
                                Presence(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                        }
                        else if ((obj as Presence).type == type.get)//获得联系人在线状态
                        {
                            if (RequestUsersPresence != null)
                                RequestUsersPresence(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                        }
                    }
                    else if (obj is DownloadGroups)//请求下载的分组信息
                    {
                        if (RequestOrgGroups != null)
                            RequestOrgGroups(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is DownloadUsers)//请求下载用户信息
                    {
                        if (RequestOrgUsers != null)
                            RequestOrgUsers(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is DownloadRooms)//请求下载群信息
                    {
                        if (RequestOrgRooms != null)
                            RequestOrgRooms(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is ChangeRoom)//更新群信息
                    {
                        if (RequestChangeRoom != null)
                            RequestChangeRoom(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is ImageFileMsg )//通知客户端到文件服务器下载已上传完成的文件
                    {
                        if (RouteDownLoadImageFile != null)
                            RouteDownLoadImageFile(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is P2PFileMsg )//转发文件传输消息
                    {
                        if (RouteP2PFileTransmit != null)
                            RouteP2PFileTransmit(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if(obj is AVMsg)//转发音视频对话的消息
                        if (RouteAVMsg != null)
                            RouteAVMsg(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));


                    #region 组织架构信息管理
                    if (obj is UserVcard)//如果是管理员变更用户信息资料
                    {
                        if (RequestChangeUserVcard != null)
                            RequestChangeUserVcard(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is GroupVcard)//如果是管理员变更分组信息资料
                    {
                        if (RequestChangeGroupVcard != null)
                            RequestChangeGroupVcard(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    else if (obj is ChangePassword)//如果是要求修改密码
                    {
                        if (RequestChangePassword != null)
                            RequestChangePassword(this, new MsgServerEventArgs(Session, e.Data, obj, RequestUser));
                    }
                    #endregion

                }
            }
            else //收到非法消息
                OnBadCommand(Session);
        }
Exemplo n.º 5
0
        /// <summary>
        /// TCP连接数据包到达事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void messageSession_PacketReceived(object sender, TcpSessionEventArgs e)
        {
            Console.WriteLine(e.Data);
            if (e.Data.Length < 2) return;

            TCPServerSession Session = sender as TCPServerSession;

            object obj = Factory.CreateInstanceObject(e.Data);
            if (obj != null)//如果收到的消息对像不为空
            {
                if (obj is Auth)//登录请求
                    onLogin(obj as Auth, Session);
                else if (Session.IsAuthenticated)//如果提供其他服务客户端必须是已经进行验证后
                {
                    UserVcard requestUser = Session.Tag as UserVcard;//获得请求用户


                    if (obj is Message)//请求转发消息
                        onMessage(obj as Message, Session);
                    else if (obj is Presence)//请求在线状态
                    {
                        if ((obj as Presence).type == type.set)//设置在线状态
                            onPresence(obj as Presence, Session);
                        else if ((obj as Presence).type == type.get)//获得联系人在线状态
                            onGetUsersPresence(obj as Presence, Session);
                    }
                    else if (obj is Groups)//请求下载的分组信息
                        onOrgGroups(obj as Groups, Session);
                    else if (obj is Users)//请求下载用户信息
                        onOrgUsers(obj as Users, Session);
                    else if (obj is Rooms)//请求下载群信息
                        onOrgRooms(obj as Rooms, Session);
                    else if (obj is ChangeRoom)//更新群信息
                        onChangeRoom(obj as ChangeRoom, Session);
                    else if (obj is TCPImageFile)//通知客户端到文件服务器下载已上传完成的文件
                        onTCPImageFile(obj as TCPImageFile, e.Data, Session);
                    else if (obj is PFile)//转发文件传输消息
                        onPFile(obj as PFile, e.Data, Session);


                    #region 组织架构信息管理
                    if (obj is UserVcard)//如果是管理员变更用户信息资料
                        onUserVcard(obj as UserVcard, e.Data, Session);
                    else if (obj is GroupVcard)
                        onGroupVcard(obj as GroupVcard, e.Data, Session);
                    else if (obj is ChangePassword)
                        onChangePassword(obj as ChangePassword, e.Data, requestUser);
                    #endregion

                }
            }
            else //收到非法消息
                OnBadCommand(Session);
        }