1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | public class SayToPlayer : ConsoleCommand
|
---|
5 | {
|
---|
6 | public SayToPlayer (ConsoleSdtd cons) : base(cons)
|
---|
7 | {
|
---|
8 | }
|
---|
9 |
|
---|
10 | public override string Description ()
|
---|
11 | {
|
---|
12 | return "send a message to a single player";
|
---|
13 | }
|
---|
14 |
|
---|
15 | public override string[] Names ()
|
---|
16 | {
|
---|
17 | return new string[] { "sayplayer", "pm" };
|
---|
18 | }
|
---|
19 |
|
---|
20 | private void SendMessage (ClientInfo _receiver, string _sender, string _message)
|
---|
21 | {
|
---|
22 | CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,
|
---|
23 | new object[] { _message, -1, _sender + " (PM)", true });
|
---|
24 | string receiverName = CommonMappingFunctions.GetPlayerName (_receiver);
|
---|
25 | m_Console.md000a ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + _sender + "\"");
|
---|
26 | }
|
---|
27 |
|
---|
28 | private void RunInternal (string _sender, string[] _params)
|
---|
29 | {
|
---|
30 | if (_params.Length < 2) {
|
---|
31 | m_Console.md000a ("Usage: sayplayer <playername|entityid> <message>");
|
---|
32 | return;
|
---|
33 | }
|
---|
34 |
|
---|
35 | string message = _params [1];
|
---|
36 | for (int i = 2; i < _params.Length; i++) {
|
---|
37 | message += " " + _params [i];
|
---|
38 | }
|
---|
39 |
|
---|
40 | ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0]);
|
---|
41 | if (ci != null) {
|
---|
42 | SendMessage (ci, _sender, message);
|
---|
43 | } else {
|
---|
44 | m_Console.md000a ("Playername or entity ID not found.");
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public override void ExecuteRemote (string _sender, string[] _params)
|
---|
49 | {
|
---|
50 | try {
|
---|
51 | this.m_Console.md000a (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params)));
|
---|
52 | ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender);
|
---|
53 | if (ci != null) {
|
---|
54 | _sender = CommonMappingFunctions.GetPlayerName (ci);
|
---|
55 | }
|
---|
56 | RunInternal (_sender, _params);
|
---|
57 | } catch (Exception e) {
|
---|
58 | Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override void Run (string[] _params)
|
---|
63 | {
|
---|
64 | try {
|
---|
65 | RunInternal ("Server", _params);
|
---|
66 | } catch (Exception e) {
|
---|
67 | Log.Out ("Error in SayToPlayer.Run: " + e);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|