All pastes #108891 Raw Edit

freeone3000

public text v1 · immutable
#108891 ·published 2006-07-31 19:00 UTC
rendered paste body
void process_message(Uint8 protocol, Uint8 * in_data, int len)
{
	switch (protocol) {
	case RAW_TEXT:
		{
			if (len < 4)
				return;
			check_message_type(in_data, len);
		}
		break;
	case ADD_NEW_ACTOR:
		add_actor(in_data, 0);
		break;
	case ADD_NEW_ENHANCED_ACTOR:
		add_actor(in_data, 1);
		break;
	case ADD_ACTOR_COMMAND:
		add_actor_command(*((short *) (in_data)), *(in_data + 2));
		break;
	case REMOVE_ACTOR:
		remove_actor(*((short *) (in_data)));
		break;
	case KILL_ALL_ACTORS:
		remove_all_actors();
		break;
	case NEW_MINUTE:
		game_minute = *((short *) (in_data));
		new_minute = 1;
		break;
	case LOG_IN_OK:
		{
			char str[200];
			sprintf(str, "Succesful login");
			add_to_buffer(str, strlen(str), CONSOLE_TEXT, 1);
			break;
		}
	case LOG_IN_NOT_OK:
		{
			char str[200];
			sprintf(str, "Unsuccesful login");
			add_to_buffer(str, strlen(str), CONSOLE_TEXT, 1);
		}
		break;
	case YOU_DONT_EXIST:
		{
			char str[200];
			sprintf(str, "%s does not exist", login_name);
			add_to_buffer(str, strlen(str), CONSOLE_TEXT, 1);
		}
		break;
	case PONG:
		{
			char str[200];
			sprintf(str, "Server latency: %i",
				SDL_GetTicks() - *((Uint32 *) (in_data)));
			add_to_buffer(str, strlen(str), CONSOLE_TEXT, 1);
		}
	case YOU_ARE:
		actor_me = *((short *) (in_data));
		break;
	case BUDDY_EVENT:
		break;
	case CHANGE_MAP:
		have_map = 0;
		getting_location_str = 1;
		send_message(el_socket, NULL, LOCATE_ME, 0);
		break;
	case GET_ACTIVE_CHANNELS:
		set_active_channels(in_data[3], (Uint32*)(in_data+4), (len-2)/4);
		break;
	default:
		break;
	}
}
void set_active_channels (Uint8 active, const Uint32 *channels, int nchan) {
	int i;
	for(i=0; i<nchan; i++) {
		cur_chans[i] = SDL_SwapLE32(channels[i]);
	}
	for(; i<MAX_ACTIVE_CHANNELS; i++) {
		cur_chans[i] = 0;
	}
#ifdef ELC_CHAT_DEBUG
	char *c = malloc(sizeof(char)*100);
	add_to_text_log("set_active_channels called!");
	for(i=0; i<nchan; i++) {
		sprintf(c, "Channel %d is %d instead of %d", i, cur_chans[i], channels[i]);
		add_to_text_log(c);
	}
	//Free c here.
#endif
	cur_chan = active;
}