示例#1
0
        public void Runing()
        {
            var result = new WSResult <CharAloneModule>();

            result.Result             = new CharAloneModule();
            result.Result.CharMessage = new CharModule.SocketModules.CharModule();
            while (true)
            {
                var value = Console.ReadLine();

                if ("CLOSE".Equals(value.ToUpper()))
                {
                    Parallel.ForEach(dicSocket.ToList(), f =>
                    {
                        result.Result.CharMessage.Message = "系统关闭!";
                        result.Result.TagetrGUID          = f.Key;
                        result.Result.CharMessage.Type    = 1;
                        f.Value.Send(JsonConvert.SerializeObject(result));
                        f.Value.Close();
                    });
                }
                else
                {
                    result.Result.CharMessage.Message = value;

                    Parallel.ForEach(dicSocket.ToList(), f =>
                    {
                        result.Result.TagetrGUID       = f.Key;
                        result.Result.CharMessage.Type = 1;
                        f.Value.Send(JsonConvert.SerializeObject(result));
                    });
                }
            }
        }
示例#2
0
        public void WebSocketInitialize()
        {
            WSResult r = new WSResult();

            try
            {
                List <Guid> list = GetUserList();
                list.ForEach(f =>
                {
                    WebSocketServer server = new WebSocketServer("ws://127.0.0.1:14001/alone/" + f);
                    server.Start(socket =>
                    {
                        socket.OnOpen = () =>
                        {
                            Console.WriteLine("Open: " + socket.ConnectionInfo.Path.Substring(socket.ConnectionInfo.Path.LastIndexOf("/") + 1));
                            try
                            {
                                var strParame  = socket.ConnectionInfo.Path;
                                var listParame = strParame.Split('&');
                                if (rg.IsMatch(listParame[0]))
                                {
                                    var UserGUID = Guid.Parse(rg.Match(listParame[0]).Value);
                                    dicSocket.TryAdd(UserGUID, socket);
                                }
                                else
                                {
                                    throw new Exception("未获取人员信息!");
                                }
                            }
                            catch (Exception e)
                            {
                                r.Code = 1;
                                r.Msg  = e.Message;
                                Console.WriteLine(r.Msg);
                                socket.Send(JsonConvert.SerializeObject(r));
                            }
                        };
                        socket.OnClose = () =>
                        {
                            Console.WriteLine("Close: " + socket.ConnectionInfo.Path.Substring(socket.ConnectionInfo.Path.LastIndexOf("/") + 1));
                            try
                            {
                                var ip = socket.ConnectionInfo.ClientIpAddress;
                                if (dicUserIP.ContainsKey(ip))
                                {
                                    var UserGUID = dicUserIP[ip];
                                    if (dicUserIP.ContainsKey(ip))
                                    {
                                        dicSocket.TryRemove(UserGUID, out IWebSocketConnection removedSocket);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        };
                        socket.OnMessage = message =>
                        {
                            var result = new WSResult <CharAloneModule>();
                            string msg;
                            Console.WriteLine("Message: " + socket.ConnectionInfo.Path.Substring(socket.ConnectionInfo.Path.LastIndexOf("/") + 1));

                            SocketPackage package = JsonConvert.DeserializeObject <SocketPackage>(message);

                            switch (package.Type)
                            {
                            case 1:
                                break;

                            case 2:
                                CharAloneModule alone = JsonConvert.DeserializeObject <CharAloneModule>(package.Data.ToString());
                                if (dicSocket.ContainsKey(alone.TagetrGUID))
                                {
                                    result.Result = alone;
                                    msg           = JsonConvert.SerializeObject(result);
                                    //dicSocket[alone.TagetrGUID].Send(msg);
                                    socket.Send(msg);
                                }
                                else
                                {
                                    //存入数据库保存历史信息
                                }
                                break;

                            case 3:
                                RoomChatModule room = (RoomChatModule)package.Data;

                                msg = JsonConvert.SerializeObject(room.CharMessage);
                                dicChatRoom[room.RoomID].Send(msg);
                                break;

                            default:
                                break;
                            }
                        };
                    });
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#3
0
    /// <summary>
    /// 建立OTP,並將相關參數與OTP,並將Client導至Gash登入頁面
    /// </summary>
    /// <param name="str_ClientIP">Client端IP</param>
    /// <param name="str_ReturnUrl">登入成功後導回的URL</param>
    /// <param name="int_LoginMode">登入方式 1:用Gash帳號登入 2:用Gash帳號登入後,選擇遊戲帳號 3:用遊戲帳號登入 4:用體驗帳號登入</param>
    /// <param name="str_ServiceCode">遊戲的Service Code</param>
    /// <param name="str_ServiceRegion">遊戲的Region Code</param>
    /// <param name="bl_isDisplayTitle">Gash登入頁面是否顯示Gamania Title</param>
    private static void CreateOTP(string str_ClientIP, string str_UserAgent, string str_ReturnUrl, int int_LoginMode, string str_ServiceCode, string str_ServiceRegion, string str_isDisplayTitle)
    {
        string str_OTP = string.Empty;

        //建立OTP

        GASHv35LoginWS ws = new GASHv35LoginWS();
        WSResult struct_Result = new WSResult();

        try
        {
            string strMergeFlow = ConfigurationManager.AppSettings["BeanFun_MergeList"] ?? "0";
            if (strMergeFlow == "1")
                struct_Result = ws.CreateOTPForMergeList(str_ClientIP, str_UserAgent, str_ReturnUrl, int_LoginMode, str_ServiceCode, str_ServiceRegion);
            else
                struct_Result = ws.CreateOTP(str_ClientIP, str_UserAgent, str_ReturnUrl, int_LoginMode, str_ServiceCode, str_ServiceRegion);

        }
        catch
        {
            SDCodeCheck.JSUtil.AlertMsg("系統忙碌中,請稍後在試! (Error(0)");
            return;
        }
        ws.Dispose();

        if (struct_Result.ResultCode == 0)
        {
            str_OTP = struct_Result.ResultDesc;

            //第二步將相關參數與OTP傳至登入頁面
            string str_ignoreChooseFlag = ConfigurationManager.AppSettings["igoreChooseFlag"] ?? "1";
            string _isalphaFlag = ConfigurationManager.AppSettings["IsaphaFlag"] ?? "0";

            string _strLoginUrl = string.Empty;
            string strGashLoginUrl=ConfigurationManager.AppSettings["GASHLoginUrl"]?? string.Empty;
            string strAlphaGashLoginUrl = ConfigurationManager.AppSettings["alphaGASHLoginUrl"] ?? strGashLoginUrl;

            string str_isRedirectTo = ConfigurationManager.AppSettings["BeanFun_RedirectFlag"] ?? string.Empty;
            if (str_isRedirectTo.ToLower() == "v30" || str_isRedirectTo.ToLower() == "v35")
                str_isRedirectTo = "&redirectto=" + str_isRedirectTo;
            else
                str_isRedirectTo = string.Empty;

            if (strGashLoginUrl == string.Empty || strAlphaGashLoginUrl == string.Empty)
                SDCodeCheck.JSUtil.Alert("系統忙碌中,請稍候再試! Error(2)");

            if (_isalphaFlag == "1")
                _strLoginUrl = strAlphaGashLoginUrl;
            else
                _strLoginUrl = strGashLoginUrl;

            string str_Url = string.Format("{0}?ClientIP={1}&OTP={2}&pageFlag={3}&ignoreChooseFlag={4}{5}", _strLoginUrl, str_ClientIP, str_OTP, str_isDisplayTitle, str_ignoreChooseFlag, str_isRedirectTo);
            HttpContext.Current.Response.Redirect(str_Url, true);
        }
        else
        {
            SDCodeCheck.JSUtil.AlertMsg("系統忙碌中,請稍候再試! Error(1)");
            return;
        }
    }
示例#4
0
    protected void ValidGashLogin()
    {
        //2009/12/02 INX新增
        if (_IsWebSiteStop == "1" && SDCodeCheck.Valid.isDate(_StopStartDate) && SDCodeCheck.Valid.isDate(_StopStartDate))
        {
            if (System.DateTime.Now >= Convert.ToDateTime(_StopStartDate) && System.DateTime.Now <= Convert.ToDateTime(_StopEndDate))
            {
                Session.Clear();
                SDCodeCheck.JSUtil.AlertCloseMsg(_StopAlertMessage);
                return;
            }
        }
        //====================

        if (str_ServiceCode == string.Empty || str_ServiceRegion == string.Empty)
        {
            SDCodeCheck.JSUtil.AlertCloseMsg("系統發生異常,請聯絡客服人員!!");
            return;
        }
        string str_LoginMode = ConfigurationManager.AppSettings["LoginMode"] ?? "0";
        int _intGetLoginMode = int.Parse(str_LoginMode);

        if (int_LoginMode == 0)
        {
            if (_intGetLoginMode <= 0 || _intGetLoginMode > 4)
            {
                SDCodeCheck.JSUtil.AlertCloseMsg("登入型別,請聯絡客服人員!");
                return;
            }
            else
            {
                int_LoginMode = _intGetLoginMode;
            }

        }

        if (Context.Session != null)
        {
            string str_OTP2 = Request.Form["OTP2"] ?? string.Empty;

            string strUserIP=string.Empty;

            if (_stralphaFlag == "1")
                strUserIP = _stralphaUserIP;
            else
                strUserIP = HttpContext.Current.Request.ServerVariables["Remote_Addr"];

            if (str_OTP2 != "")//有OTP2
            {
                string strUserAgent=Request.UserAgent ?? string.Empty;
                string strGashVersion=Request.Form["gashVersion"] ??"30";
                GASHv35LoginWS ws= new GASHv35LoginWS();

                WSResult _wsResult = new WSResult();
                int _intSecResult = 0;

                try
                {
                    _wsResult = ws.CreateSecretCode(str_OTP2, strUserIP, strUserAgent, strGashVersion);
                    if (_wsResult.ResultCode == 0)
                    {
                        string strSecCode = _wsResult.ResultDesc;
                        WSResult_UserData wsUserData = ws.GetUserData(str_OTP2, strSecCode);
                        if (wsUserData.ResultCode == 0)
                        {
                            _intSecResult = 1;
                            str_GashAccount = wsUserData.MainAccountID;
                            str_GameAccount = wsUserData.ServiceAccountID;
                            str_GashRegion = wsUserData.Region;
                            if (CommonGashUserData == null)
                            {
                                CommonGashUserData = new GashUserData();
                                this.CommonGashUserData.MainAccountID = wsUserData.MainAccountID;
                                this.CommonGashUserData.ServiceAccountID = wsUserData.ServiceAccountID;
                                this.CommonGashUserData.MainAccountSN = wsUserData.MainAccountSN;
                                this.CommonGashUserData.ServiceAccountSN = wsUserData.ServiceAccountSN;
                                this.CommonGashUserData.ServiceAccountDisplayName = wsUserData.ServiceAccountDisplayName;
                                this.CommonGashUserData.GashVersion = wsUserData.GashVersion;
                                this.CommonGashUserData.ServerIndex = wsUserData.ServerIndex;
                                this.CommonGashUserData.AuthType = wsUserData.AuthType;
                                this.CommonGashUserData.MainAccountType = wsUserData.MainAccountType;
                                this.CommonGashUserData.Region = wsUserData.Region;
                            }

                        }
                        else
                        {
                            _intSecResult = -2;
                        }

                    }
                    else
                        _intSecResult = -1;
                }
                catch
                {
                    _intSecResult = -3;
                }
                ws.Dispose();

                if (_intSecResult == 1)
                {
                    Session["GashAccount"] = str_GashAccount;
                    Session["GameAccount"] = str_GameAccount;
                    Session["GashRegion"] = str_GashRegion;
                    Session["CommonGashUserData"] = CommonGashUserData;
                }
                else
                {
                    SDCodeCheck.JSUtil.AlertSussTranscation("登入驗證失敗,請重新登入!", Request.Url.AbsoluteUri.ToString());
                    return;
                }
            }
            else//沒有OTP2
            {
                //判斷是否有登入
                if ((Session["GashAccount"] == null) || (Session["GameAccount"] == null) || (Session["GashRegion"] == null) || Session["CommonGashUserData"]==null)
                {
                    string schema = ConfigurationManager.AppSettings["WEB_Protocol"] ?? "http://";
                    string str_ReturnUrl = Request.Url.AbsoluteUri.ToString();
                    if(_LoginTimeTick=="1") str_ReturnUrl=str_ReturnUrl+"?TimeTickCode=" + DateTime.Now.Ticks.ToString();

                    if (schema.ToLower() == "https://")
                    {
                        str_ReturnUrl = str_ReturnUrl.Replace("http://", "https://");
                    }

                    string str_UserAgent = Request.UserAgent ?? string.Empty;
                    CreateOTP(strUserIP, str_UserAgent, str_ReturnUrl, int_LoginMode, str_ServiceCode, str_ServiceRegion, isDisplayTitle);
                }
                else
                {
                    str_GashAccount = (string)Session["GashAccount"] ?? string.Empty;
                    str_GameAccount = (string)Session["GameAccount"] ?? string.Empty;
                    str_GashRegion = (string)Session["GashRegion"] ?? string.Empty;
                    CommonGashUserData = (GashUserData)Session["CommonGashUserData"];
                }
            }

            //檢查是否有限定特定地區玩家才能參加
            if (str_GashRegion != string.Empty && str_SetUserGashRegion != string.Empty)
            {
                if (str_GashRegion.ToUpper() != str_SetUserGashRegion.ToUpper())
                {
                    Session["GashAccount"] = null;
                    Session["GameAccount"] = null;
                    Session["GashRegion"] = null;
                    SDCodeCheck.JSUtil.AlertCloseMsg("您所在的地區不符合參加本活動的資格唷!");
                    return;
                }
            }

        }
        else
        {
            SDCodeCheck.JSUtil.AlertCloseMsg("系統發生不可預期的錯誤,請稍後再試!");
            return;
        }
    }