Example #1
0
func (lobby *Lobby) DiscordNotif(msg string) {
	if helpers.Discord != nil {
		mumble := ""
		if lobby.Mumble {
			mumble = helpers.DiscordEmoji("mumble")
		}

		region := lobby.RegionName
		if lobby.RegionCode == "eu" || lobby.RegionCode == "au" {
			region = fmt.Sprintf(":flag_%s:", lobby.RegionCode)
		} else if lobby.RegionCode == "na" {
			region = ":flag_us:"
		}

		byLine := ""
		player, playerErr := player.GetPlayerBySteamID(lobby.CreatedBySteamID)
		if playerErr != nil {
			logrus.Error(playerErr)
		} else {
			byLine = fmt.Sprintf(" by %s", player.Alias())
		}

		formatName := format.FriendlyNamesMap[lobby.Type]

		msg := fmt.Sprintf("%s: %s%s %s on %s%s: %s/lobby/%d", msg, region, mumble, formatName, lobby.MapName, byLine, config.Constants.LoginRedirectPath, lobby.ID)
		specificChannel := strings.ToLower(fmt.Sprintf("%s-%s", formatName, lobby.RegionCode))
		helpers.DiscordSendToChannel("lobby-notifications", msg)
		helpers.DiscordSendToChannel(specificChannel, fmt.Sprintf("@here %s", msg))
	}
}
Example #2
0
func (Lobby) LobbyClose(so *wsevent.Client, args struct {
	Id *uint `json:"id"`
}) interface{} {

	player := chelpers.GetPlayer(so.Token)
	lob, tperr := lobby.GetLobbyByIDServer(uint(*args.Id))
	if tperr != nil {
		return tperr
	}

	if player.SteamID != lob.CreatedBySteamID && !(player.Role == helpers.RoleAdmin || player.Role == helpers.RoleMod) {
		return errors.New("Player not authorized to close lobby.")

	}

	if lob.State == lobby.Ended {
		return errors.New("Lobby already closed.")
	}

	lob.Close(true, false)

	notify := fmt.Sprintf("Lobby closed by %s", player.Alias())
	chat.SendNotification(notify, int(lob.ID))

	return emptySuccess
}
Example #3
0
func (Lobby) LobbyShuffle(so *wsevent.Client, args struct {
	Id uint `json:"id"`
}) interface{} {
	player := chelpers.GetPlayer(so.Token)

	lob, err := lobby.GetLobbyByID(args.Id)
	if err != nil {
		return err
	}

	if player.SteamID != lob.CreatedBySteamID && (player.Role != helpers.RoleAdmin && player.Role != helpers.RoleMod) {
		return errors.New("You aren't authorized to shuffle this lobby.")
	}

	if err = lob.ShuffleAllSlots(); err != nil {
		return err
	}

	room := fmt.Sprintf("%s_private", hooks.GetLobbyRoom(args.Id))
	broadcaster.SendMessageToRoom(room, "lobbyShuffled", args)
	chat.NewBotMessage(fmt.Sprintf("Lobby shuffled by %s", player.Alias()), int(args.Id)).Send()
	return emptySuccess
}