SuperTuxKart
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
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
24#ifndef EVENT_HPP
25#define EVENT_HPP
26
28#include "utils/leak_check.hpp"
29#include "utils/types.hpp"
30
31#include "enet/enet.h"
32
33#include <memory>
34
35class STKPeer;
36
42{
46};
47
52enum EVENT_CHANNEL : uint8_t
53{
57 EVENT_CHANNEL_COUNT = 3
58};
59
60enum PeerDisconnectInfo : unsigned int;
61
72class Event
73{
74private:
75 LEAK_CHECK()
76
77
79
82
84 std::shared_ptr<STKPeer> m_peer;
85
88
91
92public:
93 Event(ENetEvent* event, std::shared_ptr<STKPeer> peer);
94 ~Event();
95
96 // ------------------------------------------------------------------------
98 EVENT_TYPE getType() const { return m_type; }
99 // ------------------------------------------------------------------------
101 std::shared_ptr<STKPeer> getPeerSP() const { return m_peer; }
102 // ------------------------------------------------------------------------
104 STKPeer* getPeer() const { return m_peer.get(); }
105 // ------------------------------------------------------------------------
109 const NetworkString& data() const { return *m_data; }
110 // ------------------------------------------------------------------------
114 NetworkString& data() { return *m_data; }
115 // ------------------------------------------------------------------------
118 bool isSynchronous() const { return m_type==EVENT_TYPE_MESSAGE &&
120 // ------------------------------------------------------------------------
122 uint64_t getArrivalTime() const { return m_arrival_time; }
123 // ------------------------------------------------------------------------
124 PeerDisconnectInfo getPeerDisconnectInfo() const { return m_pdi; }
125 // ------------------------------------------------------------------------
126
127}; // class Event
128
129#endif // EVENT_HPP
Class representing an event that need to pass trough the system. This is used to remove ENet dependen...
Definition: event.hpp:73
NetworkString * m_data
Copy of the data passed by the event.
Definition: event.hpp:78
uint64_t m_arrival_time
Arrivial time of the event, for timeouts.
Definition: event.hpp:87
EVENT_TYPE m_type
Type of the event.
Definition: event.hpp:81
EVENT_TYPE getType() const
Returns the type of this event.
Definition: event.hpp:98
std::shared_ptr< STKPeer > m_peer
Pointer to the peer that triggered that event.
Definition: event.hpp:84
const NetworkString & data() const
Get a const reference to the received data.
Definition: event.hpp:109
NetworkString & data()
Get a non-const reference to the received data.
Definition: event.hpp:114
bool isSynchronous() const
Determines if this event should be delivered synchronous or not.
Definition: event.hpp:118
PeerDisconnectInfo m_pdi
For disconnection event, a bit more info is provided.
Definition: event.hpp:90
std::shared_ptr< STKPeer > getPeerSP() const
Returns the peer of this event (shared pointer).
Definition: event.hpp:101
uint64_t getArrivalTime() const
Returns the arrival time of this event.
Definition: event.hpp:122
STKPeer * getPeer() const
Returns the peer of this event.
Definition: event.hpp:104
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
bool isSynchronous() const
Returns if this message is synchronous or not.
Definition: network_string.hpp:470
Represents a peer. This class is used to interface the ENetPeer structure.
Definition: stk_peer.hpp:76
EVENT_CHANNEL
Represents a list of channels stk used.
Definition: event.hpp:53
@ EVENT_CHANNEL_UNENCRYPTED
Unencrypted channel.
Definition: event.hpp:55
@ EVENT_CHANNEL_NORMAL
Normal channel (encrypted if supported)
Definition: event.hpp:54
@ EVENT_CHANNEL_DATA_TRANSFER
Data transfer channel (like game replay)
Definition: event.hpp:56
EVENT_TYPE
Represents a network event type.
Definition: event.hpp:42
@ EVENT_TYPE_CONNECTED
A peer is connected.
Definition: event.hpp:43
@ EVENT_TYPE_DISCONNECTED
A peer is disconnected.
Definition: event.hpp:44
@ EVENT_TYPE_MESSAGE
A message between server and client protocols.
Definition: event.hpp:45
Defines functions to easily manipulate 8-bit network destinated strings.
PeerDisconnectInfo
Definition: stk_peer.hpp:48
Declares the general types that are used by the network.