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

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

Fixes

File size: 2.3 KB
RevLine 
[83]1using System;
2using System.Collections.Generic;
3
[130]4namespace AllocsFixes.CustomCommands
[83]5{
[130]6 public class SayToPlayer : ConsoleCommand
[83]7 {
[130]8 public SayToPlayer (ConsoleSdtd cons) : base(cons)
9 {
10 }
[83]11
[130]12 public override string Description ()
13 {
14 return "send a message to a single player";
15 }
[83]16
[130]17 public override string[] Names ()
18 {
19 return new string[] { "sayplayer", "pm" };
20 }
[83]21
[130]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,
[108]32 new object[] {
33 _message,
34 -1,
35 senderName + " (PM)",
36 true
37 }
[130]38 );
39 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver);
40 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\"");
[83]41 }
42
[130]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 }
[83]49
[130]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 }
[103]61 }
62
[130]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 }
[83]72 }
[103]73
[130]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 }
[103]81 }
82 }
[83]83}
Note: See TracBrowser for help on using the repository browser.