From c4a578c85a29272f7a139eb7b9d12c7a46785d92 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 2 Apr 2011 19:00:11 +0000 Subject: [PATCH] support for creating server list message --- src/protocol.cpp | 90 +++++++++++++++++++++++++++++++++++++++++------- src/protocol.h | 2 ++ src/serverlist.h | 4 +-- src/util.h | 8 ++--- 4 files changed, 86 insertions(+), 18 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index 0bde0dc0..63273990 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -189,6 +189,18 @@ CONNECTION LESS MESSAGES is permanent online. +- PROTMESSID_CLM_SERVER_LIST: Server list message + + for each registered server append following data: + + +--------------------+--------------+--------------------------------+ + | 4 bytes IP address | 2 bytes port | PROTMESSID_CLM_REGISTER_SERVER | + +--------------------+--------------+--------------------------------+ + + - "PROTMESSID_CLM_REGISTER_SERVER" means that exactly the same message body + of the PROTMESSID_CLM_REGISTER_SERVER message is used + + ****************************************************************************** * * This program is free software; you can redistribute it and/or modify it under @@ -544,7 +556,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, break; case PROTMESSID_CLM_SERVER_LIST: -// TODO + bRet = EvaluateCLServerListMes ( InetAddr, vecData ); break; case PROTMESSID_CLM_REQ_SERVER_LIST: @@ -1126,20 +1138,15 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr, { int iPos = 0; // init position pointer - // current string sizes - const int iNameLen = ServerInfo.strName.size(); - const int iTopicLen = ServerInfo.strTopic.size(); - const int iCityLen = ServerInfo.strCity.size(); - // size of current message body const int iEntrLen = 2 /* country */ + 1 /* number of connected clients */ + 1 /* maximum number of connected clients */ + 1 /* is permanent flag */ + - 2 /* name string size */ + iNameLen + - 2 /* topic string size */ + iTopicLen + - 2 /* city string size */ + iCityLen; + 2 /* name string size */ + ServerInfo.strName.size() + + 2 /* topic string size */ + ServerInfo.strTopic.size() + + 2 /* city string size */ + ServerInfo.strCity.size(); // build data vector CVector vecData ( iEntrLen ); @@ -1245,16 +1252,75 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ) { - // TODO + const int iNumServers = vecServerInfo.Size(); + + // build data vector + CVector vecData ( 0 ); + int iPos = 0; // init position pointer + + for ( int i = 0; i < iNumServers; i++ ) + { + // size of current list entry + const int iCurListEntrLen = + 4 /* IP address */ + + 2 /* port number */ + + 2 /* country */ + + 1 /* number of connected clients */ + + 1 /* maximum number of connected clients */ + + 1 /* is permanent flag */ + + 2 /* name string size */ + vecServerInfo[i].strName.size() + + 2 /* topic string size */ + vecServerInfo[i].strTopic.size() + + 2 /* city string size */ + vecServerInfo[i].strCity.size(); + + // make space for new data + vecData.Enlarge ( iCurListEntrLen ); + + // IP address (4 bytes) + PutValOnStream ( vecData, iPos, static_cast ( + vecServerInfo[i].HostAddr.InetAddr.toIPv4Address() ), 4 ); + + // port number (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( vecServerInfo[i].HostAddr.iPort ), 2 ); + + // country (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( vecServerInfo[i].eCountry ), 2 ); + + // number of connected clients (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( vecServerInfo[i].iNumClients ), 1 ); + + // maximum number of connected clients (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( vecServerInfo[i].iMaxNumClients ), 1 ); + + // "is permanent" flag (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( vecServerInfo[i].bPermanentOnline ), 1 ); + + // name + PutStringOnStream ( vecData, iPos, vecServerInfo[i].strName ); + + // topic + PutStringOnStream ( vecData, iPos, vecServerInfo[i].strTopic ); + + // city + PutStringOnStream ( vecData, iPos, vecServerInfo[i].strCity ); + } + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_LIST, + vecData, + InetAddr ); } -/* bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ) { // TODO + + return false; // no error } -*/ /******************************************************************************\ diff --git a/src/protocol.h b/src/protocol.h index 2deb1aba..223b89cd 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -203,6 +203,8 @@ protected: bool EvaluateCLServerFullMes(); bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, const CVector& vecData ); + bool EvaluateCLServerListMes ( const CHostAddress& InetAddr, + const CVector& vecData ); int iOldRecID; int iOldRecCnt; diff --git a/src/serverlist.h b/src/serverlist.h index 11065dcb..9d17435e 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -83,7 +83,7 @@ public: 0, false ) { RegisterTime.start(); } - CServerListEntry ( const CHostAddress& NIAddr, + CServerListEntry ( const CHostAddress& NHAddr, const QString& NsName, const QString& NsTopic, const QLocale::Country& NeCountry, @@ -91,7 +91,7 @@ public: const int NiNumClients, const int NiMaxNumClients, const bool NbPermOnline) - : CServerInfo ( NIAddr, + : CServerInfo ( NHAddr, NsName, NsTopic, NeCountry, diff --git a/src/util.h b/src/util.h index d701953b..dcc99390 100755 --- a/src/util.h +++ b/src/util.h @@ -514,10 +514,10 @@ public: "", 0, 0, - false ), InetAddr ( CHostAddress() ) {} + false ), HostAddr ( CHostAddress() ) {} CServerInfo ( - const CHostAddress& NIAddr, + const CHostAddress& NHAddr, const QString& NsName, const QString& NsTopic, const QLocale::Country& NeCountry, @@ -531,11 +531,11 @@ public: NsCity, NiNumClients, NiMaxNumClients, - NbPermOnline ), InetAddr ( NIAddr ) {} + NbPermOnline ), HostAddr ( NHAddr ) {} public: // internet address of the server - CHostAddress InetAddr; + CHostAddress HostAddr; };