Ejemplo n.º 1
0
        /// <summary>
        /// Called by UnityEngine when a broadcast is received.
        /// </summary>
        /// <param name="fromAddress">When the broadcast came from</param>
        /// <param name="data">The data in the broad cast. Not currently used, but could
        /// be used for differentiating rooms or similar.</param>
        public void receivedBroadcast(string fromAddress, string data)
        {
            Debug.Log(fromAddress);
            Debug.Log(data);
            string serverIp = fromAddress.Substring(fromAddress.LastIndexOf(':') + 1);

            // SessionInfo sessionInfo;
            if (!remoteSessions_.ContainsKey(serverIp))
            {
                remoteSessions_.Add(serverIp, new SessionInfo()
                {
                    ip = serverIp, name = data
                });
                if (SessionListChanged != null)
                {
                    SessionListChanged.Invoke();
                }
            }
        }
Ejemplo n.º 2
0
        private Task OnBroadcastData(MessageContainer obj)
        {
            Debug.Log("Received broadcast!");
            MessageAnnouncement message = MessageAnnouncement.Unpack(obj); // deserialize message

            // check if the announcement strings matches
            if (message != null && message.Message.Equals(AnnounceMessage))
            {
                if (Sessions.TryGetValue(message.IP, out SessionInfo sessionInfo) == false)
                {
                    // add to session list
                    Sessions.Add(message.IP, new SessionInfo()
                    {
                        SessionName = message.Name, SessionIp = message.IP, SessionPort = message.Port
                    });

                    // trigger event to notify about new session
                    SessionListChanged?.Invoke(this, EventArgs.Empty);
                }
            }

            return(Task.CompletedTask);
        }