summaryrefslogtreecommitdiff
path: root/src/clientiface.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-02-13 20:17:42 +0100
committersapier <Sapier at GMX dot net>2014-04-08 21:12:20 +0200
commit142e2d3b74ad886eed83b0fc9d6cfea100dae10a (patch)
tree869bd3599c590e062bc838013b83088280734a81 /src/clientiface.cpp
parent556bdc260a6938ddab8db22e2ebc4033ec3757eb (diff)
downloadminetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.tar.gz
minetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.tar.bz2
minetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.zip
Cleanup client init states by bumping protocol version
Don't use TOSERVER_RECEIVED_MEDIA but TOSERVER_CLIENT_READY as indicatio for client ready Handle clients with protocol version < 23 (almost) same way as before Make client tell server about it's version Add client state to not send bogus player position updates prior init complete Add access to statistics information (peer connction time,rtt,version) Fix clients standing stalled in world while preloading item visuals (new clients only) Add get_player_information to read client specific information from lua
Diffstat (limited to 'src/clientiface.cpp')
-rw-r--r--src/clientiface.cpp46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp
index 5394cd002..626e5da74 100644
--- a/src/clientiface.cpp
+++ b/src/clientiface.cpp
@@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <sstream>
+
#include "clientiface.h"
#include "player.h"
#include "settings.h"
@@ -397,10 +399,11 @@ void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
void RemoteClient::notifyEvent(ClientStateEvent event)
{
+ std::ostringstream myerror;
switch (m_state)
{
case Invalid:
- assert("State update for client in invalid state" != 0);
+ //intentionally do nothing
break;
case Created:
@@ -420,7 +423,8 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
/* GotInit2 SetDefinitionsSent SetMediaSent */
default:
- assert("Invalid client state transition!" == 0);
+ myerror << "Created: Invalid client state transition! " << event;
+ throw ClientStateError(myerror.str());
}
break;
@@ -446,7 +450,8 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
/* Init SetDefinitionsSent SetMediaSent */
default:
- assert("Invalid client state transition!" == 0);
+ myerror << "InitSent: Invalid client state transition! " << event;
+ throw ClientStateError(myerror.str());
}
break;
@@ -467,14 +472,15 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
/* Init GotInit2 SetMediaSent */
default:
- assert("Invalid client state transition!" == 0);
+ myerror << "InitDone: Invalid client state transition! " << event;
+ throw ClientStateError(myerror.str());
}
break;
case DefinitionsSent:
switch(event)
{
- case SetMediaSent:
+ case SetClientReady:
m_state = Active;
break;
@@ -488,7 +494,8 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
/* Init GotInit2 SetDefinitionsSent */
default:
- assert("Invalid client state transition!" == 0);
+ myerror << "DefinitionsSent: Invalid client state transition! " << event;
+ throw ClientStateError(myerror.str());
}
break;
@@ -505,7 +512,8 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
/* Init GotInit2 SetDefinitionsSent SetMediaSent SetDenied */
default:
- assert("Invalid client state transition!" == 0);
+ myerror << "Active: Invalid client state transition! " << event;
+ throw ClientStateError(myerror.str());
break;
}
break;
@@ -516,6 +524,11 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
}
}
+u32 RemoteClient::uptime()
+{
+ return getTime(PRECISION_SECONDS) - m_connection_time;
+}
+
ClientInterface::ClientInterface(con::Connection* con)
:
m_con(con),
@@ -749,7 +762,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
n->second->notifyEvent(event);
}
- if ((event == SetMediaSent) || (event == Disconnect) || (event == SetDenied))
+ if ((event == SetClientReady) || (event == Disconnect) || (event == SetDenied))
{
UpdatePlayerList();
}
@@ -763,9 +776,24 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
std::map<u16, RemoteClient*>::iterator n;
n = m_clients.find(peer_id);
- // No client to deliver event
+ // No client to get version
if (n == m_clients.end())
return 0;
return n->second->net_proto_version;
}
+
+void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full)
+{
+ JMutexAutoLock conlock(m_clients_mutex);
+
+ // Error check
+ std::map<u16, RemoteClient*>::iterator n;
+ n = m_clients.find(peer_id);
+
+ // No client to set versions
+ if (n == m_clients.end())
+ return;
+
+ n->second->setVersionInfo(major,minor,patch,full);
+}