Ejemplo n.º 1
0
        static void Debug()
        {
            GachonClass.NewPost += GachonClass_NewPost;
            //가천대 학생 객체 만들기 (학교 아이디와 패스워드로 로그인)
            GachonUser a = GachonUser.GetObject(private_data.id, private_data.password);
            GachonUser c = GachonUser.GetObject(private_data.id, private_data.password);

            // 해당 학생 정보 출력
            Console.WriteLine(a.ToString(true));
            // b.Name b.Department   b.Email   b.Phone 등으로 참조 가능

            //GachonCafe gachonCafe = new GachonCafe("135687");
            // 컴퓨터 네트워크에 2개의 카페를 연결.
            //GachonObjects.AllClass["201809970002"].CombineSite(gachonCafe);
            //GachonObjects.AllClass["201809372002"].CombineSite(new GachonCafe("140663"));

            // GachonClass gachonClass = GachonClass.GetObject("소프트웨어", "soft");
            //gachonClass.CombineSite(new NaverCafe("gachon2010"));
            a.CombineClass(GachonClass.GetObject("소프트웨어", "soft"));
            Console.WriteLine("\r\n\r\n서버에 등록된 모든 강의");
            foreach (GachonClass gc in GachonObjects.AllClass.Values)
            {
                Console.WriteLine(gc.ToString());
            }

            Console.WriteLine("\r\n\r\n");
            GachonClass.AutoCrawlingDelay = 10;   // (초단위)  3초에 한번씩 최신글을 확인
            GachonClass.StartAutoCrawling = true; // 강의 최신글 크롤링 시작.
            Console.ReadKey();                    //다른 키가 눌릴때까지 대기
            // 다른키가 눌렸을 경우 오토크롤링 종료
            GachonClass.StartAutoCrawling = false;
        }
Ejemplo n.º 2
0
        public static void Login(ESocket socket, string id, string password, bool GameLogin = true)
        {
            #region 입력값이 비어있는지 체크
            if (id.Trim() == "")
            {
                NetworkMessageList.TipMessage(socket, "아이디를 입력해주세요.");
                return;
            }
            if (password.Trim() == "")
            {
                NetworkMessageList.TipMessage(socket, "비밀번호를 입력해주세요.");
                return;
            }
            #endregion
            // 해당 입력값을 기준으로 GachonUser.GetObject 함수를 실행시킵니다.
            // 유효한 로그인일경우 GachonUser 클래스를 통해 실제 가천대 웹사이트와 세션이 연결되며,
            // 유효하지 않은 로그인일 경우 NULL값을 반환합니다.
            GachonUser gachonAccount = GachonUser.GetObject(id, password);
            if (gachonAccount == null)
            {
                NetworkMessageList.TipMessage(socket, "로그인에 실패했습니다.");
                return;
            }
            // 만약 게임에서 이 로그인을 요청한 경우 (안드로이드가 아닌)
            if (GameLogin)
            {
                // 게임 오브젝트로 관리될 새로운 User 클래스를 만들고, 소켓과 GachonUser 객체를 연결시킵니다.
                User user = null;
                try
                {
                    user = new User(socket, gachonAccount);
                }
                catch (DuplicationError e) // User 클래스는 같은 GachonUser 에 대해 중복으로 생성될수 없기때문에 발생하는 에러입니다.
                {
                    NetworkMessageList.TipMessage(socket, "이 계정은 다른 클라이언트에서 접속중입니다.");
                    return;
                }
                // 유저의 위치를 임의값으로 설정 (시작 포인트)
                user.position = new Vector4(-69.30f, 5.33f, 47.17f, 0f);

                // 접속 성공 메세지 전송
                JObject json = new JObject();
                json["type"] = NetworkProtocol.EnterWorld;
                json["no"]   = user.no; // 플레이어를 나타내는 객체가 무엇인지 알려준다. (서버에서 관리되는 고유 번호)
                socket.Send(json);
            }
            else
            {
                // 로그인 성공 메세지를 보내준다.
                JObject json = new JObject();
                json["type"] = AndroidProtocol.Login;
                json["data"] = id + ":" + password;
                socket.Send(json);
            }
            // 가천 소켓에 이 세션을 연결시킨다.
            GachonSocket.Connect(socket, id, true);
        }
Ejemplo n.º 3
0
 public User(ESocket socket, GachonUser user)
 {
     lock (Items)
     {
         foreach (User item in Items.Values)
         {
             if (item.gachonAccount == user)
             {
                 throw new DuplicationError("중복 로그인");
             }
         }
         this.socket   = socket;
         gachonAccount = user;
         Items.Add(socket, this);
         name = gachonAccount.Name;
         skin = "Eve";
     }
 }
Ejemplo n.º 4
0
 public User(ESocket socket, GachonUser user)
 {
     // 쓰레드 충돌을 막기위한 lock
     lock (Items)
     {
         // 이미 같은 아이디로 로그인한 유저가 있으면 에러 발생
         foreach (User item in Items.Values)
         {
             if (item.gachonAccount == user)
             {
                 throw new DuplicationError("중복 로그인");
             }
         }
         this.socket   = socket;
         gachonAccount = user;
         Items.Add(socket, this);
         name  = gachonAccount.Name;
         group = gachonAccount.StudentNumber.Substring(2, 2); // 이름 앞에 뜨는 그룹을 학번으로 표시 ( 201735861 -> 17)
         skin  = "Eve";                                       // 기본 스킨
     }
 }
Ejemplo n.º 5
0
        public static void Login(ESocket socket, string id, string password)
        {
            if (id.Trim() == "")
            {
                NetworkMessageList.TipMessage(socket, "아이디를 입력해주세요.");
                return;
            }
            if (password.Trim() == "")
            {
                NetworkMessageList.TipMessage(socket, "비밀번호를 입력해주세요.");
                return;
            }
            GachonUser gachonAccount = GachonUser.GetObject(id, password);

            if (gachonAccount == null)
            {
                NetworkMessageList.TipMessage(socket, "로그인에 실패했습니다.");
                return;
            }
            User user = null;

            try
            {
                user = new User(socket, gachonAccount);
            }
            catch (DuplicationError e)
            {
                NetworkMessageList.TipMessage(socket, "이 계정은 다른 클라이언트에서 접속중입니다.");
                return;
            }
            GachonSocket.Connect(socket, id, true);
            user.position = new Vector4(-69.30f, 5.33f, 47.17f, 0f);
            JObject json = new JObject();

            json["type"] = NetworkProtocol.EnterWorld;
            json["no"]   = user.no; // 플레이어를 나타내는 객체가 무엇인지 알려준다.
            socket.Send(json);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 해당 유저가 채팅을 시작합니다. 이 함수에서 명령어 구문 분석이 실행됩니다.
        /// </summary>
        /// <param name="message">입력 메세지</param>
        /// <param name="Type">입력 메세지 타입 (ChatType)</param>
        public override void ChatMessage(string message, int Type)
        {
            //Dice
            JObject json = new JObject();

            json["type"] = NetworkProtocol.Chat;

            if (message.IndexOf("/주사위") == 0)
            {
                Random rd = new Random();
                json["chattype"] = ChatType.Notice;
                json["message"]  = name + "(이)가 주사위를 굴렸습니다~!! 주사위가 " + rd.Next(1, 6).ToString() + " 나왔습니다!";
                NetworkSend.SendAllUser(json);
                return;
            }

            //Whisper
            if ((message.IndexOf("/ㅈ ") == 0) || (message.IndexOf("/w ") == 0) || (message.IndexOf("/귓속말 ") == 0))
            {
                string[] Receiver = message.Split(' ');
                //형식이 맞는지 확인
                if (Receiver.Length > 2)
                {
                    for (int i = 3; i < Receiver.Length; i++)
                    {
                        Receiver[2] += " " + Receiver[i];
                    }
                    string receiverID = GachonUser.GetID(Receiver[1]); //Sender가 입력한 이름을 통해 귓속말 대상 ID를 얻음

                    //대상이 접속해있는지 아닌지 확인
                    foreach (User user in User.Items.Values.ToList())
                    {
                        if (user.ID.Equals(receiverID))
                        {
                            json["chattype"] = ChatType.Whisper;
                            json["message"]  = Receiver[2]; //메세지 내용
                            json["no"]       = no;
                            json["sender"]   = name;
                            user.socket.Send(json);

                            json["group"] = "To " + Receiver[1];
                            //json["sender"] = "["+Receiver[1]+"]"+ name; //Sender에게 [Reiever]Sender: Content 로 보이도록
                            this.socket.Send(json);
                            return;
                        }
                    }
                    json["message"] = "[귓속말] 현재 접속해있지 않는 사용자입니다.";
                }
                else
                {
                    json["message"] = "[귓속말] 잘못된 귓속말 형식 입니다. '/w 대상 내용' 으로 입력해 주세요.";
                }
                json["chattype"] = ChatType.System;
                socket.Send(json);
                return;
            }
            // 해당 영역이 그룹의 영역일때
            string ingroup = InGroup();

            if (ingroup != null)
            {
                List <string> idlist = Study.Items[ingroup].Users;
                if (idlist.Contains(ID))
                {
                    json["chattype"] = ChatType.Group;
                    json["message"]  = message;
                    json["no"]       = no;
                    json["sender"]   = name;
                    json["group"]    = ingroup;
                    foreach (User user in User.Items.Values)
                    {
                        if (idlist.Contains(user.ID))
                        {
                            user.socket.Send(json);
                        }
                    }
                    MysqlNode node = new MysqlNode(private_data.mysqlOption, "INSERT INTO group_chat(group_name, student_id, data) VALUES (?group, ?id, ?data)");
                    node["group"] = ingroup;
                    node["id"]    = ID;
                    node["data"]  = message;
                    node.ExecuteInsertQuery();
                }
                else
                {
                    base.ChatMessage(message, Type);
                }
            }
            else
            {
                base.ChatMessage(message, Type);
            }
        }