Exemple #1
0
/**
创建角色
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)
}
Exemple #2
0
/**
登录帐号
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)
}