forked from One-Piece-Online/OPOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteLog.php
More file actions
83 lines (75 loc) · 2.74 KB
/
WriteLog.php
File metadata and controls
83 lines (75 loc) · 2.74 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
76
77
78
79
80
81
82
83
<?php
function WriteLog($text, $playerColor = 0, $highlight=false, $path="./")
{
global $gameName;
$filename = $path . "Games/" . $gameName . "/gamelog.txt";
$handler = fopen($filename, "a");
if(!$handler) return;//File does not exist
if($highlight) $output = ($playerColor != 0 ? "<span style='color:<PLAYER" . $playerColor . "COLOR>; '>" : "") . "<mark style='background-color: brown; color:azure;'>" . $text . "</mark>" . ($playerColor != 0 ? "</span>" : "");
else $output = ($playerColor != 0 ? "<span style='color:<PLAYER" . $playerColor . "COLOR>; '>" : "") . $text . ($playerColor != 0 ? "</span>" : "");
fwrite($handler, $output . "\r\n");
fclose($handler);
}
function ClearLog($n=20)
{
global $gameName;
/*
$filename = "./Games/" . $gameName . "/gamelog.txt";
$handler = fopen($filename, "w");
fclose($handler);
*/
$filename = "./Games/" . $gameName . "/gamelog.txt";
$handle = fopen("./Games/" . $gameName . "/gamelog.txt", "r");
$lines = array_fill(0, $n-1, '');
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle);
array_push($lines, $buffer);
array_shift($lines);
}
fclose($handle);
}
$handle = fopen($filename, "w");
fwrite($handle, implode("", $lines));
fclose($handle);
}
function WriteError($text)
{
WriteLog("ERROR: " . $text);
}
function EchoLog($gameName, $playerID)
{
$filename = "./Games/" . $gameName . "/gamelog.txt";
$filesize = filesize($filename);
if ($filesize > 0) {
$handler = fopen($filename, "r");
$line = str_replace("\r\n", "<br>", fread($handler, $filesize));
//$line = str_replace("<PLAYER1COLOR>", $playerID==1 ? "Blue" : "Red", $line);
//$line = str_replace("<PLAYER2COLOR>", $playerID==2 ? "Blue" : "Red", $line);
$red = "#cb0202";
$blue = "#128ee5";
$line = str_replace("<PLAYER1COLOR>", $playerID == 1 || $playerID == 3 ? $blue : $red, $line);
$line = str_replace("<PLAYER2COLOR>", $playerID == 2 ? $blue : $red, $line);
echo ($line);
fclose($handler);
}
}
function JSONLog($gameName, $playerID, $path="./")
{
$response = "";
$filename = $path . "Games/" . $gameName . "/gamelog.txt";
$filesize = filesize($filename);
if ($filesize > 0) {
$handler = fopen($filename, "r");
$line = str_replace("\r\n", "<br>", fread($handler, $filesize));
//$line = str_replace("<PLAYER1COLOR>", $playerID==1 ? "Blue" : "Red", $line);
//$line = str_replace("<PLAYER2COLOR>", $playerID==2 ? "Blue" : "Red", $line);
$red = "#cb0202";
$blue = "#128ee5";
$line = str_replace("<PLAYER1COLOR>", $playerID == 1 || $playerID == 3 ? $blue : $red, $line);
$line = str_replace("<PLAYER2COLOR>", $playerID == 2 ? $blue : $red, $line);
$response = $line;
fclose($handler);
}
return $response;
}