# Path: eaEmu/db.py
#    def makeMod(modname):
#    def makeClasses(modname, classes):
#    def Join(self, session): # TODO?
#    def Leave(self, session):
#    def getKey(cls, gameName):
#    def _get_login_dirty(self):
#    def _set_login_dirty(self, value):
#    def GetUser(cls, **kw):
#    def CreateUser(name, pwd=None):
#    def addPersona(self, name):
#       def add():
#       def ebAdd(err):
#    def getPersonas(self):
#    def getPersona(self):
#    def _get_umode(self):
#    def _set_umode(self, value):
#    def getChanMode(self, channel):
#    def setChanMode(self, channel, value):
# def modifyMode(mode, mod):
#    def getUser(cls, **kw):
#    def getStats(cls, name, chanName):
#       def dbOps():
#    def dumpFields(self, fields, withNames=False):
# def syncAccount(username):
#    def ebRunQuery(err):
#    def cbRunQuery(result):
#    def __init__(self, *args, **kw):
#    def Login(self, username, pwd):
#       def cbSync(user):
#       def ebSync(err):
#       def ebGetUser(err):
#       def cbGotUser(user):
#       def cbUserAuth(isMatch, user):
#       def ebPlainAuth(err, user):
#          def ebBadPwd(err):
#       def cbCheckNumSessions(user):
#    def getTheater(cls, name):
#    def PlayerLeaveGame(self, session, game_id):
#    def PlayerJoinGame(self, session, game_id):
#    def CreateSession(self, ip, port):
#    def DeleteSession(self, ip, port):
#    def ConnectionEstablished(self, key, user):
#    def ConnectionClosed(self, sess):
#    def GetSession(self, key):
#    def CreateGame(self):
#    def ListGames(self, filters=None):
#    def GetGame(self, game_id=None, host=None):
#    def __init__(self, model):
#    def __call__(self, func):
#       def djangoAsyncWrapper(*args, **kw):
#          def sigSaved(**kw):
# class _GameSessionAspect(object):
# class _GameAspect(object):
# class _UserAspect:
# class _PersonaAspect:
# class _StatsAspect:
# class _LoginSessionAspect(object):
# class _TheaterAspect(object):
# class djangoAsync(object):


from twisted.protocols.portforward import *
from twisted.application.service import MultiService
from twisted.application.internet import TCPServer
from ..db import Game
from .peerchat import *
      from twisted.internet import reactor
      if data:
         data = self.cipher.serverIngress.crypt(data)
         print(repr(data))
         ProxyClient.dataReceived(self, data)

class PeerchatProxyClientFactory(ProxyClientFactory):
   protocol = PeerchatProxyClient

class PeerchatProxyServer(ProxyServer):
   clientProtocolFactory = PeerchatProxyClientFactory

   def connectionMade(self):
      self.transport.pauseProducing()
      client = self.clientProtocolFactory()
      client.setServer(self)

      reactor.connectTCP(self.factory.host, self.factory.port, client)

   def dataReceived(self, data):
      print(repr(data))
      if self.peer.cipher:
         data = self.peer.cipher.clientEgress.crypt(data)
      ProxyServer.dataReceived(self, data)

class PeerchatProxyServerFactory(ProxyFactory):
   protocol = PeerchatProxyServer

   def __init__(self, gameName, host, port):
      ProxyFactory.__init__(self, host, port)
      self.gameName = gameName

# Path: eaEmu/db.py
#    def makeMod(modname):
#    def makeClasses(modname, classes):
#    def Join(self, session): # TODO?
#    def Leave(self, session):
#    def getKey(cls, gameName):
#    def _get_login_dirty(self):
#    def _set_login_dirty(self, value):
#    def GetUser(cls, **kw):
#    def CreateUser(name, pwd=None):
#    def addPersona(self, name):
#       def add():
#       def ebAdd(err):
#    def getPersonas(self):
#    def getPersona(self):
#    def _get_umode(self):
#    def _set_umode(self, value):
#    def getChanMode(self, channel):
#    def setChanMode(self, channel, value):
# def modifyMode(mode, mod):
#    def getUser(cls, **kw):
#    def getStats(cls, name, chanName):
#       def dbOps():
#    def dumpFields(self, fields, withNames=False):
# def syncAccount(username):
#    def ebRunQuery(err):
#    def cbRunQuery(result):
#    def __init__(self, *args, **kw):
#    def Login(self, username, pwd):
#       def cbSync(user):
#       def ebSync(err):
#       def ebGetUser(err):
#       def cbGotUser(user):
#       def cbUserAuth(isMatch, user):
#       def ebPlainAuth(err, user):
#          def ebBadPwd(err):
#       def cbCheckNumSessions(user):
#    def getTheater(cls, name):
#    def PlayerLeaveGame(self, session, game_id):
#    def PlayerJoinGame(self, session, game_id):
#    def CreateSession(self, ip, port):
#    def DeleteSession(self, ip, port):
#    def ConnectionEstablished(self, key, user):
#    def ConnectionClosed(self, sess):
#    def GetSession(self, key):
#    def CreateGame(self):
#    def ListGames(self, filters=None):
#    def GetGame(self, game_id=None, host=None):
#    def __init__(self, model):
#    def __call__(self, func):
#       def djangoAsyncWrapper(*args, **kw):
#          def sigSaved(**kw):
# class _GameSessionAspect(object):
# class _GameAspect(object):
# class _UserAspect:
# class _PersonaAspect:
# class _StatsAspect:
# class _LoginSessionAspect(object):
# class _TheaterAspect(object):
# class djangoAsync(object):


# Path: eaEmu/gamespy/peerchatProxy.py
from twisted.protocols.portforward import *
from twisted.application.service import MultiService
from twisted.application.internet import TCPServer
from ..db import Game
from .peerchat import *
      from twisted.internet import reactor

      if data:
         data = self.cipher.serverIngress.crypt(data)
         print(repr(data))
         ProxyClient.dataReceived(self, data)

class PeerchatProxyClientFactory(ProxyClientFactory):
   protocol = PeerchatProxyClient

class PeerchatProxyServer(ProxyServer):
   clientProtocolFactory = PeerchatProxyClientFactory

   def connectionMade(self):
      self.transport.pauseProducing()
      client = self.clientProtocolFactory()
      client.setServer(self)

      reactor.connectTCP(self.factory.host, self.factory.port, client)

   def dataReceived(self, data):
      print(repr(data))
      if self.peer.cipher:
         data = self.peer.cipher.clientEgress.crypt(data)
      ProxyServer.dataReceived(self, data)

class PeerchatProxyServerFactory(ProxyFactory):
   protocol = PeerchatProxyServer

   def __init__(self, gameName, host, port):
      ProxyFactory.__init__(self, host, port)
      self.gameName = gameName

      self.gameKey = Game.getKey(self.gameName)