Browse Source

Format name as a feature, do not connect if dont have dat/spr

Henrique Santiago 8 years ago
parent
commit
e244e1975d

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

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

+ 8
- 1
modules/client_entergame/entergame.lua View File

@@ -169,7 +169,14 @@ function EnterGame.doLogin()
169 169
 
170 170
   g_game.chooseRsa(G.host)
171 171
   g_game.setClientVersion(clientVersion)
172
-  protocolLogin:login(G.host, G.port, G.account, G.password)
172
+
173
+  if modules.game_tibiafiles.isLoaded() then
174
+    protocolLogin:login(G.host, G.port, G.account, G.password)
175
+  else
176
+    loadBox:destroy()
177
+    loadBox = nil
178
+    EnterGame.show()
179
+  end
173 180
 end
174 181
 
175 182
 function EnterGame.displayMotd()

+ 14
- 2
modules/game_tibiafiles/tibiafiles.lua View File

@@ -1,4 +1,5 @@
1 1
 filename = 'Tibia'
2
+loaded = false
2 3
 
3 4
 function init()
4 5
   connect(g_game, { onClientVersionChange = load })
@@ -12,6 +13,10 @@ function setFileName(name)
12 13
   filename = name
13 14
 end
14 15
 
16
+function isLoaded()
17
+  return loaded
18
+end
19
+
15 20
 function load()
16 21
   local version = g_game.getClientVersion()
17 22
   local datPath = resolvepath(version .. '/' .. filename .. '.dat')
@@ -22,10 +27,17 @@ function load()
22 27
     errorMessage = errorMessage .. tr("Unable to load dat file, please place a valid dat in '%s'", datPath) .. '\n'
23 28
   end
24 29
   if not g_sprites.loadSpr(sprPath) then
25
-    errorMessage = errorMessage .. tr("Unable to load spr file, please place a valid spr in '%s'", sprPath) .. '\n'
30
+    errorMessage = errorMessage .. tr("Unable to load spr file, please place a valid spr in '%s'", sprPath)
26 31
   end
27 32
 
33
+  loaded = (errorMessage:len() == 0)
34
+
28 35
   if errorMessage:len() > 0 then
29
-    displayErrorBox(tr('Error'), errorMessage)
36
+    local messageBox = displayErrorBox(tr('Error'), errorMessage)
37
+    addEvent(function() messageBox:raise() messageBox:focus() end)
38
+
39
+    disconnect(g_game, { onClientVersionChange = load })
40
+    g_game.setClientVersion(0)
41
+    connect(g_game, { onClientVersionChange = load })
30 42
   end
31 43
 end

+ 1
- 0
src/otclient/const.h View File

@@ -333,6 +333,7 @@ namespace Otc
333 333
         GameChargeableItems = 25,
334 334
         GameOfflineTrainingTime = 26,
335 335
         GamePurseSlot = 27,
336
+        GameFormatCreatureName = 28,
336 337
         // 23-50 unused yet
337 338
         // 51-100 reserved to be defined in lua
338 339
         LastGameFeature = 101

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

@@ -1128,10 +1128,11 @@ void Game::setClientVersion(int version)
1128 1128
     if(isOnline())
1129 1129
         stdext::throw_exception("Unable to change client version while online");
1130 1130
 
1131
-    if(version < 810 || version > 961)
1131
+    if(version != 0 && (version < 810 || version > 961))
1132 1132
         stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
1133 1133
 
1134 1134
     m_features.reset();
1135
+    enableFeature(Otc::GameFormatCreatureName);
1135 1136
 
1136 1137
     if(version <= 810) {
1137 1138
         enableFeature(Otc::GameChargeableItems);
@@ -1203,7 +1204,7 @@ void Game::setFollowingCreature(const CreaturePtr& creature)
1203 1204
 std::string Game::formatCreatureName(const std::string& name)
1204 1205
 {
1205 1206
     std::string formatedName = name;
1206
-    if(m_isCreatureNameFormatEnabled && name.length() > 0)
1207
+    if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0)
1207 1208
         formatedName[0] = stdext::upchar(formatedName[0]);
1208 1209
     return formatedName;
1209 1210
 }

+ 0
- 3
src/otclient/game.h View File

@@ -269,8 +269,6 @@ public:
269 269
     std::vector<uint8> getGMActions() { return m_gmActions; }
270 270
 
271 271
     std::string formatCreatureName(const std::string &name);
272
-    void enableCreatureNameFormat() { m_isCreatureNameFormatEnabled = true; }
273
-    void disableCreatureNameFormat() { m_isCreatureNameFormatEnabled = false; }
274 272
 
275 273
 protected:
276 274
     void enableBotCall() { m_denyBotCall = false; }
@@ -287,7 +285,6 @@ private:
287 285
     std::map<int, ContainerPtr> m_containers;
288 286
     std::map<int, Vip> m_vips;
289 287
 
290
-    stdext::boolean<true> m_isCreatureNameFormatEnabled;
291 288
     bool m_online;
292 289
     bool m_denyBotCall;
293 290
     bool m_dead;

+ 0
- 2
src/otclient/luafunctions.cpp View File

@@ -206,8 +206,6 @@ void OTClient::registerLuaFunctions()
206 206
     g_lua.bindSingletonFunction("g_game", "getFeature", &Game::getFeature, &g_game);
207 207
     g_lua.bindSingletonFunction("g_game", "setFeature", &Game::setFeature, &g_game);
208 208
     g_lua.bindSingletonFunction("g_game", "enableFeature", &Game::enableFeature, &g_game);
209
-    g_lua.bindSingletonFunction("g_game", "enableCreatureNameFormat", &Game::enableCreatureNameFormat, &g_game);
210
-    g_lua.bindSingletonFunction("g_game", "disableCreatureNameFormat", &Game::disableCreatureNameFormat, &g_game);
211 209
 
212 210
     g_lua.registerSingletonClass("g_shaders");
213 211
     g_lua.bindSingletonFunction("g_shaders", "createShader", &ShaderManager::createShader, &g_shaders);

Loading…
Cancel
Save