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

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

fixes

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