-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEO_client.py
71 lines (62 loc) · 1.76 KB
/
EO_client.py
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
from bge import logic
import EO_network as n
import time
from EO_config import GameConfig
"""
the property "connection" can be
-"offline" never tried to connect
-"connecting" trying to connect
-"active" is connected
-"failed" failed to connect
"""
cont = logic.getCurrentController()
own = cont.owner
own["EO_connection"] = "connecting"
ip = own["EO_IP"]
port = own["EO_PORT"]
timeout = own["EO_TIMEOUT"]
con_time = own["EO_CONNECT_TIME"]
cfg = GameConfig(timeout, "Client", own["EO_NAME"])
NF = n.NetworkFactory(cfg)
start = time.time()
client = None
endGame = False
def main():
global client
if client:
if client.isRunning():
cfg.check_global_dict()
cfg.make_transmissions()
client.main()
own["EO_PING"] = client.ping
own["EO_PLAYERS"] = client.clients_connected
else:
if endGame:
logic.endGame()
else:
if time.time()-start < con_time:
client = NF.connect(ip, port, 1.5)
if client != None:
own["EO_connection"] = "active"
try:
import bpy
bpy.EO_client = client # when exiting bge not properly, still want the client to leave
except:
pass # standalone no worries
else:
own["EO_connection"] = "failed"
def disconnect(cont):
if client:
client.disconnect()
def disconnect_and_close(cont):
if cont.sensors[0].positive:
if client:
client.disconnect()
global endGame
endGame = True
else:
logic.endGame()
def reconnect(cont):
if client:
start = time.time()
own["EO_connection"] = "connecting"