mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
64 players in server browse
This commit is contained in:
parent
d696c19e18
commit
52e83313c8
|
@ -43,6 +43,8 @@
|
|||
#include <mastersrv/mastersrv.h>
|
||||
#include <versionsrv/versionsrv.h>
|
||||
|
||||
#include <engine/client/serverbrowser.h>
|
||||
|
||||
#include "friends.h"
|
||||
#include "serverbrowser.h"
|
||||
#include "client.h"
|
||||
|
@ -1024,6 +1026,65 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
|||
m_ServerBrowser.Set(pPacket->m_Address, IServerBrowser::SET_TOKEN, Token, &Info);
|
||||
}
|
||||
}
|
||||
|
||||
// server info 64
|
||||
if(pPacket->m_DataSize >= (int)sizeof(SERVERBROWSE_INFO64) && mem_comp(pPacket->m_pData, SERVERBROWSE_INFO64, sizeof(SERVERBROWSE_INFO64)) == 0)
|
||||
{
|
||||
// we got ze info
|
||||
CUnpacker Up;
|
||||
CServerInfo NewInfo = {0};
|
||||
CServerBrowser::CServerEntry *pEntry = m_ServerBrowser.Find(pPacket->m_Address);
|
||||
CServerInfo &Info = NewInfo;
|
||||
|
||||
if (pEntry)
|
||||
Info = pEntry->m_Info;
|
||||
|
||||
Up.Reset((unsigned char*)pPacket->m_pData+sizeof(SERVERBROWSE_INFO64), pPacket->m_DataSize-sizeof(SERVERBROWSE_INFO64));
|
||||
int Token = str_toint(Up.GetString());
|
||||
str_copy(Info.m_aVersion, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aVersion));
|
||||
str_copy(Info.m_aName, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aName));
|
||||
str_copy(Info.m_aMap, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aMap));
|
||||
str_copy(Info.m_aGameType, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aGameType));
|
||||
Info.m_Flags = str_toint(Up.GetString());
|
||||
Info.m_NumPlayers = str_toint(Up.GetString());
|
||||
Info.m_MaxPlayers = str_toint(Up.GetString());
|
||||
Info.m_NumClients = str_toint(Up.GetString());
|
||||
Info.m_MaxClients = str_toint(Up.GetString());
|
||||
|
||||
// don't add invalid info to the server browser list
|
||||
if(Info.m_NumClients < 0 || Info.m_NumClients > MAX_CLIENTS || Info.m_MaxClients < 0 || Info.m_MaxClients > MAX_CLIENTS ||
|
||||
Info.m_NumPlayers < 0 || Info.m_NumPlayers > Info.m_NumClients || Info.m_MaxPlayers < 0 || Info.m_MaxPlayers > Info.m_MaxClients)
|
||||
return;
|
||||
|
||||
net_addr_str(&pPacket->m_Address, Info.m_aAddress, sizeof(Info.m_aAddress), true);
|
||||
|
||||
int Offset = Up.GetInt();
|
||||
|
||||
for(int i = Offset; i < Offset + 24 && i < MAX_CLIENTS; i++)
|
||||
{
|
||||
str_copy(Info.m_aClients[i].m_aName, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aClients[i].m_aName));
|
||||
str_copy(Info.m_aClients[i].m_aClan, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aClients[i].m_aClan));
|
||||
Info.m_aClients[i].m_Country = str_toint(Up.GetString());
|
||||
Info.m_aClients[i].m_Score = str_toint(Up.GetString());
|
||||
Info.m_aClients[i].m_Player = str_toint(Up.GetString()) != 0 ? true : false;
|
||||
}
|
||||
|
||||
if(!Up.Error())
|
||||
{
|
||||
// sort players
|
||||
qsort(Info.m_aClients, Info.m_NumClients, sizeof(*Info.m_aClients), PlayerScoreComp);
|
||||
|
||||
if(net_addr_comp(&m_ServerAddress, &pPacket->m_Address) == 0)
|
||||
{
|
||||
mem_copy(&m_CurrentServerInfo, &Info, sizeof(m_CurrentServerInfo));
|
||||
m_CurrentServerInfo.m_NetAddr = m_ServerAddress;
|
||||
m_CurrentServerInfoRequestTime = -1;
|
||||
}
|
||||
else
|
||||
//m_ServerBrowser.SetInfo(pEntry, Info);
|
||||
m_ServerBrowser.Set(pPacket->m_Address, IServerBrowser::SET_TOKEN, Token, &Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CClient::ProcessServerPacket(CNetChunk *pPacket)
|
||||
|
|
|
@ -548,9 +548,39 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons
|
|||
pEntry->m_RequestTime = time_get();
|
||||
}
|
||||
|
||||
void CServerBrowser::RequestImpl64(const NETADDR &Addr, CServerEntry *pEntry) const
|
||||
{
|
||||
unsigned char Buffer[sizeof(SERVERBROWSE_GETINFO64)+1];
|
||||
CNetChunk Packet;
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr), true);
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf),"requesting server info 64 from %s", aAddrStr);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client_srvbrowse", aBuf);
|
||||
}
|
||||
|
||||
mem_copy(Buffer, SERVERBROWSE_GETINFO64, sizeof(SERVERBROWSE_GETINFO64));
|
||||
Buffer[sizeof(SERVERBROWSE_GETINFO64)] = m_CurrentToken;
|
||||
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Address = Addr;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
Packet.m_DataSize = sizeof(Buffer);
|
||||
Packet.m_pData = Buffer;
|
||||
|
||||
m_pNetClient->Send(&Packet);
|
||||
|
||||
if(pEntry)
|
||||
pEntry->m_RequestTime = time_get();
|
||||
}
|
||||
|
||||
void CServerBrowser::Request(const NETADDR &Addr) const
|
||||
{
|
||||
RequestImpl(Addr, 0);
|
||||
RequestImpl64(Addr, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -621,7 +651,10 @@ void CServerBrowser::Update(bool ForceResort)
|
|||
break;
|
||||
|
||||
if(pEntry->m_RequestTime == 0)
|
||||
{
|
||||
RequestImpl(pEntry->m_Addr, pEntry);
|
||||
RequestImpl64(pEntry->m_Addr, pEntry);
|
||||
}
|
||||
|
||||
Count++;
|
||||
pEntry = pEntry->m_pNextReq;
|
||||
|
|
|
@ -51,6 +51,8 @@ public:
|
|||
|
||||
void SetBaseInfo(class CNetClient *pClient, const char *pNetVersion);
|
||||
|
||||
CServerEntry *Find(const NETADDR &Addr);
|
||||
|
||||
private:
|
||||
CNetClient *m_pNetClient;
|
||||
IMasterServer *m_pMasterServer;
|
||||
|
@ -101,13 +103,13 @@ private:
|
|||
void Sort();
|
||||
int SortHash() const;
|
||||
|
||||
CServerEntry *Find(const NETADDR &Addr);
|
||||
CServerEntry *Add(const NETADDR &Addr);
|
||||
|
||||
void RemoveRequest(CServerEntry *pEntry);
|
||||
void QueueRequest(CServerEntry *pEntry);
|
||||
|
||||
void RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) const;
|
||||
void RequestImpl64(const NETADDR &Addr, CServerEntry *pEntry) const;
|
||||
|
||||
void SetInfo(CServerEntry *pEntry, const CServerInfo &Info);
|
||||
|
||||
|
|
|
@ -1250,7 +1250,7 @@ void CServer::SendServerInfo(const NETADDR *pAddr, int Token, bool Extended, int
|
|||
|
||||
for(i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(m_aClients[i].m_State != CClient::STATE_EMPTY)
|
||||
if(1 || (m_aClients[i].m_State != CClient::STATE_EMPTY))
|
||||
{
|
||||
if (Skip-- > 0)
|
||||
continue;
|
||||
|
|
|
@ -676,18 +676,24 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
|
|||
|
||||
// server scoreboard
|
||||
ServerScoreBoard.HSplitBottom(20.0f, &ServerScoreBoard, 0x0);
|
||||
ServerScoreBoard.HSplitTop(ms_ListheaderHeight, &ServerHeader, &ServerScoreBoard);
|
||||
RenderTools()->DrawUIRect(&ServerHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
|
||||
RenderTools()->DrawUIRect(&ServerScoreBoard, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
|
||||
UI()->DoLabelScaled(&ServerHeader, Localize("Scoreboard"), FontSize+2.0f, 0);
|
||||
|
||||
if(pSelectedServer)
|
||||
{
|
||||
ServerScoreBoard.Margin(3.0f, &ServerScoreBoard);
|
||||
static int s_VoteList = 0;
|
||||
static float s_ScrollValue = 0;
|
||||
UiDoListboxStart(&s_VoteList, &ServerScoreBoard, 26.0f, Localize("Scoreboard"), "", pSelectedServer->m_NumClients, 1, -1, s_ScrollValue);
|
||||
|
||||
m_CallvoteSelectedOption = UiDoListboxEnd(&s_ScrollValue, 0);
|
||||
|
||||
for (int i = 0; i < pSelectedServer->m_NumClients; i++)
|
||||
{
|
||||
CListboxItem Item = UiDoListboxNextItem(&pSelectedServer->m_aClients[i]);
|
||||
|
||||
if(!Item.m_Visible)
|
||||
continue;
|
||||
|
||||
CUIRect Name, Clan, Score, Flag;
|
||||
ServerScoreBoard.HSplitTop(25.0f, &Name, &ServerScoreBoard);
|
||||
Item.m_Rect.HSplitTop(25.0f, &Name, &Item.m_Rect);
|
||||
if(UI()->DoButtonLogic(&pSelectedServer->m_aClients[i], "", 0, &Name))
|
||||
{
|
||||
if(pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_PLAYER)
|
||||
|
|
Loading…
Reference in a new issue