Terraria ModLoader  0.11.5
A framework for Terraria mods
Terraria.ModLoader.ModNet Class Reference
+ Collaboration diagram for Terraria.ModLoader.ModNet:

Classes

class  ModHeader
 
class  NetConfig
 

Static Public Member Functions

static Mod GetMod (int netID)
 
static bool IsModdedClient (int i)
 

Static Public Attributes

static int NetModCount => netMods.Length
 
static int[] rxDataType
 
static int[] rxMsgType
 
static int[] txDataType
 
static int[] txMsgType
 

Properties

static bool AllowVanillaClients [get, set]
 

Static Private Member Functions

static void AddNoSyncDeps (List< Mod > syncMods)
 
static void CancelDownload ()
 
static void DownloadNextMod ()
 
static void OnModsDownloaded (bool needsReload)
 
static void ReadNetIDs (BinaryReader reader)
 
static void SendServerConfigs (ModPacket p, Mod mod)
 
static void SetupDiagnostics ()
 

Static Private Attributes

static FileStream downloadingFile
 
static long downloadingLength
 
static ModHeader downloadingMod
 
static Queue< ModHeader > downloadQueue = new Queue<ModHeader>()
 
static Mod[] netMods
 

Detailed Description

Definition at line 18 of file ModNet.cs.

Member Function Documentation

static void Terraria.ModLoader.ModNet.AddNoSyncDeps ( List< Mod syncMods)
staticprivate

Definition at line 105 of file ModNet.cs.

105  {
106  var queue = new Queue<Mod>(syncMods.Where(m => m.Side == ModSide.Both));
107  while (queue.Count > 0) {
108  foreach (var dep in AssemblyManager.GetDependencies(queue.Dequeue())) {
109  if (dep.Side == ModSide.NoSync && !syncMods.Contains(dep)) {
110  syncMods.Add(dep);
111  queue.Enqueue(dep);
112  }
113  }
114  }
115  }
ModSide
A ModSide enum defines how mods are synced between clients and servers. You can set your mod&#39;s ModSid...
Definition: ModSide.cs:4
static void Terraria.ModLoader.ModNet.CancelDownload ( )
staticprivate

Definition at line 315 of file ModNet.cs.

315  {
316  try {
317  downloadingFile?.Close();
318  File.Delete(downloadingMod.path);
319  }
320  catch { }
321  downloadingMod = null;
322  Netplay.disconnect = true;
323  }
static ModHeader downloadingMod
Definition: ModNet.cs:70
static FileStream downloadingFile
Definition: ModNet.cs:71
static void Terraria.ModLoader.ModNet.DownloadNextMod ( )
staticprivate

Definition at line 227 of file ModNet.cs.

References Terraria.ModLoader.Mod.Close(), and Terraria.ModLoader.ModLoader.GetMod().

227  {
228  downloadingMod = downloadQueue.Dequeue();
229  downloadingFile = null;
230  var p = new ModPacket(MessageID.ModFile);
231  p.Write(downloadingMod.name);
232  p.Send();
233  }
static Queue< ModHeader > downloadQueue
Definition: ModNet.cs:68
static ModHeader downloadingMod
Definition: ModNet.cs:70
static FileStream downloadingFile
Definition: ModNet.cs:71

+ Here is the call graph for this function:

static Mod Terraria.ModLoader.ModNet.GetMod ( int  netID)
static

Referenced by Terraria.ModLoader.ItemLoader.NeedsModSaving().

+ Here is the caller graph for this function:

static bool Terraria.ModLoader.ModNet.IsModdedClient ( int  i)
static
static void Terraria.ModLoader.ModNet.OnModsDownloaded ( bool  needsReload)
staticprivate

Definition at line 325 of file ModNet.cs.

References Terraria.ModLoader.ModLoader.Mods, and Terraria.ModLoader.ModPacket.Send().

325  {
326  if (needsReload) {
327  ModLoader.OnSuccessfulLoad = NetReload();
328  ModLoader.Reload();
329  return;
330  }
331 
332  downloadingMod = null;
333  netMods = null;
334  foreach (var mod in ModLoader.Mods)
335  mod.netID = -1;
336 
337  new ModPacket(MessageID.SyncMods).Send();
338  }
static ModHeader downloadingMod
Definition: ModNet.cs:70
static Mod[] netMods
Definition: ModNet.cs:59

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModNet.ReadNetIDs ( BinaryReader  reader)
staticprivate

Definition at line 369 of file ModNet.cs.

References Terraria.ModLoader.Mod.HijackSendData(), and Terraria.ModLoader.ModLoader.Mods.

369  {
370  var mods = ModLoader.Mods;
371  var list = new List<Mod>();
372  var n = reader.ReadInt32();
373  for (short i = 0; i < n; i++) {
374  var name = reader.ReadString();
375  var mod = mods.SingleOrDefault(m => m.Name == name);
376  list.Add(mod);
377  if (mod != null) //nosync mod that doesn't exist on the client
378  mod.netID = i;
379  }
380  netMods = list.ToArray();
382 
383  ItemLoader.ReadNetGlobalOrder(reader);
384  WorldHooks.ReadNetWorldOrder(reader);
385  int serverMaxBuffs = reader.ReadInt32();
386  if (serverMaxBuffs != Player.MaxBuffs) {
387  Netplay.disconnect = true;
388  Main.statusText = $"The server expects Player.MaxBuffs of {serverMaxBuffs}\nbut this client reports {Player.MaxBuffs}.\nSome mod is behaving poorly.";
389  }
390  }
static void SetupDiagnostics()
Definition: ModNet.cs:444
static Mod[] netMods
Definition: ModNet.cs:59

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModNet.SendServerConfigs ( ModPacket  p,
Mod  mod 
)
staticprivate

Definition at line 117 of file ModNet.cs.

References Terraria.ModLoader.ModLoader.Mods, and Terraria.ModLoader.Config.ModConfig.OnChanged().

117  {
118  if (!ConfigManager.Configs.TryGetValue(mod, out var configs)) {
119  p.Write(0);
120  return;
121  }
122 
123  var serverConfigs = configs.Where(x => x.Mode == ConfigScope.ServerSide).ToArray();
124  p.Write(serverConfigs.Length);
125  foreach (var config in serverConfigs) {
126  string json = JsonConvert.SerializeObject(config, ConfigManager.serializerSettingsCompact);
127  Logging.Terraria.Info($"Sending Server Config {config.mod.Name} {config.Name}: {json}");
128 
129  p.Write(config.Name);
130  p.Write(json);
131  }
132  }
ConfigScope
Each ModConfig class has a different scope. Failure to use the correct mode will lead to bugs...
Definition: ModConfig.cs:91

+ Here is the call graph for this function:

static void Terraria.ModLoader.ModNet.SetupDiagnostics ( )
staticprivate

Definition at line 444 of file ModNet.cs.

References Terraria.ModLoader.Mod.Name.

444  {
445  rxMsgType = new int[netMods.Length];
446  rxDataType = new int[netMods.Length];
447  txMsgType = new int[netMods.Length];
448  txDataType = new int[netMods.Length];
449  }
static int[] rxDataType
Definition: ModNet.cs:440
static int[] txDataType
Definition: ModNet.cs:442
static Mod[] netMods
Definition: ModNet.cs:59
static int[] txMsgType
Definition: ModNet.cs:441
static int[] rxMsgType
Definition: ModNet.cs:439

Member Data Documentation

FileStream Terraria.ModLoader.ModNet.downloadingFile
staticprivate

Definition at line 71 of file ModNet.cs.

long Terraria.ModLoader.ModNet.downloadingLength
staticprivate

Definition at line 72 of file ModNet.cs.

ModHeader Terraria.ModLoader.ModNet.downloadingMod
staticprivate

Definition at line 70 of file ModNet.cs.

Queue<ModHeader> Terraria.ModLoader.ModNet.downloadQueue = new Queue<ModHeader>()
staticprivate

Definition at line 68 of file ModNet.cs.

int Terraria.ModLoader.ModNet.NetModCount => netMods.Length
static

Definition at line 66 of file ModNet.cs.

Referenced by Terraria.ModLoader.Mod.GetPacket().

Mod [] Terraria.ModLoader.ModNet.netMods
staticprivate

Definition at line 59 of file ModNet.cs.

int [] Terraria.ModLoader.ModNet.rxDataType
static

Definition at line 440 of file ModNet.cs.

int [] Terraria.ModLoader.ModNet.rxMsgType
static

Definition at line 439 of file ModNet.cs.

int [] Terraria.ModLoader.ModNet.txDataType
static

Definition at line 442 of file ModNet.cs.

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

int [] Terraria.ModLoader.ModNet.txMsgType
static

Definition at line 441 of file ModNet.cs.

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

Property Documentation