Devsaider
@Devsaider

Python, Twisted. Подключение к другому серверу после reactor.run() и получения данных от основного

Есть одна игры. Я пытаюсь сделать к ней бот.
После подключения к основному серверу (далее main) клиент отсылает некоторые данные, после чего получает ip и порт другого сервера (далее bulle), протокол у них одинаковый. Нужно создать второй клиент для bulle-сервера и поместить кое-какие данные от bulle в Factory, чтобы их можно было использовать в обоих клиентах.

Не очень хорошо знаю английский, пытался гуглить – ничего не нашел.

#coding: utf-8
from bytearray import ByteArray
from fingerprint import fingerprint
from Protocole import *
from twisted.internet import reactor, protocol

def _(text):
    print "[DEBUG] " + text

class TransformiceBotFactory(protocol.ClientFactory):

    def __init__(self):
        self.oop = 0

    def clientConnectionFailed(self, connector, reason):
        _("Connection failed!")
        #reactor.stop()
    
    def clientConnectionLost(self, connector, reason):
        _("Connection lost!")
        #reactor.stop()
        #main()

class TransformiceBotMainServeurClient(TFMClientProtocol):

    def connectionMade(self):
        _("Connected to main server.")
        self.factory.oop += 1
        print self.factory.oop
        self.sendInitialPacket()

    
    def connectionLost(self, reason):
        _("connection lost")

    def sendInitialPacket(self):
        bulleClient = TransformiceBotFactory()
        bulleClient.protocol = TransformiceBotBulleServeurClient

        reactor.connectTCP("bulleip", 44440, bulleClient)


class TransformiceBotBulleServeurClient(TFMClientProtocol):

    def connectionMade(self):
        _("Connected to bulle server.")
        _(str(self.factory.oop))
        self.sendInitialPacket()

    
    def connectionLost(self, reason):
        _("connection lost")

    def sendInitialPacket(self):return

def main():
    _("Transformice bot is reloaded!")
    #from twisted.python import log
    #import sys

    #log.startLogging(sys.stdout)

    mainClient = TransformiceBotFactory()
    mainClient.protocol = TransformiceBotMainServeurClient

    reactor.connectTCP("mainip", 44440, mainClient)
    reactor.run()


if __name__ == "__main__":
    # running not as imported module
    main()
  • Вопрос задан
  • 3141 просмотр
Пригласить эксперта
Ответы на вопрос 1
qmax
@qmax
программер
Так а что мешает просто добавить атрибут к объекту Factory?
В смысле что вынести mainClient в более глобальную область видимости и сделать mainClient.somedata = блаблабла

А трансформайсы разве не банят за ботов?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы