Ejemplo n.º 1
0
func forbidCallback(w http.ResponseWriter, r *http.Request) *responseDataObject.WebResponseObject {
	responseObj := responseDataObject.NewWebResponseObject()

	// 解析数据
	playerId := r.Form["PlayerId"][0]
	_type_str := r.Form["Type"][0] // 0:查看;1:封号; 2:解封
	sign := r.Form["Sign"][0]

	// 类型转换
	var _type int
	var err error
	if _type, err = strconv.Atoi(_type_str); err != nil {
		return responseObj.SetAPIDataError()
	}

	// 验证类型是否正确(0:查看封号状态 1:封号 2:解封)
	if _type != 0 && _type != 1 && _type != 2 {
		return responseObj.SetAPIDataError()
	}

	// 验证签名
	if verifyForbidSign(playerId, _type, sign) == false {
		return responseObj.SetResultStatus(responseDataObject.SignError)
	}

	// 判断玩家是否存在
	playerObj, exists, err := playerBLL.GetPlayer(playerId, true)
	if err != nil {
		return responseObj.SetDataError()
	}
	if !exists {
		return responseObj.SetResultStatus(responseDataObject.PlayerNotExist)
	}

	// 判断是否为查询状态
	if _type == 0 {
		responseObj.SetData(playerObj.IsForbidden)
	} else {
		// 修改封号状态
		if err := playerBLL.UpdateForbidStatus(playerObj, _type == 1); err != nil {
			return responseObj.SetDataError()
		}
	}

	return responseObj
}
Ejemplo n.º 2
0
func silentCallback(w http.ResponseWriter, r *http.Request) *responseDataObject.WebResponseObject {
	responseObj := responseDataObject.NewWebResponseObject()

	// 解析数据
	playerId := r.Form["PlayerId"][0]
	_type_str := r.Form["Type"][0]        // 0:查看;1:禁言; 2:解禁
	duration_str := r.Form["Duration"][0] // 单位:分钟
	sign := r.Form["Sign"][0]

	// 类型转换
	var _type int
	var duration int
	var err error

	if _type, err = strconv.Atoi(_type_str); err != nil {
		return responseObj.SetAPIDataError()
	}
	if duration, err = strconv.Atoi(duration_str); err != nil {
		return responseObj.SetAPIDataError()
	}

	// 验证类型是否正确(0:查看禁言状态 1:禁言 2:解禁)
	if _type != 0 && _type != 1 && _type != 2 {
		return responseObj.SetAPIDataError()
	}

	// 验证签名
	if verifySilentSign(playerId, _type, duration, sign) == false {
		return responseObj.SetResultStatus(responseDataObject.SignError)
	}

	// 判断玩家是否存在
	playerObj, exists, err := playerBLL.GetPlayer(playerId, true)
	if err != nil {
		return responseObj.SetDataError()
	}
	if !exists {
		return responseObj.SetResultStatus(responseDataObject.PlayerNotExist)
	}

	// 判断是否为查询状态
	if _type == 0 {
		data := make(map[string]interface{}, 2)
		isInSilent, leftMinutes := playerObj.IsInSilent()
		data["Status"] = isInSilent
		if isInSilent {
			data["LeftMinutes"] = leftMinutes
		}
		responseObj.SetData(data)
	} else {
		// 修改禁言状态
		silentEndTime := time.Now()
		if _type == 1 {
			if duration == 0 {
				silentEndTime = silentEndTime.AddDate(10, 0, 0)
			} else {
				silentEndTime = silentEndTime.Add(time.Duration(duration) * time.Minute)
			}
		}

		if err := playerBLL.UpdateSilentStatus(playerObj, silentEndTime); err != nil {
			return responseObj.SetDataError()
		}
	}

	return responseObj
}