Newer
Older
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
using System;
using System.Collections;
using System.Diagnostics;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using static CommunicationEvents;
public class CheckServer : MonoBehaviour
{
[SerializeField]
TMPro.TextMeshProUGUI WaitingText;
public static Process process;
public static ProcessStartInfo processInfo;
// Start is called before the first frame update
void Start()
{
//CommunicationEvents.ServerRunning = false;
//StartCoroutine(ServerRoutine());
StartCoroutine(waiter(CommunicationEvents.lastIP, 1, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.newIP, 2, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot1, 3, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration));
StartCoroutine(waiter(CommunicationEvents.IPslot3, 6, CommunicationEvents.IPcheckGeneration));
}
public void CheckIPAdr()
{
//CommunicationEvents.ServerRunning = false;
//StartCoroutine(ServerRoutine());
//CommunicationEvents.IPcheckGeneration++;
//StartCoroutine(waiter(CommunicationEvents.lastIP, 1, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.newIP, 2, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.IPslot1, 3, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.IPslot2, 4, CommunicationEvents.IPcheckGeneration));
//StartCoroutine(waiter(CommunicationEvents.IPslot3, 5, CommunicationEvents.IPcheckGeneration));
}
IEnumerator waiter(String NetwAddress, int NA_id, double ics)
{
//while(CommunicationEvents.IPcheckGeneration== ics)
//Wait for 1 seconds
yield return new WaitForSecondsRealtime(1f);
if(CommunicationEvents.CheckServerA[NA_id] == 1)
{
CommunicationEvents.CheckServerA[NA_id] = 0;
switch (NA_id){
case 1:
NetwAddress = CommunicationEvents.lastIP;
break;
case 2:
NetwAddress = CommunicationEvents.newIP;
break;
case 3:
NetwAddress = CommunicationEvents.IPslot1;
break;
case 4:
NetwAddress = CommunicationEvents.IPslot2;
break;
case 5:
NetwAddress = CommunicationEvents.IPslot3;
break;
case 6:
NetwAddress = CommunicationEvents.selecIP;
break;
//default:
if (string.IsNullOrEmpty(NetwAddress))
//Wait for 1 seconds
CommunicationEvents.ServerRunningA[NA_id] = 3;
yield return new WaitForSecondsRealtime(1f);
}
else
{
StartCheck(NetwAddress, NA_id, ics);
//Wait for 0,5 seconds
yield return new WaitForSecondsRealtime(0.5f);
if (CommunicationEvents.IPcheckGeneration <= ics || (NA_id != 6))// && NA_id != 2))
//if (CommunicationEvents.IPcheckGeneration < ics) { break; }
if (CommunicationEvents.ServerRunningA_test[NA_id] == true)
{
CommunicationEvents.ServerRunningA[NA_id] = 2;
}
else
{
CommunicationEvents.ServerRunningA[NA_id] = 0;
}
//Wait for 0,5 seconds
yield return new WaitForSecondsRealtime(0.5f);
}
CommunicationEvents.IPcheckGeneration--;
if (NA_id == 2)
{
CommunicationEvents.ServerRunningA[NA_id] = 1;
//Wait for 0,5 seconds
yield return new WaitForSecondsRealtime(0.5f);
}
}
}
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
}
}
}
public void StartCheck(String NetwAddress, int NA_id, double ics)
{
CommunicationEvents.ServerRunningA_test[NA_id] = false;
StartCoroutine(ServerRoutine(NetwAddress, NA_id, ics));
}
void PrepareGame()
{
//WaitingText.text = "Press any key to start the game";
//CommunicationEvents.ServerRunning_test = true;
//UnityEngine.Debug.Log("server fin");
}
IEnumerator ServerRoutine(String NetwAddress, int NA_id, double ics)
{
UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
UnityEngine.Debug.Log("no running server " + request.error);
while (true)
{
request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError)
{
// UnityEngine.Debug.Log("no running server");
}
else
{
break;
}
yield return null;
}
}
//PrepareGame();
if (CommunicationEvents.IPcheckGeneration == ics || (NA_id!=6))// && NA_id!=2))
{
CommunicationEvents.ServerRunningA_test[NA_id] = true;
}
yield return null;
}
void Update()
{
}
}