Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
82d7a728e9
@ -12,6 +12,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
"sync"
|
||||
)
|
||||
@ -280,3 +281,62 @@ func (this *ModelUniongve) infochangepush(unionid string, info *pb.DBGuildGve) {
|
||||
Info: info,
|
||||
}, users...)
|
||||
}
|
||||
|
||||
// 更新埋点数据到db中
|
||||
func (this *ModelUniongve) guildgveModel() (model *guildgveModel, err error) {
|
||||
var (
|
||||
conn *db.DBConn
|
||||
m *db.DBModel
|
||||
)
|
||||
if db.IsCross() {
|
||||
model = &guildgveModel{module: this.module, model: this.DBModel}
|
||||
} else {
|
||||
if conn, err = db.Cross(); err != nil {
|
||||
return
|
||||
}
|
||||
m = db.NewDBModel(this.TableName, conn)
|
||||
model = &guildgveModel{module: this.module, model: m}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 埋点专属模型 会封装特殊的数据转换接口
|
||||
type guildgveModel struct {
|
||||
module *GuildGve
|
||||
model *db.DBModel
|
||||
}
|
||||
|
||||
// 分布式锁
|
||||
func (this *guildgveModel) userlock(id string) (result *redis.RedisMutex, err error) {
|
||||
return this.model.Redis.NewRedisMutex(fmt.Sprintf("lockuniongve:%s", id))
|
||||
}
|
||||
|
||||
// 获取用户全部的埋点数据
|
||||
func (this *guildgveModel) getGuildGve(guildid string) (results *pb.DBGuildGve, err error) {
|
||||
|
||||
results = &pb.DBGuildGve{
|
||||
Boos: make([]*pb.DBGuildGveBoss, 0),
|
||||
}
|
||||
if err = this.model.GetByID(guildid, results); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *guildgveModel) updateGuildGve(data *pb.DBGuildGve) (err error) {
|
||||
if err = this.model.ChangeById(data.Guildid, map[string]interface{}{
|
||||
"fire": data.Fire,
|
||||
"notice": data.Notice,
|
||||
"currstage": data.Currstage,
|
||||
"rtime": data.Rtime,
|
||||
"kills": data.Kills,
|
||||
"lastkilltime": data.Lastkilltime,
|
||||
"rank": data.Rank,
|
||||
"boos": data.Boos,
|
||||
}); err != nil {
|
||||
this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -119,20 +119,25 @@ func (this *GuildGve) ModifyBooslv(session comm.IUserSession, lv int32) (errdata
|
||||
members []*pb.SociatyMemberInfo
|
||||
users []string = make([]string, 0)
|
||||
conf *cfg.GameGuildBossData
|
||||
model *guildgveModel
|
||||
err error
|
||||
)
|
||||
|
||||
if sociaty = this.ModuleSociaty.GetSociaty(session.GetUserId()); sociaty != nil {
|
||||
if sociaty = this.ModuleSociaty.GetSociaty(session.GetUserId()); sociaty == nil {
|
||||
return
|
||||
}
|
||||
lock, _ := this.modelGuildGve.userlock(sociaty.Id)
|
||||
if model, err = this.modelGuildGve.guildgveModel(); err != nil {
|
||||
this.Error("guildgveModel err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
lock, _ := model.userlock(sociaty.Id)
|
||||
err = lock.Lock()
|
||||
if err != nil {
|
||||
this.Error("公会战分布式锁 err!", log.Field{Key: "Unionid", Value: sociaty.Id}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
defer lock.Unlock()
|
||||
if info, err = this.modelGuildGve.getGuildGve(sociaty.Id); err != nil {
|
||||
if info, err = model.getGuildGve(sociaty.Id); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
@ -150,7 +155,7 @@ func (this *GuildGve) ModifyBooslv(session comm.IUserSession, lv int32) (errdata
|
||||
v.Hp = conf.Hp
|
||||
v.Record = make([]*pb.DBGveRecord, 0)
|
||||
}
|
||||
if err = this.modelGuildGve.updateGuildGve(info); err != nil {
|
||||
if err = model.updateGuildGve(info); err != nil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
"sort"
|
||||
|
||||
@ -169,10 +170,25 @@ func (this *ModelSociaty) findByName(name string) *pb.DBSociaty {
|
||||
// 获取公会
|
||||
func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty, err error) {
|
||||
sociaty = &pb.DBSociaty{}
|
||||
if db.IsCross() {
|
||||
if err = this.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil {
|
||||
this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
var (
|
||||
conn *db.DBConn
|
||||
model *db.DBModel
|
||||
)
|
||||
if conn, err = db.Cross(); err != nil {
|
||||
return
|
||||
}
|
||||
model = db.NewDBModel(this.TableName, conn)
|
||||
if err = model.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil {
|
||||
this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/event"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/utils"
|
||||
@ -131,6 +132,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
|
||||
}
|
||||
return
|
||||
}
|
||||
session.SetSession(session.GetIP(), session.GetSessionId(), session.GetServiecTag(), session.GetGatewayServiceId(), user.Uid)
|
||||
session.SendMsg(string(this.module.GetType()), UserSubTypeLogin, &pb.UserLoginResp{
|
||||
Data: user,
|
||||
Ex: expand,
|
||||
@ -138,6 +140,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
|
||||
})
|
||||
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
event.TriggerEvent(comm.EventUserLogin, session)
|
||||
this.module.ModuleFriend.ResetFriend(user.Uid)
|
||||
this.module.modelSign.UserSign(session)
|
||||
this.module.ModuleItems.InitItemBagData(session)
|
||||
@ -147,81 +150,5 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
|
||||
}
|
||||
})
|
||||
|
||||
// 在logintime更新前判断是否是昨天
|
||||
// if utils.IsYestoday(user.Logintime) {
|
||||
// tasks = append(tasks, comm.GetBuriedParam(comm.Rtype9, 1))
|
||||
// } else {
|
||||
// this.module.ModuleBuried.ResetBuriedByType(user.Uid, comm.Rtype9)
|
||||
// }
|
||||
|
||||
//不是新账号
|
||||
// if !isNewUser {
|
||||
// lastLoginTime = user.Logintime
|
||||
// user.Logintime = configure.Now().Unix()
|
||||
// user.Lastloginip = session.GetIP()
|
||||
// user.Offlinetime = 0
|
||||
// user.Area = req.Area
|
||||
// user.Channel = req.Channel
|
||||
// user.Vcode = req.Vcode
|
||||
// user.Vname = req.Vname
|
||||
// update := utils.StructToMap(user) //尽量不要更新整个数据
|
||||
// err = this.module.modelUser.Change(user.Uid, update)
|
||||
// if err != nil {
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_DBError,
|
||||
// Title: pb.ErrorCode_DBError.ToString(),
|
||||
// Message: err.Error(),
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// if this.module.modelUser.isLoginFirst(lastLoginTime) {
|
||||
// this.module.ModuleHero.NoLoginDay(user.Uid, int32(utils.DiffDays(lastLoginTime, configure.Now().Unix())))
|
||||
// tasks = append(tasks, comm.GetBuriedParam(comm.Rtype8, 1))
|
||||
// this.module.modelExpand.updateLoginDay(user.Uid, lastLoginTime)
|
||||
// // 清理点赞
|
||||
// this.module.ModuleFriend.ResetFriend(user.Uid)
|
||||
// this.module.modelSign.UserSign(session)
|
||||
// this.module.ModuleItems.InitItemBagData(session)
|
||||
// }
|
||||
|
||||
// // 判断昨日是否登录
|
||||
|
||||
// rsp.Data = user
|
||||
|
||||
// // 查询玩家扩展数据
|
||||
// if expand, err := this.module.GetUserExpand(session.GetUserId()); err != nil {
|
||||
// if err != mongo.ErrNoDocuments {
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_DBError,
|
||||
// Title: pb.ErrorCode_DBError.ToString(),
|
||||
// Message: err.Error(),
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// } else {
|
||||
// rsp.Ex = expand
|
||||
// }
|
||||
// } else { //新号
|
||||
// rsp.Ex = &pb.DBUserExpand{}
|
||||
// this.module.modelSign.UserSign(session)
|
||||
// tasks = append(tasks, comm.GetBuriedParam(comm.Rtype8, 1))
|
||||
// }
|
||||
|
||||
// this.module.ModuleHero.CheckPeachReward(session, user.Ctime)
|
||||
// go this.module.RecoverUserPsStart(session.Clone())
|
||||
// // 日常登录任务
|
||||
// tasks = append(tasks, comm.GetBuriedParam(comm.Rtype7, 1))
|
||||
// tasks = append(tasks, comm.GetBuriedParam(comm.Rtype230, 1, int32(configure.Now().Weekday())))
|
||||
// this.module.ModulePrivilege.CheckDailyPrivilegeMail(session)
|
||||
|
||||
// rsp.Data = user
|
||||
// rsp.TimeNow = configure.Now().Unix() // 设置服务器时间
|
||||
// session.SendMsg(string(this.module.GetType()), UserSubTypeLogin, rsp)
|
||||
// if len(tasks) > 0 {
|
||||
// go this.module.ModuleBuried.TriggerBuried(session.Clone(), tasks...)
|
||||
// }
|
||||
|
||||
// event.TriggerEvent(comm.EventUserLogin, session.Clone())
|
||||
return
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -64,6 +65,14 @@ var restart = &cobra.Command{
|
||||
start()
|
||||
},
|
||||
}
|
||||
var sync = &cobra.Command{
|
||||
Use: "sync",
|
||||
Short: "同步服务器",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
lego.Recover("sync")
|
||||
syncServer()
|
||||
},
|
||||
}
|
||||
|
||||
func emptyRun(*cobra.Command, []string) {}
|
||||
|
||||
@ -80,7 +89,7 @@ func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(&crosspath, "cross", "c", "./cross.json", "游戏跨服配置")
|
||||
RootCmd.PersistentFlags().StringVarP(&sid, "sid", "i", "", "区服id")
|
||||
RootCmd.PersistentFlags().BoolVarP(&openlog, "log", "l", false, "输出日志")
|
||||
RootCmd.AddCommand(confCmd, startCmd, stopCmd, restart)
|
||||
RootCmd.AddCommand(confCmd, startCmd, stopCmd, restart, sync)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -89,7 +98,7 @@ func main() {
|
||||
log.SetFileName("./s.log"),
|
||||
log.SetLoglevel(log.DebugLevel),
|
||||
log.SetUniqueLog(true),
|
||||
log.SetIsDebug(false)); err != nil {
|
||||
log.SetIsDebug(true)); err != nil {
|
||||
panic(fmt.Sprintf("Sys log Init err:%v", err))
|
||||
} else {
|
||||
log.Infof("Sys log Init success !")
|
||||
@ -221,6 +230,72 @@ func stop() {
|
||||
log.Infof("stop succ!")
|
||||
}
|
||||
|
||||
//同步服务器
|
||||
func syncServer() {
|
||||
if sid != "" {
|
||||
switch sid {
|
||||
case "qa":
|
||||
exesshcomd("10.0.0.9", `
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务准备同步--QA测试服"}}';
|
||||
cd /home/liwei/dreamworks; svn revert -R . ; svn update
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/cmd /home/liwei/dreamworks/cmd;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/gateway /home/liwei/dreamworks/gateway;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/mainte /home/liwei/dreamworks/mainte;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/worker /home/liwei/dreamworks/worker;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/json/* /home/liwei/dreamworks/json/;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/wordfilter.txt /home/liwei/dreamworks/wordfilter.txt;
|
||||
cd /home/liwei/dreamworks; svn add . --no-ignore --force ; svn commit -m "同步服务器" *;
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务停止--QA测试服"}}';
|
||||
`)
|
||||
exesshcomd("101.35.121.71", `
|
||||
cd /data/dreamworksserver/s80; python stopserver.py; python install.py; python start.py;
|
||||
cd /data/dreamworksserver/s100; python stopserver.py; python install.py; python start.py;
|
||||
`)
|
||||
exesshcomd("101.35.125.220", `
|
||||
cd /data/dreamworksserver/s90; python stopserver.py; python install.py; python start.py;
|
||||
cd /data/dreamworksserver/s110; python stopserver.py; python install.py; python start.py;
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务启动--QA测试服"}}';
|
||||
`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func exesshcomd(addr, cmd string) (err error) {
|
||||
var (
|
||||
config *ssh.ClientConfig
|
||||
sshClient *ssh.Client
|
||||
session *ssh.Session
|
||||
combo []byte
|
||||
)
|
||||
//创建sshp登陆配置
|
||||
config = &ssh.ClientConfig{
|
||||
Timeout: time.Second, //ssh 连接time out 时间一秒钟, 如果ssh验证错误 会在一秒内返回
|
||||
User: "root",
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //这个可以, 但是不够安全
|
||||
}
|
||||
config.Auth = []ssh.AuthMethod{ssh.Password("Legu.cc()123")}
|
||||
//dial 获取ssh client
|
||||
sshClient, err = ssh.Dial("tcp", fmt.Sprintf("%s:22", addr), config)
|
||||
if err != nil {
|
||||
log.Fatal("创建ssh client 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
defer sshClient.Close()
|
||||
|
||||
//创建ssh-session
|
||||
session, err = sshClient.NewSession()
|
||||
if err != nil {
|
||||
log.Fatal("创建ssh session 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
defer session.Close()
|
||||
//执行远程命令
|
||||
combo, err = session.CombinedOutput(cmd)
|
||||
if err != nil {
|
||||
log.Fatal("远程执行cmd 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
log.Println("命令输出:", string(combo))
|
||||
return
|
||||
}
|
||||
|
||||
// /转换区服配置到服务配置
|
||||
func rederServiceSttings(config *comm.GameConfig) (ss []*core.ServiceSttings, err error) {
|
||||
ss = make([]*core.ServiceSttings, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user