Ejemplo n.º 1
0
        private void OnClientLogin(ref IPAddress where, ref string[] result, out string answer)
        {
            User client; answer = VerMessage.DEFAULT_RESPONSE;
            int  idx            = users.Find(result[1], out client);

            // 用户不存在
            if (idx == -1)
            {
                answer = VerMessage.LOGIN_FAILED_NO_SUCH_USER;
                return;
            }
            // 检查密码
            if (!client.testPassword(result[2]))
            {
                answer = VerMessage.LOGIN_FAILED_WRONG_PW;
                return;
            }
            // 发送用户个人资料
            tcpClientUserFile = new TcpClientP();
            tcpClientUserFile.Connect(new IPEndPoint(where, Port.TCP_USER_FILE_PORT));
            string data = client.toUserFile();

            tcpClientUserFile.Write(data);
            tcpClientUserFile.Close();
            // 加入连接列表
            Client login = new Client(where, client);

            onlineUsers.AddClient(login);
            Invoke(new AddUserIntoToListView_dele(AddUserIntoView), new object[] { client.account, client.name });
            // 反馈消息
            answer = VerMessage.LOGIN_SUCCESS;
        }
Ejemplo n.º 2
0
        private void button_User_Click(object sender, EventArgs e)
        {
            User      person = new User(int.Parse(uid), uac, ucl, upw);
            Form_User user   = new Form_User(person);

            user.ReturnUser += (o, e1) =>
            {
                if (!e1.CanUpdate)
                {
                    return;
                }
                User now = e1.Me;
                // 更新资料
                string     question = "Change " + now.GetRawString(), answer;
                TcpClientP request = new TcpClientP();
                request.Connect(serverIP, Port.TCP_LOGIN_PORT);
                request.Query(question, out answer);
                if (answer != VerMessage.CHANGE_SUCCESS)
                {
                    MessageBox.Show("更新信息失败", "提示", MessageBoxButtons.OK);
                    request.Close();
                    return;
                }
                MessageBox.Show("更新信息成功", "提示", MessageBoxButtons.OK);
                request.Close();
                ucl = now.name;
                Registry.AddKey2Registry("PublishClient", "CurrentUserName", ucl);
                this.Text = "教材补助经费评估软件 [" + ucl + "]" + " [#" + uid + "]";
                this.label_ClientName.Text = "[#" + uid + "] " + ucl;
            };
            user.ShowDialog();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 运行时预加载项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form_Login_Load(object sender, EventArgs e)
        {
            isLogin        = false;
            isCatch        = false;
            serverIP       = IPAddress.Parse(Registry.ReadKey4Registry("PublishClient", "ServerIP"));
            tcpClientLogin = new TcpClientP();
            tcpClientLogin.Connect(serverIP, Port.TCP_LOGIN_PORT);
            string lastUser = Registry.ReadKey4Registry("PublishClient", "LastUser");

            if (lastUser != null)
            {
                this.textBox_UesrAccount.Text = lastUser;
            }
            tcpListenerUser = new TcpListenerP(new IPEndPoint(IPAddress.Any, Port.TCP_USER_FILE_PORT));
            tcpListenerUser.OnThreadTaskRequest += new TcpListenerP.ThreadTaskRequest(OnRecvData);
        }
Ejemplo n.º 4
0
        public bool TryLogoff()
        {
            // 登出系统
            string question, answer;

            tcpClientLogoff = new TcpClientP();
            try { tcpClientLogoff.Connect(serverIP, Port.TCP_LOGIN_PORT); }
            catch (Exception) { return(false); }
            question = "Logoff " + uac;
            tcpClientLogoff.Query(question, out answer);
            if (answer == VerMessage.LOGOFF_SUCCESS)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            List <IPAddress> targets = new List <IPAddress>();

            for (int i = 0, sz = listBox_Confirm.Items.Count; i < sz; i++)
            {
                string ucl = listBox_Confirm.Items[i].ToString();
                targets.Add(players.__table[facebook[ucl]].clientIP);
            }
            Parallel.ForEach(targets, (item, state, i) =>
            {
                TcpClientP home = new TcpClientP();
                home.Connect(new IPEndPoint(item, Port.TCP_BOOK_INFORMATION_PORT));
                home.Write(data);
                home.Close();
            });
            MessageBox.Show("所有数据发送完毕!", "提示", MessageBoxButtons.OK);
            this.Close();
        }
Ejemplo n.º 6
0
        private void tSMI_Sendto_Click(object sender, EventArgs e)
        {
            BookEvaluaionList data = new BookEvaluaionList();

            for (int i = 0, sz = listView_Books.SelectedItems.Count; i < sz; i++)
            {
                string        id  = listView_Books.SelectedItems[i].SubItems[0].Text;
                BookEvaluaion tmp = new BookEvaluaion();
                BookEval.tryFind(int.Parse(id), out tmp);
                data.Add(tmp);
            }
            byte[] raw;
            ToBytes <BookEvaluaionList> .GetBytes(ref data, out raw);

            TcpClientP home = new TcpClientP();

            home.Connect(new IPEndPoint(serverIP, Port.TCP_BOOK_EVALUATION_PORT));
            home.Write(raw);
            home.Close();
            MessageBox.Show("发送成功", "提示", MessageBoxButtons.OK);
        }