Example #1
0
        public void Process(Socket workerSock)
        {
            LoginMsg login = new LoginMsg();

            login.ReceiveFrom(workerSock);
            string userName = login.UserName;
            string userPwd  = login.UserPwd;

            var  userService = new UserService(userName, userPwd);
            bool loginResult = userService.CheckLogin();

            if (loginResult)
            {
                OnlineUserInfo user = new OnlineUserInfo {
                    UserName = userName, IPEnd = workerSock.RemoteEndPoint as IPEndPoint
                };
                foreach (var s in Server.TheTcpHelper.AcceptedSockets)
                {
                    NewUserOnlineMsg newUserOnlineMsg = new NewUserOnlineMsg(user.UserName, user.IPEnd.Address.ToString());
                    newUserOnlineMsg.Send(s);
                }

                UserService.LoginUsers.Add(user);
                if (!UserService.DicUserSockets.ContainsKey(user.UserName))
                {
                    UserService.DicUserSockets.Add(user.UserName, workerSock);
                }
            }
            var r = loginResult ? LOGIN_RESULT.OK : LOGIN_RESULT.PWD_ERROR;

            Console.WriteLine("{0} login {1}", userName, r);
            LoginResultMsg loginResultMsg = new LoginResultMsg(r);

            loginResultMsg.Send(workerSock);
        }
Example #2
0
        public void Process(Socket workerSock)
        {
            TxtMsg txtMsg = new TxtMsg();

            txtMsg.ReceiveFrom(workerSock);

            var userService = new UserService(txtMsg.SenderName);

            if (!userService.CheckOnLine())
            {
                Console.WriteLine("{0} not login", txtMsg.SenderName);

                LoginResultMsg loginResultMsg = new LoginResultMsg(LOGIN_RESULT.NOT_LOGIN_YET);
                loginResultMsg.Send(workerSock);
                return;
            }
            var remote = workerSock.RemoteEndPoint as IPEndPoint;

            Console.WriteLine("【{0}({1}:{2})】{3}", txtMsg.SenderName, remote.Address.ToString(), remote.Port, txtMsg.Txt);
        }