Compare commits
14 Commits
multi_plaf
...
main
Author | SHA1 | Date |
---|---|---|
|
c85e7c4db4 | ago%!(EXTRA string=3 months) |
|
67b2440096 | ago%!(EXTRA string=3 months) |
|
0f5e3e6d77 | ago%!(EXTRA string=3 months) |
|
856273e78f | ago%!(EXTRA string=4 months) |
|
0cf7329899 | ago%!(EXTRA string=4 months) |
|
0570a7ce7b | ago%!(EXTRA string=4 months) |
|
66483a3838 | ago%!(EXTRA string=12 months) |
|
4e42346bad | ago%!(EXTRA string=12 months) |
|
1fbd6426cd | ago%!(EXTRA string=1 year) |
|
a8fdc938aa | ago%!(EXTRA string=1 year) |
|
aefddcf519 | ago%!(EXTRA string=1 year) |
|
fe6d8a33bc | ago%!(EXTRA string=1 year) |
|
8dee87c096 | ago%!(EXTRA string=1 year) |
|
9895eb5b98 | ago%!(EXTRA string=1 year) |
33 changed files with 311 additions and 357 deletions
@ -1,6 +0,0 @@ |
|||||||
[submodule "vendor/spdlog"] |
|
||||||
path = vendor/spdlog |
|
||||||
url = https://github.com/gabime/spdlog |
|
||||||
[submodule "vendor/bakatools"] |
|
||||||
path = vendor/bakatools |
|
||||||
url = https://github.com/anulax1225/bakatools |
|
@ -1,82 +0,0 @@ |
|||||||
project "bakanet" |
|
||||||
kind "StaticLib" |
|
||||||
language "C++" |
|
||||||
cppdialect "C++20" |
|
||||||
systemversion "latest" |
|
||||||
staticruntime "on" |
|
||||||
|
|
||||||
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
|
||||||
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
|
||||||
|
|
||||||
defines |
|
||||||
{ |
|
||||||
"BKMOD_ALL" |
|
||||||
} |
|
||||||
|
|
||||||
includedirs |
|
||||||
{ |
|
||||||
"%{IncludeDirs.spdlog}", |
|
||||||
"%{IncludeDirs.bakanet}", |
|
||||||
"%{IncludeDirs.bakatools}" |
|
||||||
} |
|
||||||
|
|
||||||
files |
|
||||||
{ |
|
||||||
"%{prj.location}/src/bakanet/**.h", |
|
||||||
"%{prj.location}/src/bakanet/**.cpp", |
|
||||||
"%{prj.location}/src/baknetpch.h", |
|
||||||
} |
|
||||||
|
|
||||||
links |
|
||||||
{ |
|
||||||
"bakatools" |
|
||||||
} |
|
||||||
|
|
||||||
filter "system:windows" |
|
||||||
buildoptions "/MDd" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_PLATFORM_WINDOWS" |
|
||||||
} |
|
||||||
|
|
||||||
files |
|
||||||
{ |
|
||||||
"%{prj.location}/src/platform/windows/**.h", |
|
||||||
"%{prj.location}/src/platform/windows/**.cpp", |
|
||||||
} |
|
||||||
|
|
||||||
links |
|
||||||
{ |
|
||||||
"WS2_32.lib" |
|
||||||
} |
|
||||||
|
|
||||||
filter "system:linux" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_PLATFORM_LINUX" |
|
||||||
} |
|
||||||
|
|
||||||
files |
|
||||||
{ |
|
||||||
"%{prj.location}/src/platform/linux/**.h", |
|
||||||
"%{prj.location}/src/platform/linux/**.cpp", |
|
||||||
} |
|
||||||
|
|
||||||
filter "configurations:Debug" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_DEBUG", |
|
||||||
"DEBUG" |
|
||||||
} |
|
||||||
runtime "Debug" |
|
||||||
symbols "on" |
|
||||||
|
|
||||||
|
|
||||||
filter "configurations:Release" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_RELEASE", |
|
||||||
"NDEBUG" |
|
||||||
} |
|
||||||
runtime "Release" |
|
||||||
optimize "on" |
|
@ -1,95 +0,0 @@ |
|||||||
#include "linux_socket.h" |
|
||||||
|
|
||||||
namespace Bk::Net { |
|
||||||
LinuxSocket::LinuxSocket(int id, IpVersion ver, IpProtocol proto) |
|
||||||
: id(id), ip_proto(proto) |
|
||||||
{ |
|
||||||
char myIP[16] = " "; |
|
||||||
socklen_t len = sizeof(addr); |
|
||||||
getsockname(id, (struct sockaddr*)&addr, &len); |
|
||||||
inet_ntop((int)ver, &addr, myIP, sizeof(myIP)); |
|
||||||
ip_addr = IpAddress(std::string(myIP, 16), ver); |
|
||||||
} |
|
||||||
|
|
||||||
LinuxSocket::LinuxSocket(IpAddress ip, int port, IpProtocol proto) |
|
||||||
: ip_addr(ip), ip_proto(proto) |
|
||||||
{ |
|
||||||
//LinuxSocket creation step
|
|
||||||
if ((id = socket((int)ip_addr.version, (int)ip_proto, 0)) < 0)
|
|
||||||
{ |
|
||||||
BK_CORE_ERROR("Socket failed"); |
|
||||||
exit(EXIT_FAILURE); |
|
||||||
} |
|
||||||
addr.sin_addr = ip_addr.get_data(); |
|
||||||
addr.sin_family = (int)ip_addr.version; |
|
||||||
addr.sin_port = htons(port); |
|
||||||
} |
|
||||||
|
|
||||||
LinuxSocket::~LinuxSocket() |
|
||||||
{ |
|
||||||
close(id); |
|
||||||
} |
|
||||||
|
|
||||||
bool LinuxSocket::init() |
|
||||||
{ |
|
||||||
//Binding step
|
|
||||||
int status; |
|
||||||
if ((status = bind(id, (struct sockaddr*)&addr, sizeof(addr)) < 0))
|
|
||||||
{ |
|
||||||
BK_CORE_ERROR("Binding failed"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
bool LinuxSocket::start(int cpt_conn) |
|
||||||
{ |
|
||||||
//Listening step
|
|
||||||
if (listen(id, cpt_conn) < 0)
|
|
||||||
{ |
|
||||||
BK_CORE_ERROR("Listening failed"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
std::unique_ptr<Socket> LinuxSocket::ack() |
|
||||||
{ |
|
||||||
socklen_t addrlen = sizeof(addr); |
|
||||||
return std::unique_ptr<Socket>(Socket::create(accept(id, (struct sockaddr*)&addr, &addrlen), ip_addr.version, ip_proto)); |
|
||||||
} |
|
||||||
|
|
||||||
bool LinuxSocket::conn() |
|
||||||
{ |
|
||||||
if (connect(id, (struct sockaddr*)&addr, sizeof(addr)) < 0)
|
|
||||||
{ |
|
||||||
BK_CORE_ERROR("Connection failed"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
void LinuxSocket::emit(std::vector<char> packet) |
|
||||||
{ |
|
||||||
write(id, packet.data(), packet.size()); |
|
||||||
} |
|
||||||
|
|
||||||
std::vector<char> LinuxSocket::obtain(int size) |
|
||||||
{ |
|
||||||
std::vector<char> buffer; |
|
||||||
buffer.resize(size); |
|
||||||
int read_size = read(id, buffer.data(), buffer.size() - 1); |
|
||||||
buffer.resize(read_size); |
|
||||||
return buffer; |
|
||||||
} |
|
||||||
|
|
||||||
std::unique_ptr<Socket> Socket::create(IpAddress ip, int port, IpProtocol proto) |
|
||||||
{ |
|
||||||
return std::unique_ptr<Socket>(new LinuxSocket(ip, port, proto)); |
|
||||||
} |
|
||||||
|
|
||||||
std::unique_ptr<Socket> Socket::create(int id, IpVersion ver, IpProtocol proto) |
|
||||||
{ |
|
||||||
return std::unique_ptr<Socket>(new LinuxSocket(id, ver, proto)); |
|
||||||
} |
|
||||||
} |
|
@ -1,23 +0,0 @@ |
|||||||
|
|
||||||
|
|
||||||
handle_error() { |
|
||||||
echo "An error occurred on line $1" |
|
||||||
exit 1 |
|
||||||
} |
|
||||||
trap 'handle_error $LINENO' ERR |
|
||||||
|
|
||||||
if [ "-clear" == "$1" ]; then |
|
||||||
rm -rf bin bin-int |
|
||||||
fi |
|
||||||
|
|
||||||
if [ "-clear" == "$2" ]; then |
|
||||||
rm -rf bin bin-int |
|
||||||
fi |
|
||||||
|
|
||||||
clear |
|
||||||
premake5 gmake2 |
|
||||||
make |
|
||||||
|
|
||||||
if [ "-exec" == "$1" ]; then |
|
||||||
./bin/linux-x86_64-Debug/server/server |
|
||||||
fi |
|
@ -0,0 +1,5 @@ |
|||||||
|
IncludeDirs["bakanet"] = "%{wks.location}/vendor/bakanet/src/" |
||||||
|
|
||||||
|
group "Bakanet" |
||||||
|
include "vendor/bakanet" |
||||||
|
group "" |
@ -0,0 +1,20 @@ |
|||||||
|
{ |
||||||
|
"name": "Bakanet", |
||||||
|
"author": "Anulax", |
||||||
|
"git": "https://github.com/anulax1225/bakanet", |
||||||
|
"links": |
||||||
|
[ |
||||||
|
"bakanet" |
||||||
|
], |
||||||
|
"includes": |
||||||
|
[ |
||||||
|
"bakanet" |
||||||
|
], |
||||||
|
"packages": |
||||||
|
[ |
||||||
|
{ |
||||||
|
"author": "anulax", |
||||||
|
"name": "bakatools" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -1,27 +1,77 @@ |
|||||||
workspace "BakaraNet" |
project "bakanet" |
||||||
architecture "x64" |
kind "StaticLib" |
||||||
configurations { "Debug", "Release" } |
language "C++" |
||||||
startproject "server" |
cppdialect "C++20" |
||||||
flags |
systemversion "latest" |
||||||
{ |
staticruntime "on" |
||||||
"MultiProcessorCompile" |
|
||||||
} |
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
||||||
|
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
||||||
outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}" |
|
||||||
|
includedirs |
||||||
IncludeDirs = {} |
{ |
||||||
IncludeDirs["bakanet"] = "%{wks.location}/bakanet/src/" |
"%{IncludeDirs.spdlog}", |
||||||
IncludeDirs["bakatools"] = "%{wks.location}/vendor/bakatools/src/" |
"%{IncludeDirs.bakanet}", |
||||||
IncludeDirs["spdlog"] = "%{wks.location}/vendor/spdlog/include" |
"%{IncludeDirs.bakatools}" |
||||||
|
} |
||||||
group "BakaModules" |
|
||||||
include "vendor/bakatools" |
files |
||||||
group "" |
{ |
||||||
|
"%{prj.location}/src/bakanet/**.h", |
||||||
group "NetCore" |
"%{prj.location}/src/bakanet/**.cpp", |
||||||
include "bakanet" |
"%{prj.location}/src/baknetpch.h", |
||||||
group "" |
} |
||||||
|
|
||||||
group "Sandbox" |
links |
||||||
include "sandbox" |
{ |
||||||
group "" |
"bakatools" |
||||||
|
} |
||||||
|
|
||||||
|
filter "system:windows" |
||||||
|
buildoptions { "/MT", "/utf-8" } |
||||||
|
defines |
||||||
|
{ |
||||||
|
"BK_PLATFORM_WINDOWS" |
||||||
|
} |
||||||
|
|
||||||
|
files |
||||||
|
{ |
||||||
|
"%{prj.location}/src/platform/windows/**.h", |
||||||
|
"%{prj.location}/src/platform/windows/**.cpp", |
||||||
|
} |
||||||
|
|
||||||
|
links |
||||||
|
{ |
||||||
|
"WS2_32.lib" |
||||||
|
} |
||||||
|
|
||||||
|
filter "system:linux" |
||||||
|
defines |
||||||
|
{ |
||||||
|
"BK_PLATFORM_LINUX" |
||||||
|
} |
||||||
|
|
||||||
|
files |
||||||
|
{ |
||||||
|
"%{prj.location}/src/platform/linux/**.h", |
||||||
|
"%{prj.location}/src/platform/linux/**.cpp", |
||||||
|
} |
||||||
|
|
||||||
|
filter "configurations:Debug" |
||||||
|
defines |
||||||
|
{ |
||||||
|
"BK_DEBUG", |
||||||
|
"DEBUG" |
||||||
|
} |
||||||
|
runtime "Debug" |
||||||
|
symbols "on" |
||||||
|
|
||||||
|
|
||||||
|
filter "configurations:Release" |
||||||
|
defines |
||||||
|
{ |
||||||
|
"BK_RELEASE", |
||||||
|
"NDEBUG" |
||||||
|
} |
||||||
|
runtime "Release" |
||||||
|
optimize "on" |
@ -1,66 +0,0 @@ |
|||||||
project "server" |
|
||||||
location "./server" |
|
||||||
kind "ConsoleApp" |
|
||||||
language "C++" |
|
||||||
cppdialect "C++20" |
|
||||||
systemversion "latest" |
|
||||||
|
|
||||||
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") |
|
||||||
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") |
|
||||||
|
|
||||||
defines |
|
||||||
{ |
|
||||||
"BKMOD_ALL" |
|
||||||
} |
|
||||||
|
|
||||||
includedirs |
|
||||||
{ |
|
||||||
"%{IncludeDirs.spdlog}", |
|
||||||
"%{IncludeDirs.bakanet}", |
|
||||||
"%{IncludeDirs.bakatools}" |
|
||||||
} |
|
||||||
|
|
||||||
files |
|
||||||
{ |
|
||||||
"%{prj.location}/**.h", |
|
||||||
"%{prj.location}/**.cpp", |
|
||||||
} |
|
||||||
|
|
||||||
links |
|
||||||
{ |
|
||||||
"bakanet", |
|
||||||
"bakatools" |
|
||||||
} |
|
||||||
|
|
||||||
filter "system:linux" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_PLATFORM_LINUX" |
|
||||||
} |
|
||||||
|
|
||||||
filter "system:windows" |
|
||||||
buildoptions "/MDd" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_PLATFORM_WINDOWS" |
|
||||||
} |
|
||||||
|
|
||||||
filter "configurations:Debug" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_DEBUG", |
|
||||||
"DEBUG" |
|
||||||
} |
|
||||||
runtime "Debug" |
|
||||||
symbols "on" |
|
||||||
|
|
||||||
filter "configurations:Release" |
|
||||||
defines |
|
||||||
{ |
|
||||||
"BK_RELEASE", |
|
||||||
"NDEBUG" |
|
||||||
} |
|
||||||
runtime "Release" |
|
||||||
optimize "on" |
|
||||||
|
|
||||||
|
|
@ -0,0 +1,104 @@ |
|||||||
|
#include "linux_socket.h" |
||||||
|
#include <cstddef> |
||||||
|
#include <unistd.h> |
||||||
|
#include <netinet/in.h> |
||||||
|
#include <sys/socket.h> |
||||||
|
|
||||||
|
namespace Bk::Net { |
||||||
|
LinuxSocket::LinuxSocket(int id, struct sockaddr_in client_addr, IpVersion ver, IpProtocol proto) |
||||||
|
: id(id), ip_proto(proto), addr(client_addr) |
||||||
|
{ |
||||||
|
char* myIP = inet_ntoa(addr.sin_addr); |
||||||
|
ip_addr = IpAddress(std::string(myIP), ver); |
||||||
|
} |
||||||
|
|
||||||
|
LinuxSocket::LinuxSocket(IpAddress ip, int port, IpProtocol proto) |
||||||
|
: ip_addr(ip), ip_proto(proto) |
||||||
|
{ |
||||||
|
//LinuxSocket creation step
|
||||||
|
if ((id = socket((int)ip_addr.version, (int)ip_proto, 0)) < 0)
|
||||||
|
{ |
||||||
|
BK_CORE_ERROR("Socket failed"); |
||||||
|
exit(EXIT_FAILURE); |
||||||
|
} |
||||||
|
addr.sin_addr = ip_addr.get_data(); |
||||||
|
addr.sin_family = (int)ip_addr.version; |
||||||
|
addr.sin_port = htons(port); |
||||||
|
} |
||||||
|
|
||||||
|
LinuxSocket::~LinuxSocket() |
||||||
|
{ |
||||||
|
if(id > 0) close(id); |
||||||
|
} |
||||||
|
|
||||||
|
bool LinuxSocket::init() |
||||||
|
{ |
||||||
|
//Binding step
|
||||||
|
int status; |
||||||
|
if ((status = bind(id, (struct sockaddr*)&addr, sizeof(addr)) < 0))
|
||||||
|
{ |
||||||
|
BK_CORE_ERROR("Binding failed"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool LinuxSocket::start(int cpt_conn) |
||||||
|
{ |
||||||
|
//Listening step
|
||||||
|
if (listen(id, cpt_conn) < 0)
|
||||||
|
{ |
||||||
|
BK_CORE_ERROR("Listening failed"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
Socket* LinuxSocket::ack() |
||||||
|
{ |
||||||
|
struct sockaddr_in client_addr; |
||||||
|
socklen_t addrlen = sizeof(client_addr); |
||||||
|
return new LinuxSocket(accept(id, (struct sockaddr*)&client_addr, &addrlen), client_addr, ip_addr.version, ip_proto); |
||||||
|
} |
||||||
|
|
||||||
|
bool LinuxSocket::conn() |
||||||
|
{ |
||||||
|
if (connect(id, (struct sockaddr*)&addr, sizeof(addr)) != 0)
|
||||||
|
{ |
||||||
|
BK_CORE_ERROR("Connection failed"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
bool LinuxSocket::isConnected() |
||||||
|
{ |
||||||
|
char data = 0; |
||||||
|
int read_size = recv(id, &data, 1, MSG_PEEK); |
||||||
|
return (bool)read_size; |
||||||
|
} |
||||||
|
|
||||||
|
void LinuxSocket::emit(std::vector<char> packet) |
||||||
|
{ |
||||||
|
size_t size = send(id, packet.data(), packet.size(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
std::vector<char> LinuxSocket::obtain(int size) |
||||||
|
{ |
||||||
|
if(size > this->size) |
||||||
|
{ |
||||||
|
delete [] buffer; |
||||||
|
buffer = new char[size]; |
||||||
|
this->size = size; |
||||||
|
} |
||||||
|
int read_size = recv(id, buffer, this->size - 1, 0); |
||||||
|
if(read_size == -1) return std::vector<char>(0); |
||||||
|
std::vector<char> packet(buffer, buffer + read_size); |
||||||
|
return packet; |
||||||
|
} |
||||||
|
|
||||||
|
Socket* Socket::create(IpAddress ip, int port, IpProtocol proto) |
||||||
|
{ |
||||||
|
return new LinuxSocket(ip, port, proto); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
#include <bakanet/core/dns_lookup.h> |
||||||
|
|
||||||
|
namespace Bk::Net { |
||||||
|
std::vector<std::string> dns_lookup(const std::string& host_name, IpVersion ipv) |
||||||
|
{ |
||||||
|
std::vector<std::string> output; |
||||||
|
struct addrinfo hints, *res, *p; |
||||||
|
char ip_address[INET6_ADDRSTRLEN]; |
||||||
|
memset(&hints, 0, sizeof hints); |
||||||
|
hints.ai_family = (int)ipv; |
||||||
|
hints.ai_socktype = SOCK_STREAM; |
||||||
|
|
||||||
|
if (getaddrinfo(host_name.c_str(), NULL, &hints, &res) != 0) |
||||||
|
{ |
||||||
|
output.push_back(""); |
||||||
|
return output; |
||||||
|
} |
||||||
|
|
||||||
|
for (p = res;p != NULL; p = p->ai_next) |
||||||
|
{ |
||||||
|
void* addr; |
||||||
|
if (p->ai_family == AF_INET) |
||||||
|
{ |
||||||
|
struct sockaddr_in* ipv4 = (struct sockaddr_in*)p->ai_addr; |
||||||
|
addr = &(ipv4->sin_addr); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)p->ai_addr; |
||||||
|
addr = &(ipv6->sin6_addr); |
||||||
|
} |
||||||
|
inet_ntop(p->ai_family, addr, ip_address, sizeof ip_address); |
||||||
|
output.push_back(ip_address); |
||||||
|
} |
||||||
|
|
||||||
|
freeaddrinfo(res); // free the linked list
|
||||||
|
|
||||||
|
return output; |
||||||
|
} |
||||||
|
} |
@ -1 +0,0 @@ |
|||||||
Subproject commit 40d24e39a7a7b39a056418d78162103036e6534a |
|
@ -1 +0,0 @@ |
|||||||
Subproject commit 23587b0d9aebad231d7ba4f16873d70edd2b9dee |
|
Loading…
Reference in New Issue