about summary refs log tree commit diff stats
path: root/data/maps/demo/rooms/Center Building.txtpb
diff options
context:
space:
mode:
Diffstat (limited to 'data/maps/demo/rooms/Center Building.txtpb')
0 files changed, 0 insertions, 0 deletions
f4b7635ec3fa67c'>6fd6d49 ^
6fd6d49 ^







6fd6d49 ^


6fd6d49 ^
53e0509 ^
7f5f14d ^

6fd6d49 ^
b524e15 ^
53e0509 ^
99191f3 ^
6fd6d49 ^


7ee253c ^
05827d2 ^




b524e15 ^

53e0509 ^
b0f474b ^
6fd6d49 ^


cc58fb2 ^

6fd6d49 ^

6fd6d49 ^

05827d2 ^





6fd6d49 ^



7f5f14d ^

53e0509 ^
b524e15 ^
53e0509 ^
99191f3 ^
6fd6d49 ^

05827d2 ^

6fd6d49 ^
6fd6d49 ^
05827d2 ^



6fd6d49 ^
6fd6d49 ^
05827d2 ^








6fd6d49 ^
6fd6d49 ^
05827d2 ^






6fd6d49 ^
05827d2 ^


6fd6d49 ^
05827d2 ^





05827d2 ^
6fd6d49 ^
b524e15 ^

ff125bf ^
b524e15 ^
05827d2 ^
6fd6d49 ^
05827d2 ^


6fd6d49 ^
b524e15 ^







53e0509 ^







05827d2 ^





6fd6d49 ^
05827d2 ^
6fd6d49 ^
05827d2 ^

6fd6d49 ^
05827d2 ^
6fd6d49 ^
05827d2 ^




6fd6d49 ^
05827d2 ^

6fd6d49 ^
05827d2 ^


797cf68 ^
05827d2 ^
6fd6d49 ^
b524e15 ^

53e0509 ^
b524e15 ^



53e0509 ^



99191f3 ^

b524e15 ^

b0f474b ^






b53d1f9 ^





6fd6d49 ^
05827d2 ^





6fd6d49 ^
05827d2 ^
6fd6d49 ^
05827d2 ^
6fd6d49 ^
6fd6d49 ^
05827d2 ^


6fd6d49 ^


05827d2 ^
6fd6d49 ^







6fd6d49 ^




6fd6d49 ^







a54edd2 ^



6fd6d49 ^







067d8e7 ^



b0f474b ^



53e0509 ^




b53d1f9 ^







2125ccf ^



6fd6d49 ^

7f5f14d ^



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275



                                                                           
                          
 
           
                           







                                                          


              
                           
                            

                          
                   
                              
                               
                            


                        
                                  




                                                                                    

                                   
                                 
                               


             

                                                  

                                              

              





                                                                                      



                               

                              
                                
                                  
                                   
                                

 

                                            
 
 



                                                                                                    
 
 








                                                                                   
 
 






                                                                                      
 


                                                         
 





                                                                   
                                                         
 

                                                                     
                                                                        
 
                                                         
 


                                                                 
 







                                                                       







                                                                        





                                                                  
 
                                                               
 

                                                                                              
 
                                                                                  
 




                                                                   
 

                                                   
 


                                                             
                                                                                                                       
                                 
 

                                                     
                                                      



                                                                      



                                                                                   

                                                                           

                                                           






                                                                       





                                                                                              
 





                                                                                         
 
                              
 
                                            
 
 


                                         


                     
                                                







                                                    




                         







                                                                       



                                                                      







                                                                           



                                                                      



                                                                     




                                                                            







                                                         



                                      

                                           



                                              
extends Node

const ap_version = {"major": 0, "minor": 6, "build": 3, "class": "Version"}

var SCRIPT_websocketserver

var _server
var _should_process = false

var _remote_version = {"major": 0, "minor": 0, "build": 0}
var _gen_version = {"major": 0, "minor": 0, "build": 0}

var ap_server = ""
var ap_user = ""
var ap_pass = ""

var _seed = ""
var _team = 0
var _slot = 0
var _checked_locations = []
var _checked_worldports = []
var _received_indexes = []
var _received_items = {}
var _slot_data = {}
var _accessible_locations = []
var _accessible_worldports = []
var _goal_accessible = false

signal could_not_connect
signal connect_status
signal client_connected(slot_data)
signal item_received(item, amount)
signal location_scout_received(location_id, item_name, player_name, flags, for_self)
signal text_message_received(message)
signal item_sent_notification(message)
signal hint_received(message)
signal accessible_locations_updated
signal checked_locations_updated
signal checked_worldports_updated
signal keyboard_update_received


func _init():
	set_process_mode(Node.PROCESS_MODE_ALWAYS)

	global._print("Instantiated APClient")


func _ready():
	_server = SCRIPT_websocketserver.new()
	_server.client_connected.connect(_on_web_socket_server_client_connected)
	_server.client_disconnected.connect(_on_web_socket_server_client_disconnected)
	_server.message_received.connect(_on_web_socket_server_message_received)
	add_child(_server)
	_server.listen(43182)


func _reset_state():
	_should_process = false
	_received_items = {}
	_received_indexes = []
	_checked_worldports = []
	_accessible_locations = []
	_accessible_worldports = []
	_goal_accessible = false


func disconnect_from_ap():
	sendMessage([{"cmd": "Disconnect"}])


func _on_web_socket_server_client_connected(peer_id: int) -> void:
	var peer: WebSocketPeer = _server.peers[peer_id]
	print("Remote client connected: %d. Protocol: %s" % [peer_id, peer.get_selected_protocol()])
	_server.send(-peer_id, "[%d] connected" % peer_id)


func _on_web_socket_server_client_disconnected(peer_id: int) -> void:
	var peer: WebSocketPeer = _server.peers[peer_id]
	print(
		(
			"Remote client disconnected: %d. Code: %d, Reason: %s"
			% [peer_id, peer.get_close_code(), peer.get_close_reason()]
		)
	)
	_server.send(-peer_id, "[%d] disconnected" % peer_id)


func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> void:
	global._print("Got data from server: " + packet)
	var json = JSON.new()
	var jserror = json.parse(packet)
	if jserror != OK:
		global._print("Error parsing packet from AP: " + jserror.error_string)
		return

	for message in json.data:
		var cmd = message["cmd"]
		global._print("Received command: " + cmd)

		if cmd == "Connected":
			_seed = message["seed_name"]
			_remote_version = message["version"]
			_gen_version = message["generator_version"]
			_team = message["team"]
			_slot = message["slot"]
			_slot_data = message["slot_data"]

			_checked_locations = []
			for location in message["checked_locations"]:
				_checked_locations.append(int(location))

			client_connected.emit(_slot_data)

		elif cmd == "ConnectionRefused":
			could_not_connect.emit(message["text"])
			global._print("Connection to AP refused")

		elif cmd == "UpdateLocations":
			for location in message["locations"]:
				var lint = int(location)
				if not _checked_locations.has(lint):
					_checked_locations.append(lint)

			checked_locations_updated.emit()

		elif cmd == "UpdateWorldports":
			for port_id in message["worldports"]:
				var lint = int(port_id)
				if not _checked_worldports.has(lint):
					_checked_worldports.append(lint)

			checked_worldports_updated.emit()

		elif cmd == "ItemReceived":
			for item in message["items"]:
				var index = int(item["index"])
				if _received_indexes.has(index):
					# Do not re-process items.
					continue

				_received_indexes.append(index)

				var item_id = int(item["id"])
				_received_items[item_id] = _received_items.get(item_id, 0) + 1

				item_received.emit(item, _received_items[item_id])

		elif cmd == "TextMessage":
			text_message_received.emit(message["data"])

		elif cmd == "ItemSentNotif":
			item_sent_notification.emit(message)

		elif cmd == "HintReceived":
			hint_received.emit(message)

		elif cmd == "LocationInfo":
			for loc in message["locations"]:
				location_scout_received.emit(
					int(loc["id"]), loc["item"], loc["player"], int(loc["flags"]), int(loc["self"])
				)

		elif cmd == "AccessibleLocations":
			_accessible_locations.clear()
			_accessible_worldports.clear()

			for loc in message["locations"]:
				_accessible_locations.append(int(loc))

			if "worldports" in message:
				for port_id in message["worldports"]:
					_accessible_worldports.append(int(port_id))

			_goal_accessible = bool(message.get("goal", false))

			accessible_locations_updated.emit()

		elif cmd == "UpdateKeyboard":
			var updates = {}
			for k in message["updates"]:
				updates[k] = int(message["updates"][k])

			keyboard_update_received.emit(updates)

		elif cmd == "PathReply":
			var textclient = global.get_node("Textclient")
			textclient.display_logical_path(
				message["type"], int(message.get("id", null)), message["path"]
			)


func connectToServer(server, un, pw):
	sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}])

	ap_server = server
	ap_user = un
	ap_pass = pw

	_should_process = true

	connect_status.emit("Connecting...")


func sendMessage(msg):
	var payload = JSON.stringify(msg)
	_server.send(0, payload)


func connectToRoom():
	connect_status.emit("Authenticating...")

	sendMessage(
		[
			{
				"cmd": "Connect",
				"password": ap_pass,
				"game": "Lingo 2",
				"name": ap_user,
			}
		]
	)


func requestSync():
	sendMessage([{"cmd": "Sync"}])


func sendLocation(loc_id):
	sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}])


func sendLocations(loc_ids):
	sendMessage([{"cmd": "LocationChecks", "locations": loc_ids}])


func say(textdata):
	sendMessage([{"cmd": "Say", "text": textdata}])


func completedGoal():
	sendMessage([{"cmd": "StatusUpdate", "status": 30}])  # CLIENT_GOAL


func scoutLocations(loc_ids):
	sendMessage([{"cmd": "LocationScouts", "locations": loc_ids}])


func updateKeyboard(updates):
	sendMessage([{"cmd": "UpdateKeyboard", "keyboard": updates}])


func checkWorldport(port_id):
	if not _checked_worldports.has(port_id):
		sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}])


func getLogicalPath(object_type, object_id):
	var msg = {"cmd": "GetPath", "type": object_type}
	if object_id != null:
		msg["id"] = object_id

	sendMessage([msg])


func sendQuit():
	sendMessage([{"cmd": "Quit"}])


func hasItem(item_id):
	return _received_items.has(item_id)


func getItemAmount(item_id):
	return _received_items.get(item_id, 0)