def Init(self): self.prv_ping_time = time.time() self.num_ping_msgs = 0 self.max_ping_time = 0.0 self.min_ping_time = 100.0 self.sum_ping_time = 0.0 self.iters = 0 self.aes_cipher_obj = CryptoHandler.aes_cipher("") self.rsa_cipher_obj = CryptoHandler.rsa_cipher(None) ## start with a NULL session-key self.set_session_key("") ## ring-buffer of exchanged session keys self.session_keys = [""] * NUM_SESSION_KEYS self.session_key_id = 0 ## time-stamps for encrypted data self.incoming_msg_ctr = 0 self.outgoing_msg_ctr = 1 self.data_send_queue = [] self.server_info = ("", "", "", "") self.requested_registration = False ## set on out_REGISTER self.requested_authentication = False ## set on out_LOGIN self.accepted_registration = False ## set on in_REGISTRATIONACCEPTED self.rejected_registration = False ## set on in_REGISTRATIONDENIED self.accepted_authentication = False ## set on in_ACCEPTED self.received_public_key = False self.want_secure_session = False self.want_msg_auth_codes = False self.reset_session_state() ## initialize key-exchange sequence (ends with ACKSHAREDKEY) ## needed even if (for some reason) we do not want a secure ## session to discover the server force_secure_{auths,comms} ## settings if self.want_secure_session: self.out_GETPUBLICKEY() else: self.out_LOGIN()
def __init__(self, root, connection, address, session_id): 'initial setup for the connected client' self._root = root self.conn = connection # detects if the connection is from this computer if address[0].startswith('127.'): if root.online_ip: address = (root.online_ip, address[1]) elif root.local_ip: address = (root.local_ip, address[1]) self.ip_address = address[0] self.local_ip = address[0] self.port = address[1] self.setFlagByIP(self.ip_address) self.session_id = session_id self.db_id = session_id self.handler = None self.static = False self._protocol = None self.removing = False self.sendError = False self.msg_id = '' self.msg_sendbuffer = [] self.enc_sendbuffer = [] self.sendingmessage = '' ## time-stamps for encrypted data self.incoming_msg_ctr = 0 self.outgoing_msg_ctr = 1 ## note: this NEVER becomes false after LOGIN! self.logged_in = False self.status = '12' self.is_ingame = False self.cpu = 0 self.access = 'fresh' self.accesslevels = ['fresh','everyone'] self.channels = [] self.battle_bots = {} self.current_battle = None self.battle_bans = [] self.ingame_time = 0 self.went_ingame = 0 self.spectator = False self.battlestatus = {'ready':'0', 'id':'0000', 'ally':'0000', 'mode':'0', 'sync':'00', 'side':'00', 'handicap':'0000000'} self.teamcolor = '0' ## copies of the DB User values, set on successful LOGIN self.set_user_pwrd_salt("", ("", "")) self.email = '' self.hostport = None self.udpport = 0 self.bot = 0 self.floodlimit = { 'fresh':{'msglength':1024*32, 'bytespersecond':1024*32, 'seconds':2}, 'user':{'msglength':1024*32, 'bytespersecond':1024*32, 'seconds':10}, 'bot':{'msglength':1024, 'bytespersecond':10000, 'seconds':5}, 'mod':{'msglength':10000, 'bytespersecond':10000, 'seconds':10}, 'admin':{'msglength':10000, 'bytespersecond':100000, 'seconds':10}, } self.msg_length_history = {} self.lastsaid = {} self.current_channel = '' self.debug = False self.data = '' # holds compatibility flags - will be set by Protocol as necessary self.compat = defaultdict(lambda: False) self.scriptPassword = None now = time.time() self.last_login = now self.failed_logins = 0 self.register_date = now self.lastdata = now self.last_id = 0 self.users = set([]) # session_id self.battles = set([]) # [battle_id] = [user1, user2, user3, etc] self.ignored = {} self._root.console_write('Client connected from %s:%s, session ID %s.' % (self.ip_address, self.port, session_id)) ## AES cipher used for encrypted protocol communication ## with this client; starts with a NULL session-key and ## becomes active when client sends SETSHAREDKEY self.set_aes_cipher_obj(CryptoHandler.aes_cipher("")) self.set_session_key("") self.set_session_key_received_ack(False)