private void Update()
        {
            if (this.m_HostId == -1)
            {
                return;
            }
            if (this.m_IsServer)
            {
                return;
            }
            NetworkEventType networkEventType;

            do
            {
                int  num;
                int  num2;
                int  num3;
                byte b;
                networkEventType = NetworkTransport.ReceiveFromHost(this.m_HostId, out num, out num2, this.m_MsgInBuffer, 1024, out num3, out b);
                if (networkEventType == NetworkEventType.BroadcastEvent)
                {
                    NetworkTransport.GetBroadcastConnectionMessage(this.m_HostId, this.m_MsgInBuffer, 1024, out num3, out b);
                    string text;
                    int    num4;
                    NetworkTransport.GetBroadcastConnectionInfo(this.m_HostId, out text, out num4, out b);
                    NetworkBroadcastResult value = default(NetworkBroadcastResult);
                    value.serverAddress = text;
                    value.broadcastData = new byte[num3];
                    Buffer.BlockCopy(this.m_MsgInBuffer, 0, value.broadcastData, 0, num3);
                    this.m_BroadcastsReceived[text] = value;
                    this.OnReceivedBroadcast(text, NetworkDiscovery.BytesToString(this.m_MsgInBuffer));
                }
            }while (networkEventType != NetworkEventType.Nothing);
        }
示例#2
0
 private void Update()
 {
     if ((this.m_HostId != -1) && !this.m_IsServer)
     {
         NetworkEventType type;
         do
         {
             int  num;
             int  num2;
             int  num3;
             byte num4;
             type = NetworkTransport.ReceiveFromHost(this.m_HostId, out num, out num2, this.m_MsgInBuffer, 0x400, out num3, out num4);
             if (type == NetworkEventType.BroadcastEvent)
             {
                 string str;
                 int    num5;
                 NetworkTransport.GetBroadcastConnectionMessage(this.m_HostId, this.m_MsgInBuffer, 0x400, out num3, out num4);
                 NetworkTransport.GetBroadcastConnectionInfo(this.m_HostId, out str, out num5, out num4);
                 NetworkBroadcastResult result = new NetworkBroadcastResult {
                     serverAddress = str,
                     broadcastData = new byte[num3]
                 };
                 Buffer.BlockCopy(this.m_MsgInBuffer, 0, result.broadcastData, 0, num3);
                 this.m_BroadcastsReceived[str] = result;
                 this.OnReceivedBroadcast(str, BytesToString(this.m_MsgInBuffer));
             }
         }while (type != NetworkEventType.Nothing);
     }
 }
        private void Update()
        {
            if (this.m_HostId == -1 || this.m_IsServer)
            {
                return;
            }
            NetworkEventType fromHost;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;
                fromHost = NetworkTransport.ReceiveFromHost(this.m_HostId, out connectionId, out channelId, this.m_MsgInBuffer, 1024, out receivedSize, out error);
                if (fromHost == NetworkEventType.BroadcastEvent)
                {
                    NetworkTransport.GetBroadcastConnectionMessage(this.m_HostId, this.m_MsgInBuffer, 1024, out receivedSize, out error);
                    string address;
                    int    port;
                    NetworkTransport.GetBroadcastConnectionInfo(this.m_HostId, out address, out port, out error);
                    NetworkBroadcastResult networkBroadcastResult = new NetworkBroadcastResult();
                    networkBroadcastResult.serverAddress = address;
                    networkBroadcastResult.broadcastData = new byte[receivedSize];
                    Buffer.BlockCopy((Array)this.m_MsgInBuffer, 0, (Array)networkBroadcastResult.broadcastData, 0, receivedSize);
                    this.m_BroadcastsReceived[address] = networkBroadcastResult;
                    this.OnReceivedBroadcast(address, NetworkDiscovery.BytesToString(this.m_MsgInBuffer));
                }
            }while (fromHost != NetworkEventType.Nothing);
        }
示例#4
0
        public void JoinMatch(UnityEngine.Networking.NetworkBroadcastResult value, string address)
        {
            string dataString = BytesToString(value.broadcastData);
            var    items      = dataString.Split(':');

            if (items.Length == 3 && items[0] == "NetworkManager")
            {
                if (NetworkManager.singleton != null && NetworkManager.singleton.client == null)
                {
                    NetworkManager.singleton.networkAddress = address;
                    NetworkManager.singleton.networkPort    = System.Convert.ToInt32(items[2]);
                    NetworkManager.singleton.StartClient();
                    GetComponentInParent <Transform>().GetComponentInParent <NetworkDiscovery>().StopBroadcast();
                }
            }
        }
示例#5
0
        void Update()
        {
            if (m_HostId == -1)
            {
                return;
            }

            if (m_IsServer)
            {
                return;
            }

            NetworkEventType networkEvent;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;
                networkEvent = NetworkTransport.ReceiveFromHost(m_HostId, out connectionId, out channelId, m_MsgInBuffer, k_MaxBroadcastMsgSize, out receivedSize, out error);

                if (networkEvent == NetworkEventType.BroadcastEvent)
                {
                    //ブロードキャストのメッセージを取得
                    NetworkTransport.GetBroadcastConnectionMessage(m_HostId, m_MsgInBuffer, k_MaxBroadcastMsgSize, out receivedSize, out error);

                    string senderAddr;
                    int    senderPort;
                    //接続情報を取得
                    NetworkTransport.GetBroadcastConnectionInfo(m_HostId, out senderAddr, out senderPort, out error);
                    //NetworkBroadcastResult変数にアドレスとメッセージを代入
                    var recv = new NetworkBroadcastResult();
                    recv.serverAddress = senderAddr;
                    recv.broadcastData = new byte[receivedSize];
                    Buffer.BlockCopy(m_MsgInBuffer, 0, recv.broadcastData, 0, receivedSize);
                    //見つかった部屋を登録
                    m_BroadcastsReceived[senderAddr] = recv;
                    if (RoomList.roomListAddress.Contains(senderAddr) == false)
                    {
                        OnReceivedBroadcast(senderAddr, BytesToString(m_MsgInBuffer));
                    }
                }
            }while (networkEvent != NetworkEventType.Nothing);
        }
        void Update()
        {
            if (m_HostId == -1)
            {
                return;
            }

            if (m_IsServer)
            {
                return;
            }

            NetworkEventType networkEvent;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;
                networkEvent = NetworkManager.activeTransport.ReceiveFromHost(m_HostId, out connectionId, out channelId, m_MsgInBuffer, k_MaxBroadcastMsgSize, out receivedSize, out error);

                if (networkEvent == NetworkEventType.BroadcastEvent)
                {
                    NetworkManager.activeTransport.GetBroadcastConnectionMessage(m_HostId, m_MsgInBuffer, k_MaxBroadcastMsgSize, out receivedSize, out error);

                    string senderAddr;
                    int    senderPort;
                    NetworkManager.activeTransport.GetBroadcastConnectionInfo(m_HostId, out senderAddr, out senderPort, out error);

                    var recv = new NetworkBroadcastResult();
                    recv.serverAddress = senderAddr;
                    recv.broadcastData = new byte[receivedSize];
                    Buffer.BlockCopy(m_MsgInBuffer, 0, recv.broadcastData, 0, receivedSize);
                    m_BroadcastsReceived[senderAddr] = recv;

                    OnReceivedBroadcast(senderAddr, BytesToString(m_MsgInBuffer));
                }
            }while (networkEvent != NetworkEventType.Nothing);
        }
示例#7
0
        private void Update()
        {
            if (m_HostId == -1 || m_IsServer)
            {
                return;
            }
            NetworkEventType networkEventType;

            do
            {
                networkEventType = NetworkTransport.ReceiveFromHost(m_HostId, out int _, out int _, m_MsgInBuffer, 1024, out int receivedSize, out byte error);
                if (networkEventType == NetworkEventType.BroadcastEvent)
                {
                    NetworkTransport.GetBroadcastConnectionMessage(m_HostId, m_MsgInBuffer, 1024, out receivedSize, out error);
                    NetworkTransport.GetBroadcastConnectionInfo(m_HostId, out string address, out int _, out error);
                    NetworkBroadcastResult value = default(NetworkBroadcastResult);
                    value.serverAddress = address;
                    value.broadcastData = new byte[receivedSize];
                    Buffer.BlockCopy(m_MsgInBuffer, 0, value.broadcastData, 0, receivedSize);
                    m_BroadcastsReceived[address] = value;
                    OnReceivedBroadcast(address, BytesToString(m_MsgInBuffer));
                }
            }while (networkEventType != NetworkEventType.Nothing);
        }
示例#8
0
 private void Update()
 {
     if ((this.m_HostId != -1) && !this.m_IsServer)
     {
         NetworkEventType type;
         do
         {
             int num;
             int num2;
             int num3;
             byte num4;
             type = NetworkTransport.ReceiveFromHost(this.m_HostId, out num, out num2, this.m_MsgInBuffer, 0x400, out num3, out num4);
             if (type == NetworkEventType.BroadcastEvent)
             {
                 string str;
                 int num5;
                 NetworkTransport.GetBroadcastConnectionMessage(this.m_HostId, this.m_MsgInBuffer, 0x400, out num3, out num4);
                 NetworkTransport.GetBroadcastConnectionInfo(this.m_HostId, out str, out num5, out num4);
                 NetworkBroadcastResult result = new NetworkBroadcastResult {
                     serverAddress = str,
                     broadcastData = new byte[num3]
                 };
                 Buffer.BlockCopy(this.m_MsgInBuffer, 0, result.broadcastData, 0, num3);
                 this.m_BroadcastsReceived[str] = result;
                 this.OnReceivedBroadcast(str, BytesToString(this.m_MsgInBuffer));
             }
         }
         while (type != NetworkEventType.Nothing);
     }
 }
        void OnGUI()
        {
            if (!m_ShowGUI)
            {
                return;
            }

            int       xpos    = 10 + m_OffsetX;
            int       ypos    = 40 + m_OffsetY;
            const int spacing = 24;

            if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
            {
                GUI.Box(new Rect(xpos, ypos, 200, 20), "( WebGL cannot broadcast )");
                return;
            }

            if (m_MsgInBuffer == null)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Initialize Broadcast"))
                {
                    Initialize();
                }
                return;
            }
            string suffix = "";

            if (m_IsServer)
            {
                suffix = " (server)";
            }
            if (m_IsClient)
            {
                suffix = " (client)";
            }

            GUI.Label(new Rect(xpos, ypos, 200, 20), "initialized" + suffix);
            ypos += spacing;

            if (m_Running)
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Stop"))
                {
                    StopBroadcast();
                }
                ypos += spacing;

                if (m_BroadcastsReceived != null)
                {
                    if (m_BroadcastsReceived.Keys.Count > 0)
                    {
                        EnterButton.SetActive(true);
                        WaitingText.SetActive(false);
                        foreach (var addr in m_BroadcastsReceived.Keys)
                        {
                            value = m_BroadcastsReceived[addr];
                            if (GUI.Button(new Rect(xpos, ypos + 20, 200, 20), "Game at " + addr) && m_UseNetworkManager)
                            {
                                string dataString = BytesToString(value.broadcastData);
                                var    items      = dataString.Split(':');
                                if (items.Length == 3 && items[0] == "NetworkManager")
                                {
                                    if (NetworkManager.singleton != null && NetworkManager.singleton.client == null)
                                    {
                                        NetworkManager.singleton.networkAddress = value.serverAddress;
                                        NetworkManager.singleton.networkPort    = Convert.ToInt32(items[2]);
                                        NetworkManager.singleton.StartClient();
                                    }
                                }
                            }
                            ypos += spacing;
                        }
                    }
                    else
                    {
                        EnterButton.SetActive(false);
                        WaitingText.SetActive(true);
                    }
                }
            }
            else
            {
                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Start Broadcasting"))
                {
                    StartAsServer();
                }
                ypos += spacing;

                if (GUI.Button(new Rect(xpos, ypos, 200, 20), "Listen for Broadcast"))
                {
                    StartAsClient();
                }
                ypos += spacing;
            }
        }
 //decode data translates bytes recieved in data packet to original string.
 private string decodeData( NetworkBroadcastResult data)
 {
     return ( System.Text.Encoding.Unicode.GetString(data.broadcastData));
 }
示例#11
0
        private void OnGUI()
        {
            if (!m_ShowGUI)
            {
                return;
            }
            int num  = 10 + m_OffsetX;
            int num2 = 40 + m_OffsetY;

            if (m_MsgInBuffer == null)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Initialize Broadcast"))
                {
                    Initialize();
                }
                return;
            }
            string str = string.Empty;

            if (m_IsServer)
            {
                str = " (server)";
            }
            if (m_IsClient)
            {
                str = " (client)";
            }
            GUI.Label(new Rect(num, num2, 200f, 20f), "initialized" + str);
            num2 += 24;
            if (m_Running)
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Stop"))
                {
                    StopBroadcast();
                }
                num2 += 24;
                if (m_BroadcastsReceived != null)
                {
                    foreach (string key in m_BroadcastsReceived.Keys)
                    {
                        NetworkBroadcastResult networkBroadcastResult = m_BroadcastsReceived[key];
                        if (GUI.Button(new Rect(num, num2 + 20, 200f, 20f), "Game at " + key) && m_UseNetworkManager)
                        {
                            string   text  = BytesToString(networkBroadcastResult.broadcastData);
                            string[] array = text.Split(':');
                            if (array.Length == 3 && array[0] == "NetworkManager" && NetworkManager.singleton != null && NetworkManager.singleton.client == null)
                            {
                                NetworkManager.singleton.networkAddress = array[1];
                                NetworkManager.singleton.networkPort    = Convert.ToInt32(array[2]);
                                NetworkManager.singleton.StartClient();
                            }
                        }
                        num2 += 24;
                    }
                }
            }
            else
            {
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Start Broadcasting"))
                {
                    StartAsServer();
                }
                num2 += 24;
                if (GUI.Button(new Rect(num, num2, 200f, 20f), "Listen for Broadcast"))
                {
                    StartAsClient();
                }
            }
        }
示例#12
0
 private void OnGUI()
 {
     if (this.m_ShowGUI)
     {
         int num  = 10 + this.m_OffsetX;
         int num2 = 40 + this.m_OffsetY;
         if (this.m_MsgInBuffer == null)
         {
             if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Initialize Broadcast"))
             {
                 this.Initialize();
             }
         }
         else
         {
             string str = string.Empty;
             if (this.m_IsServer)
             {
                 str = " (server)";
             }
             if (this.m_IsClient)
             {
                 str = " (client)";
             }
             GUI.Label(new Rect((float)num, (float)num2, 200f, 20f), "initialized" + str);
             num2 += 0x18;
             if (this.m_Running)
             {
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Stop"))
                 {
                     this.StopBroadcast();
                 }
                 num2 += 0x18;
                 if (this.m_BroadcastsReceived != null)
                 {
                     foreach (string str2 in this.m_BroadcastsReceived.Keys)
                     {
                         NetworkBroadcastResult result = this.m_BroadcastsReceived[str2];
                         if (GUI.Button(new Rect((float)num, (float)(num2 + 20), 200f, 20f), "Game at " + str2) && this.m_UseNetworkManager)
                         {
                             char[]   separator = new char[] { ':' };
                             string[] strArray  = BytesToString(result.broadcastData).Split(separator);
                             if (((strArray.Length == 3) && (strArray[0] == "NetworkManager")) && ((NetworkManager.singleton != null) && (NetworkManager.singleton.client == null)))
                             {
                                 NetworkManager.singleton.networkAddress = strArray[1];
                                 NetworkManager.singleton.networkPort    = Convert.ToInt32(strArray[2]);
                                 NetworkManager.singleton.StartClient();
                             }
                         }
                         num2 += 0x18;
                     }
                 }
             }
             else
             {
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Start Broadcasting"))
                 {
                     this.StartAsServer();
                 }
                 num2 += 0x18;
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Listen for Broadcast"))
                 {
                     this.StartAsClient();
                 }
                 num2 += 0x18;
             }
         }
     }
 }
        private void OnGUI()
        {
            if (!this.m_ShowGUI)
            {
                return;
            }
            int num1 = 10 + this.m_OffsetX;
            int num2 = 40 + this.m_OffsetY;

            if (Application.platform == RuntimePlatform.WebGLPlayer)
            {
                GUI.Box(new Rect((float)num1, (float)num2, 200f, 20f), "( WebGL cannot broadcast )");
            }
            else if (this.m_MsgInBuffer == null)
            {
                if (!GUI.Button(new Rect((float)num1, (float)num2, 200f, 20f), "Initialize Broadcast"))
                {
                    return;
                }
                this.Initialize();
            }
            else
            {
                string str = string.Empty;
                if (this.m_IsServer)
                {
                    str = " (server)";
                }
                if (this.m_IsClient)
                {
                    str = " (client)";
                }
                GUI.Label(new Rect((float)num1, (float)num2, 200f, 20f), "initialized" + str);
                int num3 = num2 + 24;
                if (this.m_Running)
                {
                    if (GUI.Button(new Rect((float)num1, (float)num3, 200f, 20f), "Stop"))
                    {
                        this.StopBroadcast();
                    }
                    int num4 = num3 + 24;
                    if (this.m_BroadcastsReceived == null)
                    {
                        return;
                    }
                    using (Dictionary <string, NetworkBroadcastResult> .KeyCollection.Enumerator enumerator = this.m_BroadcastsReceived.Keys.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            string current = enumerator.Current;
                            NetworkBroadcastResult networkBroadcastResult = this.m_BroadcastsReceived[current];
                            if (GUI.Button(new Rect((float)num1, (float)(num4 + 20), 200f, 20f), "Game at " + current) && this.m_UseNetworkManager)
                            {
                                string[] strArray = NetworkDiscovery.BytesToString(networkBroadcastResult.broadcastData).Split(':');
                                if (strArray.Length == 3 && strArray[0] == "NetworkManager" && ((UnityEngine.Object)NetworkManager.singleton != (UnityEngine.Object)null && NetworkManager.singleton.client == null))
                                {
                                    NetworkManager.singleton.networkAddress = strArray[1];
                                    NetworkManager.singleton.networkPort    = Convert.ToInt32(strArray[2]);
                                    NetworkManager.singleton.StartClient();
                                }
                            }
                            num4 += 24;
                        }
                    }
                }
                else
                {
                    if (GUI.Button(new Rect((float)num1, (float)num3, 200f, 20f), "Start Broadcasting"))
                    {
                        this.StartAsServer();
                    }
                    int num4 = num3 + 24;
                    if (GUI.Button(new Rect((float)num1, (float)num4, 200f, 20f), "Listen for Broadcast"))
                    {
                        this.StartAsClient();
                    }
                    int num5 = num4 + 24;
                }
            }
        }
 private void Update()
 {
   if (this.m_HostId == -1 || this.m_IsServer)
     return;
   NetworkEventType fromHost;
   do
   {
     int connectionId;
     int channelId;
     int receivedSize;
     byte error;
     fromHost = NetworkTransport.ReceiveFromHost(this.m_HostId, out connectionId, out channelId, this.m_MsgInBuffer, 1024, out receivedSize, out error);
     if (fromHost == NetworkEventType.BroadcastEvent)
     {
       NetworkTransport.GetBroadcastConnectionMessage(this.m_HostId, this.m_MsgInBuffer, 1024, out receivedSize, out error);
       string address;
       int port;
       NetworkTransport.GetBroadcastConnectionInfo(this.m_HostId, out address, out port, out error);
       NetworkBroadcastResult networkBroadcastResult = new NetworkBroadcastResult();
       networkBroadcastResult.serverAddress = address;
       networkBroadcastResult.broadcastData = new byte[receivedSize];
       Buffer.BlockCopy((Array) this.m_MsgInBuffer, 0, (Array) networkBroadcastResult.broadcastData, 0, receivedSize);
       this.m_BroadcastsReceived[address] = networkBroadcastResult;
       this.OnReceivedBroadcast(address, NetworkDiscovery.BytesToString(this.m_MsgInBuffer));
     }
   }
   while (fromHost != NetworkEventType.Nothing);
 }
示例#15
0
 private void OnGUI()
 {
     if (this.m_ShowGUI)
     {
         int num  = 10 + this.m_OffsetX;
         int num2 = 40 + this.m_OffsetY;
         if (Application.platform == RuntimePlatform.WebGLPlayer)
         {
             GUI.Box(new Rect((float)num, (float)num2, 200f, 20f), "( WebGL cannot broadcast )");
         }
         else if (this.m_MsgInBuffer == null)
         {
             if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Initialize Broadcast"))
             {
                 this.Initialize();
             }
         }
         else
         {
             string str = "";
             if (this.m_IsServer)
             {
                 str = " (server)";
             }
             if (this.m_IsClient)
             {
                 str = " (client)";
             }
             GUI.Label(new Rect((float)num, (float)num2, 200f, 20f), "initialized" + str);
             num2 += 24;
             if (this.m_Running)
             {
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Stop"))
                 {
                     this.StopBroadcast();
                 }
                 num2 += 24;
                 if (this.m_BroadcastsReceived != null)
                 {
                     foreach (string text in this.m_BroadcastsReceived.Keys)
                     {
                         NetworkBroadcastResult networkBroadcastResult = this.m_BroadcastsReceived[text];
                         if (GUI.Button(new Rect((float)num, (float)(num2 + 20), 200f, 20f), "Game at " + text) && this.m_UseNetworkManager)
                         {
                             string   text2 = NetworkDiscovery.BytesToString(networkBroadcastResult.broadcastData);
                             string[] array = text2.Split(new char[]
                             {
                                 ':'
                             });
                             if (array.Length == 3 && array[0] == "NetworkManager")
                             {
                                 if (NetworkManager.singleton != null && NetworkManager.singleton.client == null)
                                 {
                                     NetworkManager.singleton.networkAddress = array[1];
                                     NetworkManager.singleton.networkPort    = Convert.ToInt32(array[2]);
                                     NetworkManager.singleton.StartClient();
                                 }
                             }
                         }
                         num2 += 24;
                     }
                 }
             }
             else
             {
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Start Broadcasting"))
                 {
                     this.StartAsServer();
                 }
                 num2 += 24;
                 if (GUI.Button(new Rect((float)num, (float)num2, 200f, 20f), "Listen for Broadcast"))
                 {
                     this.StartAsClient();
                 }
                 num2 += 24;
             }
         }
     }
 }
示例#16
0
        public void ServerInfo(string name, string address, int currentPlayer, int maxPlayer, UnityEngine.Networking.NetworkBroadcastResult value)
        {
            serverInfoText.text = address;
            slotInfo.text       = currentPlayer.ToString() + "/" + maxPlayer.ToString();

            joinButton.onClick.RemoveAllListeners();
            joinButton.onClick.AddListener(() => { JoinMatch(value, address); });
        }