diff options
author | Perttu Ahola <celeron55@gmail.com> | 2010-12-24 17:08:50 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2010-12-24 17:08:50 +0200 |
commit | a26c92d7dda327f2b1483fe7250cb27580a0a039 (patch) | |
tree | 1f7a7b9cb9ceb200fa5e1480961cd9bbe9ae38a3 /src/connection.cpp | |
parent | 705de63dcdfe78157234e1b65652d5c2f762dbd4 (diff) | |
download | minetest-a26c92d7dda327f2b1483fe7250cb27580a0a039.tar.gz minetest-a26c92d7dda327f2b1483fe7250cb27580a0a039.tar.bz2 minetest-a26c92d7dda327f2b1483fe7250cb27580a0a039.zip |
disconnect method to connection to be used instead of just timing out
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/connection.cpp b/src/connection.cpp index e0a201773..0bc8492e6 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -542,6 +542,23 @@ void Connection::Connect(Address address) //m_waiting_new_peer_id = true; } +void Connection::Disconnect() +{ + // Create and send DISCO packet + SharedBuffer<u8> data(2); + writeU8(&data[0], TYPE_CONTROL); + writeU8(&data[1], CONTROLTYPE_DISCO); + + // Send to all + core::map<u16, Peer*>::Iterator j; + j = m_peers.getIterator(); + for(; j.atEnd() == false; j++) + { + Peer *peer = j.getNode()->getValue(); + SendAsPacket(peer->id, 0, data, false); + } +} + bool Connection::Connected() { if(m_peers.size() != 1) @@ -645,7 +662,22 @@ SharedBuffer<u8> Channel::ProcessPacket( // the timeout counter con->PrintInfo(); dout_con<<"PING"<<std::endl; - throw ProcessedSilentlyException("Got a SET_PEER_ID"); + throw ProcessedSilentlyException("Got a PING"); + } + else if(controltype == CONTROLTYPE_DISCO) + { + // Just ignore it, the incoming data already reset + // the timeout counter + con->PrintInfo(); + dout_con<<"DISCO: Removing peer "<<(peer_id)<<std::endl; + + if(con->deletePeer(peer_id) == false) + { + con->PrintInfo(derr_con); + derr_con<<"DISCO: Peer not found"<<std::endl; + } + + throw ProcessedSilentlyException("Got a DISCO"); } else{ con->PrintInfo(derr_con); @@ -1323,6 +1355,16 @@ core::list<Peer*> Connection::GetPeers() return list; } +bool Connection::deletePeer(u16 peer_id) +{ + if(m_peers.find(peer_id) == NULL) + return false; + m_peerhandler->deletingPeer(m_peers[peer_id], true); + delete m_peers[peer_id]; + m_peers.remove(peer_id); + return true; +} + void Connection::PrintInfo(std::ostream &out) { out<<m_socket.GetHandle(); |