Adam Johnson
13 years ago
43 changed files with 15 additions and 3273 deletions
@ -1,19 +0,0 @@ |
|||||||
include_directories(../../CoreLib) |
|
||||||
include_directories(../../FeatureLib) |
|
||||||
include_directories(../../NucleusLib) |
|
||||||
include_directories(../../NucleusLib/inc) |
|
||||||
include_directories(../../PubUtilLib) |
|
||||||
|
|
||||||
set(pfCsrSrv_SOURCES |
|
||||||
pfCsrSrv.cpp |
|
||||||
) |
|
||||||
|
|
||||||
set(pfCsrSrv_HEADERS |
|
||||||
Pch.h |
|
||||||
pfCsrSrv.h |
|
||||||
) |
|
||||||
|
|
||||||
add_library(pfCsrSrv STATIC ${pfCsrSrv_SOURCES} ${pfCsrSrv_HEADERS}) |
|
||||||
|
|
||||||
source_group("Source Files" FILES ${pfCsrSrv_SOURCES}) |
|
||||||
source_group("Header Files" FILES ${pfCsrSrv_HEADERS}) |
|
@ -1,58 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/FeatureLib/pfCsrSrv/Pch.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFCSRSRV_PCH_H |
|
||||||
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfCsrSrv/Pch.h included more than once" |
|
||||||
#endif |
|
||||||
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFCSRSRV_PCH_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pfCsrSrv.h" |
|
||||||
|
|
||||||
#pragma warning(push, 0) |
|
||||||
#include "pfConsole/pfConsole.h" |
|
||||||
#pragma warning(pop) |
|
@ -1,160 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "Pch.h" |
|
||||||
#pragma hdrstop |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local types |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local data |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
static bool s_running; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool Recv_ExecConsoleCmd ( |
|
||||||
SimpleNetConn * , |
|
||||||
CsrNet_ExecConsoleCmd * msg |
|
||||||
) { |
|
||||||
LogMsg(kLogPerf, L"pfCsrSrv: ExecConsoleCmd: %S", msg->cmd); |
|
||||||
|
|
||||||
pfConsole::RunCommandAsync(msg->cmd); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool OnMsg ( |
|
||||||
SimpleNetConn * conn, |
|
||||||
SimpleNet_MsgHeader * msg |
|
||||||
) { |
|
||||||
bool result; |
|
||||||
|
|
||||||
#define DISPATCH(a) case kCsrNet_##a: result = Recv_##a(conn, (CsrNet_##a *) msg); break |
|
||||||
switch (msg->messageId) { |
|
||||||
DISPATCH(ExecConsoleCmd); |
|
||||||
default: |
|
||||||
result = false; |
|
||||||
} |
|
||||||
#undef DISPATCH |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void OnError ( |
|
||||||
SimpleNetConn * , |
|
||||||
ENetError error |
|
||||||
) { |
|
||||||
LogMsg(kLogPerf, L"pfCsrSrv NetError: %s", NetErrorToString(error)); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool QueryAccept ( |
|
||||||
void * , |
|
||||||
unsigned channel, |
|
||||||
SimpleNetConn * , |
|
||||||
const plNetAddress& addr |
|
||||||
) { |
|
||||||
plString str = addr.AsString(); |
|
||||||
LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str.c_str()); |
|
||||||
return channel == kSimpleNetChannelCsr; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Exports |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrSrvInitialize () { |
|
||||||
|
|
||||||
#ifdef PLASMA_ENABLE_CSR_EXTERNAL |
|
||||||
|
|
||||||
LogMsg(kLogPerf, L"pfCsrSrv: Initializing"); |
|
||||||
|
|
||||||
s_running = true; |
|
||||||
|
|
||||||
SimpleNetInitialize(); |
|
||||||
SimpleNetCreateChannel(kSimpleNetChannelCsr, OnMsg, OnError);
|
|
||||||
SimpleNetStartListening(QueryAccept, nil); |
|
||||||
|
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrSrvShutdown () { |
|
||||||
|
|
||||||
#ifdef PLASMA_ENABLE_CSR_EXTERNAL |
|
||||||
|
|
||||||
LogMsg(kLogPerf, L"pfCsrSrv: Shutting down"); |
|
||||||
|
|
||||||
s_running = false; |
|
||||||
|
|
||||||
SimpleNetStopListening(); |
|
||||||
SimpleNetDestroyChannel(kSimpleNetChannelCsr); |
|
||||||
SimpleNetShutdown(); |
|
||||||
|
|
||||||
#endif |
|
||||||
} |
|
@ -1,66 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFCSRSRV_PFCSRSRV_H |
|
||||||
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFCSRSRV_PFCSRSRV_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnCsrNet/pnCsrNet.h" |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* pfCsrSrv |
|
||||||
* - Executes remote CSR commands received through pnCsrNet |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
void CsrSrvInitialize (); |
|
||||||
void CsrSrvShutdown (); |
|
||||||
|
|
||||||
|
|
||||||
#endif // PLASMA20_SOURCES_PLASMA_FEATURELIB_PFCSRSRV_PFCSRSRV_H
|
|
@ -1,16 +0,0 @@ |
|||||||
include_directories(../../CoreLib) |
|
||||||
include_directories(../../NucleusLib) |
|
||||||
|
|
||||||
set(pnCsrCli_SOURCES |
|
||||||
pnCsrCli.cpp |
|
||||||
) |
|
||||||
|
|
||||||
set(pnCsrCli_HEADERS |
|
||||||
Pch.h |
|
||||||
pnCsrCli.h |
|
||||||
) |
|
||||||
|
|
||||||
add_library(pnCsrCli STATIC ${pnCsrCli_SOURCES} ${pnCsrCli_HEADERS}) |
|
||||||
|
|
||||||
source_group("Source Files" FILES ${pnCsrCli_SOURCES}) |
|
||||||
source_group("Header Files" FILES ${pnCsrCli_HEADERS}) |
|
@ -1,56 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrCli/Pch.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRCLI_PCH_H |
|
||||||
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnCsrCli/Pch.h included more than once" |
|
||||||
#endif |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRCLI_PCH_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnCsrCli.h" |
|
||||||
|
|
||||||
#include <malloc.h> |
|
@ -1,269 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrCli/pnCsrCli.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "Pch.h" |
|
||||||
#pragma hdrstop |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local types |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local data |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
static bool s_running; |
|
||||||
static CCritSect s_critsect; |
|
||||||
static SimpleNetConn * s_conn; |
|
||||||
static FCsrCliOnError s_onError; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static SimpleNetConn * GetConnIncRef () { |
|
||||||
|
|
||||||
SimpleNetConn * conn; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
if (nil != (conn = s_conn)) |
|
||||||
SimpleNetConnIncRef(conn); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
return conn; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool SimpleNetOnMsg ( |
|
||||||
SimpleNetConn * , |
|
||||||
SimpleNet_MsgHeader *
|
|
||||||
) { |
|
||||||
LogMsg(kLogPerf, L"pnCsrCli: Rcvd unexpected message from peer"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void SimpleNetOnError ( |
|
||||||
SimpleNetConn * , |
|
||||||
ENetError error |
|
||||||
) { |
|
||||||
if (!s_running) |
|
||||||
return; |
|
||||||
|
|
||||||
LogMsg(kLogPerf, L"pnCsrCli: NetError: %s", NetErrorToString(error)); |
|
||||||
|
|
||||||
if (error == kNetErrDisconnected) |
|
||||||
CsrCliDisconnect(); |
|
||||||
|
|
||||||
s_onError(error); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void SimpleNetOnConnect ( |
|
||||||
void * param, |
|
||||||
SimpleNetConn * conn, |
|
||||||
ENetError result |
|
||||||
) { |
|
||||||
FCsrCliOnConnect onConnect = (FCsrCliOnConnect)param; |
|
||||||
|
|
||||||
LogMsg(kLogPerf, L"pnCsrCli: OnConnect: %s", NetErrorToString(result)); |
|
||||||
|
|
||||||
if (s_conn) |
|
||||||
CsrCliDisconnect(); |
|
||||||
|
|
||||||
if (IS_NET_SUCCESS(result)) { |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
s_conn = conn; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
} |
|
||||||
|
|
||||||
if (onConnect) |
|
||||||
onConnect(result); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void Send_ExecConsoleCmd (const char cmd[]) { |
|
||||||
|
|
||||||
SimpleNetConn * conn = GetConnIncRef(); |
|
||||||
if (!conn) |
|
||||||
return; |
|
||||||
|
|
||||||
unsigned cmdBytes = StrBytes(cmd); |
|
||||||
|
|
||||||
CsrNet_ExecConsoleCmd * msg; |
|
||||||
|
|
||||||
unsigned msgBytes |
|
||||||
= sizeof(*msg) |
|
||||||
- sizeof(msg->cmd) |
|
||||||
+ cmdBytes |
|
||||||
+ sizeof(cmd[0]) |
|
||||||
; |
|
||||||
|
|
||||||
msg = new(_alloca(msgBytes)) CsrNet_ExecConsoleCmd(); |
|
||||||
msg->messageBytes = msgBytes; |
|
||||||
|
|
||||||
StrCopy(msg->cmd, cmd, cmdBytes / sizeof(cmd[0])); |
|
||||||
msg->cmd[cmdBytes] = 0; |
|
||||||
|
|
||||||
SimpleNetSend(conn, msg); |
|
||||||
SimpleNetConnDecRef(conn);
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Exports |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliInitialize (FCsrCliOnError onError) { |
|
||||||
|
|
||||||
ASSERT(!s_running); |
|
||||||
ASSERT(onError); |
|
||||||
|
|
||||||
s_running = true; |
|
||||||
s_onError = onError; |
|
||||||
|
|
||||||
SimpleNetInitialize(); |
|
||||||
SimpleNetCreateChannel(kSimpleNetChannelCsr, SimpleNetOnMsg, SimpleNetOnError); |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliShutdown () { |
|
||||||
|
|
||||||
s_running = false; |
|
||||||
s_onError = nil; |
|
||||||
|
|
||||||
CsrCliDisconnect();
|
|
||||||
SimpleNetDestroyChannel(kSimpleNetChannelCsr); |
|
||||||
SimpleNetShutdown(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliStartConnecting ( |
|
||||||
const wchar_t addr[], |
|
||||||
FCsrCliOnConnect onConnect |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
CsrCliDisconnect();
|
|
||||||
SimpleNetStartConnecting(kSimpleNetChannelCsr, addr, SimpleNetOnConnect, onConnect); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliDisconnect () { |
|
||||||
|
|
||||||
SimpleNetConn * conn = nil; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
SWAP(conn, s_conn); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
if (conn) |
|
||||||
SimpleNetDisconnect(conn); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliToggleAvatarPhysical () { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
Send_ExecConsoleCmd("Avatar.Physics.TogglePhysical"); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliWarpPlayerHere (unsigned playerId) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
char cmd[1024]; |
|
||||||
StrPrintf(cmd, arrsize(cmd), "CCR.WarpPlayerHere %u", playerId); |
|
||||||
Send_ExecConsoleCmd(cmd); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliWarpToPlayer (unsigned playerId) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
char cmd[1024]; |
|
||||||
StrPrintf(cmd, arrsize(cmd), "CCR.WarpToPlayer %u", playerId); |
|
||||||
Send_ExecConsoleCmd(cmd); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliLinkPlayerHere (unsigned playerId) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
char cmd[1024]; |
|
||||||
StrPrintf(cmd, arrsize(cmd), "CCR.LinkPlayerHere %u", playerId); |
|
||||||
Send_ExecConsoleCmd(cmd); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrCliLinkToPlayer (unsigned playerId) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
char cmd[1024]; |
|
||||||
StrPrintf(cmd, arrsize(cmd), "CCR.LinkToPlayer %u", playerId); |
|
||||||
Send_ExecConsoleCmd(cmd); |
|
||||||
} |
|
@ -1,83 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrCli/pnCsrCli.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRCLI_PNCSRCLI_H |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRCLI_PNCSRCLI_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnCsrNet/pnCsrNet.h" |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* pnCsrCli |
|
||||||
* - Connects to pfCsrSrv in remote CSR client. |
|
||||||
* - Sends commands to pfCsrSrv for remote execution. |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
typedef void (*FCsrCliOnError) (ENetError error); |
|
||||||
|
|
||||||
void CsrCliInitialize (FCsrCliOnError onError); |
|
||||||
void CsrCliShutdown (); |
|
||||||
|
|
||||||
typedef void (*FCsrCliOnConnect) (ENetError result); |
|
||||||
|
|
||||||
void CsrCliStartConnecting ( |
|
||||||
const wchar_t addr[], |
|
||||||
FCsrCliOnConnect onConnect |
|
||||||
); |
|
||||||
void CsrCliDisconnect (); |
|
||||||
|
|
||||||
void CsrCliToggleAvatarPhysical (); |
|
||||||
void CsrCliWarpPlayerHere (unsigned playerId); |
|
||||||
void CsrCliWarpToPlayer (unsigned playerId); |
|
||||||
void CsrCliLinkPlayerHere (unsigned playerId); |
|
||||||
void CsrCliLinkToPlayer (unsigned playerId); |
|
||||||
|
|
||||||
|
|
||||||
#endif // PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRCLI_PNCSRCLI_H
|
|
@ -1,16 +0,0 @@ |
|||||||
include_directories(../../CoreLib) |
|
||||||
include_directories(../../NucleusLib) |
|
||||||
|
|
||||||
set(pnCsrNet_SOURCES |
|
||||||
pnCsrNet.cpp |
|
||||||
) |
|
||||||
|
|
||||||
set(pnCsrNet_HEADERS |
|
||||||
Pch.h |
|
||||||
pnCsrNet.h |
|
||||||
) |
|
||||||
|
|
||||||
add_library(pnCsrNet STATIC ${pnCsrNet_SOURCES} ${pnCsrNet_HEADERS}) |
|
||||||
|
|
||||||
source_group("Source Files" FILES ${pnCsrNet_SOURCES}) |
|
||||||
source_group("Header Files" FILES ${pnCsrNet_HEADERS}) |
|
@ -1,54 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrNet/Pch.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRNET_PCH_H |
|
||||||
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnCsrNet/Pch.h included more than once" |
|
||||||
#endif |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRNET_PCH_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnCsrNet.h" |
|
@ -1,49 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrNet/pnCsrNet.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "Pch.h" |
|
||||||
#pragma hdrstop |
|
@ -1,88 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnCsrNet/pnCsrNet.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRNET_PNCSRNET_H |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRNET_PNCSRNET_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnSimpleNet/pnSimpleNet.h" |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* CSR Client Automation - Types and Constants |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// Newer CSR game clients must remain compatible with older CSR tools,
|
|
||||||
// therefore these values may not change. Only append to this enum.
|
|
||||||
enum { |
|
||||||
kCsrNet_ExecConsoleCmd, |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// BEGIN PACKED DATA STRUCTURES
|
|
||||||
//============================================================================
|
|
||||||
#pragma pack(push,1) |
|
||||||
|
|
||||||
#define CSRNET_MSG(a) \ |
|
||||||
CsrNet_##a () : SimpleNet_MsgHeader(kSimpleNetChannelCsr, kCsrNet_##a) { } |
|
||||||
|
|
||||||
struct CsrNet_ExecConsoleCmd : SimpleNet_MsgHeader { |
|
||||||
CSRNET_MSG (ExecConsoleCmd); |
|
||||||
|
|
||||||
char cmd[1]; // null-terminated string
|
|
||||||
}; |
|
||||||
|
|
||||||
#undef CSRNET_MSG |
|
||||||
//============================================================================
|
|
||||||
// END PACKED DATA STRUCTURES
|
|
||||||
//============================================================================
|
|
||||||
#pragma pack(pop) |
|
||||||
|
|
||||||
|
|
||||||
#endif // PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNCSRNET_PNCSRNET_H
|
|
@ -1,122 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Csr/pnNpCli2Csr.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#define USES_PROTOCOL_CLI2CSR |
|
||||||
#include "../../../Pch.h" |
|
||||||
#pragma hdrstop |
|
||||||
|
|
||||||
|
|
||||||
namespace Cli2Csr { |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Cli2Csr message field definitions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
static const NetMsgField kPingRequestFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
kNetMsgFieldTimeMs, // pingTimeMs
|
|
||||||
NET_MSG_FIELD_VAR_COUNT(1, 64 * 1024), // payloadBytes
|
|
||||||
NET_MSG_FIELD_VAR_PTR(), // payload
|
|
||||||
}; |
|
||||||
|
|
||||||
static const NetMsgField kRegisterRequestFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
}; |
|
||||||
|
|
||||||
static const NetMsgField kLoginRequestFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
NET_MSG_FIELD_DWORD(), // clientChallenge
|
|
||||||
kNetMsgFieldAccountName, // csrName
|
|
||||||
kNetMsgFieldShaDigest, // challenge
|
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Csr2Cli message field definitions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
static const NetMsgField kPingReplyFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
kNetMsgFieldTimeMs, // pingTimeMs
|
|
||||||
NET_MSG_FIELD_VAR_COUNT(1, 64 * 1024), // payloadBytes
|
|
||||||
NET_MSG_FIELD_VAR_PTR(), // payload
|
|
||||||
}; |
|
||||||
|
|
||||||
static const NetMsgField kRegisterReplyFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
NET_MSG_FIELD_DWORD(), // serverChallenge
|
|
||||||
NET_MSG_FIELD_DWORD(), // latestBuildId
|
|
||||||
}; |
|
||||||
|
|
||||||
static const NetMsgField kLoginReplyFields[] = { |
|
||||||
kNetMsgFieldTransId, // transId
|
|
||||||
kNetMsgFieldENetError, // result
|
|
||||||
kNetMsgFieldUuid, // csrId
|
|
||||||
NET_MSG_FIELD_DWORD(), // csrFlags
|
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
} using namespace Cli2Csr; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Exports |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
const NetMsg kNetMsg_Cli2Csr_PingRequest = NET_MSG(kCli2Csr_PingRequest, kPingRequestFields); |
|
||||||
const NetMsg kNetMsg_Cli2Csr_RegisterRequest = NET_MSG(kCli2Csr_RegisterRequest, kRegisterRequestFields); |
|
||||||
const NetMsg kNetMsg_Cli2Csr_LoginRequest = NET_MSG(kCli2Csr_LoginRequest, kLoginRequestFields); |
|
||||||
|
|
||||||
const NetMsg kNetMsg_Csr2Cli_PingReply = NET_MSG(kCsr2Cli_PingReply, kPingReplyFields); |
|
||||||
const NetMsg kNetMsg_Csr2Cli_RegisterReply = NET_MSG(kCsr2Cli_RegisterReply, kRegisterReplyFields); |
|
||||||
const NetMsg kNetMsg_Csr2Cli_LoginReply = NET_MSG(kCsr2Cli_LoginReply, kLoginReplyFields); |
|
||||||
|
|
@ -1,178 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Csr/pnNpCli2Csr.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETPROTOCOL_PRIVATE_PROTOCOLS_CLI2CSR_PNNPCLI2CSR_H |
|
||||||
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Csr/pnNpCli2Csr.h included more than once" |
|
||||||
#endif |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETPROTOCOL_PRIVATE_PROTOCOLS_CLI2CSR_PNNPCLI2CSR_H |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* kNetProtocolCli2Csr message ids |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// Because SrvCsr must remain backward compatible with all client builds,
|
|
||||||
// the following enum values may never change under any circumstances.
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Cli2Csr
|
|
||||||
|
|
||||||
enum { |
|
||||||
// Misc
|
|
||||||
kCli2Csr_PingRequest = 0, |
|
||||||
// Encrypt
|
|
||||||
kCli2Csr_RegisterRequest = 1, |
|
||||||
// Login
|
|
||||||
kCli2Csr_LoginRequest = 2, |
|
||||||
// Patch
|
|
||||||
kCli2Csr_PatchRequest = 3, |
|
||||||
|
|
||||||
kNumCli2CsrMessages |
|
||||||
}; |
|
||||||
COMPILER_ASSERT_HEADER(Cli2Scr, kNumCli2CsrMessages <= (uint16_t)-1); |
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Csr2Cli
|
|
||||||
|
|
||||||
enum { |
|
||||||
// Misc
|
|
||||||
kCsr2Cli_PingReply = 0, |
|
||||||
// Encrypt
|
|
||||||
kCsr2Cli_RegisterReply = 1, |
|
||||||
// Login
|
|
||||||
kCsr2Cli_LoginReply = 2, |
|
||||||
// Patch
|
|
||||||
kCli2Csr_PatchReply = 3, |
|
||||||
|
|
||||||
kNumCsr2CliMessages |
|
||||||
}; |
|
||||||
COMPILER_ASSERT_HEADER(Cli2Scr, kNumCsr2CliMessages <= (uint16_t)-1); |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Networked structures |
|
||||||
* |
|
||||||
***/ |
|
||||||
#pragma pack(push,1) |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Connect packet
|
|
||||||
|
|
||||||
struct Cli2Csr_ConnData { |
|
||||||
uint32_t dataBytes; |
|
||||||
}; |
|
||||||
struct Cli2Csr_Connect { |
|
||||||
AsyncSocketConnectPacket hdr; |
|
||||||
Cli2Csr_ConnData data; |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Message header
|
|
||||||
|
|
||||||
struct Cli2Csr_MsgHeader { |
|
||||||
uint32_t messageId; |
|
||||||
uint32_t transId; |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Cli --> Csr message structures
|
|
||||||
|
|
||||||
// PingRequest
|
|
||||||
extern const NetMsg kNetMsg_Cli2Csr_PingRequest; |
|
||||||
struct Cli2Csr_PingRequest : Cli2Csr_MsgHeader { |
|
||||||
uint32_t pingTimeMs; |
|
||||||
uint32_t payloadBytes; |
|
||||||
uint8_t payload[1]; // [payloadBytes]
|
|
||||||
}; |
|
||||||
|
|
||||||
// RegisterRequest
|
|
||||||
extern const NetMsg kNetMsg_Cli2Csr_RegisterRequest; |
|
||||||
struct Cli2Csr_RegisterRequest : Cli2Csr_MsgHeader { |
|
||||||
}; |
|
||||||
|
|
||||||
// LoginRequest
|
|
||||||
extern const NetMsg kNetMsg_Cli2Csr_LoginRequest; |
|
||||||
struct Cli2Csr_LoginRequest : Cli2Csr_MsgHeader { |
|
||||||
uint32_t clientChallenge; |
|
||||||
wchar_t csrName[kMaxAccountNameLength]; |
|
||||||
ShaDigest challengeHash; |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Csr --> Cli message structures
|
|
||||||
|
|
||||||
// PingReply
|
|
||||||
extern const NetMsg kNetMsg_Csr2Cli_PingReply; |
|
||||||
struct Csr2Cli_PingReply : Cli2Csr_MsgHeader { |
|
||||||
uint32_t pingTimeMs; |
|
||||||
uint32_t payloadBytes; |
|
||||||
uint8_t payload[1]; // [payloadBytes]
|
|
||||||
}; |
|
||||||
|
|
||||||
// RegisterReply
|
|
||||||
extern const NetMsg kNetMsg_Csr2Cli_RegisterReply; |
|
||||||
struct Csr2Cli_RegisterReply : Cli2Csr_MsgHeader { |
|
||||||
uint32_t serverChallenge; |
|
||||||
uint32_t csrBuildId; // buildId of the latest csr client
|
|
||||||
}; |
|
||||||
|
|
||||||
// LoginReply
|
|
||||||
extern const NetMsg kNetMsg_Csr2Cli_LoginReply; |
|
||||||
struct Csr2Cli_LoginReply : Cli2Csr_MsgHeader { |
|
||||||
ENetError result; |
|
||||||
Uuid csrId; |
|
||||||
uint32_t csrFlags; |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
#pragma pack(pop) |
|
||||||
|
|
@ -1,15 +0,0 @@ |
|||||||
include_directories("../../CoreLib") |
|
||||||
include_directories("../../NucleusLib") |
|
||||||
|
|
||||||
set(pnSimpleNet_HEADERS |
|
||||||
pnSimpleNet.h |
|
||||||
) |
|
||||||
|
|
||||||
set(pnSimpleNet_SOURCES |
|
||||||
pnSimpleNet.cpp |
|
||||||
) |
|
||||||
|
|
||||||
add_library(pnSimpleNet STATIC ${pnSimpleNet_HEADERS} ${pnSimpleNet_SOURCES}) |
|
||||||
|
|
||||||
source_group("Header Files" FILES ${pnSimpleNet_HEADERS}) |
|
||||||
source_group("Source Files" FILES ${pnSimpleNet_SOURCES}) |
|
@ -1,658 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "pnSimpleNet.h" |
|
||||||
#include "hsThread.h" |
|
||||||
|
|
||||||
#include <list> |
|
||||||
#include <map> |
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local types |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
struct SimpleNetConn : AtomicRef { |
|
||||||
AsyncSocket sock; |
|
||||||
AsyncCancelId cancelId; |
|
||||||
uint32_t channelId; |
|
||||||
bool abandoned; |
|
||||||
struct ConnectParam * connectParam; |
|
||||||
|
|
||||||
SimpleNet_MsgHeader * oversizeMsg; |
|
||||||
ARRAY(uint8_t) oversizeBuffer; |
|
||||||
}; |
|
||||||
|
|
||||||
struct SimpleNetChannel : AtomicRef { |
|
||||||
FSimpleNetOnMsg onMsg; |
|
||||||
FSimpleNetOnError onError; |
|
||||||
uint32_t channelId; |
|
||||||
std::list<SimpleNetConn*> conns; |
|
||||||
|
|
||||||
SimpleNetChannel (uint32_t channel) : channelId(channel) { } |
|
||||||
~SimpleNetChannel () { |
|
||||||
ASSERT(!conns.size()); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
struct ConnectParam { |
|
||||||
SimpleNetChannel * channel; |
|
||||||
FSimpleNetOnConnect callback; |
|
||||||
void * param; |
|
||||||
|
|
||||||
~ConnectParam () { |
|
||||||
if (channel) |
|
||||||
channel->DecRef(); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local data |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
static bool s_running; |
|
||||||
static hsMutex s_critsect; |
|
||||||
static FSimpleNetQueryAccept s_queryAccept; |
|
||||||
static void * s_queryAcceptParam; |
|
||||||
static std::map<uint32_t, SimpleNetChannel*> s_channels; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Local functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketConnect (SimpleNetConn * conn) { |
|
||||||
|
|
||||||
conn->TransferRef("Connecting", "Connected"); |
|
||||||
|
|
||||||
conn->connectParam->callback( |
|
||||||
conn->connectParam->param, |
|
||||||
conn, |
|
||||||
kNetSuccess |
|
||||||
); |
|
||||||
|
|
||||||
delete conn->connectParam; |
|
||||||
conn->connectParam = nil; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketConnectFailed (SimpleNetConn * conn) { |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { |
|
||||||
it->second->conns.remove(conn); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
conn->connectParam->callback( |
|
||||||
conn->connectParam->param, |
|
||||||
nil, |
|
||||||
kNetErrConnectFailed |
|
||||||
); |
|
||||||
|
|
||||||
delete conn->connectParam; |
|
||||||
conn->connectParam = nil; |
|
||||||
|
|
||||||
conn->DecRef("Connecting"); |
|
||||||
conn->DecRef("Lifetime"); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketDisconnect (SimpleNetConn * conn) { |
|
||||||
|
|
||||||
bool abandoned; |
|
||||||
SimpleNetChannel* channel = nil; |
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
abandoned = conn->abandoned; |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { |
|
||||||
channel = it->second; |
|
||||||
channel->IncRef(); |
|
||||||
channel->conns.remove(conn); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
if (channel && !abandoned) { |
|
||||||
channel->onError(conn, kNetErrDisconnected); |
|
||||||
channel->DecRef(); |
|
||||||
} |
|
||||||
|
|
||||||
conn->DecRef("Connected"); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool NotifyConnSocketRead (SimpleNetConn * conn, AsyncNotifySocketRead * read) { |
|
||||||
|
|
||||||
SimpleNetChannel* channel = nil; |
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { |
|
||||||
channel = it->second; |
|
||||||
channel->IncRef(); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
if (!channel) |
|
||||||
return false; |
|
||||||
|
|
||||||
bool result = true; |
|
||||||
|
|
||||||
const uint8_t * curr = read->buffer; |
|
||||||
const uint8_t * term = curr + read->bytes; |
|
||||||
|
|
||||||
while (curr < term) { |
|
||||||
// Reading oversize msg?
|
|
||||||
if (conn->oversizeBuffer.Count()) { |
|
||||||
unsigned spaceLeft = conn->oversizeMsg->messageBytes - conn->oversizeBuffer.Count(); |
|
||||||
unsigned copyBytes = min(spaceLeft, term - curr); |
|
||||||
conn->oversizeBuffer.Add(curr, copyBytes); |
|
||||||
|
|
||||||
curr += copyBytes; |
|
||||||
|
|
||||||
// Wait until we have received the entire message
|
|
||||||
if (copyBytes != spaceLeft) |
|
||||||
break; |
|
||||||
|
|
||||||
// Dispatch oversize msg
|
|
||||||
if (!channel->onMsg(conn, conn->oversizeMsg)) { |
|
||||||
result = false; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
conn->oversizeBuffer.SetCount(0); |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
// Wait until we receive the entire message header
|
|
||||||
if (term - curr < sizeof(SimpleNet_MsgHeader)) |
|
||||||
break; |
|
||||||
|
|
||||||
SimpleNet_MsgHeader * msg = (SimpleNet_MsgHeader *) read->buffer; |
|
||||||
|
|
||||||
// Sanity check message size
|
|
||||||
if (msg->messageBytes < sizeof(*msg)) { |
|
||||||
result = false; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
// Handle oversized messages
|
|
||||||
if (msg->messageBytes > kAsyncSocketBufferSize) { |
|
||||||
|
|
||||||
conn->oversizeBuffer.SetCount(msg->messageBytes); |
|
||||||
conn->oversizeMsg = (SimpleNet_MsgHeader *) conn->oversizeBuffer.Ptr(); |
|
||||||
*conn->oversizeMsg = *msg; |
|
||||||
|
|
||||||
curr += sizeof(*msg); |
|
||||||
continue; |
|
||||||
} |
|
||||||
|
|
||||||
// Wait until we have received the entire message
|
|
||||||
const uint8_t * msgTerm = (const uint8_t *) curr + msg->messageBytes; |
|
||||||
if (msgTerm > term) |
|
||||||
break; |
|
||||||
curr = msgTerm; |
|
||||||
|
|
||||||
// Dispatch msg
|
|
||||||
if (!channel->onMsg(conn, msg)) { |
|
||||||
result = false; |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Return count of bytes we processed
|
|
||||||
read->bytesProcessed = curr - read->buffer; |
|
||||||
|
|
||||||
channel->DecRef(); |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool AsyncNotifySocketProc ( |
|
||||||
AsyncSocket sock, |
|
||||||
EAsyncNotifySocket code, |
|
||||||
AsyncNotifySocket * notify, |
|
||||||
void ** userState |
|
||||||
) { |
|
||||||
bool result = true; |
|
||||||
SimpleNetConn * conn; |
|
||||||
|
|
||||||
switch (code) { |
|
||||||
case kNotifySocketListenSuccess: { |
|
||||||
|
|
||||||
AsyncNotifySocketListen * listen = (AsyncNotifySocketListen *) notify; |
|
||||||
|
|
||||||
const SimpleNet_ConnData & connect = *(const SimpleNet_ConnData *) listen->buffer; |
|
||||||
listen->bytesProcessed += sizeof(connect); |
|
||||||
|
|
||||||
SimpleNetChannel* channel = nil; |
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(connect.channelId)) != s_channels.end()) { |
|
||||||
channel = it->second; |
|
||||||
channel->IncRef(); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
if (!channel) |
|
||||||
break; |
|
||||||
|
|
||||||
conn = NEWZERO(SimpleNetConn); |
|
||||||
conn->channelId = channel->channelId; |
|
||||||
conn->IncRef("Lifetime"); |
|
||||||
conn->IncRef("Connected"); |
|
||||||
conn->sock = sock; |
|
||||||
*userState = conn; |
|
||||||
|
|
||||||
bool accepted = s_queryAccept( |
|
||||||
s_queryAcceptParam, |
|
||||||
channel->channelId, |
|
||||||
conn, |
|
||||||
listen->remoteAddr |
|
||||||
); |
|
||||||
|
|
||||||
if (!accepted) { |
|
||||||
SimpleNetDisconnect(conn); |
|
||||||
} |
|
||||||
else { |
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
channel->conns.push_back(conn); |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
} |
|
||||||
|
|
||||||
channel->DecRef(); |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketConnectSuccess: { |
|
||||||
conn = (SimpleNetConn *) notify->param; |
|
||||||
*userState = conn; |
|
||||||
bool abandoned; |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
conn->sock = sock; |
|
||||||
conn->cancelId = 0; |
|
||||||
abandoned = conn->abandoned; |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
if (abandoned) |
|
||||||
AsyncSocketDisconnect(sock, true); |
|
||||||
else |
|
||||||
NotifyConnSocketConnect(conn); |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketConnectFailed: |
|
||||||
conn = (SimpleNetConn *) notify->param; |
|
||||||
NotifyConnSocketConnectFailed(conn); |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketDisconnect: |
|
||||||
conn = (SimpleNetConn *) *userState; |
|
||||||
NotifyConnSocketDisconnect(conn); |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketRead: |
|
||||||
conn = (SimpleNetConn *) *userState; |
|
||||||
result = NotifyConnSocketRead(conn, (AsyncNotifySocketRead *) notify); |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void Connect(const plNetAddress& addr, ConnectParam * cp) { |
|
||||||
|
|
||||||
SimpleNetConn * conn = NEWZERO(SimpleNetConn); |
|
||||||
conn->channelId = cp->channel->channelId; |
|
||||||
conn->connectParam = cp; |
|
||||||
conn->IncRef("Lifetime"); |
|
||||||
conn->IncRef("Connecting"); |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
cp->channel->conns.push_back(conn); |
|
||||||
|
|
||||||
SimpleNet_Connect connect; |
|
||||||
connect.hdr.connType = kConnTypeSimpleNet; |
|
||||||
connect.hdr.hdrBytes = sizeof(connect.hdr); |
|
||||||
connect.hdr.buildId = BuildId(); |
|
||||||
connect.hdr.buildType = BUILD_TYPE_LIVE; |
|
||||||
connect.hdr.branchId = BranchId(); |
|
||||||
connect.hdr.productId = ProductId(); |
|
||||||
connect.data.channelId = cp->channel->channelId; |
|
||||||
|
|
||||||
AsyncSocketConnect( |
|
||||||
&conn->cancelId, |
|
||||||
addr, |
|
||||||
AsyncNotifySocketProc, |
|
||||||
conn, |
|
||||||
&connect, |
|
||||||
sizeof(connect) |
|
||||||
); |
|
||||||
|
|
||||||
conn = nil; |
|
||||||
cp = nil; |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
delete conn; |
|
||||||
delete cp; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void AsyncLookupCallback ( |
|
||||||
void * param, |
|
||||||
const char name[], |
|
||||||
unsigned addrCount, |
|
||||||
const plNetAddress addrs[] |
|
||||||
) { |
|
||||||
ConnectParam * cp = (ConnectParam *)param; |
|
||||||
|
|
||||||
if (!addrCount) { |
|
||||||
if (cp->callback) |
|
||||||
cp->callback(cp->param, nil, kNetErrNameLookupFailed); |
|
||||||
delete cp; |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
Connect(addrs[0], (ConnectParam *)param); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Exported functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetInitialize () { |
|
||||||
|
|
||||||
s_running = true; |
|
||||||
|
|
||||||
AsyncSocketRegisterNotifyProc( |
|
||||||
kConnTypeSimpleNet, |
|
||||||
AsyncNotifySocketProc |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetShutdown () { |
|
||||||
|
|
||||||
s_running = false; |
|
||||||
|
|
||||||
ASSERT(!s_channels.size()); |
|
||||||
|
|
||||||
AsyncSocketUnregisterNotifyProc( |
|
||||||
kConnTypeSimpleNet, |
|
||||||
AsyncNotifySocketProc |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetConnIncRef (SimpleNetConn * conn) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(conn); |
|
||||||
|
|
||||||
conn->IncRef(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetConnDecRef (SimpleNetConn * conn) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(conn); |
|
||||||
|
|
||||||
conn->DecRef(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool SimpleNetStartListening ( |
|
||||||
FSimpleNetQueryAccept queryAccept, |
|
||||||
void * param |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(queryAccept); |
|
||||||
ASSERT(!s_queryAccept); |
|
||||||
|
|
||||||
s_queryAccept = queryAccept; |
|
||||||
s_queryAcceptParam = param; |
|
||||||
|
|
||||||
plNetAddress addr; |
|
||||||
addr.SetPort(kNetDefaultSimpleNetPort); |
|
||||||
addr.SetAnyAddr(); |
|
||||||
return (0 != AsyncSocketStartListening(addr, nil)); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetStopListening () { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
plNetAddress addr; |
|
||||||
addr.SetPort(kNetDefaultSimpleNetPort); |
|
||||||
addr.SetAnyAddr(); |
|
||||||
AsyncSocketStopListening(addr, nil); |
|
||||||
|
|
||||||
s_queryAccept = nil; |
|
||||||
s_queryAcceptParam = nil; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetCreateChannel ( |
|
||||||
unsigned channelId, |
|
||||||
FSimpleNetOnMsg onMsg, |
|
||||||
FSimpleNetOnError onError |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
SimpleNetChannel * channel = NEWZERO(SimpleNetChannel)(channelId); |
|
||||||
channel->IncRef(); |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
#ifdef HS_DEBUGGING |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it = s_channels.find(channelId); |
|
||||||
ASSERT(it == s_channels.end()); |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
channel->onMsg = onMsg; |
|
||||||
channel->onError = onError; |
|
||||||
s_channels[channelId] = channel; |
|
||||||
channel->IncRef(); |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
channel->DecRef(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetDestroyChannel (unsigned channelId) { |
|
||||||
|
|
||||||
ASSERT(s_running); |
|
||||||
|
|
||||||
SimpleNetChannel * channel; |
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(channelId)) != s_channels.end()) { |
|
||||||
channel = it->second; |
|
||||||
|
|
||||||
while (channel->conns.size()) { |
|
||||||
SimpleNetConn* conn = channel->conns.front(); |
|
||||||
SimpleNetDisconnect(conn); |
|
||||||
|
|
||||||
channel->conns.pop_front(); |
|
||||||
} |
|
||||||
|
|
||||||
s_channels.erase(it); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
if (channel) |
|
||||||
channel->DecRef(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetStartConnecting ( |
|
||||||
unsigned channelId, |
|
||||||
const char addr[], |
|
||||||
FSimpleNetOnConnect onConnect, |
|
||||||
void * param |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(onConnect); |
|
||||||
|
|
||||||
ConnectParam * cp = new ConnectParam; |
|
||||||
cp->callback = onConnect; |
|
||||||
cp->param = param; |
|
||||||
cp->channel = nil; |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
std::map<uint32_t, SimpleNetChannel*>::iterator it; |
|
||||||
if ((it = s_channels.find(channelId)) != s_channels.end()) { |
|
||||||
cp->channel = it->second; |
|
||||||
cp->channel->IncRef(); |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
ASSERT(cp->channel); |
|
||||||
|
|
||||||
// Do we need to lookup the address?
|
|
||||||
const char* name = addr; |
|
||||||
while (unsigned ch = *name) { |
|
||||||
++name; |
|
||||||
if (!(isdigit(ch) || ch == L'.' || ch == L':')) { |
|
||||||
|
|
||||||
AsyncCancelId cancelId; |
|
||||||
AsyncAddressLookupName( |
|
||||||
&cancelId, |
|
||||||
AsyncLookupCallback, |
|
||||||
addr, |
|
||||||
kNetDefaultSimpleNetPort, |
|
||||||
cp |
|
||||||
); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
if (!name[0]) { |
|
||||||
plNetAddress netAddr(addr, kNetDefaultSimpleNetPort); |
|
||||||
Connect(netAddr, cp); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetDisconnect ( |
|
||||||
SimpleNetConn * conn |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(conn); |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
conn->abandoned = true; |
|
||||||
if (conn->sock) { |
|
||||||
AsyncSocketDisconnect(conn->sock, true); |
|
||||||
conn->sock = nil; |
|
||||||
} |
|
||||||
else if (conn->cancelId) { |
|
||||||
AsyncSocketConnectCancel(AsyncNotifySocketProc, conn->cancelId); |
|
||||||
conn->cancelId = nil; |
|
||||||
} |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
|
|
||||||
conn->DecRef("Lifetime"); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void SimpleNetSend ( |
|
||||||
SimpleNetConn * conn, |
|
||||||
SimpleNet_MsgHeader * msg |
|
||||||
) { |
|
||||||
ASSERT(s_running); |
|
||||||
ASSERT(msg); |
|
||||||
ASSERT(msg->messageBytes != (uint32_t)-1); |
|
||||||
ASSERT(conn); |
|
||||||
|
|
||||||
s_critsect.Lock(); |
|
||||||
{ |
|
||||||
if (conn->sock) |
|
||||||
AsyncSocketSend(conn->sock, msg, msg->messageBytes); |
|
||||||
} |
|
||||||
s_critsect.Unlock(); |
|
||||||
} |
|
@ -1,185 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSIMPLENET_PNSIMPLENET_H |
|
||||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSIMPLENET_PNSIMPLENET_H |
|
||||||
|
|
||||||
|
|
||||||
#include "pnUtils/pnUtils.h" |
|
||||||
#include "pnProduct/pnProduct.h" |
|
||||||
#include "pnNetBase/pnNetBase.h" |
|
||||||
#include "pnAsyncCore/pnAsyncCore.h" |
|
||||||
#include "pnNetCommon/plNetAddress.h" |
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* SimpleNet: |
|
||||||
* - TCP only, Nagle buffered only. |
|
||||||
* - Asynchronous callbacks only. |
|
||||||
* - Not encrypted, not compressed, no transaction support. |
|
||||||
* - Good for trivial networked applications only. Examples include: |
|
||||||
* - CSR client automation by CSR tools. |
|
||||||
* - Bob and I (eap) talked about 3dsmax automating |
|
||||||
* the client for the purpose of reloading reexported |
|
||||||
* assets. With SimpleNet, the client could be running |
|
||||||
* on a separate machine than Max. |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
// Because newer clients must remain compatible with older servers,
|
|
||||||
// these values may never change.
|
|
||||||
enum ESimpleNetChannel { |
|
||||||
kSimpleNetChannelNil = 0, |
|
||||||
kSimpleNetChannelCsr = 1, |
|
||||||
kSimpleNetChannelMax = 2, |
|
||||||
|
|
||||||
kMaxSimpleNetChannels |
|
||||||
}; |
|
||||||
COMPILER_ASSERT_HEADER(ESimpleNetChannel, kMaxSimpleNetChannels <= 0xff); |
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// BEGIN PACKED DATA STRUCTURES
|
|
||||||
//============================================================================
|
|
||||||
#pragma pack(push,1) |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Connect packet
|
|
||||||
|
|
||||||
struct SimpleNet_ConnData { |
|
||||||
unsigned channelId; |
|
||||||
}; |
|
||||||
struct SimpleNet_Connect { |
|
||||||
AsyncSocketConnectPacket hdr; |
|
||||||
SimpleNet_ConnData data; |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Message header
|
|
||||||
|
|
||||||
struct SimpleNet_MsgHeader { |
|
||||||
private: |
|
||||||
uint32_t channelId; |
|
||||||
public: |
|
||||||
uint32_t messageId; |
|
||||||
uint32_t messageBytes; |
|
||||||
|
|
||||||
SimpleNet_MsgHeader (uint32_t channelId, uint32_t messageId) |
|
||||||
: channelId(channelId) |
|
||||||
, messageId(messageId) |
|
||||||
#ifdef HS_DEBUGGING |
|
||||||
, messageBytes((uint32_t)-1) |
|
||||||
#endif |
|
||||||
{ } |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Simple Network API |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
struct SimpleNetConn; |
|
||||||
|
|
||||||
void SimpleNetInitialize (); |
|
||||||
void SimpleNetShutdown (); |
|
||||||
|
|
||||||
void SimpleNetConnIncRef (SimpleNetConn * conn); |
|
||||||
void SimpleNetConnDecRef (SimpleNetConn * conn); |
|
||||||
|
|
||||||
typedef bool (*FSimpleNetOnMsg) ( // return false to disconnect socket
|
|
||||||
SimpleNetConn * conn, |
|
||||||
SimpleNet_MsgHeader * msg |
|
||||||
); |
|
||||||
typedef void (*FSimpleNetOnError) ( |
|
||||||
SimpleNetConn * conn, |
|
||||||
ENetError error |
|
||||||
); |
|
||||||
typedef void (*FSimpleNetOnConnect) ( |
|
||||||
void * param, |
|
||||||
SimpleNetConn * conn, |
|
||||||
ENetError result |
|
||||||
); |
|
||||||
typedef bool (*FSimpleNetQueryAccept) ( // return true to accept incoming connection
|
|
||||||
void * param, |
|
||||||
unsigned channel, |
|
||||||
SimpleNetConn * conn, |
|
||||||
const plNetAddress& addr |
|
||||||
); |
|
||||||
|
|
||||||
void SimpleNetCreateChannel ( |
|
||||||
unsigned channel, |
|
||||||
FSimpleNetOnMsg onMsg, |
|
||||||
FSimpleNetOnError onError |
|
||||||
); |
|
||||||
void SimpleNetDestroyChannel ( |
|
||||||
unsigned channel |
|
||||||
); |
|
||||||
|
|
||||||
bool SimpleNetStartListening ( |
|
||||||
FSimpleNetQueryAccept queryAccept, |
|
||||||
void * param |
|
||||||
); |
|
||||||
void SimpleNetStopListening (); |
|
||||||
|
|
||||||
void SimpleNetStartConnecting ( |
|
||||||
unsigned channel, |
|
||||||
const wchar_t addr[], |
|
||||||
FSimpleNetOnConnect onConnect, |
|
||||||
void * param |
|
||||||
); |
|
||||||
void SimpleNetDisconnect ( |
|
||||||
SimpleNetConn * conn |
|
||||||
); |
|
||||||
void SimpleNetSend ( |
|
||||||
SimpleNetConn * conn, |
|
||||||
SimpleNet_MsgHeader * msg |
|
||||||
); |
|
||||||
#pragma pack(pop) |
|
||||||
|
|
||||||
#endif // PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSIMPLENET_PNSIMPLENET_H
|
|
@ -1,900 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#include "../Pch.h" |
|
||||||
#pragma hdrstop |
|
||||||
|
|
||||||
#include "pnEncryption/plChallengeHash.h" |
|
||||||
|
|
||||||
|
|
||||||
namespace Ngl { namespace Csr { |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Internal types |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
struct ConnectParam { |
|
||||||
FNetCliCsrConnectedCallback callback; |
|
||||||
void * param; |
|
||||||
}; |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Connection record
|
|
||||||
//============================================================================
|
|
||||||
struct CliCsConn : AtomicRef { |
|
||||||
LINK(CliCsConn) link; |
|
||||||
|
|
||||||
CCritSect critsect; |
|
||||||
AsyncSocket sock; |
|
||||||
AsyncCancelId cancelId; |
|
||||||
NetCli * cli; |
|
||||||
plNetAddress addr; |
|
||||||
unsigned seq; |
|
||||||
bool abandoned; |
|
||||||
unsigned serverChallenge; |
|
||||||
unsigned latestBuildId; |
|
||||||
ConnectParam * connectParam; |
|
||||||
|
|
||||||
// ping
|
|
||||||
AsyncTimer * pingTimer; |
|
||||||
unsigned pingSendTimeMs; |
|
||||||
unsigned lastHeardTimeMs; |
|
||||||
|
|
||||||
CliCsConn (); |
|
||||||
~CliCsConn (); |
|
||||||
|
|
||||||
void AutoPing (); |
|
||||||
void StopAutoPing (); |
|
||||||
void TimerPing (); |
|
||||||
|
|
||||||
void Send (const uintptr_t fields[], unsigned count); |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
// Transaction objects
|
|
||||||
//============================================================================
|
|
||||||
struct ConnectedNotifyTrans : NetNotifyTrans { |
|
||||||
|
|
||||||
ConnectParam * m_connectParam; |
|
||||||
unsigned m_latestBuildId; |
|
||||||
|
|
||||||
ConnectedNotifyTrans (ConnectParam * cp, unsigned lbi) |
|
||||||
: NetNotifyTrans(kCsrConnectedNotifyTrans) |
|
||||||
, m_connectParam(cp) |
|
||||||
, m_latestBuildId(lbi) |
|
||||||
{ } |
|
||||||
~ConnectedNotifyTrans () { |
|
||||||
delete m_connectParam; |
|
||||||
} |
|
||||||
void Post (); |
|
||||||
}; |
|
||||||
|
|
||||||
struct LoginRequestTrans : NetCsrTrans { |
|
||||||
|
|
||||||
wchar_t m_csrName[kMaxAccountNameLength]; |
|
||||||
ShaDigest m_namePassHash; |
|
||||||
FNetCliCsrLoginCallback m_callback; |
|
||||||
void * m_param; |
|
||||||
|
|
||||||
Uuid m_csrId; |
|
||||||
unsigned m_csrFlags; |
|
||||||
|
|
||||||
LoginRequestTrans ( |
|
||||||
const wchar_t csrName[], |
|
||||||
const ShaDigest & namePassHash, |
|
||||||
FNetCliCsrLoginCallback callback, |
|
||||||
void * param |
|
||||||
); |
|
||||||
|
|
||||||
bool Send (); |
|
||||||
void Post (); |
|
||||||
bool Recv ( |
|
||||||
const uint8_t msg[], |
|
||||||
unsigned bytes |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Internal data |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
enum { |
|
||||||
kPerfConnCount, |
|
||||||
kPingDisabled, |
|
||||||
kNumPerf |
|
||||||
}; |
|
||||||
|
|
||||||
static bool s_running; |
|
||||||
static CCritSect s_critsect; |
|
||||||
static LISTDECL(CliCsConn, link) s_conns; |
|
||||||
static CliCsConn * s_active; |
|
||||||
static long s_perf[kNumPerf]; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Internal functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static unsigned GetNonZeroTimeMs () { |
|
||||||
if (unsigned ms = TimeGetMs()) |
|
||||||
return ms; |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static CliCsConn * GetConnIncRef_CS (const char tag[]) { |
|
||||||
|
|
||||||
if (CliCsConn * conn = s_active) |
|
||||||
if (conn->cli) { |
|
||||||
conn->IncRef(tag); |
|
||||||
return conn; |
|
||||||
} |
|
||||||
return nil; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static CliCsConn * GetConnIncRef (const char tag[]) { |
|
||||||
CliCsConn * conn; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
conn = GetConnIncRef_CS(tag); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
return conn; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void UnlinkAndAbandonConn_CS (CliCsConn * conn) { |
|
||||||
|
|
||||||
s_conns.Unlink(conn); |
|
||||||
conn->abandoned = true; |
|
||||||
if (conn->cancelId) { |
|
||||||
AsyncSocketConnectCancel(nil, conn->cancelId); |
|
||||||
conn->cancelId = 0; |
|
||||||
} |
|
||||||
else if (conn->sock) { |
|
||||||
AsyncSocketDisconnect(conn->sock, true); |
|
||||||
} |
|
||||||
else { |
|
||||||
conn->DecRef("Lifetime"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void SendRegisterRequest (CliCsConn * conn) { |
|
||||||
|
|
||||||
const uintptr_t msg[] = { |
|
||||||
kCli2Csr_RegisterRequest, |
|
||||||
0 |
|
||||||
}; |
|
||||||
|
|
||||||
conn->Send(msg, arrsize(msg)); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool ConnEncrypt (ENetError error, void * param) { |
|
||||||
|
|
||||||
CliCsConn * conn = (CliCsConn *) param; |
|
||||||
|
|
||||||
if (IS_NET_SUCCESS(error)) { |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
s_active = conn; |
|
||||||
conn->AutoPing(); |
|
||||||
conn->IncRef(); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
|
|
||||||
SendRegisterRequest(conn); |
|
||||||
|
|
||||||
conn->DecRef(); |
|
||||||
} |
|
||||||
|
|
||||||
return IS_NET_SUCCESS(error); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketConnect (CliCsConn * conn) { |
|
||||||
|
|
||||||
conn->cli = NetCliConnectAccept( |
|
||||||
conn->sock, |
|
||||||
kNetProtocolCli2Csr, |
|
||||||
false, |
|
||||||
ConnEncrypt, |
|
||||||
0, |
|
||||||
nil, |
|
||||||
conn |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketConnectFailed (CliCsConn * conn) { |
|
||||||
|
|
||||||
bool notify; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
conn->cancelId = 0; |
|
||||||
s_conns.Unlink(conn); |
|
||||||
|
|
||||||
notify |
|
||||||
= s_running |
|
||||||
&& !conn->abandoned |
|
||||||
&& (!s_active || conn == s_active); |
|
||||||
|
|
||||||
if (conn == s_active) |
|
||||||
s_active = nil; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
|
|
||||||
NetTransCancelByConnId(conn->seq, kNetErrTimeout); |
|
||||||
conn->DecRef("Connecting"); |
|
||||||
conn->DecRef("Lifetime"); |
|
||||||
|
|
||||||
if (notify) |
|
||||||
ReportNetError(kNetProtocolCli2Csr, kNetErrConnectFailed); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void NotifyConnSocketDisconnect (CliCsConn * conn) { |
|
||||||
|
|
||||||
conn->StopAutoPing(); |
|
||||||
|
|
||||||
bool notify; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
s_conns.Unlink(conn); |
|
||||||
|
|
||||||
notify |
|
||||||
= s_running |
|
||||||
&& !conn->abandoned |
|
||||||
&& (!s_active || conn == s_active); |
|
||||||
|
|
||||||
if (conn == s_active) |
|
||||||
s_active = nil; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
|
|
||||||
// Cancel all transactions in process on this connection.
|
|
||||||
NetTransCancelByConnId(conn->seq, kNetErrTimeout); |
|
||||||
conn->DecRef("Connected"); |
|
||||||
conn->DecRef("Lifetime"); |
|
||||||
|
|
||||||
if (notify) |
|
||||||
ReportNetError(kNetProtocolCli2Csr, kNetErrDisconnected); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool NotifyConnSocketRead (CliCsConn * conn, AsyncNotifySocketRead * read) { |
|
||||||
|
|
||||||
conn->lastHeardTimeMs = GetNonZeroTimeMs(); |
|
||||||
bool result = NetCliDispatch(conn->cli, read->buffer, read->bytes, conn); |
|
||||||
read->bytesProcessed += read->bytes; |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool SocketNotifyCallback ( |
|
||||||
AsyncSocket sock, |
|
||||||
EAsyncNotifySocket code, |
|
||||||
AsyncNotifySocket * notify, |
|
||||||
void ** userState |
|
||||||
) { |
|
||||||
bool result = true; |
|
||||||
CliCsConn * conn; |
|
||||||
|
|
||||||
switch (code) { |
|
||||||
case kNotifySocketConnectSuccess: { |
|
||||||
conn = (CliCsConn *) notify->param; |
|
||||||
*userState = conn; |
|
||||||
conn->TransferRef("Connecting", "Connected"); |
|
||||||
bool abandoned = true; |
|
||||||
|
|
||||||
if (abandoned) |
|
||||||
AsyncSocketDisconnect(sock, true); |
|
||||||
else |
|
||||||
NotifyConnSocketConnect(conn); |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketConnectFailed: |
|
||||||
conn = (CliCsConn *) notify->param; |
|
||||||
NotifyConnSocketConnectFailed(conn); |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketDisconnect: |
|
||||||
conn = (CliCsConn *) *userState; |
|
||||||
NotifyConnSocketDisconnect(conn); |
|
||||||
break; |
|
||||||
|
|
||||||
case kNotifySocketRead: |
|
||||||
conn = (CliCsConn *) *userState; |
|
||||||
result = NotifyConnSocketRead(conn, (AsyncNotifySocketRead *) notify); |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void Connect ( |
|
||||||
const plNetAddress& addr, |
|
||||||
ConnectParam * cp |
|
||||||
) { |
|
||||||
CliCsConn * conn = NEWZERO(CliCsConn); |
|
||||||
conn->addr = addr; |
|
||||||
conn->seq = ConnNextSequence(); |
|
||||||
conn->lastHeardTimeMs = GetNonZeroTimeMs(); |
|
||||||
conn->connectParam = cp; |
|
||||||
|
|
||||||
conn->IncRef("Lifetime"); |
|
||||||
conn->IncRef("Connecting"); |
|
||||||
|
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
while (CliCsConn * conn = s_conns.Head()) |
|
||||||
UnlinkAndAbandonConn_CS(conn); |
|
||||||
s_conns.Link(conn); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
|
|
||||||
Cli2Csr_Connect connect; |
|
||||||
connect.hdr.connType = kConnTypeCliToCsr; |
|
||||||
connect.hdr.hdrBytes = sizeof(connect.hdr); |
|
||||||
connect.hdr.buildId = BuildId(); |
|
||||||
connect.hdr.buildType = BUILD_TYPE_LIVE; |
|
||||||
connect.hdr.branchId = BranchId(); |
|
||||||
connect.hdr.productId = ProductId(); |
|
||||||
connect.data.dataBytes = sizeof(connect.data); |
|
||||||
|
|
||||||
AsyncSocketConnect( |
|
||||||
&conn->cancelId, |
|
||||||
addr, |
|
||||||
SocketNotifyCallback, |
|
||||||
conn, |
|
||||||
&connect, |
|
||||||
sizeof(connect), |
|
||||||
0, |
|
||||||
0 |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static void AsyncLookupCallback ( |
|
||||||
void * param, |
|
||||||
const char name[], |
|
||||||
unsigned addrCount, |
|
||||||
const plNetAddress addrs[] |
|
||||||
) { |
|
||||||
if (!addrCount) { |
|
||||||
ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
// Only connect to one server
|
|
||||||
addrCount = MIN(addrCount, 1); |
|
||||||
|
|
||||||
for (unsigned i = 0; i < addrCount; ++i) { |
|
||||||
Connect(addrs[i], (ConnectParam *)param); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Message handlers |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool Recv_PingReply ( |
|
||||||
const uint8_t msg[], |
|
||||||
unsigned bytes, |
|
||||||
void * |
|
||||||
) { |
|
||||||
const Csr2Cli_PingReply & reply = *(const Csr2Cli_PingReply *)msg; |
|
||||||
|
|
||||||
NetTransRecv(reply.transId, msg, bytes); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool Recv_RegisterReply ( |
|
||||||
const uint8_t msg[], |
|
||||||
unsigned , |
|
||||||
void * param |
|
||||||
) { |
|
||||||
CliCsConn * conn = (CliCsConn *)param; |
|
||||||
|
|
||||||
const Csr2Cli_RegisterReply & reply = *(const Csr2Cli_RegisterReply *)msg; |
|
||||||
|
|
||||||
conn->serverChallenge = reply.serverChallenge; |
|
||||||
conn->latestBuildId = reply.csrBuildId; |
|
||||||
|
|
||||||
ConnectedNotifyTrans * trans = new ConnectedNotifyTrans( |
|
||||||
conn->connectParam, |
|
||||||
conn->latestBuildId |
|
||||||
); |
|
||||||
NetTransSend(trans); |
|
||||||
|
|
||||||
conn->connectParam = nil; |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
static bool Recv_LoginReply ( |
|
||||||
const uint8_t msg[], |
|
||||||
unsigned bytes, |
|
||||||
void * |
|
||||||
) { |
|
||||||
const Csr2Cli_LoginReply & reply = *(const Csr2Cli_LoginReply *)msg; |
|
||||||
|
|
||||||
NetTransRecv(reply.transId, msg, bytes); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Protocol |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
#define MSG(s) kNetMsg_Cli2Csr_##s |
|
||||||
static NetMsgInitSend s_send[] = { |
|
||||||
{ MSG(PingRequest) }, |
|
||||||
{ MSG(RegisterRequest) }, |
|
||||||
{ MSG(LoginRequest) }, |
|
||||||
}; |
|
||||||
#undef MSG |
|
||||||
|
|
||||||
#define MSG(s) kNetMsg_Csr2Cli_##s, Recv_##s |
|
||||||
static NetMsgInitRecv s_recv[] = { |
|
||||||
{ MSG(PingReply) }, |
|
||||||
{ MSG(RegisterReply) }, |
|
||||||
{ MSG(LoginReply) }, |
|
||||||
}; |
|
||||||
#undef MSG |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* CliCsConn |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static unsigned CliCsConnTimerDestroyed (void * param) { |
|
||||||
|
|
||||||
CliCsConn * conn = (CliCsConn *) param; |
|
||||||
conn->DecRef("PingTimer"); |
|
||||||
return kAsyncTimeInfinite; |
|
||||||
} |
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
static unsigned CliCsConnPingTimerProc (void * param) { |
|
||||||
|
|
||||||
((CliCsConn *) param)->TimerPing(); |
|
||||||
return kPingIntervalMs; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
CliCsConn::CliCsConn () { |
|
||||||
|
|
||||||
AtomicAdd(&s_perf[kPerfConnCount], 1); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
CliCsConn::~CliCsConn () { |
|
||||||
|
|
||||||
// Delete 'cli' after all refs have been removed
|
|
||||||
if (cli) |
|
||||||
NetCliDelete(cli, true); |
|
||||||
|
|
||||||
delete connectParam; |
|
||||||
|
|
||||||
AtomicAdd(&s_perf[kPerfConnCount], -1); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CliCsConn::AutoPing () { |
|
||||||
ASSERT(!pingTimer); |
|
||||||
|
|
||||||
IncRef("PingTimer"); |
|
||||||
critsect.Enter(); |
|
||||||
{ |
|
||||||
AsyncTimerCreate( |
|
||||||
&pingTimer, |
|
||||||
CliCsConnPingTimerProc, |
|
||||||
sock ? 0 : kAsyncTimeInfinite, |
|
||||||
this |
|
||||||
); |
|
||||||
} |
|
||||||
critsect.Leave(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CliCsConn::StopAutoPing () { |
|
||||||
critsect.Enter(); |
|
||||||
{ |
|
||||||
if (AsyncTimer * timer = pingTimer) { |
|
||||||
pingTimer = nil; |
|
||||||
AsyncTimerDeleteCallback(timer, CliCsConnTimerDestroyed); |
|
||||||
} |
|
||||||
} |
|
||||||
critsect.Leave(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CliCsConn::TimerPing () { |
|
||||||
|
|
||||||
// Send a ping request
|
|
||||||
pingSendTimeMs = GetNonZeroTimeMs(); |
|
||||||
|
|
||||||
const uintptr_t msg[] = { |
|
||||||
kCli2Auth_PingRequest, |
|
||||||
0, // not a transaction
|
|
||||||
pingSendTimeMs, |
|
||||||
0, // no payload
|
|
||||||
nil |
|
||||||
}; |
|
||||||
|
|
||||||
Send(msg, arrsize(msg)); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CliCsConn::Send (const uintptr_t fields[], unsigned count) { |
|
||||||
|
|
||||||
critsect.Enter(); |
|
||||||
{ |
|
||||||
NetCliSend(cli, fields, count); |
|
||||||
NetCliFlush(cli); |
|
||||||
} |
|
||||||
critsect.Leave(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* ConnectedNotifyTrans |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void ConnectedNotifyTrans::Post () { |
|
||||||
|
|
||||||
if (m_connectParam && m_connectParam->callback) |
|
||||||
m_connectParam->callback(m_connectParam->param, m_latestBuildId); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* LoginRequestTrans |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
LoginRequestTrans::LoginRequestTrans ( |
|
||||||
const wchar_t csrName[], |
|
||||||
const ShaDigest & namePassHash, |
|
||||||
FNetCliCsrLoginCallback callback, |
|
||||||
void * param |
|
||||||
) : NetCsrTrans(kCsrLoginTrans) |
|
||||||
, m_callback(callback) |
|
||||||
, m_param(param) |
|
||||||
{ |
|
||||||
ASSERT(callback); |
|
||||||
memcpy(m_namePassHash, namePassHash, sizeof(ShaDigest)); |
|
||||||
StrCopy(m_csrName, csrName, arrsize(m_csrName)); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool LoginRequestTrans::Send () { |
|
||||||
|
|
||||||
if (!AcquireConn()) |
|
||||||
return false; |
|
||||||
|
|
||||||
ShaDigest challengeHash; |
|
||||||
uint32_t clientChallenge = 0; |
|
||||||
|
|
||||||
CryptCreateRandomSeed( |
|
||||||
sizeof(clientChallenge), |
|
||||||
(uint8_t *) &clientChallenge |
|
||||||
); |
|
||||||
|
|
||||||
CryptHashPasswordChallenge( |
|
||||||
clientChallenge, |
|
||||||
s_active->serverChallenge, |
|
||||||
m_namePassHash, |
|
||||||
challengeHash |
|
||||||
); |
|
||||||
|
|
||||||
const uintptr_t msg[] = { |
|
||||||
kCli2Csr_LoginRequest, |
|
||||||
m_transId, |
|
||||||
clientChallenge, |
|
||||||
(uintptr_t) m_csrName, |
|
||||||
(uintptr_t) &challengeHash |
|
||||||
}; |
|
||||||
|
|
||||||
m_conn->Send(msg, arrsize(msg)); |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void LoginRequestTrans::Post () { |
|
||||||
m_callback( |
|
||||||
m_result, |
|
||||||
m_param, |
|
||||||
m_csrId, |
|
||||||
m_csrFlags |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool LoginRequestTrans::Recv ( |
|
||||||
const uint8_t msg[], |
|
||||||
unsigned bytes |
|
||||||
) { |
|
||||||
const Csr2Cli_LoginReply & reply = *(const Csr2Cli_LoginReply *) msg; |
|
||||||
|
|
||||||
m_result = reply.result; |
|
||||||
m_csrId = reply.csrId; |
|
||||||
m_csrFlags = reply.csrFlags; |
|
||||||
|
|
||||||
m_state = kTransStateComplete; |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} using namespace Csr; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* NetCsrTrans |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
NetCsrTrans::NetCsrTrans (ETransType transType) |
|
||||||
: NetTrans(kNetProtocolCli2Csr, transType) |
|
||||||
, m_conn(nil) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
NetCsrTrans::~NetCsrTrans () { |
|
||||||
ReleaseConn(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool NetCsrTrans::AcquireConn () { |
|
||||||
if (!m_conn) |
|
||||||
m_conn = GetConnIncRef("AcquireConn"); |
|
||||||
return m_conn != nil; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void NetCsrTrans::ReleaseConn () { |
|
||||||
if (m_conn) { |
|
||||||
m_conn->DecRef("AcquireConn"); |
|
||||||
m_conn = nil; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Module functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrInitialize () { |
|
||||||
|
|
||||||
s_running = true; |
|
||||||
|
|
||||||
NetMsgProtocolRegister( |
|
||||||
kNetProtocolCli2Csr, |
|
||||||
false, |
|
||||||
s_send, arrsize(s_send), |
|
||||||
s_recv, arrsize(s_recv), |
|
||||||
kCsrDhGValue, |
|
||||||
plBigNum(sizeof(kCsrDhXData), kCsrDhXData), |
|
||||||
plBigNum(sizeof(kCsrDhNData), kCsrDhNData) |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CsrDestroy (bool wait) { |
|
||||||
|
|
||||||
s_running = false; |
|
||||||
|
|
||||||
NetTransCancelByProtocol( |
|
||||||
kNetProtocolCli2Csr, |
|
||||||
kNetErrRemoteShutdown |
|
||||||
);
|
|
||||||
NetMsgProtocolDestroy( |
|
||||||
kNetProtocolCli2Csr, |
|
||||||
false |
|
||||||
); |
|
||||||
|
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
while (CliCsConn * conn = s_conns.Head()) |
|
||||||
UnlinkAndAbandonConn_CS(conn); |
|
||||||
s_active = nil; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
|
|
||||||
if (!wait) |
|
||||||
return; |
|
||||||
|
|
||||||
while (s_perf[kPerfConnCount]) { |
|
||||||
NetTransUpdate(); |
|
||||||
AsyncSleep(10); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
bool CsrQueryConnected () { |
|
||||||
|
|
||||||
bool result; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
if (nil != (result = s_active)) |
|
||||||
result &= (nil != s_active->cli); |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
return result; |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
unsigned CsrGetConnId () { |
|
||||||
|
|
||||||
unsigned connId; |
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
connId = (s_active) ? s_active->seq : 0; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
return connId; |
|
||||||
} |
|
||||||
|
|
||||||
} using namespace Ngl; |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Exports |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void NetCliCsrStartConnect ( |
|
||||||
const char* addrList[], |
|
||||||
uint32_t addrCount, |
|
||||||
FNetCliCsrConnectedCallback callback, |
|
||||||
void * param |
|
||||||
) { |
|
||||||
// Only connect to one server
|
|
||||||
addrCount = min(addrCount, 1); |
|
||||||
|
|
||||||
for (unsigned i = 0; i < addrCount; ++i) { |
|
||||||
// Do we need to lookup the address?
|
|
||||||
const char* name = addrList[i]; |
|
||||||
while (unsigned ch = *name) { |
|
||||||
++name; |
|
||||||
if (!(isdigit(ch) || ch == L'.' || ch == L':')) { |
|
||||||
ConnectParam * cp = new ConnectParam; |
|
||||||
cp->callback = callback; |
|
||||||
cp->param = param; |
|
||||||
|
|
||||||
AsyncCancelId cancelId; |
|
||||||
AsyncAddressLookupName( |
|
||||||
&cancelId, |
|
||||||
AsyncLookupCallback, |
|
||||||
addrList[i], |
|
||||||
kNetDefaultClientPort, |
|
||||||
cp |
|
||||||
); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
if (!name[0]) { |
|
||||||
plNetAddress addr(addrList[i], kNetDefaultClientPort); |
|
||||||
|
|
||||||
ConnectParam * cp = new ConnectParam; |
|
||||||
cp->callback = callback; |
|
||||||
cp->param = param; |
|
||||||
|
|
||||||
Connect(addr, cp); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void NetCliCsrDisconnect () { |
|
||||||
|
|
||||||
s_critsect.Enter(); |
|
||||||
{ |
|
||||||
while (CliCsConn * conn = s_conns.Head()) |
|
||||||
UnlinkAndAbandonConn_CS(conn); |
|
||||||
s_active = nil; |
|
||||||
} |
|
||||||
s_critsect.Leave(); |
|
||||||
} |
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void NetCliCsrLoginRequest ( |
|
||||||
const wchar_t csrName[], |
|
||||||
const ShaDigest & namePassHash, |
|
||||||
FNetCliCsrLoginCallback callback, |
|
||||||
void * param |
|
||||||
) { |
|
||||||
LoginRequestTrans * trans = new LoginRequestTrans( |
|
||||||
csrName, |
|
||||||
namePassHash, |
|
||||||
callback, |
|
||||||
param |
|
||||||
); |
|
||||||
NetTransSend(trans); |
|
||||||
} |
|
@ -1,94 +0,0 @@ |
|||||||
/*==LICENSE==*
|
|
||||||
|
|
||||||
CyanWorlds.com Engine - MMOG client, server and tools |
|
||||||
Copyright (C) 2011 Cyan Worlds, Inc. |
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU General Public License as published by |
|
||||||
the Free Software Foundation, either version 3 of the License, or |
|
||||||
(at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional permissions under GNU GPL version 3 section 7 |
|
||||||
|
|
||||||
If you modify this Program, or any covered work, by linking or |
|
||||||
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, |
|
||||||
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent |
|
||||||
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK |
|
||||||
(or a modified version of those libraries), |
|
||||||
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, |
|
||||||
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG |
|
||||||
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the |
|
||||||
licensors of this Program grant you additional |
|
||||||
permission to convey the resulting work. Corresponding Source for a |
|
||||||
non-source form of such a combination shall include the source code for |
|
||||||
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered |
|
||||||
work. |
|
||||||
|
|
||||||
You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
||||||
or by snail mail at: |
|
||||||
Cyan Worlds, Inc. |
|
||||||
14617 N Newport Hwy |
|
||||||
Mead, WA 99021 |
|
||||||
|
|
||||||
*==LICENSE==*/ |
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h |
|
||||||
*
|
|
||||||
***/ |
|
||||||
|
|
||||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCSR_H |
|
||||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h included more than once" |
|
||||||
#endif |
|
||||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCSR_H |
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
|
||||||
* |
|
||||||
* Client-side CSR functions |
|
||||||
* |
|
||||||
***/ |
|
||||||
|
|
||||||
typedef void (*FNetCliCsrConnectedCallback) ( |
|
||||||
void * param, |
|
||||||
unsigned latestBuildId |
|
||||||
); |
|
||||||
void NetCliCsrStartConnect ( |
|
||||||
const char* addrList[], |
|
||||||
uint32_t addrCount, |
|
||||||
FNetCliCsrConnectedCallback callback = nil, |
|
||||||
void * param = nil |
|
||||||
); |
|
||||||
void NetCliCsrDisconnect (); |
|
||||||
|
|
||||||
typedef void (*FNetCliCsrLoginCallback)( |
|
||||||
ENetError result, |
|
||||||
void * param, |
|
||||||
const Uuid & csrId, |
|
||||||
unsigned csrFlags |
|
||||||
); |
|
||||||
void NetCliCsrLoginRequest ( |
|
||||||
const wchar_t csrName[], |
|
||||||
const ShaDigest & namePassHash, |
|
||||||
FNetCliCsrLoginCallback callback, |
|
||||||
void * param |
|
||||||
); |
|
||||||
|
|
||||||
typedef void (*FNetCliCsrSetTicketFilterCallback)( |
|
||||||
ENetError result, |
|
||||||
void * param |
|
||||||
); |
|
||||||
void NetCliCsrSetTicketFilter ( |
|
||||||
const wchar_t filterSpec[], |
|
||||||
FNetCliCsrSetTicketFilterCallback callback, |
|
||||||
void * param |
|
||||||
); |
|
||||||
|
|
Loading…
Reference in new issue