Esempio n. 1
0
void net_send_game_init_data(GameNetConnection& net, PlayerData& pd, int seed) {
	for (int n = 0; n < pd.all_players().size(); n++) {
		int net_id = pd.all_players()[n].net_id;

		if (net_id == 0) {
			continue; // Don't send to self
		}

		// Send a version to each player detailing which player entry is theirs
		// This is a necessary (slight) evil

		SerializeBuffer& sb = net.grab_buffer(
				GameNetConnection::PACKET_SERV2CLIENT_INITIALPLAYERDATA);

		sb.write_int(seed);
		// Send which index is local player to recipient:
		sb.write_int(n);
		std::vector<PlayerDataEntry>& plist = pd.all_players();
		sb.write_int(plist.size());
		for (int i = 0; i < plist.size(); i++) {
			PlayerDataEntry& pde = plist[i];
			sb.write(pde.player_name);
			sb.write_int(pde.classtype);
			sb.write_int(pde.net_id);
		}
		net.send_packet(sb, net_id);
	}
}
Esempio n. 2
0
void net_recv_game_init_data(SerializeBuffer& sb, int sender,
		GameStateInitData& init_data, PlayerData& pd) {
	//Write seed
	sb.read_int(init_data.seed);
	init_data.seed_set_by_network_message = true;

	//Read player data
	int localidx;
	sb.read_int(localidx);
	pd.set_local_player_idx(localidx);
	int playern;
	sb.read_int(playern);
	LANARTS_ASSERT(pd.all_players().empty());
	for (int i = 0; i < playern; i++) {
		std::string name;
		class_id classtype;
		int net_id;
		sb.read(name);
		sb.read_int(classtype);
		sb.read_int(net_id);
		pd.register_player(name, NULL, classtype, net_id);
	}
	printf("Received init packet: seed = 0x%X, localid = %d, nplayers = %d\n",
			init_data.seed, localidx, playern);
}
Esempio n. 3
0
void net_recv_game_init_data(SerializeBuffer& sb, int sender,
        GameStateInitData& init_data, PlayerData& pd) {
    //Write seed
    sb.read(init_data);
    init_data.received_init_data = true;

    //Read player data
    int localidx;
    sb.read_int(localidx);
    int playern;
    sb.read_int(playern);
    LANARTS_ASSERT(pd.all_players().empty());
    for (int i = 0; i < playern; i++) {
        std::string name;
        std::string classtype;
        int net_id;
        sb.read(name);
        sb.read(classtype);
        sb.read_int(net_id);
        pd.register_player(name, NULL, classtype, LuaValue(), (i == localidx), net_id);
    }

    printf(
            "Received init packet: seed = 0x%X, localid = %d, nplayers = %d, "
                    "frame_action_repeat = %d, regen_level_on_death = %d, network_debug_mode = %d, time_per_step = %f\n",
            init_data.seed, localidx, playern, init_data.frame_action_repeat,
            (int) init_data.regen_on_death,
            (int) init_data.network_debug_mode, init_data.time_per_step);
}
Esempio n. 4
0
// Only the server is concerned with this message
void net_recv_connection_affirm(SerializeBuffer& sb, int sender,
		PlayerData& pd) {
	std::string name;
	class_id classtype;
	sb.read(name);
	sb.read_int(classtype);
	printf("connection affirm read\n");
	pd.register_player(name, NULL, classtype, sender);
	printf("now there are %d players\n", (int)pd.all_players().size());
	pd.set_local_player_idx(0);
}
Esempio n. 5
0
// Only the server is concerned with this message
void net_recv_connection_affirm(SerializeBuffer& sb, int sender,
        PlayerData& pd) {
    printf("Recv conn with size=%d\n", sb.size());
    std::string name;
    std::string classtype;
    sb.read(name);
    sb.read(classtype);
    printf("connection affirm read\n");
    pd.register_player(name, NULL, classtype, LuaValue(), /* is local player */ false, sender);
    printf("now there are %d players\n", (int) pd.all_players().size());
}
Esempio n. 6
0
void net_recv_player_actions(SerializeBuffer& sb, int sender, PlayerData& pd) {
	int frame, player_number;
	sb.read_int(frame);
	sb.read_int(player_number);

	PlayerDataEntry& pde = pd.all_players().at(player_number);

	ActionQueue actions;
	sb.read_container(actions);
	pde.action_queue.queue_actions_for_frame(actions, frame);

//	printf("Receiving %d actions for player %d from %d \n", actions.size(),
//			player_number, sender);
}