source: binary-improvements/7dtd-server-fixes/src/CustomCommands/Reply.cs@ 181

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

Fixes

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace 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 CommonMappingFunctions.GetConnectionManager ().networkView.RPC ("RPC_ChatMessage", _receiver.networkPlayer,
28 new object[] {
29 _message,
30 -1,
31 senderName + " (PM)",
32 true
33 }
34 );
35 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver);
36 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + senderName + "\"");
37 }
38
39 private void RunInternal (ClientInfo _sender, string[] _params)
40 {
41 if (_params.Length < 1) {
42 m_Console.SendResult ("Usage: reply <message>");
43 return;
44 }
45
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);
54 } else {
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 }
60 }
61 }
62
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 }
72 }
73
74 public override void Run (string[] _params)
75 {
76 Log.Out ("Command \"reply\" can only be used on clients!");
77 }
78 }
79}
Note: See TracBrowser for help on using the repository browser.