started server password and connection rework
This commit is contained in:
parent
7012ffb313
commit
edc9966a8e
|
@ -5,12 +5,7 @@ const DEFAULT_PORT = 31400
|
|||
const MAX_PLAYERS = 50
|
||||
|
||||
var ip = ''
|
||||
var players = { }
|
||||
var self_data : Dictionary = { name = '', password = ''}
|
||||
var password = ''
|
||||
var ongoingQry = false
|
||||
var lastRequest = ''
|
||||
var serverpassword = " "
|
||||
var serverPassword = ""
|
||||
|
||||
signal player_disconnected
|
||||
signal server_disconnected
|
||||
|
@ -18,46 +13,29 @@ signal server_disconnected
|
|||
func _ready():
|
||||
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
|
||||
get_tree().connect('network_peer_connected', self, '_on_player_connected')
|
||||
connect_to_server("name","","")
|
||||
|
||||
func connect_to_server(playerName,pw,serverpassword):
|
||||
self.serverpassword = serverpassword
|
||||
self_data.name = playerName
|
||||
self_data.password = pw
|
||||
func connect_to_server(givenServerPassword):
|
||||
serverPassword = givenServerPassword
|
||||
var peer = NetworkedMultiplayerENet.new()
|
||||
if ip == '':
|
||||
ip = DEFAULT_IP
|
||||
peer.create_client(ip, DEFAULT_PORT)
|
||||
if peer.create_client(ip, DEFAULT_PORT) == OK:
|
||||
get_tree().set_network_peer(peer)
|
||||
# PlayerManager.authcache['password']=pw
|
||||
# PlayerManager.authcache['playername']=playerName
|
||||
|
||||
func _connected_to_server():
|
||||
var local_player_id = get_tree().get_network_unique_id()
|
||||
players[local_player_id] = self_data
|
||||
rpc('checkServerPassword',serverpassword) # not implemented yet
|
||||
|
||||
print(">>>> CONNECTED TO SERVER <<<<<")
|
||||
|
||||
rpc_id(1, '_request_auth', local_player_id, self_data)# anstatt playerName und pw -> self_data
|
||||
rpc('_send_player_info', local_player_id, self_data) # requests all player in the current session
|
||||
else:
|
||||
print("invalid ip/ no server at ip")
|
||||
|
||||
func _on_player_disconnected(id):
|
||||
players.erase(id)
|
||||
PlayerManager.player_disconnected(id)
|
||||
|
||||
func _on_player_connected(connected_player_id):
|
||||
var local_player_id = get_tree().get_network_unique_id()
|
||||
rpc_id(1, '_request_player_info', local_player_id, connected_player_id)
|
||||
|
||||
remote func _requestClientServerpassword():
|
||||
rpc_id(1,'_returnClientServerPassword',serverPassword)
|
||||
|
||||
remote func _receive_auth(response):
|
||||
print('Client -> _receive_auth erreicht')
|
||||
PlayerManager.receiveAuth(response)
|
||||
WorldManager.requestMapfromServer()
|
||||
WorldManager._load_worldmap()
|
||||
#print(response)
|
||||
|
||||
|
||||
remote func _send_player_info(id, info):
|
||||
players[id] = info
|
||||
remote func _passwordReturn(correct):
|
||||
if correct:
|
||||
print("correct server password")
|
||||
else:
|
||||
print("wrong server password")
|
||||
|
|
|
@ -107,8 +107,4 @@ remote func receiveAuth(response):
|
|||
# if authcache.response.has('faction'):
|
||||
# myFactionData = response.faction
|
||||
# #to do: remove accesses to redundant data and then erase redundant data
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,36 +1,14 @@
|
|||
extends Control
|
||||
|
||||
var player_name = "Judas"
|
||||
var pw = "pw"
|
||||
|
||||
|
||||
func _on_Input_Name_text_changed(new_text):
|
||||
self.player_name = new_text
|
||||
|
||||
var serverPassword = ""
|
||||
|
||||
func _on_Input_PW_text_changed(new_text):
|
||||
self.pw = new_text
|
||||
serverPassword = new_text
|
||||
|
||||
|
||||
func _on_Input_IP_text_changed(new_text):
|
||||
Network.ip = new_text
|
||||
|
||||
|
||||
func _on_Join_pressed():# change this to check on the server user data login information
|
||||
if player_name == '':
|
||||
print('PlayerName empty')
|
||||
return
|
||||
|
||||
var _serverpassword = "myPW"
|
||||
Network.connect_to_server(player_name,pw,_serverpassword)
|
||||
|
||||
|
||||
#_load_game()
|
||||
|
||||
|
||||
func _on_register_pressed():
|
||||
get_tree().change_scene('res://menues/RegisterPlayerMenu.tscn')
|
||||
|
||||
|
||||
func _load_game():
|
||||
get_tree().change_scene('res://Worldmap.tscn')
|
||||
Network.connect_to_server(serverPassword)
|
||||
#if server exists -> load seperate menu to create name select faction etc etc
|
||||
|
|
|
@ -48,57 +48,32 @@ margin_right = 1919.0
|
|||
margin_bottom = 1021.04
|
||||
alignment = 1
|
||||
script = SubResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="lblMenuTitle" type="Label" parent="VBoxContainer"]
|
||||
margin_top = 203.0
|
||||
margin_top = 265.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 322.0
|
||||
margin_bottom = 384.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
text = "Menue"
|
||||
text = "Server Beitreten"
|
||||
align = 1
|
||||
|
||||
[node name="HBoxPlayerName" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 326.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 445.0
|
||||
alignment = 1
|
||||
|
||||
[node name="lblPlayerName" type="Label" parent="VBoxContainer/HBoxPlayerName"]
|
||||
margin_left = 618.0
|
||||
margin_right = 797.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
text = "Name"
|
||||
valign = 1
|
||||
|
||||
[node name="Input_Name" type="LineEdit" parent="VBoxContainer/HBoxPlayerName"]
|
||||
margin_left = 801.0
|
||||
margin_right = 1301.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
align = 2
|
||||
max_length = 16
|
||||
|
||||
[node name="HBoxPassword" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 449.0
|
||||
margin_top = 388.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 568.0
|
||||
margin_bottom = 507.0
|
||||
alignment = 1
|
||||
|
||||
[node name="lblPassword" type="Label" parent="VBoxContainer/HBoxPassword"]
|
||||
margin_left = 557.0
|
||||
margin_right = 858.0
|
||||
margin_left = 443.0
|
||||
margin_right = 971.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
text = "Passwort"
|
||||
text = "Server Passwort"
|
||||
valign = 1
|
||||
|
||||
[node name="iptPassword" type="LineEdit" parent="VBoxContainer/HBoxPassword"]
|
||||
margin_left = 862.0
|
||||
margin_right = 1362.0
|
||||
margin_left = 975.0
|
||||
margin_right = 1475.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
text = "pw"
|
||||
|
@ -107,49 +82,40 @@ max_length = 16
|
|||
secret = true
|
||||
|
||||
[node name="HBoxIP" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 572.0
|
||||
margin_top = 511.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 691.0
|
||||
margin_bottom = 630.0
|
||||
alignment = 1
|
||||
|
||||
[node name="lblIP" type="Label" parent="VBoxContainer/HBoxIP"]
|
||||
margin_left = 679.0
|
||||
margin_right = 735.0
|
||||
margin_left = 563.0
|
||||
margin_right = 852.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
text = "IP"
|
||||
text = "Server-IP"
|
||||
valign = 1
|
||||
|
||||
[node name="iptIP" type="LineEdit" parent="VBoxContainer/HBoxIP"]
|
||||
margin_left = 739.0
|
||||
margin_right = 1239.0
|
||||
margin_left = 856.0
|
||||
margin_right = 1356.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
align = 2
|
||||
max_length = 16
|
||||
|
||||
[node name="HBoxButtons" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 695.0
|
||||
margin_top = 634.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 820.0
|
||||
margin_bottom = 759.0
|
||||
alignment = 1
|
||||
|
||||
[node name="btnJoin" type="Button" parent="VBoxContainer/HBoxButtons"]
|
||||
margin_left = 586.0
|
||||
margin_right = 926.0
|
||||
margin_left = 789.0
|
||||
margin_right = 1129.0
|
||||
margin_bottom = 125.0
|
||||
custom_fonts/font = SubResource( 3 )
|
||||
text = " Beitreten "
|
||||
|
||||
[node name="btnRegister" type="Button" parent="VBoxContainer/HBoxButtons"]
|
||||
margin_left = 930.0
|
||||
margin_right = 1333.0
|
||||
margin_bottom = 125.0
|
||||
custom_fonts/font = SubResource( 3 )
|
||||
text = "Registrieren"
|
||||
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxPlayerName/Input_Name" to="." method="_on_Input_Name_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxPassword/iptPassword" to="." method="_on_Input_PW_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxIP/iptIP" to="." method="_on_Input_IP_text_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxButtons/btnJoin" to="." method="_on_Join_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxButtons/btnRegister" to="." method="_on_register_pressed"]
|
||||
|
|
|
@ -75,7 +75,7 @@ func unitSelectedMethod(unit, debugOriginUnit):#this is called when a unit is se
|
|||
if unit.id != selectedUnit.id:
|
||||
unit.isSelected = false
|
||||
$TileMap/LineManager.drawAdvancedLine([],[],0,0)
|
||||
print(selectedUnit)
|
||||
# print(selectedUnit)
|
||||
|
||||
func _input(event):#this responds to any input. Has various functions depending on input
|
||||
if selectedUnit != null:
|
||||
|
@ -262,7 +262,7 @@ func _on_pathAnimationCompleted():#this gets a signal from the selected unit and
|
|||
requestTiles()
|
||||
requestUnits()
|
||||
resetPathing()
|
||||
print(boardUnits)
|
||||
# print(boardUnits)
|
||||
animationInProgress = false
|
||||
selectedUnit = null
|
||||
|
||||
|
|
|
@ -16,10 +16,6 @@ signal server_disconnected
|
|||
func _ready():
|
||||
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
|
||||
get_tree().connect('network_peer_connected', self, '_on_player_connected')
|
||||
create_server()
|
||||
|
||||
remote func TESTFUNCTION(string):
|
||||
print(string)
|
||||
|
||||
remote func checkServerPassword(serverPassword):
|
||||
if (serverPassword=="myPW"):
|
||||
|
@ -27,14 +23,16 @@ remote func checkServerPassword(serverPassword):
|
|||
else:
|
||||
print("ServerPassword falsch")
|
||||
|
||||
func create_server():
|
||||
func createServer(password):
|
||||
pw = password
|
||||
print("a")
|
||||
print(pw)
|
||||
players[1] = self_data
|
||||
var peer = NetworkedMultiplayerENet.new()
|
||||
peer.create_server(DEFAULT_PORT, MAX_PLAYERS)
|
||||
get_tree().set_network_peer(peer)
|
||||
var host = NetworkedMultiplayerENet.new()
|
||||
host.create_server(DEFAULT_PORT, MAX_PLAYERS)
|
||||
get_tree().set_network_peer(host)
|
||||
set_network_master(1)
|
||||
|
||||
|
||||
#function that creates needed files and directories in user
|
||||
#To do: copy preset folder to user, handling should be uniform
|
||||
func firstStart():
|
||||
|
@ -63,21 +61,26 @@ func _on_player_disconnected(id):
|
|||
# PlayerManager.player_disconnected(id)
|
||||
|
||||
func _on_player_connected(connected_player_id):
|
||||
print(">>>>>>>>>>> on player connected <<<<<<<<<<<<< ", connected_player_id)
|
||||
var local_player_id = get_tree().get_network_unique_id()
|
||||
if not(get_tree().is_network_server()):
|
||||
rpc_id(1, '_request_player_info', local_player_id, connected_player_id)
|
||||
print('get_tree().is_network_server() is not')
|
||||
print(connected_player_id," connected")
|
||||
request_player_info(connected_player_id)
|
||||
|
||||
#method called from client to server to be identified.
|
||||
remote func _request_auth(id, userData):
|
||||
print(">>>>> WE REQUESTED AUTH <<<<<<<")
|
||||
var response = PlayerManager.identifyPlayer(userData['name'], userData['password'])
|
||||
print('Server -> _request_auth ' + response)
|
||||
rpc_id(id, 'receiveAuth', response)
|
||||
func addPlayer(id, name):
|
||||
pass
|
||||
|
||||
remote func _request_player_info(request_from_id, player_id):
|
||||
rpc_id(request_from_id, '_send_player_info', player_id, players[player_id])
|
||||
var awaitingConfirmation = []
|
||||
|
||||
func request_player_info(connected_player_id):
|
||||
awaitingConfirmation.append(connected_player_id)
|
||||
rpc_id(connected_player_id, '_requestClientServerpassword')
|
||||
|
||||
remote func _returnClientServerPassword(password):
|
||||
var clientId=multiplayer.get_remote_sender_id()
|
||||
if awaitingConfirmation.has(clientId):
|
||||
if password == pw:
|
||||
rpc_id(clientId, "_validPassword")
|
||||
addPlayer(clientId,"replaceMe")
|
||||
else:
|
||||
rpc_id(clientId, "fail")
|
||||
|
||||
# A function to be used if needed. The purpose is to request all players in the current session.
|
||||
remote func _request_players(request_from_id):
|
||||
|
|
|
@ -1,39 +1,25 @@
|
|||
extends Control
|
||||
|
||||
var player_name = "Judas"
|
||||
var pw = "pw"
|
||||
|
||||
|
||||
func _on_Input_Name_text_changed(new_text):
|
||||
player_name = new_text
|
||||
|
||||
var pw = ""
|
||||
|
||||
func _on_Input_PW_text_changed(new_text):
|
||||
pw = new_text
|
||||
|
||||
|
||||
func _on_Input_IP_text_changed(new_text):
|
||||
Network.ip = new_text
|
||||
|
||||
|
||||
func _on_Host_pressed():
|
||||
if player_name == "":
|
||||
return
|
||||
# return
|
||||
var file = File.new()
|
||||
if not file.file_exists("user://server.txt"):
|
||||
Network.firstStart()
|
||||
Network.create_server()
|
||||
#Network.create_server(PlayerManager.identify_player(player_name,pw))
|
||||
#workaround to simulate remote player for simpler testing:
|
||||
Network.createServer(pw)
|
||||
# Network.create_server(PlayerManager.identify_player(player_name,pw))
|
||||
# workaround to simulate remote player for simpler testing:
|
||||
# PlayerManager.identify_player(1,player_name,pw)
|
||||
# PlayerManager.receiveAuth(PlayerManager.identify_player(1,player_name,pw))
|
||||
_load_game()
|
||||
# _load_game()
|
||||
|
||||
|
||||
func _on_register_pressed():
|
||||
pass
|
||||
|
||||
#func _load_game():
|
||||
# get_tree().change_scene('res://Worldmap/Worldmap.tscn')
|
||||
|
||||
func _load_game():
|
||||
get_tree().change_scene('res://Worldmap/Worldmap.tscn')
|
||||
|
|
|
@ -28,35 +28,12 @@ margin_bottom = 1021.04
|
|||
alignment = 1
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||
margin_top = 203.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 322.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "Menue"
|
||||
align = 1
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 326.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 445.0
|
||||
alignment = 1
|
||||
|
||||
[node name="label_Name" type="Label" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 618.0
|
||||
margin_right = 797.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "Name"
|
||||
valign = 1
|
||||
|
||||
[node name="Input_Name" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
|
||||
margin_left = 801.0
|
||||
margin_right = 1301.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
text = "judas"
|
||||
align = 2
|
||||
max_length = 16
|
||||
text = "Server Starten"
|
||||
align = 1
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 449.0
|
||||
|
@ -65,68 +42,35 @@ margin_bottom = 568.0
|
|||
alignment = 1
|
||||
|
||||
[node name="label_PW" type="Label" parent="VBoxContainer/HBoxContainer3"]
|
||||
margin_left = 549.0
|
||||
margin_right = 866.0
|
||||
margin_left = 557.0
|
||||
margin_right = 858.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "Password"
|
||||
text = "Passwort"
|
||||
valign = 1
|
||||
|
||||
[node name="Input_PW" type="LineEdit" parent="VBoxContainer/HBoxContainer3"]
|
||||
margin_left = 870.0
|
||||
margin_right = 1370.0
|
||||
margin_left = 862.0
|
||||
margin_right = 1362.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
text = "pw"
|
||||
align = 2
|
||||
max_length = 16
|
||||
secret = true
|
||||
|
||||
[node name="HBoxContainer4" type="HBoxContainer" parent="VBoxContainer"]
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 572.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 691.0
|
||||
alignment = 1
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer/HBoxContainer4"]
|
||||
margin_left = 679.0
|
||||
margin_right = 735.0
|
||||
margin_bottom = 119.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "IP"
|
||||
valign = 1
|
||||
|
||||
[node name="Input_IP" type="LineEdit" parent="VBoxContainer/HBoxContainer4"]
|
||||
margin_left = 739.0
|
||||
margin_right = 1239.0
|
||||
margin_bottom = 119.0
|
||||
rect_min_size = Vector2( 500, 0 )
|
||||
align = 2
|
||||
max_length = 16
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
|
||||
margin_top = 695.0
|
||||
margin_right = 1919.0
|
||||
margin_bottom = 820.0
|
||||
margin_bottom = 697.0
|
||||
alignment = 1
|
||||
|
||||
[node name="Host" type="Button" parent="VBoxContainer/HBoxContainer2"]
|
||||
margin_left = 628.0
|
||||
margin_right = 1010.0
|
||||
margin_left = 819.0
|
||||
margin_right = 1100.0
|
||||
margin_bottom = 125.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
action_mode = 0
|
||||
text = " Host "
|
||||
text = " Starten "
|
||||
|
||||
[node name="Join2" type="Button" parent="VBoxContainer/HBoxContainer2"]
|
||||
margin_left = 1014.0
|
||||
margin_right = 1291.0
|
||||
margin_bottom = 125.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
text = "Register"
|
||||
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer/Input_Name" to="." method="_on_Input_Name_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer3/Input_PW" to="." method="_on_Input_PW_text_changed"]
|
||||
[connection signal="text_changed" from="VBoxContainer/HBoxContainer4/Input_IP" to="." method="_on_Input_IP_text_changed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Host" to="." method="_on_Host_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Join2" to="." method="_on_register_pressed"]
|
||||
|
|
|
@ -292,8 +292,8 @@ func moveUnit(path,unitID):
|
|||
for boardUnit in boardUnits:
|
||||
if boardUnit.id == unit.id:
|
||||
boardUnit.coords = unit.coords
|
||||
print(path," NEXT ",unit.coords)
|
||||
return [path, apCost]
|
||||
# print(path," NEXT ",unit.coords)
|
||||
# return [path, apCost]
|
||||
# return validated path and ap and then execute it
|
||||
|
||||
func getUnitById(unitId):
|
||||
|
|
Loading…
Reference in New Issue