Esempio n. 1
0
func _convertEnegeryToPilots(playerInfo PlayerInfo) bool {
	playerInfo = _generateEnergy(playerInfo)

	b, err := json.Marshal(playerInfo)
	if err != nil {
		log.Error("转换「%v」的数据格式错误: %v", playerInfo.Name, err)
		return false
	}

	client := &http.Client{}

	host := "https://universe.walkrgame.com/api/v1/pilots/convert"
	req, err := utils.GenerateWalkrRequest(host, "POST", playerInfo.Cookie, bytes.NewBuffer([]byte(b)))
	if err != nil {
		log.Error("创建「%v」的请求出错: %v", err)
		return false

	}

	if resp, err := client.Do(req); err == nil {

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Error("读取返回数据失败: %v", err)
			return false
		}

		var record BoolResponse
		if err := json.Unmarshal([]byte(body), &record); err != nil {
			log.Error("「%v」刷新能量失败: %v", playerInfo.Name, err)
			return false
		}

		if record.Success == true {
			log.Notice("第%v轮「%v」刷新能量成功, 转换能量%v", _getRound(playerInfo), playerInfo.Name, playerInfo.ConvertedEnergy)
		} else {
			log.Warning("「%v」刷新能量失败, 转换能量%v", playerInfo.Name, playerInfo.ConvertedEnergy)

		}

		resp.Body.Close()
		return true

	} else {
		log.Error("创建请求失败: %v", err)
		return false

	}
}
Esempio n. 2
0
func _leaveComment(playerInfo PlayerInfo, fleet *Fleet, comment string) bool {
	client := &http.Client{}

	commentRequestJson := CommentRequest{
		AuthToken:     playerInfo.AuthToken,
		ClientVersion: playerInfo.ClientVersion,
		Platform:      playerInfo.Platform,
		Locale:        playerInfo.Locale,
		Text:          comment,
	}
	b, err := json.Marshal(commentRequestJson)
	if err != nil {
		log.Error("Json Marshal error for %v", err)
		return false
	}

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/fleets/%v/comment", fleet.Id)
	req, err := utils.GenerateWalkrRequest(host, "POST", playerInfo.Cookie, bytes.NewBuffer([]byte(b)))
	if err != nil {
		log.Error("请求留言失败 %v", err)
		return false
	}

	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Error("读取返回数据失败: %v", err)
			return false
		}

		var record BoolResponse
		if err := json.Unmarshal([]byte(body), &record); err != nil {
			log.Error("留言失败: %v", err)
			return false
		}

		log.Notice("「%v」已经留言(%v)", playerInfo.Name, comment)

		return record.Success
	} else {
		log.Error("请求用户留言失败: %v", err)

	}

	return false
}
Esempio n. 3
0
func _requestEpicList(playerInfo PlayerInfo) (*http.Response, error) {
	client := &http.Client{}
	v := url.Values{}
	v.Add("locale", playerInfo.Locale)
	v.Add("platform", playerInfo.Platform)
	v.Add("auth_token", playerInfo.AuthToken)
	v.Add("client_version", playerInfo.ClientVersion)

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/epics?%v", v.Encode())
	req, err := utils.GenerateWalkrRequest(host, "GET", playerInfo.Cookie, nil)
	if err != nil {
		return nil, err
	}

	return client.Do(req)

}
Esempio n. 4
0
func _leaveCurrentEpicIfExists(playerInfo PlayerInfo) bool {
	client := &http.Client{}
	v := url.Values{}
	v.Add("locale", playerInfo.Locale)
	v.Add("platform", playerInfo.Platform)
	v.Add("auth_token", playerInfo.AuthToken)
	v.Add("client_version", playerInfo.ClientVersion)

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/fleets/current?%v", v.Encode())
	req, err := utils.GenerateWalkrRequest(host, "GET", playerInfo.Cookie, nil)
	if err != nil {
		return false
	}

	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Error("读取返回数据失败: %v", err)
			return false
		}

		var record CurrentEpicResponse
		if err := json.Unmarshal([]byte(body), &record); err != nil {
			log.Error("解析当前舰队信息失败: %v", err)
			return false
		}

		if record.Success == true && record.FleetId != 0 {
			log.Notice("当前有执行中的舰队['%v':%v], 即将离开舰队", record.Name, record.FleetId)

			// 循环开始之前有舰队存在,退出当前舰队
			_doLeaveFleet(playerInfo, &Fleet{Id: record.FleetId, Name: record.Name})
		} else {
			log.Debug("当前没有执行中的舰队, 即将查看邀请列表")
		}

		return true
	} else {
		log.Error("获取当前舰队信息失败: %v", err)
		return false
	}

}
Esempio n. 5
0
func _requestNewFriendList(playerInfo PlayerInfo) (*http.Response, error) {
	log.Debug("查看是否有好友申请")

	client := &http.Client{}
	v := url.Values{}
	v.Add("platform", playerInfo.Platform)
	v.Add("auth_token", playerInfo.AuthToken)
	v.Add("client_version", playerInfo.ClientVersion)

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/users/friend_invitations?%v", v.Encode())

	req, err := utils.GenerateWalkrRequest(host, "GET", playerInfo.Cookie, nil)
	if req == nil {
		return nil, err
	}

	return client.Do(req)

}
Esempio n. 6
0
func _confirmFriend(playerInfo PlayerInfo, friendId int) bool {
	client := &http.Client{}

	confirmFriendRequestJson := ConfirmFriendRequest{
		AuthToken:     playerInfo.AuthToken,
		ClientVersion: playerInfo.ClientVersion,
		Platform:      playerInfo.Platform,
		UserId:        friendId,
	}
	b, err := json.Marshal(confirmFriendRequestJson)
	if err != nil {
		log.Error("Json Marshal error for %v", err)
		return false
	}

	host := "https://universe.walkrgame.com/api/v1/users/confirm_friend"
	req, err := utils.GenerateWalkrRequest(host, "POST", playerInfo.Cookie, bytes.NewBuffer([]byte(b)))
	if err != nil {
		return false
	}

	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Error("读取返回数据失败: %v", err)
			return false
		}

		var record BoolResponse
		if err := json.Unmarshal([]byte(body), &record); err != nil {
			log.Error("通过好友失败: %v", err)
			return false
		}

		return record.Success
	} else {
		log.Error("请求添加用户失败: %v", err)

	}
	return false
}
Esempio n. 7
0
func _requestFleetList(playerInfo PlayerInfo) (*http.Response, error) {
	client := &http.Client{}
	v := url.Values{}
	v.Add("locale", playerInfo.Locale)
	v.Add("platform", playerInfo.Platform)
	v.Add("auth_token", playerInfo.AuthToken)
	v.Add("client_version", playerInfo.ClientVersion)
	v.Add("country_code", "US")
	v.Add("epic_id", "14")
	v.Add("limit", "30")
	v.Add("name", "")
	v.Add("offset", "0")

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/fleets?%v", v.Encode())
	req, err := utils.GenerateWalkrRequest(host, "GET", playerInfo.Cookie, nil)
	if err != nil {
		return nil, err
	}

	return client.Do(req)
}
Esempio n. 8
0
func _leaveFleet(playerInfo PlayerInfo, fleet *Fleet) bool {
	client := &http.Client{}

	b, err := json.Marshal(playerInfo)
	if err != nil {
		log.Error("Json Marshal error for %v", err)
		return false
	}

	host := fmt.Sprintf("https://universe.walkrgame.com/api/v1/fleets/%v/leave", fleet.Id)
	req, err := utils.GenerateWalkrRequest(host, "POST", playerInfo.Cookie, bytes.NewBuffer([]byte(b)))
	if err != nil {
		return false
	}

	if resp, err := client.Do(req); err == nil {
		defer resp.Body.Close()

		body, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Error("读取返回数据失败: %v", err)
			return false
		}

		var record BoolResponse
		if err := json.Unmarshal([]byte(body), &record); err != nil {
			log.Error("「%v」离开舰队失败: %v", playerInfo.Name, err)
			return false
		}

		log.Notice("「%v」退出舰队[%v:%v]成功", playerInfo.Name, fleet.Name, fleet.Id)

		return record.Success
	} else {
		log.Error("「%v」请求离开舰队失败: %v", playerInfo.Name, err)

	}

	return false
}