summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/GameDiscovery.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/GameDiscovery.cs')
-rw-r--r--Client/Assembly-CSharp/GameDiscovery.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/GameDiscovery.cs b/Client/Assembly-CSharp/GameDiscovery.cs
new file mode 100644
index 0000000..5742e43
--- /dev/null
+++ b/Client/Assembly-CSharp/GameDiscovery.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Hazel.Udp;
+using InnerNet;
+using UnityEngine;
+
+public class GameDiscovery : MonoBehaviour
+{
+ public JoinGameButton ButtonPrefab;
+
+ public Transform ItemLocation;
+
+ public float YStart = 0.56f;
+
+ public float YOffset = -0.75f;
+
+ private Dictionary<string, JoinGameButton> received = new Dictionary<string, JoinGameButton>();
+
+ public void Start()
+ {
+ InnerDiscover component = base.GetComponent<InnerDiscover>();
+ component.OnPacketGet += this.Receive;
+ component.StartAsClient();
+ }
+
+ public void Update()
+ {
+ float time = Time.time;
+ string[] array = this.received.Keys.ToArray<string>();
+ int num = 0;
+ foreach (string key in array)
+ {
+ JoinGameButton joinGameButton = this.received[key];
+ if (time - joinGameButton.timeRecieved > 3f)
+ {
+ this.received.Remove(key);
+ UnityEngine.Object.Destroy(joinGameButton.gameObject);
+ }
+ else
+ {
+ joinGameButton.transform.localPosition = new Vector3(0f, this.YStart + (float)num * this.YOffset, -1f);
+ num++;
+ }
+ }
+ }
+
+ private void Receive(BroadcastPacket packet)
+ {
+ string[] array = packet.Data.Split(new char[]
+ {
+ '~'
+ });
+ string address = packet.GetAddress();
+ JoinGameButton joinGameButton;
+ if (this.received.TryGetValue(address, out joinGameButton))
+ {
+ joinGameButton.timeRecieved = Time.time;
+ joinGameButton.SetGameName(array);
+ return;
+ }
+ if (array[1].Equals("Open"))
+ {
+ this.CreateButtonForAddess(address, array);
+ }
+ }
+
+ private void CreateButtonForAddess(string fromAddress, string[] gameNameParts)
+ {
+ JoinGameButton joinGameButton;
+ if (this.received.TryGetValue(fromAddress, out joinGameButton))
+ {
+ UnityEngine.Object.Destroy(joinGameButton.gameObject);
+ }
+ JoinGameButton joinGameButton2 = UnityEngine.Object.Instantiate<JoinGameButton>(this.ButtonPrefab, this.ItemLocation);
+ joinGameButton2.transform.localPosition = new Vector3(0f, this.YStart + (float)(this.ItemLocation.childCount - 1) * this.YOffset, -1f);
+ joinGameButton2.netAddress = fromAddress;
+ joinGameButton2.timeRecieved = Time.time;
+ joinGameButton2.SetGameName(gameNameParts);
+ joinGameButton2.GetComponentInChildren<MeshRenderer>().material.SetInt("_Mask", 4);
+ this.received[fromAddress] = joinGameButton2;
+ }
+}