-
Notifications
You must be signed in to change notification settings - Fork 3
/
logxml.lic
93 lines (78 loc) · 2.76 KB
/
logxml.lic
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
=begin
Logs raw XML output to lich\logs\<game code>-<char name>\<date>-<number>.xml
starts a new file after 30,000 lines (somewhere around 1mb)
Shamelessly stolen and slightly altered (to use XML) from Tillmen's log script.
Messages from the client will be wrapped in <!-- CLIENT -->...<!-- ENDCLIENT --> tags.
This script must be trusted so that it can write output.
author: LostRanger ([email protected])
game: any
version: 0.4.1 (2019-12-28)
changelog:
0.4.1 (2019-12-28):
* Implement 0.4, correctly.
0.4 (2019-12-28):
* ';logxml streams' will now include pushStream and popStream messages. Note that this may be very, very noisy
due to room window updates and such.
0.3 (2017-04-24):
* fix output including both XML and plaintext from downstream.
0.2 (2017-04-23):
* Indicate where full logging started in the log file (as opposed to contents from regetall). Client data before
this point can't be fully logged due to Lich not loading the script in time, so yell about it.
* Use a more configuration-safe mechanism of complaining about not being trusted. Also, explain why trust is
needed.
=end
unless defined?(script.want_script_output)
echo 'Your version of Lich is too old for this script.'
exit
end
unless $SAFE == 0
echo "This script must be trusted to be allowed to write to log files."
echo "You can trust it with the following command: #{$lich_char}trust #{script.name}"
exit
end
hide_me
script.want_script_output = false
script.want_upstream = true
script.want_downstream = false
script.want_downstream_xml = true
log_streams = script.vars.include?("streams")
Thread.new {
begin
loop {
script.downstream_buffer.push "<!-- CLIENT -->#{upstream_get}<!-- ENDCLIENT -->"
}
rescue
echo $!
end
}
Dir.mkdir("#{$lich_dir}logs") unless File.exists?("#{$lich_dir}logs")
dir = "#{$lich_dir}logs/#{XMLData.game}-#{XMLData.name}"
Dir.mkdir(dir) unless File.exists?(dir)
started = false
loop {
num = 1
filename = "#{dir}/#{Time.now.strftime("%Y-%m-%d")}-#{num}.xml"
filename = "#{dir}/#{Time.now.strftime("%Y-%m-%d")}-#{num+=1}.xml" while File.exists?(filename)
file = File.open(filename, 'a')
file.sync = true
file.puts "#{Time.now.strftime("%Y-%m-%d %I:%M%P").sub(/0([0-9]+\:)/) {"#{$1}"}}\n"
unless started
if(Time.now - $login_time) < 30
file.puts(reget)
file.puts "<!-- Above contents from reget; full logging now active -->\n"
end
echo "XML Logging started, currently logging to #{filename}"
started = true
end
begin
30000.times {
line = get
if log_streams or line !~ /^<(?:push|pop)Stream/
file.puts line
end
}
file.puts "#{Time.now.strftime("%Y-%m-%d %I:%M%P").sub(/0([0-9]+\:)/) {"#{$1}"}}\n"
ensure
file.close rescue()
end
}