コード例 #1
0
 def creditbalance(self):
     player = self.managers.User().session.player
     msg = self.c.writeheader(6)
     msg += self.c.writestring(str(player.credits) + '.0')
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #2
0
 def hello(self):
     """
     HELLO response
     """
     msg = self.c.writeheader(0)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #3
0
 def secretkey(self):
     """
     SECRET KEY (1) response 
     """
     msg = self.c.writeheader(1)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #4
0
ファイル: Mus.py プロジェクト: UrbanshadowDev/Kobbra
    def handle(self, connection, address):
        """
        Method to handle info message events
        """
        # Setup greenlet context
        ConsoleLogger.log("INF", "MusServer: New connection at " + address[0])

        connection.close()
コード例 #5
0
 def localisederror(self, error):
     """
     LOCALISED ERROR (33) response
     """
     msg = self.c.writeheader(33)
     msg += bytearray(error, 'utf-8')
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #6
0
 def availbadges(self):
     # TODO: Fix badges!!!
     msg = self.c.writeheader(229)
     msg += self.c.getint(0)  #numbadges
     msg += self.c.getint(0)  #badgeslot?
     msg += self.c.getint(0)  #showbadge 0/1
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #7
0
 def cryptoparams(self):
     """
     CRYPTO PARAMS (277) response 
     """
     msg = self.c.writeheader(277)
     msg += self.c.VL64.encode(1)
     msg += self.c.VL64.encode(0)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #8
0
ファイル: Mus.py プロジェクト: UrbanshadowDev/Kobbra
 def run(self):
     """
     Starting Server
     """
     self.musserver = server.StreamServer((self.serverip, self.serverport),
                                          self.handle)
     self.musserver.start()
     ConsoleLogger.log(
         "INF", "Mus server running on " + self.serverip + ':' +
         str(self.serverport))
コード例 #9
0
 def availablesets(self):
     """
     AVAILABLE SETS (8) response
     """
     configman = self.managers.Config()
     msg = self.c.writeheader(8)
     msg += b"[" + bytearray(configman.GetDb("Figure.Data.Default"),
                             'utf-8') + b"]"
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #10
0
 def userobject(self):
     player = self.managers.User().session.player
     msg = self.c.writeheader(5)
     msg += self.c.writestring(str(player.id))  #id
     msg += self.c.writestring(player.name)  #name
     msg += self.c.writestring(player.figure)  #figure
     msg += self.c.writestring(player.sex)  #sex
     msg += self.c.writestring(player.motto)  #motto
     msg += self.c.getint(player.tickets)  #tickets
     msg += self.c.writestring(player.pfigure)  #poolfigure
     msg += self.c.getint(player.films)  #films
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #11
0
    def main(self):
        """
        Main Kobbra Server method
        """
        ConsoleLogger.banner()

        #mus = MusServer(self.managers)
        info = InfoServer(self.managers)

        #mus.start()
        info.start()

        gevent.wait()

        self.managers.Database().Close()
        ConsoleLogger.log("DBG", "Exiting!")
コード例 #12
0
    def login(self, name, passwd):
        dbman = self.managers.Database() 
        users = dbman.CheckLogin(name, passwd)

        if len(users) > 0:
            player = Player(users[0])
            player.id = self.__AssignId(player)

            purses = dbman.GetPurse(player.name)
            player.credits = purses[0][1]
            player.tickets = purses[0][2]
            player.films = purses[0][3]
            
            self.session.player = player
            ConsoleLogger.log("INF", "Player " + name + " logged in")
            return True

        return False
コード例 #13
0
    def sessionparams(self):
        """
        SESSION PARAMS (257) response
        """
        # TODO: recover some of these params from DB
        params = {
            #0:0, #COPPA enabled if value 1, COPPA enforced if value > 1
            1: 1,  #Voucher enabled
            2: 0,  #Require parent email enabled
            3: 0,  #Send parent email
            4: 0,  #Allow direct mail enabled
            5: "",  #Date format string
            6: 0,  #Partner integration enabled
            7: 1,  #Allow profile editing enabled
            8: "",  #Tracking header
            9: 0  #Tutorial enabled
        }

        #OK so this one was tricky to crack
        msg = self.c.writeheader(257)

        #First we add a VL64 params size
        msg += self.c.getint(len(params))

        #Then for each param we should first add the paramID in VL64
        #then the param value always respecting the param type (VL64 for int, string \x02 for string)
        for key, value in params.items():
            msg += self.c.getint(key)
            if type(value) == int:
                msg += self.c.getint(value)
            else:
                msg += self.c.writestring(value)

        msg += self.c.geteom()
        ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
        return msg
コード例 #14
0
ファイル: Info.py プロジェクト: UrbanshadowDev/Kobbra
    def start(self):
        """
        Start info server method
        """
        localserver = server.StreamServer((self.localip, self.serverport), self.handle)
        gsignal(signal.SIGTERM, localserver.stop)
        gsignal(signal.SIGINT, localserver.stop)
        localserver.start()
        ConsoleLogger.log("INF", "Info server running on " + self.localip + ':' + str(self.serverport))

        if self.localip != '127.0.0.1':
            lbserver = server.StreamServer(('127.0.0.1', self.serverport), self.handle)
            gsignal(signal.SIGTERM, lbserver.stop)
            gsignal(signal.SIGINT, lbserver.stop)
            lbserver.start()
            ConsoleLogger.log("INF", "Info server running on 127.0.0.1:" + str(self.serverport))
        
        if len(self.remoteip) > 0:
            remoteserver = server.StreamServer(('127.0.0.1', self.serverport), self.handle)
            gsignal(signal.SIGTERM, remoteserver.stop)
            gsignal(signal.SIGINT, remoteserver.stop)
            remoteserver.start()
            ConsoleLogger.log("INF", "Info server running on " + self.remoteip + ':' + str(self.serverport))
コード例 #15
0
ファイル: Info.py プロジェクト: UrbanshadowDev/Kobbra
    def handle(self, connection, address):
        """
        Method to handle info message events
        """
        ConsoleLogger.log("INF", "InfoServer: New connection at " + address[0])
        B64 = Base64Encoding()
        evt = EventDispatcher(self.managers, connection)

        # Say hi
        connection.sendall(evt.res.hello())
        # self.evt.res.secretkey()

        while True:
            # Mandatory UTF8 conversion
            pkt = list(connection.recv(2048).decode('utf8'))
            
            if len(pkt) == 0:
                break
            
            #if encrypted:
                #pkt = decrypted

            # Split messages following header directives
            pktl = 3 + B64.decode(pkt[:3])
            while pktl <= len(pkt):
                msg = pkt[3:pktl]
                commandid = B64.decode(msg[:2])
                
                ConsoleLogger.log("DBG", "InfoServer: Received command " + "".join(msg))
                evt.request(commandid, msg)

                # Check for more piggybacked commands
                pkt = pkt[pktl:]
                pktl = 3 + B64.decode(pkt[:3])

        ConsoleLogger.log("INF", "InfoServer: Closing connection at " + address[0])
        connection.close()
コード例 #16
0
ファイル: Events.py プロジェクト: UrbanshadowDev/Kobbra
 def response(self, responseid):
     try:
         self.connection.sendall(self.resdict[responseid]())
     except KeyError:
         ConsoleLogger.log("EXC", "Session: KeyError raised. Unsupported response id " + str(responseid))
コード例 #17
0
ファイル: Events.py プロジェクト: UrbanshadowDev/Kobbra
 def request(self, commandid, msg):
     try:
         self.command = msg[2:]
         self.reqdict[commandid]()
     except KeyError:
         ConsoleLogger.log("EXC", "Session: KeyError raised. Unsupported command id " + str(commandid))
コード例 #18
0
 def Register(self, name, passwd, figure, sex, mail, birthday):
     if self.__db == None:
         pass
     
     self.__db.runsentence("INSERT INTO Users (Name,Pass,Figure,Sex,Mail,Birthday) VALUES (?,?,?,?,?,?);", [name, passwd, figure, sex, mail, birthday])
     ConsoleLogger.log("INF","Session: Register " +name + " born " + birthday + " with mail " + mail)
コード例 #19
0
 def login(self):
     msg = self.c.writeheader(3)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #20
0
 def mailapproval(self):
     msg = self.c.writeheader(271)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #21
0
 def passapproval(self, approval):
     msg = self.c.writeheader(282)
     msg += self.c.getint(approval)
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg
コード例 #22
0
 def date(self):
     msg = self.c.writeheader(163)
     msg += self.c.getshortdate()
     msg += self.c.geteom()
     ConsoleLogger.log("DBG", "ResponseEvent: " + msg.decode('utf-8'))
     return msg