示例#1
0
        public static int SendAward(DBManager dbMgr, string userID, int roleID, int awardID)
        {
            TenAwardData awardData = TenManager.getTenAward(awardID);
            int          result;

            if (awardData == null)
            {
                result = -6;
            }
            else
            {
                DateTime now = DateTime.Now;
                if (now < awardData.BeginTime || now > awardData.EndTime)
                {
                    result = -9;
                }
                else
                {
                    DBRoleInfo roleData = DBManager.getInstance().GetDBRoleInfo(ref roleID);
                    if (roleData == null)
                    {
                        result = -3;
                    }
                    else if (roleData.ChangeLifeCount * 100 + roleData.Level < awardData.RoleLevel)
                    {
                        result = -10;
                    }
                    else
                    {
                        if (awardData.OnlyNum > 0)
                        {
                            int totalNum = DBQuery.TenOnlyNum(dbMgr, userID, awardID);
                            if (totalNum > 0)
                            {
                                return(-5);
                            }
                        }
                        if (awardData.DayMaxNum > 0)
                        {
                            int totalNum = DBQuery.TenDayNum(dbMgr, userID, awardID);
                            if (totalNum >= awardData.DayMaxNum)
                            {
                                return(-5);
                            }
                        }
                        string mailGoodsString = "";
                        if (null != awardData.AwardGoods)
                        {
                            foreach (GoodsData goods in awardData.AwardGoods)
                            {
                                int useCount = goods.GCount;
                                mailGoodsString += string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}_{14}_{15}", new object[]
                                {
                                    goods.GoodsID,
                                    goods.Forge_level,
                                    goods.Quality,
                                    goods.Props,
                                    useCount,
                                    0,
                                    0,
                                    goods.Jewellist,
                                    goods.AddPropIndex,
                                    goods.Binding,
                                    goods.BornIndex,
                                    goods.Lucky,
                                    goods.Strong,
                                    goods.ExcellenceInfo,
                                    goods.AppendPropLev,
                                    goods.ChangeLifeLevForEquip
                                });
                                if (mailGoodsString.Length > 0)
                                {
                                    mailGoodsString += "|";
                                }
                            }
                        }
                        string[] fields = new string[]
                        {
                            "-1",
                            awardData.MailUser,
                            roleID.ToString(),
                            "",
                            awardData.MailTitle.ToString(),
                            awardData.MailContent.ToString(),
                            "0",
                            "0",
                            "0",
                            mailGoodsString
                        };
                        int addGoodsCount = 0;
                        int mailID        = Global.AddMail(dbMgr, fields, out addGoodsCount);
                        if (mailID > 0)
                        {
                            string gmCmd     = string.Format("{0}|{1}", roleID.ToString(), mailID);
                            string gmCmdData = string.Format("-notifymail {0}", gmCmd);
                            ChatMsgManager.AddGMCmdChatMsg(-1, gmCmdData);
                            result = mailID;
                        }
                        else
                        {
                            result = -8;
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
        public TCPProcessCmdResults ProcChangeBangHuiName(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            string cmdData   = null;
            string bhOldName = "";

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID), null, true);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            try
            {
                string[] fields = cmdData.Split(new char[]
                {
                    ':'
                });
                if (fields.Length != 3)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData), null, true);
                    tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
                    return(TCPProcessCmdResults.RESULT_DATA);
                }
                int    roleId                  = Convert.ToInt32(fields[0]);
                int    factionId               = Convert.ToInt32(fields[1]);
                string newName                 = fields[2];
                EChangeGuildNameError ne       = EChangeGuildNameError.DBFailed;
                DBRoleInfo            roleInfo = dbMgr.GetDBRoleInfo(ref roleId);
                if (null == roleInfo)
                {
                    ne = EChangeGuildNameError.DBFailed;
                }
                else
                {
                    lock (roleInfo)
                    {
                        if (roleInfo.Faction != factionId || roleInfo.BHZhiWu != 1)
                        {
                            ne = EChangeGuildNameError.OperatorDenied;
                            goto IL_381;
                        }
                    }
                    if (!this.IsNameCanUseInDb(dbMgr, newName))
                    {
                        ne = EChangeGuildNameError.InvalidName;
                    }
                    else
                    {
                        BangHuiDetailData detail = DBQuery.QueryBangHuiInfoByID(dbMgr, factionId);
                        if (detail == null || detail.CanModNameTimes <= 0 || detail.BZRoleID != roleId)
                        {
                            ne = EChangeGuildNameError.OperatorDenied;
                        }
                        else
                        {
                            bhOldName = detail.BHName;
                            SingletonTemplate <NameUsedMgr> .Instance().AddCannotUse_BangHui_Ex(detail.BHName);

                            if (!SingletonTemplate <NameUsedMgr> .Instance().AddCannotUse_BangHui_Ex(newName) || dbMgr.IsBangHuiNameExist(newName))
                            {
                                ne = EChangeGuildNameError.NameAlreadyUsed;
                            }
                            else
                            {
                                string sql = string.Format("UPDATE t_banghui SET bhname='{0}', can_mod_name_times={1} WHERE bhid={2}", newName, detail.CanModNameTimes - 1, factionId);
                                if (!this._Util_ExecNonQuery(dbMgr, sql))
                                {
                                    ne = EChangeGuildNameError.DBFailed;
                                }
                                else
                                {
                                    lock (roleInfo)
                                    {
                                        roleInfo.BHName = newName;
                                    }
                                    if (!DBWriter.UpdateAllRoleBangHuiName(dbMgr, factionId, newName))
                                    {
                                        LogManager.WriteLog(LogTypes.Error, string.Format("更新帮会id={0}的名字 {1} => {2},更新t_roles未(全部)成功", factionId, detail.BHName, newName), null, true);
                                    }
                                    List <DBRoleInfo> dbRoleInfoList = dbMgr.DBRoleMgr.GetCachingDBRoleInfoListByFaction(factionId);
                                    if (null != dbRoleInfoList)
                                    {
                                        for (int i = 0; i < dbRoleInfoList.Count; i++)
                                        {
                                            dbRoleInfoList[i].BHName = newName;
                                        }
                                    }
                                    ZhanMengShiJianData eventData = new ZhanMengShiJianData();
                                    eventData.BHID        = factionId;
                                    eventData.ShiJianType = ZhanMengShiJianConstants.ChangeName;
                                    eventData.RoleName    = roleInfo.RoleName;
                                    eventData.SubSzValue1 = newName;
                                    eventData.CreateTime  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                    ZhanMengShiJianManager.getInstance().onAddZhanMengShiJian(eventData);
                                    string recordSql = string.Format("INSERT INTO t_change_name_banghui(bhid,by_role,old_name,new_name,time) VALUES({0},{1},'{2}','{3}','{4}')", new object[]
                                    {
                                        factionId,
                                        roleId,
                                        bhOldName,
                                        newName,
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                                    });
                                    this._Util_ExecNonQuery(dbMgr, recordSql);
                                    ne = EChangeGuildNameError.Success;
                                }
                            }
                        }
                    }
                }
IL_381:
                if (ne == EChangeGuildNameError.Success)
                {
                    GameDBManager.BangHuiLingDiMgr.OnChangeBangHuiName(factionId, bhOldName, newName);
                    string gmCmdData = string.Format("-synclingdi", new object[0]);
                    ChatMsgManager.AddGMCmdChatMsg(-1, gmCmdData);
                }
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, string.Format("{0}", (int)ne), nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, "", false, false);
            }
            tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767);
            return(TCPProcessCmdResults.RESULT_DATA);
        }