| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts 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/>.
- */
- /******************************************************************************
- *
- * FILE
- * $Archive: /Commando/Code/WWOnline/WOLUser.cpp $
- *
- * DESCRIPTION
- *
- * PROGRAMMER
- * $Author: Steve_t $
- *
- * VERSION INFO
- * $Revision: 19 $
- * $Modtime: 10/10/02 10:38a $
- *
- ******************************************************************************/
- #include "always.h"
- #include "WOLUser.h"
- #include "WOLChannel.h"
- #include "WOLSquad.h"
- #include "WOLLadder.h"
- #include <WWDebug\WWDebug.h>
- namespace WWOnline {
- /******************************************************************************
- *
- * NAME
- * UserData::Create
- *
- * DESCRIPTION
- * Create a new User data instance
- *
- * INPUTS
- * WOLUser - Wolapi user structure
- *
- * RESULT
- * User -
- *
- ******************************************************************************/
- RefPtr<UserData> UserData::Create(const WOL::User& user)
- {
- return new UserData(user);
- }
- /******************************************************************************
- *
- * NAME
- * UserData::Create
- *
- * DESCRIPTION
- * Create a new User data instance
- *
- * INPUTS
- * Name - Name of user
- *
- * RESULT
- * User -
- *
- ******************************************************************************/
- RefPtr<UserData> UserData::Create(const wchar_t* name)
- {
- if (name)
- {
- WOL::User user;
- memset(&user, 0, sizeof(user));
- wcstombs((char*)user.name, name, sizeof(user.name));
- user.name[sizeof(user.name) - 1] = 0;
- return Create(user);
- }
- return RefPtr<UserData>();
- }
- /******************************************************************************
- *
- * NAME
- * UserData::UserData
- *
- * DESCRIPTION
- * Constructor
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- UserData::UserData(const WOL::User& user) :
- mUserName((char*)user.name),
- mLocation(USERLOCATION_UNKNOWN)
- {
- WWDEBUG_SAY(("WOL: Instantiating UserData '%S'\n", (const WCHAR*)mUserName));
- memcpy(&mData, &user, sizeof(mData));
- mKickTimer = 0;
- mData.next = NULL;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::~UserData
- *
- * DESCRIPTION
- * Destructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- UserData::~UserData()
- {
- WWDEBUG_SAY(("WOL: Destructing UserData '%S'\n", (const WCHAR*)mUserName));
- }
- /******************************************************************************
- *
- * NAME
- * UserData::UpdateData
- *
- * DESCRIPTION
- *
- * INPUTS
- * WOlUser - WOL user structure to update with.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::UpdateData(const WOL::User& wolUser)
- {
- wchar_t name[64];
- mbstowcs(name, (const char*)wolUser.name, sizeof(wolUser.name));
- name[sizeof(wolUser.name) - 1] = 0;
- WWASSERT(wcslen(name) && "Empty user name");
- bool isValid = (!mUserName.Is_Empty() && mUserName.Compare_No_Case(name) == 0);
- WWASSERT(isValid && "WOLUserData::UpdateData() mismatch");
- if (isValid)
- {
- if (mData.squadID != wolUser.squadID)
- {
- mSquad.Release();
- mData.squadID = wolUser.squadID;
- }
- }
- }
- /******************************************************************************
- *
- * NAME
- * UserData::Squelch
- *
- * DESCRIPTION
- *
- * INPUTS
- * OnOff - Squelch state
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::Squelch(bool onoff)
- {
- mData.flags = (onoff == true) ?
- (mData.flags | CHAT_USER_SQUELCHED) : (mData.flags ^ CHAT_USER_SQUELCHED);
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetLocation
- *
- * DESCRIPTION
- * Set the users location.
- *
- * INPUTS
- * Location - User's location
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetLocation(UserLocation location)
- {
- mLocation = location;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetChannel
- *
- * DESCRIPTION
- * Set the channel the user is in.
- *
- * INPUTS
- * Channel - Channel user is in.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetChannel(const RefPtr<ChannelData>& channel)
- {
- mChannel = channel;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetSquad
- *
- * DESCRIPTION
- * Associate a squad for this user.
- *
- * INPUTS
- * Squad
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetSquad(const RefPtr<SquadData>& squadData)
- {
- mSquad = squadData;
- if (squadData.IsValid())
- {
- mData.squadID = squadData->GetID();
- // Syncronize common data with updated squad information.
- strncpy((char*)mData.squadname, squadData->GetName(), sizeof(mData.squadname));
- mData.squadname[sizeof(mData.squadname) - 1] = 0;
- strncpy((char*)mData.squadabbrev, squadData->GetAbbr(), sizeof(mData.squadabbrev));
- mData.squadabbrev[sizeof(mData.squadabbrev) - 1] = 0;
- }
- else
- {
- mData.squadname[0] = 0;
- mData.squadabbrev[0] = 0;
- }
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetTeam
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetTeam(int team)
- {
- mData.team = team;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetLocale
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetLocale(WOL::Locale locale)
- {
- if (locale >= WOL::LOC_UNKNOWN && locale <= WOL::LOC_TURKEY)
- {
- mData.locale = locale;
- }
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetLadder
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetLadder(const RefPtr<LadderData>& ladder)
- {
- mUserLadder = ladder;
- }
- /******************************************************************************
- *
- * NAME
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<LadderData> UserData::GetClanLadder(void) const
- {
- if (mSquad.IsValid())
- {
- return mSquad->GetLadder();
- }
- return NULL;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::SetTeamLadder
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetTeamLadder(const RefPtr<LadderData>& ladder)
- {
- mTeamLadder = ladder;
- }
- /******************************************************************************
- *
- * NAME
- * UserData::
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void UserData::SetLadderFromType(const RefPtr<LadderData>& ladder, LadderType type)
- {
- if (type == LadderType_Team)
- {
- SetTeamLadder(ladder);
- return;
- }
- if (type == LadderType_Clan)
- {
- if (mSquad.IsValid())
- {
- mSquad->SetLadder(ladder);
- }
- return;
- }
- SetLadder(ladder);
- }
- /******************************************************************************
- *
- * NAME
- * UserData::
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<LadderData> UserData::GetLadderFromType(LadderType type)
- {
- if (type == LadderType_Team)
- {
- return GetTeamLadder();
- }
- if (type == LadderType_Clan)
- {
- return GetClanLadder();
- }
- return GetLadder();
- }
-
- /******************************************************************************
- *
- * NAME
- * NativeWOLUserList::
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- NativeWOLUserList::NativeWOLUserList(const UserList& users) :
- mNativeList(NULL)
- {
- int count = users.size();
- if (count > 0)
- {
- mNativeList = new WOL::User[count];
- if (mNativeList)
- {
- for (int index = 0; index < count; index++)
- {
- WOL::User* wolUser = &users[index]->GetData();
- memcpy(&mNativeList[index], wolUser, sizeof(WOL::User));
- if (index == (count - 1))
- {
- mNativeList[index].next = NULL;
- }
- else
- {
- mNativeList[index].next = &mNativeList[index + 1];
- }
- }
- }
- }
- }
- /******************************************************************************
- *
- * NAME
- * NativeWOLUserList::
- *
- * DESCRIPTION
- * Destructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- NativeWOLUserList::~NativeWOLUserList()
- {
- if (mNativeList)
- {
- delete []mNativeList;
- }
- }
- /******************************************************************************
- *
- * NAME
- * FindUserInList
- *
- * DESCRIPTION
- * Search for a user with the specified name in the list.
- *
- * INPUTS
- * Name - Name of user to search for.
- * List - UserData list to search.
- *
- * RESULT
- * User -
- *
- ******************************************************************************/
- RefPtr<UserData> FindUserInList(const wchar_t* username, const UserList& list)
- {
- for (unsigned int index = 0; index < list.size(); index++)
- {
- const WideStringClass& name = list[index]->GetName();
- if (name.Compare_No_Case(username) == 0)
- {
- return list[index];
- }
- }
- return RefPtr<UserData>();
- }
- /******************************************************************************
- *
- * NAME
- * RemoveUserInList
- *
- * DESCRIPTION
- * Remove the
- *
- * INPUTS
- * Name - Name of user to remove.
- * List - UserData list to search.
- *
- * RESULT
- * Removed - User removed from list.
- *
- ******************************************************************************/
- RefPtr<UserData> RemoveUserInList(const wchar_t* username, UserList& list)
- {
- RefPtr<UserData> removedUser;
- UserList::iterator iter = list.begin();
- while (iter != list.end())
- {
- const WideStringClass& name = (*iter)->GetName();
- if (name.Compare_No_Case(username) == 0)
- {
- removedUser = *iter;
- list.erase(iter);
- break;
- }
- iter++;
- }
- return removedUser;
- }
- } // namespace WWOnline
|