Example #1
0
func Handle(
	stdHandler *std.StdHandler,
	travianHandler *travian.TravianHandler,
	trav *travian.Game,
	ui *console.GUI,
	v *gocui.View) error {

	command := strings.Trim(v.Buffer(), "\n\r ")

	parsedCmd, _ := shellwords.Parse(command)

	if len(command) == 0 {
		return nil
	}

	if exists := stdHandler.Handle(parsedCmd, ui); exists {

	} else if exists := travianHandler.Handle(parsedCmd, trav, ui); exists {

	} else {
		ui.Println("Command not found")
	}

	v.Clear() // clears input view's input buffer

	return nil
}
Example #2
0
func Stats(args []string, trav *Game, ui *console.GUI) bool {
	stat, err := trav.HttpClient.GetStatisticsHTML()

	if err != nil {
		panic(err)
	}

	ui.Println("Position: %s; Username: %s; Alliance: %s; Population: %s, Villages: %s",
		stat["position"], stat["username"], stat["alliance"], stat["pop"], stat["village_count"])
	return true
}
Example #3
0
func PrintCookie(args []string, trav *Game, ui *console.GUI) bool {
	url, _ := url.Parse("http://s5.zravian.com")
	cookies := trav.HttpClient.GoClient.Jar.Cookies(url)

	var cookieVal string

	for _, cookie := range cookies {
		if cookie.Name == "PHPSESSID" {
			cookieVal = cookie.Value
			break
		}
	}

	ui.Println("Cookie: %v", cookieVal)
	return true
}
Example #4
0
func ping(args []string, ui *console.GUI) bool {
	ui.Println("Pong")
	return true
}