summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/GameDiscovery.cs
blob: 5742e432d4b4b6688fba43208d72f919acd7ea51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
	}
}