SuperTuxKart
connect_to_peer.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2013-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef CONNECT_TO_PEER_HPP
20 #define CONNECT_TO_PEER_HPP
21 
22 #include "network/protocol.hpp"
23 #include "network/socket_address.hpp"
24 #include "utils/cpp2011.hpp"
25 
29 class ConnectToPeer : public Protocol
30 {
31 protected:
32  SocketAddress m_peer_address;
33 
35  uint64_t m_timer = 0;
36 
38  unsigned m_tried_connection = 0;
39 
40  enum STATE
41  {
42  WAIT_FOR_CONNECTION,
43  DONE,
44  EXITING
45  } m_state;
46 
47 public:
48  ConnectToPeer(const SocketAddress &address);
49  virtual ~ConnectToPeer() {}
50  virtual void setup() OVERRIDE {}
51  virtual void update(int ticks) OVERRIDE {}
52  virtual void asynchronousUpdate() OVERRIDE;
53 }; // class ConnectToPeer
54 
55 #endif // CONNECT_TO_SERVER_HPP
One instance of this is started for every peer who tries to connect to this server.
Definition: connect_to_peer.hpp:30
unsigned m_tried_connection
If greater than a certain value, terminate this protocol.
Definition: connect_to_peer.hpp:38
virtual void asynchronousUpdate() OVERRIDE
Simple finite state machine: Start a GetPeerAddress protocol.
Definition: connect_to_peer.cpp:44
uint64_t m_timer
Timer use for tracking broadcast.
Definition: connect_to_peer.hpp:35
ConnectToPeer(const SocketAddress &address)
Constructor for peer address.
Definition: connect_to_peer.cpp:30
virtual void update(int ticks) OVERRIDE
Called by the protocol listener, synchronously with the main loop.
Definition: connect_to_peer.hpp:51
virtual void setup() OVERRIDE
Called when the protocol is going to start.
Definition: connect_to_peer.hpp:50
Abstract class used to define the global protocol functions.
Definition: protocol.hpp:68
Describes a IPv4 or IPv6 address in sockaddr_in(6) format, suitable in using with sendto.
Definition: socket_address.hpp:47
Generic protocols declarations.