def sendChatMessageOIE(self, message): """ :param message: The text of the chat message. :type message: string Called by the client proxy when the user has decided to send a chat message .. note:: This is the only function handling chat messages, irrespective of the room where the user is. Therefore it is up to the c2wChatClientProctocol or to the server to make sure that this message is handled properly, i.e., it is shown only by the client(s) who are in the same room. """ message = ''.join(filter(lambda x: x in printable, message)) seqNumber = self.num_seq message_packet = Packet(64, seqNumber, len(self.user_name) + len(message) + 2, [ len(self.user_name), self.user_name.encode('utf-8'), len(message), message.encode('utf8') ]) message_packet.packet_format = '!LB' + str( message_packet.data[0]) + 's' + 'B' + str( message_packet.data[2]) + 's' self.sendPacket(message_packet)
def sendUserListMovieRoom(self, movie_room): # send the Packet of usersList in a movie room to the user user_chat_room_dict = self.getUserChatRoomDict() update_user_list_packet = Packet(18, -1, 0, []) update_user_list_packet.data.append( len(user_chat_room_dict[movie_room])) update_user_list_packet.packet_format = "!LH" update_user_list_packet.packet_length = 2 for user_chat_room in user_chat_room_dict[movie_room]: update_user_list_packet.packet_format += "B" + str( len(user_chat_room)) + "s" update_user_list_packet.packet_length += 1 + len(user_chat_room) update_user_list_packet.data.append(len(user_chat_room)) update_user_list_packet.data.append(user_chat_room.encode("utf8")) print("user list movie", update_user_list_packet) self.sendPacket(update_user_list_packet)
def sendUserListMovieRoom(self, user, movie_room): #send the Packet of usersList in a movie room to the user user_chat_room_dict = self.getUserChatRoomDict() update_user_list_packet = Packet(18, self.num_seq[user.userName], 0, []) update_user_list_packet.data.append( len(user_chat_room_dict[movie_room])) update_user_list_packet.packet_format = "!LH" update_user_list_packet.packet_length = 2 for user_chat_room in user_chat_room_dict[movie_room]: update_user_list_packet.packet_format += "B" + str( len(user_chat_room)) + "s" update_user_list_packet.packet_length += 1 + len(user_chat_room) update_user_list_packet.data.append(len(user_chat_room)) update_user_list_packet.data.append(user_chat_room.encode("utf8")) self.sendPacket(update_user_list_packet, user.userAddress)