Esempio n. 1
0
    def do_give(self, session, line):
        if not line: session.push(tpl.SYNTAX_GIVE)
        else:
            self.argu = line.lower()
            #if not self.argu.strip(): session.push("> ")
            self.parts = line.split(' ', 3)

            if self.parts[1] == "to":
                try:
                    self.itom = Select.getItemInstance(session.p_id, self.parts[0].lower()) # Given item info

                    # Check if given to a player.
                    self.transf = Select.getPlayerInRoom(session.is_in, self.parts[2].lower())

                    # Check if given to a mob.
                    self.mob = Select.getNpcInRoom(session.is_in, self.parts[2].lower())

                    if self.transf:
                        Update.setItemOwner(self.transf[0], self.itom[0])
                        session.push(tpl.GIVE % (self.parts[0],self.parts[2]))
                        # the following line is commented out -- not sure if I'll tell the whole room + it doesn't work
                        #self.RoomBroadcast(session, session.is_in, " gives %s to %s" % (self.parts[0],self.parts[2]))
                        
                    elif self.mob:
                        Update.setItemNpcOwner(self.mob[0], self.itom[0])
                        session.push(tpl.GIVE % (self.parts[0],self.parts[2]))
                        #Effects.RoomBroadcast(session, session.is_in, " gives %s to %s" % (self.parts[0], self.parts[2]))
                    else: session.push(tpl.PLAYER_NOT_FOUND)

                except: session.push(tpl.SYNTAX_GIVE)

            else: session.push(tpl.SYNTAX_GIVE)
Esempio n. 2
0
    def handle_close(self):
        self.ival = ipsessions.items()
        for i in self.ival:
            self.test = str(sessions[i[0]])
            self.tesb = str(self.sock)
            try:
                if (self.ipaddr[0] == i[1]) & (self.test == self.tesb):
                    self.leaver = Select.getPlayerByID(i[0])
                    self.leaver = self.leaver[1].capitalize()
                    #In any case, if the player exits, remove him.
                    Update.LogoutPlayer(i[0])
                    Log("%s disconnected from %s" % (self.leaver, self.ipaddr[0]))
                    print "%s logged out." % self.leaver

                    del sessions[i[0]]
                    del ipsessions[i[0]]

                    self.locali = Select.getAllPlayersWithIP()
                    
                    for j in self.locali:
                        self.tmpsec = sessions[j[0]]
                        if self.tmpsec == None: # Shouldn't happen, do some cleaning
                            Update.LogoutPlayer(j[0])
                        else:
                            self.tmpsec.push(tpl.LEAVE_GAME % (self.leaver,))

                    async_chat.handle_close(self)
                else: raise
            except: raise
Esempio n. 3
0
    def do_help(self, session, line):
        if not line: # help command alone
            self.allh = Select.getAllHelp()
            self.allhelp = []
            for i in self.allh:
                self.allhelp.append(i[0])

            self.allhelp.sort()
            self.counter = 0
            for i in self.allhelp:
                self.counter += 1

            #Make 2 columns of help files
            self.counter = self.counter / 2
            self.counter = int(self.counter)
            self.first = self.allhelp[:self.counter]
            self.second = self.allhelp[self.counter:]
            session.push(tpl.HELP_TOPICS)
            for x, y in map(None, self.first, self.second):
                if x == None:
                    x = ' '
                    session.push(str(x).ljust(15) + str(y).ljust(10) + "\r\n")
                else: session.push(str(x).ljust(15) + str(y).ljust(10) + "\r\n")

        else: #If help <foo>
            try:
                self.helper = Select.getHelp(command)
                session.push("Help for %s: \r\n" % (line,))
                self.docu = self.helper[1].split('\\n')
                for i in self.docu:
                    session.push("%s \r\n" % (i,))
                session.push("\r\n")
            except:
                session.push(tpl.NO_HELP)
Esempio n. 4
0
    def do_clone(self, session, line):
        self.obj = Select.getItemNameId(line.lower())
        self.npc = Select.getNpc(line.lower())

        if self.obj:
            Insert.cloneItem(self.obj[0], session.p_id, time.time())
            session.push(tpl.CLONE % str(self.obj[1]))
        elif self.npc:
            Insert.cloneItem(self.obj[0], session.p_id, time.time())
            session.push(tpl.CLONE % str(self.npc[1]))
        else: session.push(tpl.CLONE_ERR)
Esempio n. 5
0
 def do_who(self, session, line):
     c = C(session)
     session.push("The following players are logged on:\r\n")
     self.whoin = Select.getAllPlayerNames()
     for i in self.whoin:
         session.push("%s\r\n" % (c.B_RED(i[0].capitalize()),))
     session.push("\r\n")
Esempio n. 6
0
    def add(self, session):
        self.ival = ipsessions.items()

        if session.addr[0] != "127.0.0.1" and session.addr[0] in self.ival: # Allow multiusers for the admin.
            session.push(tpl.LOGIN_ALREADY_IN)
            raise EndSession

        sessions[session.p_id] = session
        ipsessions[session.p_id] = session.addr[0]
        Update.setIP(session.addr[0], session.p_id)
        
        #Store the player's starting location in the socket object.
        session.is_in = 1
        Update.setLocation(session.p_id, 1)

        # Check if the user supports ANSI colors
        if Select.getColors(session.p_id) == "on": Actions.do_setansi(session, "on")
        else: Actions.do_setansi(session, "off")

        for i in sessions:
            try:
                i.push(tpl.ENTER_GAME % (session.pname,))
            except: pass

        print "%s logged in." % session.pname
        Log("%s logged in from %s" % (session.pname,session.addr[0]))
        Actions.do_look(session, '') # To be replaced with something nicer.
        session.push("> ")
Esempio n. 7
0
 def do_delitem(self, session, line):
     self.barn = Select.getItemNameId(line)
     try:
         Delete.deleteItem(self.barn[0])
         session.push(tpl.DELITEM % self.barn[1])
     except:
         session.push(tpl.DELITEM_ERR)
Esempio n. 8
0
 def do_kickout(self, session, line):
     try:
         self.kicked = Select.getPlayerByName(line.lower())
         self.kick = self.sessions[self.kicked[0]]
         self.kick.shutdown(0)
     except:
         session.push(tpl.EMAIL_ERR)
Esempio n. 9
0
 def do_ridplayer(self, session, line):
     self.getrid = Select.getPlayerByName(line.lower())
     try:
         Delete.deletePlayer(self.getrid[1])
         session.push(tpl.RIDPLAYER % line.capitalize())
     except:
         session.push(tpl.RIDPLAYER_ERR % line.capitalize())
Esempio n. 10
0
 def do_goto(self, session, line):
     try:
         self.room = Select.getRoom(line)
         Update.setLocation(self.room[0], session.p_id)
         session.is_in = self.room[0]
         session.push(tpl.GOTO)
     except: session.push(tpl.GOTO_ERR)
Esempio n. 11
0
    def do_delnpc(self, session, line):
        self.barn = Select.getNpc(line)

        if self.barn: #If the object exists
            Delete.deleteNpc(self.barn[0])
            session.push(tpl.DELNPC % line)
        else: session.push(tpl.DELNPC_ERR)
Esempio n. 12
0
 def do_email(self, session, line):
     if not line: session.push(tpl.EMAIL)
     else:
         self.email = Select.getEmail(line.lower())
         if self.email:
             session.push("%s: %s\r\n" % (self.email[0], self.email[1]))
         else:
             session.push(tpl.EMAIL_ERR)
Esempio n. 13
0
 def do_delroom(self, session, line):
     try:
         self.fop = Select.getRoom(line)
         Delete.deleteRoom(self.fop[0])
         Delete.deleteLink(self.fop[0])
         session.push(tpl.DELROOM % (fop,))
     except:
         session.push(tpl.DELROOM_ERR)
Esempio n. 14
0
    def do_get(self, session, line):
        self.objonfloor = Select.getItem(session.is_in, line.lower())

        try:
            Update.setItemOwner(session.p_id, self.objonfloor[0])
            session.push(tpl.GET % line)
        except:
            session.push(tpl.NOT_HERE)
Esempio n. 15
0
    def do_drop(self, session, line):
        try:
            self.drop = Select.getItemInstance(session.p_id, line.lower())

            self.drop = Update.dropItem(session.is_in, self.drop[0])
            #self.msg = session.pname + " dropped " + line + "."
            #self.RoomBroadcast(session, session.is_in, self.msg)
            session.push(tpl.DROP % (session.pname, line))
        except: session.push(tpl.DROP_CANT)
Esempio n. 16
0
 def do_dellink(self, session, line):
     if not line: session.push(tpl.DELLINK_ERR)
     self.linker = Select.getLink(line)
     
     if self.linker != []:
         Delete.deleteLinkById(self.linker[0])
         session.push(tpl.DELLINK % self.linker[0])
     else:
         session.push(tpl.DELLINK_ERR)
Esempio n. 17
0
 def do_npcdesc(self, session, line):
     if not line: session.push(tpl.NPCDESC_ERR)
     
     self.splitarg = line.split(' ', 1)
     self.barn = Select.getNpc(self.splitarg[0].lower())
     
     if self.barn:
         setNpcDesc(self.barn[0], self.splitarg[1])
         session.push(tpl.NPCDESC % str(self.splitarg[0]).lower())
     else: session.push(tpl.NPCDESC_ERR)
Esempio n. 18
0
 def do_chat(self, session, line):
     c = C(session)
     self.everybody = Select.getAllPlayers()
     self.talker = c.B_WHITE(session.pname)
     for i in self.everybody:
         self.listen = self.sessions.get(i[0])
         if self.listen == None:
             pass
         else:
             self.lbracket = c.B_GREEN("[")
             self.rbracket = c.B_GREEN("]")
             self.listen.push("%s%s%s %s" % (self.lbracket, self.talker, self.rbracket, line))
Esempio n. 19
0
    def do_inv(self, session, line):
        c = C(session)

        self.owned = Select.getInventory(session.p_id)
        self.owned = c.flatten(self.owned)
        session.push(c.B_WHITE(tpl.INVENTORY))

        self.stufa = {}
        for i in self.owned:
            self.stufa[i] = self.owned.count(i)

        for i in self.stufa:
            if self.stufa[i] > 1:
                c.B_GREEN(str(i))
                session.push("%s (%s)\r\n" % (c.B_GREEN(str(i)),str(self.stufa[i])))
            else:
                session.push("%s\r\n" % (c.B_GREEN(str(i)),))
Esempio n. 20
0
    def RoomBroadcast(self, session, inroom, line):
        "By calling this method, 'line' is sent to all players in 'inroom'."
        c = C(session)

        self.local = Select.getAllPlayersInLoc(inroom)
        self.pnamer = c.B_WHITE(session.pname)
        if not line:
            pass
        else:
            for i in self.local:
                self.tmpses = self.sessions.get(i[0]) # sessions dict
                if not self.tmpses: # Player is not logged in
                    pass
                elif self.tmpses.p_id == session.p_id: # Is the player
                    pass
                else:
                    self.tmpses.push("%s %s\r\n" % (self.pnamer,line))
Esempio n. 21
0
    def do_go(self, session, line):
        if not line: session.push(tpl.DONT_GO)
        else:
            try:
                self.isexit = Select.getExit(session.is_in, line.lower())
            except:
                session.push(tpl.NO_EXIT)

            try:
                # Actually move
                Update.setLocation(session.p_id , self.isexit[1])
                #Effects.RoomBroadcast(session, session.is_in, " leaves %s." % str(self.isexit[2]))
                session.is_in = self.isexit[1]
                #Effects.RoomBroadcast(session, session.is_in, " enters the room.")
                self.do_look(session, '') # Force a look, to be replaced by something nicer.

            except:
                session.push(tpl.CANT_MOVE)
Esempio n. 22
0
    def do_edig(self, session, line):
        c = C(session)
        if not line: session.push(tpl.EDIG_ERR1)
        else:
            self.splitarg = line.split(' ', 1)
            self.exists = Select.getExitsInRoom(session.is_in)

            try:
                self.flat = c.flatten(self.exists)
                if self.splitarg[1] in self.flat:
                    session.push(tpl.EDIG_ERR2)
                else:
                    self.count = Insert.addRoom(self.splitarg[0])
                    Insert.addLink(session.is_in, self.count, self.splitarg[1])
                    Insert.addLink(self.count, session.is_in, self.twoway[self.splitarg[1]])
                    session.push(tpl.EDIG % self.splitarg[1])
            except:
                session.push(tpl.EDIG_ERR1)
Esempio n. 23
0
def main():
    dataset = Dataset()
    config = Config()

    experiments = {}
    total_scores = []
    row_names = []
    col_names = Scoring.get_score_names()
    config_keys = config.get_keys()

    for index, prod in enumerate(config.get_product(), start=1):
        (target, encoding, feature_reducer, test_size, clf_info) = prod

        df = dataset.filter_df_by_targets(target['negative'] +
                                          target['positive'])
        X = dataset.extract_X(df)
        y = dataset.extract_y(df)

        X = get_encoder(encoding).encode(X)
        y = y.map(lambda x: 1 if x in target['positive'] else 0)

        X = get_feature_reducer_and_transform(feature_reducer, X, y)

        data_split = Select(X, y, test_size)
        classifier = Classifier(clf_info['clf'], data_split.X_train,
                                data_split.y_train, clf_info['param_grid'],
                                clf_info['cv'])
        clf = classifier.perform()

        scores = Scoring(clf).get_scores(data_split.X_test, data_split.y_test)

        total_scores.append(scores)
        row_names.append(f'experiment_{index}')
        experiments[f'experiment_{index}'] = dict(
            zip(config_keys, (target, encoding, feature_reducer, test_size, {
                'clf': clf_info['clf'],
                'best_params': classifier.best_params
            })))

    write_data_into_xlsx_file(total_scores, col_names, row_names)
    write_data_into_json_file(experiments)

    return
Esempio n. 24
0
    def check_password(self, passtest):
        self.cchk = Select.getPassword(self.plname)

        self.test = self.encpass(passtest, self.cchk[1])
        if self.test == self.cchk[0]: return 0
        else: return -1
Esempio n. 25
0
 def do_listrooms(self, session, line):
     self.whole = Select.getAllRooms()
     session.push("%6s %15s\r\n" % ("ID", "SHORT DESC"))
     for i in self.whole:
         session.push("%6s %15s\r\n" % (str(i[0]), str(i[1])))
Esempio n. 26
0
 def do_listbans(self, session):
     self.whole = Select.getBannedPlayers()
     session.push("%6s %20s\r\n" % ("ID", "NAME"))
     for i in self.whole:
         session.push("%6s %20s\r\n" % (str(i[0]), str(i[1])))
Esempio n. 27
0
    def check_ban(self, uname):
        self.bchk = Select.getBan(uname)

        if self.bchk[0] == 1: return 1
        else: return 0
Esempio n. 28
0
    def do_listnpcs(self, session, line):
        self.whole = Select.listNpcs()

        session.push("%5s %10s %6s\r\n" % ("ID", "NAME", "DESC"))
        for i in self.whole:
            session.push("%5s %10s %6s\r\n" % (str(i[0]), str(i[1]), str(i[2])))
Esempio n. 29
0
    def do_listplayers(self, session, line):
        self.allplay = Select.listPlayers()

        session.push("%5s %15s %20s\r\n" % ("ID", "NAME", "EMAIL"))
        for i in self.allplay:
            session.push("%5s %15s %20s\r\n" % (str(i[0]), str(i[1]), str(i[2])))
Esempio n. 30
0
    def handle(self, session, cmd):
        """ This is ugly. asynchat doesn't implement interactive sessions so we have
            to simulate a dialog using a counter that is incremented at every step."""

        if not cmd: cmd = " "

        # Filter the telnet commands
        self.tiac = TelnetTalk()
        self.ndata = self.tiac.listen(cmd)
        self.cmd = self.ndata[0]

        session.push(self.ndata[1]) # Reply accordingly

        if self.step == 1:
            self.plname = self.cmd.lower().strip()
            if not self.plname:
                session.push(tpl.NAME_NO + tpl.NAME_INPUT)
                return
            if not self.plname.isalpha():
                session.push(tpl.NAME_ALPHA + tpl.NAME_INPUT)
                return

            wrongname = False
            badnames = open('badnames', 'r')
            for naughtyword in badnames:
                if naughtyword.strip() in self.plname:
                    wrongname = True
                    break
            badnames.close()

            if wrongname:
                session.push(tpl.NAME_BAD + tpl.NAME_INPUT)
                return

            try:
                self.nak = Select.getPlayerByName(self.plname)
                session.push(str(tpl.WELCOME % self.nak[1].capitalize()))
                session.push(tpl.PASSWORD)
                self.echo_off(session)
                self.step = 5 # Existing user
            except: 
                session.push(tpl.WELCOME_NEW)
                self.plname = str(self.plname)
                session.push(tpl.NAME_IS % self.plname.capitalize())
                session.push(tpl.PASSWORD)
                self.echo_off(session)
                self.step = 2 # New user

        elif self.step == 2:
            #self.echo_on(session)
            self.fpass = self.cmd
            if not self.fpass:
                session.push(tpl.PASSWORD)
                self.echo_off(session)
                return
            else:
                session.push(tpl.PASSWORD_CONFIRM)
                self.echo_off(session)
                self.step = 3

        elif self.step == 3:
            self.spass = self.cmd
            if self.fpass == self.spass:
                self.echo_on(session)
                session.push(tpl.ANSI)
                self.step = 6
            else:
                session.push(tpl.PASSWORD_MISMATCH)
                session.push(tpl.PASSWORD)
                self.echo_off(session)
                self.step = 2

        elif self.step == 5:
            self.echo_on(session)

            if not self.cmd:
                session.push(tpl.PASSWORD)
                self.echo_off(session)
                return

            if self.check_password(self.cmd) == 0:
                # Check if the user is banned.
                if self.check_ban(self.plname) == 1:
                    session.push(tpl.BANNED)
                    session.close()
                else:
                    session.push(tpl.LOGIN + tpl.PRESS_ENTER)
                    self.step = 8
            else:
                session.push(tpl.PASSWORD_WRONG)
                session.push(tpl.PASSWORD)
                self.echo_off(session)

        elif self.step == 6:
            self.echo_on(session)
            self.colors = cmd.lower()
            if (self.colors == "y") or (self.colors == "yes"):
                self.ansi = 'on'
            else:
                self.ansi = 'off'
            session.push(tpl.EMAIL)
            self.step = 7

        elif self.step == 7: # CHANGE
            #self.echo_on(session)
            emailreg = re.compile('^[0-9a-z_.+\-]+@[0-9a-z_.\-]+\.[a-z]{2,4}', re.IGNORECASE)
            if emailreg.match(self.cmd) != None:
                self.email = self.cmd
                self.step = 8
                self.createUser(session, self.plname, self.fpass)
            else:
                session.push(tpl.EMAIL_BAD)
                session.push(tpl.EMAIL)
                self.step = 7

        elif self.step == 8:
            self.nak = Select.getIP(self.plname)

            if self.nak[1] != None and self.nak[1] != "127.0.0.1":
                session.push(tpl.LOGIN_ALREADY_IN)
                session.close()
            else:
                # Store some basic info into the socket object.
                session.p_id = self.nak[0]
                session.pname = str(self.plname.capitalize())

                session.push("> ")
                session.enter(self.server.enterg)

        else:
            session.push(tpl.ERROR_CRITICAL)
Esempio n. 31
0
    def do_list_oinst(self, session, line):
        self.instobj = Select.listObjectInstances()

        session.push("%6s %6s %7s %9s\r\n" % ("ID", "OBJ", "OWNER", "LOC"))
        for i in self.instobj:
            session.push("%6s %6s %7s %9s\r\n" % (str(i[0]), str(i[1]), str(i[2]), str(i[3])))