Ejemplo n.º 1
0
func (Lobby) LobbyClose(so *wsevent.Client, args struct {
	Id *uint `json:"id"`
}) interface{} {

	player := chelpers.GetPlayerFromSocket(so.ID)
	lob, tperr := models.GetLobbyByIDServer(uint(*args.Id))
	if tperr != nil {
		return tperr
	}

	if player.SteamID != lob.CreatedBySteamID && player.Role != helpers.RoleAdmin {
		return helpers.NewTPError("Player not authorized to close lobby.", -1)

	}

	if lob.State == models.LobbyStateEnded {
		return helpers.NewTPError("Lobby already closed.", -1)
	}

	lob.Close(true)

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

	return chelpers.EmptySuccessJS
}
Ejemplo n.º 2
0
func (Helen) SetSecret(args Args, _ *struct{}) error {
	lobby, _ := models.GetLobbyByIDServer(args.LobbyID)
	lobby.ServerInfo.LogSecret = args.LogSecret
	db.DB.Save(lobby.ServerInfo)

	return nil
}
Ejemplo n.º 3
0
func disconnectedFromServer(lobbyID uint) {
	lobby, _ := models.GetLobbyByIDServer(lobbyID)

	logrus.Debug("#%d: Lost connection to %s", lobby.ID, lobby.ServerInfo.Host)

	lobby.Close(false)
	models.SendNotification("Lobby Closed (Connection to server lost)", int(lobby.ID))
}
Ejemplo n.º 4
0
func playerChat(lobbyID uint, playerID uint, message string) {
	lobby, _ := models.GetLobbyByIDServer(lobbyID)
	player, _ := models.GetPlayerByID(playerID)

	chatMessage := models.NewInGameChatMessage(lobby, player, message)
	chatMessage.Save()
	chatMessage.Send()
}
Ejemplo n.º 5
0
func matchEnded(lobbyID uint, logsID int) {
	lobby, _ := models.GetLobbyByIDServer(lobbyID)

	logrus.Debug("#%d: Match Ended", lobbyID)

	lobby.UpdateStats()
	lobby.Close(false)

	msg := fmt.Sprintf("Lobby Ended. Logs: http://logs.tf/%d", logsID)
	models.SendNotification(msg, int(lobby.ID))
}
Ejemplo n.º 6
0
func AfterConnectLoggedIn(so *wsevent.Client, player *models.Player) {
	if time.Since(player.UpdatedAt) >= time.Hour*1 {
		player.UpdatePlayerInfo()
		player.Save()
	}

	lobbyID, err := player.GetLobbyID(false)
	if err == nil {
		lobby, _ := models.GetLobbyByIDServer(lobbyID)
		AfterLobbyJoin(so, lobby, player)
		AfterLobbySpec(socket.AuthServer, so, lobby)
		models.BroadcastLobbyToUser(lobby, chelpers.GetSteamId(so.ID))
		slot := &models.LobbySlot{}
		err := db.DB.Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).First(slot).Error
		if err == nil {
			if lobby.State == models.LobbyStateInProgress {
				broadcaster.SendMessage(player.SteamID, "lobbyStart", models.DecorateLobbyConnect(lobby, player.Name, slot.Slot))
			} else if lobby.State == models.LobbyStateReadyingUp && !slot.Ready {
				data := struct {
					Timeout int64 `json:"timeout"`
				}{lobby.ReadyUpTimeLeft()}

				broadcaster.SendMessage(player.SteamID, "lobbyReadyUp", data)
			}
		}
	}

	settings, err2 := player.GetSettings()
	if err2 == nil {
		broadcaster.SendMessage(player.SteamID, "playerSettings", models.DecoratePlayerSettingsJson(settings))
	}

	profilePlayer, err3 := models.GetPlayerWithStats(player.SteamID)
	if err3 == nil {
		broadcaster.SendMessage(player.SteamID, "playerProfile", models.DecoratePlayerProfileJson(profilePlayer))
	}

}
Ejemplo n.º 7
0
func (Player) PlayerReady(so *wsevent.Client, _ struct{}) interface{} {
	steamid := chelpers.GetSteamId(so.ID)
	player, tperr := models.GetPlayerBySteamID(steamid)
	if tperr != nil {
		return tperr
	}

	lobbyid, tperr := player.GetLobbyID(false)
	if tperr != nil {
		return tperr
	}

	lobby, tperr := models.GetLobbyByIDServer(lobbyid)
	if tperr != nil {
		return tperr
	}

	if lobby.State != models.LobbyStateReadyingUp {
		return helpers.NewTPError("Lobby hasn't been filled up yet.", 4)
	}

	tperr = lobby.ReadyPlayer(player)

	if tperr != nil {
		return tperr
	}

	if lobby.IsEveryoneReady() {
		lobby.Start()

		hooks.BroadcastLobbyStart(lobby)
		models.BroadcastLobbyList()
	}

	return chelpers.EmptySuccessJS
}