Esempio n. 1
0
            //TODO: Checking for ussed MessageTypes ids. Possible?
            private static bool ProcessIncomingMessage_Prefix(Multiplayer __instance, ref IncomingMessage msg)
            {
#if DEBUG
                if (msg.MessageType != 0)
                {
                    ModEntry.ModLogger.Log($"MessageType: {msg.MessageType}");
                }
#endif

                if (msg.MessageType == Message.TypeID && msg.Data.Length > 0)
                {
                    String keyword = Message.Action.None.ToString();

                    try {
                        //Check that this isnt other mods message by trying to read a 'key'
                        keyword = msg.Reader.ReadString();
                    } catch (EndOfStreamException) {
                        // Do nothing. If it does not contain the key, it may be anothers mod custom message or something went wrong
                    }

                    if (Enum.TryParse(keyword, out Message.Action action))
                    {
                        if (Enum.IsDefined(typeof(Message.Action), action))
                        {
                            switch (action)
                            {
                            case Message.Action.SendMapPing:
                                __instance.ReceiveMapPing(msg);
                                return(false);

                            case Message.Action.BroadcastMapPing:
                                __instance.ReceiveMapPingBroadcast(msg);
                                return(false);
                            }
                        }
                    }
                }

                // Allow to execute the vanilla method
                return(true);
            }