source: TFP-WebServer/CommandExtensions/src/Commands/TestLogSpam.cs@ 452

Last change on this file since 452 was 405, checked in by alloc, 21 months ago

Refactored console commands for A21 caching

File size: 2.1 KB
Line 
1using System.Collections;
2using System.Collections.Generic;
3using JetBrains.Annotations;
4using UnityEngine;
5
6namespace CommandExtensions.Commands {
7 [UsedImplicitly]
8 public class TestLogSpam : ConsoleCmdAbstract {
9 protected override string[] getCommands () {
10 return new[] { "tls" };
11 }
12
13 public override bool AllowedInMainMenu => true;
14
15 public override bool IsExecuteOnClient => true;
16
17 protected override string getDescription () {
18 return "Spams the log with until stopped";
19 }
20
21 protected override string getHelp () {
22 return @"
23 |Usage:
24 | 1. tls <N> ['second']
25 | 2. tls stop
26 |1. Start spamming with N messages per frame - or per second if the second argument is the word 'second'
27 |2. Stop spamming
28 ".Unindent ();
29 }
30
31 private Coroutine spamCoroutine;
32 private WaitForSeconds waitObj;
33
34 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
35 if (_params.Count != 1 && _params.Count != 2) {
36 SdtdConsole.Instance.Output ($"Wrong number of arguments, expected 1 or 2, found {_params.Count}.");
37 return;
38 }
39
40 if (_params [0].EqualsCaseInsensitive ("stop")) {
41 if (spamCoroutine == null) {
42 SdtdConsole.Instance.Output ("Not spamming.");
43 return;
44 }
45
46 ThreadManager.StopCoroutine (spamCoroutine);
47 spamCoroutine = null;
48 SdtdConsole.Instance.Output ("Spam stopped.");
49 return;
50 }
51
52 if (!int.TryParse (_params [0], out int count)) {
53 SdtdConsole.Instance.Output ("The given spam number is not a valid integer");
54 return;
55 }
56
57 bool perSecond = _params.Count > 1 && _params [1] == "second";
58
59 waitObj = perSecond ? new WaitForSeconds (1f) : null;
60
61 SdtdConsole.Instance.Output ($"Started spamming {count} messages per {(perSecond ? "second" : "frame")}");
62 spamCoroutine = ThreadManager.StartCoroutine (SpamCo (count));
63 }
64
65 private IEnumerator SpamCo (int _count) {
66 do {
67 for (int i = 0; i < _count; i++) {
68 Log.Out ("This is a spam log message.");
69 }
70
71 yield return waitObj;
72 } while (spamCoroutine != null);
73 }
74 }
75}
Note: See TracBrowser for help on using the repository browser.