-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some extra random indev networking code
- Loading branch information
Showing
10 changed files
with
269 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module; | ||
|
||
#include <SFML/Network.hpp> | ||
#include <string> | ||
|
||
export module ClientMessage; | ||
|
||
export import ClientMessageType; | ||
export import NetworkTypes; | ||
|
||
export struct [[nodiscard]] ClientMessage | ||
{ | ||
ClientMessageType type; | ||
PlayerIdType clientId; | ||
std::string clientName; | ||
std::string jsonData; // either map configuration JSON or input JSON | ||
|
||
// tick? | ||
|
||
static ClientMessage fromPacket(sf::Packet& packet) | ||
{ | ||
std::underlying_type_t<ClientMessageType> messageType; | ||
|
||
packet >> messageType; | ||
|
||
ClientMessage message; | ||
message.type = static_cast<ClientMessageType>(messageType); | ||
packet >> message.clientId; | ||
|
||
return message; | ||
} | ||
|
||
[[nodiscard]] sf::Packet toPacket() const | ||
{ | ||
sf::Packet packet; | ||
packet << static_cast<std::underlying_type_t<ClientMessageType>>(type); | ||
packet << clientId; | ||
return packet; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module; | ||
|
||
#include <cstdint> | ||
|
||
export module ClientMessageType; | ||
|
||
export enum class [[nodiscard]] ClientMessageType : uint8_t { | ||
ConnectionRequest, | ||
PeerSettingsUpdate, | ||
GameSettingsUpdate, | ||
CommitLobby, | ||
MapLoaded, | ||
ReportInput, | ||
Disconnect | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export module Network; | ||
|
||
export import Message; | ||
export import ClientData; | ||
export import Client; | ||
export import Server; | ||
export import Server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module; | ||
|
||
#include <cstdint> | ||
|
||
export module NetworkTypes; | ||
|
||
export using PlayerIdType = std::uint8_t; | ||
export using ChecksumType = std::uint64_t; |
Oops, something went wrong.