tModLoader v0.11.8.9
A mod to make and play Terraria mods
Terraria.ModLoader.ModPacket Class Reference

This class inherits from BinaryWriter. This means that you can use all of its writing functions to send information between client and server. This class also comes with a Send method that's used to actually send everything you've written between client and server. More...

+ Inheritance diagram for Terraria.ModLoader.ModPacket:
+ Collaboration diagram for Terraria.ModLoader.ModPacket:

Public Member Functions

void Send (int toClient=-1, int ignoreClient=-1)
 Sends all the information you've written between client and server. If the toClient parameter is non-negative, this packet will only be sent to the specified client. If the ignoreClient parameter is non-negative, this packet will not be sent to the specified client. More...
 

Private Member Functions

void Finish ()
 
void SendCallback (object state)
 

Private Attributes

byte[] buf
 
ushort len
 

Detailed Description

This class inherits from BinaryWriter. This means that you can use all of its writing functions to send information between client and server. This class also comes with a Send method that's used to actually send everything you've written between client and server.

ModPacket has all the same methods as BinaryWriter, and some additional ones.

See also
System.IO.BinaryWriter

Definition at line 13 of file ModPacket.cs.

Member Function Documentation

◆ Finish()

void Terraria.ModLoader.ModPacket.Finish ( )
private

Definition at line 49 of file ModPacket.cs.

49 {
50 if (buf != null)
51 return;
52
53 if (OutStream.Position > ushort.MaxValue)
54 throw new Exception(Language.GetTextValue("tModLoader.MPPacketTooLarge", OutStream.Position, ushort.MaxValue));
55
56 len = (ushort)OutStream.Position;
57 Seek(0, SeekOrigin.Begin);
58 Write(len);
59 Close();
60 buf = ((MemoryStream)OutStream).GetBuffer();
61 }

References Terraria.ModLoader.ModPacket.buf, and Terraria.ModLoader.ModPacket.len.

Referenced by Terraria.ModLoader.ModPacket.Send().

+ Here is the caller graph for this function:

◆ Send()

void Terraria.ModLoader.ModPacket.Send ( int  toClient = -1,
int  ignoreClient = -1 
)

Sends all the information you've written between client and server. If the toClient parameter is non-negative, this packet will only be sent to the specified client. If the ignoreClient parameter is non-negative, this packet will not be sent to the specified client.

Definition at line 27 of file ModPacket.cs.

27 {
28 Finish();
29
30 if (Main.netMode == 1) {
31 Netplay.Connection.Socket.AsyncSend(buf, 0, len, SendCallback);
32 Main.txMsg++;
33 Main.txData += len;
34 if (netID > 0) {
35 ModNet.txMsgType[netID]++;
36 ModNet.txDataType[netID] += len;
37 }
38 }
39 else if (toClient != -1)
40 Netplay.Clients[toClient].Socket.AsyncSend(buf, 0, len, SendCallback);
41 else
42 for (int i = 0; i < 256; i++)
43 if (i != ignoreClient && Netplay.Clients[i].IsConnected() && NetMessage.buffer[i].broadcast)
44 Netplay.Clients[i].Socket.AsyncSend(buf, 0, len, SendCallback);
45 }
void SendCallback(object state)
Definition: ModPacket.cs:47

References Terraria.ModLoader.ModPacket.buf, Terraria.ModLoader.ModPacket.Finish(), Terraria.ModLoader.ModPacket.len, Terraria.ModLoader.ModPacket.SendCallback(), Terraria.ModLoader.ModNet.txDataType, and Terraria.ModLoader.ModNet.txMsgType.

Referenced by Terraria.ModLoader.ModNet.OnModsDownloaded().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendCallback()

void Terraria.ModLoader.ModPacket.SendCallback ( object  state)
private

Definition at line 47 of file ModPacket.cs.

47{ }

Referenced by Terraria.ModLoader.ModPacket.Send().

+ Here is the caller graph for this function:

Member Data Documentation

◆ buf

byte [] Terraria.ModLoader.ModPacket.buf
private

◆ len

ushort Terraria.ModLoader.ModPacket.len
private