Esempio n. 1
0
        // 회원가입버퍼를 처리합니다.
        // msg: regist√학번√비밀번호√이름√성별√연락처
        private void RecvRegist(string msg)
        {
            string[] msgArray = msg.Split('√');

            if (msgArray[0] == "regist")
            {
                NetworkStream ns = clientSocket.GetStream();
                string response = "regist√pass√";

                for (int i = 0; i < serverForm.member.Count; i++)
                {
                    if (serverForm.member[i].classNumber == msgArray[1])
                    {
                        response = "regist√fail√"; // 학번이 중복일 경우
                        break;
                    }
                }

                byte[] buf = Encoding.UTF8.GetBytes(response);
                ns.Write(buf, 0, buf.Length);
                ns.Flush();
                try
                {
                    serverForm.Invoke(new LogDelegate(_Logging), new object[] { msg, user.classNumber + "->Server" });
                }
                catch
                {
                    serverForm.Invoke(new LogDelegate(_Logging), new object[] { msg, "Client->Server" });
                }

                if (response == "regist√pass√")
                {
                    clsPerson person = new clsPerson(msgArray[1], msgArray[2], msgArray[3], msgArray[4], msgArray[5]);
                    serverForm.member.Add(person);
                }
            }
        }
Esempio n. 2
0
        // 클라이언트에서 접속하면 대기실에 환영 메세지를 띄웁니다.
        public void SendHello(clsPerson user)
        {
            for (int i = 0; i < allClient.Count; i++)
            {
                try
                {
                    if (allClient[i].user.room[0] == 0)//|| allClient[i].user !=null)
                    {
                        NetworkStream ns = allClient[i].clientSocket.GetStream();

                        string msg = "hello√[ " + user.name + " 님이 접속하셨습니다. ]√";

                        for (int j = 0; j < allClient.Count; j++)
                        {
                            try
                            {
                                msg = msg + allClient[j].user.name + "√" + allClient[j].user.classNumber + "√" + allClient[j].user.gender + "√" +
                                    allClient[j].user.elo + "√" + allClient[j].user.room[0] + "√";
                            }
                            catch { }

                        }

                        byte[] buf = Encoding.UTF8.GetBytes(msg);
                        ns.Write(buf, 0, buf.Length);
                        ns.Flush();
                        this.Invoke(new LogDelegate(_Logging), new object[] { msg, "Server->Client" });
                    }
                }
                catch { }
            }
        }
Esempio n. 3
0
        // 로그인 버퍼를 처리합니다.
        // msg: login√학번√비밀번호√성별√승
        private void RecvLogin(string msg)
        {
            string[] msgArray = msg.Split('√');
            int clientIdx = int.Parse(clNo);

            if (msgArray[0] == "login")
            {
                NetworkStream ns = clientSocket.GetStream();
                string response = "login√fail√";

                for (int i = 0; i < serverForm.member.Count; i++)
                {
                    // 새로 가입한 회원이 있을지도 모르므로 XML파일을 한번 더 불러옴
                    //serverForm.member = serverForm.XMLDeserialize("memberDB.xml"); // XML 역직렬화

                    if (serverForm.member[i].classNumber == msgArray[1] &&
                        serverForm.member[i].password == msgArray[2])
                    {
                        if (duplicating(msgArray))  //중복이면
                            response = "login√duplicate√" + serverForm.member[i].classNumber + "√";
                        else
                        {

                            response = "login√pass√" + serverForm.member[i].classNumber + "√" +
                                serverForm.member[i].name + "√" + serverForm.member[i].gender + "√" + serverForm.member[i].elo + "√"; // 로그인에 성공한 경우
                            // login√pass√학번√이름√성별√승
                            user = new clsPerson(serverForm.member[i].classNumber, serverForm.member[i].password, serverForm.member[i].name,
                                serverForm.member[i].gender, serverForm.member[i].phone, serverForm.member[i].elo);
                            //  serverForm.allClient[clientIdx].user = user;
                            stdNum = serverForm.member[i].classNumber;  //중복로그인 체크를 위한 학번저장;
                            break;
                        }
                    }
                }

                byte[] buf1 = Encoding.UTF8.GetBytes(response);
                ns.Write(buf1, 0, buf1.Length);
                ns.Flush();
                try
                {
                    serverForm.Invoke(new LogDelegate(_Logging), new object[] { msg, user.classNumber + "->Server" });
                }
                catch
                {
                    serverForm.Invoke(new LogDelegate(_Logging), new object[] { msg, "Client->Server" });
                }

                // 채팅을 킬지말지 버퍼를 받음
                // buf: chatOn√ or fail√
                byte[] buf2 = new byte[1024];
                ns.Read(buf2, 0, buf2.Length);
                string recv = Encoding.UTF8.GetString(buf2);
                string[] chat = recv.Split('√');

                if (chat[0] == "chatOn")
                {
                    user.room[0] = 0;
                    serverForm.SendHello(/*serverForm.allClient[clientIdx].*/user);
                }
            }
        }