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 playerSub(playerID, lobbyID uint) {
	player, _ := models.GetPlayerByID(playerID)
	lobby, _ := models.GetLobbyByID(lobbyID)
	lobby.Substitute(player)

	models.SendNotification(fmt.Sprintf("%s has been reported.", player.Name), int(lobby.ID))
}
Ejemplo n.º 3
0
func playerConn(playerID, lobbyID uint) {
	player, _ := models.GetPlayerByID(playerID)
	lobby, _ := models.GetLobbyByID(lobbyID)

	lobby.SetInGame(player)
	models.SendNotification(fmt.Sprintf("%s has connected to the server.", player.Alias()), int(lobby.ID))
}
Ejemplo n.º 4
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.º 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 playerDisc(playerID, lobbyID uint) {
	player, _ := models.GetPlayerByID(playerID)
	lobby, _ := models.GetLobbyByID(lobbyID)

	lobby.SetNotInGame(player)

	models.SendNotification(fmt.Sprintf("%s has disconected from the server.", player.Name), int(lobby.ID))
	time.AfterFunc(time.Minute*2, func() {
		ingame, err := lobby.IsPlayerInGame(player)
		if err != nil {
			logrus.Error(err.Error())
		}
		if !ingame && lobby.CurrentState() != models.LobbyStateEnded {
			lobby.Substitute(player)
		}
	})
}