Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ChatHelper.cs
Go to the documentation of this file.
1using System;
7using Terraria.Net;
8
9namespace Terraria.Chat;
10
11public static class ChatHelper
12{
14
15 public static void DisplayMessageOnClient(NetworkText text, Color color, int playerId)
16 {
17 if (Main.dedServ)
18 {
20 NetManager.Instance.SendToClient(packet, playerId);
21 }
22 else
23 {
24 DisplayMessage(text, color, byte.MaxValue);
25 }
26 }
27
28 public static void SendChatMessageToClient(NetworkText text, Color color, int playerId)
29 {
30 SendChatMessageToClientAs(byte.MaxValue, text, color, playerId);
31 }
32
34 {
35 if (Main.dedServ)
36 {
38 NetManager.Instance.SendToClient(packet, playerId);
39 }
40 if (playerId == Main.myPlayer)
41 {
43 }
44 }
45
46 public static void BroadcastChatMessage(NetworkText text, Color color, int excludedPlayer = -1)
47 {
48 BroadcastChatMessageAs(byte.MaxValue, text, color, excludedPlayer);
49 }
50
63
65 {
66 return Netplay.Clients[clientIndex].State == 10;
67 }
68
69 public static void SendChatMessageFromClient(ChatMessage message)
70 {
71 if (!message.IsConsumed)
72 {
74 NetManager.Instance.SendToServer(packet);
75 }
76 }
77
78 public static void DisplayMessage(NetworkText text, Color color, byte messageAuthor)
79 {
80 string text2 = text.ToString();
81 if (messageAuthor < byte.MaxValue)
82 {
84 Main.player[messageAuthor].chatOverhead.color = color;
86 }
88 {
89 CacheMessage(text2, color);
90 }
91 else
92 {
93 Main.NewTextMultiline(text2, force: false, color);
94 }
95 }
96
97 private static void CacheMessage(string message, Color color)
98 {
99 _cachedMessages.Add(new Tuple<string, Color>(message, color));
100 }
101
102 public static void ShowCachedMessages()
103 {
105 {
107 {
109 }
110 }
111 }
112
113 public static void ClearDelayedMessagesCache()
114 {
115 _cachedMessages.Clear();
116 }
117
118 private static bool ShouldCacheMessage()
119 {
120 if (Main.netMode == 1)
121 {
122 return Main.gameMenu;
123 }
124 return false;
125 }
126}
static List< Tuple< string, Color > > _cachedMessages
Definition ChatHelper.cs:13
static void CacheMessage(string message, Color color)
Definition ChatHelper.cs:97
static void SendChatMessageFromClient(ChatMessage message)
Definition ChatHelper.cs:69
static bool OnlySendToPlayersWhoAreLoggedIn(int clientIndex)
Definition ChatHelper.cs:64
static void DisplayMessageOnClient(NetworkText text, Color color, int playerId)
Definition ChatHelper.cs:15
static void ShowCachedMessages()
static void SendChatMessageToClient(NetworkText text, Color color, int playerId)
Definition ChatHelper.cs:28
static void BroadcastChatMessage(NetworkText text, Color color, int excludedPlayer=-1)
Definition ChatHelper.cs:46
static bool ShouldCacheMessage()
static void DisplayMessage(NetworkText text, Color color, byte messageAuthor)
Definition ChatHelper.cs:78
static void ClearDelayedMessagesCache()
static void SendChatMessageToClientAs(byte messageAuthor, NetworkText text, Color color, int playerId)
Definition ChatHelper.cs:33
static void BroadcastChatMessageAs(byte messageAuthor, NetworkText text, Color color, int excludedPlayer=-1)
Definition ChatHelper.cs:51
static NetPacket SerializeClientMessage(ChatMessage message)
static NetPacket SerializeServerMessage(NetworkText text, Color color)
static int PlayerOverheadChatMessageDisplayTime
Definition Main.cs:1735
static int myPlayer
Definition Main.cs:1801
static int netMode
Definition Main.cs:2095
static bool dedServ
Definition Main.cs:1226
static void NewTextMultiline(string text, bool force=false, Microsoft.Xna.Framework.Color c=default(Microsoft.Xna.Framework.Color), int WidthLimit=-1)
Definition Main.cs:61435
static bool gameMenu
Definition Main.cs:1926
static Player[] player
Definition Main.cs:1803
static readonly NetManager Instance
Definition NetManager.cs:18
static RemoteClient[] Clients
Definition Netplay.cs:37