Ejemplo n.º 1
0
    def onOuterMessage(self, cmd, raw, *args, **kwargs):
        if not self.connection.has_login():
            with self.connection.locker:
                if cmd == Message.MSG_SYS_USER_INFO | Message.ID_REQ:
                    mi = MsgPack.unpack(cmd, raw)
                    self.process_login(mi)
                    if self.connection.has_login():
                        self.send_to_entity(cmd, self.connection.userId, raw)
                    return True

        if self.connection.has_login():
            uid = self.connection.userId
            if Message.is_game_server(cmd):
                return self.send_to_game(cmd, uid, raw)
            elif cmd == Message.MSG_SYS_HOLD | Message.ID_REQ:
                return self.on_hold()
            elif cmd == Message.MSG_SYS_QUICK_START | Message.ID_REQ:
                return self.send_to_quick(cmd, uid, raw)
            elif cmd == Message.MSG_SYS_BIND_GAME | Message.ID_REQ:
                return self.on_bind_game(cmd, raw)
            elif cmd == Message.MSG_INNER_BROKEN:
                return self.process_broken(raw)
            else:
                return self.send_to_entity(cmd, uid, raw)

        return False
Ejemplo n.º 2
0
    def onMessage(self, request):
        if request.method.lower() == 'post':
            data = request.raw_data()
            mi = MsgPack.unpack(0, data)
            Context.Log.debug('------', mi)
            gid = mi.get_param('gameId')
            if request.path in self.json_path:
                with Context.GData.server_locker:
                    return self.json_path[request.path](gid, mi, request)
            else:
                from lemon import classMap
                if gid in classMap:
                    http = classMap[gid].get('http')
                    if http:
                        if request.path in http.json_path:
                            uid = mi.get_param('userId')
                            if not self.check_token(uid, gid, mi):
                                raise ForbiddenException(
                                    'no permission access')
                            with Context.GData.user_locker[uid]:
                                return http.json_path[request.path](uid, gid,
                                                                    mi,
                                                                    request)

        raise NotFoundException('Not Found')
Ejemplo n.º 3
0
 def on_bind_game(self, cmd, raw):
     mi = MsgPack.unpack(cmd, raw)
     gid = mi.get_param('gameId')
     if gid > 0:
         room = mi.get_param('room')
         self.connection.bind_game(gid, room)
         mo = MsgPack(Message.MSG_SYS_BIND_GAME | Message.ID_ACK)
         mo.set_param('gameId', gid)
         Context.GData.send_to_client(self.connection.userId, mo,
                                      self.connection)
     return True
Ejemplo n.º 4
0
 def onInnerMessage(self, cmd, mi, *args, **kwargs):
     uid = mi.get_uid()
     gid = mi.get_gid()
     raw = mi.get_message()
     mi = MsgPack.unpack(cmd, raw)
     gid = mi.get_param('gameId', gid)
     game = Context.get_module(gid, 'game')
     with Context.GData.user_locker[uid]:
         if game:
             game.onMessage(cmd, uid, gid, mi)
         else:
             Context.Log.warn('no game found', mi)
Ejemplo n.º 5
0
 def onInnerMessage(self, cmd, mi, *args, **kwargs):
     uid = mi.get_uid()
     gid = mi.get_gid()
     raw = mi.get_message()
     mi = MsgPack.unpack(cmd, raw)
     gid = mi.get_param('gameId', gid)
     quick = Context.get_module(gid, 'quick')
     with Context.GData.server_locker:
         if quick:
             quick.onMessage(cmd, uid, gid, mi)
         else:
             Context.Log.warn('error msg', cmd, mi)
Ejemplo n.º 6
0
    def onMessage(self, request):
        if request.method.lower() == 'post':
            if request.path in self.json_path:
                data = request.raw_data()
                mi = MsgPack.unpack(0, data)
                Context.Log.debug(mi)
                # with Context.GData.server_locker:
                return self.json_path[request.path](mi, request)

        if request.path in self.callback_path:
            with Context.GData.server_locker:
                return self.callback_path[request.path](request)

        raise NotFoundException('Not Found')
Ejemplo n.º 7
0
    def onMessage(self, request):
        if request.method.lower() == 'post':
            data = request.raw_data()
            mi = MsgPack.unpack(0, data)
            Context.Log.debug(mi)
            gid = mi.get_param('gameId')
            if not self.check_token(gid, mi):
                raise ForbiddenException('no permission access')
            if request.path in self.json_path:
                return self.json_path[request.path](gid, mi, request)
            from lemon import classMap
            if gid in classMap:
                http = classMap[gid].get('shell')
                if http and request.path in http.json_path:
                    return http.json_path[request.path](gid, mi, request)

        raise NotFoundException('Not Found')
Ejemplo n.º 8
0
 def onInnerMessage(self, cmd, mi, *args, **kwargs):
     uid = mi.get_uid()
     gid = mi.get_gid()
     raw = mi.get_message()
     mi = MsgPack.unpack(cmd, raw)
     gid = mi.get_param('gameId', gid)
     with Context.GData.user_locker[uid]:
         if cmd == Message.MSG_SYS_USER_INFO | Message.ID_REQ:
             self.onUserInfo(uid, gid, mi)
         elif cmd == Message.MSG_SYS_GAME_INFO | Message.ID_REQ:
             self.onGameInfo(uid, gid, mi)
         elif cmd == Message.MSG_SYS_SERVER_INFO | Message.ID_REQ:
             self.onServerInfo(uid, gid, mi)
         elif cmd == Message.MSG_SYS_LED | Message.ID_REQ:
             self.onLed(uid, gid, mi)
         else:
             entity = Context.get_module(gid, 'entity')
             if entity:
                 entity.onMessage(cmd, uid, gid, mi)
             else:
                 Context.Log.warn('error msg', cmd, mi)