Example #1
0
        private byte[] GenerateMessage(string senderName, string dataDescription, byte[] data)
        {
            NetworkerMessage message = new NetworkerMessage
            {
                ModID           = ModID,
                SenderID        = MyAPIGateway.Multiplayer.MyId,
                DataTag         = senderName,
                DataDescription = dataDescription,
                Data            = data
            };

            return(MyAPIGateway.Utilities.SerializeToBinary(message));
        }
Example #2
0
        void Handler(byte[] rawmessage)
        {
            NetworkerMessage message = MyAPIGateway.Utilities.SerializeFromBinary <NetworkerMessage>(rawmessage);

            if (message == null || message.ModID != ModID)
            {
                return;
            }
            // TODO: <Cheetah Comment> Add logging
            if (MessageHandlers.ContainsKey(message.DataTag))
            {
                foreach (Action <NetworkerMessage> handler in MessageHandlers[message.DataTag])
                {
                    try
                    {
                        handler?.Invoke(message);
                    }
                    catch { }
                }
            }
        }