1 """User objects for the MUFF Engine"""
3 # Copyright (c) 2005 MUDpy, The Fungi <fungi@yuggoth.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # - Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # - Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
34 for module in muff.__all__:
35 exec("import " + module)
42 self.connection = None
43 self.authenticated = False
44 self.password_tries = 1
45 self.state = "entering account name"
46 self.menu_seen = False
49 self.output_queue = []
50 self.partial_input = ""
52 self.record = ConfigParser.SafeConfigParser()
54 filename = muffconf.config_data.get("general", "account_path") + "/" + self.name
56 self.record.read(filename)
57 self.passhash = self.record.get("account", "passhash")
58 self.last_address = self.record.get("account", "last_address", self.address)
61 def get_passhash(self):
62 filename = muffconf.config_data.get("general", "account_path") + "/" + self.proposed_name
63 temporary_record = ConfigParser.SafeConfigParser()
65 temporary_record.read(filename)
66 self.passhash = temporary_record.get("account", "passhash")
70 if self.authenticated:
71 filename = muffconf.config_data.get("general", "account_path") + "/" + self.name.lower()
72 if not self.record.has_section("account"):
73 self.record.add_section("account")
74 self.record.set("account", "name", self.name)
75 self.record.set("account", "passhash", self.passhash)
76 self.record.set("account", "last_address", self.address)
77 record_file = file(filename, "w")
78 self.record.write(record_file)
81 self.send(muffmenu.get_menu(self))
83 muffvars.userlist.remove(self)
84 def send(self, output, eol="$(eol)"):
86 output = "$(eol)" + output + eol
87 output = string.replace(output, "$(eol)", "\r\n")
88 output = string.replace(output, "$(div)", "\r\n\r\n")
89 output = string.replace(output, "$(bld)", chr(27)+"[1m")
90 output = string.replace(output, "$(nrm)", chr(27)+"[0m")
91 output = string.replace(output, "$(blk)", chr(27)+"[30m")
92 output = string.replace(output, "$(grn)", chr(27)+"[32m")
93 output = string.replace(output, "$(red)", chr(27)+"[31m")
94 output = string.replace(output, "$(account)", self.name)
95 output = muffmisc.wrap_ansi_text(output, 80)
96 self.output_queue.append(output)
98 self.connection.send(self.output_queue[0])
99 self.output_queue.remove(self.output_queue[0])
100 self.menu_seen = False