author | terom |
Mon, 08 Dec 2008 01:12:00 +0000 | |
changeset 277 | 40f4a03917e2 |
parent 202 | b3f5d766391e |
child 431 | c6d7272a164b |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#include <cassert> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
186 | 4 |
#include "Node.hh" |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
5 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
6 |
NetworkNode::NetworkNode (NetworkSession &session, NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &address) : |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
7 |
session(session), tcp(tcp), udp(udp), address(address) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
8 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
9 |
// connect signals |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
10 |
slots.connect(tcp->sig_disconnect(), this, &NetworkNode::on_disconnect); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
11 |
slots.connect(tcp->sig_packet(), &session, &NetworkSession::handle_message, this); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
12 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
NetworkNode::~NetworkNode (void) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
16 |
delete tcp; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
17 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
void NetworkNode::on_disconnect (void) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
20 |
// tell session |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
21 |
session.handle_disconnect(this); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
22 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
23 |
// fire signal |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
24 |
_sig_disconnected(); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
25 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
// delete |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
27 |
// delete this; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
28 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
29 |
|
202 | 30 |
void NetworkNode::write_packet_header (NetworkPacketOutput &pkt, NetworkChannelID channel_id) { |
31 |
pkt.write_uint16(channel_id); |
|
32 |
} |
|
33 |
||
34 |
void NetworkNode::send_raw (const NetworkPacketBuffer &pkt, bool reliable) { |
|
35 |
// either tcp or udp |
|
36 |
if (reliable) { |
|
37 |
assert(tcp); |
|
38 |
||
39 |
tcp->write_packet(pkt); |
|
40 |
||
41 |
} else { |
|
42 |
udp->sendto(pkt, address); |
|
43 |
} |
|
44 |
||
45 |
} |
|
46 |
||
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
186
diff
changeset
|
47 |
void NetworkNode::send (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable) { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
48 |
assert(channel_id > 0); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
49 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
50 |
// add our header |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
51 |
NetworkPacket pkt2; |
202 | 52 |
|
53 |
write_packet_header(pkt2, channel_id); |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
pkt2.write_packet(pkt); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
55 |
|
202 | 56 |
// send |
57 |
send_raw(pkt2, reliable); |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
58 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
59 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
60 |
const NetworkAddress& NetworkNode::getRemoteAddress (void) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
61 |
return address; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
62 |
} |