Crossfire Server, Trunk
report.py
Go to the documentation of this file.
1 from email.mime.text import MIMEText
2 import subprocess
3 
4 import Crossfire
5 
6 def report(pl):
7  desc = Crossfire.ScriptParameters()
8  if desc == None:
9  pl.Message("To report an issue, type 'report <description of the issue>'.")
10  return
11 
12  details = {
13  'PLAYER': Crossfire.WhoAmI().Name,
14  'MAP': Crossfire.WhoAmI().Map.Path,
15  'X': Crossfire.WhoAmI().X,
16  'Y': Crossfire.WhoAmI().Y,
17  'DESC': desc,
18  }
19 
20  report = """
21 Reporter: {PLAYER}
22 Map: {MAP} ({X}, {Y})
23 Report: {DESC}
24 """.format(**details)
25 
26  Crossfire.Log(Crossfire.LogInfo, "A problem was reported: %s" % (report))
27 
28  msg = MIMEText(report)
29  recipient = "crossfire"
30  msg["From"] = "crossfire"
31  msg["Subject"] = "Crossfire issue report"
32 
33  try:
34  result = subprocess.run(['sendmail', recipient], universal_newlines=True, input=msg.as_string(), timeout=2)
35  if result.returncode == 0:
36  pl.Message("Thank you for your report.")
37  else:
38  error(pl)
39  except subprocess.TimeoutExpired:
40  error(pl)
41  Crossfire.Log(Crossfire.LogError, "Timed out while reporting a problem")
42 
43 def error(pl):
44  pl.Message("There was an error reporting your problem. Please try again or contact a Dungeon Master to report your problem.")
45 
46 report(Crossfire.WhoAmI())
report.report
def report(pl)
Definition: report.py:6
report
Definition: report.py:1
report.error
def error(pl)
Definition: report.py:43