Exemplo n.º 1
0
        public static void Do(ClientInfo clientInfo, string data)
        {
            S2C_Bag s2c = new S2C_Bag();

            s2c.Tag  = CSParam.NetTag.Bag.ToString();
            s2c.Code = (int)CSParam.CodeType.Ok;
            try
            {
                C2S_Bag c2s    = JsonConvert.DeserializeObject <C2S_Bag>(data);
                int     UserId = c2s.UserId;

                List <KeyData> keylist = new List <KeyData>()
                {
                    new KeyData("id", UserId)
                };

                MySqlUtil.getInstance().addCommand(CmdType.query, "bag", keylist, null, (CmdReturnData cmdReturnData) =>
                {
                    if (cmdReturnData.result == CmdResult.OK)
                    {
                        s2c.Code = (int)CSParam.CodeType.Ok;

                        List <Object> list        = cmdReturnData.listData;
                        List <Table_Bag> dataList = new List <Table_Bag>();
                        if (list != null && list.Count > 0)
                        {
                            dataList = Table_Bag.init(list);
                        }
                        s2c.data = JsonConvert.SerializeObject(dataList);
                        Socket_S.getInstance().Send(clientInfo, s2c);
                    }
                    else
                    {
                        s2c.Code = (int)CSParam.CodeType.ServerError;
                        Socket_S.getInstance().Send(clientInfo, s2c);
                        return;
                    }
                });
            }
            catch (Exception ex)
            {
                s2c.Code = (int)CSParam.CodeType.ParamError;
                Socket_S.getInstance().Send(clientInfo, s2c);
            }
        }
Exemplo n.º 2
0
    public static List <Table_Bag> init(List <Object> data)
    {
        List <Table_Bag> list = new List <Table_Bag>();

        int keyCount = 5;

        if ((data.Count % keyCount) == 0)
        {
            for (int i = 0; i < data.Count; i += 5)
            {
                Table_Bag table = new Table_Bag();

                //table.pk = (int)data[i];
                //table.id = (int)data[i + 1];
                table.itemid   = (int)data[i + 2];
                table.uniqueid = (int)data[i + 3];
                table.count    = (int)data[i + 4];

                list.Add(table);
            }
        }

        return(list);
    }