Inheritance: System.IO.BinaryWriter
Exemple #1
0
        internal static void SendNetIDs(int toClient)
        {
            var p = new ModPacket(MessageID.ModPacket);

            p.Write((short)-1);
            p.Write(netMods.Length);
            foreach (var mod in netMods)
            {
                p.Write(mod.Name);
            }

            p.Send(toClient);
        }
Exemple #2
0
        internal static void SendNetIDs(int toClient)
        {
            var p = new ModPacket(MessageID.ModPacket);

            p.Write(netMods.Length);
            foreach (var mod in netMods)
            {
                p.Write(mod.Name);
            }

            ItemLoader.WriteNetGlobalOrder(p);
            WorldHooks.WriteNetWorldOrder(p);

            p.Send(toClient);
        }
Exemple #3
0
		internal static void SyncMods(int clientIndex) {
			var p = new ModPacket(MessageID.SyncMods);
			p.Write(AllowVanillaClients);

			var syncMods = ModLoader.LoadedMods.Where(mod => mod.Side == ModSide.Both).ToArray();
			p.Write(syncMods.Length);
			foreach (var mod in syncMods)
			{
				p.Write(mod.Name);
				p.Write(mod.Version.ToString());
				p.Write(mod.File.hash);
				p.Write(mod.File.ValidModBrowserSignature);
			}

			p.Send(clientIndex);
		}
Exemple #4
0
        internal static void SendNetIDs(int toClient)
        {
            var p = new ModPacket(MessageID.ModPacket);

            p.Write(netMods.Length);
            foreach (Mod mod in netMods)
            {
                p.Write(mod.Name);
            }

            ItemLoader.WriteNetGlobalOrder(p);
            SystemHooks.WriteNetSystemOrder(p);
            p.Write(Player.MaxBuffs);

            p.Send(toClient);
        }
Exemple #5
0
        internal static void SyncMods(int clientIndex)
        {
            var p = new ModPacket(MessageID.SyncMods);

            p.Write(AllowVanillaClients);

            var syncMods = ModLoader.Mods.Where(mod => mod.Side == ModSide.Both).ToArray();

            p.Write(syncMods.Length);
            foreach (var mod in syncMods)
            {
                p.Write(mod.Name);
                p.Write(mod.Version.ToString());
                p.Write(mod.File.hash);
                p.Write(mod.File.ValidModBrowserSignature);
            }

            p.Send(clientIndex);
        }
Exemple #6
0
        private static void SendServerConfigs(ModPacket p, Mod mod)
        {
            if (!ConfigManager.Configs.TryGetValue(mod, out List <ModConfig> configs))
            {
                p.Write(0);
                return;
            }

            ModConfig[] serverConfigs = configs.Where(x => x.Mode == ConfigScope.ServerSide).ToArray();
            p.Write(serverConfigs.Length);
            foreach (ModConfig config in serverConfigs)
            {
                string json = JsonConvert.SerializeObject(config, ConfigManager.serializerSettingsCompact);
                Logging.Terraria.Info($"Sending Server Config {config.mod.Name} {config.Name}: {json}");

                p.Write(config.Name);
                p.Write(json);
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates a ModPacket object that you can write to and then send between servers and clients.
        /// </summary>
        /// <param name="capacity">The capacity.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Cannot get packet for " + Name + " because it does not exist on the other side</exception>
        public ModPacket GetPacket(int capacity = 256)
        {
            if (netID < 0)
            {
                throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");
            }

            var p = new ModPacket(MessageID.ModPacket, capacity + 5);

            if (ModNet.NetModCount < 256)
            {
                p.Write((byte)netID);
            }
            else
            {
                p.Write(netID);
            }

            p.netID = netID;
            return(p);
        }
Exemple #8
0
        internal static void SyncMods(int clientIndex)
        {
            var p = new ModPacket(MessageID.SyncMods);

            p.Write(AllowVanillaClients);

            var syncMods = ModLoader.Mods.Where(mod => mod.Side == ModSide.Both).ToList();

            AddNoSyncDeps(syncMods);

            p.Write(syncMods.Count);
            foreach (var mod in syncMods)               // We only sync ServerSide configs for ModSide.Both. ModSide.Server can have
            {
                p.Write(mod.Name);
                p.Write(mod.Version.ToString());
                p.Write(mod.File.hash);
                p.Write(mod.File.ValidModBrowserSignature);
                var modConfigs = ConfigManager.Configs.SingleOrDefault(x => x.Key == mod).Value?.Where(x => x.Mode == ConfigScope.ServerSide);
                if (modConfigs == null)
                //if (modConfigs.Equals(default(List<ModConfig>)))
                {
                    p.Write(0);
                    Console.WriteLine($"No configs for {mod.Name}");
                }
                else
                {
                    p.Write(modConfigs.Count());
                    foreach (var config in modConfigs)
                    {
                        string json = JsonConvert.SerializeObject(config, ConfigManager.serializerSettingsCompact);
                        Console.WriteLine($"Sending Server Config {config.Name}: {json}");

                        p.Write(config.Name);
                        p.Write(json);
                    }
                }
            }

            p.Send(clientIndex);
        }
Exemple #9
0
        internal static void SyncMods(int clientIndex)
        {
            var p = new ModPacket(MessageID.SyncMods);

            p.Write(AllowVanillaClients);

            var syncMods = ModLoader.Mods.Where(mod => mod.Side == ModSide.Both).ToList();

            AddNoSyncDeps(syncMods);

            p.Write(syncMods.Count);
            foreach (var mod in syncMods)               // We only sync ServerSide configs for ModSide.Both. ModSide.Server can have
            {
                p.Write(mod.Name);
                p.Write(mod.Version.ToString());
                p.Write(mod.File.hash);
                p.Write(mod.File.ValidModBrowserSignature);
                SendServerConfigs(p, mod);
            }

            p.Send(clientIndex);
        }
Exemple #10
0
        internal static void SendMod(string modName, int toClient)
        {
            var mod  = ModLoader.GetMod(modName);
            var path = mod.File.path;
            var fs   = new FileStream(path, FileMode.Open);
            {            //send file length
                var p = new ModPacket(MessageID.ModFile);
                p.Write(mod.DisplayName);
                p.Write(fs.Length);
                p.Send(toClient);
            }

            var buf = new byte[CHUNK_SIZE];
            int count;

            while ((count = fs.Read(buf, 0, buf.Length)) > 0)
            {
                var p = new ModPacket(MessageID.ModFile, CHUNK_SIZE + 3);
                p.Write(buf, 0, count);
                p.Send(toClient);
            }

            fs.Close();
        }
Exemple #11
0
		internal static void SendNetIDs(int toClient) {
			var p = new ModPacket(MessageID.ModPacket);
			p.Write((short)-1);
			p.Write(netMods.Length);
			foreach (var mod in netMods)
				p.Write(mod.Name);

			p.Send(toClient);
		}
Exemple #12
0
		internal static void SendMod(string modName, int toClient) {
			var mod = ModLoader.GetMod(modName);
			var path = mod.File.path;
			var fs = new FileStream(path, FileMode.Open);
			{//send file length
				var p = new ModPacket(MessageID.ModFile);
				p.Write(mod.DisplayName);
				p.Write(fs.Length);
				p.Send(toClient);
			}
			
			var buf = new byte[CHUNK_SIZE];
			int count;
			while ((count = fs.Read(buf, 0, buf.Length)) > 0)
			{
				var p = new ModPacket(MessageID.ModFile, CHUNK_SIZE + 3);
				p.Write(buf, 0, count);
				p.Send(toClient);
			}

			fs.Close();
		}
Exemple #13
0
		private static void DownloadNextMod() {
			downloadingMod = downloadQueue.Dequeue();
			downloadingFile = null;

			var p = new ModPacket(MessageID.ModFile);
			p.Write(downloadingMod.name);
			p.Send();
		}
Exemple #14
0
		internal static void SendNetIDs(int toClient) {
			var p = new ModPacket(MessageID.ModPacket);
			p.Write((short)-1);
			p.Write(netMods.Length);
			foreach (var mod in netMods)
				p.Write(mod.Name);
			
			ItemLoader.WriteNetGlobalOrder(p);
			WorldHooks.WriteNetWorldOrder(p);

			p.Send(toClient);
		}
Exemple #15
0
		public ModPacket GetPacket(int capacity = 256)
		{
			if (netID < 0)
				throw new Exception("Cannot get packet for " + Name + " because it does not exist on the other side");

			var p = new ModPacket(MessageID.ModPacket, capacity + 5);
			p.Write(netID);
			return p;
		}