def deal_keyboard(): '''处理键盘输入的各种命令''' word = gv.word if word: if word[0] == '$': if word == '$exit': # 关闭通讯模块 com.close() return 1 else: # 命令分解 cmd_list = word.split() gv.word = '' # 修改昵称 if cmd_list[0] == '$name': gamectrl.require_name_set(cmd_list[1]) # 修改座位 elif cmd_list[0] == '$sit': gamectrl.require_site_set(int(cmd_list[1]), 0) elif cmd_list[0] == '$leave': gamectrl.require_site_set(int(cmd_list[1]), 1) # 开始游戏 elif cmd_list[0] == '$start': gamectrl.require_game_start() # 打牌 elif cmd_list[0] == '$play': gamectrl.require_play_card(int(cmd_list[1])) # 测试 elif cmd_list[0] == '$test': # 测试 多信息密集发送 是否能做到 接收端 自动 分割 if cmd_list[1] == 'msgs': msg = com.GAMEMSG(gv.dev_num, 0, 0, 1, bytes([99])) com.send(msg) com.send(msg) com.send(msg) # 方便测试,自动输入加入房间后的各类指令 elif cmd_list[1] == '0': gamectrl.require_name_set('a') gamectrl.require_site_set(0, 0) elif cmd_list[1] == '1': gamectrl.require_name_set('b') gamectrl.require_site_set(1, 0) elif cmd_list[1] == '2': gamectrl.require_name_set('c') gamectrl.require_site_set(2, 0) elif cmd_list[1] == '3': gamectrl.require_name_set('d') gamectrl.require_site_set(3, 0) return 0
def sending(text, show_detail): en_file = 'bin\\en.bin' key_file = 'bin\\keys_here.json' server_file = 'bin\\server_ip.json' with open(key_file) as f: keys = json.load(f) recipient_pub = keys['SERVER_PUB'] rsa_encrypto.encryption(text, recipient_pub, en_file) with open(en_file, 'rb') as f: data = f.read() with open(server_file) as f: server = json.load(f) server_address = (server['server_ip'], server['server_port']) sock = communication.sock() communication.connect(sock, server_address) communication.send(sock, b'SEND', show_detail) response = communication.check_response(sock, b'OK', b'READY?', 128) if response == 1: communication.send(sock, data, show_detail) communication.close(sock) return None if response == 2: data = communication.receiving_data(sock, 1024) communication.close(sock) return data
def get(show_detail): server_file = 'bin\\server_ip.json' with open(server_file) as f: server = json.load(f) server_address = (server['server_ip'], server['server_port']) sock = communication.sock() communication.connect(sock, server_address) communication.send(sock, b'GET', show_detail) response = communication.check_response(sock, b'OK', b'READY?', 128) if response == 2: data = communication.receiving_data(sock, 1024) communication.close(sock) return data
def deal_keyboard(): '''处理键盘输入的各种命令''' word = gv.word if word: if word[0] == '$': if word == '$exit': # 关闭通讯模块 com.close() return 1 elif word == '$close connect': gv.word = '' com.close() # elif word == '$build deck': # gv.word = '' # gamectrl.build_deck() return 0
def deal_keyboard(): '''处理键盘输入的各种命令''' global word if word: if word[0] == '/': if word == '/exit': # 关闭通讯模块 com.close() return 1 elif word == '/close': word = '' com.close() # elif word == '/build deck': # word = '' # gamectrl.build_deck() return 0
def deal_keyboard(): '''处理键盘输入的各种命令''' global word if word: if word[0] == '/': if word == '/exit': # 关闭通讯模块 com.close() return 1 else: # 命令分解 cmd_list = word.split() word = '' # 进入游戏大厅 if cmd_list[0] == '/login': gamectrl.require_login() # 修改昵称 elif cmd_list[0] == '/name': gamectrl.require_name_set(cmd_list[1]) # 修改座位 elif cmd_list[0] == '/sit': gamectrl.require_site_set(int(cmd_list[1])) # 开始游戏 elif cmd_list[0] == '/start': gamectrl.require_game_start() # # 打牌 # elif cmd_list[0] == '/play': # gamectrl.require_play_card(int(cmd_list[1])) # 测试 elif cmd_list[0] == '/test': # # 测试 多信息密集发送 是否能做到 接收端 自动 分割 # if cmd_list[1] == 'msgs': # msg = com.GAMEMSG(gv.dev_num, 0, 0, 1, bytes([99])) # com.send(msg) # com.send(msg) # com.send(msg) # 方便测试,自动输入加入房间后的各类指令 if cmd_list[1] == '0': threading.Thread(target=justfortest, args=('a', 0)).start() elif cmd_list[1] == '1': threading.Thread(target=justfortest, args=('b', 1)).start() elif cmd_list[1] == '2': threading.Thread(target=justfortest, args=('c', 2)).start() elif cmd_list[1] == '3': threading.Thread(target=justfortest, args=('d', 3)).start() return 0