khanat-client/scenes/connection/connection.gd

35 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

2020-03-21 09:10:26 +00:00
extends Node
signal connection_ok
signal connection_error( message )
func do_request(username, password):
var message = load("res://ressources/scripts/nel/nel_login_message.gd")
if message:
message = message.nel_login_message.new("https-login", username, password, "Lirria", "2", "en");
# $http_request.request("http://lirria.khaganat.net/login/r2_login.php?" + message.get_request_string());
$http_request.request("http://149.91.80.160/login/r2_login.php?" + message.get_request_string());
2020-03-21 09:10:26 +00:00
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"]
$http_request.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)
2020-03-21 09:10:26 +00:00
func _on_http_request_request_completed(result, response_code, headers, body):
print( response_code )
if ProjectSettings.get_setting("khanat/debug_mode"):
emit_signal( "connection_ok" )
elif not response_code == 200:
emit_signal( "connection_error", "Erreur de connexion." )
else:
var s = body.get_string_from_utf8().split(":")
if(s[0] != "0"):
var server_info_script = load("res://ressources/scripts/nel/nel_server_infos.gd");
var server_info = server_info_script.nel_server_info.new(body.get_string_from_utf8());
emit_signal( "connection_ok" )
# No error so login was successful.