0

我正在做一个泥客户端,我正在使用Duris进行连接。但是服务器似乎没有收到我一直在发送的内容,因为它在等待一分钟左右后发送回空闲超时。请注意,我是 sack overflow 的新手,我还不明白如何使用代码块。如果有人能告诉我典型的泥浆使用什么编码,那就太好了。

我的代码:

import asyncio
import socket
import socket
import os
import pyfiglet
import time
import datetime
import websockets
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

class menu:
    def debug_menu():
        print("--debug--")
        print("-"*50)
    def menu_1():
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        print(" ")
        result = pyfiglet.figlet_format("-- D R A A K", font = "3-d" )
        print(result)
        print(" ")
        result = pyfiglet.figlet_format("-- MUD ", font = "3-d" )
        print(result)
        print(" ")
        result = pyfiglet.figlet_format("-- CLIENT ", font = "3-d" )
        print(result)
        print(" ")
        print("-"*50)
        print("Version: 1.0.0")
class main:
    def recv(triggers,triggers_act,alias,alias_act):
        message=sock.recv(1000)
        temp=0
        while True:
            try:
                if message in triggers[temp]:

                    print(f"trig--{triggers_act[temp]}")
                    main.send_main(triggers_act[temp],alias,alias_act)
                    return
            except:
                print(type(message))
                return message.decode(dec)
            temp+=1

    def send_main(message,alias,alias_act):
        temp=0
        while True:
            try:
                if message in alias[temp]:
                    sock.sendall(alias_act[temp].encode(dec))
                    break
            except:
                sock.sendall(message.encode(dec))
                break
            temp+=1

    def get_url(url,debug):
        return socket.gethostbyname(url)
    def disconnect(debug):
        if debug==False:
            try:
                sock.close()
                print("--Success--")
            except:
                print("--ERROR--")
        if debug==True:
            sock.close()

    def connect(ip,port,debug):

        if debug==False:
            sock.connect((ip,port))

            print("--Connection success--")
            print(f"ip: {ip}")
            print(f"port: {port}")
        if debug==True:
            sock.connect((ip,port))
    def brute_connect(ip,debug):
        port=0


        while True:
            try:
                sock.connect((ip,port))

                print("--Connection success--")
                print(f"ip: {ip}")
                print(f"port: {port}")

            except:
                os.system("clear")
                print("--Failure--")
                print(f"ip: {ip}")
                print(f"port: {port}")
                return port
            port+=1



    def ping(name):
        name='ping '+name
        os.system(name)
    def ip_find(url):
        ip = socket.gethostbyname(url)
        return ip
class Shell:
    def main_shell(com,debug):
        com_temp=com.split(str_split)
        if com_temp[0]=="-shell":
            if com_temp[1]=="clear":
                os.system("cls")
            if com_temp[1]=="reopen":
                print("Restarting...")
                time.sleep(1)
                os.system("Dmud_Main.py")


            if com_temp[1]=="quit":
                quit()
        else:
            commands.main(com,debug)


    pass

class commands:
    def main(com,debug):
        com=com.split(str_split)
        if debug==True:
            print("debug=True")
        if com[0]=="-timeout":
            sock.setdefaulttimeout(int(com[1]))
        if com[0]=="-disconnect":
            main.disconnect(debug)
        if com[0]=="-connect":
            if debug==True:

                com=com[1]
                com=com.split(":")
                main.connect(com[0],int(com[1]),debug)
            elif debug==False:
                try:
                    com=com[1]
                    com=com.split(":")
                    main.connect(com[0],int(com[1]),debug)

                except:
                    print("--Failure--")
                    print(f"ip: {com[0]}")
                    print(f"port: {com[1]}")


        if com[0]=="-url":
            ip=main.get_url(com[1],debug)

            print(f"--{ip}--")
    pass

menu.menu_1()
global debug
global str_split
global triggers
global triggers_act
global alias_act
global alias
alias=[]
alias_act=[]
triggers=[]
triggers_act=[]
str_split=" "
dec="UTF-8"
debug=False
while True:

    command=input(">>> ")
    temp_com=command.split(str_split)
    if temp_com[0]=="-begin":
        while True:
            if debug==True:
                print("--recieving--")
            print(main.recv(triggers,triggers_act,alias,alias_act))
            command=input("}} ")
            if "-" in command:
                Shell.main_shell(command,debug)
            else:
                if debug==True:
                    print("--sending--")
                    print(f"sent: {command}")
                main.send_main(command,alias,alias_act)
                print("--complete--")
    if temp_com[0]=="-split":
        if temp_com[1]=="r":
            print(f"split: {str_split}")
        else:
            str_split=temp_com[1]
            print(f"split: {str_split}")
    if temp_com[0]==
    if temp_com[0]=="-debug":
        try:
            if temp_com[1]=="true":
                print("Debug is now true")
                debug=True


            if temp_com[1]=="false":
                print("Debug is now false")
                debug=False
        except:
            print(f"Debug={debug}")
    else:
        Shell.main_shell(command,debug)

输入和输出:

>>> -connect mud.durismud.com:2002
--Connection success--
ip: mud.durismud.com
port: 2002
>>> -debug true
Debug is now true
>>> -begin
--recieving--
<class 'bytes'>
Looking up your hostname...
Please enter term type (<CR> for ANSI, '1' for Generic, '9' for Quick):
}} 1
--sending--
sent: 1
--complete--
--recieving--
<class 'bytes'>
Idle Timeout

}}
4

0 回答 0