Beispiel #1
0
	def server_response_handler(ch,method,properties,body):
		# Decoding the data 
		json_data = str(body.decode('utf-8'))
		server_data = json.loads(json_data)

		# Extracting the status whether valid or invalid 
		status = server_data['Code']
		print("[ STATUS ] " + status)
		print(server_data)
		
		# If authentication is valid 
		if (status == 'VALID'):
			print('[ ClientID ] receiving ......')
			# read config file config.json
			config = handle_config.read_config_json()

			# Add client id in the config file received by the server
			config["client_id"] = str(server_data["Client ID"])
			config["Username"] = authenticate_login.username
			# update data in config file
			handle_config.write_config_json(config)
			# insert user detail for future use
			user_detail.insert_detail(server_data["Client ID"], authenticate_login.username) 

			print("[ Status ] " + status + "\n[ ClientID ] : " + str(server_data["Client ID"]) + "\n[ Server ] : " + server_data["Message"])
			
			# Changing login status to valid
			authenticate_login.login_status = 'VALID'
			authenticate_login.client_id = server_data["Client ID"]
			# authenticate_login.channel.basic_ack(True)
			authenticate_login.channel.stop_consuming()
			# authenticate_login.channel.basic_ack(True)

		# If login is rejected by the server 
		elif (status == 'LRJCT'):
			authenticate_login.queue.put(server_data["Message"])
			# Changing login status to rejected
			print('[ Authentication ]  REJECTED ......')
			authenticate_login.login_status = 'LRJCT'
			# Delete the queue 
			try:
				authenticate_login.channel.queue_delete(
					queue = authenticate_login.username
					)
			except Exception as Error:
				print(str(Error))
			authenticate_login.channel.basic_ack(True)
		# If login authentication is not valid 
		else:
			print("Invalid Login!!!!")
			authenticate_login.login_status = 'INVLD'
			# Deleting the queue on which the client is listening
			try:
				authenticate_login.channel.queue_delete(
					queue = authenticate_login.username
					)	
			except Exception as Error:
				print(str(Error))	
			authenticate_login.channel.basic_ack(True)
Beispiel #2
0
 def start_status(server_data):
     print(server_data)
     contest_start_time = time.time()
     # start_time = start_listening.convert_time_format(server_data["Start Time"])
     config = handle_config.read_config_json()
     config["Duration"] = server_data["Duration"]
     config["Contest"] = "RUNNING"
     config["Problem Key"] = server_data["Problem Key"]
     # contest_start_time = start_time
     config["Start Time"] = contest_start_time
     initialize_contest.set_duration(config["Duration"])
     contest_duration_seconds = initialize_contest.convert_to_seconds(
         initialize_contest.get_duration())
     config["End Time"] = contest_duration_seconds + contest_start_time
     handle_config.write_config_json(config)
     start_listening.data_changed_flags[0] = 1
     start_listening.data_changed_flags[4] = 2
     print("[START] Signal received")
     print("Contest Duration : " + server_data["Duration"])
Beispiel #3
0
 def extended_time(server_data):
     config = handle_config.read_config_json()
     time = server_data["Time"]
     config["End Time"] = config["End Time"] + time * 60
     handle_config.write_config_json(config)
     start_listening.data_changed_flags[4] = 3
Beispiel #4
0
from time import sleep
from connection import manage_connection
from database_management import manage_database, manage_local_ids
from interface_package.interface import init_gui
from interface_package.login_interface import start_interface
from listen_server import start_listening
from init_client import handle_config, rabbitmq_detail

hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)

try:
    config = handle_config.read_config_json()
    config["IP"] = ip
    handle_config.write_config_json(config)
    config = handle_config.read_config_json()
except Exception as Error:
    print(str(Error))
    sys.exit()

try:
    # Basic credentials for login to RabbitMQ Server
    rabbitmq_username = config["rabbitmq_username"]
    rabbitmq_password = config["rabbitmq_password"]
    host = config["host"]
except Exception as Error:
    print(str(Error))
    sys.exit()

rabbitmq_detail.fill_detail(rabbitmq_username, rabbitmq_password, host)