source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/SayToPlayer.cs@ 121

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

fixes

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