예제 #1
0
def ClientWrite(msg):
    log('Socket sending message: ' + str(msg))
    frame = [129]
    frame += [len(msg)]
    frame_to_send = bytearray(frame) + msg
    if conn is not None:
        conn.send(frame_to_send)
예제 #2
0
파일: main.py 프로젝트: Vgr255/Lexive
    async def on_message(self, message: discord.Message):
        if message.author == self.user:
            return
        if message.content.startswith(config.prefix) or isinstance(message.channel, discord.DMChannel):
            content = message.content.lstrip(config.prefix)
            if not content:
                return

            ctx = await self.get_context(message)
            try:
                log("REQ:", content)
                value = content.split()
                matches = complete_match(value[0], cmds)
                if len(matches) == 1:
                    await cmds[matches[0]](ctx, *value[1:])
                    return

                values, asset = get_card(ctx.guild, content)
                if values and values[0] is None: # too many values
                    await ctx.send(f"Ambiguous value. Possible matches: {', '.join(values[1:])}")
                    return
                elif values:
                    msgs = "\n".join(values).split(r"\NEWLINE/")
                    for msg in msgs:
                        await ctx.send(msg)
                    for ass in asset:
                        with open(os.path.join("assets", ass), mode="rb") as a:
                            await ctx.send(file=discord.File(a))
                    return
            except Exception as e:
                if hasattr(config, "server") and hasattr(config, "channel"):
                    await report(ctx, f"[Automatic reporting]\n{e}")
                raise

            await super().on_message(message)
예제 #3
0
def ClientRead(data):
    opcode_and_fin = data[0]
    msg_len = data[1] - 128
    mask = data[2:6]
    encrypted_msg = data[6:6 + msg_len]
    msg = bytearray([encrypted_msg[i] ^ mask[i % 4] for i in range(msg_len)])
    clientMsg = str(msg, "utf-8")
    log('Socket receiving message: ' + str(clientMsg))
    return clientMsg
예제 #4
0
def test_autogenerated_text():
    count = 0
    for cards in player_cards.values():
        for card in cards:
            code = format(card["code"][0], "PE", card["name"], card["type"])[0]
            if code and code != card["text"]:
                count += 1
                log(_error_str.format(count=count, name=card["name"], code=code, text=card["text"]), level="error")
            special = format(card["code"][1], "PS", card["name"], card["type"])[0]
            if special and special != card["special"]:
                count += 1
                log(_error_str.format(count=count, name=card["name"], code=special, text=card["special"]), level="error")
예제 #5
0
def ClientHandshake(data):
    data = data.decode().split('\r')
    for items in data:
        if 'Sec-WebSocket-Key' in items:
            log('Socket handshaking...')
            key = items.split(': ')[1]
            resp = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
            resp = hashlib.sha1(resp).digest()
            resp = binascii.b2a_base64(resp)[:-1]
            response = "HTTP/1.1 101 Switching Protocols\r\n" + \
                "Upgrade: websocket\r\n" + \
                "Connection: Upgrade\r\n" + \
                "Sec-WebSocket-Accept: %s\r\n\r\n" % (
                    resp.decode("utf-8"))
            conn.send(response.encode())
            log('Client is connected!!!')
예제 #6
0
            resp = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
            resp = hashlib.sha1(resp).digest()
            resp = binascii.b2a_base64(resp)[:-1]
            response = "HTTP/1.1 101 Switching Protocols\r\n" + \
                "Upgrade: websocket\r\n" + \
                "Connection: Upgrade\r\n" + \
                "Sec-WebSocket-Accept: %s\r\n\r\n" % (
                    resp.decode("utf-8"))
            conn.send(response.encode())
            log('Client is connected!!!')


# Socket process loop
while True:
    conn, addr = sock.accept()
    log('Socket client connection request from: ' + str(addr))
    handshake = True
    while True:
        data = conn.recv(1024)
        log('Socket data received...')
        if (len(data) <= 8):
            print('Socket client left...')
            conn = None
            break
        if handshake:
            ClientHandshake(data)
            handshake = False
        else:
            msg = ClientRead(data)
            ClientWrite(msg)
            HandleData(msg)
예제 #7
0
파일: main.py 프로젝트: Vgr255/Lexive
        return func
    return wrapper

breaches_orientation = (
    "Open",
    "Facing up",
    "Facing left",
    "Facing down",
    "Facing right",
)

# Breach opening cost formula:
# ((position-1)*number of focuses needed to open)+1
# (position*number of focuses)-number of focuses+1

log("Loading content", level="local")
load()
log("Loading complete", level="local")

activity = discord.Activity(
    name=f"{config.prefix}whoami",
    application_id=0,
    url="https://github.com/Vgr255/Lexive",
    type=discord.ActivityType.playing,
    state="Studying the arcane knowledge",
)

class Lexive(commands.Bot):
    async def on_message(self, message: discord.Message):
        if message.author == self.user:
            return