summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/MinecraftDynmap/src/dialogs.cpp14
-rw-r--r--src/mir_app/src/netlib.h5
-rw-r--r--src/mir_app/src/netlibbind.cpp47
-rw-r--r--src/mir_core/src/utils.cpp13
4 files changed, 41 insertions, 38 deletions
diff --git a/protocols/MinecraftDynmap/src/dialogs.cpp b/protocols/MinecraftDynmap/src/dialogs.cpp
index 7fd8b0d3bc..48c8c19eeb 100644
--- a/protocols/MinecraftDynmap/src/dialogs.cpp
+++ b/protocols/MinecraftDynmap/src/dialogs.cpp
@@ -48,20 +48,6 @@ HANDLE GetIconHandle(const char* name) {
// Dialogs
-static BOOL LoadDBCheckState(MinecraftDynmapProto* ppro, HWND hwnd, int idCtrl, const char* szSetting, BYTE bDef = 0)
-{
- BOOL state = db_get_b(NULL, ppro->m_szModuleName, szSetting, bDef);
- CheckDlgButton(hwnd, idCtrl, state ? BST_CHECKED : BST_UNCHECKED);
- return state;
-}
-
-static BOOL StoreDBCheckState(MinecraftDynmapProto* ppro, HWND hwnd, int idCtrl, const char* szSetting)
-{
- BOOL state = IsDlgButtonChecked(hwnd, idCtrl);
- db_set_b(NULL, ppro->m_szModuleName, szSetting, (BYTE)state);
- return state;
-}
-
static void LoadDBText(MinecraftDynmapProto* ppro, HWND hwnd, int idCtrl, const char* szSetting)
{
ptrW tstr(db_get_wsa(NULL, ppro->m_szModuleName, szSetting));
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h
index 087b7d8cb5..140353d19d 100644
--- a/src/mir_app/src/netlib.h
+++ b/src/mir_app/src/netlib.h
@@ -168,8 +168,11 @@ struct NetlibConnection : public MZeroedObject
unsigned lastPost;
};
-struct NetlibBoundPort
+struct NetlibBoundPort : public MZeroedObject
{
+ NetlibBoundPort(HNETLIBUSER nlu, NETLIBBIND *nlb);
+ ~NetlibBoundPort();
+
int handleType;
SOCKET s;
SOCKET s6;
diff --git a/src/mir_app/src/netlibbind.cpp b/src/mir_app/src/netlibbind.cpp
index fff3f092d2..bbc9c6fee3 100644
--- a/src/mir_app/src/netlibbind.cpp
+++ b/src/mir_app/src/netlibbind.cpp
@@ -109,14 +109,12 @@ bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn)
}
}
-int NetlibFreeBoundPort(struct NetlibBoundPort *nlbp)
+int NetlibFreeBoundPort(NetlibBoundPort *nlbp)
{
- closesocket(nlbp->s);
- closesocket(nlbp->s6);
if (nlbp->hThread)
WaitForSingleObject(nlbp->hThread, INFINITE);
Netlib_Logf(nlbp->nlu, "(%u) Port %u closed for incoming connections", nlbp->s, nlbp->wPort);
- mir_free(nlbp);
+ delete nlbp;
return 1;
}
@@ -176,24 +174,16 @@ static void NetlibBindAcceptThread(void* param)
MIR_APP_DLL(HNETLIBBIND) Netlib_BindPort(HNETLIBUSER nlu, NETLIBBIND *nlb)
{
- if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_INCOMING) ||
- nlb == NULL || nlb->pfnNewConnection == NULL) {
+ if (GetNetlibHandleType(nlu) != NLH_USER || !(nlu->user.flags & NUF_INCOMING) || nlb == NULL || nlb->pfnNewConnection == NULL) {
SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
+ return nullptr;
}
NetlibBoundPort *nlbp = (NetlibBoundPort*)mir_calloc(sizeof(NetlibBoundPort));
- nlbp->handleType = NLH_BOUNDPORT;
- nlbp->nlu = nlu;
- nlbp->pfnNewConnectionV2 = nlb->pfnNewConnectionV2;
-
- nlbp->s = socket(PF_INET, SOCK_STREAM, 0);
- nlbp->s6 = socket(PF_INET6, SOCK_STREAM, 0);
- nlbp->pExtra = nlb->pExtra;
if (nlbp->s == INVALID_SOCKET && nlbp->s6 == INVALID_SOCKET) {
Netlib_Logf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "socket", WSAGetLastError());
- mir_free(nlbp);
- return 0;
+ delete nlbp;
+ return nullptr;
}
SOCKADDR_IN sin = { 0 };
@@ -237,10 +227,8 @@ MIR_APP_DLL(HNETLIBBIND) Netlib_BindPort(HNETLIBUSER nlu, NETLIBBIND *nlb)
if (!foundPort) {
Netlib_Logf(nlu, "%s %d: %s() failed (%u)", __FILE__, __LINE__, "bind", WSAGetLastError());
LBL_Error:
- closesocket(nlbp->s);
- closesocket(nlbp->s6);
- mir_free(nlbp);
- return 0;
+ delete nlbp;
+ return nullptr;
}
if (nlbp->s != INVALID_SOCKET && listen(nlbp->s, 5)) {
@@ -296,3 +284,22 @@ LBL_Error:
nlbp->hThread = mir_forkthread(NetlibBindAcceptThread, nlbp);
return nlbp;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+NetlibBoundPort::NetlibBoundPort(HNETLIBUSER _nlu, NETLIBBIND *nlb)
+ : handleType(NLH_BOUNDPORT),
+ nlu(_nlu)
+{
+ pfnNewConnectionV2 = nlb->pfnNewConnectionV2;
+ pExtra = nlb->pExtra;
+
+ s = socket(PF_INET, SOCK_STREAM, 0);
+ s6 = socket(PF_INET6, SOCK_STREAM, 0);
+}
+
+NetlibBoundPort::~NetlibBoundPort()
+{
+ closesocket(s);
+ closesocket(s6);
+}
diff --git a/src/mir_core/src/utils.cpp b/src/mir_core/src/utils.cpp
index e2dea519ab..7b26bb6aab 100644
--- a/src/mir_core/src/utils.cpp
+++ b/src/mir_core/src/utils.cpp
@@ -524,8 +524,15 @@ PGENRANDOM pfnRtlGenRandom;
MIR_CORE_DLL(void) Utils_GetRandom(void *pszDest, size_t cbLen)
{
- if (pszDest != 0 || cbLen != 0 && pfnRtlGenRandom != NULL)
+ if (pszDest == nullptr || cbLen == 0)
+ return;
+
+ if (pfnRtlGenRandom != NULL)
pfnRtlGenRandom(pszDest, (ULONG)cbLen);
- else
- memset(pszDest, 0, cbLen);
+ else {
+ srand(time(NULL));
+ BYTE *p = (BYTE*)pszDest;
+ for (size_t i = 0; i < cbLen; i++)
+ p[i] = rand() & 0xFF;
+ }
}