Exemplo n.º 1
0
void sig_notify(int itf,int up)
{
    SIGNALING_ENTITY *sig;

    for (sig = entities; sig; sig = sig->next)
	if (sig->itf == itf) break;
    if (!sig) {
	diag(COMPONENT,DIAG_ERROR,"%s notification for unknown interface %d",
	  up ? "up" : "down",itf);
	return;
    }
    if (sig->pvc.sap_addr.itf == -1) return;
    if (up) {
	struct atm_qos qos;

	sig->call = new_call();
	sig->call->in.pvc = sig->pvc;
	sig->call->out.pvc.sap_addr.itf = sig->itf;
	sig->call->out.pvc.sap_addr.vpi = 0;
	sig->call->out.pvc.sap_addr.vci = 5;
	memset(&qos,0,sizeof(qos));
	qos.txtp.traffic_class = qos.rxtp.traffic_class = ATM_UBR;
	fab_op(sig->call,RM_CLAIM(_RM_ANY),&qos,up_callback,sig);
    }
    else {
	route_sig(sig,&sig->call->out.pvc,0);
	remove_entity(sig);
	fab_op(sig->call,RM_FREE,NULL,down_callback,NULL);
	free_call(sig->call);
    }
}
Exemplo n.º 2
0
void EntityManager::update()
{
	for(auto entity : pending_deletion)
	{
		std::cout << "Removing " + entity->get_name() << std::endl;
		remove_entity(entity, true);
	}
	pending_deletion.clear();
}
Exemplo n.º 3
0
void GAMEWORLD::remove_entities()
{
	// destroy objects marked for destruction
	ENTITY *ent = first_entity;
	while(ent)
	{
		ENTITY *next = ent->next_entity;
		if(ent->marked_for_destroy)
		{
			remove_entity(ent);
			ent->destroy();
		}
		ent = next;
	}
}
Exemplo n.º 4
0
int server(int num_clients, int port)
{
    WicServer server;
    wic_init_server(&server, port, num_clients);
    ClientData* clients = malloc(num_clients * sizeof(ClientData));
    for(int i = 0; i < num_clients; i++)
        clients[i].joined = false;
    
    Command command;
    command.created = false;
    pthread_t command_thread;
    pthread_create(&command_thread, 0, accept_command, &command);
    printf("Type commands below...\n");
    
    WicPacket recv;
    WicPacket send;
    while(true)
    {
        if(command.created == true)
        {
            if(strncmp(command.first_arg, "exit", 4) == 0)
                break;
            else if(strcmp(command.first_arg, "help") == 0)
                print_command_list();
            else if(strcmp(command.first_arg, "kick") == 0)
            {
                ClientData* client = lookup_client(clients, command.second_arg,
                                                   num_clients);
                if(client == 0)
                    printf("ERROR: Client %s does not exist\n",
                           command.second_arg);
                else
                    wic_kick_client(&server, client->client_id);
            }
            else if(strcmp(command.first_arg, "ban-client") == 0)
            {
                ClientData* client = lookup_client(clients, command.second_arg,
                                                   num_clients);
                if(client == 0)
                    printf("ERROR: Client %s does not exist\n",
                           command.second_arg);
                else
                    wic_ban_client(&server, client->client_id);
            }
            else if(strcmp(command.first_arg, "ban-address") == 0)
            {
                wic_ban_address(&server, command.second_arg);
            }
            else if(strcmp(command.first_arg, "unban-address") == 0)
            {
                wic_unban_address(&server, command.second_arg);
            }
            else if(strcmp(command.first_arg, "ls-clients") == 0)
            {
                print_clients(clients, num_clients);
            }
            else
                printf("%s '%s'. %s", "ERROR: Invalid command",
                       command.first_arg, "Type 'help' for command list\n");
            command.created = false;
            pthread_create(&command_thread, 0, accept_command, &command);
        }
        enum WicError error = wic_server_recv_packet(&server, &recv);
        if(error == WICER_NONE)
        {
            unsigned char client_id = recv.client_id;
            if(recv.type.id == WIC_PACKET_JOIN.id)
            {
                clients[client_id].joined = true;
                clients[client_id].client_id = client_id;
                init_entity_manager(&clients[client_id].manager);
                printf("client %u joined\n", client_id);
            }
            if(recv.type.id == PACKET_USERNAME_INFO.id)
            {
                memcpy(clients[client_id].username, recv.data,
                       PACKET_USERNAME_INFO.size);
                wic_send_packet_to_other_clients(&server, &recv, client_id);
                for(unsigned char id = 0; id < num_clients; id++)
                {
                    if(clients[id].joined && id != client_id)
                    {
                        send.type = PACKET_USERNAME_INFO;
                        send.client_id = id;
                        memcpy(send.data, clients[id].username,
                               sizeof(clients[id].username));
                        wic_send_packet_to_client(&server, &send, client_id);
                    }
                }
            }
            else if(recv.type.id == WIC_PACKET_LEAVE.id)
            {
                clients[client_id].joined = false;
                free_entity_manager(&clients[client_id].manager);
                printf("client %u left\n", recv.client_id);
            }
            else if(recv.type.id == PACKET_UPDT_ENTITY.id)
            {
                Entity entity;
                memcpy(&entity, recv.data, PACKET_UPDT_ENTITY.size);
                updt_entity(&clients[client_id].manager, entity);
                wic_send_packet_to_other_clients(&server, &recv, client_id);
            }
            else if(recv.type.id == PACKET_REMV_ENTITY.id)
            {
                remove_entity(&clients[client_id].manager, recv.data[0]);
                wic_send_packet_to_other_clients(&server, &recv, client_id);
            }
        }
    }
    printf("Exiting server..\n");
    wic_free_server(&server);
    return 0;
}
 int adp_discovery_state_machine::state_timeout(uint32_t entity_index)
 {
     remove_entity(entity_index);
     return 0;
 }
Exemplo n.º 6
0
void update_entity(entity * e){
  oct_node oc = e->node;
  remove_entity((entity_header *) e);
  oc = oct_find_fitting_node(oc, &e->offset, &e->size);
  add_entity(oc, (entity_header *) e);
}