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

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

fixes

File size: 2.0 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
[103]20 private void SendMessage (ClientInfo _receiver, string _sender, string _message)
[83]21 {
[103]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 {
[83]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
[103]40 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0]);
41 if (ci != null) {
42 SendMessage (ci, _sender, message);
[83]43 } else {
[103]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);
[83]55 }
[103]56 RunInternal (_sender, _params);
57 } catch (Exception e) {
58 Log.Out ("Error in SayToPlayer.ExecuteRemote: " + e);
[83]59 }
60 }
[103]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 }
[83]70}
71
Note: See TracBrowser for help on using the repository browser.