Esempio 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
}
Esempio n. 2
0
func pushCallback(w http.ResponseWriter, r *http.Request) *responseDataObject.WebResponseObject {
	responseObj := responseDataObject.NewWebResponseObject()

	// 解析数据
	message := r.Form["Message"][0]
	sign := r.Form["Sign"][0]

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

	// 推送数据
	go playerBLL.PushMessage(message)

	return responseObj
}
Esempio n. 3
0
func sensitiveCallback(w http.ResponseWriter, r *http.Request) *responseDataObject.WebResponseObject {
	responseObj := responseDataObject.NewWebResponseObject()

	// 解析数据
	message := r.Form["Message"][0]
	sign := r.Form["Sign"][0]

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

	// 重新加载敏感词
	if err := sensitiveWordsBLL.Reload(); err != nil {
		return responseObj.SetDataError()
	}

	return responseObj
}
Esempio n. 4
0
func (mux *SelfDefineMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	responseObj := responseDataObject.NewWebResponseObject()

	// 判断是否是POST方法
	if r.Method != "POST" {
		responseResult(w, responseObj.SetResultStatus(responseDataObject.OnlySupportPOST))
		return
	}

	// 根据路径选择不同的处理方法
	if f, ok := funcMap[r.RequestURI]; !ok {
		responseResult(w, responseObj.SetResultStatus(responseDataObject.APINotDefined))
		return
	} else {
		// 记录日志
		if configBLL.IfRecordAPIInfo() {
			if err := writeRequestLog(r.RequestURI, r); err != nil {
				responseResult(w, responseObj.SetDataError())
				return
			}
		}

		// 判断参数是否存在
		if paramNameList, ok := paramMap[r.RequestURI]; !ok {
			responseResult(w, responseObj.SetResultStatus(responseDataObject.APIDataError))
			return
		} else {
			for _, name := range paramNameList {
				if r.Form[name] == nil || len(r.Form[name]) == 0 {
					responseResult(w, responseObj.SetResultStatus(responseDataObject.APIDataError))
					return
				}
			}
		}

		// 调用方法
		responseObj = f(w, r)

		// 输出结果
		responseResult(w, responseObj)
	}
}
Esempio n. 5
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
}