tModLoader v0.11.8.9
A mod to make and play 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[] rxDataType
 
static int[] rxMsgType
 
static int[] txDataType
 
static int[] txMsgType
 

Properties

static bool AllowVanillaClients [get, set]
 
static int NetModCount [get]
 

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

◆ AddNoSyncDeps()

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's ModSid...
Definition: ModSide.cs:5

◆ CancelDownload()

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

References Terraria.ModLoader.ModNet.downloadingFile, and Terraria.ModLoader.ModNet.downloadingMod.

◆ DownloadNextMod()

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

Definition at line 227 of file ModNet.cs.

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

References Terraria.ModLoader.ModNet.downloadingFile, Terraria.ModLoader.ModNet.downloadingMod, and Terraria.ModLoader.ModNet.downloadQueue.

◆ GetMod()

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

◆ IsModdedClient()

static bool Terraria.ModLoader.ModNet.IsModdedClient ( int  i)
static

◆ OnModsDownloaded()

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

Definition at line 325 of file ModNet.cs.

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

References Terraria.ModLoader.ModNet.downloadingMod, Terraria.ModLoader.ModLoader.Mods, Terraria.ModLoader.ModNet.netMods, and Terraria.ModLoader.ModPacket.Send().

+ Here is the call graph for this function:

◆ ReadNetIDs()

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

Definition at line 374 of file ModNet.cs.

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

References Terraria.ModLoader.ModLoader.Mods, Terraria.ModLoader.ModNet.netMods, and Terraria.ModLoader.ModNet.SetupDiagnostics().

+ Here is the call graph for this function:

◆ SendServerConfigs()

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

Definition at line 117 of file ModNet.cs.

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:92

◆ SetupDiagnostics()

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

Definition at line 460 of file ModNet.cs.

460 {
461 rxMsgType = new int[netMods.Length];
462 rxDataType = new int[netMods.Length];
463 txMsgType = new int[netMods.Length];
464 txDataType = new int[netMods.Length];
465 }
static int[] rxDataType
Definition: ModNet.cs:456
static int[] rxMsgType
Definition: ModNet.cs:455
static int[] txDataType
Definition: ModNet.cs:458
static int[] txMsgType
Definition: ModNet.cs:457

References Terraria.ModLoader.ModNet.netMods, Terraria.ModLoader.ModNet.rxDataType, Terraria.ModLoader.ModNet.rxMsgType, Terraria.ModLoader.ModNet.txDataType, and Terraria.ModLoader.ModNet.txMsgType.

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ downloadingFile

FileStream Terraria.ModLoader.ModNet.downloadingFile
staticprivate

◆ downloadingLength

long Terraria.ModLoader.ModNet.downloadingLength
staticprivate

Definition at line 72 of file ModNet.cs.

◆ downloadingMod

ModHeader Terraria.ModLoader.ModNet.downloadingMod
staticprivate

◆ downloadQueue

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

Definition at line 68 of file ModNet.cs.

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

◆ netMods

Mod [] Terraria.ModLoader.ModNet.netMods
staticprivate

◆ rxDataType

int [] Terraria.ModLoader.ModNet.rxDataType
static

Definition at line 456 of file ModNet.cs.

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

◆ rxMsgType

int [] Terraria.ModLoader.ModNet.rxMsgType
static

Definition at line 455 of file ModNet.cs.

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

◆ txDataType

int [] Terraria.ModLoader.ModNet.txDataType
static

◆ txMsgType

int [] Terraria.ModLoader.ModNet.txMsgType
static

Property Documentation

◆ AllowVanillaClients

bool Terraria.ModLoader.ModNet.AllowVanillaClients
staticgetset

Definition at line 53 of file ModNet.cs.

53{ get; internal set; }

◆ NetModCount

int Terraria.ModLoader.ModNet.NetModCount
staticget

Definition at line 66 of file ModNet.cs.

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