Esempio n. 1
0
func (Player) PlayerReady(so *wsevent.Client, _ struct{}) interface{} {
	player := chelpers.GetPlayer(so.Token)
	lobbyid, tperr := player.GetLobbyID(false)
	if tperr != nil {
		return tperr
	}

	lob, err := lobby.GetLobbyByIDServer(lobbyid)
	if err != nil {
		return err
	}

	if lob.State != lobby.ReadyingUp {
		return errors.New("Lobby hasn't been filled up yet.")
	}

	err = lob.ReadyPlayer(player)

	if err != nil {
		return err
	}

	if lob.IsEveryoneReady() {
		lob.Start()

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

	return emptySuccess
}
Esempio n. 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
}
Esempio n. 3
0
func playerChat(lobbyID uint, steamID string, message string) {
	lobby, _ := lobbypackage.GetLobbyByIDServer(lobbyID)
	player, _ := playerpackage.GetPlayerBySteamID(steamID)

	chatMessage := chat.NewInGameChatMessage(lobby.ID, player, message)
	chatMessage.Save()
	chatMessage.Send()
}
Esempio n. 4
0
func disconnectedFromServer(lobbyID uint) {
	lobby, err := lobbypackage.GetLobbyByIDServer(lobbyID)
	if err != nil {
		logrus.Error("Couldn't find lobby ", lobbyID, " in database")
		return
	}

	lobby.Close(false, false)
	chat.SendNotification("Lobby Closed (Connection to server lost)", int(lobby.ID))
}
Esempio n. 5
0
func matchEnded(lobbyID uint, logsID int) {
	lobby, err := lobbypackage.GetLobbyByIDServer(lobbyID)
	if err != nil {
		logrus.Error(err)
		return
	}
	lobby.Close(false, true)

	logs := fmt.Sprintf("http://logs.tf/%d", logsID)
	msg := fmt.Sprintf("Lobby Ended. Logs: %s", logs)
	chat.SendNotification(msg, int(lobby.ID))

	room := fmt.Sprintf("%d_private", lobby.ID)
	broadcaster.SendMessageToRoom(room, "lobbyLogs", struct {
		LobbyID uint   `json:"lobbyID"`
		Logs    string `json:"logs"`
	}{lobby.ID, logs})

	lobby.UpdateHours(logsID)
}