blob: 315cf19780fd64f19c84ec28ba9ba2a387882988 [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) {
Andreu78e5bb02019-09-22 13:38:04 +02009 // Check if user is alive
10 update_info(user);
11
Andreu66ad5cf2019-09-18 17:15:44 +020012 $.ajax({
Andreued8e1f92019-09-18 22:26:04 +020013 'url': './php/request.php',
Andreu09b8b052019-09-21 21:47:20 +020014 'type': 'POST',
15 // 'contentType': 'application/json; charset=utf-8',
Andreued491672019-09-20 13:09:18 +020016 'data': { 'user_id': user.id,
Andreued491672019-09-20 13:09:18 +020017 'user_quimata': user.quimata,
Andreued491672019-09-20 13:09:18 +020018 'msg': msg
Andreu09b8b052019-09-21 21:47:20 +020019 },
20 dataType:'text',
Andreued8e1f92019-09-18 22:26:04 +020021 'success': function(data) {
Andreuabbcb7e2019-09-21 18:22:14 +020022 $.notify('Resposta guardada', 'success');
Andreu885889c2019-09-19 00:28:20 +020023 console.log(data);
Andreued8e1f92019-09-18 22:26:04 +020024 },
25 'error': function(xhr, status, error) {
Andreuabbcb7e2019-09-21 18:22:14 +020026 $.notify('Error! Torna-ho a intentar o contacta amb l\'Andreu: +34681236024');
27 console.log(error);
Andreued8e1f92019-09-18 22:26:04 +020028 }
Andreu66ad5cf2019-09-18 17:15:44 +020029 });
Andreu2c6367c2019-09-17 23:46:36 +020030}
Andreudca79f42019-09-18 23:53:19 +020031
Andreuabbcb7e2019-09-21 18:22:14 +020032function check_requests(info, user) {
Andreudca79f42019-09-18 23:53:19 +020033 let dead = false;
Andreudca79f42019-09-18 23:53:19 +020034
Andreuabbcb7e2019-09-21 18:22:14 +020035 if (info.requested) {
Andreudca79f42019-09-18 23:53:19 +020036 // Check for requests
Andreu20af6c22019-09-24 18:33:50 +020037 if (info.requested) dead = confirm("El teu assassí ha dit que t'ha matat, és veritat?");
Andreu04f79ef2019-09-22 18:52:19 +020038
Andreudca79f42019-09-18 23:53:19 +020039 // Confirm/deny request
Andreuabbcb7e2019-09-21 18:22:14 +020040 if (dead) send_request(user, "CONF DEAD"); // confirm death
41 else send_request(user, "DENY REQ"); // deny kill/death
Andreudca79f42019-09-18 23:53:19 +020042 }
43
Andreu885889c2019-09-19 00:28:20 +020044 // Return mort
Andreuabbcb7e2019-09-21 18:22:14 +020045 return dead || info.mort;
46}
47
Andreuefe66eb2019-09-21 18:41:49 +020048function update_info(user) {
49 $.ajax({
Andreu09b8b052019-09-21 21:47:20 +020050 url: "./ajax/userinfo.php",
Andreuefe66eb2019-09-21 18:41:49 +020051 data: { id: user.id },
Andreu20cbd1d2019-09-22 00:00:57 +020052 dataType: 'text',
Andreu09b8b052019-09-21 21:47:20 +020053 type: 'POST',
Andreuefe66eb2019-09-21 18:41:49 +020054 success: function(response, status, xhr) {
55 let info = JSON.parse(response);
56
57 // Check if user is dead
Andreu20af6c22019-09-24 18:33:50 +020058 if (!user.mort && !info.mort) user.mort = check_requests(info, user);
59 else window.location.href = "./dead.php";
Andreuefe66eb2019-09-21 18:41:49 +020060
61 // Check if there has been a change of victim
62 if (info.quimata != user.quimata) {
Andreu20af6c22019-09-24 18:33:50 +020063 change_victim(info);
Andreuefe66eb2019-09-21 18:41:49 +020064 user.quimata = info.quimata;
65 }
66
Andreu20af6c22019-09-24 18:33:50 +020067 console.log("Response: " + response);
Andreuefe66eb2019-09-21 18:41:49 +020068 }});
Andreudca79f42019-09-18 23:53:19 +020069}
Andreu1bf9ab72019-09-22 20:27:40 +020070
71function get_user_name(users, userid) {
72 for (let user of users) if (user.id == userid) return user.nomcomplet;
73 return "";
74}