#!/usr/bin/python3 # -*- coding: utf-8 -*- # Copyright © 2015 Matthieu DUVAL, Rudy DUCHE # This file is part of Foobar. # Foobar is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # Foobar 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 General Public License for more details. # You should have received a copy of the GNU General Public License # along with Foobar. If not, see import socketserver from threading import Thread import signal from BF_Constants import * from BF_EasterEgg import * import BF_Utils FOUND = False class InterfaceServerHandler(socketserver.BaseRequestHandler): def handle(self): self.messageType = LAN_CONSTANTS.MESSAGE_VALUE.TYPE_DEFAULT.value self.messageState = LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value self.data = self.request.recv(1024).strip() self.traitementResponse(self.data.decode('utf-8'),self.client_address[0]) if self.messageType == LAN_CONSTANTS.MESSAGE_VALUE.TYPE_RESULT.value: if self.messageState == LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value: #self.request.sendall(bytes(BF_Utils.createMessage(LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_KEY.RETURN_STATE.value,LAN_CONSTANTS.MESSAGE_VALUE.STATE_OK.value,False),"utf-8")) global FOUND FOUND = True easterEgg = EasterEgg() easterEgg.openTray() self.finish() def traitementResponse(self,param,clientAdress): errorMessage = list() errorCode = list() argvArray = param.split(LAN_CONSTANTS.MESSAGE_SPECIAL_CHAR.SEPARATOR.value) for object in argvArray: key,value = BF_Utils.getValueWithKey(object) if key == LAN_CONSTANTS.MESSAGE_KEY.MESSAGE_TYPE.value: self.messageType = value elif key == LAN_CONSTANTS.MESSAGE_KEY.RETURN_STATE.value : self.messageState = value elif key == LAN_CONSTANTS.MESSAGE_KEY.WORD.value : self.word = value class InterfaceServer(Thread): def __init__(self,port): Thread.__init__(self) self.port = port def run(self): server = socketserver.TCPServer(('', self.port), InterfaceServerHandler) while not FOUND: server.handle_request()