SuperTuxKart
Loading...
Searching...
No Matches
peer_vote.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2018 Joerg Henrichs
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 PEER_VOTE_HPP
20#define PEER_VOTE_HPP
21
23
24#include "irrString.h"
25#include <string>
26
30{
31public:
32 core::stringw m_player_name;
33 std::string m_track_name;
34 uint8_t m_num_laps;
35 bool m_reverse;
36
37 // ------------------------------------------------------
38 PeerVote() : m_player_name(""), m_track_name(""),
39 m_num_laps(1), m_reverse(false)
40 {
41 } // PeerVote()
42 // ------------------------------------------------------
43 PeerVote(const core::stringw &name,
44 const std::string track,
45 int laps, bool reverse) : m_player_name(name),
46 m_track_name(track),
47 m_num_laps(laps),
48 m_reverse(reverse)
49 {
50 } // PeerVote(name, track, laps, reverse)
51
52 // ------------------------------------------------------
55 {
56 ns.decodeStringW(&m_player_name);
57 ns.decodeString(&m_track_name);
58 m_num_laps = ns.getUInt8();
59 m_reverse = ns.getUInt8()!=0;
60
61 } // PeerVote(NetworkString &)
62
63 // ------------------------------------------------------
66 {
67 ns->encodeString(m_player_name)
68 .encodeString(m_track_name)
69 .addUInt8(m_num_laps)
70 .addUInt8(m_reverse);
71 } // encode
72}; // class PeerVote
73
74#endif // PEER_VOTE_HPP
uint8_t getUInt8() const
Returns an unsigned 8-bit integer.
Definition: network_string.hpp:346
int decodeString(std::string *out) const
Returns a string at the given position.
Definition: network_string.cpp:104
BareNetworkString & addUInt8(const uint8_t value)
Add 8 bit unsigned int.
Definition: network_string.hpp:210
BareNetworkString & encodeString(const std::string &value)
Adds one byte for the length of the string, and then (up to 255 of) the characters of the given strin...
Definition: network_string.cpp:79
int decodeStringW(irr::core::stringw *out) const
Returns an irrlicht wide string from the utf8 encoded string at the given position.
Definition: network_string.cpp:120
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
A simple structure to store a vote from a client: track name, number of laps and reverse or not.
Definition: peer_vote.hpp:30
PeerVote(NetworkString &ns)
Initialised this object from a data in a network string.
Definition: peer_vote.hpp:54
void encode(NetworkString *ns)
Encodes this vote object into a network string.
Definition: peer_vote.hpp:65
Defines functions to easily manipulate 8-bit network destinated strings.