blob: 621bbe1b2778a5ab552b1e2c77abde7d32b91263 [file] [log] [blame]
Andreu2c6367c2019-09-17 23:46:36 +02001function getUrlParameter(name) {
2 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
3 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
4 var results = regex.exec(location.search);
5 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
6};
7
Andreuabbcb7e2019-09-21 18:22:14 +02008function send_request(user, msg) {
Andreu66ad5cf2019-09-18 17:15:44 +02009 $.ajax({
Andreued8e1f92019-09-18 22:26:04 +020010 'url': './php/request.php',
Andreu09b8b052019-09-21 21:47:20 +020011 'type': 'POST',
12 // 'contentType': 'application/json; charset=utf-8',
Andreued491672019-09-20 13:09:18 +020013 'data': { 'user_id': user.id,
Andreued491672019-09-20 13:09:18 +020014 'user_quimata': user.quimata,
Andreued491672019-09-20 13:09:18 +020015 'msg': msg
Andreu09b8b052019-09-21 21:47:20 +020016 },
17 dataType:'text',
Andreued8e1f92019-09-18 22:26:04 +020018 'success': function(data) {
Andreuabbcb7e2019-09-21 18:22:14 +020019 $.notify('Resposta guardada', 'success');
Andreu885889c2019-09-19 00:28:20 +020020 console.log(data);
Andreued8e1f92019-09-18 22:26:04 +020021 },
22 'error': function(xhr, status, error) {
Andreuabbcb7e2019-09-21 18:22:14 +020023 $.notify('Error! Torna-ho a intentar o contacta amb l\'Andreu: +34681236024');
24 console.log(error);
Andreued8e1f92019-09-18 22:26:04 +020025 }
Andreu66ad5cf2019-09-18 17:15:44 +020026 });
Andreu2c6367c2019-09-17 23:46:36 +020027}
Andreudca79f42019-09-18 23:53:19 +020028
Andreuabbcb7e2019-09-21 18:22:14 +020029function check_requests(info, user) {
Andreudca79f42019-09-18 23:53:19 +020030 let dead = false;
Andreudca79f42019-09-18 23:53:19 +020031
Andreuabbcb7e2019-09-21 18:22:14 +020032 if (info.requested) {
Andreudca79f42019-09-18 23:53:19 +020033 // Check for requests
Andreuabbcb7e2019-09-21 18:22:14 +020034 if(info.requested) dead = confirm("El teu assassí ha dit que t'ha matat, és veritat?");
35
Andreudca79f42019-09-18 23:53:19 +020036 // Confirm/deny request
Andreuabbcb7e2019-09-21 18:22:14 +020037 if (dead) send_request(user, "CONF DEAD"); // confirm death
38 else send_request(user, "DENY REQ"); // deny kill/death
Andreudca79f42019-09-18 23:53:19 +020039 }
40
Andreu885889c2019-09-19 00:28:20 +020041 // Return mort
Andreuabbcb7e2019-09-21 18:22:14 +020042 return dead || info.mort;
43}
44
Andreuefe66eb2019-09-21 18:41:49 +020045function update_info(user) {
46 $.ajax({
Andreu09b8b052019-09-21 21:47:20 +020047 url: "./ajax/userinfo.php",
Andreuefe66eb2019-09-21 18:41:49 +020048 data: { id: user.id },
Andreu20cbd1d2019-09-22 00:00:57 +020049 dataType: 'text',
Andreu09b8b052019-09-21 21:47:20 +020050 type: 'POST',
Andreuefe66eb2019-09-21 18:41:49 +020051 success: function(response, status, xhr) {
52 let info = JSON.parse(response);
53
54 // Check if user is dead
55 if (!user.mort) user.mort = check_requests(info, user);
Andreu4ed74962019-09-22 00:06:15 +020056 else window.location.href= "./dead.php";
Andreuefe66eb2019-09-21 18:41:49 +020057
58 // Check if there has been a change of victim
59 if (info.quimata != user.quimata) {
60 change_victim(info);
61 user.quimata = info.quimata;
62 }
63
64 console.log(response);
65 }});
Andreudca79f42019-09-18 23:53:19 +020066}