Exemple #1
0
int on_mcp_join_game(void *p) {
	mcp_packet_t *packet = MCP_CAST(p);

	dword status = net_get_data(packet->data, 14, dword);

	if (status == 0x00) {
		cur_addr = net_get_data(packet->data, 6, dword);
	}
	
	return FORWARD_PACKET;
}
Exemple #2
0
int mcp_creategame_handler(void *p) {
	mcp_packet_t incoming = *MCP_CAST(p);

	mcp_responsed = TRUE;

	dword status = net_get_data(incoming.data, 6, dword);
	
	switch (status) {

	case 0x00: {
		plugin_print("mcp game", "successfully created game\n");

		game_created = TRUE;
		break;
	}
	
	case 0x1e: {
		plugin_error("mcp game", "error: invalid game name\n");
		break;
	}

	case 0x1f: {
		plugin_error("mcp game", "error: game already exists\n");
		// remove this (only for testing purposes)
		//game_created = TRUE;
		break;
	}

	case 0x20: {
		plugin_error("mcp game", "error: game server is unavailable\n");
		break;
	}

	case 0x6e: {
		plugin_error("mcp game", "error: a dead hardcore character cannot create games\n");
		break;
	}

	}

	pthread_mutex_lock(&game_created_mutex);

	pthread_cond_signal(&game_created_cond_v);

	pthread_mutex_unlock(&game_created_mutex);

	return FORWARD_PACKET;
}
Exemple #3
0
int mcp_charlogon_handler(void *p) {
	mcp_packet_t incoming = *MCP_CAST(p);

	pthread_mutex_lock(&mcp_char_logon_mutex);

	dword status = net_get_data(incoming.data, 0, dword);
	char_logon = status == 0x00 ? TRUE : FALSE;

	pthread_cond_signal(&mcp_char_logon_cond_v);

	char_logon_signaled = TRUE;

	pthread_mutex_unlock(&mcp_char_logon_mutex);

	return FORWARD_PACKET;
}
Exemple #4
0
int mcp_gamelist_handler(void *p) {
	mcp_packet_t *packet = MCP_CAST(p);

	game_t g;

	g.index = net_get_data(packet->data, 2, dword);
	g.players  = net_get_data(packet->data, 6, byte);
	net_extract_string(packet->data, g.name, 11);
	net_extract_string(packet->data, g.desc, 11 + strlen(g.name) + 1);

	pthread_mutex_lock(&pub_m);

	game_t *_g;
	if ((_g = list_find(&public_games, (comparator_t) compare_game_index, &g))) {
		_g->players = g.players;
		_g->active = TRUE;
		plugin_debug("mcp game", "refreshing game info\n");
	} else {
		g.joined = FALSE;
		g.active = TRUE;
		
		if (g.index) {
			list_add(&public_games, &g);

			plugin_debug("mcp game", "new game in game list\n");
		} else {
			plugin_debug("mcp game", "end of game list received\n");

			pthread_cond_signal(&pub_cv);
		}
	}

	pthread_mutex_unlock(&pub_m);

	return FORWARD_PACKET;
}
Exemple #5
0
int invoke_packet_handlers(packet_t type, void *packet) {
	int forward = FORWARD_PACKET;

	packet_handler_t *handler;
	byte id;

	switch (type) {

	case BNCS_RECEIVED:
	case BNCS_SENT:
		id = BNCS_CAST(packet)->id;
		break;

	case MCP_RECEIVED:
	case MCP_SENT:
		id = MCP_CAST(packet)->id;
		break;

	case D2GS_RECEIVED:
	case D2GS_SENT:
		id = D2GS_CAST(packet)->id;
		break;

	case INTERNAL:
		id = INTERNAL_CAST(packet)->id;
		break;

	default:
		return forward;

	}

	struct iterator i = list_iterator(&packet_handlers[type][id]);
	while ((handler = iterator_next(&i))) {
		void *c;
		void *data = NULL;
		switch (type) {

		case BNCS_RECEIVED:
		case BNCS_SENT:
			c = calloc(1, sizeof(bncs_packet_t));
			BNCS_CAST(c)->id = id;
			BNCS_CAST(c)->len = BNCS_CAST(packet)->len;
			if (bncs_has_payload(BNCS_CAST(packet))) {
				BNCS_CAST(c)->data = malloc(BNCS_CAST(packet)->len);
				data = BNCS_CAST(c)->data;
				memcpy(BNCS_CAST(c)->data, BNCS_CAST(packet)->data, BNCS_CAST(packet)->len - BNCS_HEADER_SIZE);
			}
			break;

		case MCP_RECEIVED:
		case MCP_SENT:
			c = calloc(1, sizeof(mcp_packet_t));
			MCP_CAST(c)->id = id;
			MCP_CAST(c)->len = MCP_CAST(packet)->len;
			if (mcp_has_payload(MCP_CAST(packet))) {
				MCP_CAST(c)->data = malloc(MCP_CAST(packet)->len);
				data = MCP_CAST(c)->data;
				memcpy(MCP_CAST(c)->data, MCP_CAST(packet)->data, MCP_CAST(packet)->len - MCP_HEADER_SIZE);
			}
			break;

		case D2GS_RECEIVED:
		case D2GS_SENT:
			c = calloc(1, sizeof(d2gs_packet_t));
			D2GS_CAST(c)->id = id;
			D2GS_CAST(c)->len = D2GS_CAST(packet)->len;
			if (d2gs_has_payload(D2GS_CAST(packet))) {
				D2GS_CAST(c)->data = malloc(D2GS_CAST(packet)->len);
				data = D2GS_CAST(c)->data;
				memcpy(D2GS_CAST(c)->data, D2GS_CAST(packet)->data, D2GS_CAST(packet)->len - D2GS_HEADER_SIZE);
			}
			break;

		case INTERNAL:
			c = calloc(1, sizeof(internal_packet_t));
			INTERNAL_CAST(c)->id = id;
			INTERNAL_CAST(c)->len = INTERNAL_CAST(packet)->len;
			if (internal_has_payload(INTERNAL_CAST(packet))) {
				INTERNAL_CAST(c)->data = malloc(INTERNAL_CAST(packet)->len);
				data = INTERNAL_CAST(c)->data;
				memcpy(INTERNAL_CAST(c)->data, INTERNAL_CAST(packet)->data, INTERNAL_CAST(packet)->len - INTERNAL_HEADER_SIZE);
			}
			break;

		default:
			return forward;

		}

		forward = (*handler)((void *) c);
		free(c);
		if (data) {
			free(data);
		}
		if (forward == HIDE_PACKET || forward == BLOCK_PACKET) {
			iterator_destroy(&i);
			break;
		}
	}

	return forward;
}
Exemple #6
0
int mcp_joingame_handler(void *p) {
	mcp_packet_t incoming = *MCP_CAST(p);

	mcp_responsed = TRUE;

	dword status = net_get_data(incoming.data, 14, dword);

	switch (status) {

	case 0x00: {
		plugin_print("mcp game", "successfully joined game\n");

		game_joined = TRUE;

		game_t *g;
		if ((g = list_find(&public_games, (comparator_t) compare_game_name, game_name))) g->joined = TRUE;

		break;
	}

	case 0x29: {
		plugin_error("mcp game", "error: incorrect password\n");
		break;
	}

	case 0x2a: {
		plugin_error("mcp game", "error: game does not exist\n");
		break;
	}
	
	case 0x2b: {
		plugin_error("mcp game", "error: game is full\n");
		break;
	}

	case 0x2c: {
		plugin_error("mcp game", "error: the character does not meet the level requirements for this game\n");
		break;
	}

	case 0x6e: {
		plugin_error("mcp game", "error: a dead hardcore character cannot join a game\n");
		break;
	}

	case 0x71: {
		plugin_error("mcp game", "error: a non-hardcore character cannot join a game created by a hardcore character\n");
		break;
	}

	case 0x73: {
		plugin_error("mcp game", "error: unable to join a nightmare game\n");
		break;
	}

	case 0x74: {
		plugin_error("mcp game", "error: unable to join a hell game\n");
		break;
	}

	case 0x78: {
		plugin_error("mcp game", "error: a non-expansion character cannot join a game created by an expansion character\n");
		break;
	}

	case 0x79: {
		plugin_error("mcp game", "error: a expansion character cannot join a game created by a non-expansion character\n");
		break;
	}

	case 0x7d: {
		plugin_error("mcp game", "error: a non-ladder character cannot join a game created by a ladder character\n");
		break;
	}

	}

	pthread_mutex_lock(&game_joined_mutex);

	pthread_cond_signal(&game_joined_cond_v);

	pthread_mutex_unlock(&game_joined_mutex);

	return FORWARD_PACKET;
}