Ejemplo 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);
	}
}
Ejemplo n.º 2
0
void net_send_state_and_sync(GameNetConnection& net, GameState* gs) {
    if (gs->game_settings().network_debug_mode) {
        // net.check_integrity(gs);
        return;
    }
    printf("Sent sync on frame %d\n", gs->frame());
    SerializeBuffer& sb = net.grab_buffer(GameNetConnection::PACKET_FORCE_SYNC);
    if (!net.is_connected())
        return;
    // Make sure we don't receive any stray actions after sync.
//    gs->local_player()->enqueue_io_actions(gs);
//    players_poll_for_actions(gs);

    // Make sure we are all sync'd with the same rng, even if we have to contrive a state.
    int mtwistseed = gs->rng().rand();
    gs->rng().init_genrand(mtwistseed);
    sb.write_int(mtwistseed);

    gs->serialize(sb);
    net.send_packet(sb, NetConnection::ALL_RECEIVERS);

    // Wait for clients to receive the synch data before continuing
    net_sync_and_discard(net, GameNetConnection::PACKET_SYNC_ACK);
    post_sync(gs);
    net_send_sync_ack(net);
}
Ejemplo n.º 3
0
void net_send_player_actions(GameNetConnection& net, int frame,
		int player_number, const ActionQueue& actions) {
	SerializeBuffer& sb = net.grab_buffer(GameNetConnection::PACKET_ACTION);
	sb.write_int(frame);
	sb.write_int(player_number);
	sb.write_container(actions);
	net.send_packet(sb);
}
Ejemplo n.º 4
0
void net_send_chatmessage(GameNetConnection& net, ChatMessage & message) {
	if (!net.connection()) {
		return;
	}
	SerializeBuffer& sb = net.grab_buffer(
			GameNetConnection::PACKET_CHAT_MESSAGE);
	message.serialize(sb);
	net.send_packet(sb);
}
Ejemplo n.º 5
0
void net_send_connection_affirm(GameNetConnection& net, const std::string& name,
		class_id classtype) {
	SerializeBuffer& sb = net.grab_buffer(
			GameNetConnection::PACKET_CLIENT2SERV_CONNECTION_AFFIRM);
	sb.write(name);
	sb.write_int(classtype);
	printf("connection affirm sent\n");
	net.send_packet(sb, NetConnection::SERVER_RECEIVER);
}
Ejemplo n.º 6
0
static void net_sync_and_discard(GameNetConnection& net,
		GameNetConnection::message_t) {
	std::vector<QueuedMessage> qms = net.sync_on_message(
			GameNetConnection::PACKET_SYNC_ACK);
	for (int i = 0; i < qms.size(); i++) {
		delete qms[i].message;
	}
}
Ejemplo n.º 7
0
void net_send_sync_ack(GameNetConnection& net) {
	SerializeBuffer& sb = net.grab_buffer(GameNetConnection::PACKET_SYNC_ACK);
	net.send_packet(sb);
}