Added basic connection functionality
							parent
							
								
									94ac9482d9
								
							
						
					
					
						commit
						a91e1b4f3c
					
				| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					[gd_scene load_steps=2 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ext_resource path="res://Scripts/RootNode.gd" type="Script" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="RootNode" type="Node"]
 | 
				
			||||||
 | 
					script = ExtResource( 1 )
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					extends Node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const MAX_PLAYERS : int = 2
 | 
				
			||||||
 | 
					const PORT : int = 9374
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ids = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _ready() -> void:
 | 
				
			||||||
 | 
						var peer : NetworkedMultiplayerENet = NetworkedMultiplayerENet.new()
 | 
				
			||||||
 | 
						peer.create_server( PORT, MAX_PLAYERS )
 | 
				
			||||||
 | 
						get_tree().set_network_peer( peer )
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						get_tree().connect("network_peer_connected", self, "_peer_connected")
 | 
				
			||||||
 | 
						get_tree().connect("network_peer_disconnected", self, "_peer_disconnected")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _peer_connected(id : int) -> void:
 | 
				
			||||||
 | 
						if not id:
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						ids.append(id)
 | 
				
			||||||
 | 
						print("Player has connected with id " + String(id))
 | 
				
			||||||
 | 
						# TODO: When we reach max players -> start the game
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _peer_disconnected(id : int) -> void:
 | 
				
			||||||
 | 
						ids.erase(id)
 | 
				
			||||||
 | 
						print("Player has disconnected with id " + String(id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Called every frame. 'delta' is the elapsed time since the previous frame.
 | 
				
			||||||
 | 
					#func _process(delta):
 | 
				
			||||||
 | 
					#	pass
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					[gd_resource type="Environment" load_steps=2 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="ProceduralSky" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[resource]
 | 
				
			||||||
 | 
					background_mode = 2
 | 
				
			||||||
 | 
					background_sky = SubResource( 1 )
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					[remap]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					importer="texture"
 | 
				
			||||||
 | 
					type="StreamTexture"
 | 
				
			||||||
 | 
					path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
 | 
				
			||||||
 | 
					metadata={
 | 
				
			||||||
 | 
					"vram_texture": false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[deps]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					source_file="res://icon.png"
 | 
				
			||||||
 | 
					dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[params]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					compress/mode=0
 | 
				
			||||||
 | 
					compress/lossy_quality=0.7
 | 
				
			||||||
 | 
					compress/hdr_mode=0
 | 
				
			||||||
 | 
					compress/bptc_ldr=0
 | 
				
			||||||
 | 
					compress/normal_map=0
 | 
				
			||||||
 | 
					flags/repeat=0
 | 
				
			||||||
 | 
					flags/filter=true
 | 
				
			||||||
 | 
					flags/mipmaps=false
 | 
				
			||||||
 | 
					flags/anisotropic=false
 | 
				
			||||||
 | 
					flags/srgb=2
 | 
				
			||||||
 | 
					process/fix_alpha_border=true
 | 
				
			||||||
 | 
					process/premult_alpha=false
 | 
				
			||||||
 | 
					process/HDR_as_SRGB=false
 | 
				
			||||||
 | 
					process/invert_color=false
 | 
				
			||||||
 | 
					stream=false
 | 
				
			||||||
 | 
					size_limit=0
 | 
				
			||||||
 | 
					detect_3d=true
 | 
				
			||||||
 | 
					svg/scale=1.0
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					; Engine configuration file.
 | 
				
			||||||
 | 
					; It's best edited using the editor UI and not directly,
 | 
				
			||||||
 | 
					; since the parameters that go here are not all obvious.
 | 
				
			||||||
 | 
					;
 | 
				
			||||||
 | 
					; Format:
 | 
				
			||||||
 | 
					;   [section] ; section goes between []
 | 
				
			||||||
 | 
					;   param=value ; assign values to parameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config_version=4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_global_script_classes=[  ]
 | 
				
			||||||
 | 
					_global_script_class_icons={
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[application]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config/name="Server"
 | 
				
			||||||
 | 
					run/main_scene="res://Scenes/RootNode.tscn"
 | 
				
			||||||
 | 
					config/icon="res://icon.png"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[rendering]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					environment/default_environment="res://default_env.tres"
 | 
				
			||||||
		Loading…
	
		Reference in New Issue