コード例 #1
0
ファイル: commandPost.go プロジェクト: sore0159/overpower
func (h *Handler) CommandSetDoneBuffer(g overpower.GameDat, f overpower.FactionDat, turnStr, buffStr string) (errServer, errUser error) {
	if g.Turn() < 1 {
		return nil, NewError("GAME HAS NOT YET BEGUN")
	}
	turnI, err := strconv.Atoi(turnStr)
	if err != nil || turnI != g.Turn() {
		return nil, NewError("FORM SUBMISSION TURN DOES NOT MATCH GAME TURN")
	}
	buffI, err := strconv.Atoi(buffStr)
	if err != nil {
		return nil, NewError("UNPARSABLE TURN BUFFER VALUE")
	}
	if buffI < 0 {
		buffI = -1
	}
	if buffI == f.DoneBuffer() {
		return nil, nil
	}
	return InternalSetDoneBuffer(f.GID(), f.FID(), buffI)
}
コード例 #2
0
ファイル: fullview.go プロジェクト: sore0159/overpower
func (h *Handler) GetFullView(gid int) (fv *FullView, errS, errU error) {
	wGID := h.GID(gid)
	games, err := h.M.Game().SelectWhere(wGID)
	if my, bad := Check(err, "GetFullView failure on resource aquisition", "resource", "games", "gid", gid); bad {
		return nil, my, nil
	}
	if len(games) == 0 {
		return nil, nil, NewError("NO GAME FOUND")
	}
	g := games[0]
	turn := g.Turn() - 1
	if turn < 0 {
		return nil, nil, NewError("GAME HAS NOT YET BEGUN")
	}
	facs, err := h.M.Faction().SelectWhere(wGID)
	if my, bad := Check(err, "GetFullView failure on resource aquisition", "resource", "factions", "gid", gid); bad {
		return nil, my, nil
	}
	var userF overpower.FactionDat
	for _, f := range facs {
		if f.Owner() == h.User.String() {
			userF = f
			break
		}
	}
	if userF == nil {
		return nil, nil, NewError("USER HAS NO FACTION FOR GAME")
	}
	userF.SetFullJSON()

	wFID := h.FID(gid, userF.FID())
	wTURN := h.TURN(gid, userF.FID(), turn)

	plVs, err1 := h.M.PlanetView().SelectWhere(wFID)
	shVs, err2 := h.M.ShipView().SelectWhere(wTURN)
	launchOrders, err3 := h.M.LaunchOrder().SelectWhere(wFID)
	mapviews, err4 := h.M.MapView().SelectWhere(wFID)
	laRec, err5 := h.M.LaunchRecord().SelectWhere(wTURN)
	batRec, err6 := h.M.BattleRecord().SelectWhere(wTURN)
	powOrds, err7 := h.M.PowerOrder().SelectWhere(wFID)
	truces, err8 := h.M.Truce().SelectWhere(wFID)
	for i, err := range []error{err1, err2, err3, err4, err5, err6, err7, err8} {
		if my, bad := Check(err, "fill fullview failure", "index", i, "gid", gid, "fid", userF.FID(), "turn", turn); bad {
			return nil, my, nil
		}
	}
	if len(powOrds) == 0 {
		return nil, NewError("FILL FULLVIEW FAILED TO FIND POWERORDER"), nil
	}
	if len(mapviews) == 0 {
		return nil, NewError("FILL FULLVIEW FAILED TO FIND MAPVIEWS"), nil
	}

	sortLARecords(laRec)
	sortLDRecords(batRec)
	sortFactions(facs)
	fv = &FullView{
		Game: g,
		//Faction:       userF,
		Factions:      facs,
		PlanetViews:   plVs,
		ShipViews:     shVs,
		LaunchOrders:  launchOrders,
		PowerOrder:    powOrds[0],
		Truces:        truces,
		MapView:       mapviews[0],
		LaunchRecords: laRec,
		BattleRecords: batRec,
	}
	return fv, nil, nil
}