diff --git a/Source/ThirdParty/KCP/Private/KCPWrap.cpp b/Source/ThirdParty/KCP/Private/KCPWrap.cpp index 2b7d74f..520b236 100644 --- a/Source/ThirdParty/KCP/Private/KCPWrap.cpp +++ b/Source/ThirdParty/KCP/Private/KCPWrap.cpp @@ -13,22 +13,35 @@ namespace FKCPFuncWrap void Writelog(const char* log, ikcpcb* kcp, void* user) { - UE_LOG(LogKCP, Log, TEXT("[%i]: %s"), kcp->conv, log); + FKCPWrap* KCPWrap = (FKCPWrap*)user; + UE_LOG(LogKCP, Log, TEXT("%s: %s"), *KCPWrap->GetDebugName(), ANSI_TO_TCHAR(log)); } } FKCPWrap::FKCPWrap(uint32 Conv) + : KCPPtr(ikcp_create(Conv, this)) + , DebugName(FString::Printf(TEXT("[%i]"), Conv)) { - KCPPtr = ikcp_create(Conv, this); KCPPtr->output = &FKCPFuncWrap::Output; KCPPtr->writelog = &FKCPFuncWrap::Writelog; } +FKCPWrap::FKCPWrap(uint32 Conv, const FString & InDebugName) + : FKCPWrap(Conv) +{ + DebugName = InDebugName; +} + FKCPWrap::~FKCPWrap() { ikcp_release(KCPPtr); } +ikcpcb & FKCPWrap::GetKCPCB() +{ + return *KCPPtr; +} + int FKCPWrap::Recv(uint8 * Data, int32 Count) { return ikcp_recv(KCPPtr, (char*)Data, Count); @@ -93,3 +106,13 @@ int FKCPWrap::SetTurboMode() { return SetNoDelay(1, 10, 2, 1); } + +void FKCPWrap::SetDebugName(const FString & InDebugName) +{ + DebugName = InDebugName; +} + +const FString & FKCPWrap::GetDebugName() const +{ + return DebugName; +} diff --git a/Source/ThirdParty/KCP/Public/KCPWrap.h b/Source/ThirdParty/KCP/Public/KCPWrap.h index 9f0e5c9..30d92fb 100644 --- a/Source/ThirdParty/KCP/Public/KCPWrap.h +++ b/Source/ThirdParty/KCP/Public/KCPWrap.h @@ -9,8 +9,12 @@ public: FKCPWrap(uint32 Conv); + FKCPWrap(uint32 Conv, const FString& InDebugName); + ~FKCPWrap(); + ikcpcb& GetKCPCB(); + int Recv(uint8* Data, int32 Count); int Send(const uint8* Data, int32 Count); @@ -37,10 +41,16 @@ public: int SetTurboMode(); - TFunction OutputFunc; + TFunction OutputFunc; + + void SetDebugName(const FString& InDebugName); + + const FString& GetDebugName() const; private: ikcpcb* KCPPtr; + FString DebugName; + };