Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetTextModule.cs
Go to the documentation of this file.
1using System.IO;
3using Terraria.Chat;
5using Terraria.Net;
7
9
11{
13 {
14 NetPacket result = NetModule.CreatePacket<NetTextModule>(message.GetMaxSerializedSize());
15 message.Serialize(result.Writer);
16 return result;
17 }
18
20 {
21 return SerializeServerMessage(text, color, byte.MaxValue);
22 }
23
24 public static NetPacket SerializeServerMessage(NetworkText text, Color color, byte authorId)
25 {
26 NetPacket result = NetModule.CreatePacket<NetTextModule>(1 + text.GetMaxSerializedSize() + 3);
27 result.Writer.Write(authorId);
28 text.Serialize(result.Writer);
29 result.Writer.WriteRGB(color);
30 return result;
31 }
32
33 private bool DeserializeAsClient(BinaryReader reader, int senderPlayerId)
34 {
35 byte messageAuthor = reader.ReadByte();
36 NetworkText text = NetworkText.Deserialize(reader);
37 Color color = reader.ReadRGB();
38 ChatHelper.DisplayMessage(text, color, messageAuthor);
39 return true;
40 }
41
42 private bool DeserializeAsServer(BinaryReader reader, int senderPlayerId)
43 {
44 ChatMessage message = ChatMessage.Deserialize(reader);
45 ChatManager.Commands.ProcessIncomingMessage(message, senderPlayerId);
46 return true;
47 }
48
49 public override bool Deserialize(BinaryReader reader, int senderPlayerId)
50 {
51 if (Main.dedServ)
52 {
53 return DeserializeAsServer(reader, senderPlayerId);
54 }
55 return DeserializeAsClient(reader, senderPlayerId);
56 }
57}
virtual byte ReadByte()
virtual void Write(bool value)
static void DisplayMessage(NetworkText text, Color color, byte messageAuthor)
Definition ChatHelper.cs:78
static ChatMessage Deserialize(BinaryReader reader)
void Serialize(BinaryWriter writer)
static NetPacket SerializeClientMessage(ChatMessage message)
static NetPacket SerializeServerMessage(NetworkText text, Color color, byte authorId)
override bool Deserialize(BinaryReader reader, int senderPlayerId)
bool DeserializeAsClient(BinaryReader reader, int senderPlayerId)
static NetPacket SerializeServerMessage(NetworkText text, Color color)
bool DeserializeAsServer(BinaryReader reader, int senderPlayerId)
static NetworkText Deserialize(BinaryReader reader)
static bool dedServ
Definition Main.cs:1226
static readonly ChatCommandProcessor Commands
BinaryWriter Writer
Definition NetPacket.cs:16