-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
351 additions
and
224 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
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,18 @@ | ||
local mod = Solution.Util.CreateModuleTable("Gameplay", { "base", "network" }) | ||
|
||
Solution.Util.CreateStaticLib(mod.Name, Solution.Projects.Current.BinDir, mod.Dependencies, function() | ||
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS" } | ||
|
||
Solution.Util.SetLanguage("C++") | ||
Solution.Util.SetCppDialect(20) | ||
|
||
local files = Solution.Util.GetFilesForCpp(mod.Path) | ||
Solution.Util.SetFiles(files) | ||
Solution.Util.SetIncludes(mod.Path) | ||
Solution.Util.SetDefines(defines) | ||
end) | ||
|
||
Solution.Util.CreateDep(mod.NameLow, mod.Dependencies, function() | ||
Solution.Util.SetIncludes(mod.Path) | ||
Solution.Util.SetLinks(mod.Name) | ||
end) |
Empty file.
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,10 @@ | ||
#include "Base/Types.h" | ||
|
||
namespace Network | ||
{ | ||
enum class ConnectionStatus : u8 | ||
{ | ||
None, | ||
Connected | ||
}; | ||
} |
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,33 @@ | ||
#include "GameMessageRouter.h" | ||
|
||
#include "Base/Memory/Bytebuffer.h" | ||
|
||
namespace Network | ||
{ | ||
GameMessageRouter::GameMessageRouter() { } | ||
|
||
void GameMessageRouter::SetMessageHandler(GameOpcode opcode, GameMessageHandler&& handler) | ||
{ | ||
_handlers[static_cast<u16>(opcode)] = std::move(handler); | ||
} | ||
|
||
bool GameMessageRouter::CallHandler(SocketID socketID, std::shared_ptr<Bytebuffer>& packet) | ||
{ | ||
Network::PacketHeader header; | ||
if (!packet->Get(header)) | ||
return false; | ||
|
||
GameOpcode opcode = static_cast<GameOpcode>(header.opcode); | ||
if (opcode == GameOpcode::Invalid || opcode >= GameOpcode::Count) | ||
return false; | ||
|
||
const GameMessageHandler& opcodeHandler = _handlers[static_cast<u16>(header.opcode)]; | ||
bool isSmallerThanMinSize = header.size < opcodeHandler.minSize; | ||
bool isLargerThanMaxSize = header.size > opcodeHandler.maxSize && opcodeHandler.maxSize != -1; | ||
|
||
if (!opcodeHandler.handler || isSmallerThanMinSize || isLargerThanMaxSize) | ||
return false; | ||
|
||
return opcodeHandler.handler(socketID, packet); | ||
} | ||
} |
Oops, something went wrong.