Andreu | 2c6367c | 2019-09-17 23:46:36 +0200 | [diff] [blame] | 1 | function 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 | |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 8 | function send_request(user, msg) { |
Andreu | 78e5bb0 | 2019-09-22 13:38:04 +0200 | [diff] [blame] | 9 | // Check if user is alive |
| 10 | update_info(user); |
| 11 | |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 12 | $.ajax({ |
Andreu | ed8e1f9 | 2019-09-18 22:26:04 +0200 | [diff] [blame] | 13 | 'url': './php/request.php', |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 14 | 'type': 'POST', |
| 15 | // 'contentType': 'application/json; charset=utf-8', |
Andreu | ed49167 | 2019-09-20 13:09:18 +0200 | [diff] [blame] | 16 | 'data': { 'user_id': user.id, |
Andreu | ed49167 | 2019-09-20 13:09:18 +0200 | [diff] [blame] | 17 | 'user_quimata': user.quimata, |
Andreu | ed49167 | 2019-09-20 13:09:18 +0200 | [diff] [blame] | 18 | 'msg': msg |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 19 | }, |
| 20 | dataType:'text', |
Andreu | ed8e1f9 | 2019-09-18 22:26:04 +0200 | [diff] [blame] | 21 | 'success': function(data) { |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 22 | $.notify('Resposta guardada', 'success'); |
Andreu | 885889c | 2019-09-19 00:28:20 +0200 | [diff] [blame] | 23 | console.log(data); |
Andreu | ed8e1f9 | 2019-09-18 22:26:04 +0200 | [diff] [blame] | 24 | }, |
| 25 | 'error': function(xhr, status, error) { |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 26 | $.notify('Error! Torna-ho a intentar o contacta amb l\'Andreu: +34681236024'); |
| 27 | console.log(error); |
Andreu | ed8e1f9 | 2019-09-18 22:26:04 +0200 | [diff] [blame] | 28 | } |
Andreu | 66ad5cf | 2019-09-18 17:15:44 +0200 | [diff] [blame] | 29 | }); |
Andreu | 2c6367c | 2019-09-17 23:46:36 +0200 | [diff] [blame] | 30 | } |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 31 | |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 32 | function check_requests(info, user) { |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 33 | let dead = false; |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 34 | |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 35 | if (info.requested) { |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 36 | // Check for requests |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 37 | if(info.requested) dead = confirm("El teu assassí ha dit que t'ha matat, és veritat?"); |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 38 | |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 39 | // Confirm/deny request |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 40 | if (dead) send_request(user, "CONF DEAD"); // confirm death |
| 41 | else send_request(user, "DENY REQ"); // deny kill/death |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Andreu | 885889c | 2019-09-19 00:28:20 +0200 | [diff] [blame] | 44 | // Return mort |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 45 | return dead || info.mort; |
| 46 | } |
| 47 | |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 48 | function update_info(user) { |
| 49 | $.ajax({ |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 50 | url: "./ajax/userinfo.php", |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 51 | data: { id: user.id }, |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 52 | dataType: 'text', |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 53 | type: 'POST', |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 54 | success: function(response, status, xhr) { |
| 55 | let info = JSON.parse(response); |
| 56 | |
| 57 | // Check if user is dead |
| 58 | if (!user.mort) user.mort = check_requests(info, user); |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 59 | |
| 60 | // Check if there has been a change of victim |
| 61 | if (info.quimata != user.quimata) { |
Andreu | 04f79ef | 2019-09-22 18:52:19 +0200 | [diff] [blame] | 62 | if (!user.mort) change_victim(info); |
| 63 | else window.location.href = "./dead.php"; |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 64 | user.quimata = info.quimata; |
| 65 | } |
| 66 | |
| 67 | console.log(response); |
| 68 | }}); |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 69 | } |