コード例 #1
0
ファイル: RoomService.cpp プロジェクト: antiqe/RType
void RoomService::onRoomJoin(int const to, Message *msg)
{
  Account *acc = Core::acc_manager->getAccount(to);

  if (acc)
    {
      unsigned short id = msg->getAttr<unsigned short>("id");
      Room *room = Core::room_manager->getRoom(id);
	  if (room)
		{
		  acc->setRoom(room);
		  room->addPlayer(new Player(0, to, acc));
		  std::string password = msg->getAttr<std::string>("password");
		  Message *rmsg = new Message(Message::ROOM_STATE);
		  InternalMessage *imsg = new InternalMessage(new TCPPacket(rmsg, 0), to);
		  imsg->addReceiver(to);
		  rmsg->setAttr("id", Ultra::Value((unsigned short)id));
		  if (room->getPassword() == password)
			{
				if (room->isReachable())
				  rmsg->setAttr("state", Ultra::Value(Room::OK));
				else
				   rmsg->setAttr("state", Ultra::Value(Room::LIMIT));
			}
		  else
			rmsg->setAttr("state", Ultra::Value((char)Room::KO));
		  Core::srv_manager->notifyService(ServiceManager::DISPATCH, imsg);
		}
    }
}
コード例 #2
0
ファイル: RoomService.cpp プロジェクト: antiqe/RType
void RoomService::onRoomCreate(int const to, Message *msg)
{
  Account *acc = Core::acc_manager->getAccount(to);

  if (acc)
    {
      Room *room;
      std::string name;
      std::string password;

      name = msg->getAttr<std::string>(std::string("name"));
      password = msg->getAttr<std::string>(std::string("password"));
      room = Core::room_manager->createRoom(name, password);
	  room->addPlayer(new Player(0, to, acc, Player::MASTER));
	  acc->setRoom(room);

      Message *rmsg = new Message(Message::ROOM_STATE);
      InternalMessage *imsg = new InternalMessage(new TCPPacket(rmsg, 0), to);
      imsg->addReceiver(to);
      rmsg->setAttr("id", Ultra::Value((unsigned short)room->getID()));
      rmsg->setAttr("state", Ultra::Value((char)Room::OK));

      std::stringstream ss;
      
      ss << room->getID();

      Logging::Message lm("Room create [id = " + ss.str() + ']', "RoomService", Logging::Message::DEBUG);
      this->_log << lm;

      Core::srv_manager->notifyService(ServiceManager::DISPATCH, imsg);
  }
}
コード例 #3
0
bool 
RoomManager::addPlayerIntoRoom(void * player, char type)
{
	pthread_mutex_lock(&addPlayerMutex);
	Room * room = (Room *)getMaxFilledRoom(type);
	if (room)
	{
		room->addPlayer(player);
		pthread_mutex_unlock(&addPlayerMutex);
		return true;
	}
	else
	{
		pthread_mutex_unlock(&addPlayerMutex);
		return false;
	}
}