Example #1
0
from twisted.internet import reactor

from pokernetwork import log as network_log
log = network_log.get_child('lockcheck')

class LockCheck(object):

    log = log.get_child('LockCheck')

    def __init__(self, timeout, callback, cb_args=()):
        self._timeout = timeout
        self._callback = callback
        self._callback_args = cb_args
        self._timer = None

    def start(self):
        try:
            if self._timer is None or not self._timer.active():
                self._timer = reactor.callLater(self._timeout, self._callback, *self._callback_args)
            else:
                self._timer.reset(self._timeout)
        except:
            self.log.error("Exception on start()", exc_info=1)

    def stop(self):
        try:
            if self._timer is None:
                return
            if self._timer.active():
                self._timer.cancel()
            self._timer = None
Example #2
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

from twisted.python.runtime import seconds
from pokernetwork.user import User
from pokerpackets.packets import PACKET_LOGIN, PACKET_AUTH
from pokernetwork import log as network_log

log = network_log.get_child("pokerauth")


def _import(path):
    import sys
    __import__(path)
    return sys.modules[path]


class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, memcache, settings):
        self.db = db
        self.memcache = memcache
Example #3
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Johan Euphrosine <*****@*****.**>
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#

from pokernetwork import log as network_log
log = network_log.get_child('pokerbot')


import sys
import os
sys.path.insert(0, "..")

import platform
from os.path import exists
from random import randint

from twisted.application import internet, service, app

from twisted.python import log as twisted_log
import reflogging
from reflogging.handlers import GELFHandler, StreamHandler, ColorStreamHandler, SyslogHandler
Example #4
0
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#
#
import sys
from twisted.internet import reactor, protocol, defer

from pokernetwork import log as network_log
log = network_log.get_child('server')

from pokernetwork.protocol import UGAMEProtocol
from pokerpackets.packets import PacketError

class PokerServerProtocol(UGAMEProtocol):
    """UGAMEServerProtocol"""

    log = log.get_child('PokerServerProtocol')

    def __init__(self):
        self._ping_timer = None
        self.bufferized_packets = []
        self.avatar = None
        UGAMEProtocol.__init__(self)
        self._ping_delay = 10
Example #5
0
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

from twisted.python.runtime import seconds
from pokernetwork.user import User
from pokerpackets.packets import PACKET_LOGIN, PACKET_AUTH
from pokernetwork import log as network_log
log = network_log.get_child("pokerauth")

def _import(path):
    import sys
    __import__(path)
    return sys.modules[path]

class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, memcache, settings):
        self.db = db
        self.memcache = memcache
        self.type2auth = {}
        self.auto_create_account = settings.headerGet("/server/@auto_create_account") == 'yes'
Example #6
0
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#

from pokernetwork import log as network_log
log = network_log.get_child('pokerserver')

import sys, os
sys.path.insert(0, ".")
sys.path.insert(0, "..")

import platform
from os.path import exists

try:
    from OpenSSL import SSL ; del SSL # just imported to check for SSL
    from pokernetwork.pokerservice import SSLContextFactory
    HAS_OPENSSL=True
except ImportError:
    log.inform("OpenSSL not available.")
    HAS_OPENSSL=False
Example #7
0
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#

from string import lower

from twisted.python.runtime import seconds

from pokerengine.pokerchips import PokerChips
from pokerengine.pokergame import history2messages
from pokernetwork.pokergameclient import PokerNetworkGameClient
from pokerpackets.packets import *
from pokerpackets.networkpackets import *
from pokerpackets.clientpackets import *
from pokernetwork import log as network_log
log = network_log.get_child('explain')

DEFAULT_PLAYER_USER_DATA = { 'timeout': None }

class PokerGames:

    log = log.get_child('PokerGames')

    def __init__(self, **kwargs):
        self.games = {}
        self.dirs = kwargs.get("dirs", [])
        self.prefix = kwargs.get("prefix", "")
    
    def getGame(self, game_id):
        if not hasattr(self, "games") or game_id not in self.games:
            return False
Example #8
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#
#

from pokernetwork import log as network_log
log = network_log.get_child('server')

from pokernetwork.protocol import UGAMEProtocol
from pokernetwork.util.trace import format_exc


class PokerServerProtocol(UGAMEProtocol):
    """UGAMEServerProtocol"""

    log = log.get_child('PokerServerProtocol')

    def __init__(self):
        self.avatar = None
        UGAMEProtocol.__init__(self)

    def packetReceived(self, packet):
Example #9
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
import os
from os.path import exists
import MySQLdb
from MySQLdb.cursors import DictCursor
import subprocess

from pokernetwork import log as network_log

log = network_log.get_child('pokerdatabase')


class ExceptionDatabaseTooOld(Exception):
    pass


class ExceptionSoftwareTooOld(Exception):
    pass


class ExceptionUpgradeMissing(Exception):
    pass


class ExceptionUpgradeFailed(Exception):
Example #10
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
from twisted.internet import defer, protocol, reactor, error
from twisted.internet.defer import CancelledError
from twisted.web import http, client
from twisted.python.util import InsensitiveDict
from twisted.python.runtime import seconds

from pokerpackets.packets import *
from pokerpackets.networkpackets import *
from pokerpackets.dictpack import dict2packet
from pokernetwork import log as network_log

log = network_log.get_child("pokerrestclient")


class RestClientFactory(protocol.ClientFactory):

    protocol = client.HTTPPageGetter
    noisy = False

    log = log.get_child("ClientFactory")

    def __init__(self, host, port, path, data, timeout=60):
        self.timeout = timeout
        self.agent = "RestClient"
        self.headers = InsensitiveDict()
        self.headers.setdefault("Content-Length", len(data))
        self.headers.setdefault("connection", "close")
Example #11
0
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
import os
from os.path import exists
import MySQLdb
from MySQLdb.cursors import DictCursor
import subprocess

from pokernetwork import log as network_log
log = network_log.get_child('pokerdatabase')

class ExceptionDatabaseTooOld(Exception): pass
class ExceptionSoftwareTooOld(Exception): pass
class ExceptionUpgradeMissing(Exception): pass
class ExceptionUpgradeFailed(Exception): pass

from pokernetwork.version import Version, version

class PokerDatabase:

    log = log.get_child('PokerDatabase')

    def __init__(self, settings):
        self.parameters = settings.headerGetProperties("/server/database")[0]
        self.mysql_command = settings.headerGet("/server/database/@command")
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

import MySQLdb
from pokernetwork.user import User
from pokerpackets.packets import PACKET_LOGIN
from pokernetwork import log as network_log
log = network_log.get_child('pokerauthmysql')

class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, memcache, settings):
        self.db = db
        self.memcache = memcache
        self.type2auth = {}
        self.settings = settings
        self.parameters = self.settings.headerGetProperties("/server/auth")[0]
        self.auth_db = MySQLdb.connect(
            host = self.parameters["host"],
            port = int(self.parameters.get("port", '3306')),
            user = self.parameters["user"],
Example #13
0
from twisted.internet import reactor
from twisted.python.runtime import seconds

from pokerengine.pokergame import PokerGameServer
from pokerengine import pokergame, pokertournament
from pokerengine.pokercards import PokerCards

from pokerpackets.networkpackets import *  # @UnusedWildImport
from pokernetwork.lockcheck import LockCheck

from pokernetwork import pokeravatar
from pokernetwork.pokerpacketizer import createCache, history2packets

from pokernetwork import log as network_log
log = network_log.get_child('pokertable')

class PokerAvatarCollection:

    log = log.get_child('PokerAvatarCollection')

    def __init__(self, prefix=''):
        self.serial2avatars = {}
        self.prefix = prefix

    def get(self, serial):
        return self.serial2avatars.get(serial, [])

    def set(self, serial, avatars):
        self.log.debug("set %d %s", serial, avatars)
        assert not serial in self.serial2avatars, \
Example #14
0
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
import re
import base64

from twisted.web import server, resource, http
from twisted.internet import defer, reactor

from pokerpackets.packets import *
from pokerpackets.networkpackets import *
PacketFactoryWithNames = dict((packet_class.__name__, packet_class)
                              for packet_class in PacketFactory.itervalues())

from pokernetwork import log as network_log
log = network_log.get_child('site')

from pokerpackets.dictpack import dict2packet, packet2dict


def _import(path):
    import sys
    __import__(path)
    return sys.modules[path]


class Request(server.Request):
    def getSession(self):
        uid = self.args.get('uid', [self.site._mkuid()])[0]
        auth = self.args.get('auth', [self.site._mkuid()])[0]
        explain = self.args.get('explain', ['no'])[0] == 'yes'
Example #15
0
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#

from twisted.internet import reactor, defer
from twisted.python.runtime import seconds

from pokerengine.pokerchips import PokerChips
from pokerengine.pokerengineconfig import Config
from pokernetwork.client import UGAMEClientProtocol, UGAMEClientFactory
from pokerpackets.clientpackets import *
from pokernetwork.pokerexplain import PokerGames, PokerExplain
from pokernetwork import log as network_log
log = network_log.get_child('pokerclient')

DEFAULT_PLAYER_USER_DATA = {'delay': 0, 'timeout': None}


class PokerSkin:
    """Poker Skin"""
    def __init__(self, *args, **kwargs):
        self.settings = kwargs['settings']
        (self.url, self.outfit) = self.interpret("", "")

    def destroy(self):
        pass

    def interpret(self, url, outfit):
        return (url, outfit)
Example #16
0
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#

from twisted.internet import reactor, defer
from twisted.python import failure
import threading
import thread
import MySQLdb
import Queue
import time

from pokernetwork import log as network_log
log = network_log.get_child('pokerlock')

class PokerLock(threading.Thread):

    TIMED_OUT = 1
    DEAD = 2
    RELEASE = 3

    acquire_timeout = 60
    queue_timeout = 2 * 60
    acquire_sleep = 0.1

    log = log.get_child('PokerLock')
    
    def __init__(self, parameters):
        self.q = Queue.Queue()
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

from pokernetwork.user import User
from pokernetwork import log as network_log
log = network_log.get_child("pokerauthnopassword")
    
class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, settings):
        self.db = db
        self.type2auth = {}
        self.auto_create_account = settings.headerGet("/server/@auto_create_account") == 'yes'

    def SetLevel(self, type, level):
        self.type2auth[type] = level

    def GetLevel(self, type):
        return type in self.type2auth and self.type2auth[type]
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
from twisted.internet import defer, protocol, reactor, error
from twisted.internet.defer import CancelledError
from twisted.web import http, client
from twisted.python.util import InsensitiveDict
from twisted.python.runtime import seconds

from pokerpackets.networkpackets import *
from pokernetwork import pokersite
from pokernetwork import log as network_log
log = network_log.get_child('pokerrestclient')


class RestClientFactory(protocol.ClientFactory):

    protocol = client.HTTPPageGetter
    noisy = False

    log = log.get_child('ClientFactory')
    
    def __init__(self, host, port, path, data, timeout = 60):
        self.timeout = timeout
        self.agent = "RestClient"
        self.headers = InsensitiveDict()
        self.headers.setdefault('Content-Length', len(data))
        self.headers.setdefault("connection", "close")
Example #19
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
from types import *
from twisted.web import client
from twisted.internet import defer, reactor

from pokernetwork import log as network_log
log = network_log.get_child('currencyclient')

class RealCurrencyClient:

    log = log.get_child('RealCurrencyClient')

    def __init__(self):
        self.getPage = client.getPage

    def request(self, *args, **kwargs):
        base = kwargs['url']
        if "?" in base:
            base += '&'
        else:
            base += '?'
            
Example #20
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
#
from twisted.internet import protocol, defer

from pokerpackets.packets import *
from pokernetwork.protocol import UGAMEProtocol
from pokernetwork.user import User
from pokernetwork import log as network_log

log = network_log.get_child('client')


class UGAMEClientProtocol(UGAMEProtocol):
    """ """
    log = log.get_child('UGAMEClientProtocol')

    def __init__(self):
        self.log = UGAMEClientProtocol.log.get_instance(
            self,
            refs=[('User', self, lambda x: x.user.serial
                   if x.user.serial > 0 else None)])
        self.user = User()
        UGAMEProtocol.__init__(self)
        self._keepalive_delay = 5
        self.connection_lost_deferred = defer.Deferred()
Example #21
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
import libxml2

from pokerengine import pokerengineconfig
from pokernetwork.version import version
from pokernetwork import log as network_log
log = network_log.get_child('pokernetworkconfig')


class Config(pokerengineconfig.Config):

    upgrades_repository = None

    log = log.get_child('Config')

    def __init__(self, *args, **kwargs):
        pokerengineconfig.Config.__init__(self, *args, **kwargs)
        self.version = version
        self.notify_updates = []

    def loadFromString(self, string):
        self.path = "<string>"
Example #22
0
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#

from twisted.internet import defer, protocol, reactor, error
from twisted.web import http

from pokernetwork import log as network_log
log = network_log.get_child('proxyfilter')

local_reactor = reactor

class ProxyClient(http.HTTPClient):
    """
    Used by ProxyClientFactory to implement a simple web proxy.
    """

    def __init__(self, command, rest, version, headers, data, father):
        self.father = father
        self.command = command
        self.rest = rest
        if "proxy-connection" in headers:
            del headers["proxy-connection"]
        headers["connection"] = "close"
Example #23
0
from pokernetwork import log as network_log
log = network_log.get_child('util')
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

from pokernetwork.user import User
from pokernetwork import log as network_log
log = network_log.get_child("pokerauthnopassword")


class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, settings):
        self.db = db
        self.type2auth = {}
        self.auto_create_account = settings.headerGet(
            "/server/@auto_create_account") == 'yes'

    def SetLevel(self, type, level):
        self.type2auth[type] = level
Example #25
0
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
from pokerengine.pokergame import PokerGameClient
from pokernetwork import log as network_log
log = network_log.get_child('pokergameclient')

class PokerNetworkGameClient(PokerGameClient):
    SERIAL_IN_POSITION = 0
    POSITION_OBSOLETE = 1

    log = log.get_child('PokerNetworkGameClient')

    def __init__(self, url, dirs):
        PokerGameClient.__init__(self, url, dirs)
        self.level_skin = ""
        self.currency_serial = 0
        self.history_index = 0
        self.position_info = [ 0, 0 ]

    def reset(self):
Example #26
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#

from string import lower

from twisted.python.runtime import seconds

from pokerengine.pokerchips import PokerChips
from pokerengine.pokergame import history2messages
from pokernetwork.pokergameclient import PokerNetworkGameClient
from pokerpackets.networkpackets import *  #@UnusedWildImport
from pokerpackets.clientpackets import *  #@UnusedWildImport
from pokernetwork import log as network_log
log = network_log.get_child('explain')

DEFAULT_PLAYER_USER_DATA = {'timeout': None}


class PokerGames:

    log = log.get_child('PokerGames')

    def __init__(self, **kwargs):
        self.games = {}
        self.dirs = kwargs.get("dirs", [])
        self.prefix = kwargs.get("prefix", "")

    def getGame(self, game_id):
        if not hasattr(self, "games") or game_id not in self.games:
Example #27
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
#
from twisted.internet import reactor, protocol
from twisted.python.runtime import seconds

from pokerpackets.packets import Packet, PacketFactory, PACKET_PING
from pokernetwork import protocol_number
from pokernetwork.version import Version
from pokernetwork import log as network_log
log = network_log.get_child('protocol')

protocol_version = Version(protocol_number)

PROTOCOL_MAJOR = "%03d" % protocol_version.major()
PROTOCOL_MINOR = "%d%02d" % (protocol_version.medium(),
                             protocol_version.minor())


class Queue:
    def __init__(self):
        self.delay = 0
        self.packets = []


class UGAMEProtocol(protocol.Protocol):
Example #28
0
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Johan Euphrosine <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#  Cedric Pinson <*****@*****.**> (2004-2006)

import MySQLdb
from pokernetwork.user import User
from pokerpackets.packets import PACKET_LOGIN
from pokernetwork import log as network_log
log = network_log.get_child('pokerauthmysql')


class PokerAuth:

    log = log.get_child('PokerAuth')

    def __init__(self, db, memcache, settings):
        self.db = db
        self.memcache = memcache
        self.type2auth = {}
        self.settings = settings
        self.parameters = self.settings.headerGetProperties("/server/auth")[0]
        self.auth_db = MySQLdb.connect(host=self.parameters["host"],
                                       port=int(
                                           self.parameters.get("port",
Example #29
0
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#  Henry Precheur <*****@*****.**> (2004)
#

from pokernetwork import log as network_log
log = network_log.get_child('pokerserver')

import sys, os
sys.path.insert(0, ".")
sys.path.insert(0, "..")

import platform
from os.path import exists

try:
    from OpenSSL import SSL ; del SSL # just imported to check for SSL
    from pokernetwork.pokerservice import SSLContextFactory
    HAS_OPENSSL=True
except Exception:
    log.inform("OpenSSL not available.")
    HAS_OPENSSL=False
Example #30
0
import re
import base64

from traceback import format_exc

from twisted.web import server, resource, http
from twisted.internet import defer, reactor

from pokerpackets.packets import packets2maps

from pokerpackets.packets import *
from pokerpackets.networkpackets import *
PacketFactoryWithNames = dict((packet_class.__name__,packet_class) for packet_class in PacketFactory.itervalues())

from pokernetwork import log as network_log
log = network_log.get_child('site')

def _import(path):
    import sys
    __import__(path)
    return sys.modules[path]


def args2packets(args):
    return (arg2packet(arg)[0] for arg in args)

_arg2packet_re = re.compile("^[a-zA-Z]+$")

def arg2packet(arg):
    packet_class = None
    packet = None
Example #31
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
# 
from twisted.internet import protocol, defer

from pokerpackets.packets import *
from pokernetwork.protocol import UGAMEProtocol
from pokernetwork.user import User
from pokernetwork import log as network_log

log = network_log.get_child('client')

class UGAMEClientProtocol(UGAMEProtocol):
    """ """
    log = log.get_child('UGAMEClientProtocol')
    def __init__(self):
        self.log = UGAMEClientProtocol.log.get_instance(self, refs=[
            ('User', self, lambda x: x.user.serial if x.user.serial > 0 else None)
        ])
        self.user = User()
        UGAMEProtocol.__init__(self)
        self._keepalive_delay = 5
        self.connection_lost_deferred = defer.Deferred()

    def getSerial(self):
        return self.user.serial
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
import libxml2

from pokerengine import pokerengineconfig
from pokernetwork.version import version
from pokernetwork import log as network_log
log = network_log.get_child('pokernetworkconfig')

class Config(pokerengineconfig.Config):

    upgrades_repository = None

    log = log.get_child('Config')

    def __init__(self, *args, **kwargs):
        pokerengineconfig.Config.__init__(self, *args, **kwargs)
        self.version = version
        self.notify_updates = []

    def loadFromString(self, string):
        self.path = "<string>"
        self.doc = libxml2.parseMemory(string, len(string))
Example #33
0
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
#  Loic Dachary <*****@*****.**>
#
# 
from twisted.internet import reactor, protocol
from twisted.python.runtime import seconds

from pokerpackets.packets import Packet, PacketFactory, PACKET_PING
from pokernetwork import protocol_number
from pokernetwork.version import Version
from pokernetwork import log as network_log
log = network_log.get_child('protocol')

protocol_version = Version(protocol_number)

PROTOCOL_MAJOR = "%03d" % protocol_version.major()
PROTOCOL_MINOR = "%d%02d" % ( protocol_version.medium(), protocol_version.minor() )

class Queue:
    def __init__(self):
        self.delay = 0
        self.packets = []
        
class UGAMEProtocol(protocol.Protocol):
    """UGAMEProtocol"""

    _stats_read = 0
Example #34
0
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
#

from twisted.internet import defer, protocol, reactor, error
from twisted.web import http

from pokernetwork import log as network_log
log = network_log.get_child('proxyfilter')

local_reactor = reactor


class ProxyClient(http.HTTPClient):
    """
    Used by ProxyClientFactory to implement a simple web proxy.
    """
    def __init__(self, command, rest, version, headers, data, father):
        self.father = father
        self.command = command
        self.rest = rest
        if "proxy-connection" in headers:
            del headers["proxy-connection"]
        headers["connection"] = "close"