source: binary-improvements/AllocsCommands/Commands/SayToPlayer.cs@ 224

Last change on this file since 224 was 224, checked in by alloc, 10 years ago

A11 preps

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