void ChatManagerImplementation::initiateRooms() {
	gameRooms.setNullValue(NULL);

	ChatRoom* mainRoom = createRoom("SWG");
	mainRoom->setPrivate();
	gameRooms.put("SWG", mainRoom);

	core3Room = createRoom(server->getGalaxyName(), mainRoom);
	core3Room->setPrivate();
	mainRoom->addSubRoom(core3Room);

	groupRoom = createRoom("group", core3Room);
	groupRoom->setPrivate();
	core3Room->addSubRoom(groupRoom);

	guildRoom = createRoom("guild", core3Room);
	guildRoom->setPrivate();
	core3Room->addSubRoom(guildRoom);

	auctionRoom = createRoom("Auction", core3Room);
	core3Room->addSubRoom(auctionRoom);

	generalRoom = createRoom("General", core3Room);
	core3Room->addSubRoom(generalRoom);


}
ChatRoom* ChatManagerImplementation::createRoomByFullPath(const String& path) {
	StringTokenizer tokenizer(path);
	tokenizer.setDelimeter(".");

	String game;
	tokenizer.getStringToken(game);

	ChatRoom* gameRoom = getGameRoom(game);

	if (gameRoom == NULL)
		return NULL;

	String channel;

	ChatRoom* room = gameRoom;
	while (tokenizer.hasMoreTokens()) {
		tokenizer.getStringToken(channel);

		if (room->getSubRoom(channel) == NULL)
			break;
		else
			room = room->getSubRoom(channel);
	}

	if (room == gameRoom)
		return NULL;

	if (room->isPrivate())
		return NULL;

	ChatRoom* newRoom = createRoom(channel, room);
	room->addSubRoom(newRoom);

	return newRoom;
}
Example #3
0
void *messenger( void *v ){
  ChatRoom *cr = reinterpret_cast<ChatRoom *>( v );

  while( cr )
    cr->distributeMessages();

  pthread_exit( NULL );
}
Example #4
0
void ChatPanel::OnMouseEvent(OpWidget *widget, INT32 pos, INT32 x, INT32 y, MouseButton button, BOOL down, UINT8 nclicks)
{
	if (widget != m_rooms_view)
	{
		return;
	}

	if (!down && button == MOUSE_BUTTON_2)
	{
		ShowContextMenu(OpPoint(x+widget->GetRect().x,y+widget->GetRect().y),FALSE,FALSE);
		return;
	}

	OpTreeModelItem* item;

	item = m_rooms_view->GetItemByPosition(pos);

	if (item == NULL)
	{
		return;
	}

	BOOL click_state_ok = (IsSingleClick() && !down && nclicks == 1) || nclicks == 2;

	if (click_state_ok && button == MOUSE_BUTTON_1)
	{
		if (item->GetType() == OpTreeModelItem::CHATROOM_TYPE)
		{
			ChatRoom* chat_room = g_m2_engine->GetChatRoom(item->GetID());

			if (chat_room)
			{
				OpString room;
				chat_room->GetName(room);

				ChatInfo chat_info(room, OpStringC());

				g_application->GoToChat(chat_room->GetAccountID(),
					chat_info, TRUE);
			}
		}
		else if (item->GetType() == OpTreeModelItem::CHATTER_TYPE)
		{
			ChatRoom* chatter = g_m2_engine->GetChatter(item->GetID());
			if (chatter)
			{
				OpString chatter_name;
				chatter->GetName(chatter_name);

				ChatInfo chat_info(chatter_name, OpStringC());

				g_application->GoToChat(chatter->GetAccountID(),
					chat_info, FALSE);
			}
		}
	}
}
Example #5
0
ChatRoom * linphone_qt_init_chatroom(LinphoneChatRoom *cr, const char *with){
	ChatRoom *chatw;
	QString tmp;
	chatw = new ChatRoom(w);
	tmp.sprintf("Chat with %s",with);
	chatw->setWindowTitle(tmp);
	chatw->setLinphoneChatRoom(cr);
	linphone_chat_room_set_user_data(cr,w);
	chatw->setAttribute(Qt::WA_DeleteOnClose);
	chatw->show();
	return chatw;
}
Example #6
0
void ChatRooms::closeCurrent() {
	ChatRoom* room = dynamic_cast<ChatRoom*>(currentWidget());
	if (room)
        museeq->leaveRoom(room->room());
    else {
        PublicChat* pchat = dynamic_cast<PublicChat*>(currentWidget());
        if (pchat) {
            museeq->stopPublicChat();
            delete pchat;
        }
    }
}
void ChatManagerImplementation::destroyRooms() {
	Locker _locker(_this.getReferenceUnsafeStaticCast());

	HashTableIterator<unsigned int, ManagedReference<ChatRoom* > > iter = roomMap->iterator();

	while (iter.hasNext()) {
		ChatRoom* room = iter.next();
		room->finalize();
	}

	roomMap->removeAll();

	gameRooms.removeAll();
}
void GroupObjectImplementation::disband() {
	// this locked
	ManagedReference<ChatRoom* > chat = chatRoom;

	for (int i = 0; i < groupMembers.size(); i++) {
		if (groupMembers.get(i) == NULL) {
			continue;
		}

		Reference<CreatureObject*> groupMember = getGroupMember(i).castTo<CreatureObject*>();

		try {
			Locker clocker(groupMember, _this.get());

			if (groupMember->isPlayerCreature()) {
				if (chat != NULL) {
					chat->removePlayer(groupMember, false);
					chat->sendDestroyTo(groupMember);

					ChatRoom* room = chat->getParent();
					room->sendDestroyTo(groupMember);
				}

				if (groupMember->getPlayerObject() != NULL) {
					PlayerObject* ghost = groupMember->getPlayerObject();
					ghost->removeWaypointBySpecialType(WaypointObject::SPECIALTYPE_NEARESTMISSIONFORGROUP);
				}
			}

			groupMember->updateGroup(NULL);
			//play->updateGroupId(0);

			//sendClosestWaypointDestroyTo(play);

			//removeSquadLeaderBonuses(play);
		} catch (Exception& e) {
			System::out << "Exception in GroupObject::disband(Player* player)\n";
		}
	}

	destroyChatRoom();

	if (hasSquadLeader())
		removeGroupModifiers();

	groupMembers.removeAll();

	//The mission waypoints should not be destroyed. They belong to the players.
	//missionWaypoints.removeAll();
}
Example #9
0
void ChatRooms::selected(QWidget* chatwidget) {
	if (currentIndex() == 0)
		return;
	ChatRoom * uw = dynamic_cast<ChatRoom*>(chatwidget);
	if(uw && uw->highlighted() != 0) {
		uw->setHighlighted(0);
		setHighlight(uw->highlighted(), uw );
	}
	else if (!uw) {
        PublicChat * pc = dynamic_cast<PublicChat*>(chatwidget);
        if(pc && pc->highlighted() != 0) {
            pc->setHighlighted(0);
            setHighlight(pc->highlighted(), pc );
        }
	}
}
void ChatManagerImplementation::initiatePlanetRooms() {
	// Planet Chat
	for (int i = 0; i < server->getZoneCount(); ++i) {
		ManagedReference<Zone*> zone = server->getZone(i);

		if (zone == NULL)
			continue;

		Locker locker(zone);

		ChatRoom* planetRoom = createRoom(zone->getZoneName(), core3Room);
		core3Room->addSubRoom(planetRoom);

		ChatRoom* planetaryChat = createRoom("Planet", planetRoom);
		planetRoom->addSubRoom(planetaryChat);
		zone->setChatRoom( planetaryChat );

	}
}
ChatRoom* ChatManagerImplementation::getChatRoomByGamePath(ChatRoom* game, const String& path) {
	StringTokenizer tokenizer(path);
	tokenizer.setDelimeter(".");

	String channel;
	ChatRoom* room = game;

	while (tokenizer.hasMoreTokens()) {
		tokenizer.getStringToken(channel);

		room = room->getSubRoom(channel);
		if (room == NULL)
			return NULL;
	}

	if (room == game)
		return NULL;
	else
		return room;
}
Example #12
0
void ChatRooms::setHighlight(int highlight, QWidget* chatwidget) {

	ChatRoom * uw = dynamic_cast<ChatRoom*>(chatwidget);
	PublicChat * pc = dynamic_cast<PublicChat*>(chatwidget);

    if (!uw && !pc)
        return;

	int pos;
	int tabHighlighted;
	if (uw) {
        pos = indexOf(uw);
        tabHighlighted = uw->highlighted();
	}
	else {
	    pos = indexOf(pc);
        tabHighlighted = pc->highlighted();
	}

	if(( currentIndex() != pos) && highlight > tabHighlighted )
	{
        if (uw)
            uw->setHighlighted(highlight);
        else
            pc->setHighlighted(highlight);

		if (highlight > 0)// Icon on tab
			tabBar()->setTabIcon(pos, QIcon(IMG("new-element")));
		if (highlight > 1)// Red tab
			tabBar()->setTabTextColor(pos, QColor(255, 0, 0));

	} else if (highlight == 0){
		tabBar()->setTabTextColor(pos, tabBar()->palette().buttonText().color());
		tabBar()->setTabIcon(pos, QIcon());
	}
}
Example #13
0
void GroupManager::leaveGroup(ManagedReference<GroupObject*> group, CreatureObject* player) {
	// Pre: player locked
	// Post: player locked
	if (group == NULL)
		return;

	try {
		Locker clocker(group, player);

		ChatRoom* groupChannel = group->getGroupChannel();
		if (groupChannel != NULL && player->isPlayerCreature()) {
			CreatureObject* playerCreature = cast<CreatureObject*>( player);
			groupChannel->removePlayer(playerCreature, false);
			groupChannel->sendDestroyTo(playerCreature);

			ChatRoom* room = groupChannel->getParent();
			room->sendDestroyTo(playerCreature);
		}

		if (!group->isOtherMemberPlayingMusic(player))
			group->setBandSong("");

		player->updateGroup(NULL);

		//if (player != NULL && player->isOnline() && !player->isLoggingOut())
		if (player->isPlayerCreature())
			player->sendSystemMessage("@group:removed");

		player->unlock();

		group->removeMember(player);

		if (player->isPlayerCreature())
			group->sendDestroyTo(player);

		player->info("leaving group");

		if (group->getGroupSize() < 2) {
			group->disband();
		}

	} catch (Exception& e) {
		System::out << e.getMessage();
		e.printStackTrace();

	} catch (...) {
		player->wlock();

		throw;
	}

	player->wlock();
}
void ChatManagerImplementation::handleChatRoomMessage(CreatureObject* sender, const UnicodeString& message, unsigned int roomID, unsigned int counter) {
	String name = sender->getFirstName();
	String fullName = "";

	if (sender->isPlayerCreature()) {
		ManagedReference<PlayerObject*> senderGhost = sender->getPlayerObject();

		if (senderGhost == NULL)
			return;

		if (senderGhost->isMuted()) {
			String reason = senderGhost->getMutedReason();

			if (reason != "")
				sender->sendSystemMessage("Your chat abilities are currently disabled by Customer Support for '" + reason + "'.");
			else
				sender->sendSystemMessage("Your chat abilities are currently disabled by Customer Support.");

			return;
		}

		fullName = getTaggedName(senderGhost, name);
	}

	ChatRoom* channel = getChatRoom(roomID);

	if (channel == NULL)
		return;

	if (!channel->hasPlayer(sender))
		return;

	Zone* zone = sender->getZone();
	if( zone == NULL ){
		return;
	}

	UnicodeString formattedMessage(formatMessage(message));

	ManagedReference<ChatRoom*> planetRoom = zone->getChatRoom();

	BaseMessage* msg = new ChatRoomMessage(fullName, formattedMessage, roomID);

	// Auction Chat, General Chat, and Planet Chat should adhere to player ignore list
	if( auctionRoom != NULL && auctionRoom->getRoomID() == roomID ) {
		channel->broadcastMessageCheckIgnore(msg, name);
	} else if (generalRoom != NULL && generalRoom->getRoomID() == roomID) {
		channel->broadcastMessageCheckIgnore(msg, name);
	} else if( planetRoom != NULL && planetRoom->getRoomID() == roomID ) {
		channel->broadcastMessageCheckIgnore(msg, name);
	} else {
		channel->broadcastMessage(msg);
	}

	BaseMessage* amsg = new ChatOnSendRoomMessage(counter);
	channel->broadcastMessage(amsg);

	/*Vector<Message*> messages;
	messages.add(msg);
	messages.add(amsg);

	channel->broadcastMessage(messages);*/
}
Example #15
0
BOOL ChatPanel::OnInputAction(OpInputAction* action)
{
	INT32 account_id = 0;
	INT32 id = 0;
	OpString name;
	Type type = UNKNOWN_TYPE;
	BOOL is_room = FALSE;
	BOOL is_chatter = FALSE;
	BOOL is_account = FALSE;

	OpTreeModelItem* item = m_rooms_view->GetSelectedItem();

	if (item)
	{
		id = item->GetID();
		type = item->GetType();

		switch (type)
		{
			case CHATROOM_TYPE:
		{
				ChatRoom* chat_room = g_m2_engine->GetChatRoom(id);

			if (chat_room)
			{
					chat_room->GetName(name);
					account_id = chat_room->GetAccountID();
					is_room = TRUE;
			}
				break;
			}

			case CHATTER_TYPE:
			{
				ChatRoom* chatter = g_m2_engine->GetChatter(id);

				if (chatter)
				{
					chatter->GetName(name);
					account_id = chatter->GetAccountID();
					is_chatter = TRUE;
				}
				break;
		}

			case CHATROOM_SERVER_TYPE:
			{
				account_id = item->GetID();
				is_account = TRUE;
				break;
			}
		}
	}

	switch (action->GetAction())
	{
		case OpInputAction::ACTION_GET_ACTION_STATE:
		{
			OpInputAction* child_action = action->GetChildAction();

			switch (child_action->GetAction())
			{
				case OpInputAction::ACTION_JOIN_CHAT_ROOM:
				{
					if (action->GetActionDataString())
						return FALSE;

					child_action->SetEnabled(is_room);
					return TRUE;
				}

				case OpInputAction::ACTION_LEAVE_CHAT_ROOM:
				{
					if (action->GetActionDataString())
						return FALSE;

					child_action->SetEnabled(is_room && ChatDesktopWindow::FindChatRoom(account_id, name, TRUE));
					return TRUE;
				}

				case OpInputAction::ACTION_SET_CHAT_STATUS:
				{
					if (child_action->GetActionData())
						return FALSE;

					AccountTypes::ChatStatus action_chat_status = g_application->GetChatStatusFromString(child_action->GetActionDataString());

					BOOL is_connecting = FALSE;
					AccountTypes::ChatStatus chat_status = g_application->GetChatStatus(account_id, is_connecting);

					child_action->SetSelected(chat_status == action_chat_status);

					if (is_connecting)
						child_action->SetEnabled(action_chat_status == AccountTypes::OFFLINE);
					else
						child_action->SetEnabled(g_application->SetChatStatus(account_id, chat_status, TRUE));

					return TRUE;
				}
				case OpInputAction::ACTION_DELETE:
				{
					child_action->SetEnabled(is_room || is_account);
					return TRUE;
				}
				case OpInputAction::ACTION_EDIT_PROPERTIES:
				{
					child_action->SetEnabled(is_account || is_chatter || ChatDesktopWindow::FindChatRoom(account_id, name, TRUE));
					return TRUE;
				}
			}
			break;
		}

		case OpInputAction::ACTION_SET_CHAT_STATUS:
		{
			if (action->GetActionData())
				return FALSE;

			return g_application->SetChatStatus(account_id, g_application->GetChatStatusFromString(action->GetActionDataString()));
		}

		case OpInputAction::ACTION_DELETE:
		{
			if (is_room)
			{
				ChatDesktopWindow* chat_window = ChatDesktopWindow::FindChatRoom(account_id, name, TRUE);

				if (chat_window)
				{
					chat_window->LeaveChat();
					chat_window->Close();
				}

				g_m2_engine->DeleteChatRoom(id);
			}
			else if (is_account)
			{
				g_application->DeleteAccount(account_id, GetParentDesktopWindow());
			}
			return TRUE;
		}
		case OpInputAction::ACTION_LIST_CHAT_ROOMS:
		{
			if (!action->GetActionData())
			{
				// set account and let action continue
				action->SetActionData(account_id);
			}
			break;
		}
		case OpInputAction::ACTION_NEW_CHAT_ROOM:
		case OpInputAction::ACTION_JOIN_CHAT_ROOM:
		{
			if (!action->GetActionData())
			{
				// set account and let action continue
				action->SetActionData(account_id);
			}
			if (!action->GetActionDataString() && is_room)
			{
				action->SetActionDataString(name.CStr());
			}
			break;
		}

		case OpInputAction::ACTION_SHOW_CONTEXT_MENU:
			return ShowContextMenu(GetBounds().Center(),TRUE,TRUE);
			break;

		case OpInputAction::ACTION_LEAVE_CHAT_ROOM:
		{
			if (action->GetActionDataString() || !is_room)
				break;

			return g_application->LeaveChatRoom(account_id, name);
		}

		case OpInputAction::ACTION_EDIT_PROPERTIES:
		{
			if (is_account)
			{
				g_application->EditAccount(account_id, GetParentDesktopWindow());
			}
			else if (is_chatter)
			{
				HotlistModelItem* item = g_hotlist_manager->GetContactsModel()->GetByNickname(name);

				if (item)
				{
					g_hotlist_manager->EditItem(item->GetID(), GetParentDesktopWindow());
				}
			}
			else
			{
				ChatDesktopWindow* chat_window = ChatDesktopWindow::FindChatRoom(account_id, name, TRUE);
				if(chat_window)
				    chat_window->EditRoomProperties();
			}

			return TRUE;
		}
	}
	return FALSE;
}
Example #16
0
void *commandThread( void *sID ){
  int sockID = *( reinterpret_cast<int *>( sID ) );
  pthread_mutex_unlock( &accept_mutex );

  int name_ok, n, cmdsize = COMMAND_LEN, cmdstatus, wbsize;
  bool valid, write_back;
  string clientName, comstr, comhead = "", comarg = "", wbmessage;
  char username[ CLIENT_NAME_LEN + 1 ];
  char buff[ MAXLINE ];
  Client *client;

  cout << "cThread(" << pthread_self() << "): Reading username...\n";
  if( ( readN( sockID, username, CLIENT_NAME_LEN ) ) < 0 ){
    cout << "cThread(" << pthread_self() << "): Read error.\n";
    exit( 6 );
  }

  clientName = username;
  if( allClients.exists( clientName ) ){
    name_ok = NAME_NOT_AVAILABLE;
    name_ok = htons( name_ok );
    if( ( writeN( sockID, ( char * ) &name_ok, sizeof( name_ok ) ) ) < 0 ){
      cout << "cThread(" << pthread_self() << "): Write error.\n";
      exit( 7 );
    }
    pthread_exit( NULL );
  }
  
  name_ok = NAME_AVAILABLE;
  name_ok = htons( name_ok );
  if( ( writeN( sockID, ( char * ) &name_ok, sizeof( name_ok ) ) ) < 0 ){
    cout << "cThread(" << pthread_self() << "): Write error.\n";
    exit( 8 );
  }

  client = new Client( clientName, defaultChatRoom );
  defaultChatRoom->addClient( client );
  client->setCommandSockDesc( sockID );
  allClients.addClient( client );

  while( !client->isActive() );
 
  memset( buff, '\0', MAXLINE );

  // first, read the size of the command
  while( ( readN( sockID, ( char * ) &cmdsize, sizeof( cmdsize ) ) ) > 0 ){

    // then, read the command
    if( ( n = readN( sockID, buff, cmdsize ) ) < 0 ){
      cout << "cThread(" << pthread_self() << "): Read error.\n";
      exit( 9 );
    }
    comstr = buff;
    cout << "cThread(" << pthread_self() << "): " << comstr << "\n";
    
    // In order to keep the internals consistent across clients, we lock this region
    pthread_mutex_lock( &command_mutex );

    // first pass - see if the command has the right number of characters
    valid = true;
    write_back = false;
    if( comstr.length() > 3 ){
      for( int i = 0; i < 4; i++ )
	comhead += comstr[i];
    }
    else
      valid = false;
    if( comhead != "bye." && comhead != "shut" && comhead != "lscr" && comhead != "lssu" && comhead != "myde" )
      if( comstr.length() > 5 )
	for( int j = 5; j < comstr.length(); j++ )
	  comarg += comstr[j];
      else
	valid = false;
    
    // second pass - interpret the command
    if( valid ){
      
      // "bye." - client wishes to exit the server
      if( comhead == "bye." ){
	allChatRooms.wipeClient( client->getID() );
	allClients.deleteClient( client->getID() );
	client->closeReader();
	client->closeWriter();
      }
      // "crea" - CREAte a new chatroom
      else if( comhead == "crea" ){
	ChatRoom *newRoom = new ChatRoom( comarg );
	if( !allChatRooms.addChatRoom( newRoom ) )
	  valid = false;
	else
	  dispatch( newRoom );
      }
      // "subs" - SUBScribe to an existing chatroom
      else if( comhead == "subs" ){
	ChatRoom *newRoom;
	if( newRoom = allChatRooms.exists( comarg ) )
	  if( !newRoom->addClient( client ) )
	    valid = false;
	  else;
	else
	  valid = false;
      }
      // "unsu" - UNSUbscribe from a given chatroom
      else if( comhead == "unsu" ){
	ChatRoom *newRoom;
	if( newRoom = allChatRooms.exists( comarg ) )
	  if( newRoom->removeClient( client->getID() ) )
	    if( !newRoom->numClients() && newRoom->getRoomName() != "Default" ){
	      allChatRooms.deleteChatRoom( comarg );
	      // Below should trigger the clean-up of the ChatRoom's consumer threads
	      newRoom = NULL;
	    }
	    else;
	  else 
	    valid = false;
	else
	  valid = false;
      }
      // "shut" - SHUT the server down
      else if( comhead == "shut" ){

      }
      // "myde" - displays the client's default chatroom
      else if( comhead == "myde" ){
	wbmessage = "(None)\n";
	if( client->getDefaultChatRoom() ){
	  wbmessage = client->getDefaultChatRoom()->getRoomName();
	  wbmessage += '\n';
	}
	write_back = true;
      }
      // "defa" - change the client's DEFAult chatroom; this is where the client's messages are sent
      else if( comhead == "defa" ){
	ChatRoom *newRoom;
	if( newRoom = allChatRooms.exists( comarg ) ){
	  client->setDefaultChatRoom( newRoom );
	  newRoom->addClient( client );
	}
	else
	  valid = false;
      }
      // "lscr" - provide a LIst of all existing ChatRooms
      else if( comhead == "lscr" ){
	wbmessage = allChatRooms.lscr();
	write_back = true;
      }
      // "lssu" - provide a LIst of chatrooms to which this client has SUbscribed 
      else if( comhead == "lssu" ){
	wbmessage = allChatRooms.lssu( client->getID() );
	write_back = true;
      }
      else
	valid = false;
    }

    if( valid )
      if( write_back )
	cmdstatus = COMMAND_WRITE_BACK;
      else
	cmdstatus = COMMAND_ACCEPTED;
    else
      cmdstatus = COMMAND_NOT_ACCEPTED;

    if( ( writeN( sockID, ( char * ) &cmdstatus, sizeof( cmdstatus ) ) ) < 0 ){
      cout << "cThread(" << pthread_self() << "): Write error.\n";
      exit( 10 );
    }
    if( cmdstatus == COMMAND_WRITE_BACK ){
      wbsize = wbmessage.length();
      if( ( writeN( sockID, ( char * ) &wbsize, sizeof( wbsize ) ) ) < 0 ){
	cout << "cThread(" << pthread_self() << "): Write error.\n";
	exit( 11 );
      }
      if( ( writeN( sockID, ( char * ) wbmessage.c_str(), wbsize ) ) < 0 ){
	cout << "cThread(" << pthread_self() << "): Write error.\n";
	exit( 12 );
      }
    }
    pthread_mutex_unlock( &command_mutex );

    comhead = "";
    comarg = "";
    wbmessage = "";
    memset( buff, '\0', MAXLINE );    
    
  }
  // clean up!
  pthread_exit( NULL );
}