wavelength 1.0.0
Loading...
Searching...
No Matches
launchpadrt.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <memory>
5#include <vector>
6
7#include <librtdme.h>
8
9#include "app/msgsink.h"
10#include "game/netgamescore.h"
14#include "netflow/nettask.h"
16#include "netflow/ratingstat.h"
17#include "netflow/tasklist.h"
18
20class ClientRatingPkt;
21class ClientStatusPkt;
22class LoadGamePkt;
23class Message;
24class Packet;
25class StartGamePkt;
26class UpdateRanksPkt;
27
41class LaunchpadRT : public NetLaunchpad, public MsgSink {
42public:
51
59
61 static constexpr int kHostId = 0;
62
64 static constexpr int kNoId = -2;
65
67 static constexpr int kNoWorld = -1;
68
70 static constexpr int kKeyChannel = 4;
71
73 static constexpr int kKeySize = 16;
74
76 static constexpr int kMaxClients = 5;
77
79 static constexpr int kGameHostPeerToPeer = 2;
80
91 explicit LaunchpadRT(MsgSink *pGame);
92
99 ~LaunchpadRT() override;
100
108 void Cancel(MsgSink *pSink) override;
109
116 void Activate() override;
117
124 void NotifyLoaded() override;
125
133 int IsGuest() override;
134
142 int GetPlayersVersion() override;
143
153 std::list<NetLaunchpadPlayer> *GetPlayers() override {
154 return &mPlayers;
155 }
156
165 virtual void ReportNow();
166
176 virtual void SetLocalId(int nId);
177
188 virtual void AddClient(int nId);
189
197 virtual void RemovePlayer(int nId);
198
206 virtual float GetTime() = 0;
207
213 virtual void OnConnected() = 0;
214
220 virtual void PollPriv() = 0;
221
231 virtual void EndGame();
232
242 virtual void SendRating(int nRank);
243
252 bool DispatchPriv(Message *pMsg) override;
253
263 void SetReady(int nReady);
264
275 int Poll();
276
286
295
303 void AddPlayer(const NetLaunchpadPlayer &player);
304
313 void StartGame();
314
324 void DropRating(int nId);
325
335 void RateGame(const std::vector<NetGameScore> &scores);
336
346
357 void Exit(MsgSink *pSink, int nReason);
358
369 int FindIdByAccount(int nAccountId);
370
380 void Abort(int nReason);
381
389 void Send(Packet *pPacket);
390
399 void Leave();
400
410
420
430
440
449 bool OnMsg(LoadGamePkt *pPkt);
450
459 bool OnMsg(StartGamePkt *pPkt);
460
470
480
490 static int RegisterMessages();
491
501 static void SetMgclReady(int nReady);
502
512 static int IsMgclReady();
513
515 static NetTask *GetNetTask() {
516 return sNetTask;
517 }
518
520 static void SetNetTask(NetTask *pTask) {
521 sNetTask = pTask;
522 }
523
534 static unsigned char DecodeByte(const char *pszText);
535
546 static void EncodeByte(char *pszText, unsigned char nByte);
547
559 static int FindScore(const std::vector<NetGameScore> &scores, int nId);
560
562 int GetWorldId() const {
563 return mWorldId;
564 }
565
567 void SetWorldId(int nValue) {
568 mWorldId = nValue;
569 }
570
572 const rtNetConnectionInfo &GetConnectionInfo() const {
573 return mConnectionInfo;
574 }
575
577 void SetConnectionInfo(const rtNetConnectionInfo &info) {
578 mConnectionInfo = info;
579 }
580
582 int GetConnection() const {
583 return mConnection;
584 }
585
587 void SetConnection(int nValue) {
588 mConnection = nValue;
589 }
590
592 int GetLocalId() const {
593 return mLocalId;
594 }
595
597 void SetLocalIdValue(int nValue) {
598 mLocalId = nValue;
599 }
600
602 int GetState() const {
603 return mState;
604 }
605
607 void SetState(int nValue) {
608 mState = nValue;
609 }
610
612 int GetError() const {
613 return mError;
614 }
615
617 void SetError(int nValue) {
618 mError = nValue;
619 }
620
623 return mGameSink;
624 }
625
627 std::list<NetLaunchpadPlayer> &GetPlayersList() {
628 return mPlayers;
629 }
630
632 const std::vector<int> &GetClients() const {
633 return mClients;
634 }
635
650 static int Receive(int nConnection, int nType, int nSender, rtDmeMessage *pMessage);
651
665 static void OnNetConnect(int nConnection, int nReserved1, int nReserved2, int nStatus);
666
678 static void OnNetClientJoin(int nConnection, int nClient, const char *pszAddress);
679
691 static void OnNetClientLeave(int nConnection, int nClient, const char *pszAddress);
692
693protected:
695 rtNetConnectionInfo mConnectionInfo;
698 int mState;
699 int mError;
706 std::list<NetLaunchpadPlayer> mPlayers;
708 int mSeed;
713#ifdef VIDEO_STANDARD_PAL
718 float mSyncDeadline = 0.0f;
719#endif
720 std::vector<int> mClients;
721 std::vector<RatingStat> mRatings;
722
723private:
730 static int sMessageType;
731
738 static int sMgclReady;
739
746 static int sPlayersVersion;
747
754 static NetTask *sNetTask;
755};
756
763extern std::unique_ptr<LaunchpadRT> TheLaunchpadRT;
Packet a console sends every peer when it leaves the song early.
Definition clientabortedpkt.h:21
Packet that delivers the new rating of a player after an online game.
Definition clientratingpkt.h:21
Packet that reports the state of a console of the session.
Definition clientstatuspkt.h:20
int GetPlayersVersion() override
Report sPlayersVersion.
LaunchpadRT(MsgSink *pGame)
Construct the session, stored in TheNetLaunchpad and TheLaunchpadRT.
MsgSink * GetGameSink() const
Definition launchpadrt.h:622
void Leave()
Leave the game and tell the other consoles.
void Exit(MsgSink *pSink, int nReason)
End the game and start mExitTask.
NetMultiTask mConnectTask
Definition launchpadrt.h:701
bool OnMsg(ClientRatingPkt *pPkt)
Take the rating of a player.
void Cancel(MsgSink *pSink) override
Exit the session with reason 0.
void NotifyLoaded() override
Report this console loaded.
void StartGame()
Start the song, and rate the start of a rated game as a loss of this console.
int GetWorldId() const
Definition launchpadrt.h:562
int mInGame
Definition launchpadrt.h:712
static int IsMgclReady()
Report sMgclReady.
int Poll()
Service the session once per frame.
bool OnMsg(LoadGamePkt *pPkt)
Enter the game, and tell mGameSink to load the song.
void PlayersChanged()
Count a change of the players.
static int RegisterMessages()
Register the packets of the session with the session library.
virtual void SendRating(int nRank)
Vtable slot 20.
static void EncodeByte(char *pszText, unsigned char nByte)
Write a byte as two characters and a terminator.
void SetReady(int nReady)
Set the state of this console and send it to every console.
int GetLocalId() const
Definition launchpadrt.h:592
int mStarting
Definition launchpadrt.h:711
void CheckReady()
Report this console ready once the session is active and synced.
MsgSink * mGameSink
Definition launchpadrt.h:700
void RateGame(const std::vector< NetGameScore > &scores)
Rate the players from the final scores of the game, and clear the rating.
int GetState() const
Definition launchpadrt.h:602
static constexpr int kKeySize
The size of the key of the session in bytes.
Definition launchpadrt.h:73
static NetTask * GetNetTask()
Definition launchpadrt.h:515
virtual void EndGame()
Vtable slot 19.
Ready
Values of NetLaunchpadPlayer::mReady.
Definition launchpadrt.h:53
@ kReadyLoading
Definition launchpadrt.h:56
@ kReadyNo
Definition launchpadrt.h:54
@ kReadyLoaded
Definition launchpadrt.h:57
@ kReadyYes
Definition launchpadrt.h:55
std::list< NetLaunchpadPlayer > mPlayers
Definition launchpadrt.h:706
std::list< NetLaunchpadPlayer > & GetPlayersList()
Definition launchpadrt.h:627
int mSeed
Definition launchpadrt.h:708
static constexpr int kNoWorld
The value of mWorldId and mConnection without a session.
Definition launchpadrt.h:67
static int FindScore(const std::vector< NetGameScore > &scores, int nId)
Report the score of a player in the final scores.
void SetError(int nValue)
Definition launchpadrt.h:617
int mConnection
Definition launchpadrt.h:696
PeriodicTask mPlayerReport
Definition launchpadrt.h:704
static unsigned char DecodeByte(const char *pszText)
Read a byte EncodeByte() wrote.
void SetConnection(int nValue)
Definition launchpadrt.h:587
void UpdateRating()
Rate the player of this console from mRatings and publish the rating.
rtNetConnectionInfo mConnectionInfo
Definition launchpadrt.h:695
int FindIdByAccount(int nAccountId)
Find the identifier in the session of an account.
int mError
Definition launchpadrt.h:699
virtual void OnConnected()=0
Vtable slot 17.
virtual float GetTime()=0
Vtable slot 16.
NetMultiTask mExitTask
Definition launchpadrt.h:702
int mActive
Definition launchpadrt.h:709
void SetConnectionInfo(const rtNetConnectionInfo &info)
Definition launchpadrt.h:577
void Abort(int nReason)
Exit the session for mGameSink.
static constexpr int kGameHostPeerToPeer
The kind of host the session reports to the servers, a host among its peers.
Definition launchpadrt.h:79
static constexpr int kNoId
The identifier of a console that has none yet.
Definition launchpadrt.h:64
int GetConnection() const
Definition launchpadrt.h:582
static int Receive(int nConnection, int nType, int nSender, rtDmeMessage *pMessage)
Receive a message of the session, the handler rtDmeRegisterMessageHandler() registers.
bool OnMsg(StartGamePkt *pPkt)
Take the time the song starts at and the seed of the game.
virtual void RemovePlayer(int nId)
Vtable slot 15.
int mShareOnly
Definition launchpadrt.h:710
~LaunchpadRT() override
Stop the requests, and clear TheNetLaunchpad and TheLaunchpadRT.
void AddPlayer(const NetLaunchpadPlayer &player)
Insert a player before the first player with a higher colour.
int mWorldId
Definition launchpadrt.h:694
const std::vector< int > & GetClients() const
Definition launchpadrt.h:632
NetMultiTask mRankTask
Definition launchpadrt.h:703
static void OnNetConnect(int nConnection, int nReserved1, int nReserved2, int nStatus)
Receive the result of NetHostTask and NetConnectTask, and finish sNetTask.
std::vector< int > mClients
Definition launchpadrt.h:720
virtual void PollPriv()=0
Vtable slot 18.
int GetError() const
Definition launchpadrt.h:612
virtual void AddClient(int nId)
Vtable slot 14.
int IsGuest() override
Report mLocalId.
static void SetMgclReady(int nReady)
Set sMgclReady.
bool OnMsg(ClientAbortedPkt *pPkt)
Drop a player who exited the game, and end the game when the host exited.
NetLaunchpadPlayer * FindPlayer(int nId)
Find a player of the session.
static void OnNetClientJoin(int nConnection, int nClient, const char *pszAddress)
Note a console that connected to the session.
TaskList mTasks
Definition launchpadrt.h:705
State
Values of mState.
Definition launchpadrt.h:44
@ kStateConnecting
Definition launchpadrt.h:46
@ kStateSynced
Definition launchpadrt.h:49
@ kStateConnected
Definition launchpadrt.h:47
@ kStateFailed
Definition launchpadrt.h:45
@ kStateWelcomed
Definition launchpadrt.h:48
int mLocalId
Definition launchpadrt.h:697
static constexpr int kKeyChannel
The chat channel the session exchanges its key on.
Definition launchpadrt.h:70
NetLaunchpadPlayer * GetLocalPlayer()
Find the player of this console.
float mStartTime
Definition launchpadrt.h:707
bool DispatchPriv(Message *pMsg) override
Act on a packet of the session.
std::list< NetLaunchpadPlayer > * GetPlayers() override
Report mPlayers.
Definition launchpadrt.h:153
int mState
Definition launchpadrt.h:698
static constexpr int kMaxClients
The consoles a session takes on the session library and the game server.
Definition launchpadrt.h:76
virtual void SetLocalId(int nId)
Vtable slot 13.
static constexpr int kHostId
The identifier of the host in the session.
Definition launchpadrt.h:61
void Send(Packet *pPacket)
Encrypt a packet and send it to the consoles its receiver selects.
void SetWorldId(int nValue)
Definition launchpadrt.h:567
const rtNetConnectionInfo & GetConnectionInfo() const
Definition launchpadrt.h:572
void SetState(int nValue)
Definition launchpadrt.h:607
void Activate() override
Mark the session active, and report this console ready when it can be.
void SetLocalIdValue(int nValue)
Definition launchpadrt.h:597
bool OnMsg(UpdateRanksPkt *pPkt)
Take the ranks of the players.
static void OnNetClientLeave(int nConnection, int nClient, const char *pszAddress)
Remove a console that left the session.
std::vector< RatingStat > mRatings
Definition launchpadrt.h:721
void DropRating(int nId)
Rate a player who left as a loser, and drop every guest when the host left.
static void SetNetTask(NetTask *pTask)
Definition launchpadrt.h:520
virtual void ReportNow()
Vtable slot 12.
bool OnMsg(ClientStatusPkt *pPkt)
Take the state of a player.
Packet the host sends every console to load the song of the session.
Definition loadgamepkt.h:21
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Receiver of engine messages.
Definition msgsink.h:21
The online session a console hosts or joins, from its launchpad to the end of the song.
Definition netlaunchpad.h:15
A request to the online library, as the NetTask steps that run one after another.
Definition netmultitask.h:14
A step of a request to the online library, run by a NetMultiTask.
Definition nettask.h:17
Abstract base of a message that travels between consoles.
Definition packet.h:13
A task that runs again a fixed time after each run ends.
Definition periodictask.h:12
Packet the host sends every console to start the song at an agreed time.
Definition startgamepkt.h:20
Tasks that run side by side until each one ends.
Definition tasklist.h:13
Packet that reports the ranks of the players of the song.
Definition updaterankspkt.h:24
std::unique_ptr< LaunchpadRT > TheLaunchpadRT
The online session, or null outside one.
The description of one player of the online session this console is in.
Definition netlaunchpadplayer.h:13