Source code for isomer.events.client

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# Isomer - The distributed application framework
# ==============================================
# Copyright (C) 2011-2020 Heiko 'riot' Weinen <riot@c-base.org> and others.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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.  If not, see <http://www.gnu.org/licenses/>.

"""
Isomer Client events
"""

from circuits import Event

from isomer.logger import isolog, warn, events


[docs]class send(Event): """Send a packet to a known client by UUID"""
[docs] def __init__( self, uuid, packet, sendtype="client", raw=False, username=None, fail_quiet=False, *args ): """ :param uuid: Unique User ID of known connection :param packet: Data packet to transmit to client :param args: Further Args """ super(send, self).__init__(*args) if uuid is None and username is None: isolog("[SEND-EVENT] No recipient (uuid/name) given!", lvl=warn) self.uuid = uuid self.packet = packet self.username = username self.sendtype = sendtype self.raw = raw self.fail_quiet = fail_quiet isolog( "[CM-EVENT] Send event generated:", uuid, str(packet)[:80], sendtype, lvl=events, )
[docs]class broadcast(Event): """Send a packet to a known client by UUID"""
[docs] def __init__(self, broadcasttype, content, group=None, *args): """ :param broadcasttype: One of [users|clients|usergroup|clientgroup|socks] :param content: Data packet to transmit to client :param group: Used for group broadcasting (a list of either client or user uuids) :param args: Further Args """ super(broadcast, self).__init__(*args) self.broadcasttype = broadcasttype self.content = content self.group = group isolog( "[CM-EVENT] Broadcast event generated:", broadcasttype, content, group, lvl=events )
[docs]class clientdisconnect(Event): """ A client has disconnected from the system. This has to propagate to all subscription based and other user aware components. :param clientuuid: UUID of disconnecting client :param useruuid: UUID of disconnecting user :param args: """
[docs] def __init__(self, clientuuid, useruuid=None, *args): super(clientdisconnect, self).__init__(*args) self.clientuuid = clientuuid self.useruuid = useruuid isolog( "[CM-EVENT] Client disconnect event generated:", clientuuid, useruuid, lvl=events, )
[docs]class userlogin(Event): """ A user has logged in to the system. This has to propagate to all subscription based and other user aware components. :param clientuuid: UUID of disconnecting client :param useruuid: UUID of disconnecting user :param args: """
[docs] def __init__(self, clientuuid, useruuid, client, user, *args): super(userlogin, self).__init__(*args) self.clientuuid = clientuuid self.useruuid = useruuid self.client = client self.user = user isolog( "[CM-EVENT] User login event generated:", clientuuid, useruuid, lvl=events )
[docs]class userlogout(Event): """ A user has logged out from the system. This has to propagate to all subscription based and other user aware components. :param clientuuid: UUID of disconnecting client :param useruuid: UUID of disconnecting user :param args: """
[docs] def __init__(self, useruuid, clientuuid, *args): super(userlogout, self).__init__(*args) self.useruuid = useruuid self.clientuuid = clientuuid isolog("[CM-EVENT] User logout event generated:", useruuid, lvl=events)
[docs]class authenticationrequest(Event): """A client wants to authenticate a client connection"""
[docs] def __init__( self, username, password, clientuuid, requestedclientuuid, sock, auto, *args ): """ :param username: Account username :param password: Account md5 hash :param clientuuid: Unique User ID of known connection :param sock: Associated Socket :param args: Further Args """ super(authenticationrequest, self).__init__(*args) self.username = username self.password = password self.sock = sock self.clientuuid = clientuuid self.requestedclientuuid = requestedclientuuid self.auto = auto
[docs]class authentication(Event): """Authentication has been granted to a client"""
[docs] def __init__(self, username, userdata, clientuuid, useruuid, sock, *args): """ :param username: Account username :param userdata: Tuple containing both useraccount and userprofile :param uuid: Unique User ID of known connection :param sock: Associated Socket :param args: Further Args """ super(authentication, self).__init__(*args) self.username = username self.userdata = userdata self.clientuuid = clientuuid self.useruuid = useruuid self.sock = sock isolog("[AUTH-EVENT] Authentication granted:", self.__dict__, lvl=events)