Пример #1
0
def main():
    if os.path.exists("config.json"):
        with open("config.json", 'r') as file:
            configuration = json.load(file)

        ip = configuration["ip"]
        port = configuration["port"]
        motd = configuration["motd"]["1"] + "\n" + configuration["motd"]["2"]
        version_text = configuration["version_text"]
        kick_message = ""
        server_icon = None

        for message in configuration["kick_message"]:
            kick_message += message + "\n"
        kick_message = kick_message[:-2]

        if not os.path.exists(configuration["server_icon"]):
            print("Server icon doesn't exists - submitting none...")
        else:
            with open(configuration["server_icon"], 'rb') as image:
                server_icon = "data:image/png;base64," + base64.b64encode(
                    image.read()).decode()
        try:
            global server
            server = SocketServer(ip, port, motd, version_text, kick_message,
                                  server_icon)
            server.start()
        except KeyboardInterrupt:
            server.close()
            exit(1)
        except Exception as e:
            print(e)
    else:
        configuration = {}
        configuration["ip"] = "0.0.0.0"
        configuration["port"] = 25565
        configuration["motd"] = {}
        configuration["motd"]["1"] = "§4Maintenance!"
        configuration["motd"][
            "2"] = "§aCheck example.com for more information!"
        configuration["version_text"] = "§4Maintenance"
        configuration["kick_message"] = [
            "§bSorry", "", "§aThis server is offline!"
        ]
        configuration["server_icon"] = "server_icon.png"
        configuration["samples"] = ["§bexample.com", "", "§4Maintenance"]

        with open("config.json", 'w') as file:
            json.dump(configuration,
                      file,
                      sort_keys=True,
                      indent=4,
                      ensure_ascii=False)

        print("[!] A new configuration was created!")
        print("Please check the settings in the config.json!")
        exit(1)
Пример #2
0
 def _queue_linesplit(self):
     ss = SocketServer(host='localhost', port=8888)
     ss.create()
     self.lg.info('8888 Waiting connection...')
     while True:
         ss.accept()
         self.lg.info('Connection Accepted!')
         self.lg.info('8888 Waiting for stream...')
         data = ss.recv()
         while data != '\n':
             self.tq.put(data)
             data = ss.recv()
         self.tq.put(data)
     ss.close()
Пример #3
0
 def _shipper(self, none):
     ss = SocketServer(host='localhost', port=8887)
     ss.create()
     self.lg.info('Waiting sub')
     while True:
         ss.accept()
         while True:
             data = self.tq.get()
             try:
                 ss.send(data)
             except:
                 logging.warning('Connection with 8887 losed')
                 self.tq.put(data)
                 break
     ss.close()
Пример #4
0
 def run(self, lg):
     self.lg = lg
     ss = SocketServer(host='localhost', port=9999)
     ss.create()
     self.lg.info('9999 Waiting connection...')
     while True:
         ss.accept()
         while True:
             with open('res/results.txt', 'a') as outfile:
                 try:
                     data = ss.recv()
                     outfile.write(data)
                 except:
                     logging.warning('Connection with 9999 losed')
                     break
     ss.close()
Пример #5
0
def main():
    logger = logging.getLogger("FakeMCServer")
    if not os.path.exists("logs"):
        os.makedirs("logs")
    logger.setLevel(logging.INFO)
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)
    file_handler = logging.FileHandler("logs/access.log")
    file_handler.setLevel(logging.INFO)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    file_handler.setFormatter(formatter)
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)
    logger.addHandler(file_handler)
    if os.path.exists("config.json"):
        logger.info("Loading configuration...")
        with open("config.json", 'r') as file:
            configuration = json.load(file)

        ip = configuration["ip"]
        port = configuration["port"]
        motd = configuration["motd"]["1"] + "\n" + configuration["motd"]["2"]
        version_text = configuration["version_text"]
        kick_message = ""
        samples = configuration["samples"]
        try:
            show_hostname = configuration["show_hostname_if_available"]
        except KeyError:
            configuration["show_hostname_if_available"] = True
            show_hostname = True
            with open("config.json", 'w') as file:
                json.dump(configuration,
                          file,
                          sort_keys=True,
                          indent=4,
                          ensure_ascii=False)

        player_max = configuration.get("player_max", 0)
        player_online = configuration.get("player_online", 0)
        protocol = configuration.get("protocol", 2)
        server_icon = None

        for message in configuration["kick_message"]:
            kick_message += message + "\n"

        if not os.path.exists(configuration["server_icon"]):
            logger.warning("Server icon doesn't exists - submitting none...")
        else:
            with open(configuration["server_icon"], 'rb') as image:
                server_icon = "data:image/png;base64," + base64.b64encode(
                    image.read()).decode()
        try:
            global server
            logger.info("Setting up server...")
            server = SocketServer(ip, port, motd, version_text, kick_message,
                                  samples, server_icon, logger, show_hostname,
                                  player_max, player_online, protocol)
            server.start()
        except KeyboardInterrupt:
            logger.info("Shutting down server...")
            server.close()
            logger.info("Done. Thanks for using FakeMCServer!")
            exit(0)
        except Exception as e:
            logger.exception(e)
    else:
        logger.warning("No configuration file found. Creating config.json...")
        configuration = {}
        configuration["ip"] = "0.0.0.0"
        configuration["port"] = 25565
        configuration["protocol"] = 2
        configuration["motd"] = {}
        configuration["motd"]["1"] = "§4Maintenance!"
        configuration["motd"][
            "2"] = "§aCheck example.com for more information!"
        configuration["version_text"] = "§4Maintenance"
        configuration["kick_message"] = [
            "§bSorry", "", "§aThis server is offline!"
        ]
        configuration["server_icon"] = "server_icon.png"
        configuration["samples"] = ["§bexample.com", "", "§4Maintenance"]
        configuration["show_ip_if_hostname_available"] = True
        configuration["player_max"] = 0
        configuration["player_online"] = 0

        with open("config.json", 'w') as file:
            json.dump(configuration,
                      file,
                      sort_keys=True,
                      indent=4,
                      ensure_ascii=False)
        logger.info("Please adjust the settings in the config.json!")
        exit(1)
Пример #6
0

#---------------------------------------------------------------------------
###################################### MAIN ###########################################

if __name__ == "__main__":

    # Thread for socket server
    socket_host = getIpAddress()
    socket_port = "8889"
    print "Start MAIN - host: ", socket_host, ", port: ", socket_port

    socketServer = SocketServer(socket_host, socket_port)
    socketThread = threading.Thread(target=socketServer.communicate)
    socketThread.setDaemon(True)
    socketThread.start()
    print "SocketServer is running"

    # Streaming thread
    GObject.threads_init()
    Gst.init(None)

    server = GstServer()

    loop = GObject.MainLoop()
    loop.run()

    # End
    socketServer.close()
    print "Close SocketServer"