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