예제 #1
0
        public DataPackage ReceiveData()
        {
            TcpListener listener = new TcpListener(Server_Properties.Property.Ip, Server_Properties.Property.Port);
            listener.Start();
            TcpClient remoteClient = listener.AcceptTcpClient();
            try
            {
                NetworkStream streamToClient = remoteClient.GetStream();
                byte[] buffer = new byte[BufferSize];
                int bytesRead = streamToClient.Read(buffer, 0, BufferSize);

                DataPackage rdp = new DataPackage();

                rdp.User_IP = IPAddress.Parse(GetRemoteIP(remoteClient));
                rdp.Data = buffer;
                remoteClient.Close();
                streamToClient.Close();
                return rdp;
            }
            catch
            {
                return null;
            }
            
        }
예제 #2
0
        public void Analysis(DataPackage data)
        {
            Thread tdAnalysis = new Thread(delegate ()
            {
                short type;
                byte[] bType = new byte[2];

                bType[0] = data.Data[0];
                bType[1] = data.Data[1];
                type = BitConverter.ToInt16(bType, 0);

                switch (type)
                {
                    case 1:            //信息
                        Message message = new Message(data.Data);
                        message.Send();
                        break;
                    case 2:            //登陆
                        AccountLogin accountLogin = new AccountLogin(data);
                        if (accountLogin.Login())
                        {
                            accountLogin.AddToOnlineUserList();
                            Data_BLL data_BLL = new Data_BLL();
                            data_BLL.SendAllMessage(accountLogin.loginData);
                        }
                        accountLogin.Respect();
                        break;
                    case 3:         //账号申请
                        AccountRequest accountRequest = new AccountRequest(data);
                        accountRequest.Respect();
                        break;
                }
            });
            tdAnalysis.Start();
        }
예제 #3
0
 public AccountLogin(DataPackage data)
 {
     LoginDataConvert convert = new LoginDataConvert();
     loginData = convert.ConvertToClass(data.Data);
     onlineUser.Client = data.Client;
     onlineUser.User_id = loginData.User_id;
 }
예제 #4
0
        public bool Response()
        {
            SQLService sql = new SQLService();
            ArrayList arrMsg = sql.SelOverMessages(rr.User_id);
            Sender sender = new Sender(data.Client);

            foreach (object obj in arrMsg)
            {
                MessageData msg = (MessageData)obj;
                MessageDataConvert converter = new MessageDataConvert();
                byte[] dataSend = converter.ConvertToBytes(msg);
                DataPackage dpk = new DataPackage();
                dpk.Data = dataSend;
                dpk.Client = data.Client;
                if (!sender.SendMessage(dpk))
                    return false;
            }

            //结束标识
            DataPackage endDpk = new DataPackage();
            endDpk.Data = BitConverter.GetBytes(0);
            endDpk.Client = data.Client;
            sender.SendMessage(endDpk);

            return true;
        }
예제 #5
0
 public void Send()
 {
     lock (Data.Data.ArrOnlineUsers)
     {
         bool isFoundOnline = false;
         for (int i = 0; i < Data.Data.ArrOnlineUsers.Count; i++)
         {
             Data.OnlineUserProperties user = (Data.OnlineUserProperties)Data.Data.ArrOnlineUsers[i];
             if (msgData.Receiver_id == user.User_id)
             {
                 isFoundOnline = true;
                 DataPackage dataPacksge = new DataPackage();
                 dataPacksge.User_IP = user.Ip;
                 Sender sender = new Sender(dataPacksge);
                 if (sender.SendMessage(dataPacksge))
                     return;
                 else
                 {
                     lock (Data.Data.ArrSendingMessages)
                     {
                         Data.Data.ArrSendingMessages.Add(msgData);
                     }
                 }
             }
         }
         if (!isFoundOnline)
             lock (Data.Data.ArrSendingMessages)
             {
                 Data.Data.ArrSendingMessages.Add(msgData);
             }
     }
 }
예제 #6
0
 public AccountLogin(DataPackage data)
 {
     LoginDataConvert convert = new LoginDataConvert();
     loginData = convert.ConvertToReceive(data.Data);
     onlineUser.Ip = data.User_IP;
     onlineUser.User_id = loginData.User_id;
 }
예제 #7
0
        public DataPackage ReceiveData(TcpClient tcpClient)
        {
            TcpClient remoteClient = tcpClient;
            try
            {
                NetworkStream streamToClient = remoteClient.GetStream();
                byte[] buffer = new byte[BufferSize];
                int bytesRead = streamToClient.Read(buffer, 0, BufferSize);

                DataPackage rdp = new DataPackage();

                rdp.Client = remoteClient;
                int correctSize = 0;
                while (buffer[correctSize] != 0)
                {
                    correctSize++;
                }
                byte[] correctBuffer = new byte[correctSize];
                Buffer.BlockCopy(buffer, 0, correctBuffer, 0, correctSize);

                rdp.Data = buffer;
                return rdp;
            }
            catch(Exception ex)
            {
                throw ex;
            }
            
        }
예제 #8
0
        public bool Respect()
        {
            DataPackage data = new DataPackage();
            data.Client = onlineUser.Client;
            data.Data = convert.ConvertToBytes(isLogined, loginData.Uid);
            Sender sender = new Sender(onlineUser.Client);

            //[未升级] 发送所有消息

            //ArrayList arrTemp = new ArrayList();
            //lock (Data.Data.ArrSendingMessages)
            //{
            //    ArrayList arrNew = Data.Data.ArrSendingMessages;
            //    Data.Data.ArrSendingMessages.Clear();
            //    for (int i = 0; i < arrNew.Count; i++)
            //    {
            //        MessageData msg = (MessageData)arrNew[i];
            //        if (msg.Receiver_id == data.User_id)
            //            arrTemp.Add(msg);
            //        else
            //            Data.Data.ArrSendingMessages.Add(msg);
            //    }
            //}
            //for (int i = 0; i < arrTemp.Count; i++)
            //{
            //    MessageData msg = (MessageData)arrTemp[i];
            //    Newtalking_DAL_Data.MessageDataConvert convert = new Newtalking_DAL_Data.MessageDataConvert();
            //    Message msgSend = new Message(convert.ConvertToBytes(msg));
            //    msgSend.Send();
            //})

            return sender.SendMessage(data);
        }
예제 #9
0
 public void Respect()
 {
     DataPackage data = new DataPackage();
     data.Client = onlineUser.Client;
     data.Data = convert.ConvertToBytes(isLogined, loginData.Uid);
     Sender sender = new Sender(onlineUser.Client);
     sender.SendMessage(data);
 }
예제 #10
0
 public void Respect()
 {
     DataPackage data = new DataPackage();
     data.User_IP = onlineUser.Ip;
     data.Data = convert.ConvertToSend(isLogined);
     Sender sender = new Sender(data);
     sender.SendMessage(data);
 }
예제 #11
0
 public ReadUserInfo(DataPackage data)
 {
     AccountInfoConvet convert = new AccountInfoConvet();
     accountInfo = convert.ConvertToClass(data.Data);
     SQLService sql = new SQLService();
     accountInfo = sql.AccountInfoReader(accountInfo.User_id);
     dataSend.Client = data.Client;
     dataSend.Data = convert.ConvertToBytes(accountInfo);
 }
예제 #12
0
        public AccountRequest(DataPackage data)
        {
            SQLService sql = new SQLService();
            dataRespect.User_IP = data.User_IP;

            LoginData loginData = new LoginData();
            loginData.User_password = convert.ConvertToPassword(data.Data);
            loginData.User_id = sql.AccountRequest(loginData.User_password);
            dataRespect.Data = convert.ConvertToSend(loginData);
        }
예제 #13
0
        public SendUserImage(DataPackage dataPackTemp)
        {
            dataPack = dataPackTemp;
            Buffer.BlockCopy(dataPackTemp.Data, 2, bPackBegin, 0, 4);

            FileCheck fileCheck = new FileCheck();
            FileRequestConvert fileRc = new FileRequestConvert();
            FileRequest fr = fileRc.ConvertToClass_Send(dataPackTemp.Data);
            path = fileCheck.SelUserImage(fr.User_id);
        }
예제 #14
0
        public AccountRequest(DataPackage data)
        {
            SQLService sql = new SQLService();
            dataResponse.Client = data.Client;

            LoginData loginData = convert.ConvertToClass(data.Data);
            loginData.User_id = sql.AccountRequest(loginData.User_password);

            dataResponse.Data = convert.ConvertToBytes(loginData);
        }
예제 #15
0
 public bool SendMessage(DataPackage dp)
 {
     if (client==null) return false;
     try{
         NetworkStream streamToServer = client.GetStream();
         streamToServer.Write(dp.Data, 0, dp.Data.Length);
         return true;
     } catch {
         return false;
     }
 }
예제 #16
0
        public void Send()
        {
            ArrayList arrOnlineUsers = new ArrayList();
            lock (Data.Data.ArrOnlineUsers)
            {
                for (int i = 0; i < Data.Data.ArrOnlineUsers.Count; i++)
                    arrOnlineUsers.Add(Data.Data.ArrOnlineUsers[i]);
            }
            bool isFoundOnline = false;

            //[未升级] 数据库处理
            for (int i = 0; i < arrOnlineUsers.Count; i++)
            {
                Data.OnlineUserProperties user = (Data.OnlineUserProperties)arrOnlineUsers[i];
                if (msgData.Receiver_id == user.User_id)
                {
                    isFoundOnline = true;
                    DataPackage dataPackage = new DataPackage();
                    dataPackage.Client = user.Client;
                    dataPackage.Data = bData;
                    Sender sender = new Sender(dataPackage.Client);
                    if (sender.SendMessage(dataPackage))
                        return;
                    else
                    {
                        //lock (Data.Data.ArrSendingMessages)
                        //{
                        //    Data.Data.ArrSendingMessages.Add(msgData);
                        //}
                        SQLService sql = new SQLService();
                        sql.InsertIntoOverMessages(msgData);
                    }
                    break;
                }
            }
            if (!isFoundOnline)
            {
                SQLService sql = new SQLService();
                sql.InsertIntoOverMessages(msgData);
            }
                //lock (Data.Data.ArrSendingMessages)
                //{
                //    Data.Data.ArrSendingMessages.Add(msgData);
                //}
        }
예제 #17
0
        public byte[] Receive()
        {
            try
            {
                NetworkStream streamToClient = remoteClient.GetStream();
                byte[] buffer = new byte[BufferSize];
                int bytesRead = streamToClient.Read(buffer, 0, BufferSize);

                DataPackage rdp = new DataPackage();

                rdp.Client = remoteClient;
                byte[] data = buffer;
                return data;
            }
            catch
            {
                return null;
            }
        }
예제 #18
0
 public bool Send()
 {
     try {
         byte[] data = new byte[BufferSize - 4];
         Sender sender = new Sender(tcpTarget);
         int op = 0;
         while (fsSend.Read(data, op, BufferSize - 4) != 0)
         {
             byte[] bResult = new byte[BufferSize];
             bPackSendBegin.CopyTo(bResult, 0);
             data.CopyTo(bResult, 4);     
             DataPackage dpk = new DataPackage();
             dpk.Data = data;
             sender.SendMessage(dpk);
         }
         fsSend.Close();
         return true; }
     catch
     {
         return false;
     }
 }
예제 #19
0
        public bool Response()
        {
            try
            {
                SQLService sql = new SQLService();
                System.Collections.ArrayList arr = sql.SearchAccount(selAcc);

                foreach (object obj in arr)
                {
                    Sender sender = new Sender(client);
                    DataPackage dpk = new DataPackage();
                    AccountInfoConvet converter = new AccountInfoConvet();
                    dpk.Data = converter.ConvertToBytes((AccountInfo)obj);
                    dpk.Client = client;
                    sender.SendMessage(dpk);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #20
0
 public EditAccountInfo(DataPackage data)
 {
     AccountInfoConvet convert = new AccountInfoConvet();
     accountInfo = convert.ConvertToClass(data.Data);
     dataSend.Client = data.Client;
 }
예제 #21
0
 public ReceiveFile(DataPackage data)
 {
     FileRequestConvert frc = new FileRequestConvert();
     rfr = frc.ConvertToData_Receive(data.Data);
     remoteClient = data.Client;
 }
예제 #22
0
        public void Analysis(DataPackage data)
        {
            Thread tdAnalysis = new Thread(delegate () {

            short type;
            byte[] bType = new byte[2];

            bType[0] = data.Data[0];
            bType[1] = data.Data[1];
            type = BitConverter.ToInt16(bType, 0);

                switch (type)
                {
                    case 1:            //信息[部分未测试]
                        Message message = new Message(data.Data);
                        message.Send();
                        break;
                    case 2:            //登陆
                        AccountLogin accountLogin = new AccountLogin(data);
                        if (accountLogin.Login())
                        {
                            accountLogin.AddToOnlineUserList();
                        }
                        accountLogin.Respect();
                        break;
                    case 3:         //账号申请[未测试]
                        AccountRequest accountRequest = new AccountRequest(data);
                        accountRequest.Response();
                        break;
                    case 4:        //获取账户信息[未测试]
                        ReadUserInfo readUserInfo = new ReadUserInfo(data);
                        readUserInfo.Response();
                        break;
                    case 5:        //修改账户信息[未测试]
                        EditAccountInfo editUserInfo = new EditAccountInfo(data);
                        editUserInfo.Response();
                        break;
                    case 6:        //请求文件[未测试] --机制待修改[重要]
                        SendFile sendFile = new SendFile(data);
                        sendFile.Send();
                        break;
                    case 7:        //接收文件[未测试] --机制待修改[重要]
                                   //开辟新线程[待修改]
                        Newtalking_BLL_Server.File.ReceiveFile receFile = new File.ReceiveFile(data);
                        receFile.Receive();
                        break;
                    case 8:         //用户头像申请[未测试]
                        SendUserImage sendUserImage = new SendUserImage(data);
                        sendUserImage.Send();
                        break;
                    case 9:         //消息刷新申请[未测试]
                        MessageFresh msgFresh = new MessageFresh(data);
                        msgFresh.Response();
                        break;
                    case 10:        //搜索用户

                        break;
                    case 11:        //添加关注
                        break;
                    case 12:        //撤销关注
                        break;
                    case 13:        //屏蔽
                        break;
                }
            });
            tdAnalysis.Start();
        }
예제 #23
0
 public MessageFresh(DataPackage dpk)
 {
     data = dpk;
     RefreshRequestConvert converter = new RefreshRequestConvert();
     rr = converter.ConvertToClass(dpk.Data);
 }
예제 #24
0
 public Sender(DataPackage dp) {
     TcpClient c = new TcpClient();
     c.Connect(dp.User_IP, Server_Properties.Property.Port);
     client = c;
 }
예제 #25
0
 public SearchAccount(DataPackage dpk)
 {
     SelectAccountConvert converter = new SelectAccountConvert();
     selAcc = converter.ConvertToClass(dpk.Data);
     client = dpk.Client;
 }