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

<%@ Import Namespace="System.Linq" %>
<script runat="server">
    
    public class OutGameStudio
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public string IsSuccess { get; set; }
        /// <summary>
        /// 数据类型
        /// <para>游戏 服务器 其他</para>
        /// </summary>
        public string DataType { get; set; }
        /// <summary>
        /// 加密信息
        /// </summary>
        public string Encryption { get; set; }
        public object Datas { get; set; }
        public System.Collections.Generic.IList<GameClass> Games { get; set; }

        public System.Collections.Generic.IList<ServerClass> Servers { get; set; }

        public System.Collections.Generic.IList<com.xykj.model.xy_ports> Ports { get; set; }

        public class GameClass
        {
            /// <summary>
            /// 游戏LOGO
            /// </summary>
            public string Logo { get; set; }
            /// <summary>
            /// 游戏名称
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 额外信息,如游戏介绍
            /// </summary>
            public string Message { get; set; }
            /// <summary>
            /// 游戏编号
            /// </summary>
            public string GameNumber { get; set; }
            /// <summary>
            /// 兑换比例
            /// </summary>
            public int MoneyBit { get; set; }
            /// <summary>
            /// 货币名称
            /// </summary>
            public string MoneyName { get; set; }
        }
        public class ServerClass
        {
            /// <summary>
            /// 游戏名称
            /// </summary>
            public string ServerName { get; set; }
            /// <summary>
            /// 游戏编号
            /// </summary>
            public string ServerNumber { get; set; }
            /// <summary>
            /// 服务器线路
            /// </summary>
            public string ServerCircuit { get; set; }

            public string GNumber { get; set; }

            public string sid1 { get; set; }
            public string sid2 { get; set; }

        }

    }


    protected override void OnError(EventArgs e)
    {
        var error = Server.GetLastError();
        Server.ClearError();
        OutGameStudio json = new OutGameStudio();
        json.IsSuccess = error.Message;
        Response.Clear();
        Response.Write(XY.JToJson(json));
    }
    protected override void OnLoad(EventArgs e)
    {
        var req_data_type = Request.Params["datatype"];
        var sign = Request.Headers["sign"];
        string mySign = "123456789000";
        OutGameStudio json = new OutGameStudio();
        json.IsSuccess = "success";

        if (!string.Equals(mySign, sign, StringComparison.OrdinalIgnoreCase))
        {
            json.IsSuccess = "加密参数错误";
            Response.Clear();
            Response.Write(XY.JToJson(json));
            return;
        }

        if (string.Equals(req_data_type, "game", StringComparison.OrdinalIgnoreCase))
        {
            json.Games = new System.Collections.Generic.List<OutGameStudio.GameClass>();

            var _game = new com.xykj.business.View.Games.Game();
            var _games = _game.GetGame().Where(idc => idc.OnPay);
            foreach (var g in _games)
            {
                json.Games.Add(new OutGameStudio.GameClass() { GameNumber = g.ID + "", Logo = g.Img1, Message = "", MoneyBit = g.BitMoney, Name = g.Name, MoneyName = g.Currency });
            }
        }
        if (string.Equals(req_data_type, "server", StringComparison.OrdinalIgnoreCase))
        {
            json.Servers = new System.Collections.Generic.List<OutGameStudio.ServerClass>();
            var req_game_number = Request.Params["gamenumber"];//获取服务器时使用
            int gameId = int.Parse(req_game_number);
            var _server = new com.xykj.business.View.Games.Server();
            int count = 0;
            var servers = _server.GetServerByGidWeb(gameId, 10000, 1, out count).Where(idc => idc.OnPay);
            foreach (var s in servers)
            {
                json.Servers.Add(new OutGameStudio.ServerClass() { ServerCircuit = s.Circuit, ServerName = s.Name, ServerNumber = s.ID + "" });
            }
        }
        if (string.Equals(req_data_type, "allserver", StringComparison.OrdinalIgnoreCase))
        {
            json.Servers = new System.Collections.Generic.List<OutGameStudio.ServerClass>();
            var _server = new com.xykj.business.View.Games.Server();

            var servers = _server.GetServerss(1000000);
            foreach (var s in servers)
            {
                json.Servers.Add(new OutGameStudio.ServerClass() { sid1 = s.ServerNumber, sid2 = s.ServerNumber2, GNumber = s.GameId + "", ServerCircuit = s.Circuit, ServerName = s.Name, ServerNumber = s.ID + "" });
            }
        }
        if (string.Equals(req_data_type, "ports", StringComparison.OrdinalIgnoreCase))//同步接口参数
        {
            json.Ports = new com.xykj.database.General().GetDatas<com.xykj.model.xy_ports>("select * from xy_ports");
        }

        if (string.Equals(req_data_type, "hasuser", StringComparison.OrdinalIgnoreCase))//判断主站是否有该用户
        {
            var req_user_name = Request.Params["username"];//用户名
            json.Encryption = "nouser";
            if (!string.IsNullOrEmpty(req_user_name))
            {
                var user = new com.xykj.business.View.Account.Account().GetUserByAccount(req_user_name);
                if (user != null)
                {
                    json.Encryption = "success";
                    json.Datas = new { uName = user.Account, uId = user.ID };
                }
            }
        }

        Response.Clear();
        Response.Write(XY.JToJson(json));
    }
</script>
