-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathCEntryHistory.h
97 lines (75 loc) · 2.88 KB
/
CEntryHistory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: core/CEntryHistory.h
* PURPOSE: Header file for the entry history class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#pragma once
// Used for cleaning sensitive info from entries
struct
{
unsigned int numBlanks;
const char* delim;
const char* text;
} const g_WordsToCheck[] = {{2, "", "login "}, {2, "", "register "}, {2, "", "addaccount "}, {2, "", "chgpass "}, {2, "", "chgmypass "}, {1, "'", "password"}};
class CEntryHistoryItem
{
public:
// Contains the original entry
SString entry;
// Contains the temporary, edited version of the entry
SString temp;
// Contains a clean version of the entry with sensitive info parsed out
SString clean;
CEntryHistoryItem(const SString& entry) { SetContent(entry); }
// Reset the temporary value with the original value
void Reset() { temp = entry; }
void SetContent(SString entry);
bool operator!=(const SString& other) const { return entry != other; }
bool operator==(const SString& other) const { return entry == other; }
operator const char*() const { return entry.c_str(); }
};
class CEntryHistory
{
public:
CEntryHistory(unsigned int historyLength) : m_maxEntries(historyLength) {}
static void CleanLine(SString& line);
static int ReplaceNextWord(SString& line, int pos, const char* blanker);
void Add(SString line);
void LoadFromFile(SString filename);
// Clear all history entries
void Clear() { m_entries.clear(); }
// Check whether history contains a line
bool Contains(const SString& line) const { return std::find(m_entries.begin(), m_entries.end(), line) != m_entries.end(); }
// Return a boolean representing whether the history is empty or not
bool Empty() const { return m_entries.empty(); }
// Return a specific entry from history
CEntryHistoryItem* Get(unsigned int index)
{
auto iter = std::next(m_entries.begin(), index);
if (iter != m_entries.end())
return &(*iter);
return nullptr;
}
// Get the last entry in history
CEntryHistoryItem& GetLast() { return m_entries.front(); }
// Resets temporary history edits to their original values
void ResetChanges()
{
for (auto& item : m_entries)
item.Reset();
}
// Return the size of history
int Size() const { return m_entries.size(); }
private:
// Contains all history entries
std::list<CEntryHistoryItem> m_entries;
// Maximum amount of entries before we start deleting from the end
unsigned int m_maxEntries;
// Output filename to save history to
SString m_outFilename;
};