145 lines
7 KiB
GDScript
145 lines
7 KiB
GDScript
extends Control
|
|
|
|
signal login_button_pressed
|
|
signal register_button_pressed
|
|
|
|
var _username
|
|
var _password
|
|
|
|
func _on_login_button_pressed():
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
|
|
func _on_play_button_pressed():
|
|
var username = get_node("h_box_container/v_box_container/margin_container/login_box/email_box/email_edit").get_text();
|
|
var password = get_node("h_box_container/v_box_container/margin_container/login_box/password_box/password_edit").get_text();
|
|
if username != null and username != "" and password != null and password != "":
|
|
do_request_salt(username, password)
|
|
|
|
|
|
func _on_play_without_connexion_pressed():
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
# Step get salt
|
|
|
|
func do_request_salt(username, password):
|
|
#var message = load("res://assets/Scripts/Models/nel_login_message.gd")
|
|
var connexion = load("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
#if message:
|
|
_username = username
|
|
_password = password
|
|
var message = load("res://assets/Scripts/Models/nel_login_message.gd").nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
#message = message.nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
var url_login = connexion.get_url_login();
|
|
$HTTPSalt.request(url_login + "?" + message.get_request_salt());
|
|
#$HTTPRequest.request(url_login + "?" + message.get_request_salt());
|
|
print("[login_menu] URL:" + url_login + "?" + message.get_request_salt());
|
|
|
|
|
|
func _on_HTTPSalt_request_completed(result, response_code, headers, body):
|
|
if response_code != 200 || ProjectSettings.get_setting("kaghanat/debug_mode"):
|
|
emit_signal( "login_button_pressed" )
|
|
else:
|
|
var text = str2var(body.get_string_from_utf8())
|
|
var s = body.get_string_from_utf8().split(":")
|
|
print("[login_menu:_on_HTTPSalt_request_completed] return:'" + str(text) + "'")
|
|
if(s[0] == "1"):
|
|
print("[login_menu] salt:'" + str(s[1]) + "'")
|
|
var message = load("res://assets/Scripts/Models/nel_login_message.gd").nel_login_message.new("https-login", _username, _password, "Lirria", "2", "en")
|
|
var connexion = load("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
var url_login = connexion.get_url_login();
|
|
print("[login_menu] URL:" + url_login + "?" + message.get_request_string(str(s[1])));
|
|
$HTTPRequest.request(url_login + "?" + message.get_request_string(str(s[1])));
|
|
else:
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible de se connecter"
|
|
get_node("error_dialog").popup_centered()
|
|
|
|
# Step Login
|
|
|
|
func do_request(username, password):
|
|
var message = load("res://assets/Scripts/Models/nel_login_message.gd")
|
|
var connexion = load("res://assets/Scripts/Config/connexion.gd").connexion.new()
|
|
if message:
|
|
var url_login
|
|
message = message.nel_login_message.new("https-login", username, password, "Lirria", "2", "en")
|
|
url_login = connexion.get_url_login();
|
|
$HTTPRequest.request(url_login + "?" + message.get_request_string());
|
|
print("Login to URL:" + url_login + "?" + message.get_request_string());
|
|
|
|
|
|
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
|
|
if response_code != 200 || ProjectSettings.get_setting("kaghanat/debug_mode"):
|
|
emit_signal( "login_button_pressed" )
|
|
else:
|
|
var text = str2var(body.get_string_from_utf8())
|
|
var lines = body.get_string_from_utf8().split("\n")
|
|
if lines.size() != 2:
|
|
print("[login_menu] Impossible to connect (bad return)")
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible to connect (bad return)"
|
|
get_node("error_dialog").popup_centered()
|
|
return
|
|
var line1 = lines[0].split("#")
|
|
var line2 = lines[1].split("#")
|
|
#print("[login_menu:_on_HTTPRequest_request_completed] return:'" + str(text) + "'" + str(lines.size()) + "'" + str(line1.size()) + "'" + str(line2.size()))
|
|
if line1[0] != "1":
|
|
print("[login_menu] Impossible to connect (return" + line1[0] + ")")
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible to connect (return :" + str(line1[0]) + ")"
|
|
get_node("error_dialog").popup_centered()
|
|
return
|
|
if line1.size() < 5:
|
|
print("[login_menu] Impossible to connect (bad return 1st line, size:" + str(line1.size()) + ")")
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible to connect (bad return 1st line, size:" + str(line1.size()) + ")"
|
|
get_node("error_dialog").popup_centered()
|
|
return
|
|
if line2.size() != 3:
|
|
print("[login_menu] Impossible to connect (bad return 2nd line, size:" + str(line2.size()) + ")")
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible to connect (bad return 2nd line, size:" + str(line2.size()) + ")"
|
|
get_node("error_dialog").popup_centered()
|
|
return
|
|
var server_info_script = load("res://assets/Scripts/Models/nel_server_info.gd");
|
|
print("[login_menu] " + str(body.get_string_from_utf8()))
|
|
var state = line1[0]
|
|
var cookie = line1[1]
|
|
var fsaddr = line1[2]
|
|
var khaganat = fsaddr.split(":")
|
|
var khaganat_host = khaganat[0]
|
|
var khaganat_port = int(khaganat[1])
|
|
var ringmainurl = line1[3]
|
|
var fartp = line1[4]
|
|
var stat = "0"
|
|
if line1.size() >= 6:
|
|
stat = line1[5]
|
|
var r2serverversion = line2[0]
|
|
var r2backuppatchurl = line2[1]
|
|
var r2patchurl = line2[2]
|
|
|
|
var cookieSplit = cookie.split("|")
|
|
if cookieSplit.size() != 3:
|
|
get_node("error_dialog/v_box_container/label").text = "Impossible de se connecter (bad cookies size:" + str(cookieSplit.size()) + ")"
|
|
get_node("error_dialog").popup_centered()
|
|
return
|
|
var UserAddr = cookieSplit[0]
|
|
var UserKey = cookieSplit[1]
|
|
var UserId = cookieSplit[2]
|
|
|
|
print("[login_menu:_on_HTTPRequest_request_completed] state:" + state + ", cookie:" + cookie + ", fsaddr:" + fsaddr + ", ringmainurl:" + ringmainurl + ", fartp:" + fartp + ", stat:" + stat + ", r2serverversion:" + r2serverversion + ", r2backuppatchurl:" + r2backuppatchurl + ", r2patchurl:" + r2patchurl)
|
|
var server_info = server_info_script.nel_server_info.new(body.get_string_from_utf8());
|
|
net_low_level.set_khaganat_server(khaganat_host, khaganat_port)
|
|
net_low_level.connect_to_server(UserAddr, UserKey, UserId)
|
|
|
|
emit_signal( "login_button_pressed" )
|
|
|
|
func _make_post_request(url, data_to_send, use_ssl):
|
|
# Convert data to json string:
|
|
var query = JSON.print(data_to_send)
|
|
# Add 'Content-Type' header:
|
|
var headers = ["Content-Type: application/json"]
|
|
$HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)
|
|
|
|
|
|
func _on_register_button_pressed():
|
|
emit_signal( "register_button_pressed" )
|
|
|
|
|
|
func _on_error_dialog_button_pressed():
|
|
get_node("error_dialog").hide()
|