Browse Source

Avoid spr loading freeze when logging

Eduardo Bart 8 years ago
parent
commit
90312965bc

+ 6
- 0
modules/client/client.lua View File

@@ -37,6 +37,11 @@ function Client.init()
37 37
   g_window.setIcon(resolvepath('clienticon.png'))
38 38
   g_keyboard.bindKeyDown('Ctrl+Shift+R', Client.reloadScripts)
39 39
 
40
+  -- load default client version
41
+  local clientVersion = g_settings.getInteger('client-version')
42
+  if not clientVersion or clientVersion == 0 then clientVersion = 960 end
43
+  g_game.setClientVersion(clientVersion)
44
+
40 45
   connect(g_app, { onRun =
41 46
     function()
42 47
       -- Play startup music (The Silver Tree, by Mattias Westlund)
@@ -53,5 +58,6 @@ function Client.terminate()
53 58
   g_settings.set('window-size', g_window.getUnmaximizedSize())
54 59
   g_settings.set('window-pos', g_window.getUnmaximizedPos())
55 60
   g_settings.set('window-maximized', g_window.isMaximized())
61
+  g_settings.set('client-version', g_game.getClientVersion())
56 62
   Client = nil
57 63
 end

+ 5
- 9
modules/client_entergame/entergame.lua View File

@@ -67,11 +67,9 @@ function EnterGame.init()
67 67
   local host = g_settings.get('host')
68 68
   local port = g_settings.get('port')
69 69
   local autologin = g_settings.getBoolean('autologin')
70
-  local protocol = g_settings.getInteger('protocol', 860)
70
+  local clientVersion = g_game.getClientVersion()
71 71
 
72
-  if not protocol or protocol == 0 then
73
-    protocol = 860
74
-  end
72
+  if not clientVersion or clientVersion == 0 then clientVersion = 960 end
75 73
 
76 74
   if port == nil or port == 0 then port = 7171 end
77 75
 
@@ -87,7 +85,7 @@ function EnterGame.init()
87 85
   for _i, proto in pairs(g_game.getSupportedProtocols()) do
88 86
     protocolBox:addOption(proto)
89 87
   end
90
-  protocolBox:setCurrentOption(protocol)
88
+  protocolBox:setCurrentOption(clientVersion)
91 89
 
92 90
   -- only open entergame when app starts
93 91
   if not g_app.isRunning() then
@@ -142,7 +140,7 @@ function EnterGame.doLogin()
142 140
   G.password = enterGame:getChildById('accountPasswordTextEdit'):getText()
143 141
   G.host = enterGame:getChildById('serverHostTextEdit'):getText()
144 142
   G.port = tonumber(enterGame:getChildById('serverPortTextEdit'):getText())
145
-  local protocol = tonumber(protocolBox:getText())
143
+  local clientVersion = tonumber(protocolBox:getText())
146 144
   EnterGame.hide()
147 145
 
148 146
   if g_game.isOnline() then
@@ -153,7 +151,6 @@ function EnterGame.doLogin()
153 151
 
154 152
   g_settings.set('host', G.host)
155 153
   g_settings.set('port', G.port)
156
-  g_settings.set('protocol', protocol)
157 154
 
158 155
   local protocolLogin = ProtocolLogin.create()
159 156
   protocolLogin.onError = onError
@@ -168,8 +165,7 @@ function EnterGame.doLogin()
168 165
                                 end })
169 166
 
170 167
   g_game.chooseRsa(G.host)
171
-  g_game.setClientVersion(protocol)
172
-  modules.game_tibiafiles.load()
168
+  g_game.setClientVersion(clientVersion)
173 169
   protocolLogin:login(G.host, G.port, G.account, G.password)
174 170
 end
175 171
 

+ 2
- 2
modules/corelib/settings.lua View File

@@ -51,12 +51,12 @@ function g_settings.getString(key, default)
51 51
 end
52 52
 
53 53
 function g_settings.getInteger(key, default)
54
-  local v = tonumber(g_settings.get(key, default)) or 1
54
+  local v = tonumber(g_settings.get(key, default)) or 0
55 55
   return v
56 56
 end
57 57
 
58 58
 function g_settings.getNumber(key, default)
59
-  local v = tonumber(g_settings.get(key, default)) or 1
59
+  local v = tonumber(g_settings.get(key, default)) or 0
60 60
   return v
61 61
 end
62 62
 

+ 5
- 3
modules/game_tibiafiles/tibiafiles.lua View File

@@ -1,7 +1,9 @@
1 1
 function init()
2
-  if g_game.getClientVersion() ~= 0 then
3
-    load()
4
-  end
2
+  connect(g_game, { onClientVersionChange = load })
3
+end
4
+
5
+function terminate()
6
+  disconnect(g_game, { onClientVersionChange = load })
5 7
 end
6 8
 
7 9
 function load()

+ 1
- 0
modules/game_tibiafiles/tibiafiles.otmod View File

@@ -5,3 +5,4 @@ Module
5 5
   sandboxed: true
6 6
   scripts: [tibiafiles.lua]
7 7
   @onLoad: init()
8
+  @onUnload: terminate()

+ 6
- 3
src/otclient/game.cpp View File

@@ -39,7 +39,7 @@ Game g_game;
39 39
 Game::Game()
40 40
 {
41 41
     resetGameStates();
42
-    m_protocolVersion = 0;
42
+    m_clientVersion = 0;
43 43
 }
44 44
 
45 45
 void Game::terminate()
@@ -430,7 +430,7 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
430 430
     if(m_protocolGame || isOnline())
431 431
         stdext::throw_exception("Unable to login into a world while already online or logging.");
432 432
 
433
-    if(m_protocolVersion == 0)
433
+    if(m_clientVersion == 0)
434 434
         stdext::throw_exception("Must set a valid game protocol version before logging.");
435 435
 
436 436
     // reset the new game state
@@ -1123,6 +1123,9 @@ bool Game::canPerformGameAction()
1123 1123
 
1124 1124
 void Game::setClientVersion(int version)
1125 1125
 {
1126
+    if(m_clientVersion == version)
1127
+        return;
1128
+
1126 1129
     if(isOnline())
1127 1130
         stdext::throw_exception("Unable to change client version while online");
1128 1131
 
@@ -1175,7 +1178,7 @@ void Game::setClientVersion(int version)
1175 1178
         enableFeature(Otc::GameOfflineTrainingTime);
1176 1179
     }
1177 1180
 
1178
-    m_protocolVersion = version;
1181
+    m_clientVersion = version;
1179 1182
 
1180 1183
     Proto::buildMessageModesMap(version);
1181 1184
 

+ 2
- 2
src/otclient/game.h View File

@@ -242,7 +242,7 @@ public:
242 242
     bool getFeature(Otc::GameFeature feature) { return m_features.test(feature); }
243 243
 
244 244
     void setClientVersion(int version);
245
-    int getClientVersion() { return m_protocolVersion; }
245
+    int getClientVersion() { return m_clientVersion; }
246 246
 
247 247
     bool canPerformGameAction();
248 248
     bool checkBotProtection();
@@ -297,7 +297,7 @@ private:
297 297
     std::string m_characterName;
298 298
     std::string m_worldName;
299 299
     std::bitset<Otc::LastGameFeature> m_features;
300
-    int m_protocolVersion;
300
+    int m_clientVersion;
301 301
 };
302 302
 
303 303
 extern Game g_game;

Loading…
Cancel
Save