/** 检查角色名 name 角色名 */ func CheckPlayerName(session *server.Session, response *server.Response, request server.Request) { name, hasName := request.Get("name") if !hasName { response.Faild("参数错误!") return } isExist, err := world.WPlayerService.CheckPlayerName(name) if err != nil { response.Faild("程序执行错误!") return } if isExist { response.Faild("角色名已经存在!") return } response.Success() }
/** 登录帐号 name 帐号 pwd 密码 */ func UserLogin(session *server.Session, response *server.Response, request server.Request) { name, hasName := request.Get("name") pwd, hasPwd := request.Get("pwd") if !hasName || !hasPwd { response.Put("state", server.STATE_FAILD) response.Put("msg", "参数异常!") return } tx, err := dao.Begin() defer tx.Close() userId, err := tx.QueryUser(name, pwd) if err != nil { utils.CheckErr(err) response.Put("state", server.STATE_FAILD) response.Put("msg", "程序执行异常!") return } // 帐号不存在,或者密码错误 if userId == 0 { response.Put("state", server.STATE_FAILD) response.Put("msg", "请检查帐号密码是否正确!") return } // 帐号检查成功 // 存储userId session.Put(server.ATTR_USER_ID, userId) // session.Put(server.ATTR_IS_LOGIN, true) response.Put("state", server.STATE_OK) }
/** 注册帐号 name 帐号 pwd 密码 */ func RegisterUser(session *server.Session, response *server.Response, request server.Request) { logger.Printf("regist user: %v", request) //dao.CheckUserExist("aa") name, hasName := request.Get("name") pwd, hasPwd := request.Get("pwd") if !hasName || !hasPwd { response.Put("state", server.STATE_FAILD) response.Put("msg", "参数异常!") return } tx, err := dao.Begin() defer tx.Close() isExist, err := tx.CheckUserExist(name) if err != nil { utils.CheckErr(err) response.Put("state", server.STATE_FAILD) response.Put("msg", "处理异常!") return } if isExist { response.Put("state", server.STATE_FAILD) response.Put("msg", "帐号已经存在!") return } err = tx.RegistUser(name, pwd) if err != nil { utils.CheckErr(err) response.Put("state", server.STATE_FAILD) response.Put("msg", "处理异常!") return } tx.Commit() response.Put("state", server.STATE_OK) }
/** 创建角色 name 角色名 pic 角色头像/avatar */ func CreatePlayer(session *server.Session, response *server.Response, request server.Request) { // name, hasName := request.Get("name") pic, hasPic := request.Get("pic") if !hasName || !hasPic { response.Put("state", server.STATE_FAILD) response.Put("msg", "参数错误!") return } var userId int if v, err := session.Get(server.ATTR_USER_ID); err != nil { response.Put("state", server.STATE_FAILD) response.Put("msg", "找不到userid!") return } else { userId = v.(int) } err := world.WPlayerService.CreatePlayer(name, userId, pic) if err != nil { utils.CheckErr(err) response.Put("state", server.STATE_FAILD) response.Put("msg", "程序执行错误!") return } response.Put("state", server.STATE_OK) }