예제 #1
0
        private static void Commander(command_data_client CMD)
        {
            Console.WriteLine("Command] {0} : ", ((Command_Client)CMD.Command_code).ToString());
            switch (CMD.Command_code)
            {
            case (int)Command_Client.Set_UnitNo:
            {
                Unit_No = Convert.ToInt32(CMD.data);
                Make_Client_Event(Unit_Event_Type.Change_connect, new List <object> {
                        true
                    });
            }
            break;

            case (int)Command_Client.Make_Login:
            {
                i_Make_Login login_info = (i_Make_Login)CMD.data;

                Tefreeca_client_interface.Add_Response(
                    Command_Server.Login,
                    new i_Login(
                        Unit_No,
                        login_info.ID,
                        MD5HashFunc(login_info.PW),
                        Type_User.Starter               //기본값은 스타터이나 로그인하면서 실제 회원등급을 전달받는다.
                        )
                    );
            }
            break;

            case (int)Command_Client.Login_success:
            {
                i_Login_success ils = JsonConvert.DeserializeObject <i_Login_success>(CMD.data.ToString());

                User_No    = ils.User_No;
                Unit_State = State_Unit.Logged;         //로그드를 사용하지 않고 일반 유닛처럼 운영.
                Session    = ils.Session;
                Type_user  = ils.Type_user;

                Add_Response(Command_Server.User_Info, null);

                Make_Client_Event(Unit_Event_Type.Login_success, new List <object> {
                    });
            }
            break;

            case (int)Command_Client.Login_Failure:
            {
                i_Login_Failure_type Failure_info = JsonConvert.DeserializeObject <i_Login_Failure_type>(CMD.data.ToString());

                Make_Client_Event(Unit_Event_Type.Login_Failure, new List <object> {
                        Failure_info
                    });
            }
            break;

            case (int)Command_Client.User_Info:
            {
                User_info = JsonConvert.DeserializeObject <i_User_info>(CMD.data.ToString());

                Make_Client_Event(Unit_Event_Type.User_info, new List <object> {
                        User_info
                    });
                //로그인 정보 가져오는 코드.
                ///그래서 받으면 폼에다 업데이트 할 수 있게 이벤트로 넘겨줌1
            }
            break;

            case (int)Command_Client.Order_No:
            {
                this_order_No = JsonConvert.DeserializeObject <int>(CMD.data.ToString());

                Make_Client_Event(Unit_Event_Type.Order_no, this_order_No);                                                              //이벤트 발생시키고

                i_Order io = new i_Order(this_order_No, User_No, this_order.Max_Connect, this_order.URL, Type_Order.Enter_Afreeca_Room); //실제 명령을 만든 후,

                Add_Response(Command_Server.Order_Connect, io);                                                                          //서버로 보낸다.
            }
            break;

            case (int)Command_Client.Error_Order:
            {
                client_message error_info = JsonConvert.DeserializeObject <client_message>(CMD.data.ToString());

                Make_Client_Event(Unit_Event_Type.Error_Order, new List <object> {
                        error_info
                    });
                //로그인 정보 가져오는 코드.
                ///그래서 받으면 폼에다 업데이트 할 수 있게 이벤트로 넘겨줌1
            }
            break;

            case (int)Command_Client.Make_Connect:
            {
                i_Make_Connect connect_info = (i_Make_Connect)CMD.data;
                this_order = connect_info;
                Add_Response(Command_Server.Order_Request_No, null);         //오더 리퀘스트 실행. 그러면 번호를 서버에서 생성하여 Order_No 응답이 온다.
            }
            break;

            case (int)Command_Client.Order_Info:
            {
                i_Order_Info order_info = JsonConvert.DeserializeObject <i_Order_Info>(CMD.data.ToString());

                Make_Client_Event(Unit_Event_Type.Order_Info, new List <object> {
                        order_info
                    });
            }
            break;

            case (int)Command_Client.Active_Order:
            {
                int order_no = JsonConvert.DeserializeObject <int>(CMD.data.ToString());
                if (this_order_No == order_no)
                {
                    Make_Client_Event(Unit_Event_Type.Active_Order, order_no);
                }
            }
            break;

            case (int)Command_Client.Close_Order:     //폼 컨르롤로부터 연결 해지 명령을 받을때 사용, 이 명령을 받으면 현재 활성화된 오더를 닫는 명령을 서버로 보낸다.
            {
                Add_Response(Command_Server.Order_Disconnect, this_order_No);
            }
            break;

            case (int)Command_Client.Make_Order_Set_MaxConnect:
            {
                int set_maxConnect = JsonConvert.DeserializeObject <int>(CMD.data.ToString());

                i_Set_MaxConnect iset = new i_Set_MaxConnect(User_No, this_order_No, set_maxConnect);

                Add_Response(Command_Server.Order_Set_MaxConnect, iset);
            }
            break;

            case (int)Command_Client.R_Order_Set_MaxConnect:
            {
                i_R_Order_Set_MaxConnect ir = JsonConvert.DeserializeObject <i_R_Order_Set_MaxConnect>(CMD.data.ToString());
                Make_Client_Event(Unit_Event_Type.Order_Set_MaxConnect, new List <object> {
                        ir
                    });
            }
            break;

            case (int)Command_Client.HeartBeat:
            {
            }
            break;

            default:
            {
                Command_Client S = (Command_Client)CMD.Command_code;
                Console.WriteLine("Unknown Command : {0}", S.ToString());
            }
            break;
            }
        }
예제 #2
0
        public void Eventer_Tefreeca_client_event(object sender, EventArgs e)
        {
            try
            {
                Tefreeca_client_EventArgs RecieveEventArg = e as Tefreeca_client_EventArgs;
                if (RecieveEventArg == null)
                {
                    return;
                }
                Unit_Event_Type type = RecieveEventArg.type;

                switch (type)
                {
                case Unit_Event_Type.Change_connect:     //연결 상태가 변하면,
                {
                    bool connected = (bool)RecieveEventArg.Data_object_list[0];
                    UI.set_button_delegate(btn_Login, connected, Option_button.enable);
                    if (connected)
                    {
                        UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.로그인_준비_완료.ToString().Replace("_", " ") }, Option_listBox.add);
                        if (Data_structure.is_debug)
                        {
                            UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.디버깅_모드.ToString().Replace("_", " ") }, Option_listBox.add);
                        }
                    }
                }
                break;

                case Unit_Event_Type.Login_success:
                {
                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.로그인_성공.ToString().Replace("_", " ") }, Option_listBox.add);

                    //판낼 정보를 업데이트가 먼저 되어야 한다.


                    UI.set_PanelVisible_delegate(panel_login, false);
                    UI.set_button_delegate(btn_Login, true, Option_button.enable);
                }
                break;

                case Unit_Event_Type.Login_Failure:    // 로그인 실패시
                {
                    //Login_Failure
                    string s = "";
                    i_Login_Failure_type Failure_info = (i_Login_Failure_type)RecieveEventArg.Data_object_list[0];
                    if (Failure_info == i_Login_Failure_type.Duplicate_Login)
                    {
                        s = "중복로그인 불가.";
                    }
                    else if (Failure_info == i_Login_Failure_type.Invalid_login_information)
                    {
                        s = "잘못된 로그인 정보";
                    }

                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.로그인_실패.ToString().Replace("_", " ") + " : " + s }, Option_listBox.add);
                    UI.set_button_delegate(btn_Login, true, Option_button.enable);
                }
                break;

                case Unit_Event_Type.User_info:
                {
                    i_User_info User_info = (i_User_info)RecieveEventArg.Data_object_list[0];
                    TimeSpan    remind    = User_info.Expire - DateTime.Now;

                    Max_Connect = User_info.slot;                                                                  //최대 연결 가능 슬롯을 세팅해준다.
                    UI.NumericUpDowndelegate(numericUpDown_MaxConnect, Max_Connect, Option_NumericUpDown.Maximum); //최대치로 세팅
                    UI.NumericUpDowndelegate(numericUpDown_MaxConnect, Max_Connect, Option_NumericUpDown.value);   //최대치로 세팅
                    UI.TrackBardelegate(trackBar_order_maxconnect, 50, Option_TrackBar.value);                     //맥시멈으로..
                    Set_MaxConnect = Max_Connect;
                    UI.set_label_delegate(lb_userName, User_info.Id + "님");
                    UI.set_label_delegate(lb_expire, "expire : " + User_info.Expire.ToShortDateString() + " (" + ((int)remind.TotalDays).ToString() + " days remained.)");
                    UI.set_label_delegate(lb_usergrade, User_info.type.ToString() + " 등급");
                }
                break;

                case Unit_Event_Type.Order_no:
                {
                    //int order_no = RecieveEventArg.data_int;
                    UI.set_button_delegate(btn_connect, "해제", Option_button.text);
                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "접속 명령 생성." }, Option_listBox.add);
                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.접속_명령_생성.ToString().Replace("_", " ") }, Option_listBox.add);
                }
                break;

                case Unit_Event_Type.Error_Order:
                {
                    client_message error_info = (client_message)RecieveEventArg.Data_object_list[0];
                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.오류.ToString().Replace("_", " ") + " : " + error_info.ToString().Replace("_", " ") }, Option_listBox.add);
                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "[오류] : " + error_info }, Option_listBox.add);
                    UI.set_TextBox_delegate(tbx_BJID, true, Option_TextBox.enable);
                    UI.set_button_delegate(btn_connect, "접속", Option_button.text);
                    UI.set_button_delegate(btn_connect, true, Option_button.enable);
                }
                break;

                case Unit_Event_Type.Active_Order:     //주문이 활성화 되면 이것을 취소할 수 있게 해준다.
                {
                    //int order_no = RecieveEventArg.data_int;
                    mode = btn_mode.disconnect;
                    UI.set_button_delegate(btn_connect, true, Option_button.enable);
                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.활성화_되었습니다.ToString().Replace("_", " ") }, Option_listBox.add);
                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "활성화 되었습니다." }, Option_listBox.add);
                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "[" + order_no.ToString() + "]활성화." }, Option_listBox.add);
                }
                break;

                case Unit_Event_Type.Order_Info:
                {
                    i_Order_Info Order_info = (i_Order_Info)RecieveEventArg.Data_object_list[0];

                    string State = Order_info.State.ToString().Replace("_", " ");

                    UI.set_label_delegate(lb_connect_state, State);

                    /*
                     * if (Order_info.State == State_Order.Close || Order_info.State == State_Order.Closing) //클로징, 클로즈땐 카운트 표시 안함.
                     *  UI.set_label_delegate(lb_connect_state, State);
                     * else
                     *  UI.set_label_delegate(lb_connect_state, State + " (" + Order_info.Connect_Count + ")");
                     */
                    if (Old_State == State_Order.Active && Order_info.State == State_Order.Closing)         //활성화 되었다가 클로징으로 바뀌면.
                    {
                        //UI.set_listBox_delegate(listBox_state_log, new string[] { "연결 해제중.." }, Option_listBox.add);
                        UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.연결_해제중.ToString().Replace("_", " ") }, Option_listBox.add);
                        UI.set_TextBox_delegate(tbx_BJID, true, Option_TextBox.enable);
                    }

                    if (Order_info.State == State_Order.Close)         //활성화 되었다가 클로징으로 바뀌면.
                    {
                        mode = btn_mode.connect;
                        UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.연결_해제_성공.ToString().Replace("_", " ") }, Option_listBox.add);
                        //UI.set_listBox_delegate(listBox_state_log, new string[] { "연결 해제 성공." }, Option_listBox.add);
                        UI.set_TextBox_delegate(tbx_BJID, true, Option_TextBox.enable);
                        UI.set_button_delegate(btn_connect, "접속", Option_button.text);
                        UI.set_button_delegate(btn_connect, true, Option_button.enable);
                    }
                    Old_State = Order_info.State;
                }
                break;

                case Unit_Event_Type.Server_Connection_Broken:     //서버와 연결이 끊김.
                {
                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "서버와의 접속이 끊어졌습니다." }, Option_listBox.add);
                    UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.서버와_접속이_끊어졌습니다.ToString().Replace("_", " ") }, Option_listBox.add);
                }
                break;

                case Unit_Event_Type.Order_Set_MaxConnect:     //최대 연결 수가 변경 수락되면..
                {
                    i_R_Order_Set_MaxConnect ir = (i_R_Order_Set_MaxConnect)RecieveEventArg.Data_object_list[0];

                    if (ir.message == client_message.방송_접속수가_변경되었습니다)
                    {
                        UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.방송_접속수가_변경되었습니다.ToString().Replace("_", " ") + "[" + ir.Max_Connect + "]" }, Option_listBox.add);

                        Set_MaxConnect = ir.Max_Connect;

                        if (int.Parse(numericUpDown_MaxConnect.Value.ToString()) == Set_MaxConnect)
                        {
                            UI.set_button_delegate(btn_set_Maxconnect, false, Option_button.enable);
                        }
                        else
                        {
                            UI.set_button_delegate(btn_set_Maxconnect, true, Option_button.enable);
                        }
                    }
                    else if (ir.message == client_message.방송_접속수_변경중_오류)
                    {
                        UI.set_listBox_delegate(listBox_state_log, new string[] { client_message.방송_접속수_변경중_오류.ToString().Replace("_", " ") }, Option_listBox.add);
                    }
                    if (int.Parse(numericUpDown_MaxConnect.Value.ToString()) == Set_MaxConnect)
                    {
                        UI.set_button_delegate(btn_set_Maxconnect, false, Option_button.enable);
                    }
                    else
                    {
                        UI.set_button_delegate(btn_set_Maxconnect, true, Option_button.enable);
                    }

                    //UI.set_listBox_delegate(listBox_state_log, new string[] { "서버와의 접속이 끊어졌습니다." }, Option_listBox.add);
                }
                break;

                default:
                { }
                break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : {0}", ex.ToString());
                throw;
            }
        }