Example #1
0
func lookupStatsChar(c *census.Census, name string) (string, error) {
	char, err := c.GetCharacterByName(name)
	if err != nil {
		return "", err
	}
	buf := bytes.NewBufferString("")

	// This is ugly and terrible and idc
	var cleared int
	var reported int
	reports := []db.Report{}
	db.DB.Where("name = ?", char.Name.First).Find(&reports)
	for _, v := range reports {
		if v.Cleared {
			cleared += 1
		} else {
			reported += 1
		}
	}

	if err := lookupTmpl.Execute(buf, Global{
		Character:     char,
		Dev:           Dev,
		TimesReported: reported,
		TimesCleared:  cleared,
		Reports:       reports}); err != nil {
		return "", err
	}
	return buf.String(), nil
}
Example #2
0
// NewReport creates a new report with the provided information
//
// Additionally, it creates an outfit instance if possible to reference
// if we need to.
func NewReport(reporter, player, PSN, info string, c *census.Census) error {
	report := Report{
		Reporter:       reporter,
		Name:           player,
		PSNName:        PSN,
		AdditionalInfo: info,
	}

	char, err := c.GetCharacterByName(player)
	if err != nil {
		return err
	}

	report.OutfitCID = char.Outfit.ID

	outfit := new(Outfit)

	// Create an outfit instace if we can
	DB.Where(Outfit{CID: char.Outfit.ID, Name: char.Outfit.Name}).FirstOrCreate(outfit)

	DB.Create(&report)
	return nil
}
Example #3
0
func parseEventsInto(c *census.Census, events *census.EventStream, pop *census.PopulationSet) {
loop:
	for {
		select {
		case err := <-events.Err:
			if strings.Contains(err.Error(), census.ErrCharDoesNotExist.Error()) {
				fmt.Printf("Events: error: %v\n", err.Error())
			}
		case <-events.Closed:
			fmt.Printf("Events: websocket closed\n")
			break loop
		case event := <-events.Events:
			switch event.Payload.EventName {
			case "PlayerLogin":
				ch, err := c.GetCharacterByIDRes(event.Payload.CharacterID, "faction")
				if err != nil {
					if err == census.ErrCharDoesNotExist {
						continue
					}
					fmt.Printf("Events: ERROR: Failed to get character from ID: '%v' [%v]\n",
						event.Payload.CharacterID, err.Error())
					continue
				}
				server := c.GetServerByID(event.Payload.WorldID)
				pop.PlayerLogin(server.Name.En, ch.FactionID)
			case "PlayerLogout":
				ch, err := c.GetCharacterByIDRes(event.Payload.CharacterID, "faction")
				if err != nil {
					fmt.Printf("ERROR: Failed to get character from ID: '%v' [%v]\n",
						event.Payload.CharacterID, err.Error())
					continue
				}
				server := c.GetServerByID(event.Payload.WorldID)
				pop.PlayerLogin(server.Name.En, ch.FactionID)
			}
		}
	}
	events.Close()
}