forked from PapaCharlie9/procon-basic-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicPlugin.cs
242 lines (168 loc) · 5.45 KB
/
BasicPlugin.cs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* BasicPlugin.cs
Free to use as is in any way you want with no warranty.
*/
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Collections;
using System.Net;
using System.Web;
using System.Data;
using System.Threading;
using System.Timers;
using System.Diagnostics;
using System.Reflection;
using PRoCon.Core;
using PRoCon.Core.Plugin;
using PRoCon.Core.Plugin.Commands;
using PRoCon.Core.Players;
using PRoCon.Core.Players.Items;
using PRoCon.Core.Battlemap;
using PRoCon.Core.Maps;
namespace PRoConEvents
{
//Aliases
using EventType = PRoCon.Core.Events.EventType;
using CapturableEvent = PRoCon.Core.Events.CapturableEvents;
public class BasicPlugin : PRoConPluginAPI, IPRoConPluginInterface
{
/* Inherited:
this.PunkbusterPlayerInfoList = new Dictionary<String, CPunkbusterInfo>();
this.FrostbitePlayerInfoList = new Dictionary<String, CPlayerInfo>();
*/
private bool fIsEnabled;
private int fDebugLevel;
public BasicPlugin() {
fIsEnabled = false;
fDebugLevel = 2;
}
public enum MessageType { Warning, Error, Exception, Normal };
public String FormatMessage(String msg, MessageType type) {
String prefix = "[^b" + GetPluginName() + "^n] ";
if (type.Equals(MessageType.Warning))
prefix += "^1^bWARNING^0^n: ";
else if (type.Equals(MessageType.Error))
prefix += "^1^bERROR^0^n: ";
else if (type.Equals(MessageType.Exception))
prefix += "^1^bEXCEPTION^0^n: ";
return prefix + msg;
}
public void LogWrite(String msg)
{
this.ExecuteCommand("procon.protected.pluginconsole.write", msg);
}
public void ConsoleWrite(String msg, MessageType type)
{
LogWrite(FormatMessage(msg, type));
}
public void ConsoleWrite(String msg)
{
ConsoleWrite(msg, MessageType.Normal);
}
public void ConsoleWarn(String msg)
{
ConsoleWrite(msg, MessageType.Warning);
}
public void ConsoleError(String msg)
{
ConsoleWrite(msg, MessageType.Error);
}
public void ConsoleException(String msg)
{
ConsoleWrite(msg, MessageType.Exception);
}
public void DebugWrite(String msg, int level)
{
if (fDebugLevel >= level) ConsoleWrite(msg, MessageType.Normal);
}
public void ServerCommand(params String[] args)
{
List<String> list = new List<String>();
list.Add("procon.protected.send");
list.AddRange(args);
this.ExecuteCommand(list.ToArray());
}
public String GetPluginName() {
return "BasicPlugin";
}
public String GetPluginVersion() {
return "0.0.0.1";
}
public String GetPluginAuthor() {
return "PapaCharlie9";
}
public String GetPluginWebsite() {
return "TBD";
}
public String GetPluginDescription() {
return @"
<h1>Your Title Here</h1>
<p>TBD</p>
<h2>Description</h2>
<p>TBD</p>
<h2>Commands</h2>
<p>TBD</p>
<h2>Settings</h2>
<p>TBD</p>
<h2>Development</h2>
<p>TBD</p>
<h3>Changelog</h3>
<blockquote><h4>1.0.0.0 (15-SEP-2012)</h4>
- initial version<br/>
</blockquote>
";
}
public List<CPluginVariable> GetDisplayPluginVariables() {
List<CPluginVariable> lstReturn = new List<CPluginVariable>();
lstReturn.Add(new CPluginVariable("Settings|Debug level", fDebugLevel.GetType(), fDebugLevel));
return lstReturn;
}
public List<CPluginVariable> GetPluginVariables() {
return GetDisplayPluginVariables();
}
public void SetPluginVariable(String strVariable, String strValue) {
if (Regex.Match(strVariable, @"Debug level").Success) {
int tmp = 2;
int.TryParse(strValue, out tmp);
fDebugLevel = tmp;
}
}
public void OnPluginLoaded(String strHostName, String strPort, String strPRoConVersion) {
this.RegisterEvents(this.GetType().Name, "OnVersion", "OnServerInfo", "OnResponseError", "OnListPlayers", "OnPlayerJoin", "OnPlayerLeft", "OnPlayerKilled", "OnPlayerSpawned", "OnPlayerTeamChange", "OnGlobalChat", "OnTeamChat", "OnSquadChat", "OnRoundOverPlayers", "OnRoundOver", "OnRoundOverTeamScores", "OnLoadingLevel", "OnLevelStarted", "OnLevelLoaded");
}
public void OnPluginEnable() {
fIsEnabled = true;
ConsoleWrite("Enabled!");
}
public void OnPluginDisable() {
fIsEnabled = false;
ConsoleWrite("Disabled!");
}
public override void OnVersion(String serverType, String version) { }
public override void OnServerInfo(CServerInfo serverInfo) {
ConsoleWrite("Debug level = " + fDebugLevel);
}
public override void OnResponseError(List<String> requestWords, String error) { }
public override void OnListPlayers(List<CPlayerInfo> players, CPlayerSubset subset) {
}
public override void OnPlayerJoin(String soldierName) {
}
public override void OnPlayerLeft(CPlayerInfo playerInfo) {
}
public override void OnPlayerKilled(Kill kKillerVictimDetails) { }
public override void OnPlayerSpawned(String soldierName, Inventory spawnedInventory) { }
public override void OnPlayerTeamChange(String soldierName, int teamId, int squadId) { }
public override void OnGlobalChat(String speaker, String message) { }
public override void OnTeamChat(String speaker, String message, int teamId) { }
public override void OnSquadChat(String speaker, String message, int teamId, int squadId) { }
public override void OnRoundOverPlayers(List<CPlayerInfo> players) { }
public override void OnRoundOverTeamScores(List<TeamScore> teamScores) { }
public override void OnRoundOver(int winningTeamId) { }
public override void OnLoadingLevel(String mapFileName, int roundsPlayed, int roundsTotal) { }
public override void OnLevelStarted() { }
public override void OnLevelLoaded(String mapFileName, String Gamemode, int roundsPlayed, int roundsTotal) { } // BF3
} // end BasicPlugin
} // end namespace PRoConEvents