Пример #1
0
bool BellServer::registerClient(uint32 key, socketuid_t uid, BellSocket *socket)
{
	ClientsIt clientIt;
	ClientsBellsIt bellIt;
	
	// Skip uid == 0 as that is reserved
	if(uid == 0)
		return false;
	
	// Check if this key even exists
	bellIt = clientBells_.find(key);
	if(bellIt == clientBells_.end())
	{
		printf("This key does not exists!\n");
		return false;
	}
	
	// Check if it already exists if so we can not register you
	Clients *bells = &clientBells_[key];
	clientIt = bells->find(uid);
	if(clientIt != bells->end())
		return false;
	
	// Register this socket
	(*bells)[uid] = socket;
	return true;
}
Пример #2
0
Client::Client(Clients& clients, size_t size, size_t my_server_slot,
               unique_ptr<Socket> socket_tcp,
               unique_ptr<Socket> socket_udp)
	  : clients_(clients),
      my_server_slot_(my_server_slot), 
      socket_tcp_(move(socket_tcp)),
      socket_udp_(move(socket_udp)),
      connected { true } {
  //Setup the sending queues.
  reliable_data_.resize(size);
  data_.resize(size);
	//load the dataStream with unique shared ptrs at each index.
	for (size_t i = 0; i < data_.size(); ++i) {
    data_[i] = make_shared<Data::Sharing::FixedQueue>();
    reliable_data_[i] = make_shared<Data::Sharing::FixedQueue>();
	}

	//assert(size < 256 && index < 256);
	Send(*socket_tcp_, InitialMessage{ uint8_t(size), uint8_t(my_server_slot_) });
  clients_.SendReliableToAll(
      Packet::PackStatus(uint8_t(my_server_slot_), Packet::Status::kNew));
  clients.SendInitialClientDataTo(*socket_tcp_);
	clients.SendReliableToAll(Packet::RequestData(uint8_t(my_server_slot_)));

  thread_receive_ = thread(&Client::ReceiveLoop, this);
  thread_send_ = thread(&Client::SendLoop, this);
}
Пример #3
0
void Game::process()
{
   Admin* admin;
   Client * player;
   Clients* clients = mClientMgr.list();
   bool worldSave = false;
   for (Clients::iterator client=clients->begin(); client != clients->end(); client++)
   {
      player = client->second;
      if (player->isAdmin())
      {
         admin = player->getAdmin();

         /* Add any buildings that an admin has placed down. */
         processBuildingReqs(admin);

         /* Check if the save command was issued */
         if (admin->getWorldSaveReq())
         {
            worldSave = true;
         }
      }
   }

   if (worldSave)
   {
      mZoneMgr.saveWorld();
   }
}
Пример #4
0
std::string get_name_by_sock(Clients clients, int sockfd)
{
   /* cauta numele dupa socket */
   std::map <std::string, ClientInfo> ::iterator it;
   
   for (it = clients.begin(); it != clients.end(); it++)
      if ((*it).second.getSock() == sockfd)
	 return (*it).first;
      
   return "anonymous";
}
Пример #5
0
bool Musicmanager::login(const boost::optional<std::string>& oauth_credentials, 
                         const boost::optional<identifier>& uploader_id, 
                         const boost::optional<std::string>& uploader_name)
{
    auto credentials = oauth_credentials ? *oauth_credentials : []()
    {
        Clients c;
        return c.OAUTH_FILEPATH();
    }();

    return callMethod<bool>("login", oauth_credentials, uploader_id, uploader_name);
}
Пример #6
0
Файл: Main.cpp Проект: leod/game
    void onPlayerInputWish(ClientId clientId, PlayerInput const& playerInput) {
        auto client = clients.get(clientId);

        auto entity = client->entity;
        if (entity) {
            auto input = entity->component<PlayerInputComponent>();
            auto physics = entity->component<PhysicsComponent>();
            ASSERT(input);
            ASSERT(physics);

            input->onPlayerInput(playerInput);

            if (playerInput.shoot) {
                auto origin = physics->getPosition() +
                              physics->getOrientation() * 0.65f;
                auto orientation =
                    vec3(playerInput.orientation.x, 0,
                         playerInput.orientation.y);
                auto components =
                    makeProjectile(netSystem.makeNetEntityId(),
                                   clientId,
                                   origin,
                                   orientation);
                entities.create(std::move(components));
            }

#ifdef USE_PREDICTION
            vec3 newPosition = physics->getPosition();
            sendEvent<PlayerPositionOrder>(client->peer, newPosition);
#endif
        }
    }
Пример #7
0
void BellServer::handleButton(uint8 buttonNo)
{
	switch(buttonNo)
	{
		case 6:
			printf("Call all\n");
		break;
		default:
			uint32 key = indexToKey(buttonNo);
			printf("Calling client %i with key: %08X\n", buttonNo, key);
			Clients *bells = &clientBells_[key];
			
			// Go through all client attached to this bell
			for(ClientsIt it=bells->begin(); it!=bells->end(); it++)
			{
				if(it->first == 0) continue;
				BellSocket *socket = it->second;
				socket->handleCall();
			}
		break;
	}
}
Пример #8
0
//-------------------------------------------------------------------------------------------------
Clients Configuration::create_clients(const XmlElement *from) const
{
	string name;
	const XmlElement *which;
	Clients clients;
	if (from_or_default(from, "target_comp_id", name) && (which = find_group(g_client_group, name)))
	{
		XmlElement::XmlSet slist;
		if (which->find("client_group/client", slist))
		{
			// <client name="Goldsteins" target_comp_id="DLD_TEX" ip="192.168.0.17" active="true" />
			for(const auto *pp : slist)
			{
				string name, tci;
				const Poco::Net::IPAddress addr(get_ip(pp));
				if (pp->GetAttr("name", name) && pp->GetAttr("target_comp_id", tci) && pp->FindAttr("active", true))
					if (!clients.insert({tci, Client(name, addr)}).second)
						throw ConfigurationError("Failed to add client from client_group", tci);
			}
		}
	}

	return clients;
}
Пример #9
0
Файл: Main.cpp Проект: leod/game
    // Implement ENetReceiver
    void onConnect(ENetPeer* peer) {
        auto newClient = clients.add(peer);

        INFO(server) << "Client " << (int)newClient->id << " connected";

        // Tell the client its id. This needs to happen before sending
        // the CreateEntityMessages, so that the client can identify what
        // entities belong to it.
        sendEvent<LoggedInOrder>(peer, newClient->id);
        
        // Create player entity for the client
        newClient->entity = entities.create(
            makePlayer(netSystem.makeNetEntityId(),
                       newClient->id,
                       vec3(0, 0, 0),
                       vec3(0, 0, 0)));

        // Send messages to create our net objects on the client side
        netSystem.sendCreateEntityOrders(newClient);

        // Tell everyone about the new client
        clients.broadcast<ClientConnectedOrder>(newClient->id, "dummy");
    }
Пример #10
0
Файл: Main.cpp Проект: leod/game
 void onDisconnect(ENetPeer* peer) {
     auto client = reinterpret_cast<ClientInfo*>(peer->data);
     handleDisconnect(client);
     clients.remove(client);
 }
Пример #11
0
Файл: Main.cpp Проект: leod/game
 void onPing(ClientId clientId) {
     sendEvent<Pong>(clients.get(clientId)->peer);
 }
Пример #12
0
Файл: Main.cpp Проект: leod/game
 void onDisconnectWish(ClientId clientId) {
     handleDisconnect(clients.get(clientId));
 }
Пример #13
0
bool BellServer::unregisterClient(uint32 key, socketuid_t uid)
{
	Clients *bells = &clientBells_[key];
	return bells->erase(uid);
}