-
Notifications
You must be signed in to change notification settings - Fork 4
/
putter.php
144 lines (132 loc) · 4.15 KB
/
putter.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
include("config.php");
include("include.php");
$time_start = microtime();
$pre_get;
$post_get;
$pre_post;
$post_post;
$log = sprintf("<b>%.3f</b> - ", fmod(microtime(true), 60));
function do_request($method,$url, $data, &$log, $optional_headers = null) {
$params = array('http' => array(
'method' => $method,
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if ($http_response_header[0] == "HTTP/1.1 503 Service Unavailable") {
$log .= "<b style=\"color:red\">503</b>, ";
}
if (!$fp) {
//throw new Exception("Problem with $url, $php_errormsg <br>");
}
$response = @stream_get_contents($fp);
if ($response === false) {
//throw new Exception("Problem reading data from $url, $php_errormsg <br>");
}
return $response;
}
$path = $_GET["path"];
$command = $_GET["command"];
$server = $_GET["server"];
$method = "POST";
$data = "";
if($server == 'animator') {
$method = "PUT";
if($_GET["type"] && $_GET["type"] == 'player') {
$title = getStatscard($_GET["id"]);
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script: " . $_GET['type'] . ' ' . $_GET['id'] . implode("|",array_keys($title));
}
else if ($_GET["type"])
{
$title = getTitle($_GET["id"]);
if ($title["parent"] == 'templates/gameSummary.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script: " . $title['name'] . ' ' . $_GET['id'];
}
else if($title["parent"] == 'templates/sog_dropdown.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script Test: " . $title['name'] . ' ' . $_GET['id'];
}
else if($title["parent"] == 'templates/home_offense_starters.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script Test: " . $title['name'] . ' ' . $_GET['id'];
}
else if($title["parent"] == 'templates/home_defensive_starters.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script Test: " . $title['name'] . ' ' . $_GET['id'];
}
else if($title["parent"] == 'templates/visitor_defensive_starters.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script Test: " . $title['name'] . ' ' . $_GET['id'];
}
else if($title["parent"] == 'templates/visitor_offense_starters.xml')
{
$data = getAnimationScriptForTitle($title);
$command = 'script';
$log .= "Animator Script Test: " . $title['name'] . ' ' . $_GET['id'];
}
else
{
http_response_code(400);
$title = getTitle($_GET["id"]);
die('Title type not supported for animation 2 ' . $title[parent] . implode("|",array_keys($title)));
}
}
else
{
$data = $command;
$command = 'command'; // does this make sense? OH WELL
$log .= "Animator Command: $data, ";
}
} else if (strlen($command) > 0) {
$log .= "Command: $command, ";
$headers = "Content-Length: 0\n";
} else {
$command = "key";
$method = "PUT";
$pre_get = microtime();
if (strlen($path) > 1) {
$data = file_get_contents("$path");
$log .= "PNG Path: $path, ";
}
if (!$data) {
$data = file_get_contents("assets/blank.png");
$log .= "ERROR: Couldn't load title; clearing existing title";
}
$post_get = microtime();
}
$server_url = $server == 'animator' ? $animator_url : $keyer_url;
$log .= "<br>" . $server_url . "<br>";
if ($_GET["tie"]) {
$command .= "?tie_to_source";
}
$pre_post = microtime();
$result = do_request($method,$server_url . "$command", $data, $log, $headers);
$post_post = microtime();
// re-write timing at some point
$time_end = microtime();
$post_time = sprintf("%.3f", $post_post - $pre_post);
$get_time = sprintf("%.3f", $post_get - $pre_get);
$total_time = sprintf("%.3f", $time_end - $time_start);
$log .= "Total: $total_time, Get: $get_time , Post: $post_time. <br>";
$log .= $result;
$log .= "I'M HERE";
echo $log;
//echo("<hr>");
?>