コード例 #1
0
void Model::write_nsr( BinOut &nut, BinOut &uut, Database *db ) {
    if ( not _server_id ) {
        if ( type() != underlying_type() )
            nut << 'n' << get_server_id( db ) << type() << underlying_type();
        else
            nut << 'N' << get_server_id( db ) << type();
        write_usr( nut, uut, db );
    }
}
コード例 #2
0
ファイル: homemap.cpp プロジェクト: Zhanyin/taomee
/*! public fuction */
int handle_homeserv_pkg(homeserv_proto_t* compkg, int len)
{
	KDEBUG_LOG(compkg->id, "HOME OPID\t[%u %u %lu opid=%u %u]", compkg->online_id, get_server_id(), compkg->mapid, compkg->opid, len);
	if (compkg->online_id != get_server_id() 
			|| compkg->opid == SOP_enter_map || (compkg->opid >= 1300 && compkg->opid < 1400)) {
		homeserv_proto_t* svrproto = compkg;
		sprite_info_chg_op(svrproto->id, svrproto->mapid, svrproto->opid, svrproto->body, len - sizeof(homeserv_proto_t ) ,svrproto->ret);
	}
	return 0;
}
コード例 #3
0
ファイル: svr_proto.cpp プロジェクト: Zhanyin/taomee
/**
  * @brief connect to switch and send an init package of online information when online is launched
  */
void connect_to_switch()
{
	DEBUG_LOG("do  connect_to_switch");
	switch_fd = connect_to_service(config_get_strval("service_switch"), 0, 65535, 1);
	if (switch_fd != -1) {
		//连上时
 		is_add_timer_to_connect_switch=false;
	   	static uint32_t seqno = 0;
		sw_report_online_info_in sw_in;
	 	sw_in.domain_id= config_get_intval("domain", 0);
		sw_in.online_id= get_server_id();
		memcpy(sw_in.online_name,get_server_name(),sizeof(sw_in.online_name)); 
		memcpy(sw_in.online_ip,get_server_ip(),sizeof(sw_in.online_ip)); 
		sw_in.online_port=get_server_port();
		sw_in.seqno=seqno;
		g_sprite_map->get_userid_list(sw_in.userid_list);

	 	sw_in.user_num=sw_in.userid_list.size() ;
	
	    ++seqno;
	    send_msg_to_switch(NULL,sw_report_online_info_cmd,0,&sw_in );

		KDEBUG_LOG(0, "BEGIN CONNECTING TO CENTRAL ONLINE AND SEND INIT PKG");
	}else{//
		if(! is_add_timer_to_connect_switch){//还没有加入定时器
			DEBUG_LOG("ADD TIMER connect_switch ");
			g_timer_map->add_timer( TimeVal(3),n_sw_report_online_info,0 );
			is_add_timer_to_connect_switch=true;
		}
	}
}
コード例 #4
0
ファイル: mcast_proto.hpp プロジェクト: Zhanyin/taomee
inline void init_mcast_pkg_head(void* buf, uint32_t major_cmd, uint32_t minor_cmd)
{
	mcast_pkg_t* pkg = reinterpret_cast<mcast_pkg_t *>(buf);
	pkg->server_id = get_server_id(); /* mcast pkg_head id */
	pkg->main_cmd  = major_cmd;
	pkg->minor_cmd = minor_cmd;
}
コード例 #5
0
ファイル: trade.hpp プロジェクト: Zhanyin/taomee
		void init()
		{
			timeval tv = *get_now_tv();
			tv.tv_sec += 1;
			aliveEvent = emgr.add_event(*this, &TradeSvr::keep_trade_alive, tv, 3, -1);
			server_id = get_server_id();
		}
コード例 #6
0
ファイル: pilot.c プロジェクト: Comanche93/eech
void create_client_pilot (void)
{
	client_pilot_request_data
		pilot_data;

	ASSERT (get_comms_model () == COMMS_MODEL_CLIENT);

	//
	// pack required gunship data
	//

	strcpy (pilot_data.name, get_player_log_name (get_current_player_log ()));
	pilot_data.side = get_global_gunship_side ();
	pilot_data.rank = get_player_log_rank (get_global_gunship_side (), get_current_player_log ());
	pilot_data.sub_type = ENTITY_SUB_TYPE_PILOT_PILOT;
	pilot_data.unique_id = direct_play_get_player_id ();
	pilot_data.difficulty = get_global_difficulty_level ();

	//
	// Send request
	//

	send_packet (get_server_id (), PACKET_TYPE_CLIENT_PILOT_REQUEST, (unsigned char *) &pilot_data, sizeof (client_pilot_request_data), SEND_TYPE_PERSONAL);

	// turn off NEXT button while Pilot entity is being created client_server
	if (get_comms_model () == COMMS_MODEL_CLIENT)
	{

		set_display_gunship_buttons (FALSE, "ENGAGE");
	}
}
コード例 #7
0
ファイル: Lst.cpp プロジェクト: hleclerc/Soca
void Lst::write_usr( BinOut &nut, BinOut &uut, Database *db ) {
    for( int i = 0; i < _data.size(); ++i )
        _data[ i ]->write_nsr( nut, uut, db );
    for( int i = 0; i < _data.size(); ++i )
        uut << 'P' << _data[ i ]->_server_id;
    uut << 'U' << get_server_id( db ) << quint32( _data.size() );
}
コード例 #8
0
ファイル: hc_updt.c プロジェクト: DexterWard/comanche
void reset_interpolation_timer (void)
{

	connection_list_type
		*connection;

	if (get_comms_model () == COMMS_MODEL_CLIENT)
	{

		connection = get_connection_list_item (get_server_id ());

		if (connection)
		{

			connection->interpolation_time = get_system_time ();
		}
	}
}
コード例 #9
0
ファイル: reload_conf.cpp プロジェクト: Zhanyin/taomee
/**
  * @brief reload configs
  */
void reload_conf_op(uint32_t cmd, const uint8_t* data, uint32_t datalen)
{
	TRACE_LOG("datalen %u", datalen);
	if (datalen != 4) {
		return;
	}

	uint32_t target_id = 0;
	int idx = 0;
	taomee::unpack_h(data, target_id, idx);
	TRACE_LOG("reload_conf_op target_id %u", target_id);
	if (target_id && target_id != get_server_id()) {
		return;
	}

	switch (cmd) {
	default:
		ERROR_LOG("unsurported cmd %u", cmd);
		break;
	}
}
コード例 #10
0
ファイル: wbclient.c プロジェクト: 0x24bin/winexe-1
/**
 * Initialize the wbclient context, talloc_free() when done.
 *
 * \param mem_ctx talloc context to allocate memory from
 * \param msg_ctx message context to use
 * \param
 */
struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
			     struct messaging_context *msg_ctx,
			     struct tevent_context *event_ctx)
{
	struct wbc_context *ctx;
	NTSTATUS status;

	ctx = talloc(mem_ctx, struct wbc_context);
	if (ctx == NULL) return NULL;

	status = get_server_id(msg_ctx, mem_ctx, &ctx->ids);
	if (!NT_STATUS_IS_OK(status)) {
		talloc_free(ctx);
		return NULL;
	}

	ctx->msg_ctx = msg_ctx;
	ctx->event_ctx = event_ctx;

	return ctx;
}
コード例 #11
0
ファイル: reload_conf.cpp プロジェクト: Zhanyin/taomee
/**
  * @brief reload configs
  */
void reload_conf_op(uint32_t cmd, const uint8_t* data, uint32_t datalen)
{
	DEBUG_LOG("here2");
	if (datalen != 4) {
		return;
	}

	uint32_t target_id = 0;
	int idx = 0;
	taomee::unpack_h(data, target_id, idx);
	if (target_id && target_id != get_server_id()) {
		return;
	}

	switch (cmd) {
	case reload_bench_config_cmd:
		DEBUG_LOG("here");
		reload_bench_conf();
		break;
	default:
		ERROR_LOG("unsurported cmd %u", cmd);
		break;
	}
}
コード例 #12
0
ファイル: server.c プロジェクト: 117311730/PHP
    dest->username = pestrdup(source->username, persist);
    dest->password = pestrdup(source->password, persist);
    dest->db = pestrdup(source->db, persist);
  }

  mongo_util_pool_get(dest, 0 TSRMLS_CC);

  return dest;
}

int mongo_util_server_cmp(char *host1, char *host2 TSRMLS_DC) {
  char *id1 = 0, *id2 = 0;
  int result = 0;
  zend_rsrc_list_entry *le1 = 0, *le2 = 0;

  id1 = get_server_id(host1);
  id2 = get_server_id(host2);

  if (zend_hash_find(&EG(persistent_list), id1, strlen(id1)+1, (void**)&le1) == SUCCESS &&
      zend_hash_find(&EG(persistent_list), id2, strlen(id2)+1, (void**)&le2) == SUCCESS &&
      ((server_info*)le1->ptr)->guts == ((server_info*)le2->ptr)->guts) {
    mongo_log(MONGO_LOG_SERVER, MONGO_LOG_INFO TSRMLS_CC, "server: detected that %s is the same server as %s",
              host1, host2);
    // result is initialized to 0
  }
  else {
    result = strcmp(id1, id2);
  }

  efree(id1);
  efree(id2);
コード例 #13
0
ファイル: hc_updt.c プロジェクト: DexterWard/comanche
void interpolate_entity_position (entity *en)
{

	vec3d
		new_position,
		*motion_vector,
		*position;

	connection_list_type
		*connection;

	float
		delta_time;

	if ((!command_line_comms_interpolate_gunships) || (get_local_entity_int_value (en, INT_TYPE_LANDED)))
	{

		return;
	}

	position = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION);

	motion_vector = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_MOTION_VECTOR);

	if (get_comms_model () == COMMS_MODEL_CLIENT)
	{

		connection = get_connection_list_item (get_server_id ());
	}
	else
	{

		connection = get_gunships_connection_list_item (en);
	}

	if (connection)
	{
	
		delta_time = (float) (get_system_time () - connection->interpolation_time) / TIME_1_SECOND;
	
		new_position.x = position->x + motion_vector->x * delta_time;
		new_position.y = position->y + motion_vector->y * delta_time;
		new_position.z = position->z + motion_vector->z * delta_time;
	
		set_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &new_position);
						
		if (get_comms_model () == COMMS_MODEL_SERVER)
		{

			connection->interpolation_time = get_system_time ();
		}

		#if DEBUG_MODULE
	
		debug_log ("SERVER: interpolating entity %s (%d) old [%f, %f, %f], new [%f, %f, %f], motion_vector [%f, %f, %f], deltatime %f",
						get_local_entity_string (en, STRING_TYPE_FULL_NAME),
						get_local_entity_index (en),
						position->x, position->y, position->z,
						new_position.x, new_position.y, new_position.z,
						motion_vector->x, motion_vector->y, motion_vector->z,
						delta_time);

		#endif
	}
}
コード例 #14
0
ファイル: comm_man.c プロジェクト: DexterWard/comanche
void comms_process_data (void)
{

	session_list_data_type
		*current_session;

	connection_list_type
		*this_connection,
		*connection;

	char
		*received_data;

	int
		planner_event,
		frame_id,
		packet_id,
		receive_flag,
		received_size;

	GUID
		received_id = 0;

	entity
		*member;

	send_types
		send_type;

	packet_types
		type;

	// receive all packets in queue

	current_session = get_current_game_session ();

	received_size = MAX_RECEIVE_SIZE;

	connection = get_connection_list_head ();

	while (connection)
	{

		this_connection = connection;

		connection = connection->next;

		send_type = SEND_TYPE_GROUP;

		while (send_type >= SEND_TYPE_PERSONAL)
		{

			receive_flag = TRUE;

			while (receive_flag)
			{

				type = process_packet_list (send_type, this_connection, &received_id, &received_data, &received_size);

				switch (type)
				{

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// System packets, used internally
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_INVALID:
					{

						receive_flag = FALSE;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							if (this_connection->packet_rerequested > command_line_comms_packet_rerequest_limit)
							{

								debug_log ("COMM_MAN: REJECTING CONNECTION. CONNECTION TOO BAD (re-request limit %d reached)", command_line_comms_packet_rerequest_limit);

								send_packet (this_connection->connection_id, PACKET_TYPE_SERVER_REJECTED, NULL, 0, SEND_TYPE_PERSONAL);
							}
						}

						break;
					}

					case PACKET_TYPE_RESEND_PACKET:
					{

						send_types
							resend_send_type;

						frame_id = get_list_item (received_data, int);

						packet_id = get_list_item (received_data, int);

						resend_send_type = get_list_item (received_data, send_types);

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received RESEND PACKET for frame %d packet %d from %s (dpid %d)",
											frame_id, packet_id,
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: received RESEND PACKET by unknown (pdid %d)",
											received_id);
						}

						#endif

						resend_packet (received_id, frame_id, packet_id, resend_send_type);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// Packets for initialisation and joining
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_SESSION_QUERY:
					{

						char
							*ptr;

						int
							server_version_number,
							player_count,
							size;

						connection_list_type
							*new_connection;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %d", received_id);
							}

							#endif

							new_connection = get_connection_list_item (received_id);

							if (!new_connection->already_sent_query_data)
							{

								new_connection->already_sent_query_data = TRUE;

								while (TRUE)
								{

									ptr = new_connection->connection_receive_buffer;

									size = 0;

									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									//
									// Check both client and server are running same campaign data
									//
									server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

									quick_set_list_item (ptr, int, server_version_number);

									size += sizeof (int);
									//
									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

									// map details

									quick_set_list_item (ptr, int, NUM_MAP_X_SECTORS);

									quick_set_list_item (ptr, int, NUM_MAP_Z_SECTORS);

									quick_set_list_item (ptr, int, SECTOR_SIDE_LENGTH);

									size += sizeof (int) * 3;

									// data path

									strcpy (ptr, current_session->data_path);

									ptr += strlen (current_session->data_path) + 1;

									size += strlen (current_session->data_path) + 1;

									// population_placement filename

									if (population_placement_filename)
									{

										strcpy (ptr, population_placement_filename);

										ptr += strlen (population_placement_filename) + 1;

										size += strlen (population_placement_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//

									// side_data filename

									if (side_data_filename)
									{

										strcpy (ptr, side_data_filename);

										ptr += strlen (side_data_filename) + 1;

										size += strlen (side_data_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									// campaign_population filename

									if (campaign_population_filename)
									{

										strcpy (ptr, campaign_population_filename);

										ptr += strlen (campaign_population_filename) + 1;

										size += strlen (campaign_population_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//
									// planner position and zoom
									//

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_x);

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_z);

//									size += sizeof (float) * 2;

//									quick_set_list_item (ptr, int, planner_map_data.map_zoom);

//									size += sizeof (int);

									//
									// Pilots
									//

									player_count = get_number_of_connected_players ();

									quick_set_list_item (ptr, int, player_count);

									size += sizeof (int);

									//
									//
									//

									#if DEBUG_MODULE

									debug_log ("COMM_MAN: sending data path %s, population placement %s, side data %s, campaign_pop file %s",
													current_session->data_path, population_placement_filename, side_data_filename, campaign_population_filename);

									#endif

									new_connection->connection_receive_buffer_size -= size;

									if (!pack_session (ptr, &new_connection->connection_receive_buffer_size, PACK_MODE_BROWSE_SESSION))
									{

										break;
									}

									new_connection->connection_receive_buffer_size *= 2;

									#if DEBUG_MODULE

									debug_log ("COMMS MAN: Browse: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

									#endif

									free_mem (new_connection->connection_receive_buffer);

									new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);
								}

								//
								//
								//

								send_packet (received_id, PACKET_TYPE_SESSION_INFO, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size + size, SEND_TYPE_PERSONAL);

								/*
								{

									FILE
										*test_ptr;

									test_ptr = fopen ("out.txt", "wb");

									fwrite (new_connection->connection_receive_buffer, 1, new_connection->connection_receive_buffer_size + size, test_ptr);

									fclose (test_ptr);
								}
								*/
							}
							else
							{

								debug_log ("COMM_MAN: not resending query data");
							}
						}

						break;
					}

					case PACKET_TYPE_CONNECTION_VALIDATION:
					{

						debug_log ("COMM_MAN: received CONNECTION_VALIDATION, sending RESPONSE");

						send_packet (received_id, PACKET_TYPE_CONNECTION_RESPONSE, NULL, 0, SEND_TYPE_PERSONAL);

						break;
					}

					case PACKET_TYPE_CONNECTION_RESPONSE:
					{

						connection_list_type
							*connection;

						connection = get_connection_list_item (received_id);

						connection->validation_count = 0;

						debug_log ("COMM_MAN: received CONNECTION_RESPONSE, connection still alive");

						break;
					}

					case PACKET_TYPE_SESSION_INFO:
					{

						entity
							*force,
							*pilot;

						int
							client_version_number,
							server_version_number;

						int
							size,
							x_size,
							z_size,
							sector_size,
							player_count,
							loop;

						char
							*ptr,
							warzone_ffp_filename [256],
							temp_campaign_population_filename [256],
							temp_population_placement_filename [256],
							temp_side_data_filename [256],
							buffer [128];

						session_data = FALSE;

						reinitialise_entity_system ();

						ptr = received_data;

						size = 0;

						set_ui_object_redraw (gunships_screen, TRUE);

						ui_force_update ();

						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
						//
						// Check both client and server are running same campaign data
						//
						client_version_number = get_global_version_number ();

						server_version_number = get_list_item (ptr, int);

						size += sizeof (int);

						if (client_version_number != server_version_number)
						{

							debug_fatal ("COMM_MAN: Incorrect version. Server Version No. %d, Client Version No. %d", server_version_number, client_version_number);
						}
						//
						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

						// map details

						x_size = get_list_item (ptr, int);

						z_size = get_list_item (ptr, int);

						sector_size = get_list_item (ptr, int);

						size += (sizeof (int) * 3);

						set_entity_world_map_size (x_size, z_size, sector_size);

						// data path

						strncpy (current_session->data_path, ptr, sizeof (current_session->data_path));

						ptr += strlen (current_session->data_path) + 1;

						size += strlen (current_session->data_path) + 1;

						// population_placement_filename

						strncpy (temp_population_placement_filename, ptr, sizeof (temp_population_placement_filename));

						ptr += strlen (temp_population_placement_filename) + 1;

						size += strlen (temp_population_placement_filename) + 1;

						if (population_placement_filename)
						{

							free_mem (population_placement_filename);
						}

						if (strlen (temp_population_placement_filename) > 0)
						{

							population_placement_filename = (char *) malloc_heap_mem (strlen (temp_population_placement_filename) + 1);

							sprintf (population_placement_filename, "%s", temp_population_placement_filename);
						}
						else
						{

							population_placement_filename = NULL;
						}

						// side_data filename

						strncpy (temp_side_data_filename, ptr, sizeof (temp_side_data_filename));

						ptr += strlen (temp_side_data_filename) + 1;

						size += strlen (temp_side_data_filename) + 1;

						if (side_data_filename)
						{

							free_mem (side_data_filename);
						}

						if (strlen (temp_side_data_filename) > 0)
						{

							side_data_filename = (char *) malloc_heap_mem (strlen (temp_side_data_filename) + 1);

							sprintf (side_data_filename, "%s", temp_side_data_filename);
						}
						else
						{

							side_data_filename = NULL;
						}

						// campaign_population_filename

						strncpy (temp_campaign_population_filename, ptr, sizeof (temp_campaign_population_filename));

						ptr += strlen (temp_campaign_population_filename) + 1;

						size += strlen (temp_campaign_population_filename) + 1;

						if (campaign_population_filename)
						{

							free_mem (campaign_population_filename);
						}

						if (strlen (temp_campaign_population_filename) > 0)
						{

							campaign_population_filename = (char *) malloc_heap_mem (strlen (temp_campaign_population_filename) + 1);

							sprintf (campaign_population_filename, "%s", temp_campaign_population_filename);
						}
						else
						{

							campaign_population_filename = NULL;
						}

						//
						//
						//

						player_count = get_list_item (ptr, int);

						size += sizeof (int);

						//
						//
						//

						received_size -= size;

						#if DEBUG_MODULE

						debug_log ("COMM_MAN: data path %s population placement filename %s, side data filename %s", current_session->data_path, population_placement_filename, side_data_filename);

						debug_log ("COMM_MAN: campaign data path = %s", current_session->data_path);

						#endif

						//
						// check we have the correct warzone locally
						//

						sprintf (warzone_ffp_filename, "%s\\terrain\\terrain.ffp", current_session->data_path);

						if (!file_exist (warzone_ffp_filename))
						{

							add_to_pop_up_list_with_word_wrap (get_trans ("UNRECOGNISED_WARZONE"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);
							//add_to_pop_up_list (get_trans ("Server using unrecognised warzone"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

							break;
						}

						//
						//
						//

						create_local_only_entities (PACK_MODE_BROWSE_SESSION);

						if (unpack_session (ptr, received_size, PACK_MODE_BROWSE_SESSION))
						{

							debug_fatal ("COMMS MAN: browse: received size overflow");
						}

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received SESSION INFO from %s (dpid %d) (setting server id)",
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: RECEIVED SESSION INFO from %d", received_id);
						}

						debug_log ("COMMS MAN: session info: time of day = %f",
										get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_TIME_OF_DAY));

						debug_log ("COMMS MAN: map dimensions %d, %d, sector size %d", x_size, z_size, sector_size);

						#endif

						set_ui_object_drawable (session_screen_next_button, TRUE);

						//
						// Display game info
						//

						ui_object_destroy_list_items (session_info_list);

						if (get_local_entity_int_value (get_session_entity (), INT_TYPE_CAMPAIGN_REQUIRES_APACHE_HAVOC))
						{

							// campaign requires apache havoc to be installed
							// check it is...

							if (!get_global_apache_havoc_installed ())
							{

								add_to_pop_up_list_with_word_wrap (get_trans ("REQUIRES_APACHE_HAVOC"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

								set_ui_object_drawable (session_screen_next_button, FALSE);

								break;
							}
						}

						loop = 3;

						sprintf (buffer, "%s : %d", get_trans ("Players"), player_count);

						add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							pilot = get_local_entity_first_child (force, LIST_TYPE_PILOT);

							while (pilot)
							{
								{
									rgb_colour
										col;

									sprintf (buffer, "%2d  ", loop - 2);

									strncat (buffer, get_local_entity_string (pilot, STRING_TYPE_PILOTS_NAME), 64);

									switch (get_local_entity_int_value (pilot, INT_TYPE_SIDE))
									{
										case ENTITY_SIDE_BLUE_FORCE:
										{
											col.r = 120;
											col.g = 158;
											col.b = 255;
											col.a = 255;

											break;
										}
										case ENTITY_SIDE_RED_FORCE:
										{
											col.r = 255;
											col.g = 120;
											col.b = 80;
											col.a = 255;

											break;
										}
										default:
										{
									      col = ui_colour_white;

											break;
										}
									}

									add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, col);

									loop ++;
								}

								pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
							}

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

						set_server_id (received_id);

						//
						// destroy all entities created by browse info
						//

						reinitialise_entity_system ();

						break;
					}

					case PACKET_TYPE_CLIENT_PILOT_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_pilot_request_data
							pilot_data;

						entity
							*new_pilot;

						int
							index;

						ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: RECEIVED PILOT REQUEST from %d", received_id);

//						#endif

						//
						// unpack name
						//

						memcpy (&pilot_data, (client_pilot_request_data *) received_data, sizeof (client_pilot_request_data));

						new_pilot = create_new_pilot_entity
										(
											pilot_data.name,
											pilot_data.side,
											pilot_data.rank,
											pilot_data.sub_type,
											pilot_data.unique_id,
											pilot_data.difficulty
										);

						ASSERT (new_pilot);

						index = get_local_entity_safe_index (new_pilot);

						new_connection = get_connection_list_item (received_id);

						transmit_entity_comms_message (ENTITY_COMMS_PILOT_REQUEST_ACCEPTED, NULL, received_id, index);

						new_connection->pilot_entity = new_pilot;

						break;
					}

					case PACKET_TYPE_CLIENT_GUNSHIP_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_gunship_request_data
							pilot_data;

						int
							index_number,
							buffer [2];

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

//							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %d", received_id);
							}

//							#endif

							memcpy (&pilot_data, (client_gunship_request_data *) received_data, sizeof (client_gunship_request_data));

							index_number = pilot_data.gunship_index;

							ASSERT (index_number != ENTITY_INDEX_DONT_CARE);

							member = get_local_entity_safe_ptr (index_number);

							if (!member)
							{
//								#if DEBUG_MODULE

								if (this_connection->pilot_entity)
								{

									debug_log ("COMMS MAN: REFUSING GUNSHIP FOR PLAYER %s (dpid %d) for helicopter %d",
													get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
													received_id, pilot_data.gunship_index);
								}
								else
								{

									debug_log ("COMMS MAN: Refusing gunship for player %d to helicopter %d", received_id, pilot_data.gunship_index);
								}

//								#endif

								send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_REFUSED, NULL, 0, SEND_TYPE_PERSONAL);

								break;
							}

							new_connection = get_connection_list_item (received_id);

							//
							// send acceptance
							//

							buffer [0] = index_number;

//							#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending gunship request accepted for gunship %d pilot id %d", index_number, received_id);

//							#endif

							send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED, (void *) &buffer, 4, SEND_TYPE_PERSONAL);

							new_connection->gunship_number = pilot_data.gunship_index;

							new_connection->gunship_entity = member;
						}

						break;
					}

					case PACKET_TYPE_CLIENT_CAMPAIGN_DATA_REQUEST:
					{

						connection_list_type
							*new_connection;

						int
							index_number;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED JOIN REQUEST by %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: received JOIN REQUEST by %d", received_id);
							}

							#endif

							//
							// flush group send buffer
							//

							send_comms_data ();

							//
							// pack mission data into packet
							//

							new_connection = get_connection_list_item (received_id);

							//
							// Store entity data
							//

							while (pack_session (new_connection->connection_receive_buffer, &new_connection->connection_receive_buffer_size, PACK_MODE_CLIENT_SESSION))
							{

								new_connection->connection_receive_buffer_size *= 2;

								#if DEBUG_MODULE

								debug_log ("COMMS MAN: Mission data: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

								#endif

								free_mem (new_connection->connection_receive_buffer);

								new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);

								memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);
							}

							// add frame id
							index_number = get_group_frame_id ();
							memcpy (&new_connection->connection_receive_buffer [new_connection->connection_receive_buffer_size], (void *) &index_number, sizeof (int));
							new_connection->connection_receive_buffer_size += sizeof (int);

							send_packet (received_id, PACKET_TYPE_MISSION_DATA, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size, SEND_TYPE_PERSONAL);

							memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);

							//
							// send group frame id
							//

							SDL_Delay (100);

							index_number = get_group_frame_id ();

							//send_packet (received_id, PACKET_TYPE_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

							zero_average_pack_size ();
						}

						break;
					}

					case PACKET_TYPE_CLIENT_FRAME_ID:
					{

						int
							loop1,
							loop2,
							index_number;

						stub_packet_type
							*stub_packet;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						new_connection = get_connection_list_item (received_id);

						//#if DEBUG_MODULE

						if (new_connection)
						{

							debug_log ("COMMS MAN: received CLIENT FRAME ID (%d) by %d %s", index_number, received_id, direct_play_get_player_name (received_id));
						}

						//#endif

						//
						// send all packets between when the client started to join and when it actually joined.
						//

						for (loop1 = index_number; loop1 < get_group_frame_id () - 1; loop1 ++)
						{

							//#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, 0);

							//#endif

							stub_packet = resend_packet (received_id, loop1, 1, SEND_TYPE_GROUP);

							ASSERT (stub_packet);

							for (loop2 = 2; loop2 <= stub_packet->packet->number_of_packets; loop2 ++)
							{

								//#if DEBUG_MODULE

								debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, loop2);

								//#endif

								stub_packet = resend_packet (received_id, loop1, loop2, SEND_TYPE_GROUP);
							}
						}

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_REFUSED:
					{

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: Gunship refused");

//						#endif

						set_server_response (SERVER_RESPONSE_REFUSE);

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED:
					{

						entity
							*gunship;

						int
							index_number;

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received GUNSHIP ACCEPTED by %d", received_id);

//						#endif

						//
						// set gunship
						//

						index_number = get_list_item (received_data, int);

						ASSERT (get_pilot_entity ());

						gunship = get_local_entity_safe_ptr (index_number);

						debug_filtered_log ("COMM_MAN: setting gunship");

						planner_event = FALSE;

						if (get_event_stack_head_function() == ingame_screen_set_events)
						{

							pop_event (ingame_screen_set_events);

							planner_event = TRUE;
						}

						assign_entity_to_user (gunship);

						if (planner_event)
						{

							push_event (ingame_screen_set_events, "ingame screen events");
						}

						debug_filtered_log ("COMM_MAN: gunship set");

						////////////////////////////////////////////////////////////////////////

						break;
					}

					case PACKET_TYPE_PILOT_REQUEST_ACCEPTED:
					{

						int
							index_number;

						ASSERT (get_comms_model () == COMMS_MODEL_CLIENT);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received PILOT ACCEPTED by %d", received_id);

//						#endif

						index_number = get_list_item (received_data, int);

						set_pilot_entity (get_local_entity_safe_ptr (index_number));

						break;
					}

					case PACKET_TYPE_MISSION_DATA:
					{

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received MISSION DATA by %d", received_id);

						#endif

						set_mouse_graphic_off ();

						//
						// LOAD TERRAIN DATA
						//

						load_3d_terrain_game_data ();

						initialise_population_name_database ();

						load_route_data (); // might need to send what route filename to load...

						//
						// Initialise stuff
						//

						create_local_only_entities (PACK_MODE_CLIENT_SESSION);

						/////////////////////////////////////////////////////////////////
						if (strstr ((char*) stoupper (side_data_filename), "SID"))
						{

							read_sector_side_file (side_data_filename);
						}
						else if (strstr ((char*) stoupper (side_data_filename), "DAT"))
						{

							load_ai_sector_data (side_data_filename);
						}
						/////////////////////////////////////////////////////////////////

						deinitialise_formation_database ();

						initialise_formation_database ();

						deinitialise_formation_component_database ();

						initialise_formation_component_database ();

						if (unpack_session (received_data, received_size - 4, PACK_MODE_CLIENT_SESSION))
						{

							debug_fatal ("COMMS MAN: received size overflow");
						}
/*
						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							create_frontline (force);

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

*/
						{
							int
								index_number;

							connection_list_type
								*new_connection;

							received_data += received_size - 4;
							index_number = get_list_item (received_data, int);

							new_connection = get_connection_list_item (received_id);

							new_connection->receive_group_frame_id = index_number;

							send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);
						}

						session_data = TRUE;

						//direct_play_join_group ();

						set_gunship_waiting_for_connection ( FALSE );

						zero_average_pack_size ();

						set_mouse_graphic_on ();

						break;
					}

					case PACKET_TYPE_FRAME_ID:
					{

						int
							index_number;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received FRAME ID (%d) by %d", index_number, received_id);

						#endif

						new_connection = get_connection_list_item (received_id);

						new_connection->receive_group_frame_id = index_number;

						send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// In game packets
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_AI_DATA:
					{

						int
							//padding,
							data_size;

						#if DEBUG_MODULE >= 2

						debug_log ("COMMS MAN: received AI DATA by %d", received_id);

						#endif

						if (get_comms_model () == COMMS_MODEL_CLIENT)
						{

							ASSERT (session_data);
						}

						data_size = get_list_item (received_data, int);

						//debug
						//padding = get_list_item (received_data, int);
						//end

						open_unpack_buffer (received_data, received_size);

						process_received_entity_comms_messages ();

						ASSERT (!get_unpack_buffer_overflow ());

						close_unpack_buffer ();

						//debug
						//padding = get_list_item (received_data, int);
						//end

						memset (received_data, 0, this_connection->connection_receive_buffer_size);

						break;
					}

					case PACKET_TYPE_END_GAME:
					{

						debug_log ("COMMS MAN: received END GAME from %d", received_id);

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{
							if (this_connection->gunship_entity)
							{

								set_client_server_entity_int_value (this_connection->gunship_entity, INT_TYPE_PLAYER, ENTITY_PLAYER_AI);
							}

							if (this_connection->pilot_entity)
							{

								debug_log ("	from %s ", get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME));
							}

							unregister_connection (received_id);
						}
						else
						{

							if (received_id == get_server_id ())
							{

								//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_STALEMATE);

								start_game_exit (GAME_EXIT_KICKOUT, FALSE);
							}
						}

						receive_flag = FALSE;

						break;
					}

					case PACKET_TYPE_SERVER_REJECTED:
					{

						debug_log ("COMMS MAN: received SERVER REJECTED (server id %d)", received_id);

						//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_SERVER_REJECTED);

						start_game_exit (GAME_EXIT_KICKOUT, FALSE);

						break;
					}

					default:
					{

						debug_fatal ("ERROR: Data Exchange, unknown packet type %d", type);

						break;
					}
				}
			}

			send_type --;
		}
	}
}
コード例 #15
0
int main() {

    // create thread as 'joinable'
    pthread_attr_t tattr;
    pthread_attr_init(&tattr);
    pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);

    // set thread cancel state and type
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

    int i = 0;
    char buffer[1024] = "";

    if (check_process_lock()) exit(1);

    // read database configuration
    if (read_config()) {
        exit(1);
    }

    // connect to database
    if (db_connect(&mysql, dbhost, dbuser, dbpass, dbname, dbport, NULL, 0) == 1) {
        exit(1);
    }

    // try another location
    if (get_server_id(SERVERCONFPATH)) {
        mor_log("Cannot read server configuration from: " SERVERCONFPATH " or server_id is not set", 0);
        exit(1);
    }

    // just to be sure
    if (server_id == 0) {
        mor_log("server_id is not set", 0);
        exit(1);
    }

    // starting sript
    mor_log("Starting Provider Check script", 1);

    // get provider data
    mor_log("Fetching provider data from database", 0);
    if (get_providers()) {
        exit(1);
    }

    if (prov_count == 0) {
        mor_log("No suitable providers were found", 0);
        exit(1);
    }

    mor_log("Checking provider availability", 0);
    for (i = 0; i < prov_count; i++) {

        prov_status = 0;

        pthread_create(&timeout, &tattr, timeout_thread, NULL);
        pthread_create(&pcheck, NULL, check_provider_status_thread, (void *)(intptr_t)i);
        pthread_join(timeout, NULL);

        if (prov_status == 0) {
            printf("Updating provider: [%d] %s:%d ALIVE = 0\n", prov[i].id, prov[i].server_ip, prov[i].port);
            sprintf(buffer, "Updating provider: [%d] %s:%d ALIVE = 0", prov[i].id, prov[i].server_ip, prov[i].port);
            mor_log(buffer, 0);
            if (update_provider_status(i, 0)) {
                exit(1);
            }
        } else {
            printf("Updating provider: [%d] %s:%d ALIVE = 1\n", prov[i].id, prov[i].server_ip, prov[i].port);
            sprintf(buffer, "Updating provider: [%d] %s:%d ALIVE = 1", prov[i].id, prov[i].server_ip, prov[i].port);
            mor_log(buffer, 0);
            if (update_provider_status(i, 1)) {
                exit(1);
            }
        }

    }

    unlink(TMP_FILE);

    return 0;

}
コード例 #16
0
ファイル: mole2_online.cpp プロジェクト: Zhanyin/taomee
int  init_service(int isparent)
{

	if (!isparent) {

        DEBUG_LOG("INIT_SERVICE");
	    const char *ip= get_ip_ex(0x01);
	    if ( strncmp( ip,"10.",3 )==0 ) {
	        g_is_test_env=true;
			DEBUG_LOG("=============TEST ENV TRUE =============");
	    }else{
	        g_is_test_env=false;
			DEBUG_LOG("=============TEST ENV FALSE =============");
	    }

		g_log_send_buf_hex_flag=g_is_test_env?1:0;
	



		if (sizeof(sprite_t) >= SPRITE_STRUCT_LEN - 800 || sizeof(grp_loop_t) != VIP_BUFF_LEN) {
			ERROR_RETURN(("sprite struct not big enough\t[%lu %u]", sizeof(sprite_t), SPRITE_STRUCT_LEN), -1);
		}
		srand(time(0) * get_server_id());
		setup_timer();
		INIT_LIST_HEAD(&(g_events.timer_list));
		INIT_LIST_HEAD(&active_box_list);
		if ( config_get_strval("_use_lua_config") ==NULL  ){
			config_init("./conf/common.conf");
		}

		statistic_logfile = config_get_strval("statistic_file");
		if (!statistic_logfile)
			return -1;
		if ((init_cli_proto_handles(0) == -1)	|| 
			(init_db_proto_handles(0) == -1)		||
			(init_home_handle_funs() == -1)		||
			(init_switch_handle_funs() == -1)		||
			(init_all_timer_type() == -1)			||
			(init_magic_code_proto_handles(0) == -1) ||
			(init_spacetime_code_proto_handles(0) == -1) ||
			(init_mall_proto_handles(0) == -1)
			) {
			return -1;
		}
		init_sprites();
		init_exp_lv();
		init_home_maps();
		init_all_items();
		init_beast_grp();
		init_rand_infos();
		init_npcs();
		init_all_skills();
		init_all_clothes();
		init_sys_info();
		init_all_tasks();
		init_mail();
		init_shops();
		init_vip_items();
		init_products();

		idc_type = config_get_intval("idc_type" ,1);
		KDEBUG_LOG(0, "ONLINE START\t[%lu %d]", sizeof(sprite_t), idc_type);

		if (
			//11
			(load_xmlconf("./conf/items.xml", load_items) == -1)
			|| (load_xmlconf("./conf/clothes.xml", load_clothes) == -1)
			|| (load_xmlconf("./conf/beasts.xml", load_beasts) == -1)
			//
			|| (load_xmlconf("./conf/pet_exchange.xml", load_pet_exchange) == -1)//3M
			|| (load_xmlconf("./conf/pet_exchange_egg.xml", load_pet_exchange_egg) == -1)
			//62
			|| (load_xmlconf("./conf/gplan.xml", load_rare_beasts) == -1)
			|| (load_xmlconf("./conf/titles.xml", load_honor_titles) == -1)
			|| (load_xmlconf("./conf/picsrv.xml", load_picsrv_config) == -1)
			) {
			return -1;
		}
		if (
				load_xmlconf("./conf/beastgrp.xml", load_beast_grp) == -1 
				|| (load_xmlconf("./conf/handbook.xml", load_handbook) == -1)
				|| (load_xmlconf("./conf/suits.xml", load_suit) == -1)
				|| ( load_xmlconf("./conf/maps.xml", load_maps) == -1)
				|| (load_xmlconf("./conf/rand_item.xml", load_rand_item) == -1)
				|| (load_xmlconf("./conf/vip_item.xml", load_vip_item) == -1)
				|| (load_xmlconf("./conf/commodity.xml", load_products) == -1)
				|| (load_xmlconf("./conf/skills_price.xml", load_all_skills) == -1)
				|| (load_xmlconf("./conf/tasks_new.xml", load_tasks) == -1)//task:12M
				|| (load_xmlconf("./conf/tasks_new.xml", load_task_loops) == -1)
				|| (load_xmlconf("./conf/holiday.xml", load_holiday_factor) == -1)
				|| (load_xmlconf("./conf/box.xml", load_box) == -1)
				|| (load_xmlconf("./conf/exchanges.xml", load_exchange_info) == -1)
				|| (load_xmlconf("./conf/npc.xml", load_npc) == -1)
				|| (load_xmlconf("./conf/npcSkills.xml", load_shop_skill) == -1)
				|| (load_xmlconf("./conf/npcShop.xml", load_shop_item) == -1)
				|| (load_xmlconf("./conf/mail.xml", load_sys_mail) == -1)
				|| (load_xmlconf("./conf/sysinfo.xml", load_sys_info) == -1)
				|| (load_xmlconf("./conf/fishGame.xml", load_fish_info) == -1)
				|| (load_xmlconf("./conf/professtion.xml", load_init_prof_info) == -1)
				|| (load_xmlconf("./conf/maze.xml", load_maze_xml) == -1)
				|| (load_xmlconf("./conf/mapcopy.xml", load_map_copy) == -1)
			)

			return -1;

	//	sleep(1000);
		activate_boxes();
		start_maze_timer();

		/*
		if(tm_load_dirty("./data/tm_dirty.dat") < 0){
			KERROR_LOG(0, "Failed to load drity word file!");
			return -1;
		}
		*/
		
		init_batter_teams();
		init_batter_infos();
		connect_to_switch_timely(0, 0);
		regist_timers();
		udp_report_fd = create_udp_socket(&udp_report_addr, config_get_strval("report_svr_ip"), config_get_intval("report_svr_port", 0));
		udp_post_fd = create_udp_socket(&udp_post_addr, config_get_strval("post_svr_ip"), config_get_intval("post_svr_port", 0));
		switch (idc_type) {
		case idc_type_dx:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("dx_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		case idc_type_wt:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("wt_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		case idc_type_internal:
		case idc_type_internal + 1:
			chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("in_chat_svr_ip"), config_get_intval("chat_svr_port", 0));
			break;
		default:
			return -1;
		}
	}

	return 0;
}