[112] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[130] | 4 | namespace AllocsFixes.CustomCommands
|
---|
[112] | 5 | {
|
---|
[130] | 6 | public class Reply : ConsoleCommand
|
---|
[112] | 7 | {
|
---|
[130] | 8 | public Reply (ConsoleSdtd cons) : base(cons)
|
---|
| 9 | {
|
---|
| 10 | }
|
---|
[112] | 11 |
|
---|
[130] | 12 | public override string Description ()
|
---|
| 13 | {
|
---|
| 14 | return "send a message to the player who last sent you a PM";
|
---|
| 15 | }
|
---|
[112] | 16 |
|
---|
[130] | 17 | public override string[] Names ()
|
---|
| 18 | {
|
---|
| 19 | return new string[] { "reply", "re" };
|
---|
| 20 | }
|
---|
[112] | 21 |
|
---|
[130] | 22 | private void SendMessage (ClientInfo _receiver, ClientInfo _sender, string _message)
|
---|
| 23 | {
|
---|
| 24 | PrivateMassageConnections.SetLastPMSender (_sender, _receiver);
|
---|
| 25 | string senderName = CommonMappingFunctions.GetPlayerName (_sender);
|
---|
[112] | 26 |
|
---|
[130] | 27 | CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,
|
---|
[112] | 28 | new object[] {
|
---|
| 29 | _message,
|
---|
| 30 | -1,
|
---|
| 31 | senderName + " (PM)",
|
---|
| 32 | true
|
---|
| 33 | }
|
---|
[130] | 34 | );
|
---|
| 35 | string receiverName = CommonMappingFunctions.GetPlayerName (_receiver);
|
---|
| 36 | m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\"");
|
---|
[112] | 37 | }
|
---|
| 38 |
|
---|
[130] | 39 | private void RunInternal (ClientInfo _sender, string[] _params)
|
---|
| 40 | {
|
---|
| 41 | if (_params.Length < 1) {
|
---|
| 42 | m_Console.SendResult ("Usage: reply <message>");
|
---|
| 43 | return;
|
---|
| 44 | }
|
---|
[112] | 45 |
|
---|
[130] | 46 | string message = _params [0];
|
---|
| 47 | for (int i = 1; i < _params.Length; i++) {
|
---|
| 48 | message += " " + _params [i];
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | ClientInfo receiver = PrivateMassageConnections.GetLastPMSenderForPlayer (_sender);
|
---|
| 52 | if (receiver != null && CommonMappingFunctions.GetClientID (receiver) >= 0) {
|
---|
| 53 | SendMessage (receiver, _sender, message);
|
---|
[112] | 54 | } else {
|
---|
[130] | 55 | if (receiver != null) {
|
---|
| 56 | m_Console.SendResult ("The sender of the PM you last received is currently not online.");
|
---|
| 57 | } else {
|
---|
| 58 | m_Console.SendResult ("You have not received a PM so far.");
|
---|
| 59 | }
|
---|
[112] | 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[130] | 63 | public override void ExecuteRemote (string _sender, string[] _params)
|
---|
| 64 | {
|
---|
| 65 | try {
|
---|
| 66 | 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 Reply.ExecuteRemote: " + e);
|
---|
| 71 | }
|
---|
[112] | 72 | }
|
---|
| 73 |
|
---|
[130] | 74 | public override void Run (string[] _params)
|
---|
| 75 | {
|
---|
| 76 | Log.Out ("Command \"reply\" can only be used on clients!");
|
---|
| 77 | }
|
---|
[112] | 78 | }
|
---|
| 79 | }
|
---|