Terraria ModLoader  0.10.1.5
A framework for 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

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  }
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.

References Terraria.ModLoader.ModNet.txDataType, and Terraria.ModLoader.ModNet.txMsgType.

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

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

+ Here is the caller graph for this function:

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

Definition at line 47 of file ModPacket.cs.

47 { }

Member Data Documentation

byte [] Terraria.ModLoader.ModPacket.buf
private

Definition at line 15 of file ModPacket.cs.

ushort Terraria.ModLoader.ModPacket.len
private

Definition at line 16 of file ModPacket.cs.