diff --git a/model/gameparam.go b/model/gameparam.go index 8cbbd89..d834e6b 100644 --- a/model/gameparam.go +++ b/model/gameparam.go @@ -88,6 +88,7 @@ type GameParam struct { TestActSwitch bool // 开启所有活动开关 RankPlayerLevelMaxNum int //等级榜最大人数 CloseChannelSwitch bool //关闭渠道开关功能 + BackendTimeLocal int //后台时区 } var GameParamPath = "../data/gameparam.json" @@ -238,4 +239,7 @@ func InitGameParam() { if GameParamData.RankPlayerLevelMaxNum == 0 { GameParamData.RankPlayerLevelMaxNum = 100 } + if GameParamData.BackendTimeLocal == 0 { + GameParamData.BackendTimeLocal = 8 + } } diff --git a/protocol/webapi/webapi.pb.go b/protocol/webapi/webapi.pb.go index f508726..35e9cc2 100644 --- a/protocol/webapi/webapi.pb.go +++ b/protocol/webapi/webapi.pb.go @@ -8519,6 +8519,8 @@ type ASAddItemById struct { Snid int32 `protobuf:"varint,1,opt,name=Snid,proto3" json:"Snid,omitempty"` // 玩家id Platform string `protobuf:"bytes,2,opt,name=Platform,proto3" json:"Platform,omitempty"` // 平台id ItemInfo []*ItemInfo `protobuf:"bytes,3,rep,name=ItemInfo,proto3" json:"ItemInfo,omitempty"` //道具 + TypeId int32 `protobuf:"varint,4,opt,name=TypeId,proto3" json:"TypeId,omitempty"` // 变化类型 + Remark string `protobuf:"bytes,5,opt,name=Remark,proto3" json:"Remark,omitempty"` // 描述 } func (x *ASAddItemById) Reset() { @@ -8574,6 +8576,20 @@ func (x *ASAddItemById) GetItemInfo() []*ItemInfo { return nil } +func (x *ASAddItemById) GetTypeId() int32 { + if x != nil { + return x.TypeId + } + return 0 +} + +func (x *ASAddItemById) GetRemark() string { + if x != nil { + return x.Remark + } + return "" +} + type SAAddItemById struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -9548,34 +9564,38 @@ var file_webapi_proto_rawDesc = []byte{ 0x2e, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x54, 0x61, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x4c, 0x69, 0x6e, 0x6b, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4c, 0x69, 0x6e, 0x6b, 0x22, 0x6d, 0x0a, 0x0d, 0x41, 0x53, - 0x41, 0x64, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x42, 0x79, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x53, - 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x6e, 0x69, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x2c, 0x0a, 0x08, 0x49, - 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x08, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x44, 0x0a, 0x0d, 0x53, 0x41, 0x41, - 0x64, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x42, 0x79, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x03, 0x54, 0x61, - 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, - 0x2e, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x54, 0x61, 0x67, 0x12, 0x10, 0x0a, - 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x2a, - 0xce, 0x01, 0x0a, 0x07, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, - 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, - 0x45, 0x53, 0x53, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, - 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x49, 0x47, 0x4e, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, - 0x03, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x5f, - 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x4a, 0x59, 0x42, 0x5f, 0x44, - 0x41, 0x54, 0x41, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x05, 0x12, 0x12, 0x0a, 0x0e, 0x4a, - 0x59, 0x42, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x58, 0x49, 0x53, 0x54, 0x10, 0x06, 0x12, - 0x11, 0x0a, 0x0d, 0x50, 0x6c, 0x61, 0x79, 0x5f, 0x4e, 0x6f, 0x74, 0x45, 0x58, 0x49, 0x53, 0x54, - 0x10, 0x07, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x10, 0x08, 0x12, 0x0c, 0x0a, - 0x08, 0x54, 0x65, 0x6c, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0x09, 0x12, 0x13, 0x0a, 0x0f, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x10, 0x0a, - 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x65, 0x6c, 0x4e, 0x6f, 0x74, 0x42, 0x69, 0x6e, 0x64, 0x10, 0x0b, - 0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, - 0x6c, 0x2f, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4c, 0x69, 0x6e, 0x6b, 0x22, 0x9d, 0x01, 0x0a, 0x0d, 0x41, + 0x53, 0x41, 0x64, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x42, 0x79, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x53, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x6e, 0x69, 0x64, + 0x12, 0x1a, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x2c, 0x0a, 0x08, + 0x49, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x08, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x54, 0x79, + 0x70, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x54, 0x79, 0x70, 0x65, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x52, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x22, 0x44, 0x0a, 0x0d, 0x53, 0x41, + 0x41, 0x64, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x42, 0x79, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x03, 0x54, + 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x77, 0x65, 0x62, 0x61, 0x70, + 0x69, 0x2e, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x54, 0x61, 0x67, 0x12, 0x10, + 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, + 0x2a, 0xce, 0x01, 0x0a, 0x07, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, + 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, + 0x43, 0x45, 0x53, 0x53, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, + 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x49, 0x47, 0x4e, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, + 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x5f, 0x44, 0x41, 0x54, 0x41, + 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x4a, 0x59, 0x42, 0x5f, + 0x44, 0x41, 0x54, 0x41, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x05, 0x12, 0x12, 0x0a, 0x0e, + 0x4a, 0x59, 0x42, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x58, 0x49, 0x53, 0x54, 0x10, 0x06, + 0x12, 0x11, 0x0a, 0x0d, 0x50, 0x6c, 0x61, 0x79, 0x5f, 0x4e, 0x6f, 0x74, 0x45, 0x58, 0x49, 0x53, + 0x54, 0x10, 0x07, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x10, 0x08, 0x12, 0x0c, + 0x0a, 0x08, 0x54, 0x65, 0x6c, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0x09, 0x12, 0x13, 0x0a, 0x0f, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x74, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x10, + 0x0a, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x65, 0x6c, 0x4e, 0x6f, 0x74, 0x42, 0x69, 0x6e, 0x64, 0x10, + 0x0b, 0x42, 0x26, 0x5a, 0x24, 0x6d, 0x6f, 0x6e, 0x67, 0x6f, 0x2e, 0x67, 0x61, 0x6d, 0x65, 0x73, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x61, 0x6d, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, + 0x6f, 0x6c, 0x2f, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/protocol/webapi/webapi.proto b/protocol/webapi/webapi.proto index c97e848..cc6a79f 100644 --- a/protocol/webapi/webapi.proto +++ b/protocol/webapi/webapi.proto @@ -914,6 +914,8 @@ message ASAddItemById{ int32 Snid = 1; // 玩家id string Platform = 2; // 平台id repeated ItemInfo ItemInfo = 3;//道具 + int32 TypeId = 4; // 变化类型 + string Remark = 5; // 描述 } message SAAddItemById{ diff --git a/worldsrv/tournament.go b/worldsrv/tournament.go index 4be91fb..64aa182 100644 --- a/worldsrv/tournament.go +++ b/worldsrv/tournament.go @@ -7,6 +7,7 @@ import ( "sync" "time" + nowtool "github.com/jinzhu/now" "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/i18n" "mongo.games.com/goserver/core/logger" @@ -25,6 +26,7 @@ import ( func init() { module.RegisteModule(TournamentMgr, time.Second, 0) + ClockMgrSington.RegisteSinker(TournamentMgr) } const ( @@ -78,6 +80,7 @@ type PlayerRoundInfo struct { } type Tournament struct { + BaseClockSinker GameMatchDateList map[string]map[int32]*webapiproto.GameMatchDate // 比赛配置,platform:比赛场配置id:比赛配置 singleSignupPlayers map[int32]*SignupInfo // 开启机器人时,报名的玩家,玩家Id:报名信息 signupPlayers map[string]map[int32]*SignInfo // 报名的玩家 platform:比赛配置id:报名人 @@ -182,6 +185,7 @@ func (this *Tournament) UpdateData(init bool, data *webapiproto.GameMatchDateLis configs := make(map[int32]*webapiproto.GameMatchDate) for _, v := range data.List { if this.checkData(v) { + this.FixMatchTimeStamp(v) configs[v.Id] = v } else { logger.Logger.Error("GameMatchDate error: ", v) @@ -274,17 +278,6 @@ func (this *Tournament) IsRobotOn(match *webapiproto.GameMatchDate) bool { // IsTimeRange 判断是否在比赛时间段内 // 在时间段内才能报名 func (this *Tournament) IsTimeRange(gmd *webapiproto.GameMatchDate) bool { - getWeekNum := func(t time.Time) int { - strWeek := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} - week := t.Weekday() - for i, s := range strWeek { - if week.String() == s { - return i - } - } - return 0 - } - if gmd == nil { return false } @@ -299,17 +292,21 @@ func (this *Tournament) IsTimeRange(gmd *webapiproto.GameMatchDate) bool { case 0: return true case 1: - nowWeek := getWeekNum(tNow) - hms := int32(tNow.Hour()*10000 + tNow.Minute()*100 + tNow.Second()) - if gmd.MatchTimeWeek != nil && len(gmd.MatchTimeWeek) > 0 { - for _, week := range gmd.MatchTimeWeek { - if nowWeek == int(week) { - if hms >= gmd.MatchTimeStartHMS && hms <= gmd.MatchTimeEndHMS { + week := this.getWeekDay() + for _, v := range gmd.MatchTimeWeek { + if week == int(v) { + if gmd.MatchTimeStamp != nil && len(gmd.MatchTimeStamp) > 1 { + this.FixMatchTimeStamp(gmd) + startStamp := gmd.MatchTimeStamp[0] + endStamp := gmd.MatchTimeStamp[1] + if tNow.Unix() >= startStamp && tNow.Unix() <= endStamp { return true } } + return false } } + case 2: if gmd.MatchTimeStamp != nil && len(gmd.MatchTimeStamp) > 1 { startStamp := gmd.MatchTimeStamp[0] @@ -1201,7 +1198,7 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int64, title := i18n.Tr("languages", "MatchAwardTitle") content := i18n.Tr("languages", "MatchAward", params) newMsg = model.NewMessage("", 0, "", mc.p.SnId, model.MSGTYPE_RANK_REWARD, - title, content, 0, 0, model.MSGSTATE_UNREAD, time.Now().Unix(), 0, "", nil, mc.p.Platform, model.HallTienlen) + title, content, 0, 0, model.MSGSTATE_UNREAD, time.Now().Unix(), 0, "", nil, mc.p.Platform, model.HallTienlen, nil) err := model.InsertMessage(mc.p.Platform, newMsg) if err != nil { logger.Logger.Errorf("发送邮件失败 snid:%v itemID:%v err:%v", mc.p.SnId, data.Id, err) @@ -1534,3 +1531,61 @@ func (this *Tournament) Update() { } func (this *Tournament) Shutdown() {} + +func (this *Tournament) getWeekDay() int { + getWeekNum := func(t time.Time) int { + strWeek := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} + week := t.Weekday() + for i, s := range strWeek { + if week.String() == s { + return i + } + } + return 0 + } + + l := time.FixedZone("CST", model.GameParamData.BackendTimeLocal*3600) + bTs := time.Now().In(l) + week := getWeekNum(bTs) + return week +} + +func (this *Tournament) FixMatchTimeStamp(d *webapiproto.GameMatchDate) { + // 更新比赛时间 + if d == nil || d.MatchTimeType != 1 { + return + } + if len(d.MatchTimeStamp) != 2 { + return + } + + l := time.FixedZone("CST", model.GameParamData.BackendTimeLocal*3600) + bTs := time.Now().In(l) + week := this.getWeekDay() + st := time.Unix(d.MatchTimeStamp[0], 0).In(l) + et := time.Unix(d.MatchTimeStamp[1], 0).In(l) + logger.Logger.Tracef("FixMatchTimeStamp 1 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et) + // 重复时间段比赛时间 + for _, v := range d.MatchTimeWeek { + if v == int32(week) { + stSub := st.Unix() - nowtool.New(st).BeginningOfDay().Unix() + sub := d.MatchTimeStamp[1] - d.MatchTimeStamp[0] + d.MatchTimeStamp[0] = nowtool.New(bTs).BeginningOfDay().Add(time.Duration(stSub) * time.Second).Unix() + d.MatchTimeStamp[1] = d.MatchTimeStamp[0] + sub + + st = time.Unix(d.MatchTimeStamp[0], 0).In(l) + et = time.Unix(d.MatchTimeStamp[1], 0).In(l) + logger.Logger.Tracef("FixMatchTimeStamp 2 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et) + + break + } + } +} + +func (this *Tournament) OnHourTimer() { + for _, v := range this.GameMatchDateList { + for _, vv := range v { + this.FixMatchTimeStamp(vv) + } + } +} diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index bec8804..68ee0e3 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -4367,13 +4367,13 @@ func init() { p := PlayerMgrSington.GetPlayerBySnId(msg.GetSnid()) if p != nil { //获取道具Id - BagMgrSingleton.AddItems(p, items, 0, common.GainWayBackend, "system", "后台操作", 0, 0, false) + BagMgrSingleton.AddItems(p, items, 0, msg.GetTypeId(), "system", msg.GetRemark(), 0, 0, false) pack.Tag = webapiproto.TagCode_SUCCESS pack.Msg = "AddItem success" return common.ResponseTag_Ok, pack } else { - BagMgrSingleton.AddItemsOffline(msg.Platform, msg.Snid, items, common.GainWayBackend, - "system", "后台操作", 0, 0, false, func(err error) { + BagMgrSingleton.AddItemsOffline(msg.Platform, msg.Snid, items, msg.GetTypeId(), + "system", msg.GetRemark(), 0, 0, false, func(err error) { if err != nil { pack.Tag = webapiproto.TagCode_FAILED pack.Msg = "AddItem failed:" + err.Error()