Skip to content

Commit

Permalink
Make NAT use MatchServer tunnelling rather than MatchAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
Asunaya committed Aug 5, 2016
1 parent 09c4515 commit e068fc1
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 169 deletions.
11 changes: 5 additions & 6 deletions CSCommon/Include/MMatchClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,11 @@ class MMatchClient : public MClient
virtual void SendCommand(MCommand* pCommand);
bool SendCommandToAgent(MCommand* pCommand);
void SendCommandByTunneling(MCommand* pCommand);
void SendCommandByMatchServerTunneling(MCommand* pCommand, const MUID& Receiver);
void SendCommandByMatchServerTunneling(MCommand* pCommand);
void ParseUDPPacket(char* pData,MPacketHeader* pPacketHeader,DWORD dwIP,unsigned int nPort);
public:
void SendCommandByUDP(MCommand* pCommand, char* szIP, int nPort);
/*
public :
void SendCommandByUDP(MCommand* pCommand, char* szIP, int nPort);
*/

public:
MMatchClient();
Expand All @@ -203,7 +200,6 @@ public :
bool GetBridgePeerFlag() { return m_bBridgePeerFlag; }
void SetBridgePeerFlag(bool bFlag) { m_bBridgePeerFlag = bFlag; }
void AddPeer(MMatchPeerInfo* pPeerInfo);
//bool DeletePeer(const char* szIP);
bool DeletePeer(const MUID uid);
MUID FindPeerUID(const DWORD dwIP, const int nPort);
MMatchPeerInfo* FindPeer(const MUID& uidChar);
Expand All @@ -213,7 +209,8 @@ public :
bool GetUDPTestProcess() { return m_bUDPTestProcess; }
void SetUDPTestProcess(bool bVal) { m_bUDPTestProcess = bVal; }
void UpdateUDPTestProcess();
void GetUDPTraffic(int* nSendTraffic, int* nRecvTraffic) { return m_SafeUDP.GetTraffic(nSendTraffic, nRecvTraffic); }
void GetUDPTraffic(int* nSendTraffic, int* nRecvTraffic)
{ return m_SafeUDP.GetTraffic(nSendTraffic, nRecvTraffic); }

void SetUDPPort(int nPort);
MUID GetServerUID() { return m_uidServer; }
Expand Down Expand Up @@ -262,6 +259,8 @@ public :
MMatchServerMode GetServerMode() { return m_nServerMode; }
const char* GetServerName() { return m_szServerName; }

protected:
virtual void OnStopUDPTest(const MUID& uid) = 0;
};

/*
Expand Down
2 changes: 1 addition & 1 deletion CSCommon/Source/MAsyncDBJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void MAsyncDBJob_InsertQuestGameLog::Run( void* pContext )
{
if( MSM_TEST == MGetServerConfig()->GetServerMode() )
{
MMatchDBMgr* pDBMgr = reinterpret_cast< MMatchDBMgr* >( pContext );
IDatabase* pDBMgr = static_cast< IDatabase* >( pContext );

int nQGLID;

Expand Down
94 changes: 35 additions & 59 deletions CSCommon/Source/MMatchClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,6 @@ void MMatchClient::OnAgentConnected(const MUID& uidAgentServer, const MUID& uidA
MPacketCrypterKey key;
MMakeSeedKey(&key, uidAgentServer, uidAlloc, 0);
m_AgentPacketCrypter.InitKey(&key);

// MCommand* pCmd = CreateCommand(MC_AGENT_PEER_BIND, GetAgentServerUID());
// pCmd->AddParameter(new MCmdParamUID(GetPlayerUID()));
// Post(pCmd);
}

int MMatchClient::OnResponseMatchLogin(const MUID& uidServer, int nResult, const char* szServerName,
Expand Down Expand Up @@ -530,47 +526,29 @@ void MMatchClient::CastStageBridgePeer(const MUID& uidChar, const MUID& uidStage
{
MCommand* pCmd = new MCommand(m_CommandManager.GetCommandDescByID(MC_MATCH_BRIDGEPEER), GetServerUID(), m_This);
pCmd->AddParameter(new MCommandParameterUID(uidChar));
pCmd->AddParameter(new MCommandParameterUInt(0)); // 수신측에서 IP로 치환됨
pCmd->AddParameter(new MCommandParameterUInt(0)); // 수신측에서 Port로 치환됨
pCmd->AddParameter(new MCommandParameterUInt(0)); // IP
pCmd->AddParameter(new MCommandParameterUInt(0)); // Port

MSafeUDP* pSafeUDP = GetSafeUDP();
SendCommandByUDP(pCmd, GetServerIP(), GetServerPeerPort());

delete pCmd;
}

void MMatchClient::OnUDPTest(const MUID& uidChar)
{
MMatchPeerInfo* pPeer = FindPeer(uidChar);
if (pPeer) {

#ifdef _DEBUG
if ( //(strcmp("발렌타인", pPeer->CharInfo.szName)==0) ||
(strcmp("버드", pPeer->CharInfo.szName)==0) ||
(strcmp("dddd", pPeer->CharInfo.szName)==0) ||
(strcmp("라온하제5", pPeer->CharInfo.szName)==0) ||
(strcmp("라온하제6", pPeer->CharInfo.szName)==0) )
{
return;
}
#endif
auto* pPeer = FindPeer(uidChar);
if (!pPeer)
return;

MCommand* pCmd = CreateCommand(MC_PEER_UDPTEST_REPLY, uidChar);
SendCommandByUDP(pCmd, pPeer->szIP, pPeer->nPort);
delete pCmd;
}
auto* pCmd = CreateCommand(MC_PEER_UDPTEST_REPLY, uidChar);
SendCommandByUDP(pCmd, pPeer->szIP, pPeer->nPort);
delete pCmd;
}

void MMatchClient::OnUDPTestReply(const MUID& uidChar)
{
//// UDPTEST LOG ////////////////////////////////
#ifndef _PUBLISH
char szLog[64];
sprintf_safe(szLog, "[%d:%d] UDP_TEST_REPLY: from (%d:%d) \n",
DMLog("[%d:%d] UDP_TEST_REPLY: from (%d:%d) \n",
GetPlayerUID().High, GetPlayerUID().Low, uidChar.High, uidChar.Low);
mlog(szLog);
#endif
/////////////////////////////////////////////////

MMatchPeerInfo* pPeer = FindPeer(uidChar);
if (pPeer) {
Expand All @@ -582,17 +560,21 @@ mlog(szLog);
void MMatchClient::UpdateUDPTestProcess()
{
int nProcessCount = 0;
for (MMatchPeerInfoList::iterator i=m_Peers.begin(); i!=m_Peers.end(); i++) {
MMatchPeerInfo* pPeer = (*i).second;
for (auto i=m_Peers.begin(); i!=m_Peers.end(); i++) {
auto* pPeer = (*i).second;
if (pPeer->GetProcess()) {
pPeer->UseTestCount();
if (pPeer->GetTestCount() <= 0) {
pPeer->StopUDPTest();

OnStopUDPTest(pPeer->uidChar);

#ifdef MATCHAGENT
MCommand* pCmd = CreateCommand(MC_MATCH_REQUEST_PEER_RELAY, GetServerUID());
pCmd->AddParameter(new MCmdParamUID(GetPlayerUID()));
pCmd->AddParameter(new MCmdParamUID(pPeer->uidChar));
Post(pCmd);
#endif
} else {
nProcessCount++;
}
Expand Down Expand Up @@ -738,17 +720,26 @@ void MMatchClient::SendCommand(MCommand* pCommand)
if ((pPeerInfo->uidChar == MUID(0, 0)) ||
(pPeerInfo->uidChar != GetPlayerUID()))
{
#ifdef MATCHAGENT
if ((pPeerInfo->GetProcess() == false) &&
(pPeerInfo->GetUDPTestResult() == false))
nTunnelingCount++;
else
SendCommandByUDP(pCommand, pPeerInfo->szIP, pPeerInfo->nPort);
#else
if (!pPeerInfo->GetUDPTestResult())
SendCommandByMatchServerTunneling(pCommand, pPeerInfo->uidChar);
else
SendCommandByUDP(pCommand, pPeerInfo->szIP, pPeerInfo->nPort);
#endif
}
}

#ifdef MATCHAGENT
if (nTunnelingCount > 0) {
SendCommandByTunneling(pCommand);
}
#endif
}
else {
MMatchPeerInfo* pPeerInfo = FindPeer(pCommand->GetReceiverUID());
Expand Down Expand Up @@ -889,39 +880,24 @@ void MMatchClient::SendCommandByTunneling(MCommand* pCommand)
}
}

void MMatchClient::SendCommandByMatchServerTunneling(MCommand* pCommand)
void MMatchClient::SendCommandByMatchServerTunneling(MCommand * pCommand, const MUID & Receiver)
{
//DMLog("SendCommandByMatchServerTunneling %d %d\n", GetAllowTunneling(), GetBridgePeerFlag());

if (GetBridgePeerFlag() == false) {
MCommand* pCmd = CreateCommand(MC_AGENT_TUNNELING_TCP, GetAgentServerUID());
pCmd->AddParameter(new MCmdParamUID(GetPlayerUID()));
pCmd->AddParameter(new MCmdParamUID(pCommand->GetReceiverUID()));
MCommand* pCmd = CreateCommand(MC_MATCH_P2P_COMMAND, GetServerUID());
pCmd->AddParameter(new MCmdParamUID(Receiver));

// Create Param : Command Blob ////
if (!MakeTunnelingCommandBlob(pCmd, pCommand))
{
delete pCmd; pCmd = NULL; return;
}
///////////////////////////////////
SendCommandToAgent(pCmd);
delete pCmd; // PACKETQUEUE 만들때까지 delete 임시로 사용
if (!MakeSaneTunnelingCommandBlob(pCmd, pCommand))
{
delete pCmd; pCmd = NULL; return;
}
else {
MCommand* pCmd = CreateCommand(MC_MATCH_P2P_COMMAND, GetServerUID());
pCmd->AddParameter(new MCmdParamUID(pCommand->GetReceiverUID()));

if (!MakeSaneTunnelingCommandBlob(pCmd, pCommand))
{
delete pCmd; pCmd = NULL; return;
}

//MClient::SendCommand(pCmd);
Post(pCmd);
//delete pCmd;
Post(pCmd);
}

//DMLog("SendCommandByMatchServerTunnelling %d\n", pCommand->GetID());
}
void MMatchClient::SendCommandByMatchServerTunneling(MCommand* pCommand)
{
SendCommandByMatchServerTunneling(pCommand, pCommand->GetReceiverUID());
}

bool MMatchClient::UDPSocketRecvEvent(DWORD dwIP, WORD wRawPort, char* pPacket, DWORD dwSize)
Expand Down
26 changes: 5 additions & 21 deletions CSCommon/Source/MMatchServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,9 +1771,9 @@ MMatchObject* MMatchServer::GetPlayerByAID(unsigned long int nAID)
{
if (nAID == 0) return NULL;

for(MMatchObjectList::iterator i=m_Objects.begin(); i!=m_Objects.end(); i++)
for(auto i=m_Objects.begin(); i!=m_Objects.end(); i++)
{
MMatchObject* pObj = ((*i).second);
auto* pObj = i->second;
if (pObj->GetAccountInfo()->m_nAID == nAID)
return pObj;
}
Expand Down Expand Up @@ -1818,36 +1818,20 @@ void MMatchServer::Announce(MObject* pObj, char* pszMsg)

void MMatchServer::AnnounceErrorMsg(const MUID& CommUID, const int nErrorCode)
{
// 다음 서버 패치때 Announce대신 ErrorCode로 클라이언트에 메세지를 전송할 수 있도록 만들 예정
}

void MMatchServer::AnnounceErrorMsg(MObject* pObj, const int nErrorCode)
{

}




void MMatchServer::OnBridgePeer(const MUID& uidChar, DWORD dwIP, DWORD nPort)
{
MMatchObject* pObj = GetObject(uidChar);
if (pObj == NULL) return;
// 임시 Debug코드 ///////
#ifdef _DEBUG
if (strcmp(pObj->GetAccountName(), "라온하제4")==0)
return;
if (strcmp(pObj->GetAccountName(), "라온하제3")==0)
return;
#endif
/////////////////////////

/* if (pObj->GetBridgePeer() == false) {
char szMsg[128];
sprintf_safe(szMsg, "BridgePeer : Player[%d%d] Local(%s:%u) , Routed(%s:%u)",
uidChar.High, uidChar.Low, szLocalIP, nLocalPort, szIP, nPort);
LOG(LOG_DEBUG, szMsg);
}*/
auto* pObj = GetObject(uidChar);
if (!pObj)
return;

in_addr addr;
addr.s_addr = dwIP;
Expand Down
2 changes: 1 addition & 1 deletion CSCommon/Source/MMatchStageSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void MMatchStageSetting::SetDefault()
m_StageSetting.Netcode = NetcodeType::ServerBased;
m_StageSetting.ForceHPAP = true;
m_StageSetting.HP = 100;
m_StageSetting.AP = 100;
m_StageSetting.AP = 50;
m_StageSetting.NoFlip = true;
m_StageSetting.SwordsOnly = false;
}
Expand Down
2 changes: 1 addition & 1 deletion Gunz/ZConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ZConfiguration::ZConfiguration()
{
Init();

strcpy_safe( m_szServerIP, "0,0,0,0");
strcpy_safe( m_szServerIP, "127.0.0.1");
m_nServerPort = 6000;

strcpy_safe( m_szBAReportAddr, "www.battlearena.com");
Expand Down
Loading

0 comments on commit e068fc1

Please sign in to comment.