Fix names (issue)
This commit is contained in:
parent
4ebf3849ab
commit
47c874d2b4
@ -8,6 +8,8 @@ namespace Components
|
|||||||
Colors();
|
Colors();
|
||||||
const char* GetName() { return "Colors"; };
|
const char* GetName() { return "Colors"; };
|
||||||
|
|
||||||
|
static void Strip(const char* in, char* out, int max);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Dvar::Var NewColors;
|
static Dvar::Var NewColors;
|
||||||
|
|
||||||
@ -15,7 +17,5 @@ namespace Components
|
|||||||
static char* GetClientName(int localClientNum, int index, char *buf, size_t size);
|
static char* GetClientName(int localClientNum, int index, char *buf, size_t size);
|
||||||
|
|
||||||
static void UpdateColorTable();
|
static void UpdateColorTable();
|
||||||
|
|
||||||
static void Strip(const char* in, char* out, int max);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,29 @@ namespace Components
|
|||||||
{
|
{
|
||||||
// TODO: Register string dvars here
|
// TODO: Register string dvars here
|
||||||
|
|
||||||
|
// Name watcher
|
||||||
|
Renderer::OnFrame([] ()
|
||||||
|
{
|
||||||
|
static std::string lastValidName = "Unknown Soldier";
|
||||||
|
std::string name = Dvar::Var("name").Get<char*>();
|
||||||
|
|
||||||
|
// Don't perform any checks if name didn't change
|
||||||
|
if (name == lastValidName) return;
|
||||||
|
|
||||||
|
char saneName[64] = { 0 };
|
||||||
|
Colors::Strip(Utils::Trim(name).data(), saneName, sizeof(saneName));
|
||||||
|
|
||||||
|
if (strlen(saneName) < 3 || (saneName[0] == '[' && saneName[1] == '{'))
|
||||||
|
{
|
||||||
|
Logger::Print("Username '%s' is invalid. It must at least be 3 characters long and not appear empty!\n", name.data());
|
||||||
|
Dvar::Var("name").Set(lastValidName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastValidName = name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return Dvar::Register<const char*>(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).Get<Game::dvar_t*>();
|
return Dvar::Register<const char*>(name, "Unknown Soldier", Dvar::Flag(flag | Game::dvar_flag::DVAR_FLAG_SAVED).val, description).Get<Game::dvar_t*>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <cctype>
|
||||||
|
#include <locale>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -77,6 +77,26 @@ namespace Utils
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trim from start
|
||||||
|
std::string <rim(std::string &s)
|
||||||
|
{
|
||||||
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim from end
|
||||||
|
std::string &RTrim(std::string &s)
|
||||||
|
{
|
||||||
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim from both ends
|
||||||
|
std::string &Trim(std::string &s)
|
||||||
|
{
|
||||||
|
return LTrim(RTrim(s));
|
||||||
|
}
|
||||||
|
|
||||||
// Infostring class
|
// Infostring class
|
||||||
void InfoString::Set(std::string key, std::string value)
|
void InfoString::Set(std::string key, std::string value)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,9 @@ namespace Utils
|
|||||||
std::vector<std::string> Explode(const std::string& str, char delim);
|
std::vector<std::string> Explode(const std::string& str, char delim);
|
||||||
void Replace(std::string &string, std::string find, std::string replace);
|
void Replace(std::string &string, std::string find, std::string replace);
|
||||||
unsigned int OneAtATime(char *key, size_t len);
|
unsigned int OneAtATime(char *key, size_t len);
|
||||||
|
std::string <rim(std::string &s);
|
||||||
|
std::string &RTrim(std::string &s);
|
||||||
|
std::string &Trim(std::string &s);
|
||||||
|
|
||||||
class InfoString
|
class InfoString
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user