Ejemplo n.º 1
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.º 2
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.º 3
0
func (Chat) ChatDelete(so *wsevent.Client, args struct {
	ID   *int  `json:"id"`
	Room *uint `json:"room"`
}) interface{} {

	if err := chelpers.CheckPrivilege(so, helpers.ActionDeleteChat); err != nil {
		return err
	}

	message := &models.ChatMessage{}
	err := db.DB.Table("chat_messages").Where("room = ? AND id = ?", args.Room, args.ID).First(message).Error
	if message.Bot {
		return helpers.NewTPError("Cannot delete notification messages", -1)
	}
	if err != nil {
		return helpers.NewTPError("Can't find message", -1)
	}

	player, _ := models.GetPlayerByID(message.PlayerID)
	message.Deleted = true
	message.Timestamp = message.CreatedAt.Unix()
	message.Save()
	message.Message = "<deleted>"
	message.Player = models.DecoratePlayerSummary(player)
	message.Player.Tags = append(message.Player.Tags, "deleted")
	message.Send()

	return chelpers.EmptySuccessJS
}
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 (Chat) ChatSend(so *wsevent.Client, args struct {
	Message *string `json:"message"`
	Room    *int    `json:"room"`
}) interface{} {

	playerID := chelpers.GetPlayerID(so.ID)
	now := time.Now().Unix()
	if now-lastChatTime[playerID] == 0 {
		return helpers.NewTPError("You're sending messages too quickly", -1)
	}

	lastChatTime[playerID] = now
	player, _ := models.GetPlayerByID(playerID)

	//logrus.Debug("received chat message: %s %s", *args.Message, player.Name)

	if *args.Room > 0 {
		var count int
		spec := player.IsSpectatingID(uint(*args.Room))
		//Check if player has either joined, or is spectating lobby
		db.DB.Table("lobby_slots").Where("lobby_id = ? AND player_id = ?", *args.Room, player.ID).Count(&count)

		if !spec && count == 0 {
			return helpers.NewTPError("Player is not in the lobby.", 5)
		}
	} else {
		// else room is the lobby list room
		*args.Room, _ = strconv.Atoi(config.GlobalChatRoom)
	}
	switch {
	case len(*args.Message) == 0:
		return helpers.NewTPError("Cannot send an empty message", 4)

	case (*args.Message)[0] == '\n':
		return helpers.NewTPError("Cannot send messages prefixed with newline", 4)

	case len(*args.Message) > 150:
		return helpers.NewTPError("Message too long", 4)
	}

	message := models.NewChatMessage(*args.Message, *args.Room, player)
	message.Save()

	if strings.HasPrefix(*args.Message, "!admin") {
		chelpers.SendToSlack(*args.Message, player.Name, player.SteamID)
		return chelpers.EmptySuccessJS
	}

	message.Send()

	return chelpers.EmptySuccessJS
}
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)
		}
	})
}
Ejemplo n.º 7
0
func DisplayLogs(w http.ResponseWriter, r *http.Request) {
	allBans := models.GetAllActiveBans()
	var bans []BanData

	templ, err := template.ParseFiles("views/admin/templates/ban_logs.html")
	if err != nil {
		logrus.Error(err.Error())
		return
	}

	for _, ban := range allBans {
		player, _ := models.GetPlayerByID(ban.PlayerID)
		banData := BanData{
			Player:  player,
			BanName: fmt.Sprintf("Banned from %s", banString[ban.Type]),
			Ban:     ban}

		bans = append(bans, banData)
	}

	templ.Execute(w, bans)
}
Ejemplo n.º 8
0
func GetPlayerFromSocket(socketid string) *models.Player {
	id := GetPlayerID(socketid)
	player, _ := models.GetPlayerByID(id)
	return player
}