+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
#ifndef CONNECTION_HEADER
#define CONNECTION_HEADER
{}
};
-class GotSplitPacketException
-{
- SharedBuffer<u8> m_data;
-public:
- GotSplitPacketException(SharedBuffer<u8> data):
- m_data(data)
- {}
- SharedBuffer<u8> getData()
- {
- return m_data;
- }
-};
-
inline u16 readPeerId(u8 *packetdata)
{
return readU16(&packetdata[4]);
Only channels 0, 1 and 2 exist.
*/
#define BASE_HEADER_SIZE 7
-#define PEER_ID_NEW 0
+#define PEER_ID_INEXISTENT 0
#define PEER_ID_SERVER 1
#define CHANNEL_COUNT 3
/*
CONTROLTYPE_SET_PEER_ID
[2] u16 peer_id_new
CONTROLTYPE_PING
- - This can be sent in a reliable packet to get a reply
+ - There is no actual reply, but this can be sent in a reliable
+ packet to get a reply
+ CONTROLTYPE_DISCO
*/
#define TYPE_CONTROL 0
#define CONTROLTYPE_ACK 0
#define CONTROLTYPE_SET_PEER_ID 1
#define CONTROLTYPE_PING 2
+#define CONTROLTYPE_DISCO 3
/*
ORIGINAL: This is a plain packet with no control and no error
checking at all.
public:
~IncomingSplitBuffer();
/*
- This will throw a GotSplitPacketException when a full
- split packet is constructed.
+ Returns a reference counted buffer of length != 0 when a full split
+ packet is constructed. If not, returns one of length 0.
*/
- void insert(BufferedPacket &p, bool reliable);
+ SharedBuffer<u8> insert(BufferedPacket &p, bool reliable);
void removeUnreliableTimedOuts(float dtime, float timeout);
void Connect(Address address);
bool Connected();
+ void Disconnect();
+
// Sets peer_id
SharedBuffer<u8> GetFromBuffers(u16 &peer_id);
// The peer_id of sender is stored in peer_id
// Return value: I guess this always throws an exception or
// actually gets data
+ // May call PeerHandler methods
u32 Receive(u16 &peer_id, u8 *data, u32 datasize);
// These will automatically package the data as an original or split
// Sends a raw packet
void RawSend(const BufferedPacket &packet);
+ // May call PeerHandler methods
void RunTimeouts(float dtime);
+
// Can throw a PeerNotFoundException
Peer* GetPeer(u16 peer_id);
// returns NULL if failed
Peer* GetPeerNoEx(u16 peer_id);
core::list<Peer*> GetPeers();
+
+ // Calls PeerHandler::deletingPeer
+ // Returns false if peer was not found
+ bool deletePeer(u16 peer_id, bool timeout);
void SetPeerID(u16 id){ m_peer_id = id; }
u16 GetPeerID(){ return m_peer_id; }