]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client.cpp
Add clientside translations.
[dragonfireclient.git] / src / client.cpp
index 402418ea2a9c129d3ee07bfa66864ed56b859e7a..658b10393d3ade8eb00eb088daa02abc1c6a83c7 100644 (file)
@@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <cmath>
 #include <IFileSystem.h>
+#include "client.h"
+#include "network/clientopcodes.h"
+#include "network/connection.h"
+#include "network/networkpacket.h"
 #include "threading/mutex_auto_lock.h"
 #include "client/renderingengine.h"
 #include "util/auth.h"
@@ -30,14 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/serialize.h"
 #include "util/string.h"
 #include "util/srp.h"
-#include "client.h"
-#include "network/clientopcodes.h"
 #include "filesys.h"
 #include "mapblock_mesh.h"
 #include "mapblock.h"
 #include "minimap.h"
 #include "mods.h"
 #include "profiler.h"
+#include "shader.h"
 #include "gettext.h"
 #include "clientmap.h"
 #include "clientmedia.h"
@@ -48,6 +51,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "script/scripting_client.h"
 #include "game.h"
 #include "chatmessage.h"
+#include "translation.h"
 
 extern gui::IGUIEnvironment* guienv;
 
@@ -81,7 +85,7 @@ Client::Client(
                tsrc, this
        ),
        m_particle_manager(&m_env),
-       m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
+       m_con(new con::Connection(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this)),
        m_address_name(address_name),
        m_server_ser_ver(SER_FMT_VER_INVALID),
        m_last_chat_message_sent(time(NULL)),
@@ -217,7 +221,7 @@ bool Client::isShutdown()
 Client::~Client()
 {
        m_shutdown = true;
-       m_con.Disconnect();
+       m_con->Disconnect();
 
        m_mesh_update_thread.stop();
        m_mesh_update_thread.wait();
@@ -251,8 +255,8 @@ void Client::connect(Address address, bool is_local_server)
 
        initLocalMapSaving(address, m_address_name, is_local_server);
 
-       m_con.SetTimeoutMs(0);
-       m_con.Connect(address);
+       m_con->SetTimeoutMs(0);
+       m_con->Connect(address);
 }
 
 void Client::step(float dtime)
@@ -681,8 +685,19 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
                return true;
        }
 
-       errorstream<<"Client: Don't know how to load file \""
-                       <<filename<<"\""<<std::endl;
+       const char *translate_ext[] = {
+               ".tr", NULL
+       };
+       name = removeStringEnd(filename, translate_ext);
+       if (!name.empty()) {
+               verbosestream << "Client: Loading translation: "
+                               << "\"" << filename << "\"" << std::endl;
+               g_translations->loadTranslation(data);
+               return true;
+       }
+
+       errorstream << "Client: Don't know how to load file \""
+               << filename << "\"" << std::endl;
        return false;
 }
 
@@ -785,7 +800,7 @@ void Client::Receive()
 {
        DSTACK(FUNCTION_NAME);
        NetworkPacket pkt;
-       m_con.Receive(&pkt);
+       m_con->Receive(&pkt);
        ProcessData(&pkt);
 }
 
@@ -852,7 +867,7 @@ void Client::ProcessData(NetworkPacket *pkt)
 
 void Client::Send(NetworkPacket* pkt)
 {
-       m_con.Send(PEER_ID_SERVER,
+       m_con->Send(PEER_ID_SERVER,
                serverCommandFactoryTable[pkt->getCommand()].channel,
                pkt,
                serverCommandFactoryTable[pkt->getCommand()].reliable);
@@ -1295,7 +1310,7 @@ void Client::sendPlayerPos()
        u16 our_peer_id;
        {
                //MutexAutoLock lock(m_con_mutex); //bulk comment-out
-               our_peer_id = m_con.GetPeerID();
+               our_peer_id = m_con->GetPeerID();
        }
 
        // Set peer id if not set already
@@ -1317,7 +1332,7 @@ void Client::sendPlayerItem(u16 item)
        if(myplayer == NULL)
                return;
 
-       u16 our_peer_id = m_con.GetPeerID();
+       u16 our_peer_id = m_con->GetPeerID();
 
        // Set peer id if not set already
        if(myplayer->peer_id == PEER_ID_INEXISTENT)
@@ -1656,6 +1671,16 @@ ClientEvent Client::getClientEvent()
        return event;
 }
 
+bool Client::connectedToServer()
+{
+       return m_con->Connected();
+}
+
+const Address Client::getServerAddress()
+{
+       return m_con->GetPeerAddress(PEER_ID_SERVER);
+}
+
 float Client::mediaReceiveProgress()
 {
        if (m_media_downloader)
@@ -1766,13 +1791,13 @@ void Client::afterContentReceived()
 
 float Client::getRTT()
 {
-       return m_con.getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
+       return m_con->getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
 }
 
 float Client::getCurRate()
 {
-       return (m_con.getLocalStat(con::CUR_INC_RATE) +
-                       m_con.getLocalStat(con::CUR_DL_RATE));
+       return (m_con->getLocalStat(con::CUR_INC_RATE) +
+                       m_con->getLocalStat(con::CUR_DL_RATE));
 }
 
 void Client::makeScreenshot()