<%@ Page Language="C#" %>

<script runat="server">

    string downpath = "http://www.0856yx.com/wd/0856yx刺影传奇.exe";//微端下载地址[放混服 本站]
    int gid = 62480;//游戏ID
    
    
    protected override void OnLoad(EventArgs e)
    {
        Response.Clear();
        //用户ID
        string uid = Request.Params["uid"];

        //游戏ID,如果不能传递gid参数,这里需要写成固定参数
        //如果是固定参数,必须复制多个此文件来应对不同游戏
        Error += new EventHandler(api_back_client_aspx_Error); 
        if (string.IsNullOrEmpty(uid))//混服用户为空,下载主站微端
        {
            if (!System.IO.File.Exists(Request.MapPath(downpath)))
            {
                Response.Write("微端不存在,这里可以转向或者显示信息");
            }
            else
            {
                Response.Redirect(downpath);
            }
        }
        else//有uid参数 可能是混服,判断混服
        {
            #region 根据UID跳转到混服
            string hf_uid = Request.Params["uid"];
            var hf_uid_user = new com.xykj.business.View.Account.User().GetUserByAccount(XY.ToInt(hf_uid));
            if (hf_uid_user == null)
            {
                hf_uid_user = new com.xykj.business.View.Account.User().GetUserByAccount(hf_uid + "");
            }
            if (hf_uid_user != null)//根据 uid 找到了用户
            {
                if (hf_uid_user.Account.Contains("_"))//是混服用户
                {
                    var mac_num = hf_uid_user.Account.Split(new char[] { '_' })[0];
                    com.xykj.database.connectEngine _connectUser = new com.xykj.database.connectEngine(); 
                    var macs = _connectUser.GetDatas<com.xykj.model.cf_merchants>("select * from cf_merchants where [mMark]='" + mac_num + "'")[0];
                    var cf_gamelink = _connectUser.GetDatas<com.xykj.model.cf_gamelink>("select * from cf_gamelink where [uid]='" + macs.ID + "' and gameid='"+gid+"'")[0];
                    
                    var mac_user = new com.xykj.business.connect.cUser();
                     
                    if (cf_gamelink != null)
                    {
                        Response.Clear();
                        Response.Redirect(cf_gamelink.pClientDownload);
                    }
                    else//未设置转向链接,下载本站微端
                    {
                        Response.Redirect(downpath);
                    }
                }
                else//不是混服用户,下载本站微端
                {
                    Response.Redirect(downpath);
                }
            }
            else//无用户,下载本站微端
            {
                Response.Redirect(downpath);
            }
            #endregion
        }
    }

    void api_back_client_aspx_Error(object sender, EventArgs e)
    {
        Response.Redirect(downpath);
    }
</script>
