DDNet serverlist added

This commit is contained in:
east 2014-09-13 16:36:25 +02:00
parent 3ea1bab617
commit e732008157
9 changed files with 205 additions and 4 deletions

View file

@ -1154,6 +1154,15 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
Packet.m_Flags = NETSENDFLAG_CONNLESS;
m_NetClient[g_Config.m_ClDummy].Send(&Packet);
// request ddnet server list
mem_zero(&Packet, sizeof(Packet));
Packet.m_ClientID = -1;
Packet.m_Address = m_VersionInfo.m_VersionServeraddr.m_Addr;
Packet.m_pData = VERSIONSRV_GETDDNETLIST;
Packet.m_DataSize = sizeof(VERSIONSRV_GETDDNETLIST);
Packet.m_Flags = NETSENDFLAG_CONNLESS;
m_NetClient[g_Config.m_ClDummy].Send(&Packet);
// request the map version list now
mem_zero(&Packet, sizeof(Packet));
Packet.m_ClientID = -1;
@ -1181,6 +1190,21 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
}
}
// ddnet server list
if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_DDNETLIST) + DDNETLIST_SIZE) &&
mem_comp(pPacket->m_pData, VERSIONSRV_DDNETLIST, sizeof(VERSIONSRV_DDNETLIST)) == 0)
{
char aBuf[DDNETLIST_SIZE];
mem_copy(aBuf, (char*)pPacket->m_pData + sizeof(VERSIONSRV_DDNETLIST), DDNETLIST_SIZE);
IOHANDLE File = m_pStorage->OpenFile("ddnet-servers.txt", IOFLAG_WRITE, IStorage::TYPE_SAVE);
if (File)
{
io_write(File, aBuf, sizeof(aBuf));
io_close(File);
}
}
// map version list
if(pPacket->m_DataSize >= (int)sizeof(VERSIONSRV_MAPLIST) &&
mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0)

View file

@ -9,11 +9,13 @@
#include <engine/shared/memheap.h>
#include <engine/shared/network.h>
#include <engine/shared/protocol.h>
#include <engine/shared/linereader.h>
#include <engine/config.h>
#include <engine/console.h>
#include <engine/friends.h>
#include <engine/masterserver.h>
#include <engine/storage.h>
#include <mastersrv/mastersrv.h>
@ -35,6 +37,7 @@ CServerBrowser::CServerBrowser()
m_pSortedServerlist = 0;
m_NumFavoriteServers = 0;
m_NumDDNetServers = 0;
mem_zero(m_aServerlistIp, sizeof(m_aServerlistIp));
@ -238,6 +241,29 @@ void CServerBrowser::Filter()
}
}
// check for ddnet country filters
if(m_ServerlistType == TYPE_DDNET)
{
#define ISVALID(expr, conf) (str_find_nocase(m_ppServerlist[i]->m_Info.m_aName, expr) && conf)
if(ISVALID("DDNET GER", g_Config.m_BrFilterGer) ||
ISVALID("DDNET FRA", g_Config.m_BrFilterFra) ||
ISVALID("DDNET USA", g_Config.m_BrFilterUsa) ||
ISVALID("DDNET RUS", g_Config.m_BrFilterRus) ||
ISVALID("DDNET CHILE", g_Config.m_BrFilterChile) ||
ISVALID("DDNET CHN", g_Config.m_BrFilterChn) ||
ISVALID("DDNET PERSIAN", g_Config.m_BrFilterPersia) ||
ISVALID("DDNET SOUTH AFRICA", g_Config.m_BrFilterSouthAfrica))
{
// valid
}
else
Filtered = 1;
#undef ISVALID
}
if(Filtered == 0)
{
// check for friend
@ -445,6 +471,17 @@ void CServerBrowser::Set(const NETADDR &Addr, int Type, int Token, const CServer
QueueRequest(pEntry);
}
}
else if(Type == IServerBrowser::SET_DDNET_ADD)
{
if(m_ServerlistType != IServerBrowser::TYPE_DDNET)
return;
if(!Find(Addr))
{
pEntry = Add(Addr);
QueueRequest(pEntry);
}
}
else if(Type == IServerBrowser::SET_TOKEN)
{
if(Token != m_CurrentToken)
@ -521,6 +558,12 @@ void CServerBrowser::Refresh(int Type)
for(int i = 0; i < m_NumFavoriteServers; i++)
Set(m_aFavoriteServers[i], IServerBrowser::SET_FAV_ADD, -1, 0);
}
else if(Type == IServerBrowser::TYPE_DDNET)
{
LoadDDNet();
for(int i = 0; i < m_NumDDNetServers; i++)
Set(m_aDDNetServers[i], IServerBrowser::SET_DDNET_ADD, -1, 0);
}
}
void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) const
@ -826,6 +869,37 @@ void CServerBrowser::RemoveFavorite(const NETADDR &Addr)
}
}
void CServerBrowser::LoadDDNet()
{
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
IOHANDLE File = pStorage->OpenFile("ddnet-servers.txt", IOFLAG_READ, IStorage::TYPE_ALL);
// reset ddnet server list
m_NumDDNetServers = 0;
if(File)
{
char *pLine;
CLineReader lr;
lr.Init(File);
for(int i = 0; i < MAX_DDNET && (pLine = lr.Get()); i++)
{
NETADDR Addr;
if(net_addr_from_str(&Addr, pLine) == 0)
{
m_aDDNetServers[i] = Addr;
m_NumDDNetServers++;
}
else
break; // failed to parse ip:port
}
io_close(File);
}
}
bool CServerBrowser::IsRefreshing() const
{
return m_pFirstReqServer != 0;

View file

@ -25,7 +25,8 @@ public:
enum
{
MAX_FAVORITES=2048
MAX_FAVORITES=2048,
MAX_DDNET=2048
};
CServerBrowser();
@ -45,6 +46,8 @@ public:
void AddFavorite(const NETADDR &Addr);
void RemoveFavorite(const NETADDR &Addr);
void LoadDDNet();
//
void Update(bool ForceResort);
void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo);
@ -70,6 +73,9 @@ private:
NETADDR m_aFavoriteServers[MAX_FAVORITES];
int m_NumFavoriteServers;
NETADDR m_aDDNetServers[MAX_DDNET];
int m_NumDDNetServers;
CServerEntry *m_aServerlistIp[256]; // ip hash list
CServerEntry *m_pFirstReqServer; // request list

View file

@ -77,9 +77,11 @@ public:
TYPE_INTERNET = 0,
TYPE_LAN = 1,
TYPE_FAVORITES = 2,
TYPE_DDNET = 3,
SET_MASTER_ADD=1,
SET_FAV_ADD,
SET_DDNET_ADD,
SET_TOKEN
};

View file

@ -50,6 +50,16 @@ MACRO_CONFIG_INT(BrFilterPure, br_filter_pure, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLI
MACRO_CONFIG_INT(BrFilterPureMap, br_filter_pure_map, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard maps in browser")
MACRO_CONFIG_INT(BrFilterCompatversion, br_filter_compatversion, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser")
// DDNet filters
MACRO_CONFIG_INT(BrFilterGer, br_filter_ger, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterFra, br_filter_fra, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterUsa, br_filter_usa, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterRus, br_filter_rus, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterChn, br_filter_chn, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterChile, br_filter_chile, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterSouthAfrica, br_filter_southafrica, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrFilterPersia, br_filter_persia, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrSort, br_sort, 1, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrSortOrder, br_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(BrMaxRequests, br_max_requests, 25, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser")

View file

@ -610,13 +610,23 @@ int CMenus::RenderMenubar(CUIRect r)
//box.VSplitLeft(4.0f, 0, &box);
Box.VSplitLeft(110.0f, &Button, &Box);
static int s_FavoritesButton=0;
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage==PAGE_FAVORITES, &Button, CUI::CORNER_TR))
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage==PAGE_FAVORITES, &Button, 0))
{
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
NewPage = PAGE_FAVORITES;
m_DoubleClickIndex = -1;
}
//box.VSplitLeft(4.0f, 0, &box);
Box.VSplitLeft(110.0f, &Button, &Box);
static int s_DDNetButton=0;
if(DoButton_MenuTab(&s_DDNetButton, Localize("DDNet"), m_ActivePage==PAGE_DDNET, &Button, CUI::CORNER_TR))
{
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
NewPage = PAGE_DDNET;
m_DoubleClickIndex = -1;
}
Box.VSplitLeft(10.0f, 0, &Box);
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_DemosButton=0;
@ -871,6 +881,8 @@ int CMenus::Render()
ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
else if(g_Config.m_UiPage == PAGE_FAVORITES)
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
else if(g_Config.m_UiPage == PAGE_DDNET)
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
m_pClient->m_pSounds->Enqueue(CSounds::CHN_MUSIC, SOUND_MENU);
s_First = false;
m_DoubleClickIndex = -1;
@ -951,6 +963,8 @@ int CMenus::Render()
RenderDemoList(MainView);
else if(g_Config.m_UiPage == PAGE_FAVORITES)
RenderServerbrowser(MainView);
else if(g_Config.m_UiPage == PAGE_DDNET)
RenderServerbrowser(MainView);
else if(g_Config.m_UiPage == PAGE_SETTINGS)
RenderSettings(MainView);
}

View file

@ -228,6 +228,7 @@ class CMenus : public CComponent
void RenderServerbrowserServerList(CUIRect View);
void RenderServerbrowserServerDetail(CUIRect View);
void RenderServerbrowserFilters(CUIRect View);
void RenderServerbrowserFiltersDDNet(CUIRect View);
void RenderServerbrowserFriends(CUIRect View);
void RenderServerbrowser(CUIRect MainView);
static void ConchainFriendlistUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
@ -277,6 +278,7 @@ public:
PAGE_INTERNET,
PAGE_LAN,
PAGE_FAVORITES,
PAGE_DDNET,
PAGE_DEMOS,
PAGE_SETTINGS,
PAGE_SYSTEM,

View file

@ -567,6 +567,64 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
UI()->DoLabelScaled(&Status, aBuf, 14.0f, -1);
}
void CMenus::RenderServerbrowserFiltersDDNet(CUIRect View)
{
Client()->ServerBrowserUpdate();
CUIRect ServerFilter = View, FilterHeader;
const float FontSize = 12.0f;
ServerFilter.HSplitBottom(42.5f, &ServerFilter, 0);
// server filter
ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter);
RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
UI()->DoLabelScaled(&FilterHeader, Localize("Server filter"), FontSize+2.0f, 0);
CUIRect Button;
ServerFilter.VSplitLeft(5.0f, 0, &ServerFilter);
ServerFilter.Margin(3.0f, &ServerFilter);
ServerFilter.VMargin(5.0f, &ServerFilter);
// countries
ServerFilter.HSplitTop(19.0f, &Button, &ServerFilter);
UI()->DoLabelScaled(&Button, Localize("Countries:"), FontSize, -1);
Button.VSplitRight(60.0f, 0, &Button);
ServerFilter.HSplitTop(3.0f, 0, &ServerFilter);
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterGer, Localize("Germany"), g_Config.m_BrFilterGer, &Button))
g_Config.m_BrFilterGer ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterFra, Localize("France"), g_Config.m_BrFilterFra, &Button))
g_Config.m_BrFilterFra ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterUsa, Localize("USA"), g_Config.m_BrFilterUsa, &Button))
g_Config.m_BrFilterUsa ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterChn, Localize("China"), g_Config.m_BrFilterChn, &Button))
g_Config.m_BrFilterChn ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterRus, Localize("Russia"), g_Config.m_BrFilterRus, &Button))
g_Config.m_BrFilterRus ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterSouthAfrica, Localize("South Africa"), g_Config.m_BrFilterSouthAfrica, &Button))
g_Config.m_BrFilterSouthAfrica ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterChile, Localize("Chile"), g_Config.m_BrFilterChile, &Button))
g_Config.m_BrFilterChile ^= 1;
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if (DoButton_CheckBox(&g_Config.m_BrFilterPersia, Localize("Persia"), g_Config.m_BrFilterPersia, &Button))
g_Config.m_BrFilterPersia ^= 1;
}
void CMenus::RenderServerbrowserFilters(CUIRect View)
{
CUIRect ServerFilter = View, FilterHeader;
@ -1108,7 +1166,12 @@ void CMenus::RenderServerbrowser(CUIRect MainView)
if(ToolboxPage == 0)
RenderServerbrowserFilters(ToolBox);
{
if (m_ActivePage == PAGE_DDNET)
RenderServerbrowserFiltersDDNet(ToolBox);
else
RenderServerbrowserFilters(ToolBox);
}
else if(ToolboxPage == 1)
RenderServerbrowserServerDetail(ToolBox);
else if(ToolboxPage == 2)
@ -1149,6 +1212,8 @@ void CMenus::RenderServerbrowser(CUIRect MainView)
ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
else if(g_Config.m_UiPage == PAGE_FAVORITES)
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
else if(g_Config.m_UiPage == PAGE_DDNET)
ServerBrowser()->Refresh(IServerBrowser::TYPE_DDNET);
m_DoubleClickIndex = -1;
}
@ -1186,6 +1251,6 @@ void CMenus::ConchainFriendlistUpdate(IConsole::IResult *pResult, void *pUserDat
void CMenus::ConchainServerbrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
pfnCallback(pResult, pCallbackUserData);
if(pResult->NumArguments() && g_Config.m_UiPage == PAGE_FAVORITES && ((CMenus *)pUserData)->Client()->State() == IClient::STATE_OFFLINE)
if(pResult->NumArguments() && (g_Config.m_UiPage == PAGE_FAVORITES || g_Config.m_UiPage == PAGE_DDNET) && ((CMenus *)pUserData)->Client()->State() == IClient::STATE_OFFLINE)
((CMenus *)pUserData)->ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
}

View file

@ -4,6 +4,7 @@
#define VERSIONSRV_VERSIONSRV_H
static const int VERSIONSRV_PORT = 8302;
static const int NEWS_SIZE = 1380;
static const int DDNETLIST_SIZE = 1380;
struct CMapVersion
{
@ -20,4 +21,7 @@ static const unsigned char VERSIONSRV_MAPLIST[] = {255, 255, 255, 255, 'v', 'm',
static const unsigned char VERSIONSRV_GETNEWS[] = {255, 255, 255, 255, 'n', 'e', 'w', 'g'};
static const unsigned char VERSIONSRV_NEWS[] = {255, 255, 255, 255, 'n', 'e', 'w', 's'};
static const unsigned char VERSIONSRV_GETDDNETLIST[] = {255, 255, 255, 255, 'e', 'a', 's', 't'};
static const unsigned char VERSIONSRV_DDNETLIST[] = {255, 255, 255, 255, 't', 's', 'a', 'e'};
#endif