private ModPacket GetServerPacket(bool isRequest)
        {
            if (Main.netMode != 2)
            {
                throw new ModHelpersException("Not a server");
            }

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

            packet.Write((int)PacketProtocol.GetPacketCode(name));
            packet.Write(isRequest);

            return(packet);
        }
        private ModPacket GetClientPacket(bool isRequest, bool syncToAll)
        {
            if (Main.netMode != 1)
            {
                throw new ModHelpersException("Not a client");
            }

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

            packet.Write((int)PacketProtocol.GetPacketCode(name));
            packet.Write(isRequest);
            packet.Write(syncToAll);

            return(packet);
        }
Exemple #3
0
        internal static IDictionary <int, Type> GetProtocolTypes()
        {
            IEnumerable <Type>      protocolTypes   = ReflectionHelpers.GetAllAvailableSubTypesFromMods(typeof(PacketProtocol));
            IDictionary <int, Type> protocolTypeMap = new Dictionary <int, Type>();

            foreach (Type subclassType in protocolTypes)
            {
                ConstructorInfo ctorInfo = subclassType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null,
                                                                       new Type[] { }, null);
                if (ctorInfo == null)
                {
                    throw new ModHelpersException("Missing private constructor for " + subclassType.Name + " (" + subclassType.Namespace + ")");
                }
                if (ctorInfo.IsFamily)
                {
                    throw new ModHelpersException("Invalid constructor for " + subclassType.Name + " (" + subclassType.Namespace + "); must be private, not protected.");
                }

                if (ModHelpersMod.Config.DebugModeNetInfo)
                {
                    string name = subclassType.Namespace + "." + subclassType.Name;
                    LogHelpers.Alert(name);
                }

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

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

            return(protocolTypeMap);
        }