source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/SayToPlayer.cs@ 95

Last change on this file since 95 was 83, checked in by alloc, 10 years ago

server fixes

File size: 2.0 KB
RevLine 
[83]1using System;
2using System.Collections.Generic;
3
4public class SayToPlayer : ConsoleCommand
5{
6 private GameManager manager;
7
8 public SayToPlayer (ConsoleSdtd cons) : base(cons)
9 {
10 manager = m_Console.gameManager;
11 }
12
13 public override string Description ()
14 {
15 return "send a message to a single player";
16 }
17
18 public override string[] Names ()
19 {
20 return new string[] { "sayplayer", string.Empty };
21 }
22
23 public override void Run (string[] _params)
24 {
25 if (_params.Length < 2) {
26 m_Console.md000a ("Usage: sayplayer <playername|entityid> <message>");
27 return;
28 }
29
30 string message = _params [1];
31 for (int i = 2; i < _params.Length; i++) {
32 message += " " + _params [i];
33 }
34
35 int entityId = -1;
36 if (int.TryParse (_params [0], out entityId)) {
37 foreach (KeyValuePair<int, int> kvp in manager.connectionManager.mapClientToEntity) {
38 if (kvp.Value == entityId) {
39 int clientid = kvp.Key;
40 ClientInfo ci = manager.connectionManager.connectedClients[clientid];
41 if (ci != null) {
42 manager.connectionManager.networkView.RPC ("RPC_ChatMessage", ci.networkPlayer, new object[] {
43 message,
44 -1,
45 "Server (private)",
46 true
47 }
48 );
49 m_Console.md000a ("Message sent");
50 return;
51 }
52 }
53 }
54 m_Console.md000a ("Entity ID not found.");
55 } else {
56 string destPlayerName = _params [0].ToLower ();
57 foreach (ClientInfo ci in manager.connectionManager.connectedClients.Values) {
58 Dictionary<int,int> d = manager.connectionManager.mapClientToEntity;
59 if (d.ContainsKey (ci.clientId)) {
60 entityId = d [ci.clientId];
61 string curName = manager.World.playerEntities.dict [entityId].EntityName;
62 if (curName.ToLower ().Equals (destPlayerName)) {
63 manager.connectionManager.networkView.RPC ("RPC_ChatMessage", ci.networkPlayer, new object[] {
64 message,
65 -1,
66 "Server (private)",
67 true
68 }
69 );
70 m_Console.md000a ("Message sent");
71 return;
72 }
73 }
74 }
75 m_Console.md000a ("Playername not found.");
76 }
77 }
78}
79
Note: See TracBrowser for help on using the repository browser.