コード例 #1
0
        internal static IDictionary <int, Type> GetProtocols()
        {
            IDictionary <int, Type> protocols = new Dictionary <int, Type>();

            //var subclasses = from assembly in AppDomain.CurrentDomain.GetAssemblies()
            var mod_types  = ModLoader.LoadedMods.Select(mod => mod.GetType());
            var assemblies = mod_types.Select(mod_type => mod_type.Assembly);
            var subclasses = from assembly in assemblies
                             from type in assembly.GetTypes()
                             where type.IsSubclassOf(typeof(OldPacketProtocol)) && !type.IsAbstract
                             select type;

            foreach (Type subclass in subclasses)
            {
                if (HamstarHelpersMod.Instance.Config.DebugModeNetInfo)
                {
                    string name = subclass.Namespace + "." + subclass.Name;
                    LogHelpers.Log("PacketProtocol.GetProtocols() - " + name);
                }

                try {
                    string name = subclass.Namespace + "." + subclass.Name;
                    int    code = OldPacketProtocol.GetPacketCode(name);

                    protocols[code] = subclass;
                } catch (Exception e) {
                    LogHelpers.Log(subclass.Name + " - " + e.Message);
                }
            }

            return(protocols);
        }
コード例 #2
0
        private ModPacket GetServerPacket(bool is_request)
        {
            if (Main.netMode != 2)
            {
                throw new Exception("Not a server");
            }

            string name   = this.GetPacketName();
            var    packet = HamstarHelpersMod.Instance.GetPacket();

            packet.Write((int)OldPacketProtocol.GetPacketCode(name));
            packet.Write(is_request);

            return(packet);
        }
コード例 #3
0
        private ModPacket GetClientPacket(bool is_request, bool sync_to_all)
        {
            if (Main.netMode != 1)
            {
                throw new Exception("Not a client");
            }

            string name   = this.GetPacketName();
            var    packet = HamstarHelpersMod.Instance.GetPacket();

            packet.Write((int)OldPacketProtocol.GetPacketCode(name));
            packet.Write(is_request);
            packet.Write(sync_to_all);

            return(packet);
        }