mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Fix line endings and tabs
This commit is contained in:
@ -1,21 +1,21 @@
|
||||
include_directories("../../CoreLib")
|
||||
include_directories("../../NucleusLib/inc")
|
||||
include_directories("../../NucleusLib")
|
||||
include_directories("../../PubUtilLib")
|
||||
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
set(plNetTransport_SOURCES
|
||||
plNetTransport.cpp
|
||||
plNetTransportMember.cpp
|
||||
)
|
||||
|
||||
set(plNetTransport_HEADERS
|
||||
plNetTransport.h
|
||||
plNetTransportMember.h
|
||||
)
|
||||
|
||||
add_library(plNetTransport STATIC ${plNetTransport_SOURCES} ${plNetTransport_HEADERS})
|
||||
|
||||
source_group("Source Files" FILES ${plNetTransport_SOURCES})
|
||||
source_group("Header Files" FILES ${plNetTransport_HEADERS})
|
||||
include_directories("../../CoreLib")
|
||||
include_directories("../../NucleusLib/inc")
|
||||
include_directories("../../NucleusLib")
|
||||
include_directories("../../PubUtilLib")
|
||||
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
set(plNetTransport_SOURCES
|
||||
plNetTransport.cpp
|
||||
plNetTransportMember.cpp
|
||||
)
|
||||
|
||||
set(plNetTransport_HEADERS
|
||||
plNetTransport.h
|
||||
plNetTransportMember.h
|
||||
)
|
||||
|
||||
add_library(plNetTransport STATIC ${plNetTransport_SOURCES} ${plNetTransport_HEADERS})
|
||||
|
||||
source_group("Source Files" FILES ${plNetTransport_SOURCES})
|
||||
source_group("Header Files" FILES ${plNetTransport_HEADERS})
|
||||
|
@ -1,355 +1,355 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#pragma warning(disable: 4786)
|
||||
|
||||
#include "hsTimer.h"
|
||||
#include "plNetTransport.h"
|
||||
#include "plNetTransportMember.h"
|
||||
#include "plNetMessage/plNetMessage.h"
|
||||
#include "plNetClient/plNetClientMgr.h"
|
||||
#include <algorithm>
|
||||
|
||||
plNetTransport::~plNetTransport()
|
||||
{
|
||||
ClearMembers();
|
||||
}
|
||||
|
||||
//
|
||||
// add a member to the master list if not already there
|
||||
//
|
||||
int plNetTransport::AddMember(plNetTransportMember* mbr)
|
||||
{
|
||||
if (FindMember(mbr)==-1)
|
||||
{
|
||||
fMembers.push_back(mbr);
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Adding member %s", mbr->AsStdString().c_str()) );
|
||||
plNetClientMgr::GetInstance()->GetListenList()->AddMember(mbr);
|
||||
plNetClientMgr::GetInstance()->GetTalkList()->AddMember(mbr);
|
||||
DumpState();
|
||||
return fMembers.size()-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void plNetTransport::IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr)
|
||||
{
|
||||
int i;
|
||||
for( i=mbr->GetNumSubscriptions()-1; i>=0 ; i-- )
|
||||
{
|
||||
int chan=mbr->GetSubscription(i);
|
||||
hsBool ok=UnSubscribeToChannelGrp(mbr, chan);
|
||||
hsAssert(ok, "can't find supposed subscription to remove");
|
||||
} // for
|
||||
}
|
||||
|
||||
void plNetTransport::IRemoveMember(plNetTransportMember* mbr)
|
||||
{
|
||||
if (!mbr)
|
||||
return;
|
||||
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Removing member %s", mbr->AsStdString().c_str()) );
|
||||
|
||||
// plNetClientMgr::GetInstance()->GetNetCore()->RemovePeer(mbr->GetPeerID());
|
||||
plNetClientMgr::GetInstance()->GetTalkList()->RemoveMember(mbr);
|
||||
plNetClientMgr::GetInstance()->GetListenList()->RemoveMember(mbr);
|
||||
|
||||
// remove member from subscription lists
|
||||
IUnSubscribeToAllChannelGrps(mbr);
|
||||
|
||||
plMembersList::iterator it=std::find(fMembers.begin(),fMembers.end(),mbr);
|
||||
|
||||
// remove member from master list
|
||||
fMembers.erase(it);
|
||||
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Done Removing member %s", mbr->AsStdString().c_str()) );
|
||||
DumpState();
|
||||
|
||||
delete mbr;
|
||||
}
|
||||
|
||||
//
|
||||
// remove member from master list, and all subscription channels.
|
||||
// return true on success.
|
||||
//
|
||||
hsBool plNetTransport::RemoveMember(int idx)
|
||||
{
|
||||
if (idx>=0)
|
||||
{
|
||||
plNetTransportMember* mbr=GetMember(idx);
|
||||
IRemoveMember(mbr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// remove member from master list, and all subscription channels.
|
||||
// return true on success.
|
||||
//
|
||||
hsBool plNetTransport::RemoveMember(plNetTransportMember* mbr)
|
||||
{
|
||||
IRemoveMember(mbr);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(const plNetTransportMember* mbr)
|
||||
{
|
||||
plMembersList::iterator it = std::find(fMembers.begin(), fMembers.end(), mbr);
|
||||
return (it==fMembers.end()) ? -1 : (it-fMembers.begin());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// add this member to the given channel grp
|
||||
//
|
||||
void plNetTransport::SubscribeToChannelGrp(plNetTransportMember* mbr, int channel)
|
||||
{
|
||||
// hsAssert(FindMember(mbr) != -1, "must add member before subscribing to channel");
|
||||
if (mbr->AddSubscription(channel))
|
||||
{
|
||||
hsAssert(channel<fChannelGroups.size(), "invalid channel index");
|
||||
fChannelGroups[channel].push_back(mbr);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Remove the subscription to the given channel grp for a member.
|
||||
//
|
||||
hsBool plNetTransport::UnSubscribeToChannelGrp(plNetTransportMember* mbr, int chan)
|
||||
{
|
||||
hsAssert(chan>=0 && chan<fChannelGroups.size(), "invalid channel idx");
|
||||
plMembersList* mList = &fChannelGroups[chan];
|
||||
plMembersList::iterator it=std::find(mList->begin(), mList->end(), mbr);
|
||||
if (it != mList->end())
|
||||
{
|
||||
mList->erase(it);
|
||||
hsBool ret=mbr->RemoveSubscription(chan);
|
||||
hsAssert(ret, "error removing subscription");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// copy list of members channelGrp subscriptions
|
||||
//
|
||||
void plNetTransport::GetSubscriptions(plNetTransportMember* mbr, std::vector<int>* channels) const
|
||||
{
|
||||
mbr->CopySubscriptions(channels);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Send Msg to all members in the given channelGrp.
|
||||
// Here's where multicasting would be used.
|
||||
// Returns neg number (NetCore::RetCode) on send error, 1, if not sent, and 0 if sent
|
||||
//
|
||||
int plNetTransport::SendMsg(int chan, plNetMessage* netMsg) const
|
||||
{
|
||||
NetCommSendMsg(netMsg);
|
||||
return hsOK;
|
||||
|
||||
plNetClientMgr* nc=plNetClientMgr::GetInstance();
|
||||
int ret=1; // didn't send
|
||||
|
||||
if (chan < fChannelGroups.size())
|
||||
{
|
||||
const plMembersList* mList = &fChannelGroups[chan];
|
||||
|
||||
// does this msg have a list of receivers
|
||||
plNetMsgReceiversListHelper* rl = plNetMsgReceiversListHelper::ConvertNoRef(netMsg);
|
||||
|
||||
#if 0
|
||||
// send msg to all subscribers to this channel
|
||||
int size=mList->size();
|
||||
for( int i=0 ; i<size; i++ )
|
||||
{
|
||||
hsAssert(false, "eric, port me");
|
||||
|
||||
plNetTransportMember* tm=(*mList)[i];
|
||||
hsAssert(tm, "nil mbr in sendMsg");
|
||||
// int peerID=tm->GetPeerID();
|
||||
// hsAssert(peerID>=0, "queing message to invalid peer");
|
||||
|
||||
// if ((ncRet=nc->GetNetClientComm().SendMsg(netMsg, peerID, sendFlags, msgSize)) != plNetCore::kNetOK)
|
||||
|
||||
NetCommSendMsg(netMsg);
|
||||
if (rl)
|
||||
{
|
||||
hsBool ok=rl->RemoveReceiverPlayerID(tm->GetPlayerID());
|
||||
hsAssert(ok, "couldn't find rcvr to remove?");
|
||||
}
|
||||
ret=0; // sent ok
|
||||
} // for
|
||||
#endif
|
||||
|
||||
// if there are rcvrs left that we couldn't send to, send via server
|
||||
if (rl && rl->GetNumReceivers())
|
||||
{
|
||||
// if ((ncRet=nc->GetNetClientComm().SendMsg(netMsg, nc->GetServerPeerID(), sendFlags, msgSize)) != plNetCore::kNetOK)
|
||||
NetCommSendMsg(netMsg);
|
||||
ret=0; // sent
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hsStatusMessage("EMPTY TRANSPORT GROUP\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void plNetTransport::ClearMembers()
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
hsAssert(mbr, "nil member?");
|
||||
IUnSubscribeToAllChannelGrps(mbr);
|
||||
delete mbr;
|
||||
} // for
|
||||
|
||||
fMembers.clear();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(UInt32 playerID) const
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
if (mbr->GetPlayerID()==playerID)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(const plKey avKey) const
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
if (mbr->GetAvatarKey()==avKey)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// clear channel and unsubscribe all members to that channel
|
||||
//
|
||||
void plNetTransport::ClearChannelGrp(int channel)
|
||||
{
|
||||
const plMembersList* mList = &fChannelGroups[channel];
|
||||
int i, size=mList->size();
|
||||
for( i=0 ; i<size; i++ )
|
||||
{
|
||||
plNetTransportMember* tm=(*mList)[i];
|
||||
hsBool ok=tm->RemoveSubscription(channel);
|
||||
hsAssert(ok, "error removing subscription");
|
||||
}
|
||||
|
||||
fChannelGroups[channel].clear();
|
||||
}
|
||||
|
||||
void plNetTransport::DumpState()
|
||||
{
|
||||
plNetClientMgr* nc=plNetClientMgr::GetInstance();
|
||||
|
||||
hsLogEntry( nc->DebugMsg("-------------------\n") );
|
||||
hsLogEntry( nc->DebugMsg("Num Channels=%d\n", fChannelGroups.size()) );
|
||||
|
||||
int i;
|
||||
for(i=0;i<fChannelGroups.size();i++)
|
||||
{
|
||||
plMembersList* mList = &fChannelGroups[i];
|
||||
hsLogEntry( nc->DebugMsg("\tChannel %d, num mbrs=%d\n", i, mList->size()) );
|
||||
int j;
|
||||
for(j=0; j<mList->size();j++)
|
||||
{
|
||||
plNetTransportMember * mbr = (*mList)[j];
|
||||
hsLogEntry( nc->DebugMsg("\t\tMbr %s\n",(*mList)[j]->AsStdString().c_str()) );
|
||||
}
|
||||
}
|
||||
|
||||
nc->DebugMsg("Num Mbrs=%d\n", GetNumMembers());
|
||||
for(i=0;i<GetNumMembers();i++)
|
||||
{
|
||||
plNetTransportMember * mbr = GetMember(i);
|
||||
hsLogEntry (nc->DebugMsg("\tMbr %d, name=%s, plyrID=%lu, subs=%d",
|
||||
i,mbr->AsStdString().c_str(),mbr->GetPlayerID(),mbr->GetNumSubscriptions()) );
|
||||
int j;
|
||||
for(j=0;j<mbr->GetNumSubscriptions();j++)
|
||||
{
|
||||
hsLogEntry( nc->DebugMsg("\t\tSub %d, chan=%d\n", j, mbr->GetSubscription(j)) );
|
||||
}
|
||||
}
|
||||
hsLogEntry( nc->DebugMsg("\n") );
|
||||
}
|
||||
|
||||
void plNetTransport::SetNumChannels(int n)
|
||||
{
|
||||
if (n>fChannelGroups.size())
|
||||
fChannelGroups.resize(n);
|
||||
}
|
||||
|
||||
|
||||
int compare( const void* arg1, const void *arg2 )
|
||||
{
|
||||
plNetTransportMember** m1 = (plNetTransportMember**)arg1;
|
||||
plNetTransportMember** m2 = (plNetTransportMember**)arg2;
|
||||
float d1=m1 ? (*m1)->GetDistSq() : hsScalarMax;
|
||||
float d2=m2 ? (*m2)->GetDistSq() : hsScalarMax;
|
||||
return (int)(d1-d2);
|
||||
}
|
||||
|
||||
//
|
||||
// create a members list sorted by dist.
|
||||
// caller must delete this when done
|
||||
//
|
||||
void plNetTransport::GetMemberListDistSorted(plNetTransportMember**& listIn) const
|
||||
{
|
||||
// copy members list
|
||||
listIn = TRACKED_NEW plNetTransportMember* [fMembers.size()];
|
||||
int i;
|
||||
for (i=0; i<fMembers.size(); i++)
|
||||
listIn[i]=fMembers[i];
|
||||
|
||||
// sort members list
|
||||
qsort(listIn, fMembers.size(), sizeof(plNetTransportMember*), compare);
|
||||
}
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#pragma warning(disable: 4786)
|
||||
|
||||
#include "hsTimer.h"
|
||||
#include "plNetTransport.h"
|
||||
#include "plNetTransportMember.h"
|
||||
#include "plNetMessage/plNetMessage.h"
|
||||
#include "plNetClient/plNetClientMgr.h"
|
||||
#include <algorithm>
|
||||
|
||||
plNetTransport::~plNetTransport()
|
||||
{
|
||||
ClearMembers();
|
||||
}
|
||||
|
||||
//
|
||||
// add a member to the master list if not already there
|
||||
//
|
||||
int plNetTransport::AddMember(plNetTransportMember* mbr)
|
||||
{
|
||||
if (FindMember(mbr)==-1)
|
||||
{
|
||||
fMembers.push_back(mbr);
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Adding member %s", mbr->AsStdString().c_str()) );
|
||||
plNetClientMgr::GetInstance()->GetListenList()->AddMember(mbr);
|
||||
plNetClientMgr::GetInstance()->GetTalkList()->AddMember(mbr);
|
||||
DumpState();
|
||||
return fMembers.size()-1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void plNetTransport::IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr)
|
||||
{
|
||||
int i;
|
||||
for( i=mbr->GetNumSubscriptions()-1; i>=0 ; i-- )
|
||||
{
|
||||
int chan=mbr->GetSubscription(i);
|
||||
hsBool ok=UnSubscribeToChannelGrp(mbr, chan);
|
||||
hsAssert(ok, "can't find supposed subscription to remove");
|
||||
} // for
|
||||
}
|
||||
|
||||
void plNetTransport::IRemoveMember(plNetTransportMember* mbr)
|
||||
{
|
||||
if (!mbr)
|
||||
return;
|
||||
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Removing member %s", mbr->AsStdString().c_str()) );
|
||||
|
||||
// plNetClientMgr::GetInstance()->GetNetCore()->RemovePeer(mbr->GetPeerID());
|
||||
plNetClientMgr::GetInstance()->GetTalkList()->RemoveMember(mbr);
|
||||
plNetClientMgr::GetInstance()->GetListenList()->RemoveMember(mbr);
|
||||
|
||||
// remove member from subscription lists
|
||||
IUnSubscribeToAllChannelGrps(mbr);
|
||||
|
||||
plMembersList::iterator it=std::find(fMembers.begin(),fMembers.end(),mbr);
|
||||
|
||||
// remove member from master list
|
||||
fMembers.erase(it);
|
||||
|
||||
hsLogEntry( plNetClientMgr::GetInstance()->DebugMsg("Done Removing member %s", mbr->AsStdString().c_str()) );
|
||||
DumpState();
|
||||
|
||||
delete mbr;
|
||||
}
|
||||
|
||||
//
|
||||
// remove member from master list, and all subscription channels.
|
||||
// return true on success.
|
||||
//
|
||||
hsBool plNetTransport::RemoveMember(int idx)
|
||||
{
|
||||
if (idx>=0)
|
||||
{
|
||||
plNetTransportMember* mbr=GetMember(idx);
|
||||
IRemoveMember(mbr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// remove member from master list, and all subscription channels.
|
||||
// return true on success.
|
||||
//
|
||||
hsBool plNetTransport::RemoveMember(plNetTransportMember* mbr)
|
||||
{
|
||||
IRemoveMember(mbr);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(const plNetTransportMember* mbr)
|
||||
{
|
||||
plMembersList::iterator it = std::find(fMembers.begin(), fMembers.end(), mbr);
|
||||
return (it==fMembers.end()) ? -1 : (it-fMembers.begin());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// add this member to the given channel grp
|
||||
//
|
||||
void plNetTransport::SubscribeToChannelGrp(plNetTransportMember* mbr, int channel)
|
||||
{
|
||||
// hsAssert(FindMember(mbr) != -1, "must add member before subscribing to channel");
|
||||
if (mbr->AddSubscription(channel))
|
||||
{
|
||||
hsAssert(channel<fChannelGroups.size(), "invalid channel index");
|
||||
fChannelGroups[channel].push_back(mbr);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Remove the subscription to the given channel grp for a member.
|
||||
//
|
||||
hsBool plNetTransport::UnSubscribeToChannelGrp(plNetTransportMember* mbr, int chan)
|
||||
{
|
||||
hsAssert(chan>=0 && chan<fChannelGroups.size(), "invalid channel idx");
|
||||
plMembersList* mList = &fChannelGroups[chan];
|
||||
plMembersList::iterator it=std::find(mList->begin(), mList->end(), mbr);
|
||||
if (it != mList->end())
|
||||
{
|
||||
mList->erase(it);
|
||||
hsBool ret=mbr->RemoveSubscription(chan);
|
||||
hsAssert(ret, "error removing subscription");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// copy list of members channelGrp subscriptions
|
||||
//
|
||||
void plNetTransport::GetSubscriptions(plNetTransportMember* mbr, std::vector<int>* channels) const
|
||||
{
|
||||
mbr->CopySubscriptions(channels);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Send Msg to all members in the given channelGrp.
|
||||
// Here's where multicasting would be used.
|
||||
// Returns neg number (NetCore::RetCode) on send error, 1, if not sent, and 0 if sent
|
||||
//
|
||||
int plNetTransport::SendMsg(int chan, plNetMessage* netMsg) const
|
||||
{
|
||||
NetCommSendMsg(netMsg);
|
||||
return hsOK;
|
||||
|
||||
plNetClientMgr* nc=plNetClientMgr::GetInstance();
|
||||
int ret=1; // didn't send
|
||||
|
||||
if (chan < fChannelGroups.size())
|
||||
{
|
||||
const plMembersList* mList = &fChannelGroups[chan];
|
||||
|
||||
// does this msg have a list of receivers
|
||||
plNetMsgReceiversListHelper* rl = plNetMsgReceiversListHelper::ConvertNoRef(netMsg);
|
||||
|
||||
#if 0
|
||||
// send msg to all subscribers to this channel
|
||||
int size=mList->size();
|
||||
for( int i=0 ; i<size; i++ )
|
||||
{
|
||||
hsAssert(false, "eric, port me");
|
||||
|
||||
plNetTransportMember* tm=(*mList)[i];
|
||||
hsAssert(tm, "nil mbr in sendMsg");
|
||||
// int peerID=tm->GetPeerID();
|
||||
// hsAssert(peerID>=0, "queing message to invalid peer");
|
||||
|
||||
// if ((ncRet=nc->GetNetClientComm().SendMsg(netMsg, peerID, sendFlags, msgSize)) != plNetCore::kNetOK)
|
||||
|
||||
NetCommSendMsg(netMsg);
|
||||
if (rl)
|
||||
{
|
||||
hsBool ok=rl->RemoveReceiverPlayerID(tm->GetPlayerID());
|
||||
hsAssert(ok, "couldn't find rcvr to remove?");
|
||||
}
|
||||
ret=0; // sent ok
|
||||
} // for
|
||||
#endif
|
||||
|
||||
// if there are rcvrs left that we couldn't send to, send via server
|
||||
if (rl && rl->GetNumReceivers())
|
||||
{
|
||||
// if ((ncRet=nc->GetNetClientComm().SendMsg(netMsg, nc->GetServerPeerID(), sendFlags, msgSize)) != plNetCore::kNetOK)
|
||||
NetCommSendMsg(netMsg);
|
||||
ret=0; // sent
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hsStatusMessage("EMPTY TRANSPORT GROUP\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void plNetTransport::ClearMembers()
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
hsAssert(mbr, "nil member?");
|
||||
IUnSubscribeToAllChannelGrps(mbr);
|
||||
delete mbr;
|
||||
} // for
|
||||
|
||||
fMembers.clear();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(UInt32 playerID) const
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
if (mbr->GetPlayerID()==playerID)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// return array index or -1
|
||||
//
|
||||
int plNetTransport::FindMember(const plKey avKey) const
|
||||
{
|
||||
int i;
|
||||
for( i=0 ;i<GetNumMembers() ;i++ )
|
||||
{
|
||||
plNetTransportMember* mbr = GetMember(i);
|
||||
if (mbr->GetAvatarKey()==avKey)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// clear channel and unsubscribe all members to that channel
|
||||
//
|
||||
void plNetTransport::ClearChannelGrp(int channel)
|
||||
{
|
||||
const plMembersList* mList = &fChannelGroups[channel];
|
||||
int i, size=mList->size();
|
||||
for( i=0 ; i<size; i++ )
|
||||
{
|
||||
plNetTransportMember* tm=(*mList)[i];
|
||||
hsBool ok=tm->RemoveSubscription(channel);
|
||||
hsAssert(ok, "error removing subscription");
|
||||
}
|
||||
|
||||
fChannelGroups[channel].clear();
|
||||
}
|
||||
|
||||
void plNetTransport::DumpState()
|
||||
{
|
||||
plNetClientMgr* nc=plNetClientMgr::GetInstance();
|
||||
|
||||
hsLogEntry( nc->DebugMsg("-------------------\n") );
|
||||
hsLogEntry( nc->DebugMsg("Num Channels=%d\n", fChannelGroups.size()) );
|
||||
|
||||
int i;
|
||||
for(i=0;i<fChannelGroups.size();i++)
|
||||
{
|
||||
plMembersList* mList = &fChannelGroups[i];
|
||||
hsLogEntry( nc->DebugMsg("\tChannel %d, num mbrs=%d\n", i, mList->size()) );
|
||||
int j;
|
||||
for(j=0; j<mList->size();j++)
|
||||
{
|
||||
plNetTransportMember * mbr = (*mList)[j];
|
||||
hsLogEntry( nc->DebugMsg("\t\tMbr %s\n",(*mList)[j]->AsStdString().c_str()) );
|
||||
}
|
||||
}
|
||||
|
||||
nc->DebugMsg("Num Mbrs=%d\n", GetNumMembers());
|
||||
for(i=0;i<GetNumMembers();i++)
|
||||
{
|
||||
plNetTransportMember * mbr = GetMember(i);
|
||||
hsLogEntry (nc->DebugMsg("\tMbr %d, name=%s, plyrID=%lu, subs=%d",
|
||||
i,mbr->AsStdString().c_str(),mbr->GetPlayerID(),mbr->GetNumSubscriptions()) );
|
||||
int j;
|
||||
for(j=0;j<mbr->GetNumSubscriptions();j++)
|
||||
{
|
||||
hsLogEntry( nc->DebugMsg("\t\tSub %d, chan=%d\n", j, mbr->GetSubscription(j)) );
|
||||
}
|
||||
}
|
||||
hsLogEntry( nc->DebugMsg("\n") );
|
||||
}
|
||||
|
||||
void plNetTransport::SetNumChannels(int n)
|
||||
{
|
||||
if (n>fChannelGroups.size())
|
||||
fChannelGroups.resize(n);
|
||||
}
|
||||
|
||||
|
||||
int compare( const void* arg1, const void *arg2 )
|
||||
{
|
||||
plNetTransportMember** m1 = (plNetTransportMember**)arg1;
|
||||
plNetTransportMember** m2 = (plNetTransportMember**)arg2;
|
||||
float d1=m1 ? (*m1)->GetDistSq() : hsScalarMax;
|
||||
float d2=m2 ? (*m2)->GetDistSq() : hsScalarMax;
|
||||
return (int)(d1-d2);
|
||||
}
|
||||
|
||||
//
|
||||
// create a members list sorted by dist.
|
||||
// caller must delete this when done
|
||||
//
|
||||
void plNetTransport::GetMemberListDistSorted(plNetTransportMember**& listIn) const
|
||||
{
|
||||
// copy members list
|
||||
listIn = TRACKED_NEW plNetTransportMember* [fMembers.size()];
|
||||
int i;
|
||||
for (i=0; i<fMembers.size(); i++)
|
||||
listIn[i]=fMembers[i];
|
||||
|
||||
// sort members list
|
||||
qsort(listIn, fMembers.size(), sizeof(plNetTransportMember*), compare);
|
||||
}
|
||||
|
@ -1,79 +1,79 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#ifndef plNetTransport_h
|
||||
#define plNetTransport_h
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsStlUtils.h"
|
||||
|
||||
//
|
||||
// The transport class handles the details of sending net msgs to
|
||||
// the server or to groups of clients (members).
|
||||
// It hides whether we are playing in P2P mode or C/S mode.
|
||||
// It is currently used only clientside but is general enough to
|
||||
// be used by a server as well.
|
||||
//
|
||||
class plKey;
|
||||
class plNetTransportMember;
|
||||
typedef std::vector<plNetTransportMember*> plMembersList;
|
||||
class plNetMessage;
|
||||
class plNetTransport
|
||||
{
|
||||
private:
|
||||
plMembersList fMembers; // master list of all members in the game, server is member[0]
|
||||
std::vector<plMembersList> fChannelGroups; // members grouped by channel
|
||||
|
||||
void IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr);
|
||||
void IRemoveMember(plNetTransportMember* mbr);
|
||||
public:
|
||||
plNetTransport() {}
|
||||
~plNetTransport();
|
||||
|
||||
void DumpState();
|
||||
|
||||
// master list ops
|
||||
void GetMemberListDistSorted(plNetTransportMember**& listPtr) const; // allocates and sorts array
|
||||
int FindMember(const plKey avKey) const; // return array index or -1
|
||||
int FindMember(UInt32 playerID) const; // return array index or -1
|
||||
int FindMember(const plNetTransportMember* mbr); // return array index or -1
|
||||
int AddMember(plNetTransportMember* mbr); // to master list, if not there
|
||||
hsBool RemoveMember(plNetTransportMember* mbr); // from master list and all channels
|
||||
hsBool RemoveMember(int idx); // from master list and all channels
|
||||
int GetNumMembers() const { return fMembers.size(); }
|
||||
plNetTransportMember* GetMember(int i) const { return i>=0 && i<fMembers.size() ? fMembers[i] : nil; }
|
||||
void ClearMembers();
|
||||
|
||||
// channel group ops
|
||||
void SubscribeToChannelGrp(plNetTransportMember* mbr, int channel);
|
||||
hsBool UnSubscribeToChannelGrp(plNetTransportMember* mbr, int channel);
|
||||
void GetSubscriptions(plNetTransportMember* mbr, std::vector<int>* channels) const;
|
||||
void ClearChannelGrp(int channel);
|
||||
void SetNumChannels(int n);
|
||||
|
||||
int SendMsg(int channel, plNetMessage* msg) const;
|
||||
};
|
||||
|
||||
#endif // plNetTransport_h
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#ifndef plNetTransport_h
|
||||
#define plNetTransport_h
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsStlUtils.h"
|
||||
|
||||
//
|
||||
// The transport class handles the details of sending net msgs to
|
||||
// the server or to groups of clients (members).
|
||||
// It hides whether we are playing in P2P mode or C/S mode.
|
||||
// It is currently used only clientside but is general enough to
|
||||
// be used by a server as well.
|
||||
//
|
||||
class plKey;
|
||||
class plNetTransportMember;
|
||||
typedef std::vector<plNetTransportMember*> plMembersList;
|
||||
class plNetMessage;
|
||||
class plNetTransport
|
||||
{
|
||||
private:
|
||||
plMembersList fMembers; // master list of all members in the game, server is member[0]
|
||||
std::vector<plMembersList> fChannelGroups; // members grouped by channel
|
||||
|
||||
void IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr);
|
||||
void IRemoveMember(plNetTransportMember* mbr);
|
||||
public:
|
||||
plNetTransport() {}
|
||||
~plNetTransport();
|
||||
|
||||
void DumpState();
|
||||
|
||||
// master list ops
|
||||
void GetMemberListDistSorted(plNetTransportMember**& listPtr) const; // allocates and sorts array
|
||||
int FindMember(const plKey avKey) const; // return array index or -1
|
||||
int FindMember(UInt32 playerID) const; // return array index or -1
|
||||
int FindMember(const plNetTransportMember* mbr); // return array index or -1
|
||||
int AddMember(plNetTransportMember* mbr); // to master list, if not there
|
||||
hsBool RemoveMember(plNetTransportMember* mbr); // from master list and all channels
|
||||
hsBool RemoveMember(int idx); // from master list and all channels
|
||||
int GetNumMembers() const { return fMembers.size(); }
|
||||
plNetTransportMember* GetMember(int i) const { return i>=0 && i<fMembers.size() ? fMembers[i] : nil; }
|
||||
void ClearMembers();
|
||||
|
||||
// channel group ops
|
||||
void SubscribeToChannelGrp(plNetTransportMember* mbr, int channel);
|
||||
hsBool UnSubscribeToChannelGrp(plNetTransportMember* mbr, int channel);
|
||||
void GetSubscriptions(plNetTransportMember* mbr, std::vector<int>* channels) const;
|
||||
void ClearChannelGrp(int channel);
|
||||
void SetNumChannels(int n);
|
||||
|
||||
int SendMsg(int channel, plNetMessage* msg) const;
|
||||
};
|
||||
|
||||
#endif // plNetTransport_h
|
||||
|
@ -1,70 +1,70 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include <algorithm>
|
||||
#include "plNetTransportMember.h"
|
||||
|
||||
//
|
||||
// add a channel subscription if it's not already there
|
||||
// returns true if added
|
||||
//
|
||||
hsBool plNetTransportMember::AddSubscription(int chan)
|
||||
{
|
||||
if (FindSubscription(chan)==-1)
|
||||
{
|
||||
fSubscriptions.push_back(chan);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
hsBool plNetTransportMember::RemoveSubscription(int chan)
|
||||
{
|
||||
int idx=FindSubscription(chan);
|
||||
if (idx>=0)
|
||||
{
|
||||
fSubscriptions.erase(fSubscriptions.begin()+idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int plNetTransportMember::FindSubscription(int chan)
|
||||
{
|
||||
std::vector<int>::iterator it=std::find(fSubscriptions.begin(), fSubscriptions.end(), chan);
|
||||
return (it==fSubscriptions.end()) ? -1 : (it-fSubscriptions.begin());
|
||||
}
|
||||
|
||||
std::string plNetTransportMember::AsStdString() const
|
||||
{
|
||||
if (IsServer())
|
||||
{
|
||||
return "(server)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetPlayerName();
|
||||
}
|
||||
}
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#include <algorithm>
|
||||
#include "plNetTransportMember.h"
|
||||
|
||||
//
|
||||
// add a channel subscription if it's not already there
|
||||
// returns true if added
|
||||
//
|
||||
hsBool plNetTransportMember::AddSubscription(int chan)
|
||||
{
|
||||
if (FindSubscription(chan)==-1)
|
||||
{
|
||||
fSubscriptions.push_back(chan);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
hsBool plNetTransportMember::RemoveSubscription(int chan)
|
||||
{
|
||||
int idx=FindSubscription(chan);
|
||||
if (idx>=0)
|
||||
{
|
||||
fSubscriptions.erase(fSubscriptions.begin()+idx);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int plNetTransportMember::FindSubscription(int chan)
|
||||
{
|
||||
std::vector<int>::iterator it=std::find(fSubscriptions.begin(), fSubscriptions.end(), chan);
|
||||
return (it==fSubscriptions.end()) ? -1 : (it-fSubscriptions.begin());
|
||||
}
|
||||
|
||||
std::string plNetTransportMember::AsStdString() const
|
||||
{
|
||||
if (IsServer())
|
||||
{
|
||||
return "(server)";
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetPlayerName();
|
||||
}
|
||||
}
|
||||
|
@ -1,108 +1,108 @@
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#ifndef plNetTransportMember_h
|
||||
#define plNetTransportMember_h
|
||||
|
||||
#include "hsConfig.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include "plNetCommon/plNetMember.h"
|
||||
#include "pnKeyedObject/plKey.h"
|
||||
|
||||
//
|
||||
// This represents a participant in the game, ie. another
|
||||
// remote user.
|
||||
// It is a basic net member with a list of channels that it subscribes to.
|
||||
//
|
||||
class plKey;
|
||||
|
||||
class plNetTransportMember : public plNetMember
|
||||
{
|
||||
public:
|
||||
enum TransportFlags
|
||||
{
|
||||
kSendingVoice = 1<<0,
|
||||
kSendingActions = 1<<1,
|
||||
};
|
||||
protected:
|
||||
plKey fAvatarKey;
|
||||
std::string fPlayerName;
|
||||
UInt32 fPlayerID;
|
||||
std::vector<int> fSubscriptions; // list of channelGrp subscriptions
|
||||
UInt32 fTransportFlags;
|
||||
float fDistSq; // from local player, temp
|
||||
UInt8 fCCRLevel;
|
||||
public:
|
||||
CLASSNAME_REGISTER( plNetTransportMember);
|
||||
GETINTERFACE_ANY( plNetTransportMember, plNetMember);
|
||||
|
||||
plNetTransportMember() : fAvatarKey(nil),
|
||||
fTransportFlags(0),fPlayerID(0),fDistSq(-1),fCCRLevel(0) {}
|
||||
plNetTransportMember(plNetApp* na) : plNetMember(na),
|
||||
fAvatarKey(nil),fTransportFlags(0),fPlayerID(0),fDistSq(-1),fCCRLevel(0) {}
|
||||
~plNetTransportMember() {}
|
||||
|
||||
void SetDistSq(float s) { fDistSq=s; }
|
||||
float GetDistSq() const { return fDistSq; }
|
||||
|
||||
plKey GetAvatarKey() { return fAvatarKey; }
|
||||
void SetAvatarKey(plKey k)
|
||||
{
|
||||
fAvatarKey=k;
|
||||
}
|
||||
void SetPlayerName(const char * value) { fPlayerName=value;}
|
||||
const char * GetPlayerName() const { return fPlayerName.c_str();}
|
||||
void SetPlayerID(UInt32 value) { fPlayerID=value;}
|
||||
UInt32 GetPlayerID() const { return fPlayerID;}
|
||||
void SetIsServer(bool value) { (value)?SetFlags(GetFlags()|kIsServer):SetFlags(GetFlags()&!kIsServer);}
|
||||
bool IsServer() const { return (GetFlags()&kIsServer)?true:false;}
|
||||
|
||||
hsBool AddSubscription(int chan);
|
||||
hsBool RemoveSubscription(int chan); // return true on success
|
||||
int FindSubscription(int chan); // return index into subscription array or -1
|
||||
|
||||
int GetNumSubscriptions() { return fSubscriptions.size(); }
|
||||
int GetSubscription(int i) { return fSubscriptions[i]; }
|
||||
|
||||
void CopySubscriptions(std::vector<int>* channels) { *channels = fSubscriptions; }
|
||||
|
||||
void SetTransportFlags(UInt32 f) { fTransportFlags=f; }
|
||||
UInt32 GetTransportFlags() const { return fTransportFlags; }
|
||||
|
||||
bool IsPeerToPeer() const { return hsCheckBits(fFlags, kRequestP2P); }
|
||||
std::string AsStdString() const;
|
||||
bool IsEqualTo(const plNetMember * other) const
|
||||
{
|
||||
const plNetTransportMember * o = plNetTransportMember::ConvertNoRef(other);
|
||||
if (!o) return false;
|
||||
return o->fPlayerID==fPlayerID;
|
||||
}
|
||||
|
||||
bool IsCCR() const { return (fCCRLevel>0); }
|
||||
UInt8 GetCCRLevel() const { return fCCRLevel; }
|
||||
void SetCCRLevel(UInt8 cl) { fCCRLevel=cl; }
|
||||
};
|
||||
|
||||
#endif // plNetTransportMember_h
|
||||
/*==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/>.
|
||||
|
||||
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==*/
|
||||
#ifndef plNetTransportMember_h
|
||||
#define plNetTransportMember_h
|
||||
|
||||
#include "hsConfig.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include "plNetCommon/plNetMember.h"
|
||||
#include "pnKeyedObject/plKey.h"
|
||||
|
||||
//
|
||||
// This represents a participant in the game, ie. another
|
||||
// remote user.
|
||||
// It is a basic net member with a list of channels that it subscribes to.
|
||||
//
|
||||
class plKey;
|
||||
|
||||
class plNetTransportMember : public plNetMember
|
||||
{
|
||||
public:
|
||||
enum TransportFlags
|
||||
{
|
||||
kSendingVoice = 1<<0,
|
||||
kSendingActions = 1<<1,
|
||||
};
|
||||
protected:
|
||||
plKey fAvatarKey;
|
||||
std::string fPlayerName;
|
||||
UInt32 fPlayerID;
|
||||
std::vector<int> fSubscriptions; // list of channelGrp subscriptions
|
||||
UInt32 fTransportFlags;
|
||||
float fDistSq; // from local player, temp
|
||||
UInt8 fCCRLevel;
|
||||
public:
|
||||
CLASSNAME_REGISTER( plNetTransportMember);
|
||||
GETINTERFACE_ANY( plNetTransportMember, plNetMember);
|
||||
|
||||
plNetTransportMember() : fAvatarKey(nil),
|
||||
fTransportFlags(0),fPlayerID(0),fDistSq(-1),fCCRLevel(0) {}
|
||||
plNetTransportMember(plNetApp* na) : plNetMember(na),
|
||||
fAvatarKey(nil),fTransportFlags(0),fPlayerID(0),fDistSq(-1),fCCRLevel(0) {}
|
||||
~plNetTransportMember() {}
|
||||
|
||||
void SetDistSq(float s) { fDistSq=s; }
|
||||
float GetDistSq() const { return fDistSq; }
|
||||
|
||||
plKey GetAvatarKey() { return fAvatarKey; }
|
||||
void SetAvatarKey(plKey k)
|
||||
{
|
||||
fAvatarKey=k;
|
||||
}
|
||||
void SetPlayerName(const char * value) { fPlayerName=value;}
|
||||
const char * GetPlayerName() const { return fPlayerName.c_str();}
|
||||
void SetPlayerID(UInt32 value) { fPlayerID=value;}
|
||||
UInt32 GetPlayerID() const { return fPlayerID;}
|
||||
void SetIsServer(bool value) { (value)?SetFlags(GetFlags()|kIsServer):SetFlags(GetFlags()&!kIsServer);}
|
||||
bool IsServer() const { return (GetFlags()&kIsServer)?true:false;}
|
||||
|
||||
hsBool AddSubscription(int chan);
|
||||
hsBool RemoveSubscription(int chan); // return true on success
|
||||
int FindSubscription(int chan); // return index into subscription array or -1
|
||||
|
||||
int GetNumSubscriptions() { return fSubscriptions.size(); }
|
||||
int GetSubscription(int i) { return fSubscriptions[i]; }
|
||||
|
||||
void CopySubscriptions(std::vector<int>* channels) { *channels = fSubscriptions; }
|
||||
|
||||
void SetTransportFlags(UInt32 f) { fTransportFlags=f; }
|
||||
UInt32 GetTransportFlags() const { return fTransportFlags; }
|
||||
|
||||
bool IsPeerToPeer() const { return hsCheckBits(fFlags, kRequestP2P); }
|
||||
std::string AsStdString() const;
|
||||
bool IsEqualTo(const plNetMember * other) const
|
||||
{
|
||||
const plNetTransportMember * o = plNetTransportMember::ConvertNoRef(other);
|
||||
if (!o) return false;
|
||||
return o->fPlayerID==fPlayerID;
|
||||
}
|
||||
|
||||
bool IsCCR() const { return (fCCRLevel>0); }
|
||||
UInt8 GetCCRLevel() const { return fCCRLevel; }
|
||||
void SetCCRLevel(UInt8 cl) { fCCRLevel=cl; }
|
||||
};
|
||||
|
||||
#endif // plNetTransportMember_h
|
||||
|
Reference in New Issue
Block a user