示例#1
0
文件: do_quit.py 项目: totalgit/PyRom
def do_quit(ch, argument):
    if ch.is_npc():
        return
    if ch.position == merc.POS_FIGHTING:
        ch.send("No way! You are fighting.\n")
        return
    if ch.position < merc.POS_STUNNED:
        ch.send("You're not DEAD yet.\n")
        return
    ch.send("Alas, all good things must come to an end.\n")
    handler_game.act("$n has left the game.", ch, None, None, merc.TO_ROOM)
    logger.info("%s has quit.", ch.name)
    handler_game.wiznet("$N rejoins the real world.", ch, None,
                        merc.WIZ_LOGINS, 0, ch.trust)
    # After extract_char the ch is no longer valid!
    ch.save(logout=True, force=True)
    #save.legacy_save_char_obj(ch)
    id = ch.id
    d = ch.desc
    ch.extract(True)
    if d is not None:
        comm.close_socket(d)

    # toast evil cheating bastards
    for d in merc.descriptor_list[:]:
        tch = handler_ch.CH(d)
        if tch and tch.id == id:
            tch.extract(True)
            comm.close_socket(d)
    return
示例#2
0
def con_break_connect(self):
    argument = self.get_command()[:1].lower()
    ch = self.character

    if argument == 'y':
        for d_old in merc.descriptor_list[:]:
            if d_old == self or not d_old.character:
                continue
            chname = d_old.original if d_old.original else d_old.character
            if ch.name != chname:
                continue
            comm.close_socket(d_old)
        if comm.check_reconnect(self, ch.name, True):
            return
        self.send("Reconnect attempt failed.\nName: ")
        if self.character:
            del self.character
            self.character = None
        self.set_connected(con_get_name)
        return
    if argument == 'n':
        self.send("Name: ")
        if self.character:
            del self.character
            self.character = None
        self.set_connected(con_get_name)
        return

    self.send("Please type Y or N? ")
    return
示例#3
0
def cmd_disconnect(ch, argument):
    argument, arg = game_utils.read_word(argument)

    if not arg:
        ch.send("Disconnect whom?\n")
        return

    victim = ch.get_char_world(arg)
    if not victim:
        ch.not_here(arg)
        return

    if not victim.desc:
        handler_game.act("$N doesn't have a descriptor.", ch, None, victim,
                         merc.TO_CHAR)
        return

    if victim.act.is_set(
            merc.PLR_GODLESS
    ) and ch.trust < merc.NO_GODLESS and not ch.extra.is_set(
            merc.EXTRA_ANTI_GODLESS):
        ch.send("You failed.\n")
        return

    for d in instance.descriptor_list:
        if d == victim.desc:
            comm.close_socket(d)
            ch.send("Ok.\n")
            return

    comm.notify("cmd_disconnect: desc not found", merc.CONSOLE_WARNING)
    ch.send("Descriptor not found!\n")
示例#4
0
def do_quit(ch, argument):
    if ch.is_npc():
        return
    if ch.position == merc.POS_FIGHTING:
        ch.send("No way! You are fighting.\n")
        return
    if ch.position < merc.POS_STUNNED:
        ch.send("You're not DEAD yet.\n")
        return
    ch.send("Alas, all good things must come to an end.\n")
    handler_game.act("$n has left the game.", ch, None, None, merc.TO_ROOM)
    logger.info("%s has quit.", ch.name)
    handler_game.wiznet("$N rejoins the real world.", ch, None, merc.WIZ_LOGINS, 0, ch.trust)
    # After extract_char the ch is no longer valid!
    ch.save(logout=True, force=True)
    #save.legacy_save_char_obj(ch)
    id = ch.id
    d = ch.desc
    ch.extract(True)
    if d is not None:
        comm.close_socket(d)

    # toast evil cheating bastards
    for d in merc.descriptor_list[:]:
        tch = handler_ch.CH(d)
        if tch and tch.id == id:
            tch.extract(True)
            comm.close_socket(d)
    return
示例#5
0
def do_disconnect(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        ch.send("Disconnect whom?\n")
        return
    if arg.isdigit():
        desc = int(arg)
        for d in merc.descriptor_list:
            if d.descriptor == desc:
                comm.close_socket(d)
                ch.send("Ok.\n")
                return
    victim = ch.get_char_world(arg)
    if not victim:
        ch.send("They aren't here.\n")
        return
    if victim.desc is None:
        handler_game.act("$N doesn't have a descriptor.", ch, None, victim,
                         merc.TO_CHAR)
        return
    for d in merc.descriptor_list:
        if d == victim.desc:
            comm.close_socket(d)
            ch.send("Ok.\n")
            return
    logger.warn("BUG: Do_disconnect: desc not found.")
    ch.send("Descriptor not found!\n")
    return
示例#6
0
def do_disconnect(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        ch.send("Disconnect whom?\n")
        return
    if arg.isdigit():
        desc = int(arg)
        for d in merc.descriptor_list:
            if d.descriptor == desc:
                comm.close_socket(d)
                ch.send("Ok.\n")
                return
    victim = ch.get_char_world(arg)
    if not victim:
        ch.send("They aren't here.\n")
        return
    if victim.desc is None:
        handler_game.act("$N doesn't have a descriptor.", ch, None, victim, merc.TO_CHAR)
        return
    for d in merc.descriptor_list:
        if d == victim.desc:
            comm.close_socket(d)
            ch.send("Ok.\n")
            return
    logger.warn("BUG: Do_disconnect: desc not found.")
    ch.send("Descriptor not found!\n")
    return
示例#7
0
def con_get_timecode(self):
    argument = self.get_command()
    ch_dummy = self.character

    if not ch_dummy.stub['auth'].verify(argument):
        ch_dummy.send('\nWrong timecode.\n')
        ch_dummy.failed_attempts += 1
        if ch_dummy.failed_attempts > 3:
            comm.close_socket(self)
        else:
            ch_dummy.send('Authenticator code: ')
            self.set_connected(con_get_timecode)
        return

    ch_dummy.send("\n")
    if comm.check_playing(self, ch_dummy.name):
        return

    if comm.check_reconnect(self, ch_dummy.name, True):
        return
    ch = handler_pc.Pc.load(ch_dummy.name)
    del ch_dummy
    ch.send = self.send
    ch.desc = self
    self.character = ch
    log_buf = "%s@%s has connected." % (ch.name, self.addrport())
    logger.info(log_buf)
    handler_game.wiznet(log_buf, None, None, merc.WIZ_SITES, 0, ch_dummy.trust)
    if ch.is_immortal():
        ch.do_help("imotd")
        self.set_connected(con_read_imotd)
    else:
        ch.do_help("motd")
        self.set_connected(con_read_motd)
    return
示例#8
0
def cmd_quit(ch, argument):
    if ch.is_npc():
        return

    if ch.position == merc.POS_FIGHTING:
        ch.send("No way! You are fighting.\n")
        return

    if ch.position < merc.POS_SLEEPING:
        ch.send("You're not DEAD yet.\n")
        return

    mount = ch.mount
    if mount:
        ch.cmd_dismount("")

    # After extract_char the ch is no longer valid!
    for item_id in ch.equipped.values():
        if not item_id:
            continue

        item = instance.items[item_id]

        if not ch.is_npc() and (item.chobj and not item.chobj.is_npc() and item.chobj.obj_vnum != 0) or item.item_type == merc.ITEM_KEY:
            ch.unequip(item.equipped_to, silent=True, forced=True)

    ch.save(logout=True, force=True)

    if ch.obj_vnum != 0:
        handler_game.act("$n slowly fades out of existance.", ch, None, None, merc.TO_ROOM)
    else:
        handler_game.act("$n has left the game.", ch, None, None, merc.TO_ROOM)

    comm.notify("{} has quit.".format(ch.name), merc.CONSOLE_INFO)
    if ch.obj_vnum == 0:
        comm.info("{} has left the God Wars.".format(ch.name))

    if ch.chobj:
        ch.chobj.extract()

    ch.send("\n           I'm a lean dog, a keen dog, a wild dog, and lone;\n"
            "           I'm a rough dog, a tough dog, hunting on my own;\n"
            "           I'm a bad dog, a mad dog, teasing silly sheep;\n"
            "           I love to sit and bay the moon, to keep fat souls from sleep.\n\n")

    d = ch.desc
    pid = ch.id
    ch.extract(True)

    if d:
        comm.close_socket(d)

    # toast evil cheating bastards
    for d in instance.descriptor_list[:]:
        tch = handler_ch.ch_desc(d)
        if tch and tch.id == pid:
            tch.extract(True)
            comm.close_socket(d)
示例#9
0
def do_reboot(ch, argument):
    if ch.invis_level < merc.LEVEL_HERO:
        ch.do_echo("Reboot by %s." % ch.name)
    comm.done = True
    for d in merc.descriptor_list[:]:
        vch = handler_ch.CH(d)
        if vch:
            vch.save(logout=True, force=True)
            comm.close_socket(d)
示例#10
0
def do_shutdown(ch, argument):
    if ch.invis_level < merc.LEVEL_HERO:
        ch.do_echo("Shutdown by %s." % ch.name)
    comm.done = True
    for d in merc.descriptor_list[:]:
        vch = handler_ch.CH(d)
        if vch:
            vch.save(logout=True, force=True)
            comm.close_socket(d)
示例#11
0
def cmd_reboot(ch, argument):
    ch.cmd_echo("Reboot by {}.".format(ch.name))
    comm.down = True

    for d in instance.descriptor_list[:]:
        vch = handler_ch.ch_desc(d)
        if vch:
            vch.save(logout=True, force=True)
            comm.close_socket(d)
示例#12
0
def con_get_name(self):
    argument = self.get_command()
    name = argument.title()

    if not check_parse_name(name):
        self.send("Illegal name, try another.\n" "Name: ")
        return

    if not self.character:
        ch_dummy = CharDummy()
        ch_dummy.desc = self
        self.character = ch_dummy
        ch_dummy.send = self.send
    else:
        ch_dummy = self.character

    ch_dummy.name = name
    comm.notify("{} trying to connect".format(name), merc.CONSOLE_INFO)

    ch_dummy.stub = handler_pc.Pc.load_stub(name)
    if ch_dummy.stub:
        found = True
        if ch_dummy.stub["is_banned"]:
            comm.notify(
                "Denying access to {}@{}".format(ch_dummy.stub["name"],
                                                 self.addrport()),
                merc.CONSOLE_INFO)
            self.send("You are denied access.\n")
            comm.close_socket(self)
            return

        if settings.WIZLOCK and not ch_dummy.stub["is_immortal"]:
            self.send("The game is wizlocked.\n")
            comm.close_socket(self)
            return

        if comm.is_reconnecting(self, name):
            found = True
    else:
        found, ch_dummy = save.legacy_load_char_obj(self, name)
        ch_dummy.send = self.send
        ch_dummy.desc = self
        self.character = ch_dummy

    if found:
        ch_dummy.send("Please enter password: "******"You want {} engraved on your tombstone (Y/N)? ".format(
            ch_dummy.name))
        self.set_connected(con_confirm_new_name)
示例#13
0
def cmd_shutdown(ch, argument):
    buf = "Shutdown by {}.".format(ch.name)
    ch.cmd_echo(buf)
    game_utils.append_file(ch, settings.SHUTDOWN_FILE, buf)
    comm.done = True

    for d in instance.descriptor_list[:]:
        vch = handler_ch.ch_desc(d)
        if vch:
            vch.save(logout=True, force=True)
            comm.close_socket(d)

    if pywars.server:
        pywars.server.stop()
示例#14
0
def con_get_old_password(self):
    argument = self.get_command()
    ch_dummy = self.character
    ch_dummy.desc.password_mode_off()
    if settings.ENCRYPT_PASSWORD:
        argument = argument.encode('utf8')
        pwdcmp = hashlib.sha512(argument).hexdigest()
    else:
        pwdcmp = argument
    if pwdcmp != ch_dummy.stub['pwd']:
        ch_dummy.send("\nWrong password.\n")
        ch_dummy.failed_attempts += 1
        if ch_dummy.failed_attempts > 3:
            comm.close_socket(self)
        else:
            ch_dummy.send("Password: "******"\n")
    if comm.check_playing(self, ch_dummy.name):
        return

    if comm.check_reconnect(self, ch_dummy.name, True):
        return
    ch = handler_pc.Pc.load(ch_dummy.name)
    del ch_dummy
    ch.send = self.send
    ch.desc = self
    self.character = ch
    log_buf = "%s@%s has connected." % (ch.name, self.addrport())
    logger.info(log_buf)
    handler_game.wiznet(log_buf, None, None, merc.WIZ_SITES, 0, ch.trust)
    if ch.is_immortal():
        ch.do_help("imotd")
        self.set_connected(con_read_imotd)
    else:
        ch.do_help("motd")
        self.set_connected(con_read_motd)
    return
示例#15
0
def do_purge(ch, argument):
    argument, arg = game_utils.read_word(argument)
    if not arg:
        for victim_id in ch.in_room.people:
            victim = instance.characters[victim_id]
            if victim.is_npc() and not state_checks.IS_SET(victim.act, merc.ACT_NOPURGE) \
                    and victim != ch:  # safety precaution
                victim.in_room.get(victim)
                victim.extract(True)
        for item_id in ch.in_room.items:
            item = instance.items[item_id]
            if not item.flags.no_purge:
                ch.in_room.get(item)
                item.extract()
        handler_game.act("$n purges the room!", ch, None, None, merc.TO_ROOM)
        ch.send("Ok.\n")
        return
    victim = ch.get_char_world(arg)
    if not victim:
        ch.send("They aren't here.\n")
        return
    if not victim.is_npc():
        if ch == victim:
            ch.send("Ho ho ho.\n")
            return
        if ch.trust <= victim.trust:
            ch.send("Maybe that wasn't a good idea...\n")
            victim.send("%s tried to purge you!\n" % ch.name)
            return
        handler_game.act("$n disintegrates $N.", ch, 0, victim, merc.TO_NOTVICT)

        if victim.level > 1:
            victim.save(logout=True, force=True)
        d = victim.desc
        victim.in_room.get(victim)
        victim.extract(True)
        if d:
            comm.close_socket(d)
        return
    handler_game.act("$n purges $N.", ch, None, victim, merc.TO_NOTVICT)
    victim.extract(True)
    return
示例#16
0
def con_get_old_password(self):
    argument = self.get_command()
    ch_dummy = self.character
    ch_dummy.send("\n")
    ch_dummy.desc.password_mode_off()

    pwdcmp = argument
    if pwdcmp != ch_dummy.stub["pwd"]:
        ch_dummy.send("Wrong password.\n")
        comm.close_socket(self)
        return

    ch_dummy.desc.password_mode_on()
    if comm.check_reconnect(self, ch_dummy.name, True):
        return

    if comm.check_playing(self, ch_dummy.name):
        return

    ch = handler_pc.Pc.load(ch_dummy.name)
    del ch_dummy
    ch.send = self.send
    ch.desc = self
    self.character = ch
    comm.notify("{}@{} has connected.".format(ch.name, self.addrport()),
                merc.CONSOLE_INFO)

    # In case we have level 4+ players from another merc mud, or
    # players who have somehow got file access and changed their pfiles.
    if ch.level > 3 and ch.trust == 0:
        ch.level = 3
    else:
        ch.level = min(ch.level, merc.MAX_LEVEL)
        ch.trust = min(ch.trust, merc.MAX_LEVEL)

    if ch.is_hero():
        ch.cmd_help("imotd")
    ch.cmd_help("motd")
    self.set_connected(con_read_motd)
示例#17
0
    def stop(self):
        # Disconnects the clients and shuts down the server
        for clients in self.client_list():
            comm.close_socket(clients.sock)

        self.server_socket.close()
示例#18
0
    def poll(self):
        # Perform a non-blocking scan of recv and send states on the server
        # and client connection sockets.  Process new connection requests,
        # read incomming data, and send outgoing data.  Sends and receives may
        # be partial.
        #
        # Build a list of connections to test for receive data pending
        recv_list = [self.server_fileno]  # always add the server

        del_list = []  # list of clients to delete after polling

        for client in self.clients.values():
            if client.active:
                recv_list.append(client.fileno)
            else:
                self.on_disconnect(client)
                del_list.append(client.fileno)
                client.sock.close()

        # Delete inactive connections from the dictionary
        for client in del_list:
            del self.clients[client]

        # Build a list of connections that need to send data
        send_list = []
        for client in self.clients.values():
            if client.send_pending:
                send_list.append(client.fileno)

        # Get active socket file descriptors from select.select()
        try:
            rlist, slist, elist = select.select(recv_list, send_list, [],
                                                self.timeout)
        except select.error as err:
            # If we can't even use select(), game over man, game over
            comm.notify("SELECT socket error '{}'".format(str(err)),
                        merc.CONSOLE_ERROR)
            raise

        # Process socket file descriptors with data to receive
        for sock_fileno in rlist:
            # If it's coming from the server's socket then this is a new
            # connection request.
            if sock_fileno == self.server_fileno:
                try:
                    sock, addr_tup = self.server_socket.accept()
                except socket.error as err:
                    comm.notify(
                        "ACCEPT socket error '{}:{}'.".format(
                            err.errno, err.strerror), merc.CONSOLE_ERROR)
                    continue

                # Check for maximum connections
                if self.client_count() >= self.max_connections:
                    comm.notify(
                        "Refusing new connection, maximum already in use.",
                        merc.CONSOLE_INFO)
                    comm.close_socket(sock)
                    continue

                # Create the client instance
                new_client = TelnetClient(sock, addr_tup)

                # Add the connection to our dictionary and call handler
                self.clients[new_client.fileno] = new_client
                self.on_connect(new_client)

            else:
                # Call the connection's recieve method
                try:
                    self.clients[sock_fileno].socket_recv()
                except ConnectionLost:
                    self.clients[sock_fileno].deactivate()

        # Process sockets with data to send
        for sock_fileno in slist:
            # Call the connection's send method
            self.clients[sock_fileno].socket_send()