Ejemplo n.º 1
0
int run_game_cont2(void)
{
    int quitflag = 0;
    if(boot_mode & 2)
        quitflag = quitflag || update_server();
    net_flush();

    // update time
    sec_lasttime = sec_curtime;
    int64_t usec_curtime = platform_get_time_usec() - usec_basetime;
    sec_curtime = ((float)usec_curtime)/1000000.0f;

    return quitflag;
}
Ejemplo n.º 2
0
void run_game(void)
{
    //clmap = map_load_aos(fnmap);

    tcam.mpx = 256.5f;
    tcam.mpz = 256.5f;
    tcam.mpy = 32.0f-3.0f;
    //clmap->pillars[((int)tcam.mpz)*clmap->xlen+((int)tcam.mpy)][4+1]-2.0f;

    tcam.mxx = 1.0f;
    tcam.mxy = 0.0f;
    tcam.mxz = 0.0f;
    tcam.myx = 0.0f;
    tcam.myy = 1.0f;
    tcam.myz = 0.0f;
    tcam.mzx = 0.0f;
    tcam.mzy = 0.0f;
    tcam.mzz = 1.0f;

    int i;

    //render_vxl_redraw(&tcam, clmap);

    int quitflag = 0;

    usec_basetime = platform_get_time_usec();

    while(!quitflag)
    {
        // update time
        sec_lasttime = sec_curtime;
        int64_t usec_curtime = platform_get_time_usec() - usec_basetime;
        sec_curtime = ((float)usec_curtime)/1000000.0f;

        // update client/server
        if(boot_mode & 1)
            quitflag = quitflag || update_client();
        net_flush();
        if(boot_mode & 2)
            quitflag = quitflag || update_server();
        net_flush();
    }
    map_free(clmap);
    clmap = NULL;
}
Ejemplo n.º 3
0
int run_game_cont1(void)
{
	int quitflag = update_client_cont1();
	net_flush();
	if(boot_mode & 2)
		quitflag = quitflag || update_server();
	net_flush();
	
	// update time
	sec_lasttime = sec_curtime;
	int64_t usec_curtime = platform_get_time_usec() - usec_basetime;
	sec_curtime = ((double)usec_curtime)/1000000.0;
	
	// update client/server
	quitflag = quitflag || update_client_contpre1();
	
	return quitflag;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
	int i, cur;

	tgetopt(argc, argv);

	if ( toptset('h') )
	{
		printf(usage, argv[0]);
		exit(0);
	}

	if ( toptset('c') ) 
		config_file = toptargs('c');

	syslog_open("updategroups", LOG_PID, LOG_NEWS);

	if ( (master = memmap(sizeof(MASTER))) == NULL )
		die("Can't allocate master memory");

	if ( (groups = memmap(sizeof(ACTIVE) * MAX_GROUPS)) == NULL )
		die("Can't allocate groups memory");

	loadconfig();
	load_servers();

	cur = -1;
	for (i=master->numservers-2; i>=0; i-- )
		if ( (master->lservers[i])->Level != cur )
		{
			cur = (master->lservers[i])->Level;
			update_server( master->lservers[i] );
		}

	write_active();
	write_newsgroups();

	memunmap(master, sizeof(MASTER));
	memunmap(groups, sizeof(ACTIVE) * MAX_GROUPS);

	syslog_close();

	exit(0);
}
int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
  int error= ER_FOREIGN_SERVER_DOESNT_EXIST;
  FOREIGN_SERVER *altered, *existing;
  LEX_STRING name= { server_options->server_name, 
                     server_options->server_name_length };
  DBUG_ENTER("alter_server");
  DBUG_PRINT("info", ("server_options->server_name %s",
                      server_options->server_name));

  rw_wrlock(&THR_LOCK_servers);

  if (!(existing= (FOREIGN_SERVER *) hash_search(&servers_cache,
                                                 (uchar*) name.str,
                                                 name.length)))
    goto end;

  altered= (FOREIGN_SERVER *)alloc_root(&mem,
                                        sizeof(FOREIGN_SERVER));

  prepare_server_struct_for_update(server_options, existing, altered);

  error= update_server(thd, existing, altered);

  /* close the servers table before we call closed_cached_connection_tables */
  close_thread_tables(thd);

  if (close_cached_connection_tables(thd, FALSE, &name))
  {
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                        ER_UNKNOWN_ERROR, "Server connection in use");
  }

end:
  DBUG_PRINT("info", ("error returned %d", error));
  rw_unlock(&THR_LOCK_servers);
  DBUG_RETURN(error);
}
Ejemplo n.º 6
0
void
GameSession::update(float delta)
{
  update_server(delta);
  GUIScreen::update(delta);
}
Ejemplo n.º 7
0
void
handle_server_events(server_t *server)
{
    // respond to events
    memset(&server->ke, 0, sizeof(server->ke));
    if (kevent(server->kq, NULL, 0, &server->ke, 1, NULL) <= 0) {
        usleep(5000);
        return;
    }

    if (server->ke.ident == (uintptr_t)server->sock) {
        // client connection
        int cl_sock;
        struct sockaddr_in c;
        socklen_t len;

        if ((cl_sock = accept(server->sock,
                        (struct sockaddr *)&c, &len)) == -1)
            err(EX_UNAVAILABLE, "accept");

        // init client
        client_conn_t *conn = calloc(1, sizeof(client_conn_t));
        conn->sock = cl_sock;
        memcpy(&conn->addr, &c.sin_addr, sizeof(c.sin_addr));
        conn->client = init_client();
        server->clients[server->client_count++] = conn;

        // listen to the client socket
        EV_SET(&server->ke, conn->sock, EVFILT_READ, EV_ADD, 0, 0, NULL);
        if (kevent(server->kq, &server->ke, 1, NULL, 0, NULL) == -1)
            err(EX_UNAVAILABLE, "kevent add user");

        fprintf(stderr, "connection from %s\n", inet_ntoa(c.sin_addr));
    } else if (server->ke.ident == 0) {
        // game update timer fired
        update_server(server);
    } else {
        // client data
        client_conn_t *conn = find_client(server, server->ke.ident);

        // read the data
        char buf[1024];
        memset(&buf, 0, sizeof(buf));
        int n = read(conn->sock, buf, sizeof(buf));

        // not ready yet
        if (n == -1)
            return;

        // EOF - disconnect user
        if (n == 0) {
            EV_SET(&server->ke, conn->sock, EVFILT_READ, EV_DELETE, 0, 0,
                    NULL);
            if (kevent(server->kq, &server->ke, 1, 0, 0, NULL) == -1)
                err(EX_UNAVAILABLE, "disconnect user");

            fprintf(stderr, "%s logged out\n", conn->client->username);
            close(conn->sock);

            if (conn->client)
                if (conn->client->entity)
                    conn->client->entity->dead = true;

            free(conn);

            return;
        }

        // handle the data
        handle_client_request(server, conn, buf, n);
    }
}
Ejemplo n.º 8
0
int main()
{
	int which_to_update = 6; // start greater than 5 so we get data
	uint32_t data[5]; // Array to hold ADC data

	// Initialize all the things
	LED_init();
	systick_init(400000); // Timer goes off 10 times per second
	USART2_init();
	USART3_init();
	button_init();
	ADC_init();
	servo_init();
	DMA_init();

	/* Enable interrupts */
	__asm ("  cpsie i \n" );


	/* Main program loop */
	while(1)
	{
		// State specific behavior (every time)
		switch (mode_state) {
		case CONFIGURE_S:
			// Don't do anything
			break;
		case COMMAND_S:
		{
			/* Send in two cases:
			 * a) we're not waiting for a packet
			 * b) the update flag is set (every second, because sometimes packets get dropped
			 * 	and we don't want to wait forever)
			 *
			 * When we send a byte, we'll send whichever is next in the sequence (the current one
			 * is stored in the local variable (in main) which_to_update). When it goes over 5,
			 * we read in all the data for the next round of packets.
			 */
			if (!waiting_to_recv_packet || send_update_f) {
//			if (send_update_f) {
				if (which_to_update > 5) { // finished updating
					ADC_read(data);
					which_to_update = 1;
				}

				// We will be waiting for a packet back, so set this ahead of time
				waiting_to_recv_packet=1;
				// A new packet will be inbound, so reset the offset to 0 (in case it got messed up before)
				recv_offset = 0;
				update_server(which_to_update, data);
				which_to_update++;

				send_update_f = 0;
			}

			break;
		}
		case CLIENT_S:
		{
			/*
			 * Update the servos on the high tick of this flag. That is set in systick, and happens 10 times
			 * per second
			 */
			if (update_servos_from_server_f) {
				// We're about to receive a response packet, so we reset the recv_offset to 0
				recv_offset = 0;
				waiting_to_recv_packet = 1;
				update_servos();
				update_servos_from_server_f = 0;
			}

			break;
		}
		default:
			break;
		}

		// Every time, regardless of state:
		// If we received a packet, print it
		if (received_new_packet) {
//			switch (recv_msg.pingmsg.type) {
//			case TYPE_PING:
//				print_string("[PING,id=");
//				printUnsignedDecimal(recv_msg.pingmsg.id);
//				print_string("]\n");
//				break;
//			case TYPE_UPDATE:
//				print_string("[UPDATE,id=");
//				printUnsignedDecimal(recv_msg.respmsg.id);
//				print_string(",average=");
//				printUnsignedDecimal(recv_msg.respmsg.average);
//				print_string(",{");
//				for (int i=0; i<CLASS_SIZE_MAX; i++) {
//					print_string(" ");
//					printUnsignedDecimal(recv_msg.respmsg.values[i]);
//				}
//				print_string("}]\n\r");
//				break;
//			default:
//				break;
//			}
			// Reset the flag
			received_new_packet = 0;

			// If we're in client mode, set the servo values to those from the server
			if (mode_state == CLIENT_S) {
				if (recv_msg.respmsg.type == TYPE_UPDATE) {
					for (int i=1; i<=5; i++)
						servo_update(i, recv_msg.respmsg.values[i]);
				}
			}
		}

		// After switching states, update leds
		if (update_leds_f) {
			switch (mode_state) {
			case CONFIGURE_S:
				LED_update(LED_BLUE_ON|LED_ORANGE_OFF);
				// Configuration:
				// $$$ (escape sequence)
				// set ip dhcp 1 (get IP address with dhcp)
				// set ip host 172.16.1.10 (set remote IP)
				// set ip remote 8004
				// set wlan join 1 (try to connect to stored access point)
				// set wlan auth 4 (set to WPA2-PSK)
				// set wlan phrase ENGS62wifi
				// set wlan ssid ENGS62
				// save
				// reboot
				break;
			case CLIENT_S:
				LED_update(LED_BLUE_OFF|LED_ORANGE_ON);
				break;
			case COMMAND_S:
				LED_update(LED_BLUE_ON|LED_ORANGE_ON);
				waiting_to_recv_packet = 0;
				break;
			}
			update_leds_f = 0;
		}

		// If in debug mode, print ADC data to the console
		if (DEBUG && test_flag)
		{
			test_flag = 0;
			uint32_t data[5];
			// Initialize the data array to 0 for clarity
			for (int i=0; i<5; i++) {
				data[i] = 0;
			}

			ADC_read(data);
			for (int i=0; i<5; i++) {
				printUnsignedDecimal((uint16_t)data[i]);
				print_string("\n");
				print_string("\r");
			}
			print_string("-----------\n");
		}
	}
	/* We'll never reach this line */
	return 0;
}