mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-13 18:17:49 -04:00
CWE Directory Reorganization
Rearrange directory structure of CWE to be loosely equivalent to the H'uru Plasma repository. Part 1: Movement of directories and files.
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
/*==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/plNglAllIncludes.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLALLINCLUDES_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAllIncludes.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLALLINCLUDES_H
|
||||
|
||||
|
||||
// libs on which we rely
|
||||
#include "../pnGameMgr/pnGameMgr.h"
|
||||
|
||||
#include "plNglCore.h"
|
||||
#include "plNglAuth.h"
|
||||
#include "plNglGame.h"
|
||||
#include "plNglFile.h"
|
||||
#include "plNglCsr.h"
|
||||
#include "plNglGateKeeper.h"
|
6132
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
Normal file
6132
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
Normal file
File diff suppressed because it is too large
Load Diff
717
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h
Normal file
717
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h
Normal file
@ -0,0 +1,717 @@
|
||||
/*==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/plNglAuth.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Client auth functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
// Connect
|
||||
//============================================================================
|
||||
void NetCliAuthStartConnect (
|
||||
const wchar * authAddrList[],
|
||||
unsigned authAddrCount
|
||||
);
|
||||
bool NetCliAuthQueryConnected ();
|
||||
void NetCliAuthAutoReconnectEnable (bool enable); // is enabled by default
|
||||
unsigned NetCliAuthGetCurrentConnPort(); // for Game Server socket port
|
||||
|
||||
// Called after the auth/client connection is encrypted
|
||||
typedef void (*FNetCliAuthConnectCallback)();
|
||||
void NetCliAuthSetConnectCallback (
|
||||
FNetCliAuthConnectCallback callback
|
||||
);
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Disconnect
|
||||
//============================================================================
|
||||
void NetCliAuthDisconnect ();
|
||||
void NetCliAuthUnexpectedDisconnect ();
|
||||
|
||||
//============================================================================
|
||||
// Ping
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthPingRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned pingAtMs,
|
||||
unsigned replyAtMs,
|
||||
unsigned payloadbytes,
|
||||
const byte payload[]
|
||||
);
|
||||
void NetCliAuthPingRequest (
|
||||
unsigned pingTimeMs,
|
||||
unsigned payloadBytes, // max 64k (pnNetCli enforced upon send)
|
||||
const void * payload,
|
||||
FNetCliAuthPingRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// AccountExists
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountExistsRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
bool accountExists
|
||||
);
|
||||
void NetCliAuthAccountExistsRequest (
|
||||
const wchar accountName[],
|
||||
FNetCliAuthAccountExistsRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Login
|
||||
//============================================================================
|
||||
struct NetCliAuthPlayerInfo {
|
||||
unsigned playerInt;
|
||||
wchar playerName[kMaxPlayerNameLength];
|
||||
wchar avatarShape[kMaxVaultNodeStringLength];
|
||||
unsigned playerFlags;
|
||||
unsigned explorer;
|
||||
};
|
||||
|
||||
typedef void (*FNetCliAuthLoginRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const Uuid & accountId,
|
||||
unsigned accountFlags,
|
||||
unsigned billingType,
|
||||
const NetCliAuthPlayerInfo playerInfoArr[],
|
||||
unsigned playerCount
|
||||
);
|
||||
void NetCliAuthLoginRequest (
|
||||
const wchar accountName[], // nil --> reuse previous acct name
|
||||
const ShaDigest * accountNamePassHash, // nil --> reuse previous acct pass
|
||||
const wchar authToken[], // nil --> reuse previous auth token
|
||||
const wchar os[], // nil --> reuse previous os
|
||||
FNetCliAuthLoginRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Set Player
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthSetPlayerRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthSetPlayerRequest (
|
||||
unsigned playerInt,
|
||||
FNetCliAuthSetPlayerRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Create Account
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountCreateRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const Uuid & accountId
|
||||
);
|
||||
void NetCliAuthAccountCreateRequest (
|
||||
const wchar accountName[],
|
||||
const wchar accountPass[],
|
||||
unsigned accountFlags,
|
||||
unsigned billingType,
|
||||
FNetCliAuthAccountCreateRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Create Account From Key
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountCreateFromKeyRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const Uuid & accountId,
|
||||
const Uuid & activationKey
|
||||
);
|
||||
void NetCliAuthAccountCreateFromKeyRequest (
|
||||
const wchar accountName[],
|
||||
const wchar accountPass[],
|
||||
Uuid key,
|
||||
unsigned billingType,
|
||||
FNetCliAuthAccountCreateFromKeyRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Create Player
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthPlayerCreateRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const NetCliAuthPlayerInfo & playerInfo
|
||||
);
|
||||
void NetCliAuthPlayerCreateRequest (
|
||||
const wchar playerName[],
|
||||
const wchar avatarShape[],
|
||||
const wchar friendInvite[],
|
||||
FNetCliAuthPlayerCreateRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Delete Player
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthPlayerDeleteRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthPlayerDeleteRequest (
|
||||
unsigned playerId,
|
||||
FNetCliAuthPlayerDeleteRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Upgrade Visitor
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthUpgradeVisitorRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthUpgradeVisitorRequest (
|
||||
unsigned playerId,
|
||||
FNetCliAuthUpgradeVisitorRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// SetCCRLevel
|
||||
//============================================================================
|
||||
void NetCliAuthSetCCRLevel (
|
||||
unsigned ccrLevel
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// SetAgePublic
|
||||
//============================================================================
|
||||
void NetCliAuthSetAgePublic (
|
||||
unsigned ageInfoId,
|
||||
bool publicOrNot
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// GetPublicAgeList
|
||||
//============================================================================
|
||||
struct NetAgeInfo;
|
||||
typedef void (*FNetCliAuthGetPublicAgeListCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const ARRAY(NetAgeInfo) & ages
|
||||
);
|
||||
void NetCliAuthGetPublicAgeList (
|
||||
const wchar ageName[],
|
||||
FNetCliAuthGetPublicAgeListCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Change Password
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountChangePasswordRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthAccountChangePasswordRequest (
|
||||
const wchar accountName[],
|
||||
const wchar accountPass[],
|
||||
FNetCliAuthAccountChangePasswordRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Set Account Roles
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountSetRolesRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthAccountSetRolesRequest (
|
||||
const wchar accountName[],
|
||||
unsigned accountFlags,
|
||||
FNetCliAuthAccountSetRolesRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Set Billing Type
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountSetBillingTypeRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthAccountSetBillingTypeRequest (
|
||||
const wchar accountName[],
|
||||
unsigned billingType,
|
||||
FNetCliAuthAccountSetBillingTypeRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Account Activate
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAccountActivateRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthAccountActivateRequest (
|
||||
const Uuid & activationKey,
|
||||
FNetCliAuthAccountActivateRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Age
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthAgeRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned ageMcpId,
|
||||
unsigned ageVaultId,
|
||||
const Uuid & ageInstId,
|
||||
NetAddressNode gameAddr
|
||||
);
|
||||
void NetCliAuthAgeRequest (
|
||||
const wchar ageName[], // L"Teledahn"
|
||||
const Uuid & ageInstId,
|
||||
FNetCliAuthAgeRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Secure File Encryption Key
|
||||
//============================================================================
|
||||
void NetCliAuthGetEncryptionKey (
|
||||
UInt32 key[],
|
||||
unsigned size
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// File List
|
||||
//============================================================================
|
||||
struct NetCliAuthFileInfo {
|
||||
wchar filename[MAX_PATH];
|
||||
unsigned filesize;
|
||||
};
|
||||
typedef void (*FNetCliAuthFileListRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const NetCliAuthFileInfo infoArr[],
|
||||
unsigned infoCount
|
||||
);
|
||||
void NetCliAuthFileListRequest (
|
||||
const wchar dir[],
|
||||
const wchar ext[],
|
||||
FNetCliAuthFileListRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// File Download
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthFileRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const wchar filename[],
|
||||
hsStream * writer
|
||||
);
|
||||
void NetCliAuthFileRequest (
|
||||
const wchar filename[],
|
||||
hsStream * writer,
|
||||
FNetCliAuthFileRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Vault Operations
|
||||
//============================================================================
|
||||
struct NetVaultNode;
|
||||
struct NetVaultNodeRef;
|
||||
|
||||
// VaultNodeChanged
|
||||
typedef void (*FNetCliAuthVaultNodeChanged)(
|
||||
unsigned nodeId,
|
||||
const Uuid & revisionId
|
||||
);
|
||||
void NetCliAuthVaultSetRecvNodeChangedHandler (
|
||||
FNetCliAuthVaultNodeChanged handler
|
||||
);
|
||||
// VaultNodeAdded
|
||||
typedef void (*FNetCliAuthVaultNodeAdded)(
|
||||
unsigned parentId,
|
||||
unsigned childId,
|
||||
unsigned ownerId
|
||||
);
|
||||
void NetCliAuthVaultSetRecvNodeAddedHandler (
|
||||
FNetCliAuthVaultNodeAdded handler
|
||||
);
|
||||
// VaultNodeRemoved
|
||||
typedef void (*FNetCliAuthVaultNodeRemoved)(
|
||||
unsigned parentId,
|
||||
unsigned childId
|
||||
);
|
||||
void NetCliAuthVaultSetRecvNodeRemovedHandler (
|
||||
FNetCliAuthVaultNodeRemoved handler
|
||||
);
|
||||
// VaultNodeDeleted
|
||||
typedef void (*FNetCliAuthVaultNodeDeleted)(
|
||||
unsigned nodeId
|
||||
);
|
||||
void NetCliAuthVaultSetRecvNodeDeletedHandler (
|
||||
FNetCliAuthVaultNodeDeleted handler
|
||||
);
|
||||
// VaultNodeAdd
|
||||
typedef void (*FNetCliAuthVaultNodeAddCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthVaultNodeAdd (
|
||||
unsigned parentId,
|
||||
unsigned childId,
|
||||
unsigned ownerId,
|
||||
FNetCliAuthVaultNodeAddCallback callback,
|
||||
void * param
|
||||
);
|
||||
// VaultNodeRemove
|
||||
typedef void (*FNetCliAuthVaultNodeRemoveCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthVaultNodeRemove (
|
||||
unsigned parentId,
|
||||
unsigned childId,
|
||||
FNetCliAuthVaultNodeRemoveCallback callback,
|
||||
void * param
|
||||
);
|
||||
// VaultNodeCreate
|
||||
typedef void (*FNetCliAuthVaultNodeCreated)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned nodeId
|
||||
);
|
||||
void NetCliAuthVaultNodeCreate (
|
||||
NetVaultNode * templateNode,
|
||||
FNetCliAuthVaultNodeCreated callback,
|
||||
void * param
|
||||
);
|
||||
// VaultNodeFetch
|
||||
typedef void (*FNetCliAuthVaultNodeFetched)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
NetVaultNode * node
|
||||
);
|
||||
void NetCliAuthVaultNodeFetch (
|
||||
unsigned nodeId,
|
||||
FNetCliAuthVaultNodeFetched callback,
|
||||
void * param
|
||||
);
|
||||
// VaultNodeFind
|
||||
typedef void (*FNetCliAuthVaultNodeFind)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned nodeIdCount,
|
||||
const unsigned nodeIds[]
|
||||
);
|
||||
void NetCliAuthVaultNodeFind (
|
||||
NetVaultNode * templateNode,
|
||||
FNetCliAuthVaultNodeFind callback,
|
||||
void * param
|
||||
);
|
||||
// VaultNodeSave
|
||||
typedef void (*FNetCliAuthVaultNodeSaveCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
unsigned NetCliAuthVaultNodeSave ( // returns number of bytes written
|
||||
NetVaultNode * node,
|
||||
FNetCliAuthVaultNodeSaveCallback callback,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthVaultNodeDelete (
|
||||
unsigned nodeId
|
||||
);
|
||||
// FetchRefs (a vault structure only; no data)
|
||||
typedef void (*FNetCliAuthVaultNodeRefsFetched)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
NetVaultNodeRef * refs,
|
||||
unsigned refCount
|
||||
);
|
||||
void NetCliAuthVaultFetchNodeRefs (
|
||||
unsigned nodeId,
|
||||
FNetCliAuthVaultNodeRefsFetched callback,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthVaultSetSeen (
|
||||
unsigned parentId,
|
||||
unsigned childId,
|
||||
bool seen
|
||||
);
|
||||
|
||||
void NetCliAuthVaultSendNode (
|
||||
unsigned srcNodeId,
|
||||
unsigned dstPlayerId
|
||||
);
|
||||
|
||||
// Initialize an age vault. Will find existing match in db, or create a new age vault structure.
|
||||
typedef void (*FNetCliAuthAgeInitCallback) (
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned ageVaultId,
|
||||
unsigned ageInfoVaultId
|
||||
);
|
||||
void NetCliAuthVaultInitAge (
|
||||
const Uuid & ageInstId, // optional. is used in match
|
||||
const Uuid & parentAgeInstId, // optional. is used in match
|
||||
const wchar ageFilename[], // optional. is used in match
|
||||
const wchar ageInstName[], // optional. not used in match
|
||||
const wchar ageUserName[], // optional. not used in match
|
||||
const wchar ageDesc[], // optional. not used in match
|
||||
unsigned ageSequenceNumber, // optional. not used in match
|
||||
unsigned ageLanguage, // optional. not used in match
|
||||
FNetCliAuthAgeInitCallback callback, // optional
|
||||
void * param // optional
|
||||
);
|
||||
|
||||
void NetCliAuthLogPythonTraceback (const wchar traceback[]);
|
||||
|
||||
void NetCliAuthLogStackDump (const wchar stackdump[]);
|
||||
void NetCliAuthLogClientDebuggerConnect ();
|
||||
|
||||
//============================================================================
|
||||
// SetPlayerBanStatusRequest
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthSetPlayerBanStatusRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthSetPlayerBanStatusRequest (
|
||||
unsigned playerId,
|
||||
unsigned banned,
|
||||
FNetCliAuthSetPlayerBanStatusRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// KickPlayerRequest
|
||||
//============================================================================
|
||||
void NetCliAuthKickPlayer (
|
||||
unsigned playerId
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// ChangePlayerNameRequest
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthChangePlayerNameRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliAuthChangePlayerNameRequest (
|
||||
unsigned playerId,
|
||||
const wchar newName[],
|
||||
FNetCliAuthChangePlayerNameRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// CCRPetition
|
||||
//============================================================================
|
||||
void NetCliAuthSendCCRPetition (
|
||||
const wchar * petitionText
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// SendFriendInvite
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthSendFriendInviteCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
|
||||
void NetCliAuthSendFriendInvite (
|
||||
const wchar emailAddress[],
|
||||
const wchar toName[],
|
||||
const Uuid& inviteUuid,
|
||||
FNetCliAuthSendFriendInviteCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Propagate app-specific data
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthRecvBufferHandler)(
|
||||
unsigned type,
|
||||
unsigned bytes,
|
||||
const byte buffer[]
|
||||
);
|
||||
void NetCliAuthSetRecvBufferHandler (
|
||||
FNetCliAuthRecvBufferHandler handler
|
||||
);
|
||||
void NetCliAuthPropagateBuffer (
|
||||
unsigned type,
|
||||
unsigned bytes,
|
||||
const byte buffer[]
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// New build notifications
|
||||
//============================================================================
|
||||
typedef void (*FNotifyNewBuildHandler)();
|
||||
void NetCliAuthSetNotifyNewBuildHandler (FNotifyNewBuildHandler handler);
|
||||
|
||||
//============================================================================
|
||||
// Score handling
|
||||
//============================================================================
|
||||
struct NetGameScore;
|
||||
|
||||
typedef void (*FNetCliAuthScoreUpdateCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthCreateScoreCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned scoreId,
|
||||
UInt32 createdTime,
|
||||
unsigned ownerId,
|
||||
const char* gameName,
|
||||
unsigned gameType,
|
||||
int value
|
||||
);
|
||||
void NetCliAuthScoreCreate(
|
||||
unsigned ownerId,
|
||||
const char* gameName,
|
||||
unsigned gameType,
|
||||
int value,
|
||||
FNetCliAuthCreateScoreCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
void NetCliAuthScoreDelete(
|
||||
unsigned scoreId,
|
||||
FNetCliAuthScoreUpdateCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
typedef void (*FNetCliAuthGetScoresCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const NetGameScore scores[],
|
||||
unsigned scoreCount
|
||||
);
|
||||
|
||||
void NetCliAuthScoreGetScores(
|
||||
unsigned ownerId,
|
||||
const char* gameName,
|
||||
FNetCliAuthGetScoresCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
void NetCliAuthScoreAddPoints(
|
||||
unsigned scoreId,
|
||||
int numPoints,
|
||||
FNetCliAuthScoreUpdateCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
void NetCliAuthScoreTransferPoints(
|
||||
unsigned srcScoreId,
|
||||
unsigned destScoreId,
|
||||
int numPoints,
|
||||
FNetCliAuthScoreUpdateCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
void NetCliAuthScoreSetPoints(
|
||||
unsigned scoreId,
|
||||
int numPoints,
|
||||
FNetCliAuthScoreUpdateCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
struct NetGameRank;
|
||||
typedef void (*FNetCliAuthGetRanksCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const NetGameRank ranks[],
|
||||
unsigned rankCount
|
||||
);
|
||||
|
||||
void NetCliAuthScoreGetRankList(
|
||||
unsigned ownerId,
|
||||
unsigned scoreGroup,
|
||||
unsigned parentFolderId,
|
||||
const char * gameName,
|
||||
unsigned timePeriod,
|
||||
unsigned numResults,
|
||||
unsigned pageNumber,
|
||||
bool sortDesc,
|
||||
FNetCliAuthGetRanksCallback callback,
|
||||
void * param
|
||||
);
|
203
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.cpp
Normal file
203
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.cpp
Normal file
@ -0,0 +1,203 @@
|
||||
/*==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/plNglCore.cpp
|
||||
*
|
||||
***/
|
||||
|
||||
#include "../Pch.h"
|
||||
#pragma hdrstop
|
||||
|
||||
|
||||
namespace Ngl {
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
struct ReportNetErrorTrans : NetNotifyTrans {
|
||||
ENetProtocol m_errProtocol;
|
||||
ENetError m_errError;
|
||||
|
||||
ReportNetErrorTrans (
|
||||
ENetProtocol errProtocol,
|
||||
ENetError errError
|
||||
);
|
||||
|
||||
void Post ();
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private data
|
||||
*
|
||||
***/
|
||||
|
||||
static FNetClientErrorProc s_errorProc;
|
||||
static long s_initCount;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Local functions
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Transactions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
// NetNotifyTrans
|
||||
//============================================================================
|
||||
NetNotifyTrans::NetNotifyTrans (ETransType transType)
|
||||
: NetTrans(kNetProtocolNil, transType)
|
||||
{
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
// ReportNetErrorTrans
|
||||
//============================================================================
|
||||
ReportNetErrorTrans::ReportNetErrorTrans (
|
||||
ENetProtocol errProtocol,
|
||||
ENetError errError
|
||||
) : NetNotifyTrans(kReportNetErrorTrans)
|
||||
, m_errProtocol(errProtocol)
|
||||
, m_errError(errError)
|
||||
{ }
|
||||
|
||||
//============================================================================
|
||||
void ReportNetErrorTrans::Post () {
|
||||
if (s_errorProc)
|
||||
s_errorProc(m_errProtocol, m_errError);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Module functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
void ReportNetError (ENetProtocol protocol, ENetError error) {
|
||||
ReportNetErrorTrans * trans = NEW(ReportNetErrorTrans)(protocol, error);
|
||||
NetTransSend(trans);
|
||||
}
|
||||
|
||||
} using namespace Ngl;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Exports
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
void NetClientInitialize () {
|
||||
|
||||
if (0 == AtomicAdd(&s_initCount, 1)) {
|
||||
NetTransInitialize();
|
||||
AuthInitialize();
|
||||
GameInitialize();
|
||||
FileInitialize();
|
||||
CsrInitialize();
|
||||
GateKeeperInitialize();
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientCancelAllTrans () {
|
||||
NetTransCancelAll(kNetErrTimeout);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientDestroy (bool wait) {
|
||||
|
||||
if (1 == AtomicAdd(&s_initCount, -1)) {
|
||||
s_errorProc = nil;
|
||||
|
||||
GateKeeperDestroy(false);
|
||||
CsrDestroy(false);
|
||||
FileDestroy(false);
|
||||
GameDestroy(false);
|
||||
AuthDestroy(false);
|
||||
NetTransDestroy(false);
|
||||
if (wait) {
|
||||
GateKeeperDestroy(true);
|
||||
CsrDestroy(true);
|
||||
FileDestroy(true);
|
||||
GameDestroy(true);
|
||||
AuthDestroy(true);
|
||||
NetTransDestroy(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientUpdate () {
|
||||
NetTransUpdate();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientSetTransTimeoutMs (unsigned ms) {
|
||||
NetTransSetTimeoutMs(ms);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientPingEnable (bool enable) {
|
||||
AuthPingEnable(enable);
|
||||
GamePingEnable(enable);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetClientSetErrorHandler (FNetClientErrorProc errorProc) {
|
||||
s_errorProc = errorProc;
|
||||
}
|
74
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.h
Normal file
74
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*==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/plNglCore.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCORE_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCore.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLCORE_H
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Core functions
|
||||
*
|
||||
***/
|
||||
|
||||
void NetClientInitialize ();
|
||||
// void NetClientCancelAllTrans ();
|
||||
void NetClientDestroy (bool wait = true);
|
||||
|
||||
void NetClientUpdate ();
|
||||
|
||||
void NetClientSetTransTimeoutMs (unsigned ms);
|
||||
void NetClientPingEnable (bool enable);
|
||||
|
||||
typedef void (*FNetClientErrorProc)(
|
||||
ENetProtocol protocol,
|
||||
ENetError error
|
||||
);
|
||||
void NetClientSetErrorHandler (FNetClientErrorProc errorProc);
|
908
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp
Normal file
908
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp
Normal file
@ -0,0 +1,908 @@
|
||||
/*==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
|
||||
|
||||
// This file excluded from pre-compiled header because it is auto-generated by the build server.
|
||||
#include "pnNetBase/pnNbCsrKey.hpp"
|
||||
|
||||
|
||||
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;
|
||||
NetAddress 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 unsigned_ptr 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 () {
|
||||
DEL(m_connectParam);
|
||||
}
|
||||
void Post ();
|
||||
};
|
||||
|
||||
struct LoginRequestTrans : NetCsrTrans {
|
||||
|
||||
wchar m_csrName[kMaxAccountNameLength];
|
||||
ShaDigest m_namePassHash;
|
||||
FNetCliCsrLoginCallback m_callback;
|
||||
void * m_param;
|
||||
|
||||
Uuid m_csrId;
|
||||
unsigned m_csrFlags;
|
||||
|
||||
LoginRequestTrans (
|
||||
const wchar csrName[],
|
||||
const ShaDigest & namePassHash,
|
||||
FNetCliCsrLoginCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
bool Send ();
|
||||
void Post ();
|
||||
bool Recv (
|
||||
const byte 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[]) {
|
||||
REF(GetConnIncRef);
|
||||
|
||||
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 unsigned_ptr 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 NetAddress & 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 = BuildType();
|
||||
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 wchar name[],
|
||||
unsigned addrCount,
|
||||
const NetAddress addrs[]
|
||||
) {
|
||||
REF(name);
|
||||
|
||||
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 byte msg[],
|
||||
unsigned bytes,
|
||||
void *
|
||||
) {
|
||||
const Csr2Cli_PingReply & reply = *(const Csr2Cli_PingReply *)msg;
|
||||
|
||||
NetTransRecv(reply.transId, msg, bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool Recv_RegisterReply (
|
||||
const byte 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 byte 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);
|
||||
|
||||
DEL(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 unsigned_ptr msg[] = {
|
||||
kCli2Auth_PingRequest,
|
||||
0, // not a transaction
|
||||
pingSendTimeMs,
|
||||
0, // no payload
|
||||
nil
|
||||
};
|
||||
|
||||
Send(msg, arrsize(msg));
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void CliCsConn::Send (const unsigned_ptr 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 csrName[],
|
||||
const ShaDigest & namePassHash,
|
||||
FNetCliCsrLoginCallback callback,
|
||||
void * param
|
||||
) : NetCsrTrans(kCsrLoginTrans)
|
||||
, m_namePassHash(namePassHash)
|
||||
, m_callback(callback)
|
||||
, m_param(param)
|
||||
{
|
||||
ASSERT(callback);
|
||||
StrCopy(m_csrName, csrName, arrsize(m_csrName));
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool LoginRequestTrans::Send () {
|
||||
|
||||
if (!AcquireConn())
|
||||
return false;
|
||||
|
||||
ShaDigest challengeHash;
|
||||
dword clientChallenge = 0;
|
||||
|
||||
CryptCreateRandomSeed(
|
||||
sizeof(clientChallenge),
|
||||
(byte *) &clientChallenge
|
||||
);
|
||||
|
||||
CryptHashPasswordChallenge(
|
||||
clientChallenge,
|
||||
s_active->serverChallenge,
|
||||
m_namePassHash,
|
||||
&challengeHash
|
||||
);
|
||||
|
||||
const unsigned_ptr msg[] = {
|
||||
kCli2Csr_LoginRequest,
|
||||
m_transId,
|
||||
clientChallenge,
|
||||
(unsigned_ptr) m_csrName,
|
||||
(unsigned_ptr) &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 byte msg[],
|
||||
unsigned bytes
|
||||
) {
|
||||
REF(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),
|
||||
kDhGValue,
|
||||
BigNum(sizeof(kDhXData), kDhXData),
|
||||
BigNum(sizeof(kDhNData), kDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
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 wchar * addrList[],
|
||||
unsigned 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 wchar * 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]) {
|
||||
NetAddress addr;
|
||||
NetAddressFromString(&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 csrName[],
|
||||
const ShaDigest & namePassHash,
|
||||
FNetCliCsrLoginCallback callback,
|
||||
void * param
|
||||
) {
|
||||
LoginRequestTrans * trans = NEW(LoginRequestTrans)(
|
||||
csrName,
|
||||
namePassHash,
|
||||
callback,
|
||||
param
|
||||
);
|
||||
NetTransSend(trans);
|
||||
}
|
94
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h
Normal file
94
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*==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 wchar * addrList[],
|
||||
unsigned 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 csrName[],
|
||||
const ShaDigest & namePassHash,
|
||||
FNetCliCsrLoginCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
typedef void (*FNetCliCsrSetTicketFilterCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliCsrSetTicketFilter (
|
||||
const wchar filterSpec[],
|
||||
FNetCliCsrSetTicketFilterCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
1476
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp
Normal file
1476
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp
Normal file
File diff suppressed because it is too large
Load Diff
137
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h
Normal file
137
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h
Normal file
@ -0,0 +1,137 @@
|
||||
/*==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/plNglFile.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLFILE_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLFILE_H
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Client file functions
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Connect
|
||||
//============================================================================
|
||||
void NetCliFileStartConnect (
|
||||
const wchar * fileAddrList[],
|
||||
unsigned fileAddrCount,
|
||||
bool isPatcher = false
|
||||
);
|
||||
void NetCliFileStartConnectAsServer (
|
||||
const wchar * fileAddrList[],
|
||||
unsigned fileAddrCount,
|
||||
unsigned serverType,
|
||||
unsigned serverBuildId
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Disconnect
|
||||
//============================================================================
|
||||
void NetCliFileDisconnect ();
|
||||
|
||||
//============================================================================
|
||||
// File server related messages
|
||||
//============================================================================
|
||||
typedef void (*FNetCliFileBuildIdRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned buildId
|
||||
);
|
||||
void NetCliFileBuildIdRequest (
|
||||
FNetCliFileBuildIdRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
typedef void (*FNetCliFileBuildIdUpdateCallback)(unsigned buildId);
|
||||
void NetCliFileRegisterBuildIdUpdate (FNetCliFileBuildIdUpdateCallback callback);
|
||||
|
||||
//============================================================================
|
||||
// Manifest
|
||||
//============================================================================
|
||||
struct NetCliFileManifestEntry {
|
||||
wchar clientName[MAX_PATH]; // path and file on client side (for comparison)
|
||||
wchar downloadName[MAX_PATH]; // path and file on server side (for download)
|
||||
wchar md5[MAX_PATH];
|
||||
wchar md5compressed[MAX_PATH]; // md5 for the compressed file
|
||||
unsigned fileSize;
|
||||
unsigned zipSize;
|
||||
unsigned flags;
|
||||
};
|
||||
typedef void (*FNetCliFileManifestRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const wchar group[],
|
||||
const NetCliFileManifestEntry manifest[],
|
||||
unsigned entryCount
|
||||
);
|
||||
void NetCliFileManifestRequest (
|
||||
FNetCliFileManifestRequestCallback callback,
|
||||
void * param,
|
||||
const wchar group[], // the group of files you want (empty or nil = all)
|
||||
unsigned buildId = 0 // 0 = get latest, other = get particular build (servers only)
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// File Download
|
||||
//============================================================================
|
||||
typedef void (*FNetCliFileDownloadRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const wchar filename[],
|
||||
hsStream * writer
|
||||
);
|
||||
void NetCliFileDownloadRequest (
|
||||
const wchar filename[],
|
||||
hsStream * writer,
|
||||
FNetCliFileDownloadRequestCallback callback,
|
||||
void * param,
|
||||
unsigned buildId = 0 // 0 = get latest, other = get particular build (servers only)
|
||||
);
|
829
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
Normal file
829
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
Normal file
@ -0,0 +1,829 @@
|
||||
/*==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/plNglGame.cpp
|
||||
*
|
||||
***/
|
||||
|
||||
#include "../Pch.h"
|
||||
#pragma hdrstop
|
||||
|
||||
// This file excluded from pre-compiled header because it is auto-generated by the build server.
|
||||
#include "pnNetBase/pnNbGameKey.hpp"
|
||||
|
||||
namespace Ngl { namespace Game {
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private
|
||||
*
|
||||
***/
|
||||
|
||||
struct CliGmConn : AtomicRef {
|
||||
LINK(CliGmConn) link;
|
||||
|
||||
CCritSect critsect;
|
||||
AsyncSocket sock;
|
||||
AsyncCancelId cancelId;
|
||||
NetCli * cli;
|
||||
NetAddress addr;
|
||||
unsigned seq;
|
||||
bool abandoned;
|
||||
|
||||
// ping
|
||||
AsyncTimer * pingTimer;
|
||||
unsigned pingSendTimeMs;
|
||||
unsigned lastHeardTimeMs;
|
||||
|
||||
CliGmConn ();
|
||||
~CliGmConn ();
|
||||
|
||||
void Send (const unsigned_ptr fields[], unsigned count);
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
// JoinAgeRequestTrans
|
||||
//============================================================================
|
||||
struct JoinAgeRequestTrans : NetGameTrans {
|
||||
FNetCliGameJoinAgeRequestCallback m_callback;
|
||||
void * m_param;
|
||||
// sent
|
||||
unsigned m_ageMcpId;
|
||||
Uuid m_accountUuid;
|
||||
unsigned m_playerInt;
|
||||
|
||||
JoinAgeRequestTrans (
|
||||
unsigned ageMcpId,
|
||||
const Uuid & accountUuid,
|
||||
unsigned playerInt,
|
||||
FNetCliGameJoinAgeRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
bool Send ();
|
||||
void Post ();
|
||||
bool Recv (
|
||||
const byte msg[],
|
||||
unsigned bytes
|
||||
);
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
// RcvdPropagatedBufferTrans
|
||||
//============================================================================
|
||||
struct RcvdPropagatedBufferTrans : NetNotifyTrans {
|
||||
|
||||
unsigned bufferType;
|
||||
unsigned bufferBytes;
|
||||
byte * bufferData;
|
||||
|
||||
RcvdPropagatedBufferTrans () : NetNotifyTrans(kGmRcvdPropagatedBufferTrans) {}
|
||||
~RcvdPropagatedBufferTrans ();
|
||||
void Post ();
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
// RcvdGameMgrMsgTrans
|
||||
//============================================================================
|
||||
struct RcvdGameMgrMsgTrans : NetNotifyTrans {
|
||||
|
||||
unsigned bufferBytes;
|
||||
byte * bufferData;
|
||||
|
||||
RcvdGameMgrMsgTrans () : NetNotifyTrans(kGmRcvdGameMgrMsgTrans) {}
|
||||
~RcvdGameMgrMsgTrans ();
|
||||
void Post ();
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private data
|
||||
*
|
||||
***/
|
||||
|
||||
enum {
|
||||
kPerfConnCount,
|
||||
kPingDisabled,
|
||||
kNumPerf
|
||||
};
|
||||
|
||||
static bool s_running;
|
||||
static CCritSect s_critsect;
|
||||
static LISTDECL(CliGmConn, link) s_conns;
|
||||
static CliGmConn * s_active;
|
||||
static FNetCliGameRecvBufferHandler s_bufHandler;
|
||||
static FNetCliGameRecvGameMgrMsgHandler s_gameMgrMsgHandler;
|
||||
static long s_perf[kNumPerf];
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Internal functions
|
||||
*
|
||||
***/
|
||||
|
||||
//===========================================================================
|
||||
static unsigned GetNonZeroTimeMs () {
|
||||
if (unsigned ms = TimeGetMs())
|
||||
return ms;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static CliGmConn * GetConnIncRef_CS (const char tag[]) {
|
||||
if (CliGmConn * conn = s_active)
|
||||
if (conn->cli) {
|
||||
conn->IncRef(tag);
|
||||
return conn;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static CliGmConn * GetConnIncRef (const char tag[]) {
|
||||
CliGmConn * conn;
|
||||
s_critsect.Enter();
|
||||
{
|
||||
conn = GetConnIncRef_CS(tag);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
return conn;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void UnlinkAndAbandonConn_CS (CliGmConn * 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 bool ConnEncrypt (ENetError error, void * param) {
|
||||
CliGmConn * conn = (CliGmConn *) param;
|
||||
|
||||
if (IS_NET_SUCCESS(error)) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
SWAP(s_active, conn);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
return IS_NET_SUCCESS(error);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void NotifyConnSocketConnect (CliGmConn * conn) {
|
||||
|
||||
conn->TransferRef("Connecting", "Connected");
|
||||
conn->cli = NetCliConnectAccept(
|
||||
conn->sock,
|
||||
kNetProtocolCli2Game,
|
||||
true,
|
||||
ConnEncrypt,
|
||||
0,
|
||||
nil,
|
||||
conn
|
||||
);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void NotifyConnSocketConnectFailed (CliGmConn * 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(kNetProtocolCli2Game, kNetErrConnectFailed);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void NotifyConnSocketDisconnect (CliGmConn * conn) {
|
||||
|
||||
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(kNetProtocolCli2Game, kNetErrDisconnected);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool NotifyConnSocketRead (CliGmConn * conn, AsyncNotifySocketRead * read) {
|
||||
// TODO: Only dispatch messages from the active game server
|
||||
conn->lastHeardTimeMs = GetNonZeroTimeMs();
|
||||
bool result = NetCliDispatch(conn->cli, read->buffer, read->bytes, nil);
|
||||
read->bytesProcessed += read->bytes;
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool SocketNotifyCallback (
|
||||
AsyncSocket sock,
|
||||
EAsyncNotifySocket code,
|
||||
AsyncNotifySocket * notify,
|
||||
void ** userState
|
||||
) {
|
||||
bool result = true;
|
||||
CliGmConn * conn;
|
||||
|
||||
switch (code) {
|
||||
case kNotifySocketConnectSuccess:
|
||||
conn = (CliGmConn *) notify->param;
|
||||
*userState = conn;
|
||||
conn->TransferRef("Connecting", "Connected");
|
||||
bool abandoned;
|
||||
s_critsect.Enter();
|
||||
{
|
||||
conn->sock = sock;
|
||||
conn->cancelId = 0;
|
||||
abandoned = conn->abandoned;
|
||||
}
|
||||
s_critsect.Leave();
|
||||
if (abandoned)
|
||||
AsyncSocketDisconnect(sock, true);
|
||||
else
|
||||
NotifyConnSocketConnect(conn);
|
||||
break;
|
||||
|
||||
case kNotifySocketConnectFailed:
|
||||
conn = (CliGmConn *) notify->param;
|
||||
NotifyConnSocketConnectFailed(conn);
|
||||
break;
|
||||
|
||||
case kNotifySocketDisconnect:
|
||||
conn = (CliGmConn *) *userState;
|
||||
NotifyConnSocketDisconnect(conn);
|
||||
break;
|
||||
|
||||
case kNotifySocketRead:
|
||||
conn = (CliGmConn *) *userState;
|
||||
result = NotifyConnSocketRead(conn, (AsyncNotifySocketRead *) notify);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void Connect (
|
||||
const NetAddress & addr
|
||||
) {
|
||||
CliGmConn * conn = NEWZERO(CliGmConn);
|
||||
conn->addr = addr;
|
||||
conn->seq = ConnNextSequence();
|
||||
conn->lastHeardTimeMs = GetNonZeroTimeMs();
|
||||
|
||||
conn->IncRef("Lifetime");
|
||||
conn->IncRef("Connecting");
|
||||
|
||||
s_critsect.Enter();
|
||||
{
|
||||
while (CliGmConn * conn = s_conns.Head())
|
||||
UnlinkAndAbandonConn_CS(conn);
|
||||
s_conns.Link(conn);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
|
||||
Cli2Game_Connect connect;
|
||||
connect.hdr.connType = kConnTypeCliToGame;
|
||||
connect.hdr.hdrBytes = sizeof(connect.hdr);
|
||||
connect.hdr.buildId = BuildId();
|
||||
connect.hdr.buildType = BuildType();
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* CliGmConn
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
CliGmConn::CliGmConn () {
|
||||
AtomicAdd(&s_perf[kPerfConnCount], 1);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
CliGmConn::~CliGmConn () {
|
||||
if (cli)
|
||||
NetCliDelete(cli, true);
|
||||
AtomicAdd(&s_perf[kPerfConnCount], -1);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void CliGmConn::Send (const unsigned_ptr fields[], unsigned count) {
|
||||
critsect.Enter();
|
||||
{
|
||||
NetCliSend(cli, fields, count);
|
||||
NetCliFlush(cli);
|
||||
}
|
||||
critsect.Leave();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Cli2Game protocol
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
static bool Recv_PingReply (
|
||||
const byte msg[],
|
||||
unsigned bytes,
|
||||
void * param
|
||||
) {
|
||||
REF(msg);
|
||||
REF(bytes);
|
||||
REF(param);
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool Recv_JoinAgeReply (
|
||||
const byte msg[],
|
||||
unsigned bytes,
|
||||
void * param
|
||||
) {
|
||||
REF(bytes);
|
||||
REF(param);
|
||||
|
||||
const Game2Cli_JoinAgeReply & reply = *(const Game2Cli_JoinAgeReply *)msg;
|
||||
if (sizeof(reply) != bytes)
|
||||
return false;
|
||||
|
||||
NetTransRecv(reply.transId, msg, bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool Recv_PropagateBuffer (
|
||||
const byte msg[],
|
||||
unsigned bytes,
|
||||
void * param
|
||||
) {
|
||||
REF(bytes);
|
||||
REF(param);
|
||||
|
||||
const Game2Cli_PropagateBuffer & reply = *(const Game2Cli_PropagateBuffer *)msg;
|
||||
|
||||
RcvdPropagatedBufferTrans * trans = NEW(RcvdPropagatedBufferTrans);
|
||||
trans->bufferType = reply.type;
|
||||
trans->bufferBytes = reply.bytes;
|
||||
trans->bufferData = (byte *)ALLOC(reply.bytes);
|
||||
MemCopy(trans->bufferData, reply.buffer, reply.bytes);
|
||||
NetTransSend(trans);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static bool Recv_GameMgrMsg (
|
||||
const byte msg[],
|
||||
unsigned bytes,
|
||||
void * param
|
||||
) {
|
||||
REF(bytes);
|
||||
REF(param);
|
||||
|
||||
const Game2Cli_GameMgrMsg & reply = *(const Game2Cli_GameMgrMsg *)msg;
|
||||
|
||||
RcvdGameMgrMsgTrans * trans = NEW(RcvdGameMgrMsgTrans);
|
||||
trans->bufferBytes = reply.bytes;
|
||||
trans->bufferData = (byte *)ALLOC(reply.bytes);
|
||||
MemCopy(trans->bufferData, reply.buffer, reply.bytes);
|
||||
NetTransSend(trans);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Send/Recv protocol handler init
|
||||
//============================================================================
|
||||
#define MSG(s) kNetMsg_Cli2Game_##s
|
||||
static NetMsgInitSend s_send[] = {
|
||||
{ MSG(PingRequest), },
|
||||
{ MSG(JoinAgeRequest), },
|
||||
{ MSG(PropagateBuffer), },
|
||||
{ MSG(GameMgrMsg), },
|
||||
};
|
||||
#undef MSG
|
||||
|
||||
#define MSG(s) kNetMsg_Game2Cli_##s, Recv_##s
|
||||
static NetMsgInitRecv s_recv[] = {
|
||||
{ MSG(PingReply) },
|
||||
{ MSG(JoinAgeReply), },
|
||||
{ MSG(PropagateBuffer), },
|
||||
{ MSG(GameMgrMsg), },
|
||||
};
|
||||
#undef MSG
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* JoinAgeRequestTrans
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
JoinAgeRequestTrans::JoinAgeRequestTrans (
|
||||
unsigned ageMcpId,
|
||||
const Uuid & accountUuid,
|
||||
unsigned playerInt,
|
||||
FNetCliGameJoinAgeRequestCallback callback,
|
||||
void * param
|
||||
) : NetGameTrans(kJoinAgeRequestTrans)
|
||||
, m_ageMcpId(ageMcpId)
|
||||
, m_accountUuid(accountUuid)
|
||||
, m_playerInt(playerInt)
|
||||
, m_callback(callback)
|
||||
, m_param(param)
|
||||
{
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool JoinAgeRequestTrans::Send () {
|
||||
if (!AcquireConn())
|
||||
return false;
|
||||
|
||||
const unsigned_ptr msg[] = {
|
||||
kCli2Game_JoinAgeRequest,
|
||||
m_transId,
|
||||
m_ageMcpId,
|
||||
(unsigned_ptr) &m_accountUuid,
|
||||
m_playerInt,
|
||||
};
|
||||
|
||||
m_conn->Send(msg, arrsize(msg));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void JoinAgeRequestTrans::Post () {
|
||||
m_callback(
|
||||
m_result,
|
||||
m_param
|
||||
);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool JoinAgeRequestTrans::Recv (
|
||||
const byte msg[],
|
||||
unsigned bytes
|
||||
) {
|
||||
REF(bytes);
|
||||
|
||||
const Game2Cli_JoinAgeReply & reply = *(const Game2Cli_JoinAgeReply *) msg;
|
||||
m_result = reply.result;
|
||||
m_state = kTransStateComplete;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* RcvdPropagatedBufferTrans
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
RcvdPropagatedBufferTrans::~RcvdPropagatedBufferTrans () {
|
||||
FREE(bufferData);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void RcvdPropagatedBufferTrans::Post () {
|
||||
if (s_bufHandler)
|
||||
s_bufHandler(bufferType, bufferBytes, bufferData);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* RcvdGameMgrMsgTrans
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
RcvdGameMgrMsgTrans::~RcvdGameMgrMsgTrans () {
|
||||
FREE(bufferData);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void RcvdGameMgrMsgTrans::Post () {
|
||||
if (s_gameMgrMsgHandler)
|
||||
s_gameMgrMsgHandler((GameMsgHeader *)bufferData);
|
||||
}
|
||||
|
||||
|
||||
} using namespace Game;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* NetGameTrans
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
NetGameTrans::NetGameTrans (ETransType transType)
|
||||
: NetTrans(kNetProtocolCli2Game, transType)
|
||||
, m_conn(nil)
|
||||
{
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
NetGameTrans::~NetGameTrans () {
|
||||
ReleaseConn();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool NetGameTrans::AcquireConn () {
|
||||
if (!m_conn)
|
||||
m_conn = GetConnIncRef("AcquireConn");
|
||||
return m_conn != nil;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetGameTrans::ReleaseConn () {
|
||||
if (m_conn) {
|
||||
m_conn->DecRef("AcquireConn");
|
||||
m_conn = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Protected functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
void GameInitialize () {
|
||||
s_running = true;
|
||||
NetMsgProtocolRegister(
|
||||
kNetProtocolCli2Game,
|
||||
false,
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kDhGValue,
|
||||
BigNum(sizeof(kDhXData), kDhXData),
|
||||
BigNum(sizeof(kDhNData), kDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void GameDestroy (bool wait) {
|
||||
s_running = false;
|
||||
s_bufHandler = nil;
|
||||
s_gameMgrMsgHandler = nil;
|
||||
|
||||
NetTransCancelByProtocol(
|
||||
kNetProtocolCli2Game,
|
||||
kNetErrRemoteShutdown
|
||||
);
|
||||
NetMsgProtocolDestroy(
|
||||
kNetProtocolCli2Game,
|
||||
false
|
||||
);
|
||||
|
||||
s_critsect.Enter();
|
||||
{
|
||||
while (CliGmConn * conn = s_conns.Head())
|
||||
UnlinkAndAbandonConn_CS(conn);
|
||||
s_active = nil;
|
||||
}
|
||||
s_critsect.Leave();
|
||||
|
||||
if (!wait)
|
||||
return;
|
||||
|
||||
while (s_perf[kPerfConnCount]) {
|
||||
NetTransUpdate();
|
||||
AsyncSleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool GameQueryConnected () {
|
||||
bool result;
|
||||
s_critsect.Enter();
|
||||
{
|
||||
if (nil != (result = s_active))
|
||||
result &= (nil != s_active->cli);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
unsigned GameGetConnId () {
|
||||
unsigned connId;
|
||||
s_critsect.Enter();
|
||||
connId = (s_active) ? s_active->seq : 0;
|
||||
s_critsect.Leave();
|
||||
return connId;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void GamePingEnable (bool enable) {
|
||||
s_perf[kPingDisabled] = !enable;
|
||||
}
|
||||
|
||||
} using namespace Ngl;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Exported functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameStartConnect (
|
||||
const NetAddressNode & node
|
||||
) {
|
||||
NetAddress addr;
|
||||
NetAddressFromNode(node, NetCliAuthGetCurrentConnPort(), &addr);
|
||||
Connect(addr);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameDisconnect () {
|
||||
|
||||
s_critsect.Enter();
|
||||
{
|
||||
while (CliGmConn * conn = s_conns.Head())
|
||||
UnlinkAndAbandonConn_CS(conn);
|
||||
s_active = nil;
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameJoinAgeRequest (
|
||||
unsigned ageMcpId,
|
||||
const Uuid & accountUuid,
|
||||
unsigned playerInt,
|
||||
FNetCliGameJoinAgeRequestCallback callback,
|
||||
void * param
|
||||
) {
|
||||
JoinAgeRequestTrans * trans = NEWZERO(JoinAgeRequestTrans)(
|
||||
ageMcpId,
|
||||
accountUuid,
|
||||
playerInt,
|
||||
callback,
|
||||
param
|
||||
);
|
||||
NetTransSend(trans);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameSetRecvBufferHandler (
|
||||
FNetCliGameRecvBufferHandler handler
|
||||
) {
|
||||
s_bufHandler = handler;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGamePropagateBuffer (
|
||||
unsigned type,
|
||||
unsigned bytes,
|
||||
const byte buffer[]
|
||||
) {
|
||||
CliGmConn * conn = GetConnIncRef("PropBuffer");
|
||||
if (!conn)
|
||||
return;
|
||||
|
||||
const unsigned_ptr msg[] = {
|
||||
kCli2Game_PropagateBuffer,
|
||||
type,
|
||||
bytes,
|
||||
(unsigned_ptr) buffer,
|
||||
};
|
||||
|
||||
conn->Send(msg, arrsize(msg));
|
||||
|
||||
conn->DecRef("PropBuffer");
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameSetRecvGameMgrMsgHandler (FNetCliGameRecvGameMgrMsgHandler handler) {
|
||||
s_gameMgrMsgHandler = handler;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetCliGameSendGameMgrMsg (GameMsgHeader * msgHdr) {
|
||||
CliGmConn * conn = GetConnIncRef("GameMgrMsg");
|
||||
if (!conn)
|
||||
return;
|
||||
|
||||
const unsigned_ptr msg[] = {
|
||||
kCli2Game_GameMgrMsg,
|
||||
msgHdr->messageBytes,
|
||||
(unsigned_ptr) msgHdr,
|
||||
};
|
||||
|
||||
conn->Send(msg, arrsize(msg));
|
||||
|
||||
conn->DecRef("GameMgrMsg");
|
||||
}
|
110
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h
Normal file
110
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*==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/plNglGame.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLGAME_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLGAME_H
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Client-side Game functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
// Connect
|
||||
//============================================================================
|
||||
void NetCliGameStartConnect (
|
||||
const NetAddressNode & node
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Disconnect
|
||||
//============================================================================
|
||||
void NetCliGameDisconnect ();
|
||||
|
||||
//============================================================================
|
||||
// Join Age
|
||||
//============================================================================
|
||||
typedef void (*FNetCliGameJoinAgeRequestCallback)(
|
||||
ENetError result,
|
||||
void * param
|
||||
);
|
||||
void NetCliGameJoinAgeRequest (
|
||||
unsigned ageMcpId,
|
||||
const Uuid & accountUuid,
|
||||
unsigned playerInt,
|
||||
FNetCliGameJoinAgeRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// Propagate app-specific data
|
||||
//============================================================================
|
||||
typedef void (*FNetCliGameRecvBufferHandler)(
|
||||
unsigned type,
|
||||
unsigned bytes,
|
||||
const byte buffer[]
|
||||
);
|
||||
void NetCliGameSetRecvBufferHandler (
|
||||
FNetCliGameRecvBufferHandler handler
|
||||
);
|
||||
void NetCliGamePropagateBuffer (
|
||||
unsigned type,
|
||||
unsigned bytes,
|
||||
const byte buffer[]
|
||||
);
|
||||
|
||||
//============================================================================
|
||||
// GameMgrMsg
|
||||
//============================================================================
|
||||
struct GameMsgHeader;
|
||||
typedef void (*FNetCliGameRecvGameMgrMsgHandler)(GameMsgHeader * msg);
|
||||
void NetCliGameSetRecvGameMgrMsgHandler (FNetCliGameRecvGameMgrMsgHandler handler);
|
||||
void NetCliGameSendGameMgrMsg (GameMsgHeader * msg);
|
1145
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp
Normal file
1145
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp
Normal file
File diff suppressed because it is too large
Load Diff
137
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h
Normal file
137
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h
Normal file
@ -0,0 +1,137 @@
|
||||
/*==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/plNglGateKeeper.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifdef PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLGATEKEEPER_H
|
||||
#error "Header $/Plasma20/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h included more than once"
|
||||
#endif
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLGATEKEEPER_H
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Client gatekeeper functions
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Connect
|
||||
//============================================================================
|
||||
void NetCliGateKeeperStartConnect (
|
||||
const wchar * gateKeeperAddrList[],
|
||||
unsigned gateKeeperAddrCount
|
||||
);
|
||||
|
||||
bool NetCliGateKeeperQueryConnected ();
|
||||
void NetCliGateKeeperAutoReconnectEnable (bool enable); // is enabled by default
|
||||
|
||||
// Called after the gatekeeper/client connection is encrypted
|
||||
typedef void (*FNetCliGateKeeperConnectCallback)();
|
||||
void NetCliGateKeeperSetConnectCallback (
|
||||
FNetCliGateKeeperConnectCallback callback
|
||||
);
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Disconnect
|
||||
//============================================================================
|
||||
void NetCliGateKeeperDisconnect ();
|
||||
void NetCliGateKeeperUnexpectedDisconnect ();
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Ping
|
||||
//============================================================================
|
||||
typedef void (*FNetCliGateKeeperPingRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
unsigned pingAtMs,
|
||||
unsigned replyAtMs,
|
||||
unsigned payloadbytes,
|
||||
const byte payload[]
|
||||
);
|
||||
void NetCliGateKeeperPingRequest (
|
||||
unsigned pingTimeMs,
|
||||
unsigned payloadBytes, // max 64k (pnNetCli enforced upon send)
|
||||
const void * payload,
|
||||
FNetCliGateKeeperPingRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
|
||||
//============================================================================
|
||||
// FileSrvIpAddress
|
||||
//============================================================================
|
||||
typedef void (*FNetCliGateKeeperFileSrvIpAddressRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const wchar addr[]
|
||||
);
|
||||
|
||||
void NetCliGateKeeperFileSrvIpAddressRequest (
|
||||
FNetCliGateKeeperFileSrvIpAddressRequestCallback callback,
|
||||
void * param,
|
||||
bool isPatcher
|
||||
);
|
||||
|
||||
|
||||
//============================================================================
|
||||
// AuthSrvIpAddress
|
||||
//============================================================================
|
||||
typedef void (*FNetCliGateKeeperAuthSrvIpAddressRequestCallback)(
|
||||
ENetError result,
|
||||
void * param,
|
||||
const wchar addr[]
|
||||
);
|
||||
|
||||
void NetCliGateKeeperAuthSrvIpAddressRequest (
|
||||
FNetCliGateKeeperAuthSrvIpAddressRequestCallback callback,
|
||||
void * param
|
||||
);
|
||||
|
||||
|
||||
|
89
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglMisc.cpp
Normal file
89
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglMisc.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*==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/plNglMisc.cpp
|
||||
*
|
||||
***/
|
||||
|
||||
#include "../Pch.h"
|
||||
#pragma hdrstop
|
||||
|
||||
|
||||
namespace Ngl {
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private data
|
||||
*
|
||||
***/
|
||||
|
||||
static unsigned s_connSequence;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Module functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
unsigned ConnNextSequence () {
|
||||
if (!++s_connSequence)
|
||||
++s_connSequence;
|
||||
return s_connSequence;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
unsigned ConnGetId (ENetProtocol protocol) {
|
||||
switch (protocol) {
|
||||
case kNetProtocolCli2Auth: return AuthGetConnId();
|
||||
case kNetProtocolCli2Game: return GameGetConnId();
|
||||
case kNetProtocolCli2File: return FileGetConnId();
|
||||
case kNetProtocolCli2Csr: return CsrGetConnId();
|
||||
case kNetProtocolCli2GateKeeper: return GateKeeperGetConnId();
|
||||
DEFAULT_FATAL(protocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ngl
|
359
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp
Normal file
359
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp
Normal file
@ -0,0 +1,359 @@
|
||||
/*==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/plNglTrans.cpp
|
||||
*
|
||||
***/
|
||||
|
||||
#include "../Pch.h"
|
||||
#pragma hdrstop
|
||||
|
||||
|
||||
namespace Ngl {
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Private
|
||||
*
|
||||
***/
|
||||
|
||||
enum {
|
||||
kPerfCurrTransactions,
|
||||
kNumPerf
|
||||
};
|
||||
|
||||
static const unsigned kDefaultTimeoutMs = 5 * 60 * 1000;
|
||||
|
||||
static bool s_running;
|
||||
static CCritSect s_critsect;
|
||||
static LISTDECL(NetTrans, m_link) s_transactions;
|
||||
static long s_perf[kNumPerf];
|
||||
static unsigned s_timeoutMs = kDefaultTimeoutMs;
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Internal functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
static NetTrans * FindTransIncRef_CS (unsigned transId, const char tag[]) {
|
||||
// There shouldn't be more than a few transactions; just do a linear scan
|
||||
for (NetTrans * trans = s_transactions.Head(); trans; trans = s_transactions.Next(trans))
|
||||
if (trans->m_transId == transId) {
|
||||
trans->IncRef(tag);
|
||||
return trans;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static NetTrans * FindTransIncRef (unsigned transId, const char tag[]) {
|
||||
NetTrans * trans;
|
||||
s_critsect.Enter();
|
||||
{
|
||||
trans = FindTransIncRef_CS(transId, tag);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
return trans;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
static void CancelTrans_CS (NetTrans * trans, ENetError error) {
|
||||
ASSERT(IS_NET_ERROR(error));
|
||||
if (trans->m_state != kTransStateComplete) {
|
||||
trans->m_result = error;
|
||||
trans->m_state = kTransStateComplete;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* NetTrans implementation
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
NetTrans::NetTrans (ENetProtocol protocol, ETransType transType)
|
||||
: m_state(kTransStateWaitServerConnect)
|
||||
, m_result(kNetPending)
|
||||
, m_transId(0)
|
||||
, m_connId(0)
|
||||
, m_protocol(protocol)
|
||||
, m_hasSubTrans(false)
|
||||
, m_transType(transType)
|
||||
{
|
||||
AtomicAdd(&s_perf[kPerfCurrTransactions], 1);
|
||||
AtomicAdd(&s_perfTransCount[m_transType], 1);
|
||||
// DebugMsg("%s@%p created", s_transTypes[m_transType], this);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
NetTrans::~NetTrans () {
|
||||
ASSERT(!m_link.IsLinked());
|
||||
AtomicAdd(&s_perfTransCount[m_transType], -1);
|
||||
AtomicAdd(&s_perf[kPerfCurrTransactions], -1);
|
||||
// DebugMsg("%s@%p destroyed", s_transTypes[m_transType], this);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool NetTrans::CanStart () const {
|
||||
switch (m_protocol) {
|
||||
case kNetProtocolCli2Auth: return AuthQueryConnected();
|
||||
case kNetProtocolCli2Game: return GameQueryConnected();
|
||||
case kNetProtocolCli2File: return FileQueryConnected();
|
||||
case kNetProtocolCli2Csr: return CsrQueryConnected();
|
||||
case kNetProtocolCli2GateKeeper: return GateKeeperQueryConnected();
|
||||
DEFAULT_FATAL(m_protocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Module functions
|
||||
*
|
||||
***/
|
||||
|
||||
//============================================================================
|
||||
void NetTransInitialize () {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
s_running = true;
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransDestroy (bool wait) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
s_running = false;
|
||||
}
|
||||
s_critsect.Leave();
|
||||
|
||||
NetTransCancelAll(kNetErrRemoteShutdown);
|
||||
|
||||
if (!wait)
|
||||
return;
|
||||
|
||||
while (s_perf[kPerfCurrTransactions]) {
|
||||
NetTransUpdate();
|
||||
AsyncSleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransSetTimeoutMs (unsigned ms) {
|
||||
s_timeoutMs = ms ? ms : kDefaultTimeoutMs;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
unsigned NetTransGetTimeoutMs () {
|
||||
return s_timeoutMs;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransSend (NetTrans * trans) {
|
||||
trans->IncRef("Lifetime");
|
||||
s_critsect.Enter();
|
||||
{
|
||||
static unsigned s_transId;
|
||||
while (!trans->m_transId)
|
||||
trans->m_transId = ++s_transId;
|
||||
s_transactions.Link(trans, kListTail);
|
||||
if (!s_running)
|
||||
CancelTrans_CS(trans, kNetErrRemoteShutdown);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool NetTransRecv (unsigned transId, const byte msg[], unsigned bytes) {
|
||||
NetTrans * trans = FindTransIncRef(transId, "Recv");
|
||||
|
||||
if (!trans)
|
||||
return true; // transaction was canceled.
|
||||
|
||||
// Update the timeout time
|
||||
trans->m_timeoutAtMs = TimeGetMs() + s_timeoutMs;
|
||||
|
||||
bool result = trans->Recv(msg, bytes);
|
||||
|
||||
if (!result)
|
||||
NetTransCancel(transId, kNetErrInternalError);
|
||||
|
||||
trans->DecRef("Recv");
|
||||
return result;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransCancel (unsigned transId, ENetError error) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
NetTrans * trans = s_transactions.Head();
|
||||
for (; trans; trans = trans->m_link.Next()) {
|
||||
if (trans->m_transId == transId) {
|
||||
CancelTrans_CS(trans, error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransCancelByProtocol (ENetProtocol protocol, ENetError error) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
NetTrans * trans = s_transactions.Head();
|
||||
for (; trans; trans = trans->m_link.Next()) {
|
||||
if (trans->m_protocol == protocol)
|
||||
CancelTrans_CS(trans, error);
|
||||
}
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransCancelByConnId (unsigned connId, ENetError error) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
NetTrans * trans = s_transactions.Head();
|
||||
for (; trans; trans = trans->m_link.Next()) {
|
||||
if (trans->m_connId == connId)
|
||||
CancelTrans_CS(trans, error);
|
||||
}
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransCancelAll (ENetError error) {
|
||||
s_critsect.Enter();
|
||||
{
|
||||
NetTrans * trans = s_transactions.Head();
|
||||
for (; trans; trans = trans->m_link.Next())
|
||||
CancelTrans_CS(trans, error);
|
||||
}
|
||||
s_critsect.Leave();
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void NetTransUpdate () {
|
||||
LISTDECL(NetTrans, m_link) completed;
|
||||
LISTDECL(NetTrans, m_link) parentCompleted;
|
||||
|
||||
s_critsect.Enter();
|
||||
NetTrans * next, * trans = s_transactions.Head();
|
||||
for (; trans; trans = next) {
|
||||
next = s_transactions.Next(trans);
|
||||
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
switch (trans->m_state) {
|
||||
case kTransStateComplete:
|
||||
if (trans->m_hasSubTrans)
|
||||
parentCompleted.Link(trans);
|
||||
else
|
||||
completed.Link(trans);
|
||||
done = true;
|
||||
break;
|
||||
|
||||
case kTransStateWaitServerConnect:
|
||||
if (!trans->CanStart()) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
if (trans->m_protocol && 0 == (trans->m_connId = ConnGetId(trans->m_protocol))) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
// This is the default "next state", trans->Send() can override this
|
||||
trans->m_state = kTransStateWaitServerResponse;
|
||||
// Set timeout time before calling Send(), allowing Send() to change it if it wants to.
|
||||
trans->m_timeoutAtMs = TimeGetMs() + s_timeoutMs;
|
||||
if (!trans->Send()) {
|
||||
// Revert back to current state so that we'll attempt to send again
|
||||
trans->m_state = kTransStateWaitServerConnect;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case kTransStateWaitServerResponse:
|
||||
// Check for timeout
|
||||
if ((int)(TimeGetMs() - trans->m_timeoutAtMs) > 0) {
|
||||
// Check to see if the transaction wants to "abort" the timeout
|
||||
if (trans->TimedOut())
|
||||
CancelTrans_CS(trans, kNetErrTimeout);
|
||||
else
|
||||
trans->m_timeoutAtMs = TimeGetMs() + s_timeoutMs; // Reset the timeout counter
|
||||
}
|
||||
done = true;
|
||||
break;
|
||||
|
||||
DEFAULT_FATAL(trans->m_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_critsect.Leave();
|
||||
|
||||
// Post completed transactions
|
||||
while (NetTrans * trans = completed.Head()) {
|
||||
completed.Unlink(trans);
|
||||
trans->Post();
|
||||
trans->DecRef("Lifetime");
|
||||
}
|
||||
// Post completed parent transactions
|
||||
while (NetTrans * trans = parentCompleted.Head()) {
|
||||
parentCompleted.Unlink(trans);
|
||||
trans->Post();
|
||||
trans->DecRef("Lifetime");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Ngl
|
Reference in New Issue
Block a user