예제 #1
0
//**********************************MAP*********************************************//
e_socket_status serializeMapToOrder(int socket, t_map *map) {
	uint8_t order = COMMAND_MAP;
	uint16_t snodeIP = strlen(map->nodeIP);
	size_t sbuffer = sizeof(uint8_t) + sizeof(uint16_t) + sizeof(snodeIP)
			+ snodeIP + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(char) * 60;

	uint16_t id = htons(map->id);
	uint16_t serializedSNodeIP = htons(snodeIP);
	uint16_t numBlock = htons(map->numBlock);
	uint16_t nodePort = htons(map->nodePort);

	void *buffer = malloc(sbuffer);
	memcpy(buffer, &order, sizeof(order));
	void *bufferOffset = buffer + sizeof(order);
	memcpy(bufferOffset, &id, sizeof(id));
	bufferOffset += sizeof(id);
	memcpy(bufferOffset, &serializedSNodeIP, sizeof(serializedSNodeIP));
	bufferOffset += sizeof(serializedSNodeIP);
	memcpy(bufferOffset, map->nodeIP, snodeIP);
	bufferOffset += snodeIP;
	memcpy(bufferOffset, &nodePort, sizeof(nodePort));
	bufferOffset += sizeof(nodePort);
	memcpy(bufferOffset, &numBlock, sizeof(numBlock));
	bufferOffset += sizeof(numBlock);
	memcpy(bufferOffset, map->tempResultName, sizeof(char) * 60);
	e_socket_status status = socket_send_packet(socket, buffer, sbuffer);
	free(buffer);
	return status;
}
예제 #2
0
파일: updates.c 프로젝트: atrinik/atrinik
/**
 * Request the server to send us an updated copy of a file.
 * @param filename
 * What to request.
 */
static void file_updates_request(char *filename)
{
    packet_struct *packet;

    file_updates_requested++;

    packet = packet_new(SERVER_CMD_REQUEST_UPDATE, 64, 64);
    packet_append_string_terminated(packet, filename);
    socket_send_packet(packet);

}
예제 #3
0
e_socket_status sendDieOrder(int socket, uint8_t result) {
	uint8_t order = COMMAND_MARTA_TO_JOB_DIE;
	size_t sbuffer = sizeof(order) + sizeof(result);
	void *buffer = malloc(sbuffer);

	memcpy(buffer, &order, sizeof(order));
	memcpy(buffer + sizeof(order), &result, sizeof(result));

	e_socket_status status = socket_send_packet(socket, buffer, sbuffer);
	free(buffer);
	return status;
}
예제 #4
0
파일: main.c 프로젝트: RemiBauzac/haka
static bool send_packet(struct packet *orig_pkt)
{
	struct nfqueue_packet *pkt = (struct nfqueue_packet*)orig_pkt;
	bool ret;

	ret = socket_send_packet(pkt->state->send_fd, pkt->data, pkt->length);

	free(pkt->data);
	pkt->data = NULL;

	return ret;
}
예제 #5
0
파일: main.c 프로젝트: RemiBauzac/haka
static void packet_verdict(struct packet *orig_pkt, filter_result result)
{
	int ret;
	struct nfqueue_packet *pkt = (struct nfqueue_packet*)orig_pkt;

	if (pkt->data) {
		if (pkt->id == -1) {
			if (result == FILTER_ACCEPT) {
				ret = socket_send_packet(pkt->state->send_mark_fd, pkt->data, pkt->length);
			}
			else {
				ret = 0;
			}
		}
		else {
			/* Convert verdict to netfilter */
			int verdict;
			switch (result) {
			case FILTER_ACCEPT: verdict = NF_ACCEPT; break;
			case FILTER_DROP:   verdict = NF_DROP; break;
			default:
				message(HAKA_LOG_DEBUG, MODULE_NAME, L"unknown verdict");
				verdict = NF_DROP;
				break;
			}

			if (pkt->modified)
				ret = nfq_set_verdict(pkt->state->queue, pkt->id, verdict, pkt->length, pkt->data);
			else
				ret = nfq_set_verdict(pkt->state->queue, pkt->id, verdict, 0, NULL);
		}

		if (pcap) {
			switch (result) {
			case FILTER_ACCEPT:
				dump_pcap(&pcap->out, pkt);
				break;

			case FILTER_DROP:
			default:
				dump_pcap(&pcap->drop, pkt);
				break;
			}
		}

		if (ret == -1) {
			message(HAKA_LOG_ERROR, MODULE_NAME, L"packet verdict failed");
		}

		free(pkt->data);
		pkt->data = NULL;
	}
}
예제 #6
0
파일: item.c 프로젝트: atrinik/atrinik
/**
 * Toggle the locked status of an object.
 * @param op
 * Object.
 */
void toggle_locked(object *op)
{
    packet_struct *packet;

    /* If object is on the ground, don't lock it. */
    if (!op || !op->env || op->env->tag == 0) {
        return;
    }

    packet = packet_new(SERVER_CMD_ITEM_LOCK, 8, 0);
    packet_append_uint32(packet, op->tag);
    socket_send_packet(packet);
}
bool connections_marta_sendFileBlocks(void *bufferReceived) {
	bool sendFailed() {
		uint16_t blocksCount = 0; // We send 0 as an error.
		uint16_t blocksCountSerialized = htons(blocksCount);

		void *buffer = malloc(sizeof(blocksCount));
		memcpy(buffer, &blocksCountSerialized, sizeof(blocksCount));

		size_t sBuffer = sizeof(blocksCount);

		e_socket_status status = socket_send_packet(martaSocket, buffer, sBuffer);
		free(buffer);

		bool success = status == SOCKET_ERROR_NONE;
		log_info(mdfs_logger, "Error informed to MaRTA %s!", success ? "successfully" : "unsuccessfully");

		return success;
	}
예제 #8
0
void serializeMap(int sock_nodo, t_map* map) {
	uint8_t order = COMMAND_MAP;
	size_t sOrder = sizeof(uint8_t);
	size_t sBlock = sizeof(uint16_t);
	char* fileMap;

	/* Obtenemos binario de File Map */
	fileMap = getMapReduceRoutine(cfgJob->MAPPER);
	uint32_t sfileMap = strlen(fileMap);
	uint32_t sTempName = strlen(map->tempResultName);
	size_t sbuffer = sOrder + sBlock + sizeof(uint32_t) + sfileMap
			+ sizeof(uint32_t) + sTempName;

	/* htons - htonl */
	uint16_t numBlock = htons(map->numBlock);

	uint32_t sfileMapSerialize = htonl(sfileMap);
	uint32_t sTempNameSerialize = htonl(sTempName);

	/* Armo el paquete y lo mando */

	void* buffer = malloc(sbuffer);
	buffer = memset(buffer, '\0', sbuffer);
	memcpy(buffer, &order, sOrder);
	memcpy(buffer + sOrder, &numBlock, sBlock);
	memcpy(buffer + sOrder + sBlock, &sfileMapSerialize, sizeof(uint32_t));
	memcpy(buffer + sOrder + sBlock + sizeof(uint32_t), fileMap, sfileMap);
	memcpy(buffer + sOrder + sBlock + sizeof(uint32_t) + sfileMap,
			&sTempNameSerialize, sizeof(uint32_t));
	memcpy(
			buffer + sOrder + sBlock + sizeof(uint32_t) + sfileMap
					+ sizeof(uint32_t), map->tempResultName, sTempName);

	e_socket_status status = socket_send_packet(sock_nodo, buffer, sbuffer);
	if (status > 0) {
		log_info(logger, "Map: %d --> send to nodo", map->mapID);
	}
	//free(fileMap);
	free(buffer);

}
예제 #9
0
파일: item.c 프로젝트: atrinik/atrinik
/**
 * Update the marked object.
 * @param op
 * The object.
 */
void object_send_mark(object *op)
{
    packet_struct *packet;

    /* If object is on the ground, don't mark it. */
    if (!op || !op->env || op->env->tag == 0) {
        return;
    }

    if (cpl.mark_count == op->tag) {
        cpl.mark_count = 0;
    } else {
        cpl.mark_count = op->tag;
    }

    object_redraw(op);

    packet = packet_new(SERVER_CMD_ITEM_MARK, 8, 0);
    packet_append_uint32(packet, op->tag);
    socket_send_packet(packet);
}
예제 #10
0
void serializeReduce(int sock_nodo, t_reduce* reduce) {
	uint8_t order = COMMAND_REDUCE;
	size_t sOrder = sizeof(uint8_t);
	char* fileReduce;
	uint32_t sTempName = strlen(reduce->tempResultName);

	/* Obtenemos binario de File Map */
	fileReduce = getMapReduceRoutine(cfgJob->REDUCER);
	uint32_t sfileReduce = strlen(fileReduce);

	/* htons */
	uint32_t sfileReduceSerialize = htonl(sfileReduce);
	uint32_t sTempNameSerialize = htonl(sTempName);

	/* Armo el paquete y lo mando */
	size_t sbuffer = sOrder + sizeof(uint32_t) + sfileReduce + sizeof(uint32_t)
			+ sTempName + sizeof(uint32_t) + reduce->sizetmps;
	void* buffer = malloc(sbuffer);
	buffer = memset(buffer, '\0', sbuffer);
	memcpy(buffer, &order, sOrder);
	memcpy(buffer + sOrder, &sfileReduceSerialize, sizeof(uint32_t));
	memcpy(buffer + sOrder + sizeof(uint32_t), fileReduce, sfileReduce);
	memcpy(buffer + sOrder + sizeof(uint32_t) + sfileReduce,
			&sTempNameSerialize, sizeof(uint32_t));
	memcpy(buffer + sOrder + sizeof(uint32_t) + sfileReduce + sizeof(uint32_t),
			reduce->tempResultName, sTempName);
	memcpy(
			buffer + sOrder + sizeof(uint32_t) + sfileReduce + sizeof(uint32_t)
					+ sTempName, reduce->buffer_tmps, reduce->sizetmps);


	e_socket_status status = socket_send_packet(sock_nodo, buffer, sbuffer);

	if (status > 0) {
		log_info(logger, "Reduce: %d --> send to nodo", reduce->reduceID);
	}
	//free(fileMap);
	free(buffer);
}
예제 #11
0
파일: menu.c 프로젝트: atrinik/atrinik
/**
 * Analyze /cmd type commands the player has typed in the console or bound to a
 * key.
 * Sort out the "client intern" commands and expand or pre process them for the
 * server.
 * @param cmd
 * Command to check
 * @return
 * 0 to send command to server, 1 to not send it
 */
int client_command_check(const char *cmd)
{
    if (cmd_aliases_handle(cmd)) {
        return 1;
    } else if (strncasecmp(cmd, "/ready_spell", 12) == 0) {
        cmd = strchr(cmd, ' ');

        if (!cmd || *++cmd == '\0') {
            draw_info(COLOR_RED, "Usage: /ready_spell <spell name>");
            return 1;
        } else {
            object *tmp;

            for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) {
                if (tmp->itype == TYPE_SPELL && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) {
                    if (!(tmp->flags & CS_FLAG_APPLIED)) {
                        client_send_apply(tmp);
                    }

                    return 1;
                }
            }
        }

        draw_info(COLOR_RED, "Unknown spell.");
        return 1;
    } else if (strncasecmp(cmd, "/ready_skill", 12) == 0) {
        cmd = strchr(cmd, ' ');

        if (!cmd || *++cmd == '\0') {
            draw_info(COLOR_RED, "Usage: /ready_skill <skill name>");
            return 1;
        } else {
            object *tmp;

            for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) {
                if (tmp->itype == TYPE_SKILL && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) {
                    if (!(tmp->flags & CS_FLAG_APPLIED)) {
                        client_send_apply(tmp);
                    }

                    return 1;
                }
            }
        }

        draw_info(COLOR_RED, "Unknown skill.");
        return 1;
    } else if (!strncmp(cmd, "/help", 5)) {
        cmd += 5;

        if (*cmd == '\0') {
            help_show("main");
        } else {
            help_show(cmd + 1);
        }

        return 1;
    } else if (!strncmp(cmd, "/resetwidgets", 13)) {
        widgets_reset();
        return 1;
    } else if (!strncmp(cmd, "/effect ", 8)) {
        if (!strcmp(cmd + 8, "none")) {
            effect_stop();
            draw_info(COLOR_GREEN, "Stopped effect.");
            return 1;
        }

        if (effect_start(cmd + 8)) {
            draw_info_format(COLOR_GREEN, "Started effect %s.", cmd + 8);
        } else {
            draw_info_format(COLOR_RED, "No such effect %s.", cmd + 8);
        }

        return 1;
    } else if (!strncmp(cmd, "/d_effect ", 10)) {
        effect_debug(cmd + 10);
        return 1;
    } else if (!strncmp(cmd, "/music_pause", 12)) {
        sound_pause_music();
        return 1;
    } else if (!strncmp(cmd, "/music_resume", 13)) {
        sound_resume_music();
        return 1;
    } else if (!strncmp(cmd, "/party joinpassword ", 20)) {
        cmd += 20;

        if (cpl.partyjoin[0] != '\0') {
            char buf[MAX_BUF];

            snprintf(VS(buf), "/party join %s\t%s", cpl.partyjoin, cmd);
            send_command(buf);
        }

        return 1;
    } else if (!strncmp(cmd, "/invfilter ", 11)) {
        inventory_filter_set_names(cmd + 11);
        return 1;
    } else if (!strncasecmp(cmd, "/screenshot", 11)) {
        SDL_Surface *surface_save;

        cmd += 11;

        if (!strncasecmp(cmd, " map", 4)) {
            surface_save = cur_widget[MAP_ID]->surface;
        } else {
            surface_save = ScreenSurface;
        }

        if (!surface_save) {
            draw_info(COLOR_RED, "No surface to save.");
            return 1;
        }

        screenshot_create(surface_save);
        return 1;
    } else if (!strncasecmp(cmd, "/console-load ", 14)) {
        FILE *fp;
        char path[HUGE_BUF], buf[HUGE_BUF * 4], *cp;
        StringBuffer *sb;

        cmd += 14;

        snprintf(path, sizeof(path), "%s/.atrinik/console/%s", get_config_dir(), cmd);

        fp = fopen(path, "r");

        if (!fp) {
            draw_info_format(COLOR_RED, "Could not read %s.", path);
            return 1;
        }

        send_command("/console noinf::");

        while (fgets(buf, sizeof(buf) - 1, fp)) {
            cp = strchr(buf, '\n');

            if (cp) {
                *cp = '\0';
            }

            sb = stringbuffer_new();
            stringbuffer_append_string(sb, "/console noinf::");
            stringbuffer_append_string(sb, buf);
            cp = stringbuffer_finish(sb);
            send_command(cp);
            efree(cp);
        }

        send_command("/console noinf::");

        fclose(fp);

        return 1;
    } else if (strncasecmp(cmd, "/console-obj", 11) == 0) {
        menu_inventory_loadtoconsole(cpl.inventory_focus, NULL, NULL);
        return 1;
    } else if (strncasecmp(cmd, "/patch-obj", 11) == 0) {
        menu_inventory_patch(cpl.inventory_focus, NULL, NULL);
        return 1;
    } else if (string_startswith(cmd, "/cast ") || string_startswith(cmd, "/use_skill ")) {
        object *tmp;
        uint8_t type;

        type = string_startswith(cmd, "/cast ") ? TYPE_SPELL : TYPE_SKILL;
        cmd = strchr(cmd, ' ') + 1;

        if (string_isempty(cmd)) {
            return 1;
        }

        for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) {
            if (tmp->itype == type && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) {
                client_send_fire(5, tmp->tag);
                return 1;
            }
        }

        draw_info_format(COLOR_RED, "Unknown %s.", type == TYPE_SPELL ? "spell" : "skill");
        return 1;
    } else if (strncasecmp(cmd, "/clearcache", 11) == 0) {
        cmd += 12;

        if (string_isempty(cmd)) {
            return 1;
        }

        if (strcasecmp(cmd, "sound") == 0) {
            sound_clear_cache();
            draw_info(COLOR_GREEN, "Sound cache cleared.");
        } else if (strcasecmp(cmd, "textures") == 0) {
            texture_reload();
            draw_info(COLOR_GREEN, "Textures reloaded.");
        }

        return 1;
    } else if (string_startswith(cmd, "/droptag ") ||
            string_startswith(cmd, "/gettag ")) {
        char *cps[3];
        unsigned long int loc, tag, num;

        if (string_split(strchr(cmd, ' ') + 1, cps, arraysize(cps), ' ') !=
                arraysize(cps)) {
            return 1;
        }

        loc = strtoul(cps[0], NULL, 10);
        tag = strtoul(cps[1], NULL, 10);
        num = strtoul(cps[2], NULL, 10);
        client_send_move(loc, tag, num);

        if (string_startswith(cmd, "/gettag ")) {
            sound_play_effect("get.ogg", 100);
        } else {
            sound_play_effect("drop.ogg", 100);
        }

        return 1;
    } else if (string_startswith(cmd, "/talk")) {
        char type[MAX_BUF], npc_name[MAX_BUF];
        size_t pos;
        uint8_t type_num;
        packet_struct *packet;

        pos = 5;

        if (!string_get_word(cmd, &pos, ' ', type, sizeof(type), 0) || string_isempty(cmd + pos)) {
            return 1;
        }

        type_num = atoi(type);

        if (type_num == CMD_TALK_NPC_NAME && (!string_get_word(cmd, &pos, ' ', npc_name, sizeof(npc_name), '"') || string_isempty(cmd + pos))) {
            return 1;
        }

        packet = packet_new(SERVER_CMD_TALK, 64, 64);
        packet_append_uint8(packet, type_num);

        if (type_num == CMD_TALK_NPC || type_num == CMD_TALK_NPC_NAME) {
            if (type_num == CMD_TALK_NPC_NAME) {
                packet_append_string_terminated(packet, npc_name);
            }

            packet_append_string_terminated(packet, cmd + pos);
        } else {
            char tag[MAX_BUF];

            if (!string_get_word(cmd, &pos, ' ', tag, sizeof(tag), 0) || string_isempty(cmd + pos)) {
                packet_free(packet);
                return 1;
            }

            packet_append_uint32(packet, atoi(tag));
            packet_append_string_terminated(packet, cmd + pos);
        }

        socket_send_packet(packet);

        return 1;
    } else if (string_startswith(cmd, "/widget_toggle")) {
        size_t pos;
        char word[MAX_BUF], *cps[2];
        int widget_id;

        pos = 14;

        while (string_get_word(cmd, &pos, ' ', word, sizeof(word), 0)) {
            if (string_split(word, cps, arraysize(cps), ':') < 1) {
                continue;
            }

            widget_id = widget_id_from_name(cps[0]);

            /* Invalid widget ID */
            if (widget_id == -1) {
                continue;
            }

            /* Redraw all or a specific one identified by its UID */
            if (cps[1] == NULL) {
                WIDGET_SHOW_TOGGLE_ALL(widget_id);
            } else {
                widgetdata *widget;

                widget = widget_find(NULL, widget_id, cps[1], NULL);

                if (widget) {
                    WIDGET_SHOW_TOGGLE(widget);
                }
            }
        }

        return 1;
    } else if (string_startswith(cmd, "/widget_focus")) {
        size_t pos;
        char word[MAX_BUF], *cps[2];
        int widget_id;

        pos = 14;

        while (string_get_word(cmd, &pos, ' ', word, sizeof(word), 0)) {
            if (string_split(word, cps, arraysize(cps), ':') < 1) {
                continue;
            }

            widget_id = widget_id_from_name(cps[0]);
            if (widget_id == -1) {
                /* Invalid widget ID */
                continue;
            }

            widget_switch_focus(widget_id, cps[1]);
        }

        return 1;
    } else if (string_startswith(cmd, "/ping")) {
        keepalive_ping_stats();
        return 1;
    } else if (string_startswith(cmd, "/region_map")) {
        region_map_open();
        return 1;
    }

    return 0;
}