-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbos.php
More file actions
75 lines (70 loc) · 2.61 KB
/
bos.php
File metadata and controls
75 lines (70 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
function bos_Send($game){
// send incidents/triggers to BOS
include "incidents.php";
include "logging.php";
include "get_config.php";
$witnesses = $config->subscriptions->witnesses;
$message = new stdClass();
$errors = new stdClass();
$good = 0;
// send incident message to all BOS witnesses
foreach($witnesses as $witness) {
$curl = curl_init(trim($witness->url));
$incident = json_encode(make_incident($game, $config),JSON_UNESCAPED_SLASHES);
$headers = ['Content-Type: application/json'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $incident);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
$message->status = "520";
$message->subcode = "520";
$message->title = "BOS server may not be available";
$message->message = $incident;
log_error($message, $witness->url);
}
else{
curl_close($curl);
$decoded = json_decode($curl_response);
if($decoded == null){
$errors->status = "400";
$errors->title = $curl_response;
if($errors->title == "Not normalized incident"){
// if this fails for one BOS node it will fail for all
$errors->subcode = "450";
}
elseif($errors->title == "Invalid data format"){
// if this fails for one BOS node it will fail for all
$errors->subcode = "451";
}
else{
$errors->title = "Internal server error";
$errors->subcode = "452";
}
$errors->message = $incident;
log_error($errors, $witness->url);
}
else{
log_incident(json_decode($incident), $witness->url);
log_success($decoded, $witness->url);
$good++;
}
}
}
if($good > 0)
{
// at least one end point was reached
$message->status = "200";
$message->message = "[" . $good . " of " . count($witnesses) . " subscribers reached]";
return $message;
}
else
{
// could have failed for various reasons, most likely not normalized or bad format
return $errors;
}
}
?>