예제 #1
0
// HandleRoot runs when someone hits / on the website
func HandleRoot(rw http.ResponseWriter, r *http.Request) {
	//mytools.Debug(fmt.Sprint("/ Request from ", r.RemoteAddr, " at ", time.Now()))
	go mytools.Log("Access", fmt.Sprint("/ Request from ", r.RemoteAddr, " at ", time.Now()))
	page, err := template.ParseFiles("index.html")
	mytools.CheckError("Parsing index Template", err)
	err = page.Execute(rw, "")
	mytools.CheckError("executing template", err)
}
예제 #2
0
//UpdateTheBoxes is a url handler
func UpdateTheBoxes(rw http.ResponseWriter, r *http.Request) {
	go mytools.Log("Access", fmt.Sprint("/UpdateTheBoxes Request from ", r.RemoteAddr, " at ", time.Now()))
	mytools.WebDebug(rw, "Getting Clan Member List")
	members := boxcheckerbackend.GetClanMembers()
	mytools.WebDebug(rw, "Getting boxes")
	boxcheckerbackend.GetBoxes(members)
	mytools.WebDebug(rw, "Counting boxes")
	boxcheckerbackend.CountLastMonthBoxes(members)
	mytools.WebDebug(rw, "Updating activity dates")
	boxcheckerbackend.UpdateLastActive(members)
}
예제 #3
0
// Scheduler automates the updating of boxes.  Runs forever and sleeps a minute at a Time
// and when the date changes trigger the update process.
func Scheduler() {

	today := time.Now().Local().Format("2006-01-02 00:00:00")
	hours, minutes, _ := time.Now().Clock()
	for {
		if today != time.Now().Local().Format("2006-01-02 00:00:00") {
			mytools.Debug("Performing Update")
			mytools.Log("Scheduler", fmt.Sprint("Performing update at", hours))
			members := boxcheckerbackend.GetClanMembers()
			boxcheckerbackend.GetBoxes(members)
			boxcheckerbackend.CountLastMonthBoxes(members)
			today = time.Now().Local().Format("2006-01-02 00:00:00")
		}

		if minutes == 0 {
			//mytools.Debug(fmt.Sprint("Hourly Scheduler Heartbeat at ", hours))
			go mytools.Log("Scheduler", fmt.Sprint("Hourly Scheduler Heartbeat at ", hours))
		}
		time.Sleep(time.Minute)
	}
}
예제 #4
0
//UpcomingBattles is a page handler.
func UpcomingBattles(rw http.ResponseWriter, r *http.Request) {
	go mytools.Log("Access", fmt.Sprint("/UpcomingBattles Request from ", r.RemoteAddr, " at ", time.Now()))
	var Battles AllBattles
	Battles.SHBattles = battlechecker.GetStrongBattleTimes()
	Battles.NumSHBattles = len(Battles.SHBattles.Battles)
	Battles.CWBattles = battlechecker.GetCWBattleTimes()
	Battles.NumCWBattles = len(Battles.CWBattles.Battles)
	page, err := template.ParseFiles("upcomingbattles.html")
	mytools.CheckError("Parsing Template", err)
	err = page.Execute(rw, Battles)
	mytools.CheckError("executing template", err)
}
예제 #5
0
// Die is a debugging function that will kill the website process.
func Die(rw http.ResponseWriter, r *http.Request) {
	go mytools.Log("Access", fmt.Sprint("/Die Request from ", r.RemoteAddr, " at ", time.Now()))
	rw.Write([]byte("Shutting down."))
	os.Exit(999)
}
예제 #6
0
//ShowMeTheBoxesOld try to use only one template.
func ShowMeTheBoxesOld(rw http.ResponseWriter, r *http.Request) {
	/*
		Query the database Members table and then cycles through the  ordered results
		and prints out some html templates in a table.
	*/
	go mytools.Log("Access", fmt.Sprint("/ShowMeTheBoxesOld Request from ", r.RemoteAddr, " at ", time.Now()))
	database, tx := boxcheckerbackend.MakeDBConnection()
	var i, j, CurrentMemberCount int
	var AverageBoxes float32
	var PageData ShowMePageData

	//var stats ClanStats
	const white = "#FFFFFF"
	const green = "#99FF99"
	const greenDark = "#7ACC7A"
	const brown = "#CC8845"
	const brownDark = "#996633"
	const red = "#FFCCCC"
	const redDark = "#CCA5A5"

	CurrentMemberCount = len(boxcheckerbackend.GetClanMembers().Members)
	TableRows := make([]TableRow, CurrentMemberCount)

	err := database.QueryRow("SELECT AVG(`lastmonthboxcount`) FROM `members`").Scan(&AverageBoxes)
	mytools.CheckError("AverageBoxes", err)
	PageData.Average = int(AverageBoxes)

	page, err := template.ParseFiles("showmetheboxesold.html")
	mytools.CheckError("Parsing template", err)

	//query database for members table
	rows, err := database.Query("SELECT * FROM members WHERE active = ? ORDER BY lastmonthboxcount DESC", true)

	i = 1
	j = 0

	for rows.Next() {
		TableRows[j].Comment = ""
		TableRows[j].Position = i

		err := rows.Scan(&TableRows[j].UserID, &TableRows[j].Name, &TableRows[j].BoxCount, &TableRows[j].Days, &TableRows[j].Since, &TableRows[j].Active, &TableRows[j].LastActiveDate)
		mytools.CheckError("scan row results", err)
		if TableRows[j].Days > 0 { //avoid div by 0
			TableRows[j].AverageBoxesPerDay = int(TableRows[j].BoxCount / TableRows[j].Days)
		} else {
			TableRows[j].AverageBoxesPerDay = 0
		}
		if TableRows[j].BoxCount > int(AverageBoxes) { //green
			if i%2 == 0 {
				TableRows[j].Colour = greenDark
			} else {
				TableRows[j].Colour = green
			}
		} else { //red rows for below AverageBoxes
			if i%2 == 0 {
				TableRows[j].Colour = redDark
			} else {
				TableRows[j].Colour = red
			}
		}
		if TableRows[j].BoxCount == 0 { //Commence shitter logic for the guys with no boxes
			if i%2 == 0 { //row shading
				TableRows[j].Colour = brownDark
			} else {
				TableRows[j].Colour = brown
			}
			TableRows[j].Comment = "No Box Shitter"
			if TableRows[j].Name == "Powderworx" {
				TableRows[j].Comment = "Head Shitter" //Colour commentary
			}
			TableRows[j].LastActiveDate = playerchecker.GetPlayerData(TableRows[j].UserID).LastBattleTime.Format("2006-01-02")
		}
		//'special' handling logics  first place has no life etc.
		if TableRows[j].BoxCount < PageData.Average { //Nestingthese checks removes the need for an if j>0 check
			if TableRows[j-1].BoxCount > PageData.Average {
				TableRows[j].Comment = "So Close!"
				TableRows[j-1].Comment = "Phew!"
			}
		}
		if TableRows[j].BoxCount == PageData.Average {
			TableRows[j].Comment = "Mr. Average"
		}
		i++
		j++
	}
	TableRows[0].Comment = "No life Super Stah!"

	TableRows[9].Comment = "Top Ten Baby!"

	PageData.Rows = TableRows
	mytools.CheckError("Executing Page", page.Execute(rw, PageData))

	//Clean up
	rows.Close()
	err = tx.Commit()
	mytools.CheckError("tx.Commit()", err)
	database.Close()
}
예제 #7
0
//ShowMeTheBoxesNew is a page handler does more than it should
func ShowMeTheBoxesNew(rw http.ResponseWriter, r *http.Request) {
	/*
		Query the database Members table and then cycles through the  ordered results
		and prints out some html templates in a table.
	*/

	go mytools.Log("Access", fmt.Sprint("/ShowMeTheBoxes Request from ", r.RemoteAddr, " at ", time.Now()))
	database, tx := boxcheckerbackend.MakeDBConnection()
	var i, j, CurrentMemberCount int
	var AverageBoxes float32
	var PageData ShowMePageData

	//var stats ClanStats

	CurrentMemberCount = len(boxcheckerbackend.GetClanMembers().Members)
	TableRows := make([]TableRow, CurrentMemberCount)

	err := database.QueryRow("SELECT AVG(`lastmonthboxcount`) FROM `members`").Scan(&AverageBoxes)
	mytools.CheckError("AverageBoxes", err)
	PageData.Average = int(AverageBoxes)

	page, err := template.ParseFiles("showmetheboxes.html")
	mytools.CheckError("Parsing template", err)

	//query database for members table
	rows, err := database.Query("SELECT * FROM members WHERE active = ? ORDER BY lastmonthboxcount DESC", true)

	i = 1
	j = 0

	for rows.Next() {
		TableRows[j].Comment = ""
		TableRows[j].Position = i

		err := rows.Scan(&TableRows[j].UserID, &TableRows[j].Name, &TableRows[j].BoxCount, &TableRows[j].Days, &TableRows[j].Since, &TableRows[j].Active, &TableRows[j].LastActiveDate)
		mytools.CheckError("scan row results", err)
		if TableRows[j].Days > 0 { //avoid div by 0
			TableRows[j].AverageBoxesPerDay = int(TableRows[j].BoxCount / TableRows[j].Days)
		} else {
			TableRows[j].AverageBoxesPerDay = 0
		}
		if TableRows[j].BoxCount > 0 {
			TableRows[j].LastActiveDate = ""
		}
		if TableRows[j].BoxCount == 0 { //Commence shitter logic for the guys with no boxes
			TableRows[j].Comment = "No Box Shitter"
			if TableRows[j].Name == "Powderworx" {
				TableRows[j].Comment = "Head Shitter" //Colour commentary
			}
			//TableRows[j].LastActiveDate = playerchecker.GetPlayerData(TableRows[j].UserID).LastBattleTime.Format("2006-01-02")
		}

		/*		if TableRows[j].BoxCount < PageData.Average { //Nesting these checks removes the need for an if j>0 check
				if TableRows[j-1].BoxCount > PageData.Average {
					TableRows[j].Comment = "So Close!" //almost above average
					TableRows[j-1].Comment = "Phew!"   //barely above average
				}
			}*/
		if TableRows[j].Name == "BluesmanRS" {
			TableRows[j].Comment = "Brasil!"
		}
		i++
		j++
	}
	TableRows[0].Comment = "No life Super Stah!"
	TableRows[9].Comment = "Top Ten Baby!"
	//get the rows into the page data struct then execute the page.
	PageData.Rows = TableRows
	ColourCodeRowsAverage(&PageData)

	mytools.CheckError("Executing Page", page.Execute(rw, PageData))

	//Clean up
	rows.Close()
	err = tx.Commit()
	mytools.CheckError("tx.Commit()", err)
	database.Close()

}