/
yaseeeeechka
/
CenterControl
Обзор
Документация
Войти
/
yaseeeeechka
/
CenterControl
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CenterControl_TCP/include/server/Utils.h
76 строк
2 KB
Yaroslava
New structure of Repo. TCP impl
11 дек 2025, 21:12
11 дек 2025, 21:12
6fdf9d7
Код
Авторство
О чём код?
#ifndef CENTERCONTROL_UTILS_H #define CENTERCONTROL_UTILS_H static std::pair<float, float> GetSpawnCoords(SpawnLocation spawn) { float x = 0.f; float y = 0.f; switch (spawn) { case SpawnLocation::Bottom: { x = kFieldWidth * 0.5f; y = kFieldHeight - kHeightUpToBottom - 5.0f; break; } case SpawnLocation::Left: { x = 5.0f; y = (kFieldHeight - kHeightUpToBottom) * 0.5f; break; } case SpawnLocation::Top: { x = kFieldWidth * 0.5f; y = 5.0f; break; } case SpawnLocation::Right: { x = kFieldWidth - 5.0f; y = (kFieldHeight - kHeightUpToBottom) * 0.5f; break; } } // кламп в границах поля x = std::clamp(x, kMinX, kMaxX); y = std::clamp(y, kMinY, kMaxY); return {x, y}; } inline uint8_t SpawnLocationToIndex(SpawnLocation s) { return static_cast<uint8_t>(s); } static bool sendAll(SOCKET s, const char *data, size_t len) { size_t sent = 0; while (sent < len) { int n = ::send(s, data + sent, static_cast<int>(len - sent), 0); if (n == SOCKET_ERROR || n == 0) return false; sent += static_cast<size_t>(n); } return true; } std::string ToLowerCopy(const std::string &str) { std::string tmp_str{str}; for (char &symbol: tmp_str) { symbol = static_cast<char>(std::tolower(static_cast<unsigned char>(symbol))); } return tmp_str; } void TrimCR(std::string &s) { if (!s.empty() && s.back() == '\r') { s.pop_back(); } } static std::string NormalizeUsername(std::string s) { // trim s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); // tolower std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return (char) std::tolower((unsigned char) c); }); return s; } #endif //CENTERCONTROL_UTILS_H