forked from Mik4sa/Procon-1
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSdkTemplatePlugin.Commands.cs
More file actions
93 lines (80 loc) · 3.25 KB
/
SdkTemplatePlugin.Commands.cs
File metadata and controls
93 lines (80 loc) · 3.25 KB
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
/*
* SdkTemplatePlugin — Chat Command Handling (Partial Class)
*
* This file handles all chat-based commands (!help, !info, etc.)
* It's compiled together with SdkTemplatePlugin.cs automatically.
*
* NAMING RULE: The file must be named <ClassName>.<Anything>.cs
* SdkTemplatePlugin.Commands.cs ← This file
* SdkTemplatePlugin.cs ← Main file
*
* Both files share the same class, namespace, and all fields/methods.
*/
using System;
using System.Collections.Generic;
using PRoCon.Core;
using PRoCon.Core.Plugin;
using PRoCon.Core.Players;
namespace PRoConEvents
{
public partial class SdkTemplatePlugin
{
// =====================================================================
// Chat event overrides — route to command handler
// =====================================================================
public override void OnGlobalChat(string speaker, string message)
{
if (!_isEnabled || string.IsNullOrEmpty(message)) return;
HandleChatCommand(speaker, message);
}
public override void OnTeamChat(string speaker, string message, int teamId)
{
if (!_isEnabled || string.IsNullOrEmpty(message)) return;
HandleChatCommand(speaker, message);
}
public override void OnSquadChat(string speaker, string message, int teamId, int squadId)
{
if (!_isEnabled || string.IsNullOrEmpty(message)) return;
HandleChatCommand(speaker, message);
}
// =====================================================================
// Command dispatcher
// =====================================================================
private void HandleChatCommand(string speaker, string message)
{
string cmd = message.Trim().ToLower();
if (cmd == "!help")
{
SayToPlayer(speaker, "Available commands: !help, !info, !stats");
}
else if (cmd == "!info")
{
SayToPlayer(speaker,
string.Format("Server: {0}:{1} | PRoCon {2}", _hostName, _port, _proconVersion));
}
else if (cmd == "!stats")
{
// Example: query database for player stats
// This calls into the Database partial class
string stats = GetPlayerStats(speaker);
SayToPlayer(speaker, stats ?? "No stats found.");
}
}
// =====================================================================
// Chat helpers
// =====================================================================
private void SayToPlayer(string soldierName, string message)
{
ExecuteCommand("procon.protected.send", "admin.say", message, "player", soldierName);
}
private void SayToAll(string message)
{
ExecuteCommand("procon.protected.send", "admin.say", message, "all");
}
private void YellToPlayer(string soldierName, string message, int durationSeconds = 5)
{
ExecuteCommand("procon.protected.send", "admin.yell", message,
durationSeconds.ToString(), "player", soldierName);
}
}
}