This is a fork of Zandronum Beta for TSPG.
Revision | 7e0a46587fd030775105391f24817f60e52d701c (tree) |
---|---|
Time | 2021-12-13 07:55:44 |
Author | Joshua Surace <doomjoshuaboy@live...> |
Commiter | Joshua Surace |
Fixed the time load for badwords to 10 minutes instead of 2 seconds
@@ -26,48 +26,48 @@ | ||
26 | 26 | |
27 | 27 | #define badwords_Print(fmt, ...) \ |
28 | 28 | if (tspg_badwords_debug) { \ |
29 | - Printf(fmt, ##__VA_ARGS__); \ | |
30 | - } | |
31 | - | |
32 | -enum class BadWordType | |
33 | -{ | |
34 | - Word, | |
35 | - Includes | |
36 | -}; | |
37 | - | |
38 | -struct BadWordEntry | |
39 | -{ | |
40 | - BadWordType type; | |
41 | - FString word; | |
42 | -}; | |
29 | + Printf(fmt, ##__VA_ARGS__); \ | |
30 | + } | |
31 | + | |
32 | +enum class BadWordType | |
33 | +{ | |
34 | + Word, | |
35 | + Includes | |
36 | +}; | |
37 | + | |
38 | +struct BadWordEntry | |
39 | +{ | |
40 | + BadWordType type; | |
41 | + FString word; | |
42 | +}; | |
43 | 43 | |
44 | 44 | CVAR(String, tspg_badwordsfile, "", TSPG_NOSET); |
45 | 45 | CVAR(Bool, tspg_badwords_debug, false, TSPG_NOSET); |
46 | -CUSTOM_CVAR(Int, tspg_badwordsreloadtime, 2, TSPG_NOSET) | |
46 | +CUSTOM_CVAR(Int, tspg_badwordsreloadtime, 600, TSPG_NOSET) | |
47 | 47 | { |
48 | 48 | if (self.GetGenericRep(CVAR_Int).Int < 1) |
49 | 49 | self = 1; |
50 | 50 | } |
51 | 51 | |
52 | -CUSTOM_CVAR(Bool, tspg_badwordsenabled, false, TSPG_NOSET) | |
52 | +CUSTOM_CVAR(Bool, tspg_badwordsenabled, false, TSPG_NOSET) | |
53 | 53 | { |
54 | 54 | if (self) |
55 | - BADWORDS_Init(); | |
55 | + BADWORDS_Init(); | |
56 | 56 | else |
57 | 57 | BADWORDS_Shutdown(); |
58 | -} | |
59 | - | |
60 | -static TArray<BadWordEntry> BadWords; | |
61 | - | |
58 | +} | |
59 | + | |
60 | +static TArray<BadWordEntry> BadWords; | |
61 | + | |
62 | 62 | static bool badwords_Load(); |
63 | 63 | static bool badwords_LoadFile(const char *filename, const char *includedFrom = nullptr, int includeLine = -1); |
64 | -static void badwords_Clear(); | |
64 | +static void badwords_Clear(); | |
65 | 65 | static bool badwords_CheckStringEquals(FString text); |
66 | 66 | static bool badwords_CheckStringWords(FString text); |
67 | 67 | static bool badwords_CheckStringIncludes(FString text); |
68 | 68 | |
69 | -static unsigned lastReload = 0; | |
70 | - | |
69 | +static unsigned lastReload = 0; | |
70 | + | |
71 | 71 | void BADWORDS_Init() |
72 | 72 | { |
73 | 73 | if (!tspg_badwordsenabled) |
@@ -82,8 +82,8 @@ | ||
82 | 82 | return; |
83 | 83 | |
84 | 84 | badwords_Clear(); |
85 | -} | |
86 | - | |
85 | +} | |
86 | + | |
87 | 87 | bool badwords_Load() |
88 | 88 | { |
89 | 89 | if (BadWords.Size() > 0) |
@@ -105,8 +105,8 @@ | ||
105 | 105 | lastReload = I_MSTime(); |
106 | 106 | |
107 | 107 | return true; |
108 | -} | |
109 | - | |
108 | +} | |
109 | + | |
110 | 110 | bool badwords_LoadFile(const char *filename, const char *includedFrom, int includeLine) |
111 | 111 | { |
112 | 112 | // check if we can read the file first |
@@ -203,101 +203,101 @@ | ||
203 | 203 | buffer.AppendFormat("%c", c); |
204 | 204 | } |
205 | 205 | |
206 | - // Now check the words | |
207 | - for (size_t i = 0; i < BadWords.Size(); i++) | |
208 | - { | |
209 | - BadWordEntry *entry = &BadWords[i]; | |
210 | - | |
211 | - if (entry->type != BadWordType::Word) | |
212 | - { | |
213 | - continue; | |
214 | - } | |
215 | - | |
216 | - if (entry->word.CompareNoCase(buffer) == 0) | |
206 | + // Now check the words | |
207 | + for (size_t i = 0; i < BadWords.Size(); i++) | |
208 | + { | |
209 | + BadWordEntry *entry = &BadWords[i]; | |
210 | + | |
211 | + if (entry->type != BadWordType::Word) | |
217 | 212 | { |
218 | - badwords_Print("badwords_CheckStringEquals: Got a match for \"%s\".\n", entry->word.GetChars()); | |
219 | - return true; | |
220 | - } | |
213 | + continue; | |
214 | + } | |
215 | + | |
216 | + if (entry->word.CompareNoCase(buffer) == 0) | |
217 | + { | |
218 | + badwords_Print("badwords_CheckStringEquals: Got a match for \"%s\".\n", entry->word.GetChars()); | |
219 | + return true; | |
220 | + } | |
221 | 221 | } |
222 | 222 | |
223 | 223 | return false; |
224 | 224 | } |
225 | - | |
226 | -static bool badwords_CheckStringWords(FString text) | |
227 | -{ | |
228 | - TArray<FString> words; | |
229 | - FString buffer; | |
230 | - | |
231 | - for (size_t i = 0; i < text.Len(); i++) | |
232 | - { | |
233 | - char c = text[i]; | |
234 | - | |
235 | - // If we hit a space, push it to the array | |
236 | - if (c == ' ') | |
237 | - { | |
238 | - if (buffer.Len() >= 1) | |
239 | - { | |
240 | - words.Push(buffer); | |
241 | - buffer = ""; | |
242 | - } | |
243 | - | |
244 | - continue; | |
245 | - } | |
246 | - | |
247 | - // Ignore it if it's not alphanumeric | |
248 | - if (!isalnum(c)) | |
249 | - { | |
250 | - continue; | |
251 | - } | |
252 | - | |
253 | - // Add it to the buffer | |
254 | - buffer.AppendFormat("%c", c); | |
255 | - } | |
256 | - | |
257 | - // Push anything left over in the buffer | |
258 | - if (buffer.Len() >= 1) | |
259 | - { | |
260 | - words.Push(buffer); | |
261 | - buffer = ""; | |
262 | - } | |
263 | - | |
264 | - // Now check the words | |
265 | - for (size_t i = 0; i < BadWords.Size(); i++) { | |
266 | - BadWordEntry *entry = &BadWords[i]; | |
267 | - | |
268 | - if (entry->type != BadWordType::Word) | |
269 | - { | |
270 | - continue; | |
271 | - } | |
272 | - | |
273 | - for (size_t j = 0; j < words.Size(); j++) | |
274 | - { | |
275 | - FString word = words[j]; | |
276 | - | |
277 | - if (entry->word.CompareNoCase(word) == 0) | |
225 | + | |
226 | +static bool badwords_CheckStringWords(FString text) | |
227 | +{ | |
228 | + TArray<FString> words; | |
229 | + FString buffer; | |
230 | + | |
231 | + for (size_t i = 0; i < text.Len(); i++) | |
232 | + { | |
233 | + char c = text[i]; | |
234 | + | |
235 | + // If we hit a space, push it to the array | |
236 | + if (c == ' ') | |
237 | + { | |
238 | + if (buffer.Len() >= 1) | |
278 | 239 | { |
279 | - badwords_Print("badwords_CheckStringWords: Got a match for \"%s\".\n", entry->word.GetChars()); | |
280 | - return true; | |
281 | - } | |
282 | - } | |
283 | - } | |
284 | - | |
285 | - // We found nothing | |
286 | - return false; | |
287 | -} | |
288 | - | |
240 | + words.Push(buffer); | |
241 | + buffer = ""; | |
242 | + } | |
243 | + | |
244 | + continue; | |
245 | + } | |
246 | + | |
247 | + // Ignore it if it's not alphanumeric | |
248 | + if (!isalnum(c)) | |
249 | + { | |
250 | + continue; | |
251 | + } | |
252 | + | |
253 | + // Add it to the buffer | |
254 | + buffer.AppendFormat("%c", c); | |
255 | + } | |
256 | + | |
257 | + // Push anything left over in the buffer | |
258 | + if (buffer.Len() >= 1) | |
259 | + { | |
260 | + words.Push(buffer); | |
261 | + buffer = ""; | |
262 | + } | |
263 | + | |
264 | + // Now check the words | |
265 | + for (size_t i = 0; i < BadWords.Size(); i++) { | |
266 | + BadWordEntry *entry = &BadWords[i]; | |
267 | + | |
268 | + if (entry->type != BadWordType::Word) | |
269 | + { | |
270 | + continue; | |
271 | + } | |
272 | + | |
273 | + for (size_t j = 0; j < words.Size(); j++) | |
274 | + { | |
275 | + FString word = words[j]; | |
276 | + | |
277 | + if (entry->word.CompareNoCase(word) == 0) | |
278 | + { | |
279 | + badwords_Print("badwords_CheckStringWords: Got a match for \"%s\".\n", entry->word.GetChars()); | |
280 | + return true; | |
281 | + } | |
282 | + } | |
283 | + } | |
284 | + | |
285 | + // We found nothing | |
286 | + return false; | |
287 | +} | |
288 | + | |
289 | 289 | bool badwords_CheckStringIncludes(FString text) |
290 | 290 | { |
291 | 291 | FString lowerText(text); |
292 | 292 | lowerText.ToLower(); |
293 | 293 | |
294 | - // Now check the words | |
295 | - for (size_t i = 0; i < BadWords.Size(); i++) { | |
296 | - BadWordEntry *entry = &BadWords[i]; | |
297 | - | |
298 | - if (entry->type != BadWordType::Includes) | |
299 | - { | |
300 | - continue; | |
294 | + // Now check the words | |
295 | + for (size_t i = 0; i < BadWords.Size(); i++) { | |
296 | + BadWordEntry *entry = &BadWords[i]; | |
297 | + | |
298 | + if (entry->type != BadWordType::Includes) | |
299 | + { | |
300 | + continue; | |
301 | 301 | } |
302 | 302 | |
303 | 303 | FString lowerWord(entry->word); |
@@ -307,7 +307,7 @@ | ||
307 | 307 | { |
308 | 308 | badwords_Print("badwords_CheckStringIncludes: Got a match for \"%s\".\n", entry->word.GetChars()); |
309 | 309 | return true; |
310 | - } | |
310 | + } | |
311 | 311 | } |
312 | 312 | |
313 | 313 | return false; |