Beispiel #1
0
        public bool SaveSetting(GameSetting setting)
        {
            if (this.ReadDB.Exists <GameSetting>(t => t.Code == setting.Code && t.ID != setting.ID))
            {
                return(this.FaildMessage("代码重复"));
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameSetting>(t => t.ID == setting.ID))
                {
                    db.Update(setting);
                }
                else
                {
                    db.InsertIdentity(setting);

                    //保存游戏时默认开启所有商户该游戏
                    IEnumerable <Site> list = ReadDB.ReadList <Site>();
                    foreach (Site site in list)
                    {
                        SiteGameSetting siteGameSetting = new SiteGameSetting()
                        {
                            SiteID = site.ID,
                            GameID = setting.ID,
                            Status = SiteGameSetting.SiteGameStatus.Open
                        };

                        siteGameSetting.Add(db);
                    }
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Setting, $"保存游戏设置:{setting.Name}"));
        }
Beispiel #2
0
        /// <summary>
        /// 添加管理员账号
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool AddAdminInfo(string username, string password)
        {
            if (!WebAgent.IsUserName(username))
            {
                return(this.FaildMessage("账户名错误,账户名长度再5~16位之间,字母与数字的组合"));
            }
            if (string.IsNullOrEmpty(password))
            {
                return(this.FaildMessage("请设置管理员密码"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <SystemAdmin>(t => t.UserName == username))
                {
                    return(this.FaildMessage("账户名已存在"));
                }

                new SystemAdmin()
                {
                    UserName = username,
                    Password = Encryption.SHA1WithMD5(password),
                    Status   = SystemAdmin.AdminStatus.Normal
                }.Add(db);

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Setting, $"添加管理员账号:{username}"));
        }
Beispiel #3
0
        /// <summary>
        /// 保存游戏的时间节点
        /// </summary>
        public void SaveMarkTime(string gameCode, long time, MarkType type, byte mark)
        {
            GameSetting game = GameAgent.Instance().GetGameSetting(gameCode);

            if (game == null)
            {
                return;
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameMark>(t => t.GameID == game.ID && t.Type == type && t.Mark == mark))
                {
                    db.Update <GameMark, long>(t => t.Time, time,
                                               t => t.GameID == game.ID && t.Type == type && t.Mark == mark);
                }
                else
                {
                    db.Insert(new GameMark()
                    {
                        GameID = game.ID,
                        Type   = type,
                        Mark   = mark,
                        Time   = time
                    });
                }
                db.Commit();
            }
        }
Beispiel #4
0
        public void SaveMarkTime(OrderTaskModel task, long time, byte mark = 0)
        {
            int?gameId = GameAgent.Instance().GetGameSetting(task)?.ID;

            if (gameId == null)
            {
                return;
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameMark>(t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type))
                {
                    db.Update <GameMark, long>(t => t.Time, time, t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type);
                }
                else
                {
                    new GameMark()
                    {
                        GameID = gameId.Value,
                        Mark   = mark,
                        Type   = task.Type,
                        Time   = time
                    }.Add(db);
                }
                db.Commit();
            }
        }
Beispiel #5
0
        /// <summary>
        /// 根据用户名生成后台域名
        /// </summary>
        /// <param name="siteName"></param>
        private string CreateDefaultAdminUrl(DbExecutor db, string siteName)
        {
            string shortName = PinyinAgent.ToPinYinAbbr(siteName).ToLower();

            if (shortName.Length < 4)
            {
                shortName += Guid.NewGuid().ToString("N").Substring(4 - shortName.Length);
            }
            while (db.Exists <SiteDetail>(t => t.AdminURL == shortName))
            {
                shortName += Guid.NewGuid().ToString("N").Substring(1);
            }
            return(shortName);
        }
Beispiel #6
0
        /// <summary>
        /// 添加域名记录
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domainId">根域名ID</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (string.IsNullOrEmpty(subName) || !Regex.IsMatch(subName, @"^@$|^\*$|^\w+$"))
            {
                return(this.FaildMessage($"子域名{subName}不符合规范"));
            }
            SiteDomain domain = this.GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.FaildMessage("域名ID错误"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <DomainRecord>(t => t.DomainID == domainId && t.SubName == subName))
                {
                    return(this.FaildMessage("子域名记录已经存在"));
                }

                DomainRecord record = new DomainRecord()
                {
                    CDNType  = provider,
                    CName    = this.CreateRecordCName(subName, domain.Domain),
                    DomainID = domainId,
                    Status   = DomainRecord.RecordStatus.Wait,
                    SubName  = subName
                };
                record.AddIdentity(db);

                // 添加CDN记录
                DomainCDN cdn = new DomainCDN()
                {
                    RecordID = record.ID,
                    Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                    CName    = string.Empty,
                    CDNType  = provider,
                    Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                };
                cdn.Add(db);

                db.Commit();
            }
            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// 创建默认的商户管理员账号
        /// </summary>
        private void CreateDefaultAdmin(DbExecutor db, int siteId)
        {
            if (db.Exists <SiteAdmin>(t => t.SiteID == siteId))
            {
                return;
            }
            SiteAdmin admin = new SiteAdmin()
            {
                SiteID    = siteId,
                AdminName = "admin",
                Password  = Encryption.SHA1WithMD5("admin"),
                CreateAt  = DateTime.Now,
                IsDefault = true,
                Status    = SiteAdmin.AdminStatus.Normal
            };

            admin.Add(db);
        }
Beispiel #8
0
        /// <summary>
        /// 切换域名记录的CDN供应商
        /// </summary>
        /// <param name="recordId">域名记录</param>
        /// <param name="type">CDN供应商</param>
        /// <param name="cname">自定义的别名记录</param>
        /// <returns></returns>
        public bool UpdateCDNProvider(int recordId, CDNProviderType type, string cname)
        {
            DomainRecord record = this.GetRecordInfo(recordId);

            if (record == null)
            {
                return(this.FaildMessage("域名记录错误"));
            }
            if (type == CDNProviderType.Manual && string.IsNullOrEmpty(cname))
            {
                return(this.FaildMessage("请手动设置CDN别名"));
            }
            if (!IsCDNProvider(type))
            {
                return(this.FaildMessage("当前不支持该供应商"));
            }

            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                bool isExists = db.Exists <DomainCDN>(t => t.RecordID == recordId && t.CDNType == type);
                switch (type)
                {
                case CDNProviderType.Manual:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Finish,
                                CName  = cname
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status, t => t.CName);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            CName    = cname,
                            Status   = DomainCDN.CDNStatus.Finish,
                            CDNType  = type
                        }.Add(db);
                    }

                    record.Status = DomainRecord.RecordStatus.Finish;

                    db.AddCallback(() =>
                        {
                            // 调用DNS供应商的接口,设定记录的别名指向到此处手动设定的CDN别名地址
                        });
                }
                break;

                default:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Wait
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            Status   = DomainCDN.CDNStatus.Wait,
                            CDNType  = type
                        }.Add(db);
                    }
                    record.Status = DomainRecord.RecordStatus.Wait;
                }
                break;
                }

                record.CDNType = type;
                record.Update(db, t => t.Status, t => t.CDNType);

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Site, $"设定域名{record.SubName}.{domain.Domain}的CDN供应商为:{type.GetDescription()}"));
        }