Пример #1
0
    // 是否可以对玩家账号进行上分下分操作
    private OpRes canDoScoreToPlayer(string acc, long score, bool isAddScore, GMUser user)
    {
        Player player = new Player(acc, user);

        if (!player.m_isExists)
        {
            return(OpRes.op_res_player_not_exist);
        }

        if (player.isAccStop())
        {
            return(OpRes.op_res_acc_block);
        }

        if (!player.isDerivedFrom(user))
        {
            return(OpRes.op_res_no_right);
        }

        if (!isAddScore)
        {
            if (!player.isMoneyEnough(score))
            {
                return(OpRes.op_res_money_not_enough);
            }
        }

        Dictionary <string, object> data = QueryBase.getPlayerPropertyByAcc(acc, user, new string[] { "SyncLock" });

        if (data != null)
        {
            if (data.ContainsKey("SyncLock"))
            {
                int state = Convert.ToInt32(data["SyncLock"]);
                if (state == 2)
                {
                    return(OpRes.op_res_player_locked);
                }
            }
        }

        if (player.isInGame())
        {
            return(OpRes.op_res_player_in_game);
        }

        return(OpRes.opres_success);
    }
    public override OpRes makeQuery(object param, GMUser user, QueryCondition queryCond)
    {
        ParamQueryRecharge p = (ParamQueryRecharge)param;

        int          condCount = 0;
        PlatformInfo pinfo     = null;

        if (!string.IsNullOrEmpty(p.m_param))
        {
            switch (p.m_way)
            {
            case QueryWay.by_way0:     //  通过玩家id查询
            {
                int val = -1;
                if (!int.TryParse(p.m_param, out val))
                {
                    return(OpRes.op_res_param_not_valid);
                }
                Dictionary <string, object> ret = QueryBase.getPlayerProperty(val, user, s_field);
                if (ret == null)
                {
                    return(OpRes.op_res_not_found_data);
                }
                if (!ret.ContainsKey("platform"))
                {
                    return(OpRes.op_res_failed);
                }

                // 取玩家ID所在平台
                string platName = Convert.ToString(ret["platform"]);
                queryCond.addQueryCond("PlayerId", val);

                pinfo = ResMgr.getInstance().getPlatformInfoByName(platName);

                // 获取服务器ID

                /*DbServerInfo dbInfo = ResMgr.getInstance().getDbInfo(user.m_dbIP);
                 * if (dbInfo != null)
                 * {
                 *  queryCond.addQueryCond("ServerId", dbInfo.m_serverId);
                 * }*/
            }
            break;

            case QueryWay.by_way1:     //  通过账号查询
            {
                Dictionary <string, object> ret = QueryBase.getPlayerPropertyByAcc(p.m_param, user, s_field);
                if (ret == null)
                {
                    return(OpRes.op_res_not_found_data);
                }
                if (!ret.ContainsKey("platform"))
                {
                    return(OpRes.op_res_failed);
                }

                // 取玩家账号所在平台,然后从相应的平台去查
                string platName = Convert.ToString(ret["platform"]);
                queryCond.addQueryCond("Account", p.m_param);

                pinfo = ResMgr.getInstance().getPlatformInfoByName(platName);

                // 获取服务器ID

                /* DbServerInfo dbInfo = ResMgr.getInstance().getDbInfo(user.m_dbIP);
                 * if (dbInfo != null)
                 * {
                 *   queryCond.addQueryCond("ServerId", dbInfo.m_serverId);
                 * }*/
            }
            break;

            case QueryWay.by_way2:     //  通过订单号查询
            {
                pinfo = ResMgr.getInstance().getPlatformInfo(p.m_platIndex);
                queryCond.addQueryCond("OrderID", p.m_param);
            }
            break;

            default:
            {
                return(OpRes.op_res_failed);
            }
            }
            condCount++;
        }
        else
        {
            pinfo = ResMgr.getInstance().getPlatformInfo(p.m_platIndex);

            // 获取服务器ID

            /*DbServerInfo dbInfo = ResMgr.getInstance().getDbInfo(user.m_dbIP);
             * if (dbInfo != null)
             * {
             *  queryCond.addQueryCond("ServerId", dbInfo.m_serverId);
             * }*/
        }

        if (pinfo == null)
        {
            return(OpRes.op_res_need_sel_platform);
        }

        if (!m_items.ContainsKey(pinfo.m_engName))
        {
            return(OpRes.op_res_not_found_data);
        }

        m_rbase = m_items[pinfo.m_engName];

        m_platInfo.m_tableName = pinfo.m_tableName;
        m_platInfo.m_platName  = pinfo.m_engName;

        if (queryCond.isExport())
        {
            queryCond.addCond("table", m_platInfo.m_tableName);
            queryCond.addCond("plat", m_platInfo.m_platName);
        }

        if (p.m_time != "")
        {
            DateTime mint = DateTime.Now, maxt = DateTime.Now;
            bool     res = Tool.splitTimeStr(p.m_time, ref mint, ref maxt);
            if (!res)
            {
                return(OpRes.op_res_time_format_error);
            }

            condCount++;
            if (queryCond.isExport())
            {
                queryCond.addCond("time", p.m_time);
            }
            else
            {
                IMongoQuery imq1 = Query.LT("PayTime", BsonValue.Create(maxt));
                IMongoQuery imq2 = Query.GTE("PayTime", BsonValue.Create(mint));
                queryCond.addImq(Query.And(imq1, imq2));
            }
        }

        if (p.m_result > 0)
        {
            queryCond.addQueryCond("Process", p.m_result == 1 ? true : false);
        }
        if (!string.IsNullOrEmpty(p.m_range))
        {
            if (!Tool.isTwoNumValid(p.m_range))
            {
                return(OpRes.op_res_param_not_valid);
            }

            if (queryCond.isExport())
            {
                queryCond.addCond("range", p.m_range);
            }
            else
            {
                List <int> range = new List <int>();
                Tool.parseNumList(p.m_range, range);
                IMongoQuery timq1  = Query.LTE("RMB", BsonValue.Create(range[1]));
                IMongoQuery timq2  = Query.GTE("RMB", BsonValue.Create(range[0]));
                IMongoQuery tmpImq = Query.And(timq1, timq2);
                queryCond.addImq(tmpImq);
            }
        }

        if (condCount == 0)
        {
            return(OpRes.op_res_need_at_least_one_cond);
        }

        return(OpRes.opres_success);
    }
    private OpRes query(GMUser user, ParamMemberInfo p)
    {
        string cmd = "";
        OpRes  res = m_generator.genSearchSql(p, user, ref cmd);

        if (res != OpRes.opres_success)
        {
            return(res);
        }

        if (p.m_countEachPage > 0 && p.m_curPage > 0)
        {
            cmd += string.Format(" LIMIT {0}, {1}", (p.m_curPage - 1) * p.m_countEachPage, p.m_countEachPage);
            user.totalRecord = user.sqlDb.getRecordCount(TableName.PLAYER_ACCOUNT_XIANXIA,
                                                         p.m_resultCond, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA);
        }

        List <Dictionary <string, object> > dataList =
            user.sqlDb.queryList(cmd, user.getMySqlServerID(), MySqlDbName.DB_XIANXIA);

        if (dataList == null)
        {
            return(OpRes.op_res_failed);
        }

        // 账号所在数据库ID
        int accServerId = -1;

        if (user.isAdmin() || user.isGeneralAgency())
        {
            // 账号所在数据库ID
            accServerId = DBMgr.getInstance().getSpecialServerId(DbName.DB_ACCOUNT);
        }

        for (int i = 0; i < dataList.Count; i++)
        {
            MemberInfo info = new MemberInfo();
            m_result.Add(info);
            Dictionary <string, object> data = dataList[i];
            info.m_createTime = Convert.ToString(data["createTime"]);
            info.m_acc        = Convert.ToString(data["acc"]);
            info.m_accType    = AccType.ACC_PLAYER;
            info.m_owner      = Convert.ToString(data["creator"]);
            info.m_moneyType  = Convert.ToInt32(data["moneyType"]);
            info.m_state      = Convert.ToInt32(data["state"]);
            if (info.m_state == PlayerState.STATE_IDLE) // 离线
            {
                info.m_money = Convert.ToInt64(data["money"]);
            }
            else // 在线
            {
                if (!(data["moneyOnline"] is DBNull))
                {
                    info.m_money = Convert.ToInt64(data["moneyOnline"]);
                }
            }

            if (!(data["aliasName"] is DBNull))
            {
                info.m_aliasName = Convert.ToString(data["aliasName"]);
            }

            if (!(data["lastLoginDate"] is DBNull))
            {
                info.m_lastLoginDate = Convert.ToDateTime(data["lastLoginDate"]).ToString();
            }

            if (!(data["enable"] is DBNull))
            {
                bool enable = Convert.ToBoolean(data["enable"]);
                if (!enable)
                {
                    info.m_state = PlayerState.STATE_BLOCK;
                }
            }

            if (accServerId >= 0)
            {
                // 查询最后登录IP

                /* Dictionary<string, object> retData = DBMgr.getInstance().getTableData(TableName.PLAYER_ACCOUNT,
                 *                                "acc", info.m_acc, s_fields, accServerId, DbName.DB_ACCOUNT);
                 * if (retData != null)
                 * {
                 *   if (retData.ContainsKey("lastip"))
                 *   {
                 *       info.m_lastLoginIP = Convert.ToString(retData["lastip"]);
                 *   }
                 * }*/
            }

            if (!(data["playerWashRatio"] is DBNull))
            {
                info.m_washRatio = Convert.ToInt32(data["playerWashRatio"]);
            }

            Dictionary <string, object> retData = QueryBase.getPlayerPropertyByAcc(info.m_acc, user, s_fields);
            if (retData != null)
            {
                if (retData.ContainsKey("NotSaveRate"))
                {
                    info.m_isAffectRate = !Convert.ToBoolean(retData["NotSaveRate"]);
                }
                else
                {
                    info.m_isAffectRate = true;
                }
            }
            else
            {
                info.m_isAffectRate = true;
            }
        }

        return(OpRes.opres_success);
    }