Exemplo n.º 1
0
        /**
         * 訊息分派
         */
        public void MessageProcess(string msg)
        {
            // TODO Lock ??

            if (msg != string.Empty)
            {
                try
                {
                    JObject jsMain = JObject.Parse(msg);

                    if (jsMain.ContainsKey("CmdID"))
                    {
                        int cmdID = (int)jsMain["CmdID"];

                        if (jsMain.ContainsKey("Data"))
                        {
                            string packetData = jsMain["Data"].ToString();

                            switch (cmdID)
                            {
                            case (int)C2S_CmdID.emJoinService:

                                JoinService joinMsg = JsonConvert.DeserializeObject <JoinService>(packetData);

                                OnJoinService(joinMsg);

                                break;



                            default:
                                SaveLog($"[Warning] ClientHandler::MessageProcess Can't Find CmdID {cmdID}");

                                break;
                            }
                        }
                        else
                        {
                            SaveLog("[Warning] ClientHandler::MessageProcess Can't Find Member \"Data\" ");
                        }
                    }
                    else
                    {
                        SaveLog("[Warning] ClientHandler::MessageProcess Can't Find Member \"CmdID\" ");
                    }
                }
                catch (Exception ex)
                {
                    SaveLog("[Error] ClientHandler::MessageProcess Process Error Msg:" + ex.Message);
                }
            }
            else
            {
                SaveLog("[Warning] ClientHandler::MessageProcess Msg Is Empty");
            }
        }
Exemplo n.º 2
0
        /**
         * 使用者加入
         */
        private void OnJoinService(JoinService packet)
        {
            JoinServiceResult rData = new JoinServiceResult();

            rData.Result = 0;

            DataBaseConnect dbConnect = sev.GetController().GetDataBase();

            try
            {
                List <UserAccount> accountList = dbConnect.GetSql().Queryable <UserAccount>().Where(it => it.Email == packet.Email && it.Password == packet.Password).ToList();

                // 有找到帳號
                if (accountList.Count() == 1)
                {
                    if (accountList[0].Password == packet.Password)
                    {
                        List <UserInfo> infoList = dbConnect.GetSql().Queryable <UserInfo>().Where(it => it.MemberID == accountList[0].MemberID).ToList();

                        // 有找到會員
                        if (infoList.Count() == 1)
                        {
                            if (sev.AddMember(teamID, memberID, this))
                            {
                                rData.Result = 1;

                                SaveLog($"[Info] ClientHandler::onUserJoin, Add Member:{memberID} Success");
                            }
                            else
                            {
                                SaveLog($"[Warning] ClientHandler::onUserJoin, Add Member:{memberID} Fail");
                            }
                        }
                        else
                        {
                            SaveLog("[Warning] ClientHandler::onUserJoin, Can't Find User Info");

                            rData.Result = 0;
                        }
                    }
                    else
                    {
                        rData.Result = 3;

                        SaveLog("[Info] ClientHandler::onUserJoin, Can't Password Error");
                    }
                }
                else
                {
                    rData.Result = 2;
                }
            }
            catch (Exception ex)
            {
                SaveLog($"[Error] ClientHandler::onUserJoin, Catch Error, Msg:{ex.Message}");
            }

            JObject jsMain = new JObject();

            jsMain.Add("CmdID", (int)S2C_CmdID.emJoinServiceResult);
            jsMain.Add("Data", JsonConvert.DeserializeObject <JObject>(JsonConvert.SerializeObject(rData)));

            Send(jsMain.ToString());

            // 加入失敗
            if (rData.Result != 1)
            {
                //SaveLog($"[Warning] ClientHandler::onUserJoin, Can Not Find Member");

                // 強制斷線
            }
        }