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