Init Version.

This commit is contained in:
taynpg 2025-05-05 23:22:43 +08:00
commit dba16b321d
23 changed files with 18580 additions and 0 deletions

17
.clang-format Normal file
View File

@ -0,0 +1,17 @@
BasedOnStyle: LLVM
IndentWidth: 4
PointerAlignment: Left
AccessModifierOffset: -4
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true
AfterClass: true
Cpp11BracedListStyle: true
ReflowComments: true
SpacesBeforeTrailingComments: 3
TabWidth: 4
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ColumnLimit: 130
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
AllowShortEnumsOnASingleLine: false

41
.gitignore vendored Normal file
View File

@ -0,0 +1,41 @@
# Prerequisites
*.d
.idea
cmake-build-*
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
build
*.user
compile_commands.json
.vs
out
.cache
CMakeLists.txt.*

46
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,46 @@
{
"files.autoSave": "onFocusChange",
"editor.fontSize": 14,
//"editor.fontFamily": "'Monaspace Krypton Light', 'Monaspace Krypton Light', 'Monaspace Krypton Light'",
"terminal.integrated.fontFamily": "monospace",
"cmake.configureOnOpen": true,
"cmake.debugConfig": {
"console": "integratedTerminal",
"setupCommands": [
{
"description": "-gdb-set charset utf-8",
"text": "-gdb-set charset UTF-8"
},
{
"description": "Enable gdb pretty-printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//"visualizerFile": "${workspaceRoot}/.vscode/qt6.natvis",
"args": [
]
},
// "cmake.configureSettings": {
// "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
// },
"cmake.configureArgs": [
"-Wno-dev",
"-DCMAKE_PREFIX_PATH:STRING=D:/Program/Dev/wxWidgets"
],
"cmake.options.statusBarVisibility": "visible",
"cmake.generator": "Ninja",
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"editor.inlayHints.enabled": "off",
"editor.unicodeHighlight.allowedLocales": {
"ja": true,
"zh-hant": true,
"zh-hans": true
},
"files.associations": {
"vector": "cpp",
"memory": "cpp"
}
}

18162
3rd/toml.hpp Normal file

File diff suppressed because it is too large Load Diff

24
CMakeLists.txt Normal file
View File

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16)
project(RemoteTran LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (MSVC)
add_compile_options(/utf-8)
endif()
set(CMAKE_DEBUG_POSTFIX "d")
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/)
include_directories(3rd)
add_subdirectory(ClientCore)
add_subdirectory(Util)
add_subdirectory(Protocol)
add_subdirectory(UserInterface)
add_subdirectory(RemoteServer)

15
ClientCore/CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)
project(ClientCore LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(wxWidgets CONFIG REQUIRED)
set(MSOURCES
ClientCore.h
ClientCore.cxx
)
add_library(ClientCore STATIC ${MSOURCES})
target_link_libraries(ClientCore PRIVATE wx::base wx::core)

View File

@ -0,0 +1,5 @@
#include "ClientCore.h"
ClientCore::ClientCore()
{
}

10
ClientCore/ClientCore.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef CLIENTCORE_H
#define CLIENTCORE_H
class ClientCore
{
public:
ClientCore();
};
#endif // CLIENTCORE_H

15
Protocol/CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)
project(Protocol LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(wxWidgets CONFIG REQUIRED)
set(MSOURCES
Communicate.h
Communicate.cxx
)
add_library(Protocol STATIC ${MSOURCES})
target_link_libraries(Protocol PRIVATE wx::base wx::core)

5
Protocol/Communicate.cxx Normal file
View File

@ -0,0 +1,5 @@
#include "Communicate.h"
Communicate::Communicate()
{
}

10
Protocol/Communicate.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef COMMUNICATE_H
#define COMMUNICATE_H
class Communicate
{
public:
Communicate();
};
#endif // COMMUNICATE_H

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# RemoteTran

View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(RemoteServer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(wxWidgets CONFIG REQUIRED)
set(MSOURCES
RemoteServer.h
RemoteServer.cxx
main.cxx
)
add_executable(RemoteServer ${MSOURCES})
target_link_libraries(RemoteServer PRIVATE wx::base wx::core Util)
set_target_properties(RemoteServer PROPERTIES WIN32_EXECUTABLE TRUE)

View File

@ -0,0 +1,23 @@
#include "RemoteServer.h"
RemoteServer::RemoteServer()
{
}
bool RemoteServer::Init(const wxString& ip, unsigned short port)
{
return false;
}
int RemoteServer::Run()
{
return 0;
}
void RemoteServer::OnServerEvent(wxSocketEvent& event)
{
}
void RemoteServer::thClientThread(const std::shared_ptr<wxSocketBase>& wxSock, const wxString& id)
{
}

View File

@ -0,0 +1,45 @@
#ifndef REMOTE_SERVER_H
#define REMOTE_SERVER_H
#include <Util.h>
#include <array>
#include <chrono>
#include <cstdint>
#include <shared_mutex>
#include <thread>
#include <unordered_map>
#include <wx/event.h>
#include <wx/evtloop.h>
#include <wx/socket.h>
#include <wx/wx.h>
using highClock_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
struct TranClient {
std::shared_ptr<wxSocketBase> wxSock;
MutBuffer buffer;
int64_t onlineTime;
highClock_t lastRecvTime;
};
class RemoteServer : public wxEvtHandler
{
public:
RemoteServer();
public:
bool Init(const wxString& ip, unsigned short port);
int Run();
private:
void OnServerEvent(wxSocketEvent& event);
void thClientThread(const std::shared_ptr<wxSocketBase>& wxSock, const wxString& id);
private:
wxWindowID serverId_;
std::shared_mutex clientsMutex_;
std::unique_ptr<wxSocketServer> server_;
std::unordered_map<wxString, std::thread> threads_;
std::unordered_map<wxString, std::shared_ptr<TranClient>> clients_;
};
#endif // REMOTE_SERVER_H

14
RemoteServer/main.cxx Normal file
View File

@ -0,0 +1,14 @@
#include "RemoteServer.h"
class RemoteServerApp : public wxApp
{
public:
bool OnInit() override;
};
bool RemoteServerApp::OnInit()
{
return true;
}
wxIMPLEMENT_APP(RemoteServerApp);

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.16)
project(RemoteTran LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(MSOURCES
UserInterface.h
UserInterface.cxx
main.cxx
)
add_executable(UserInterface ${MSOURCES})

View File

@ -0,0 +1,5 @@
#include "UserInterface.h"
UserInterface::~UserInterface()
{
}

View File

@ -0,0 +1,10 @@
#ifndef _IUSERINTERFACE_H
#define _IUSERINTERFACE_H
class UserInterface
{
public:
~UserInterface();
};
#endif // _IUSERINTERFACE_H

6
UserInterface/main.cxx Normal file
View File

@ -0,0 +1,6 @@
#include "UserInterface.h"
int main()
{
return 0;
}

16
Util/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(Util LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(wxWidgets CONFIG REQUIRED)
set(MSOURCES
Util.h
Util.cxx
)
add_library(Util STATIC ${MSOURCES})
target_link_libraries(Util PRIVATE wx::base wx::core)
target_include_directories(Util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

47
Util/Util.cxx Normal file
View File

@ -0,0 +1,47 @@
#include "Util.h"
#include <algorithm>
TranUtil::TranUtil()
{
}
void MutBuffer::Push(const char* data, int len)
{
buffer_.insert(buffer_.end(), data, data + len);
}
int MutBuffer::IndexOf(const char* data, int len, int start_pos)
{
if (start_pos < 0 || start_pos >= static_cast<int>(buffer_.size()) || len <= 0) {
return -1;
}
auto it = std::search(buffer_.begin() + start_pos, buffer_.end(), data, data + len);
if (it != buffer_.end()) {
return std::distance(buffer_.begin(), it);
}
return -1;
}
int MutBuffer::Length() const
{
return static_cast<int>(buffer_.size());
}
void MutBuffer::RemoveOf(int start_pos, int len)
{
if (start_pos < 0 || start_pos >= static_cast<int>(buffer_.size()) || len <= 0) {
return;
}
auto end_pos = std::min(start_pos + len, static_cast<int>(buffer_.size()));
buffer_.erase(buffer_.begin() + start_pos, buffer_.begin() + end_pos);
}
void MutBuffer::Clear()
{
buffer_.clear();
}
const char* MutBuffer::GetData() const
{
return buffer_.data();
}

32
Util/Util.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef REMOTE_TRAN_UTIL
#define REMOTE_TRAN_UTIL
#include <mutex>
#include <vector>
constexpr int MAX_BUFFER_SIZE = 1024 * 1024 * 10;
class TranUtil
{
public:
TranUtil();
};
class MutBuffer
{
public:
MutBuffer() = default;
public:
void Push(const char* data, int len);
int IndexOf(const char* data, int len, int start_pos = 0);
const char* GetData() const;
int Length() const;
void RemoveOf(int start_pos, int len);
void Clear();
private:
std::vector<char> buffer_;
};
#endif // REMOTE_TRAN_UTIL