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) { |
Adrià Vilanova Martínez | d3394e1 | 2022-11-19 15:45:58 +0100 | [diff] [blame] | 26 | $.notify('Error! Torna-ho a intentar o contacta\'ns: operacio236@avm99963.com'); |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 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 | 20af6c2 | 2019-09-24 18:33:50 +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 |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 58 | if (!user.mort && !info.mort) user.mort = check_requests(info, user); |
| 59 | else window.location.href = "./dead.php"; |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 60 | |
| 61 | // Check if there has been a change of victim |
| 62 | if (info.quimata != user.quimata) { |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 63 | change_victim(info); |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 64 | user.quimata = info.quimata; |
| 65 | } |
| 66 | |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 67 | console.log("Response: " + response); |
Andreu | efe66eb | 2019-09-21 18:41:49 +0200 | [diff] [blame] | 68 | }}); |
Andreu | dca79f4 | 2019-09-18 23:53:19 +0200 | [diff] [blame] | 69 | } |
Andreu | 1bf9ab7 | 2019-09-22 20:27:40 +0200 | [diff] [blame] | 70 | |
| 71 | function get_user_name(users, userid) { |
| 72 | for (let user of users) if (user.id == userid) return user.nomcomplet; |
| 73 | return ""; |
| 74 | } |