wavelength 1.0.0
Loading...
Searching...
No Matches
hostpadrt.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include <librtdme.h>
7
8#include "app/msgsink.h"
9#include "game/netgamescore.h"
10#include "netflow/launchpadrt.h"
14#include "os/string.h"
15
16class ChatMsg;
17class ClientInfoPkt;
18class DataAckPkt;
19class TimeRequestPkt;
20
29class HostpadRT : public LaunchpadRT {
30public:
36 struct ClientClr {
37 int mColor;
38 int mPlayer;
39 };
40
46 class ClientData {
47 public:
57 ClientData(int nId, int nRank, int nRating) : mId(nId), mRank(nRank), mRating(nRating) {
58 }
59
68 bool operator==(const ClientData &other) const {
69 return mId == other.mId;
70 }
71
81 static bool HigherRating(const ClientData &left, const ClientData &right) {
82 return right.mRating < left.mRating;
83 }
84
85 int mId;
86 int mRank;
87 int mRating;
88 };
89
91 static constexpr int kMaxPlayers = 4;
92
101 static void Create(MsgSink *pScreen, MsgSink *pGame);
102
111 HostpadRT(MsgSink *pScreen, MsgSink *pGame);
112
119 ~HostpadRT() override;
120
127 void EndEdit() override;
128
136 bool ShareRemix() override;
137
147 int Launch() override;
148
156 void BootPlayer(int nPlayer) override;
157
164 void ReportNow() override;
165
173 void SetLocalId(int nId) override;
174
182 void AddClient(int nId) override;
183
191 void RemovePlayer(int nId) override;
192
200 float GetTime() override;
201
208 void OnConnected() override;
209
216 void PollPriv() override;
217
224 void EndGame() override;
225
233 void SendRating(int nRank) override;
234
243 bool DispatchPriv(Message *pMsg) override;
244
254
265 bool StartShare(int nShareOnly);
266
277 void Kick(int nId, int nBan);
278
288 void SendScores(const std::vector<NetGameScore> &scores);
289
298 void PollStart();
299
309
319 void PollShare();
320
330 int CanJoin();
331
342
353 int AssignColor(int nId);
354
364 void FreeColor(int nId);
365
374 void SendRanks();
375
384 bool OnMsg(ClientInfoPkt *pPkt);
385
395
404 bool OnMsg(DataAckPkt *pPkt);
405
414 bool OnMsg(ChatMsg *pMsg);
415
425
426 using LaunchpadRT::OnMsg;
427
429 int GetMgclConnected() const {
430 return mMgclConnected;
431 }
432
434 void SetMgclConnected(int nValue) {
435 mMgclConnected = nValue;
436 }
437
439 int GetLost() const {
440 return mLost;
441 }
442
444 const rtNetConnectionInfo &GetServerInfo() const {
445 return mServerInfo;
446 }
447
449 void SetServerInfo(const rtNetConnectionInfo &info) {
450 mServerInfo = info;
451 }
452
454 const String &GetSessionKey() const {
455 return mSessionKey;
456 }
457
459 void SetSessionKey(const char *pszSessionKey) {
460 mSessionKey = pszSessionKey;
461 }
462
465 return mParams;
466 }
467
469 const NetGameParams &GetParams() const {
470 return mParams;
471 }
472
475 return mShareTask;
476 }
477
479 int GetSharing() const {
480 return mSharing;
481 }
482
484 void SetSharing(int nValue) {
485 mSharing = nValue;
486 }
487
488private:
489 int mMgclConnected;
490 int mLost;
491 rtNetConnectionInfo mServerInfo;
492 String mSessionKey;
493 NetGameParams mParams;
494 PeriodicTask mServerReport;
495 PeriodicTask mWorldReport;
496 NetMultiTask mShareTask;
497 std::vector<ClientClr> mColors;
498#ifndef VIDEO_STANDARD_PAL
499 float mSyncDeadline;
500#endif
501 unsigned char mKey[kKeySize];
502 std::vector<int> mRecipients;
503 std::vector<int> mAwaiting;
504 std::vector<ClientData> mClientData;
505 int mSharing;
506 int mBlock;
507 int mBlockCount;
508 int mRemixShared;
509 float mBlockDeadline;
510};
511
518extern HostpadRT *TheHostpadRT;
Message with one line of chat between the consoles of an online session or lobby.
Definition chatmsg.h:24
Packet that describes one player of the session.
Definition clientinfopkt.h:21
Packet that delivers the new rating of a player after an online game.
Definition clientratingpkt.h:21
Packet a guest sends the host to acknowledge a DataBlockPkt.
Definition dataackpkt.h:21
ClientData(int nId, int nRank, int nRating)
Construct an entry.
Definition hostpadrt.h:57
static bool HigherRating(const ClientData &left, const ClientData &right)
Report whether an entry has a higher rating than another, the order of SendRanks().
Definition hostpadrt.h:81
bool operator==(const ClientData &other) const
Report whether two entries are of the same player.
Definition hostpadrt.h:68
int mRating
Definition hostpadrt.h:87
int mId
Definition hostpadrt.h:85
int mRank
Definition hostpadrt.h:86
The online session of a console that hosts it.
Definition hostpadrt.h:29
int GetMgclConnected() const
Definition hostpadrt.h:429
void SetMgclConnected(int nValue)
Definition hostpadrt.h:434
void OnConnected() override
Report HostLaunchpadSuccessMsg to the sink of mConnectTask.
void SetSharing(int nValue)
Definition hostpadrt.h:484
void RemovePlayer(int nId) override
Free the colour of a player who left, and forget the player.
bool OnMsg(ClientInfoPkt *pPkt)
Enter a console whose player arrived, or remove it when the session is full.
void BootPlayer(int nPlayer) override
Ban a guest from the session and remove the guest.
void SetServerInfo(const rtNetConnectionInfo &info)
Definition hostpadrt.h:449
bool OnMsg(ChatMsg *pMsg)
Send the key of the session to the account that requested it.
int GetSharing() const
Definition hostpadrt.h:479
const NetGameParams & GetParams() const
Definition hostpadrt.h:469
NetGameParams & GetParams()
Definition hostpadrt.h:464
void SetSessionKey(const char *pszSessionKey)
Definition hostpadrt.h:459
void ReportNow() override
Send the reports to the game server at the next poll.
void SendRanks()
Rank the players by rating and send the ranks to every console.
void PollShare()
Send the next block of the remix once every guest acknowledged the last, and remove the guests too sl...
void SendGameParams()
Send the settings of the game to every console, and send the world report at the next poll.
bool DispatchPriv(Message *pMsg) override
Act on a packet of the session, before LaunchpadRT does.
void FreeColor(int nId)
Free the colour of a player.
bool ShareRemix() override
Share the remix of the game with the guests only.
void EndEdit() override
Take the settings of the game again and publish them once the remix name is filtered.
void PollPriv() override
Poll the reports and the share, and watch the connection to the game server.
static constexpr int kMaxPlayers
The number of slots of a session.
Definition hostpadrt.h:91
bool OnMsg(ClientRatingPkt *pPkt)
Take the rating of a player and send the ranks again.
~HostpadRT() override
Stop mShareTask and clear TheHostpadRT.
float GetTime() override
Report the clock of this console, the clock of the session.
const String & GetSessionKey() const
Definition hostpadrt.h:454
NetMultiTask & GetShareTask()
Definition hostpadrt.h:474
bool StartShare(int nShareOnly)
Share the remix of the game with every guest once every player is ready.
void KickUnloaded()
Remove every guest that has not loaded the song.
void SendRating(int nRank) override
Send the rating of the host and note it in mClientData.
int CanJoin()
Report whether the session takes another player.
HostpadRT(MsgSink *pScreen, MsgSink *pGame)
Construct the session, draw its key, and start mConnectTask.
int Launch() override
Load the song on every console once every player is ready.
void EndGame() override
Leave the game and send the reports.
void PollStart()
Start the song once every console loaded it, and remove the consoles too slow to load.
void AddClient(int nId) override
Welcome a console that connected, or turn it away.
int GetLost() const
Definition hostpadrt.h:439
void SendScores(const std::vector< NetGameScore > &scores)
Send the final scores to every console, rate the game, and leave it.
bool OnMsg(TimeRequestPkt *pPkt)
Answer the clock of the session.
static void Create(MsgSink *pScreen, MsgSink *pGame)
Start hosting a session.
bool OnMsg(DataAckPkt *pPkt)
Note a guest that received the last block of the remix.
void SetLocalId(int nId) override
Take the identifier of this console and enter the host as the first player.
int AssignColor(int nId)
Give a player the first free colour.
int GetWorldStatus()
Report the state of the session for the game server.
void Kick(int nId, int nBan)
Remove a guest from the session, and ban the guest from the game server first.
const rtNetConnectionInfo & GetServerInfo() const
Definition hostpadrt.h:444
LaunchpadRT(MsgSink *pGame)
Construct the session, stored in TheNetLaunchpad and TheLaunchpadRT.
static constexpr int kKeySize
The size of the key of the session in bytes.
Definition launchpadrt.h:73
bool OnMsg(ClientStatusPkt *pPkt)
Take the state of a player.
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 settings of an online game that the host publishes with its session.
Definition netgameparams.h:13
A request to the online library, as the NetTask steps that run one after another.
Definition netmultitask.h:14
A task that runs again a fixed time after each run ends.
Definition periodictask.h:12
Growable text buffer that is also a PrnStream.
Definition string.h:19
Packet that asks a console for its clock, to measure the delay to it.
Definition timerequestpkt.h:20
HostpadRT * TheHostpadRT
The hosted session, or null.
The colour of a slot of the session and the player who holds it.
Definition hostpadrt.h:36
int mPlayer
Definition hostpadrt.h:38
int mColor
Definition hostpadrt.h:37