Esempio n. 1
0
func FumbleLobbyStarted(lob_ *Lobby) {
	if Fumble == nil {
		return
	}

	var lob Lobby
	db.DB.Preload("Slots").First(&lob, lob_.ID)

	for _, slot := range lob.Slots {
		team, class, _ := LobbyGetSlotInfoString(lob.Type, slot.Slot)

		var player Player
		db.DB.First(&player, slot.PlayerId)

		if _, ok := broadcaster.GetSocket(player.SteamId); ok {
			/*var userIp string
			if userIpParts := strings.Split(so.Request().RemoteAddr, ":"); len(userIpParts) == 2 {
				userIp = userIpParts[0]
			} else {
				userIp = so.Request().RemoteAddr
			}*/
			FumbleAllowPlayer(lob.ID, strings.ToUpper(class)+" "+player.Name, strings.ToUpper(team))
		} else {
			helpers.Logger.Warning("Socket for player with steamid[%d] not found.", player.SteamId)
		}
	}
}
Esempio n. 2
0
func (Lobby) LobbyBan(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)

	if reqerr != nil {
		return reqerr.Encode()
	}

	var args struct {
		Id      *uint   `json:"id"`
		Steamid *string `json:"steamid"`
	}

	if err := chelpers.GetParams(data, &args); err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	steamId := *args.Steamid
	selfSteamId := chelpers.GetSteamId(so.Id())

	if steamId == selfSteamId {
		return helpers.NewTPError("Player can't kick himself.", -1).Encode()
	}
	if ok, tperr := playerCanKick(*args.Id, selfSteamId); !ok {
		return tperr.Encode()
	}

	lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
	if tperr != nil {
		return tperr.Encode()
	}

	lob.BanPlayer(player)

	so, _ = broadcaster.GetSocket(player.SteamId)
	chelpers.AfterLobbyLeave(server, so, lob, player)

	broadcaster.SendMessage(steamId, "sendNotification",
		fmt.Sprintf(`{"notification": "You have been removed from Lobby #%d"}`, *args.Id))

	return chelpers.EmptySuccessJS
}