Terraria

ModWorld Networking

Defined in 'Global\World.cs':

  • void NetReceive(int msg, BinaryReader reader) - Called when a net message is received for this ModWorld class.
  • void NetSend(int msg, BinaryWriter writer) - Called when a net message needs to be sent
  • void PlayerConnected(int playerID) - Called on the server when a player connects
  • void SyncPlayers() - Called on the server when a player joins, and periodically afterwards
  • void NetReceiveIntercept(messageBuffer msgBuffer, int b, int start, int length, ref int num)
  • void NetSendIntercept(int num, ref int num2, ref int num3, int msgType, int remoteClient, int ignoreClient, string text, int number, float number2, float number3, float number4, int number5)
To send a message with NetSend, you would call NetMessage.SendData with 100 as the msgType, and the modIndex & your own message ID passed as parameters.

Another way to send a message, much more easily, is using the new NetMessage.SendModData() method. You can pass in basic data types and it will automatically write them into the networking stream appropriately. The method signature is:

void SendModData(int modIndex, int msgID, int remoteClient = -1, int ignoreClient = -1, params object[] parameters)

Article information

Added on

Written by

Surfpup

0 comments