Exemplo n.º 1
0
void fs2netd_gameserver_update(bool force)
{
	if ( !Logged_in ) {
		return;
	}

	// server hasn't started yet?
	if ( !(Net_player->flags & NETINFO_FLAG_MT_CONNECTED) ) {
		return;
	}

	// is it actually time for an update
	if ( !force && (timer_get_seconds() < Next_gameserver_update) ) {
		return;
	}

	strcpy_s(Multi_tracker_game_data.mission_name, Netgame.mission_name);
	strcpy_s(Multi_tracker_game_data.title, Netgame.title);
	strcpy_s(Multi_tracker_game_data.campaign_name, Netgame.campaign_name);

	Multi_tracker_game_data.campaign_mode = (ubyte)Netgame.campaign_mode;
	Multi_tracker_game_data.players = (short)multi_num_players();
	Multi_tracker_game_data.game_state = (ubyte)Netgame.game_state;

	FS2NetD_SendServerUpdate();

	// set timeout for every 2 minutes
	Next_gameserver_update = timer_get_seconds() + 120;

	ml_string("FS2NetD sent game server update");
}
Exemplo n.º 2
0
int fs2netd_get_pilot_info(const char *callsign, player *out_plr, bool first_call)
{
	if ( !Logged_in ) {
		return -2;
	}

	if ( (out_plr == NULL) || (callsign == NULL) || !(strlen(callsign)) ) {
		return -2;
	}

	static player new_plr;

	if (first_call) {
		new_plr.reset();
		strncpy( new_plr.callsign, callsign, CALLSIGN_LEN );

		// initialize the stats to default values
		init_scoring_element( &new_plr.stats );

		out_plr->reset();

		Local_timeout = timer_get_seconds() + 30;

		In_process = true;

		ml_printf("FS2NetD MSG: Requesting pilot stats for '%s' ...", callsign);
	}

	int rc = FS2NetD_GetPlayerData(callsign, &new_plr, false, first_call);

	// some sort of failure
	if (rc > 0) {
		In_process = false;
		Local_timeout = -1;
		return -2;
	}

	// if timeout passes then bail on failure
	if ( timer_get_seconds() > Local_timeout ) {
		In_process = false;
		Local_timeout = -1;
		return -2;
	}

	if (rc == 0) {
		memcpy( out_plr, &new_plr, sizeof(player) );
		In_process = false;
		Local_timeout = -1;
	}

	// we should only be returning -1 (processing) or 0 (got data successfully)
	return rc;
}
Exemplo n.º 3
0
void show_timer_text() {
  SDL_FreeSurface(timer_text);
  char time[128];
  sprintf(time, "%d", timer_get_seconds());
  timer_text = TTF_RenderText_Blended(input_font, time, font_color);
  apply_surface(
    screen_width - timer_text->w, 0, timer_text, screen
  );
}
void fs2netd_do_frame()
{
	// in a previous processing loop, so don't do a frame until that has completed
	if ( In_process ) {
		return;
	}

	if ( !Logged_in ) {
		// maybe try and reconnect, if we were bumped due to a comm error ...
		if ( (Login_retry_time != -1) && (timer_get_seconds() >= Login_retry_time) ) {
			fs2netd_login();

			if ( !Logged_in ) {
				// bah!  try again in another 5 minutes
				Login_retry_time = timer_get_seconds() + 300;
			} else {
				Login_retry_time = -1;
			}
		}

		return;
	}

	// do ping/pong and ident
	fs2netd_handle_ping();

	if (!Is_connected) {
		// The ping handling above made us realize that we are disconnected. We will reconnect in some time so we can
		// just return here
		return;
	}

	// handle gameserver updates
	fs2netd_gameserver_update();

	// check for server messages, ping replies, etc.
	fs2netd_handle_messages();

	// WTF?!  (TODO: figure out how this happens)
	if (Is_connected && !Logged_in) {
		fs2netd_login();
	}
}
Exemplo n.º 5
0
int fs2netd_update_valid_tables_do()
{
	if (Local_timeout == -1) {
		Local_timeout = timer_get_seconds() + 30;
	}

	int rc = FS2NetD_ValidateTableList(do_full_packet);

	do_full_packet = false;

	// if timeout passes then bail on crc failure
	if ( timer_get_seconds() > Local_timeout ) {
		Local_timeout = -1;
		return 1;
	}

	if ( rc == 0 ) {
		return 0;
	}

	switch (rc) {
		// some error occured, assume that there are no valid table crcs
		case -1:
			Local_timeout = -1;
			return 2;

		// timeout
		case 1:
			Local_timeout = -1;
			return 1;

		// done!
		case 2:
			Local_timeout = -1;
			return 3;
	}

	return 0;
}
Exemplo n.º 6
0
static int fs2netd_send_player_do()
{
	if (Local_timeout == -1) {
		Local_timeout = timer_get_seconds() + 15;
	}

	// if timeout passes then bail on stats failure
	if ( timer_get_seconds() > Local_timeout ) {
		Local_timeout = -1;
		return 2;
	}

	int rescode = FS2NetD_SendPlayerData(Players[Player_num].callsign, &Players[Player_num], do_full_packet);

	do_full_packet = false;

	if (rescode != -1) {
		Local_timeout = -1;
		return rescode+3;
	}

	return 0;
}
Exemplo n.º 7
0
int fs2netd_check_mission_do()
{
	if (Local_timeout == -1) {
		Local_timeout = timer_get_seconds() + 15;
	}

	// if timeout passes then bail on stats failure
	if ( timer_get_seconds() > Local_timeout ) {
		Local_timeout = -1;
		return 4;
	}

	int rescode = FS2NetD_CheckSingleMission(Chk_mission_name, Chk_mission_crc, do_full_packet);

	do_full_packet = false;

	if (rescode) {
		Local_timeout = -1;
		return rescode;
	}

	return 0;
}
Exemplo n.º 8
0
int fs2netd_update_ban_list_do()
{
	if (Local_timeout == -1) {
		Local_timeout = timer_get_seconds() + 30;
	}

	// if timeout passes then bail on stats failure
	if ( timer_get_seconds() > Local_timeout ) {
		Local_timeout = -1;
		return 2;
	}

	int rc = FS2NetD_GetBanList(FS2NetD_ban_list, do_full_packet);

	do_full_packet = false;

	if (rc) {
		Local_timeout = -1;
		return 1;
	}

	return 0;
}
Exemplo n.º 9
0
void fs2netd_gameserver_start()
{
	if ( !Logged_in ) {
		return;
	}

	// already been here
	if (Net_player->flags & NETINFO_FLAG_MT_CONNECTED) {
		return;
	}

	memset(&Multi_tracker_game_data, 0, sizeof(tracker_game_data));

	strcpy_s(Multi_tracker_game_data.name, Netgame.name);
	strcpy_s(Multi_tracker_game_data.mission_name, Netgame.mission_name);
	strcpy_s(Multi_tracker_game_data.title, Netgame.title);
	strcpy_s(Multi_tracker_game_data.campaign_name, Netgame.campaign_name);

	if ( strlen(Multi_fs_tracker_channel) ) {
		strcpy_s(Multi_tracker_game_data.chat_channel, Multi_fs_tracker_channel);
	}

	Multi_tracker_game_data.campaign_mode = (ubyte)Netgame.campaign_mode;
	Multi_tracker_game_data.flags = Netgame.flags;
	Multi_tracker_game_data.type_flags = Netgame.type_flags;
	Multi_tracker_game_data.players = (short)multi_num_players();
	Multi_tracker_game_data.max_players = (short)Netgame.max_players;
	Multi_tracker_game_data.mode = (ubyte)Netgame.mode;
	Multi_tracker_game_data.rank_base = (ubyte)Netgame.rank_base;
	Multi_tracker_game_data.game_state = (ubyte)Netgame.game_state;
	Multi_tracker_game_data.speed = (ubyte)multi_get_connection_speed();

	FS2NetD_SendServerStart();

	Net_player->flags |= NETINFO_FLAG_MT_CONNECTED;

	// initial update should be about 2 seconds from now
	Next_gameserver_update = timer_get_seconds() + 2;

	ml_string("FS2NetD sent game server start");
}
Exemplo n.º 10
0
int main(int argc, char* args[]) {
  setlocale(LC_ALL, "de_DE.UTF-8");

  if (init() == FALSE)
    return 1;

  Uint32 frameStart = 0;
  espeak_set_run(TRUE);
  int valid_input = -1;
  int do_input_name = FALSE;
  int do_input_continue = FALSE;
  int input_move_y = 0;

  while (quit == FALSE) {
    if (do_input_name == FALSE && do_input_continue == FALSE)
      timer_update();
    frameStart = SDL_GetTicks();

    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) {

        int skip_input = (strcmp(input_str, "") == 0) ? TRUE : FALSE;
        if (do_input_continue && strcmp(input_str, "") != 0) {
          if (strcmp(input_str, "nein") == 0) {
            quit = TRUE;
          } else {
            do_input_continue = FALSE;
            textlist_init();
            textlist_set_random_pos();
            timer_start();
            inputs_count = 0;
            input_init();
            espeak_set_run(TRUE);
          }
        } else if (do_input_name == TRUE && strcmp(input_str, "") != 0) {
          scorelist_add_score(input_str_w, textlist_get_chars_count(), timer_get_seconds());
          do_input_continue = TRUE;
          do_input_name = FALSE;
          input_init();

        } else if (textlist_current_compare(input_str_w) == 0 || skip_input == TRUE) {
          if (skip_input == FALSE)
            valid_input = TRUE;
          inputs_count++;
          espeak_lock();
          textlist_remove_current(skip_input);
          espeak_unlock();

          if (inputs_count == max_inputs) {
            do_input_name = TRUE;
            input_init();
          }
          if (do_input_name == FALSE && quit == FALSE) {
            espeak_lock();
            quit = (textlist_set_random_pos() == TRUE) ? FALSE : TRUE;
            espeak_unlock();
            input_init();
            espeak_set_run(TRUE);
          }
        } else {
          valid_input = FALSE;
          input_init();
          espeak_set_run(TRUE);
        }
      } else {
        handle_input();
      }
      if (event.type == SDL_VIDEORESIZE) {
        screen_width = event.resize.w;
        screen_height = event.resize.h;
        screen = SDL_SetVideoMode(
          screen_width, screen_height, screen_bpp, SDL_SWSURFACE | SDL_RESIZABLE
        );
      }
      if (event.type == SDL_QUIT) {
        quit = TRUE;
      }
    }

    SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0));

    show_timer_text();
    input_move_y = (do_input_continue == TRUE) ? screen_height * 0.1 : 0;

    if (do_input_continue == TRUE)
      output_scores();
    show_info_text(valid_input, do_input_name, do_input_continue, input_move_y);
    input_show_centered(input_move_y);

    apply_surface(
      screen_width - footer_message->w, screen_height - footer_message->h,
      footer_message, screen
    );
    apply_surface(0, 0, header_message, screen);
    if (SDL_Flip(screen) == -1)
      return 1;

    if ((SDL_GetTicks() - frameStart) < (1000 / FPS)) {
      SDL_Delay((1000 / FPS) - (SDL_GetTicks() - frameStart));
    }
  }

  clean_up();
  return 0;
}
Exemplo n.º 11
0
static void fs2netd_handle_messages()
{
	int buffer_size = 0, buffer_offset = 0;
	int bytes_read = 0;
	char tbuf[256];
	char buffer[8192];
	ubyte pid = 0;
	int itemp;

	while ( FS2NetD_DataReady() && (bytes_read < (int)sizeof(buffer)) ) {
		int read_size = FS2NetD_GetData(buffer+bytes_read, sizeof(buffer)-bytes_read);

		if (read_size <= 0) {
			break;
		}

		bytes_read += read_size;

		Sleep(20);
	}

	if ( (bytes_read == 0) || (bytes_read < BASE_PACKET_SIZE) ) {
		return;
	}

	Last_activity = timer_get_seconds();

	buffer_offset = 0;

	while (buffer_offset+BASE_PACKET_SIZE <= bytes_read) {
		PXO_GET_DATA( pid );
		PXO_GET_INT( buffer_size );

		// packet has more data than our buffer received
		if (buffer_offset+buffer_size-BASE_PACKET_SIZE > bytes_read) {
			break;
		}

		// processing time!
		switch (pid) {
			case PCKT_PING: {
				PXO_GET_INT( itemp );

			//	ml_printf("FS2NetD received PING");

				FS2NetD_Pong(itemp);

				break;
			}

			case PCKT_PONG: {
				PXO_GET_INT( itemp );

				ml_printf("FS2NetD PONG: %d ms", timer_get_milliseconds() - itemp);

				// reset timestamp, since the ping was successful
				Ping_timestamp = -1;

				break;
			}

			case PCKT_NETOWRK_WALL: {
				PXO_GET_STRING( tbuf );
				ml_printf("FS2NetD WALL received MSG: %s", tbuf);

				switch (Netgame.game_state) {
					case NETGAME_STATE_FORMING:
					case NETGAME_STATE_BRIEFING:
					case NETGAME_STATE_MISSION_SYNC:
					case NETGAME_STATE_DEBRIEF:
						multi_display_chat_msg(tbuf, 0, 0);
						break;

					case NETGAME_STATE_IN_MISSION: // gotta make it paused
						//multi_pause_request(1); 
						//send_game_chat_packet(Net_player, str, MULTI_MSG_ALL, NULL);
						HUD_printf(tbuf);
						break;

					default:
						// do-nothing
						break;
				}

				break;
			}

			case PCKT_CHAT_CHAN_COUNT_REPLY: {
				PXO_GET_STRING( tbuf );
				PXO_GET_INT( itemp );

				if ( (itemp < 0) || (itemp > USHRT_MAX) ) {
					itemp = 0;
				}

				multi_pxo_channel_count_update(tbuf, itemp);

				break;
			}

			case PCKT_VALID_SID_REPLY: {
				ubyte login_status = 0;

				PXO_GET_DATA( login_status );

				if (login_status != 1) {
					ml_printf("FS2NetD IDENT: Got invalid login check!");
					fs2netd_reset_connection();
				}

				break;
			}

			case PCKT_DUP_LOGIN_REPLY: {
				ubyte dupe_status = 0;

				PXO_GET_DATA( dupe_status );

				Duplicate_login_detected = (dupe_status != 0);

				break;
			}

			case PCKT_SLIST_REPLY: {
				int numServers = 0;
				int svr_flags;
				ushort svr_port;
				char svr_ip[16];
				active_game ag;

				PXO_GET_USHORT( numServers );

				if (numServers == 0) {
					break;
				}

				for (int i = 0; i < numServers; i++) {
					PXO_GET_INT( svr_flags );
					PXO_GET_USHORT( svr_port );
					PXO_GET_STRING( svr_ip );

					if ( !psnet_is_valid_ip_string(svr_ip) ) {
						ml_printf("FS2NetD SLIST: Invalid ip string (%s)!", svr_ip);
					} else {
						memset( &ag, 0, sizeof(active_game) );

						ag.server_addr.type = NET_TCP;
						ag.server_addr.port = (short) svr_port;

						if (ag.server_addr.port <= 0) {
							ag.server_addr.port = DEFAULT_GAME_PORT;
						}

						psnet_string_to_addr(&ag.server_addr, svr_ip);

						// query this server
						send_server_query(&ag.server_addr);
					}
				}

				break;
			}

			default: {
				break;
			}
		}
	}
}
Exemplo n.º 12
0
static void fs2netd_handle_ping()
{
	static int CONN_check = -1;

	// if we didn't get a pong within 30 seconds of a ping then assume that the
	// server connection must of have dropped or is otherwise unresponsive
	if ( (Ping_timestamp != -1) && ((timer_get_seconds() - Ping_timestamp) > 30) ) {
		Ping_timestamp = -1;

		ml_string("FS2NetD WARNING: Lost connection to server!");
		fs2netd_reset_connection();

		// make sure that we are good to go
		if ( !Is_connected ) {
			if (!Is_standalone) {
				gamesnd_play_iface(SND_GENERAL_FAIL);
				popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_BIG | PF_TITLE_RED, 1, POPUP_OK, "ERROR:\nLost connection to the FS2NetD server!");
			}

			ml_string("FS2NetD ERROR: Lost connection to the FS2NetD server!");

			fs2netd_disconnect();

			ml_string("FS2NetD MSG: Will attempt an automatic reconnect to server in 5 minutes...");
			Login_retry_time = timer_get_seconds() + 300;

			return;
		} else {
			ml_string("FS2NetD NOTICE: Connection to server has been reestablished!");
		}
	}

	// send out a ping after 5 minutes of no other activity to make sure the server
	// is still responding (probably not though)
	if ( (Ping_timestamp == -1) && (timer_get_seconds() >= (Last_activity + 300)) ) {
		Ping_timestamp = timer_get_seconds();
		FS2NetD_Ping();
		ml_string("FS2NetD sent PING");

		if (Last_activity < 0) {
			Last_activity = timer_get_seconds();
		}
	}

	// check for a valid connection (SID, duplicate login, etc.)
	if ( (CONN_check == -1) || (timer_get_seconds() >= CONN_check) ) {
		// every 3 minutes
		CONN_check = timer_get_seconds() + 180;

		// session ID check
		if ( FS2NetD_CheckValidID() < 0 ) {
			ml_string("FS2NetD WARNING: Unable to validate login!");
			fs2netd_reset_connection();

			// make sure that we are good to go
			if ( !Is_connected ) {
				if (!Is_standalone) {
					gamesnd_play_iface(SND_GENERAL_FAIL);
					popup(PF_USE_AFFIRMATIVE_ICON | PF_TITLE_BIG | PF_TITLE_RED, 1, POPUP_OK, "ERROR:\nLost connection to the FS2NetD server!");
				}

				ml_string("FS2NetD ERROR: Lost connection to the FS2NetD server!");

				fs2netd_disconnect();

				ml_string("FS2NetD MSG: Will attempt an automatic reconnect to server in 5 minutes...");
				Login_retry_time = timer_get_seconds() + 300;

				return;
			} else {
				ml_string("FS2NetD NOTICE: Connection to server has been reestablished!");
			}
		}

		// verify that we are only logged in once (for stats saving purposes)
		if ( (Netgame.game_state == NETGAME_STATE_BRIEFING) || (Netgame.game_state == NETGAME_STATE_MISSION_SYNC) ) {
			FS2NetD_CheckDuplicateLogin();
		}

		ml_string("FS2NetD sent IDENT check");
	}
}
Exemplo n.º 13
0
int fs2netd_login_do()
{
	if (Multi_tracker_id < 0) {
		if ( Is_standalone && std_gen_is_active() ) {
			std_gen_set_text("Verifying username and password", 1);
		} else {
			popup_change_text( XSTR("Verifying username and password", 1576) );
		}

		memset(Multi_tracker_id_string, 0, sizeof(Multi_tracker_id_string));

		if (Local_timeout == -1) {
			Local_timeout = timer_get_seconds() + 15;
		}

		// if timeout passes then bail on SID failure
		if ( timer_get_seconds() > Local_timeout ) {
			ml_string("FS2NetD MSG: Login failure due to timeout!");
			Local_timeout = -1;
			return 2;
		}

		const char *user = Multi_tracker_login;
		const char *passwd = Multi_tracker_passwd;

		if (Is_standalone) {
			if ( strlen(Multi_options_g.std_pxo_login) ) {
				user = Multi_options_g.std_pxo_login;
			}

			if ( strlen(Multi_options_g.std_pxo_password) ) {
				passwd = Multi_options_g.std_pxo_password;
			}
		}

		Multi_tracker_id = FS2NetD_Login(user, passwd, do_full_packet);

		// if we have already been through once then only deal with the recieve packet next time
		do_full_packet = false;

		// invalid login
		if (Multi_tracker_id == -2) {
			Multi_tracker_id = -1;
			Local_timeout = -1;
			return 1;
		}

		if (Multi_tracker_id >= 0) {
			ml_printf("FS2NetD MSG: Login '%s' is valid, session ID is %d!", user, Multi_tracker_id);
			do_full_packet = true;
			Local_timeout = -1;
		}
	} else {
		if ( Is_standalone && std_gen_is_active() ) {
			std_gen_set_text("Getting pilot stats", 1);
		} else {
			popup_change_text( XSTR("Getting pilot stats", 1577) );
		}

		if (Local_timeout == -1) {
			Local_timeout = timer_get_seconds() + 30;
		}

		// if timeout passes then bail on stats failure
		if ( timer_get_seconds() > Local_timeout ) {
		
			Local_timeout = -1;
			return 2;
		}

		if (do_full_packet) {
			ml_printf("FS2NetD MSG: Requesting login pilot stats for '%s' ...", Players[Player_num].callsign);
		}

		int rescode = FS2NetD_GetPlayerData(Players[Player_num].callsign, &Players[Player_num], true, do_full_packet);

		do_full_packet = false;

		if ( rescode != -1 ) {
			Local_timeout = -1;
			return (rescode + 3);
		}
	}

	return 0;
}
Exemplo n.º 14
0
int fs2netd_get_valid_missions_do()
{
	if (Local_timeout == -1) {
		Local_timeout = timer_get_seconds() + 30;
	}

	// get the available CRCs from the server if we need to
	if ( FS2NetD_file_list.empty() ) {
		int rc = FS2NetD_GetMissionsList(FS2NetD_file_list, do_full_packet);

		do_full_packet = false;

		// communications error
		if (rc < 0) {
			Local_timeout = -1;
			return 4;
		}

		// no missions
		if ( rc && FS2NetD_file_list.empty() ) {
			Local_timeout = -1;
			return 2;
		}

		// if timeout passes then bail on crc failure
		if ( timer_get_seconds() > Local_timeout ) {
			Local_timeout = -1;
			return 1;
		}
	}
	// we should have the CRCs, or there were no missions, so process them
	else {
		static char **file_names = NULL;
		static int idx = 0, count = 0;

		bool found = false;
		int file_index = 0;
		char valid_status = MVALID_STATUS_UNKNOWN;
		char full_name[MAX_FILENAME_LEN], wild_card[10];
		char val_text[MAX_FILENAME_LEN+15];
		uint checksum = 0;

		if (file_names == NULL) {
			// allocate filename space	
			file_names = (char**) vm_malloc_q( sizeof(char*) * 1024 ); // 1024 files should be safe!

			if (file_names == NULL) {
				Local_timeout = -1;
				return 3;
			}

			memset( wild_card, 0, sizeof(wild_card) );
			strcpy_s( wild_card, NOX("*") );
			strcat_s( wild_card, FS_MISSION_FILE_EXT );

			idx = count = cf_get_file_list(1024, file_names, CF_TYPE_MISSIONS, wild_card);
		}

		// drop idx first thing
		idx--;

		// we should be done validating, or just not have nothing to validate
		if (idx < 0) {
			for (idx = 0; idx < count; idx++) {
				if (file_names[idx] != NULL) {
					vm_free(file_names[idx]);
					file_names[idx] = NULL;
				}
			}

			vm_free(file_names);
			file_names = NULL;

			idx = count = 0;

			Local_timeout = -1;
			return 4;
		}


		// verify all filenames that we know about with their CRCs
		// NOTE: that this is done for one file per frame, since this is inside of a popup
		memset( full_name, 0, MAX_FILENAME_LEN );
		strncpy( full_name, cf_add_ext(file_names[idx], FS_MISSION_FILE_EXT), sizeof(full_name) - 1 );

		memset( val_text, 0, sizeof(val_text) );
		snprintf( val_text, sizeof(val_text) - 1, "Validating:  %s", full_name );

		if (Is_standalone) {
			if ( std_gen_is_active() ) {
				std_gen_set_text(val_text, 1);
			}
		} else {
			popup_change_text(val_text);
		}

		cf_chksum_long(full_name, &checksum);

		// try and find the file
		file_index = multi_create_lookup_mission(full_name);

		found = false;

		if (file_index >= 0) {
			for (SCP_vector<file_record>::iterator fr = FS2NetD_file_list.begin(); fr != FS2NetD_file_list.end() && !found; ++fr) {
				if ( !stricmp(full_name, fr->name) ) {
					if (fr->crc32 == checksum) {
						found = true;
						valid_status = MVALID_STATUS_VALID;
					} else {
						valid_status = MVALID_STATUS_INVALID;
					}

					Multi_create_mission_list[file_index].valid_status = valid_status;
				}
			}

			if (found) {
				ml_printf("FS2NetD Mission Validation: %s  =>  Valid!", full_name);
			} else {
				ml_printf("FS2NetD Mission Validation: %s  =>  INVALID! -- 0x%08x", full_name, checksum);
			}
		}
	}

	return 0;
}