source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/Reply.cs@ 116

Last change on this file since 116 was 112, checked in by alloc, 10 years ago

fixes

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