Browse Source

Player Creation to plString

Adam Johnson 10 years ago
parent
commit
3d9f822412
  1. 6
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp
  2. 35
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  3. 13
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h
  4. 96
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  5. 6
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

6
Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.cpp

@ -112,7 +112,11 @@ void cyAccountManagement::CreatePlayer(const char* playerName, const char* avata
void cyAccountManagement::CreatePlayerW(const wchar_t* playerName, const wchar_t* avatar, const wchar_t* invitationCode) void cyAccountManagement::CreatePlayerW(const wchar_t* playerName, const wchar_t* avatar, const wchar_t* invitationCode)
{ {
NetCommCreatePlayer(playerName, avatar, invitationCode, 0, nil); NetCommCreatePlayer(plString::FromWchar(playerName),
plString::FromWchar(avatar),
plString::FromWchar(invitationCode),
0,
nullptr);
} }
void cyAccountManagement::DeletePlayer(unsigned playerId) void cyAccountManagement::DeletePlayer(unsigned playerId)

35
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -444,7 +444,7 @@ static void INetCliAuthCreatePlayerRequestCallback (
LogMsg(kLogDebug, L"Create player failed: %s", NetErrorToString(result)); LogMsg(kLogDebug, L"Create player failed: %s", NetErrorToString(result));
} }
else { else {
LogMsg(kLogDebug, L"Created player %s: %u", playerInfo.playerName, playerInfo.playerInt); LogMsg(kLogDebug, L"Created player %S: %u", playerInfo.playerName.c_str(), playerInfo.playerInt);
unsigned currPlayer = s_player ? s_player->playerInt : 0; unsigned currPlayer = s_player ? s_player->playerInt : 0;
NetCommPlayer * newPlayer = s_players.New(); NetCommPlayer * newPlayer = s_players.New();
@ -1136,41 +1136,16 @@ void NetCommSetActivePlayer (//--> plNetCommActivePlayerMsg
//============================================================================ //============================================================================
void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg
const char playerName[], const plString& playerName,
const char avatarShape[], const plString& avatarShape,
const char friendInvite[], const plString& friendInvite,
unsigned createFlags,
void * param
) {
wchar_t wplayerName[kMaxPlayerNameLength];
wchar_t wavatarShape[MAX_PATH];
wchar_t wfriendInvite[MAX_PATH];
StrToUnicode(wplayerName, playerName, arrsize(wplayerName));
StrToUnicode(wavatarShape, avatarShape, arrsize(wavatarShape));
StrToUnicode(wfriendInvite, friendInvite, arrsize(wfriendInvite));
NetCliAuthPlayerCreateRequest(
wplayerName,
wavatarShape,
(friendInvite != NULL) ? wfriendInvite : NULL,
INetCliAuthCreatePlayerRequestCallback,
param
);
}
//============================================================================
void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg
const wchar_t playerName[],
const wchar_t avatarShape[],
const wchar_t friendInvite[],
unsigned createFlags, unsigned createFlags,
void * param void * param
) { ) {
NetCliAuthPlayerCreateRequest( NetCliAuthPlayerCreateRequest(
playerName, playerName,
avatarShape, avatarShape,
(friendInvite != NULL) ? friendInvite : NULL, friendInvite,
INetCliAuthCreatePlayerRequestCallback, INetCliAuthCreatePlayerRequestCallback,
param param
); );

13
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h

@ -208,16 +208,9 @@ void NetCommSetActivePlayer (//--> plNetCommActivePlayerMsg
void * param void * param
); );
void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg
const char playerName[], const plString& playerName,
const char avatarShape[], const plString& avatarShape,
const char friendInvite[], const plString& friendInvite,
unsigned createFlags,
void * param
);
void NetCommCreatePlayer ( // --> plNetCommCreatePlayerMsg
const wchar_t playerName[],
const wchar_t avatarShape[],
const wchar_t friendInvite[],
unsigned createFlags, unsigned createFlags,
void * param void * param
); );

96
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -291,18 +291,18 @@ struct PlayerCreateRequestTrans : NetAuthTrans {
void * m_param; void * m_param;
// send // send
wchar_t m_playerName[kMaxPlayerNameLength]; plString m_playerName;
wchar_t m_avatarShape[MAX_PATH]; plString m_avatarShape;
wchar_t m_friendInvite[MAX_PATH]; plString m_friendInvite;
// recv // recv
NetCliAuthPlayerInfo m_playerInfo; NetCliAuthPlayerInfo m_playerInfo;
PlayerCreateRequestTrans ( PlayerCreateRequestTrans (
const wchar_t playerName[], const plString& playerName,
const wchar_t avatarShape[], const plString& avatarShape,
const wchar_t friendInvite[], const plString& friendInvite,
FNetCliAuthPlayerCreateRequestCallback callback, FNetCliAuthPlayerCreateRequestCallback callback,
void * param void * param
); );
@ -1231,42 +1231,28 @@ static FNotifyNewBuildHandler s_notifyNewBuildHandler;
***/ ***/
//=========================================================================== //===========================================================================
static inline bool ICharIsSpace (unsigned ch) { static ENetError FixupPlayerName (plString& name) {
return ch == ' '; ASSERT(!name.IsEmpty());
}
//=========================================================================== // Trim leading and trailing whitespace
static ENetError FixupPlayerName (wchar_t * name) { name = name.Trim(" \t\n\r");
ASSERT(name);
// Trim leading and trailing whitespace and convert
// multiple internal spaces into only one space
unsigned nonSpaceChars = 0;
wchar_t *dst = name;
for (wchar_t *src = name; *src; ) {
// Skip whitespace
while (*src && ICharIsSpace(*src))
src++;
// If the block skipped was not at the beginning
// of the string then add one space character
if (*src && (dst != name))
*dst++ = ' ';
// Copy characters until end-of-string or next whitespace
while (*src && !ICharIsSpace(*src)) {
++nonSpaceChars;
*dst++ = *src++;
}
}
// Ensure destination string is terminated // Convert remaining internal whitespace to a single space.
*dst = 0; // Kind of hacky, but meh.
std::vector<plString> things = name.Tokenize(" \t\n\r");
// Check for minimum name length plStringStream ss;
if (nonSpaceChars < 3) for (auto it = things.begin(); it != things.end(); ++it) {
return kNetErrPlayerNameInvalid; ss << *it;
if ((it + 1) != things.end())
ss << " ";
}
name = ss.GetString();
// Now, check to see if we have the appropriate length
// We could count the characters, but lazy...
if (name.Replace(" ", "").GetSize() < 3)
return kNetErrPlayerNameInvalid;
return kNetSuccess; return kNetSuccess;
} }
@ -2938,21 +2924,18 @@ bool AccountCreateFromKeyRequestTrans::Recv (
//============================================================================ //============================================================================
PlayerCreateRequestTrans::PlayerCreateRequestTrans ( PlayerCreateRequestTrans::PlayerCreateRequestTrans (
const wchar_t playerName[], const plString& playerName,
const wchar_t avatarShape[], const plString& avatarShape,
const wchar_t friendInvite[], const plString& friendInvite,
FNetCliAuthPlayerCreateRequestCallback callback, FNetCliAuthPlayerCreateRequestCallback callback,
void * param void * param
) : NetAuthTrans(kPlayerCreateRequestTrans) ) : NetAuthTrans(kPlayerCreateRequestTrans)
, m_playerName(playerName)
, m_avatarShape(avatarShape)
, m_friendInvite(friendInvite)
, m_callback(callback) , m_callback(callback)
, m_param(param) , m_param(param)
{ {
StrCopy(m_playerName, playerName, arrsize(m_playerName));
StrCopy(m_avatarShape, avatarShape, arrsize(m_avatarShape));
if (friendInvite)
StrCopy(m_friendInvite, friendInvite, arrsize(m_friendInvite));
else
m_friendInvite[0] = 0;
memset(&m_playerInfo, 0, sizeof(m_playerInfo)); memset(&m_playerInfo, 0, sizeof(m_playerInfo));
} }
@ -2961,12 +2944,16 @@ bool PlayerCreateRequestTrans::Send () {
if (!AcquireConn()) if (!AcquireConn())
return false; return false;
plStringBuffer<uint16_t> playerName = m_playerName.ToUtf16();
plStringBuffer<uint16_t> avatarShape = m_avatarShape.ToUtf16();
plStringBuffer<uint16_t> friendInvite = m_friendInvite.ToUtf16();
const uintptr_t msg[] = { const uintptr_t msg[] = {
kCli2Auth_PlayerCreateRequest, kCli2Auth_PlayerCreateRequest,
m_transId, m_transId,
(uintptr_t) m_playerName, (uintptr_t) playerName.GetData(),
(uintptr_t) m_avatarShape, (uintptr_t) avatarShape.GetData(),
(uintptr_t) m_friendInvite, (uintptr_t) friendInvite.GetData(),
}; };
m_conn->Send(msg, arrsize(msg)); m_conn->Send(msg, arrsize(msg));
@ -5322,14 +5309,13 @@ void NetCliAuthAccountCreateFromKeyRequest (
//============================================================================ //============================================================================
void NetCliAuthPlayerCreateRequest ( void NetCliAuthPlayerCreateRequest (
const wchar_t playerName[], const plString& playerName,
const wchar_t avatarShape[], const plString& avatarShape,
const wchar_t friendInvite[], const plString& friendInvite,
FNetCliAuthPlayerCreateRequestCallback callback, FNetCliAuthPlayerCreateRequestCallback callback,
void * param void * param
) { ) {
wchar_t name[kMaxPlayerNameLength]; plString name = playerName;
StrCopy(name, playerName, arrsize(name));
ENetError error = FixupPlayerName(name); ENetError error = FixupPlayerName(name);
if (IS_NET_ERROR(error)) { if (IS_NET_ERROR(error)) {
NetCliAuthPlayerInfo playerInfo; NetCliAuthPlayerInfo playerInfo;

6
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

@ -200,9 +200,9 @@ typedef void (*FNetCliAuthPlayerCreateRequestCallback)(
const NetCliAuthPlayerInfo & playerInfo const NetCliAuthPlayerInfo & playerInfo
); );
void NetCliAuthPlayerCreateRequest ( void NetCliAuthPlayerCreateRequest (
const wchar_t playerName[], const plString& playerName,
const wchar_t avatarShape[], const plString& avatarShape,
const wchar_t friendInvite[], const plString& friendInvite,
FNetCliAuthPlayerCreateRequestCallback callback, FNetCliAuthPlayerCreateRequestCallback callback,
void * param void * param
); );

Loading…
Cancel
Save