|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + * |
| 4 | + * MaNGOS is a full featured server for World of Warcraft, supporting |
| 5 | + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 |
| 6 | + * |
| 7 | + * Copyright (C) 2005-2026 MaNGOS <https://www.getmangos.eu> |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + * World of Warcraft, and all World of Warcraft or Warcraft art, images, |
| 23 | + * and lore are copyrighted by Blizzard Entertainment, Inc. |
| 24 | + */ |
| 25 | + |
| 26 | +#pragma once |
| 27 | + |
| 28 | +#include <cstdarg> |
| 29 | +#include <cstddef> |
| 30 | +#include <cstdio> |
| 31 | +#include <string> |
| 32 | + |
| 33 | +namespace ai |
| 34 | +{ |
| 35 | + constexpr std::size_t PLAYERBOT_LOG_MESSAGE_CAPACITY = 1024; |
| 36 | + |
| 37 | + inline std::string FormatPlayerbotLogMessage(char const* format, va_list args) |
| 38 | + { |
| 39 | + if (!format) |
| 40 | + { |
| 41 | + return std::string(); |
| 42 | + } |
| 43 | + |
| 44 | + char buffer[PLAYERBOT_LOG_MESSAGE_CAPACITY] = {}; |
| 45 | + int const result = std::vsnprintf(buffer, sizeof(buffer), format, args); |
| 46 | + buffer[sizeof(buffer) - 1] = '\0'; |
| 47 | + return result < 0 ? std::string() : std::string(buffer); |
| 48 | + } |
| 49 | + |
| 50 | + inline bool WritePlayerbotLogLine(FILE* file, std::string const& message) |
| 51 | + { |
| 52 | + if (!file || std::fputs(message.c_str(), file) == EOF) |
| 53 | + { |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + return std::fputc('\n', file) != EOF; |
| 58 | + } |
| 59 | +} |
0 commit comments