def onCancel(client_name): try: socket_id = request.sid session_closed, room_id = matchmake.checkDisconnect(socket_id) if session_closed: session.close(room_id) chat.roomServerMessage( 'Client ' + misc.generateNameTag( socket_id, matchmake.sid_cid_pairs[socket_id]) + ' has left the room', room_id) matchmake.clearRoom(room_id, socket_id) else: room_found, room, index = matchmake.checkObserverDisconnect( socket_id) if room_found: del matchmake._rooms[room]['Viewers'][index] chat.roomServerMessage( 'Client ' + misc.generateNameTag( socket_id, matchmake.sid_cid_pairs[socket_id]) + ' has left the room', room) chat.roomChatInfo(socket_id, matchmake.sid_cid_pairs[socket_id]) print((u'Client canceled: ' + client_name).encode('utf-8')) except Exception: err_log = open('err_log', 'a', encoding='utf-8') err_log.write(traceback.format_exc()) print(traceback.format_exc())
def onDisconnect(): try: socket_id = request.sid chat.removeGlobalClient(socket_id) session_closed, room_id = matchmake.checkDisconnect(socket_id) if session_closed: chat.roomServerMessage( 'Client ' + misc.generateNameTag( socket_id, matchmake.sid_cid_pairs[socket_id]) + ' has left the room', room_id) matchmake.clearRoom(room_id, socket_id) try: del matchmake.sid_cid_pairs[socket_id] except KeyError: print((u'sid ' + sid + u' already cleared').encode('utf-8')) else: room_found, room, index = matchmake.checkObserverDisconnect( socket_id) if room_found: del matchmake._rooms[room]['Viewers'][index] chat.roomServerMessage( 'Client ' + misc.generateNameTag( socket_id, matchmake.sid_cid_pairs[socket_id]) + ' has left the room', room) chat.roomChatInfo(socket_id, matchmake.sid_cid_pairs[socket_id]) print(u"Client disconnect: " + socket_id) except Exception: err_log = open('err_log', 'a', encoding='utf-8') err_log.write(traceback.format_exc()) print(traceback.format_exc())