コード例 #1
0
ファイル: multiplayer.c プロジェクト: BackupTheBerlios/bmc
void process_message_from_server(unsigned char *in_data, int data_lenght)
{
	//see what kind of data we got
	switch (in_data[PROTOCOL])
		{
		case RAW_TEXT:
			{
				// do filtering and ignoring
				data_lenght=filter_or_ignore_text(&in_data[3],data_lenght-3)+3;
				if(data_lenght > 3)
					{
						//how to display it
						if(interface_mode!=interface_opening)
							put_text_in_buffer(&in_data[3],data_lenght-3,0);
						else put_text_in_buffer(&in_data[3],data_lenght-3,54);
						//lets log it
						write_to_log(&in_data[3],data_lenght-3);
					}
			}
			break;
		
		case SMALL_WINDOW_TEXT:
			{
				add_text_to_small_text_buffer(in_data+3, data_lenght-3);
				display_small_text_window();
			}
			break;

		case ADD_NEW_ACTOR:
			{
				add_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_NEW_ENHANCED_ACTOR:
			{
				add_enhanced_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_ACTOR_COMMAND:
			{
				add_command_to_actor(*((short *)(in_data+3)),in_data[5]);
			}
			break;

		case REMOVE_ACTOR:
			{
				destroy_actor(*((short *)(in_data+3)));
			}
			break;

		case KILL_ALL_ACTORS:
			{
				destroy_all_actors();
			}
			break;

		case NEW_MINUTE:
			{
				game_minute=*((short *)(in_data+3));
				new_minute();
			}
			break;

		case LOG_IN_OK:
			{
				interface_mode=interface_game;
				previously_logged_in=1;
			}
			break;

		case HERE_YOUR_STATS:
			{
				get_the_stats((Sint16 *)(in_data+3));
			}
			break;

		case SEND_PARTIAL_STAT:
			{
				get_partial_stat(*((Uint8 *)(in_data+3)),*((Sint32 *)(in_data+4)));
			}
			break;

		case GET_KNOWLEDGE_LIST:
			{
				get_knowledge_list(*(Uint16 *)(in_data+1)-1, in_data+3);
			}
			break;

		case GET_NEW_KNOWLEDGE:
			{
				get_new_knowledge(*(Uint16 *)(in_data+3));
			}
			break;

		case HERE_YOUR_INVENTORY:
			{
				get_your_items(in_data+3);
			}
			break;

		case GET_NEW_INVENTORY_ITEM:
			{
				get_new_inventory_item(in_data+3);
			}
			break;

		case REMOVE_ITEM_FROM_INVENTORY:
			{
				remove_item_from_inventory(*((Uint8 *)(in_data+3)));
			}
			break;

		case INVENTORY_ITEM_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+100,items_string);
				if(!(get_show_window(items_win)||get_show_window(trade_win)))
					{
						put_text_in_buffer(&in_data[3],data_lenght-3,0);
					}
			}
			break;

		case GET_KNOWLEDGE_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+150,knowledge_string);
			}
			break;

		case CHANGE_MAP:
			{
				current_sector=-1;
				if(map_file_name[0]!=0)
					save_map(map_file_name);
				object_under_mouse=-1;//to prevent a nasty crash, while looking for bags, when we change the map
				close_dialogue();	// close the dialogue window if open
				destroy_all_particles();

				if(!load_map(&in_data[4])){ // creating map if it does not exist
					int size=(in_data[3]&0x1f)<<4;
					new_map(size,size);
					dungeon=(in_data[3]&0x20)?1:0;
					strcpy(map_file_name,&in_data[4]);
					save_map(map_file_name);
				}
				kill_local_sounds();
#ifndef	NO_MUSIC
				playing_music=0;
#endif	//NO_MUSIC
				get_map_playlist();
				have_a_map=1;
				//also, stop the rain
				seconds_till_rain_starts=-1;
				seconds_till_rain_stops=-1;
				is_raining=0;
				rain_sound=0;//kill local sounds also kills the rain sound
				weather_light_offset=0;
				rain_light_offset=0;
			}
			break;

		case GET_TELEPORTERS_LIST:
			{
				add_teleporters_from_list(&in_data[3]);
			}
			break;

		case PLAY_MUSIC:
			{
				if(!no_sound)play_music(*((short *)(in_data+3)));
			}
			break;

		case PLAY_SOUND:
			{
				if(!no_sound)add_sound_object(*((short *)(in_data+3)),*((short *)(in_data+5)),*((short *)(in_data+7)),*((char *)(in_data+9)),*((short *)(in_data+10)));
			}
			break;

		case TELEPORT_OUT:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_out,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case TELEPORT_IN:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_in,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case LOG_IN_NOT_OK:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,invalid_pass);
			}
			break;

		case REDEFINE_YOUR_COLORS:
			{
				strcpy(log_in_error_str,redefine_your_colours);
			}
			break;

		case YOU_DONT_EXIST:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,char_dont_exist);
			}
			break;


		case CREATE_CHAR_NOT_OK:
			{
				sprintf(create_char_error_str,"%s: %s",reg_error_str,char_name_in_use);
				return;
			}
			break;


		case CREATE_CHAR_OK:
			{
				login_from_new_char();
			}
			break;

		case YOU_ARE:
			{
				yourself=*((short *)(in_data+3));
			}
			break;

		case START_RAIN:
			{
				seconds_till_rain_starts=*((Uint8 *)(in_data+3));
				seconds_till_rain_stops=-1;
			}
			break;

		case STOP_RAIN:
			{
				seconds_till_rain_stops=*((Uint8 *)(in_data+3));
				seconds_till_rain_starts=-1;
			}
			break;

		case THUNDER:
			{
				add_thunder(rand()%5,*((Uint8 *)(in_data+3)));
			}
			break;


		case SYNC_CLOCK:
			{
				server_time_stamp=*((int *)(in_data+3));
				client_time_stamp=SDL_GetTicks();
				client_server_delta_time=server_time_stamp-client_time_stamp;
			}
			break;

		case PONG:
			{
				Uint8 str[160];
				sprintf(str,"%s: %i MS",server_latency, SDL_GetTicks()-*((Uint32 *)(in_data+3)));
				log_to_console(c_green1,str);
			}
			break;

		case UPGRADE_NEW_VERSION:
			{
				log_to_console(c_red1,update_your_client);
				log_to_console(c_red1,(char*)web_update_address);
			}
			break;

		case UPGRADE_TOO_OLD:
			{
				log_to_console(c_red1,client_ver_not_supported);
				log_to_console(c_red1,(char*)web_update_address);
				this_version_is_invalid=1;
			}
			break;

		case GET_NEW_BAG:
			{
				put_bag_on_ground(*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)),*((Uint8 *)(in_data+7)));
			}
			break;

		case GET_BAGS_LIST:
			{
				add_bags_from_list(&in_data[3]);
			}
			break;

		case SPAWN_BAG_PARTICLES:
			{
			  add_particle_sys_at_tile("./particles/bag_in.part",*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)));
			}
			break;

		case GET_NEW_GROUND_ITEM:
			{
				get_bag_item(in_data+3);
			}
			break;

		case HERE_YOUR_GROUND_ITEMS:
			{
				get_bags_items_list(&in_data[3]);
			}
			break;

		case CLOSE_BAG:
			{
				hide_window(ground_items_win);
			}
			break;

		case REMOVE_ITEM_FROM_GROUND:
			{
				remove_item_from_ground(in_data[3]);
			}
			break;

		case DESTROY_BAG:
			{
				remove_bag(in_data[3]);
			}
			break;

		case NPC_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,dialogue_menu_x_len-70,dialogue_string);
				display_dialogue();
				if(in_data[3]>=127 && in_data[4]>=127)
					{
						add_questlog(&in_data[4],data_lenght-4);
					}
			}
			break;

		case SEND_NPC_INFO:
			{
				my_strcp(npc_name,&in_data[3]);
				cur_portrait=in_data[23];
			}
			break;

		case NPC_OPTIONS_LIST:
			{
				build_response_entries(&in_data[3],*((Uint16 *)(in_data+1)));
			}
			break;

		case GET_TRADE_ACCEPT:
			{
				if(!in_data[3])trade_you_accepted=1;
				else
					trade_other_accepted=1;
			}
			break;

		case GET_TRADE_REJECT:
			{
				if(!in_data[3])trade_you_accepted=0;
				else
					trade_other_accepted=0;
			}
			break;

		case GET_TRADE_EXIT:
			{
				hide_window(trade_win);
			}
			break;

		case GET_YOUR_TRADEOBJECTS:
			{
				get_your_trade_objects(in_data+3);
			}
			break;

		case GET_TRADE_OBJECT:
			{
				put_item_on_trade(in_data+3);
			}
			break;

		case REMOVE_TRADE_OBJECT:
			{
				remove_item_from_trade(in_data+3);
			}
			break;

		case GET_TRADE_PARTNER_NAME:
			{
				get_trade_partner_name(&in_data[3],*((Uint16 *)(in_data+1))-1);
			}
			break;

		case GET_ACTOR_DAMAGE:
			{
				get_actor_damage(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case GET_ACTOR_HEAL:
			{
				get_actor_heal(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_UNWEAR_ITEM:
			{
				unwear_item_from_actor(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_WEAR_ITEM:
			{
				actor_wear_item(*((Uint16 *)(in_data+3)),in_data[5],in_data[6]);
			}
			break;

		case NPC_SAY_OVERTEXT:
			{
				add_displayed_text_to_actor(
					get_actor_ptr_from_id( *((Uint16 *)(in_data+3)) ), in_data+5 );
			}
			break;

		case BUDDY_EVENT:
			{
				if(in_data[3]==1)
					add_buddy(&in_data[5],in_data[4],data_lenght-5);
				else if(in_data[3]==0)
					del_buddy(&in_data[4],data_lenght-4);
			}
			break;

		// BARREN MOON NEW MESSAGES
		case THIS_IS_ACTIVE_SECTOR:
			active_sector=*((Uint16 *)(in_data+3));
			break;

		case GET_TILE_DATA:
			get_tile_data(in_data+3);
			break;

		case GET_3D_OBJECTS:
			get_3d_objects(in_data+3);
			break;

		case GET_2D_OBJECTS:
			get_2d_objects(in_data+3);
			break;

		case GET_LIGHT_OBJECTS:
			get_light_objects(in_data+3);
			break;

		case GET_PARTICLE_OBJECTS:
			get_particle_objects(in_data+3);
			break;

		case GET_3D_OBJECTS_FULL_ROTATION:
			get_3d_objects_full_rotation(in_data+3);
			break;

		case GET_CHECKSUMS:
		{
			actor *actor=pf_get_our_actor();
			get_checksums(in_data+3, sector_get(actor->x_pos,actor->y_pos));
			break;
		}

		case ADD_3D_OBJECT:
			add_3d_object(in_data+3);
			break;

		case ADD_3D_OBJECT_FULL_ROTATION:
			add_3d_object_fullrotation(in_data+3);
			break;

		case DELETE_3D_OBJECT:
			delete_3d_object(in_data+3);
			break;

		case REPLACE_3D_OBJECT:
			replace_3d_object(in_data+3);
			break;

		case ADD_2D_OBJECT:
			add_2d_object(in_data+3);
			break;

		case DELETE_2D_OBJECT:
			delete_2d_object(in_data+3);
			break;

		case REPLACE_2D_OBJECT:
			replace_2d_object(in_data+3);
			break;

		case ADD_LIGHT:
			add_lights(in_data+3);
			break;

		case DELETE_LIGHT:
			delete_light(in_data+3);
			break;

		case ADD_PARTICLE:
			add_particle(in_data+3);
			break;

		case DELETE_PARTICLE:
			delete_particle(in_data+3);
			break;

		case REPLACE_PARTICLE:
			replace_particle(in_data+3);
			break;

		default:
			{
				/* Unknown data type?? */;
			}
			break;
		}
}
コード例 #2
0
ファイル: map.c プロジェクト: raduprv/Eternal-Lands
void change_map (const char *mapname)
{
#ifndef	MAP_EDITOR
	remove_all_bags();
	remove_all_mines();
#endif	//MAP_EDITOR

	set_all_intersect_update_needed(main_bbox_tree);
	object_under_mouse=-1;//to prevent a nasty crash, while looking for bags, when we change the map
#ifndef MAP_EDITOR2
#ifdef EXTRA_DEBUG
	ERR();
#endif
	close_dialogue();	// close the dialogue window if open
	close_storagewin(); //if storage is open, close it
	destroy_all_particles();
	ec_delete_all_effects();
#ifdef NEW_SOUND
	stop_all_sounds();
#endif	//NEW_SOUND
	missiles_clear();
	if (!el_load_map(mapname)) {
		char error[255];
		safe_snprintf(error, sizeof(error), cant_change_map, mapname);
		LOG_TO_CONSOLE(c_red4, error);
		LOG_TO_CONSOLE(c_red4, empty_map_str);
		LOG_ERROR(cant_change_map, mapname);
		load_empty_map();
	} else {
		locked_to_console = 0;
	}
	load_map_marks();
	
#ifdef NEW_SOUND
	get_map_playlist();
	setup_map_sounds(get_cur_map(mapname));
#endif // NEW_SOUND
	have_a_map=1;
	//also, stop the rain
	weather_clear();

	if ( get_show_window (map_root_win) )
	{
		hide_window(map_root_win);
		show_window(game_root_win);
	}
#else // !MAP_EDITOR2
	destroy_all_particles();
#ifdef NEW_SOUND
	stop_all_sounds();
#endif	//NEW_SOUND
	if (!load_map(mapname)) {
		char error[255];
		safe_snprintf(error, sizeof(error), cant_change_map, mapname);
		LOG_TO_CONSOLE(c_red4, error);
		LOG_TO_CONSOLE(c_red4, empty_map_str);
		LOG_ERROR(cant_change_map, mapname);
		load_empty_map();
	}

#ifdef NEW_SOUND
	get_map_playlist();
	setup_map_sounds(get_cur_map(mapname));
#endif // NEW_SOUND
	have_a_map=1;
#endif  //MAP_EDITOR2
	change_minimap();

#ifdef PAWN
	run_pawn_map_function ("change_map", "s", mapname);
#endif
}