diff --git a/cmd/gameserver/action/GmAction.go b/cmd/gameserver/action/GmAction.go deleted file mode 100644 index d19cd17..0000000 --- a/cmd/gameserver/action/GmAction.go +++ /dev/null @@ -1,73 +0,0 @@ -// GM系统API -package action - -import ( - "pro2d/models" - "pro2d/pb" - "strconv" -) - -type GmAction struct{} - -// GMParams GM系统API请求参数的基础类型 -type GMParams map[string]string - -/* -AddExp 增加经验 - exp 增加经验数量 -*/ -func (gm *GmAction) AddExp(role *models.RoleModel, params GMParams) { - expIncrease, _ := strconv.Atoi(params["exp"]) - exp := role.IncrProperty("exp", int64(expIncrease)) - role.UpdateProperty("exp", exp, true) -} - -/* -AddEquip 添加装备 - id: 装备id -*/ -func (gm *GmAction) AddEquip(role *models.RoleModel, params GMParams) { - //TODO 验证装备是否存在 - - equip := &pb.Equipment{ - Id: role.IncreEquipByKey(1), - RoleId: role.Role.Id, - Type: params["id"], - Quality: 1, - } - role.AddEquip(equip) -} - -/* -AddItem 添加物品 - id: 物品id - count: 物品数量 -*/ -func (gm *GmAction) AddItem(role *models.RoleModel, params GMParams) { - id := params["id"] - count, _ := strconv.Atoi(params["count"]) - role.AddItem(id, int32(count)) -} - -/* -UpdatePackLimit 更新背包限制 - clotheslimit: 服饰限制数 - weaponslimit: 武器限制数 - otherlimit: 其他限制数 -*/ -func (gm *GmAction) UpdatePackLimit(role *models.RoleModel, params GMParams) { - update := make(map[string]interface{}, 3) - c, ok := params["clotheslimit"] - if ok { - update["clotheslimit"], _ = strconv.Atoi(c) - } - w := params["weaponslimit"] - if ok { - update["weaponslimit"], _ = strconv.Atoi(w) - } - o := params["otherlimit"] - if ok { - update["otherlimit"], _ = strconv.Atoi(o) - } - role.UpdateProperties(update, true) -} diff --git a/cmd/gameserver/gmaction/GmAction.go b/cmd/gameserver/gmaction/GmAction.go new file mode 100644 index 0000000..7df9ea3 --- /dev/null +++ b/cmd/gameserver/gmaction/GmAction.go @@ -0,0 +1,73 @@ +// GM系统API +package gmaction + +import ( + "pro2d/models" + "pro2d/pb" + "strconv" +) + +type GmAction struct{} + +// GMParams GM系统API请求参数的基础类型 +type GMParams map[string]string + +/* +AddExp 增加经验 + exp 增加经验数量 +*/ +func (gm *GmAction) AddExp(role *models.RoleModel, params GMParams) { + expIncrease, _ := strconv.Atoi(params["exp"]) + exp := role.IncrProperty("exp", int64(expIncrease)) + role.UpdateProperty("exp", exp, true) +} + +/* +AddEquip 添加装备 + id: 装备id +*/ +func (gm *GmAction) AddEquip(role *models.RoleModel, params GMParams) { + //TODO 验证装备是否存在 + + equip := &pb.Equipment{ + Id: role.IncreEquipByKey(1), + RoleId: role.Role.Id, + Type: params["id"], + Quality: 1, + } + role.AddEquip(equip) +} + +/* +AddItem 添加物品 + id: 物品id + count: 物品数量 +*/ +func (gm *GmAction) AddItem(role *models.RoleModel, params GMParams) { + id := params["id"] + count, _ := strconv.Atoi(params["count"]) + role.AddItem(id, int32(count)) +} + +/* +UpdatePackLimit 更新背包限制 + clotheslimit: 服饰限制数 + weaponslimit: 武器限制数 + otherlimit: 其他限制数 +*/ +func (gm *GmAction) UpdatePackLimit(role *models.RoleModel, params GMParams) { + update := make(map[string]interface{}, 3) + c, ok := params["clotheslimit"] + if ok { + update["clotheslimit"], _ = strconv.Atoi(c) + } + w := params["weaponslimit"] + if ok { + update["weaponslimit"], _ = strconv.Atoi(w) + } + o := params["otherlimit"] + if ok { + update["otherlimit"], _ = strconv.Atoi(o) + } + role.UpdateProperties(update, true) +} diff --git a/cmd/httpserver/action/AccountAction.go b/cmd/httpserver/action/AccountAction.go index 0f666f6..a3235c8 100644 --- a/cmd/httpserver/action/AccountAction.go +++ b/cmd/httpserver/action/AccountAction.go @@ -19,12 +19,13 @@ type AccountAction struct { HttpServer *service.AccountServer } -/*Register 账号注册 -2 验证码转化为string错误 -3 验证码错误 -4 手机号已存在,不用重复注册 -5 uid get error -6 mongo create error +/* +Register 账号注册 + 2 验证码转化为string错误 + 3 验证码错误 + 4 手机号已存在,不用重复注册 + 5 uid get error + 6 mongo create error */ func (h *AccountAction) Register(c *gin.Context) (int, interface{}) { var register pb.Register @@ -64,9 +65,10 @@ func (h *AccountAction) Register(c *gin.Context) (int, interface{}) { return 0, "success" } -/*Login 登录 -2 账号不存在 -3 密码错误 +/* +Login 登录 + 2 账号不存在 + 3 密码错误 */ func (h *AccountAction) Login(c *gin.Context) (int, interface{}) { var login pb.Account @@ -97,9 +99,10 @@ func (h *AccountAction) Login(c *gin.Context) (int, interface{}) { return 0, rsp } -/*Sms 发短信 -2 发送太频繁 -3 发送失败 +/* +Sms 发短信 + 2 发送太频繁 + 3 发送失败 */ func (h *AccountAction) Sms(c *gin.Context) (int, interface{}) { phone, ok := c.GetQuery("phone") diff --git a/cmd/httpserver/main.go b/cmd/httpserver/main.go new file mode 100644 index 0000000..99cbc4c --- /dev/null +++ b/cmd/httpserver/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + "os/signal" + "pro2d/cmd/httpserver/action" + "pro2d/cmd/httpserver/service" + "pro2d/common" + "pro2d/common/logger" + "syscall" +) + +func main() { + err := make(chan error) + stopChan := make(chan os.Signal) + signal.Notify(stopChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) + + common.GlobalSconf = common.GlobalConf.AccountConf + + web := service.NewAccountServer("v1", fmt.Sprintf(":%d", common.GlobalSconf.Port)) + web.BindHandler(&action.AccountAction{HttpServer: web}) + go func() { + err <- web.Start() + }() + + select { + case e := <-err: + logger.Error("http server error: %v", e) + case <-stopChan: + logger.Debug("http stop") + web.Stop() + } +} diff --git a/common/db/mongoproxy/mongoplugin.go b/common/db/mongoproxy/mongoplugin.go index 9b4e639..3f855bf 100644 --- a/common/db/mongoproxy/mongoplugin.go +++ b/common/db/mongoproxy/mongoplugin.go @@ -47,7 +47,11 @@ func ConnectMongo(conf *common.MongoConf, ID int64) error { return err } - mongoDatabase = mongoClient.Database(fmt.Sprintf("%s_%d", conf.DBName, ID)) + if conf.DBName != "account" { + mongoDatabase = mongoClient.Database(fmt.Sprintf("%s_%d", conf.DBName, ID)) + } else { + mongoDatabase = mongoClient.Database(conf.DBName) + } return nil } -- libgit2 0.21.2