-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpropeller.h
More file actions
123 lines (106 loc) · 3.43 KB
/
propeller.h
File metadata and controls
123 lines (106 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Propeller Arena game server.
Copyright 2026 Flyinghead <flyinghead.github@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 3 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, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "model.h"
enum PropMessages : uint8_t
{
IN_SET_PLAYER_ATTRS = 0,
IN_GET_ROOM_ATTRS = 1,
IN_GAME_STARTING = 2,
IN_SET_ROOM_ATTRS = 3,
IN_GAME_OVER = 4,
IN_GAME_START = 6,
IN_GAME_STOP = 7,
IN_GAME_CDATA = 0xa,
IN_GAME_HDATA2 = 0xb,
IN_GAME_HDATA = 0xc,
IN_GAME_ENDED = 0xe,
OUT_SET_PLAYER_ATTRS = 0xf,
OUT_PLAYER_LIST = 0x10,
OUT_SET_ROOM_ATTRS = 0x12,
OUT_SET_RNG_SEED = 0x13,
OUT_AUDIO = 0x14,
OUT_ACK_PLAYER_ATTRS = 0x18,
OUT_GAME_DATA_AUDIO = 0x1c,
OUT_GAME_DATA = 0x1d,
OUT_UPDATE_SCORE = 0x1e,
};
class PARoom : public Room
{
public:
struct PlayerState
{
uint8_t plane = 0;
uint8_t flags = 0;
uint8_t rank = 0;
uint8_t score = 0;
std::array<uint8_t, 0x3c> data {};
std::array<uint8_t, 0x28> audio {};
bool rankUpdated = false;
bool inGame = false;
uint16_t seqnum = 0;
float flightDist = 0.f;
uint32_t kills = 0;
uint32_t deaths = 0;
uint32_t wins = 0;
};
PARoom(Lobby& lobby, uint32_t id, const std::string& name, uint32_t attributes, Player *owner, asio::io_context& io_context);
bool removePlayer(Player *player) override;
void updateSettings(int stage, int maxPoints, uint8_t flags, uint8_t field2, uint8_t field3);
void setPlane(Player *player, uint8_t plane);
void setPlayerFlags(Player *player, uint8_t flags);
void setRank(Player *player, uint8_t rank);
void setStartState(uint8_t state) { startState = state; }
void setStateData(int slot, const uint8_t *data);
void setAudio(uint8_t slot, const uint8_t *data);
const PlayerState& getPlayerState(int i) const { return playerState[i]; }
void setInGame(Player *player, bool inGame);
void gameStop(Player *player);
void sendRankUpdate(Player *player, uint32_t flightTime, Packet& packet);
void sendPlayerList(Packet& packet);
void sendRoomAttrs(Packet& packet);
void sendRngSeed(Packet& packet);
void resetState();
private:
void sendGameData(const std::error_code& ec);
uint8_t controllingSlot(uint8_t slot) const {
return (slot + players.size()) % players.size();
}
int stage = 0;
int maxPoints = 0;
uint8_t flags = 0x72;
int slots = 0;
uint8_t field2 = 0;
uint8_t field3 = 0;
uint8_t startState = 0;
uint32_t rngSeed;
std::array<PlayerState, 6> playerState;
asio::steady_timer timer;
bool timerStarted = false;
uint8_t talkingSlot = 0xff;
uint8_t audioSeq = 1;
time_point audioStart;
};
class PropellerServer : public LobbyServer
{
public:
PropellerServer(uint16_t port, asio::io_context& io_context)
: LobbyServer(Game::PropellerA, port, io_context) {}
Room *addRoom(const std::string& name, uint32_t attributes, Player *owner) override;
protected:
bool handlePacket(Player *player, const uint8_t *data, size_t len) override;
private:
void sendPlayerAttrs(Player *player);
};