source: binary-improvements/7dtd-server-fixes/src/CustomCommands/SayToPlayer.cs@ 145

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

Fixes

File size: 2.3 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 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,
32 new object[] {
33 _message,
34 -1,
35 senderName + " (PM)",
36 true
37 }
38 );
39 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver);
40 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\"");
41 }
42
43 private void RunInternal (ClientInfo _sender, string[] _params)
44 {
45 if (_params.Length < 2) {
46 m_Console.SendResult ("Usage: sayplayer <playername|entityid> <message>");
47 return;
48 }
49
50 string message = _params [1];
51 for (int i = 2; i < _params.Length; i++) {
52 message += " " + _params [i];
53 }
54
55 ClientInfo receiver = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true);
56 if (receiver != null) {
57 SendMessage (receiver, _sender, message);
58 } else {
59 m_Console.SendResult ("Playername or entity ID not found.");
60 }
61 }
62
63 public override void ExecuteRemote (string _sender, string[] _params)
64 {
65 try {
66 this.m_Console.SendResult (string.Format ("{0} executing remote command '{1}' {2}", _sender, this.Names () [0], string.Join (" ", _params)));
67 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_sender);
68 RunInternal (ci, _params);
69 } catch (Exception e) {
70 Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e);
71 }
72 }
73
74 public override void Run (string[] _params)
75 {
76 try {
77 RunInternal (null, _params);
78 } catch (Exception e) {
79 Log.Out ("Error in SayToPlayer.Run: " + e);
80 }
81 }
82 }
83}
Note: See TracBrowser for help on using the repository browser.