This site is for P2P development and test software ONLY!

Create a random Modstring

It's placed in Preferences.cpp/.h so it can be called from nearly everwhere when needed.

Preferences.cpp

CString CPreferences::m_strSessionModstring;
CString CPreferences::GetSessionModString()
{
if (!m_strSessionModstring.IsEmpty())
return m_strSessionModstring;
//
// Create the Modname
int i, maxchar;
m_strSessionModstring.Empty();

maxchar = 4+(rand()%9); // min length == 4 chars, max length (4+9-1) == 12 chars
i = 0;
while (i < maxchar) { int iRand = rand()%3; switch(iRand){ case 0: m_strSessionModstring.AppendFormat(_T("%c"), _T('A')+rand()%26); // Capitals case 1: m_strSessionModstring.AppendFormat(_T("%c"), _T('0')+rand()%10); // Numbers case 2: default: m_strSessionModstring.AppendFormat(_T("%c"), _T('a')+rand()%26); // lower case } i++; if (m_strSessionModstring.GetLength() >= maxchar)
break;
}
//
// Add a prefix to the version number
i = rand()%5;
switch (i){
case 0: m_strSessionModstring.Append(_T(" V")); break;
case 1: m_strSessionModstring.Append(_T(" v")); break;
case 2: m_strSessionModstring.Append(_T(" r")); break;
case 3: m_strSessionModstring.Append(_T(" R")); break;
default:
case 4: m_strSessionModstring.Append(_T(" ")); break;
}
//
// Add the version number
m_strSessionModstring.AppendFormat(_T("%c.%c%c"), _T('0')+rand()%10, _T('0')+rand()%10, (rand()%2 ? _T('0')+rand()%10 : _T('a')+rand()%7));
//
// This will return a ModID consisting of ModVersion + 1.00 or 1.0a
return m_strSessionModstring;
}

Preferences.h

static CString m_strSessionModstring;
static CString GetSessionModString();

0 comments:

发表评论