def __send_end_level(players: List[RemotePlayer], key, exits, ejects): '''Sends the level end message to all players ''' key = 'null' if not key else key end_lvl = EndLevel(key, exits, ejects) msg = str(end_lvl) for player in players: send_msg(player.socket, msg, player.name)
def __request_client_move(player: RemotePlayer, gm: GameManager, key, exits, ejects): msg = "move" msg = json.dumps(msg) conn = player.socket for i in range(4): send_msg(conn, msg, player.name) move_res = player.move_to_tile(gm) if move_res: player_obj = gm.get_player_actor(player.name) if move_res[VALID_MOVE] and move_res[INFO].traversable: res = gm.apply_player_item_interaction(player_obj, player_obj.pos) if res: if res == KEY: key = player.name move_msg = json.dumps(res) elif res == EXIT: exits.append(player.name) move_msg = json.dumps(res) elif move_res[EJECT]: ejects.append(player.name) move_msg = json.dumps(EJECT) else: move_msg = json.dumps(OK) send_msg(conn, move_msg, player.name) return move_msg move_msg = json.dumps(INVALID) send_msg(conn, move_msg, player.name)
f=open(str(port)+'.txt','a') t = time.time() ## --------------Run the PIR query---------------------## # Check if we're running regular PIR (hashFlag=0) or hashed PIR (hashFlag=1) if not hashFlag: result = serv.submitPirQuery(query,base).tolist() result = [int(a) for a in result] else: # print('bins is ',bins) result = serv.submitPirQueryHash(query,base) # print('result is ',result) # print('result dims',[len(item) for item in result]) t = time.time()-t f.write(str(t)+'\n') f.close() # return the result to the client # print ('size result',len(result),len(marshal.dumps([port]+result)), len(marshal.loads(marshal.dumps([port]+result)))) # print('result is',result[0][:10]) # client_socket.send(marshal.dumps([port]+result)) if hashFlag: result = sum(result.tolist(),[]) msg = [port] + result utilities.send_msg(client_socket,marshal.dumps(msg)) else: utilities.send_msg(client_socket,marshal.dumps([port]+result)) t = time.time() client_socket.close()
def __send_end_game(players: List[RemotePlayer], player_scores: List[PlayerScore]): end_game = EndGame(player_scores) msg = str(end_game) for player in players: send_msg(player.socket, msg, player.name)
def __send(self, msg): send_msg(self.__socket, msg, 'server')
def __send(self, msg): send_msg(self.socket, msg, self.name)
f = open(str(port) + '.txt', 'a') t = time.time() ## --------------Run the PIR query---------------------## # Check if we're running regular PIR (hashFlag=0) or hashed PIR (hashFlag=1) if not hashFlag: result = serv.submitPirQuery(query, base).tolist() result = [int(a) for a in result] else: # print('bins is ',bins) result = serv.submitPirQueryHash(query, base) # print('result is ',result) # print('result dims',[len(item) for item in result]) t = time.time() - t f.write(str(t) + '\n') f.close() # return the result to the client # print ('size result',len(result),len(marshal.dumps([port]+result)), len(marshal.loads(marshal.dumps([port]+result)))) # print('result is',result[0][:10]) # client_socket.send(marshal.dumps([port]+result)) if hashFlag: result = sum(result.tolist(), []) msg = [port] + result utilities.send_msg(client_socket, marshal.dumps(msg)) else: utilities.send_msg(client_socket, marshal.dumps([port] + result)) t = time.time() client_socket.close()