forked from Mirrors/openclonk
Move GUI code from C4InputValidation to C4GonfigShareware
That way, C4InputValidation can be used by C4Group as is.stable-5.2
parent
7fe7e557e0
commit
fb249aafcd
|
@ -46,9 +46,6 @@ namespace C4InVal
|
||||||
bool ValidateInt(int32_t &riVal, int32_t iMinVal, int32_t iMaxVal);
|
bool ValidateInt(int32_t &riVal, int32_t iMinVal, int32_t iMaxVal);
|
||||||
|
|
||||||
inline bool ValidateFilename(char *szFilename, size_t iMaxSize=_MAX_PATH) { return ValidateString(szFilename, VAL_Filename, iMaxSize); }
|
inline bool ValidateFilename(char *szFilename, size_t iMaxSize=_MAX_PATH) { return ValidateString(szFilename, VAL_Filename, iMaxSize); }
|
||||||
|
|
||||||
// checks for phising attacks: Return true if input contains user's webcode
|
|
||||||
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validation adapter: Call ValidateString on string after compiling it
|
// Validation adapter: Call ValidateString on string after compiling it
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <C4ConfigShareware.h>
|
#include <C4ConfigShareware.h>
|
||||||
#include <C4SecurityCertificates.h>
|
#include <C4SecurityCertificates.h>
|
||||||
#include <C4Log.h>
|
#include <C4Log.h>
|
||||||
|
#include <C4Gui.h>
|
||||||
|
|
||||||
#include <StdFile.h>
|
#include <StdFile.h>
|
||||||
|
|
||||||
|
@ -484,3 +485,21 @@ void C4ConfigShareware::ClearRegistrationError()
|
||||||
// Reset error message(s)
|
// Reset error message(s)
|
||||||
RegistrationError.Clear();
|
RegistrationError.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool C4ConfigShareware::IsConfidentialData(const char *szInput, bool fShowWarningMessage)
|
||||||
|
{
|
||||||
|
// safety
|
||||||
|
if (!szInput) return false;
|
||||||
|
// unreg users don't have confidential data
|
||||||
|
if (!Config.Registered()) return false;
|
||||||
|
// shouldn't send the webcode!
|
||||||
|
const char *szWebCode = GetRegistrationData("WebCode");
|
||||||
|
if (szWebCode && *szWebCode) if (SSearchNoCase(szInput, szWebCode))
|
||||||
|
{
|
||||||
|
if (fShowWarningMessage && ::pGUI)
|
||||||
|
::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// all OK
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ class C4ConfigShareware: public C4Config
|
||||||
const char* GetInvalidKeyFilename();
|
const char* GetInvalidKeyFilename();
|
||||||
const char* GetKeyPath();
|
const char* GetKeyPath();
|
||||||
StdStrBuf GetKeyMD5();
|
StdStrBuf GetKeyMD5();
|
||||||
|
// checks for phising attacks: Return true if input contains user's webcode
|
||||||
|
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage);
|
||||||
protected:
|
protected:
|
||||||
StdStrBuf RegistrationError;
|
StdStrBuf RegistrationError;
|
||||||
bool HandleError(const char *strMessage);
|
bool HandleError(const char *strMessage);
|
||||||
|
|
|
@ -836,7 +836,7 @@ bool C4ChatControl::ProcessInput(const char *szInput, ChatSheet *pChatSheet)
|
||||||
// safety
|
// safety
|
||||||
if (!szInput || !*szInput || !pChatSheet) return fResult;
|
if (!szInput || !*szInput || !pChatSheet) return fResult;
|
||||||
// check confidential data
|
// check confidential data
|
||||||
if (C4InVal::IsConfidentialData(szInput, true)) return fResult;
|
if (Config.IsConfidentialData(szInput, true)) return fResult;
|
||||||
// command?
|
// command?
|
||||||
if (*szInput == '/' && !SEqual2NoCase(szInput + 1, "me "))
|
if (*szInput == '/' && !SEqual2NoCase(szInput + 1, "me "))
|
||||||
{
|
{
|
||||||
|
|
|
@ -449,7 +449,7 @@ C4GUI::Edit::InputResult MainDlg::OnChatInput(C4GUI::Edit *edt, bool fPasting, b
|
||||||
::MessageInput.StoreBackBuffer(szInputText);
|
::MessageInput.StoreBackBuffer(szInputText);
|
||||||
bool fProcessed = false;
|
bool fProcessed = false;
|
||||||
// check confidential data
|
// check confidential data
|
||||||
if (C4InVal::IsConfidentialData(szInputText, true)) fProcessed = true;
|
if (Config.IsConfidentialData(szInputText, true)) fProcessed = true;
|
||||||
// CAUTION when implementing special commands (like /quit) here:
|
// CAUTION when implementing special commands (like /quit) here:
|
||||||
// those must not be executed when text is pasted, because that could crash the GUI system
|
// those must not be executed when text is pasted, because that could crash the GUI system
|
||||||
// when there are additional lines to paste, but the edit field is destructed by the command
|
// when there are additional lines to paste, but the edit field is destructed by the command
|
||||||
|
|
|
@ -23,10 +23,6 @@
|
||||||
#include <C4Log.h>
|
#include <C4Log.h>
|
||||||
#include <C4Config.h>
|
#include <C4Config.h>
|
||||||
|
|
||||||
#ifdef C4ENGINE
|
|
||||||
// FIXME: One should not have to include C4Game.h for pGUI
|
|
||||||
#include <C4Game.h>
|
|
||||||
#endif
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
namespace C4InVal
|
namespace C4InVal
|
||||||
|
@ -178,26 +174,4 @@ namespace C4InVal
|
||||||
else if (riVal > iMaxVal) { riVal = iMaxVal; return false; }
|
else if (riVal > iMaxVal) { riVal = iMaxVal; return false; }
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage)
|
|
||||||
{
|
|
||||||
// safety
|
|
||||||
if (!szInput) return false;
|
|
||||||
#ifdef C4ENGINE
|
|
||||||
// unreg users don't have confidential data
|
|
||||||
if (!Config.Registered()) return false;
|
|
||||||
// shouldn't send the webcode!
|
|
||||||
const char *szWebCode = Config.GetRegistrationData("WebCode");
|
|
||||||
if (szWebCode && *szWebCode) if (SSearchNoCase(szInput, szWebCode))
|
|
||||||
{
|
|
||||||
if (fShowWarningMessage && ::pGUI)
|
|
||||||
::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN"));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// all OK
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt, bool f
|
||||||
// Store to back buffer
|
// Store to back buffer
|
||||||
::MessageInput.StoreBackBuffer(szInputText);
|
::MessageInput.StoreBackBuffer(szInputText);
|
||||||
// check confidential data - even for object input (script triggered), webcode should not be pasted here
|
// check confidential data - even for object input (script triggered), webcode should not be pasted here
|
||||||
if (C4InVal::IsConfidentialData(szInputText, true))
|
if (Config.IsConfidentialData(szInputText, true))
|
||||||
{
|
{
|
||||||
szInputText = "";
|
szInputText = "";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue