started server password and connection rework

This commit is contained in:
Joa2 2023-12-05 16:23:59 +01:00
parent 7012ffb313
commit edc9966a8e
9 changed files with 87 additions and 236 deletions

View File

@ -5,12 +5,7 @@ const DEFAULT_PORT = 31400
const MAX_PLAYERS = 50 const MAX_PLAYERS = 50
var ip = '' var ip = ''
var players = { } var serverPassword = ""
var self_data : Dictionary = { name = '', password = ''}
var password = ''
var ongoingQry = false
var lastRequest = ''
var serverpassword = " "
signal player_disconnected signal player_disconnected
signal server_disconnected signal server_disconnected
@ -18,46 +13,29 @@ signal server_disconnected
func _ready(): func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected') get_tree().connect('network_peer_connected', self, '_on_player_connected')
connect_to_server("name","","")
func connect_to_server(playerName,pw,serverpassword): func connect_to_server(givenServerPassword):
self.serverpassword = serverpassword serverPassword = givenServerPassword
self_data.name = playerName
self_data.password = pw
var peer = NetworkedMultiplayerENet.new() var peer = NetworkedMultiplayerENet.new()
if ip == '': if ip == '':
ip = DEFAULT_IP ip = DEFAULT_IP
peer.create_client(ip, DEFAULT_PORT) if peer.create_client(ip, DEFAULT_PORT) == OK:
get_tree().set_network_peer(peer) get_tree().set_network_peer(peer)
# PlayerManager.authcache['password']=pw else:
# PlayerManager.authcache['playername']=playerName print("invalid ip/ no server at ip")
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
func _on_player_disconnected(id): func _on_player_disconnected(id):
players.erase(id)
PlayerManager.player_disconnected(id) PlayerManager.player_disconnected(id)
func _on_player_connected(connected_player_id): func _on_player_connected(connected_player_id):
var local_player_id = get_tree().get_network_unique_id() var local_player_id = get_tree().get_network_unique_id()
rpc_id(1, '_request_player_info', local_player_id, connected_player_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): remote func _passwordReturn(correct):
print('Client -> _receive_auth erreicht') if correct:
PlayerManager.receiveAuth(response) print("correct server password")
WorldManager.requestMapfromServer() else:
WorldManager._load_worldmap() print("wrong server password")
#print(response)
remote func _send_player_info(id, info):
players[id] = info

View File

@ -107,8 +107,4 @@ remote func receiveAuth(response):
# if authcache.response.has('faction'): # if authcache.response.has('faction'):
# myFactionData = response.faction # myFactionData = response.faction
# #to do: remove accesses to redundant data and then erase redundant data # #to do: remove accesses to redundant data and then erase redundant data
#

View File

@ -1,36 +1,14 @@
extends Control extends Control
var player_name = "Judas" var serverPassword = ""
var pw = "pw"
func _on_Input_Name_text_changed(new_text):
self.player_name = new_text
func _on_Input_PW_text_changed(new_text): func _on_Input_PW_text_changed(new_text):
self.pw = new_text serverPassword = new_text
func _on_Input_IP_text_changed(new_text): func _on_Input_IP_text_changed(new_text):
Network.ip = new_text Network.ip = new_text
func _on_Join_pressed():# change this to check on the server user data login information func _on_Join_pressed():# change this to check on the server user data login information
if player_name == '': Network.connect_to_server(serverPassword)
print('PlayerName empty') #if server exists -> load seperate menu to create name select faction etc etc
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')

View File

@ -48,57 +48,32 @@ margin_right = 1919.0
margin_bottom = 1021.04 margin_bottom = 1021.04
alignment = 1 alignment = 1
script = SubResource( 1 ) script = SubResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="lblMenuTitle" type="Label" parent="VBoxContainer"] [node name="lblMenuTitle" type="Label" parent="VBoxContainer"]
margin_top = 203.0 margin_top = 265.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 322.0 margin_bottom = 384.0
custom_fonts/font = SubResource( 2 ) custom_fonts/font = SubResource( 2 )
text = "Menue" text = "Server Beitreten"
align = 1 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"] [node name="HBoxPassword" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 449.0 margin_top = 388.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 568.0 margin_bottom = 507.0
alignment = 1 alignment = 1
[node name="lblPassword" type="Label" parent="VBoxContainer/HBoxPassword"] [node name="lblPassword" type="Label" parent="VBoxContainer/HBoxPassword"]
margin_left = 557.0 margin_left = 443.0
margin_right = 858.0 margin_right = 971.0
margin_bottom = 119.0 margin_bottom = 119.0
custom_fonts/font = SubResource( 2 ) custom_fonts/font = SubResource( 2 )
text = "Passwort" text = "Server Passwort"
valign = 1 valign = 1
[node name="iptPassword" type="LineEdit" parent="VBoxContainer/HBoxPassword"] [node name="iptPassword" type="LineEdit" parent="VBoxContainer/HBoxPassword"]
margin_left = 862.0 margin_left = 975.0
margin_right = 1362.0 margin_right = 1475.0
margin_bottom = 119.0 margin_bottom = 119.0
rect_min_size = Vector2( 500, 0 ) rect_min_size = Vector2( 500, 0 )
text = "pw" text = "pw"
@ -107,49 +82,40 @@ max_length = 16
secret = true secret = true
[node name="HBoxIP" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxIP" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 572.0 margin_top = 511.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 691.0 margin_bottom = 630.0
alignment = 1 alignment = 1
[node name="lblIP" type="Label" parent="VBoxContainer/HBoxIP"] [node name="lblIP" type="Label" parent="VBoxContainer/HBoxIP"]
margin_left = 679.0 margin_left = 563.0
margin_right = 735.0 margin_right = 852.0
margin_bottom = 119.0 margin_bottom = 119.0
custom_fonts/font = SubResource( 2 ) custom_fonts/font = SubResource( 2 )
text = "IP" text = "Server-IP"
valign = 1 valign = 1
[node name="iptIP" type="LineEdit" parent="VBoxContainer/HBoxIP"] [node name="iptIP" type="LineEdit" parent="VBoxContainer/HBoxIP"]
margin_left = 739.0 margin_left = 856.0
margin_right = 1239.0 margin_right = 1356.0
margin_bottom = 119.0 margin_bottom = 119.0
rect_min_size = Vector2( 500, 0 ) rect_min_size = Vector2( 500, 0 )
align = 2 align = 2
max_length = 16 max_length = 16
[node name="HBoxButtons" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxButtons" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 695.0 margin_top = 634.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 820.0 margin_bottom = 759.0
alignment = 1 alignment = 1
[node name="btnJoin" type="Button" parent="VBoxContainer/HBoxButtons"] [node name="btnJoin" type="Button" parent="VBoxContainer/HBoxButtons"]
margin_left = 586.0 margin_left = 789.0
margin_right = 926.0 margin_right = 1129.0
margin_bottom = 125.0 margin_bottom = 125.0
custom_fonts/font = SubResource( 3 ) custom_fonts/font = SubResource( 3 )
text = " Beitreten " 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/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="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/btnJoin" to="." method="_on_Join_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxButtons/btnRegister" to="." method="_on_register_pressed"]

View File

@ -75,7 +75,7 @@ func unitSelectedMethod(unit, debugOriginUnit):#this is called when a unit is se
if unit.id != selectedUnit.id: if unit.id != selectedUnit.id:
unit.isSelected = false unit.isSelected = false
$TileMap/LineManager.drawAdvancedLine([],[],0,0) $TileMap/LineManager.drawAdvancedLine([],[],0,0)
print(selectedUnit) # print(selectedUnit)
func _input(event):#this responds to any input. Has various functions depending on input func _input(event):#this responds to any input. Has various functions depending on input
if selectedUnit != null: if selectedUnit != null:
@ -262,7 +262,7 @@ func _on_pathAnimationCompleted():#this gets a signal from the selected unit and
requestTiles() requestTiles()
requestUnits() requestUnits()
resetPathing() resetPathing()
print(boardUnits) # print(boardUnits)
animationInProgress = false animationInProgress = false
selectedUnit = null selectedUnit = null

View File

@ -16,10 +16,6 @@ signal server_disconnected
func _ready(): func _ready():
get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected') get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
get_tree().connect('network_peer_connected', self, '_on_player_connected') get_tree().connect('network_peer_connected', self, '_on_player_connected')
create_server()
remote func TESTFUNCTION(string):
print(string)
remote func checkServerPassword(serverPassword): remote func checkServerPassword(serverPassword):
if (serverPassword=="myPW"): if (serverPassword=="myPW"):
@ -27,14 +23,16 @@ remote func checkServerPassword(serverPassword):
else: else:
print("ServerPassword falsch") print("ServerPassword falsch")
func create_server(): func createServer(password):
pw = password
print("a")
print(pw)
players[1] = self_data players[1] = self_data
var peer = NetworkedMultiplayerENet.new() var host = NetworkedMultiplayerENet.new()
peer.create_server(DEFAULT_PORT, MAX_PLAYERS) host.create_server(DEFAULT_PORT, MAX_PLAYERS)
get_tree().set_network_peer(peer) get_tree().set_network_peer(host)
set_network_master(1) set_network_master(1)
#function that creates needed files and directories in user #function that creates needed files and directories in user
#To do: copy preset folder to user, handling should be uniform #To do: copy preset folder to user, handling should be uniform
func firstStart(): func firstStart():
@ -63,21 +61,26 @@ func _on_player_disconnected(id):
# PlayerManager.player_disconnected(id) # PlayerManager.player_disconnected(id)
func _on_player_connected(connected_player_id): func _on_player_connected(connected_player_id):
print(">>>>>>>>>>> on player connected <<<<<<<<<<<<< ", connected_player_id) print(connected_player_id," connected")
var local_player_id = get_tree().get_network_unique_id() request_player_info(connected_player_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')
#method called from client to server to be identified. func addPlayer(id, name):
remote func _request_auth(id, userData): pass
print(">>>>> WE REQUESTED AUTH <<<<<<<")
var response = PlayerManager.identifyPlayer(userData['name'], userData['password'])
print('Server -> _request_auth ' + response)
rpc_id(id, 'receiveAuth', response)
remote func _request_player_info(request_from_id, player_id): var awaitingConfirmation = []
rpc_id(request_from_id, '_send_player_info', player_id, players[player_id])
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. # 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): remote func _request_players(request_from_id):

View File

@ -1,39 +1,25 @@
extends Control extends Control
var player_name = "Judas" var pw = ""
var pw = "pw"
func _on_Input_Name_text_changed(new_text):
player_name = new_text
func _on_Input_PW_text_changed(new_text): func _on_Input_PW_text_changed(new_text):
pw = new_text pw = new_text
func _on_Input_IP_text_changed(new_text):
Network.ip = new_text
func _on_Host_pressed(): func _on_Host_pressed():
if player_name == "":
return
# return
var file = File.new() var file = File.new()
if not file.file_exists("user://server.txt"): if not file.file_exists("user://server.txt"):
Network.firstStart() Network.firstStart()
Network.create_server() Network.createServer(pw)
#Network.create_server(PlayerManager.identify_player(player_name,pw)) # Network.create_server(PlayerManager.identify_player(player_name,pw))
#workaround to simulate remote player for simpler testing: # workaround to simulate remote player for simpler testing:
# PlayerManager.identify_player(1,player_name,pw) # PlayerManager.identify_player(1,player_name,pw)
# PlayerManager.receiveAuth(PlayerManager.identify_player(1,player_name,pw)) # PlayerManager.receiveAuth(PlayerManager.identify_player(1,player_name,pw))
_load_game() # _load_game()
func _on_register_pressed(): func _on_register_pressed():
pass pass
#func _load_game():
# get_tree().change_scene('res://Worldmap/Worldmap.tscn')
func _load_game():
get_tree().change_scene('res://Worldmap/Worldmap.tscn')

View File

@ -28,35 +28,12 @@ margin_bottom = 1021.04
alignment = 1 alignment = 1
[node name="Label" type="Label" parent="VBoxContainer"] [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_top = 326.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 445.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 ) custom_fonts/font = SubResource( 1 )
text = "Name" text = "Server Starten"
valign = 1 align = 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
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 449.0 margin_top = 449.0
@ -65,68 +42,35 @@ margin_bottom = 568.0
alignment = 1 alignment = 1
[node name="label_PW" type="Label" parent="VBoxContainer/HBoxContainer3"] [node name="label_PW" type="Label" parent="VBoxContainer/HBoxContainer3"]
margin_left = 549.0 margin_left = 557.0
margin_right = 866.0 margin_right = 858.0
margin_bottom = 119.0 margin_bottom = 119.0
custom_fonts/font = SubResource( 1 ) custom_fonts/font = SubResource( 1 )
text = "Password" text = "Passwort"
valign = 1 valign = 1
[node name="Input_PW" type="LineEdit" parent="VBoxContainer/HBoxContainer3"] [node name="Input_PW" type="LineEdit" parent="VBoxContainer/HBoxContainer3"]
margin_left = 870.0 margin_left = 862.0
margin_right = 1370.0 margin_right = 1362.0
margin_bottom = 119.0 margin_bottom = 119.0
rect_min_size = Vector2( 500, 0 ) rect_min_size = Vector2( 500, 0 )
text = "pw"
align = 2 align = 2
max_length = 16 max_length = 16
secret = true secret = true
[node name="HBoxContainer4" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 572.0 margin_top = 572.0
margin_right = 1919.0 margin_right = 1919.0
margin_bottom = 691.0 margin_bottom = 697.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
alignment = 1 alignment = 1
[node name="Host" type="Button" parent="VBoxContainer/HBoxContainer2"] [node name="Host" type="Button" parent="VBoxContainer/HBoxContainer2"]
margin_left = 628.0 margin_left = 819.0
margin_right = 1010.0 margin_right = 1100.0
margin_bottom = 125.0 margin_bottom = 125.0
custom_fonts/font = SubResource( 2 ) custom_fonts/font = SubResource( 2 )
action_mode = 0 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/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/Host" to="." method="_on_Host_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Join2" to="." method="_on_register_pressed"]

View File

@ -292,8 +292,8 @@ func moveUnit(path,unitID):
for boardUnit in boardUnits: for boardUnit in boardUnits:
if boardUnit.id == unit.id: if boardUnit.id == unit.id:
boardUnit.coords = unit.coords boardUnit.coords = unit.coords
print(path," NEXT ",unit.coords) # print(path," NEXT ",unit.coords)
return [path, apCost] # return [path, apCost]
# return validated path and ap and then execute it # return validated path and ap and then execute it
func getUnitById(unitId): func getUnitById(unitId):