• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Correct a bit of code

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
650
Solutions
14
Reaction score
87
Hi.
I'm not good at C++ and I don't know how it fix.
I'm trying to replace mount system from 9.80 to 8.6, but I have one problem.
Code:
bool Player::tameMount(uint8_t mountId)
{
   if(!Mounts::getInstance()->getMountById(mountId))
       return false;

   --mountId;
   int32_t key = PSTRG_MOUNTS_RANGE_START + (mountId / 31), value = 0;

   std::string tmp;
   if(getStorage(key, tmp))
   {
       value = atoi(tmp.c_str());
       value |= (int32_t)pow(2., mountId % 31);
   }
   else
       value = (int32_t)pow(2., mountId % 31);

   setStorage(key, asStorage(value));
   return true;
}
And the error:
In member function `bool Player::tameMount(uint8_t)':
`asStorage' was not declared in this scope

@Edit
I got it.. something just like this:
Code:
setStorage(key, (const char*)value);

Sorry for refresh but I have already one problem. I added new files mounts.h and mounts.cpp, but linker has fucking errors....

When I added the files .h and .cpp, should I add something else for example mounts.o ??? or others
 
Last edited by a moderator:
Solution
Hm It's strange. there are no "encriptionType, world_id" e.t.c And I don't know which type of encryption is.
I've downloaded from this forum TFS 1.0.

First time I'm doing such a version.

The password should be encrypted, you can only have sha1 on the 1.x series and only 1 world.
So there is no need to have the encryptionType and world_id in the config.lua.

So just make sure the password in the database is encrypted and you should be fine.
Hi.
I'm not good at C++ and I don't know how it fix.
I'm trying to replace mount system from 9.80 to 8.6, but I have one problem.
Code:
bool Player::tameMount(uint8_t mountId)
{
   if(!Mounts::getInstance()->getMountById(mountId))
       return false;

   --mountId;
   int32_t key = PSTRG_MOUNTS_RANGE_START + (mountId / 31), value = 0;

   std::string tmp;
   if(getStorage(key, tmp))
   {
       value = atoi(tmp.c_str());
       value |= (int32_t)pow(2., mountId % 31);
   }
   else
       value = (int32_t)pow(2., mountId % 31);

   setStorage(key, asStorage(value));
   return true;
}
And the error:
In member function `bool Player::tameMount(uint8_t)':
`asStorage' was not declared in this scope

@Edit
I got it.. something just like this:
Code:
setStorage(key, (const char*)value);

Sorry for refresh but I have already one problem. I added new files mounts.h and mounts.cpp, but linker has fucking errors....

When I added the files .h and .cpp, should I add something else for example mounts.o ??? or others

Not sure what asStorage should do, try to just write key, value insted.

Try to remove all .o files and use the function clean / make clean and see if that fixes it.
 
Thanks @WibbenZ, but just forgot to add the files to the project. The compilation completed successfully, but when I turn on the engine, it loads normally, but after a short time the engine its shutdown.

This is list of files which I've edited:
Code:
config.lua
configmanager.cpp
configmanager.h
const.h
databasemanager.cpp
enums.h
game.cpp
game.h
iologindata.cpp
luascript.cpp
luascript.h
monsters.cpp
mounts.cpp
mounts.h
npc.cpp
otserv.cpp
player.cpp 
player.h
protocolgame.cpp
protocolgame.h
scriptmanager.cpp
And added "mounts.lua" to XML

So maybe I've forgotten to edit some file. Hm any ideas? (OTC is alright).
 
Thanks @WibbenZ, but just forgot to add the files to the project. The compilation completed successfully, but when I turn on the engine, it loads normally, but after a short time the engine its shutdown.

This is list of files which I've edited:
Code:
config.lua
configmanager.cpp
configmanager.h
const.h
databasemanager.cpp
enums.h
game.cpp
game.h
iologindata.cpp
luascript.cpp
luascript.h
monsters.cpp
mounts.cpp
mounts.h
npc.cpp
otserv.cpp
player.cpp
player.h
protocolgame.cpp
protocolgame.h
scriptmanager.cpp
And added "mounts.lua" to XML

So maybe I've forgotten to edit some file. Hm any ideas? (OTC is alright).

If it crashes upload a crash log, we can't help you otherwise.
 
Hmm but I don't have any crash log :((

I debugged:
Code:
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\TheForgottenServer-console.exe'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\lua5.1.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libmysql.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wsock32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libxml2-2.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libiconv-2.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\zlib1.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mswsock.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\NapiNSP.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\pnrpnsp.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nlaapi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dnsapi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\IPHLPAPI.DLL'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winrnr.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wshbth.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\FWPUCLNT.DLL'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rasadhlp.dll'. Cannot find or open the PDB file.
The thread 0x7c4 has exited with code 0 (0x0).
Unhandled exception at 0x006134A4 in TheForgottenServer-console.exe: 0xC0000005: Access violation reading location 0x00000008.

Hm I'm using DEV to compile. It seems that I should add some dll.
 
Last edited:
Hmm but I don't have any crash log :((

I debugged:
Code:
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\TheForgottenServer-console.exe'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\lua5.1.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libmysql.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wsock32.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libxml2-2.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\libiconv-2.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Users\VAIO\Desktop\Test OTS\zlib1.dll'. Module was built without symbols.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mswsock.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\NapiNSP.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\pnrpnsp.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nlaapi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dnsapi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\IPHLPAPI.DLL'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winrnr.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wshbth.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\FWPUCLNT.DLL'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. Cannot find or open the PDB file.
'TheForgottenServer-console.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rasadhlp.dll'. Cannot find or open the PDB file.
The thread 0x7c4 has exited with code 0 (0x0).
Unhandled exception at 0x006134A4 in TheForgottenServer-console.exe: 0xC0000005: Access violation reading location 0x00000008.

Hm I'm using DEV to compile. It seems that I should add some dll.

That dosn't really say anything, you need a crash log.
If you use visual studios you should be able to get a crash log, not really sure how to do it on windows I normally host servers and debug them with gdb on linux ubuntu.
 
Hm I'm working on Dev-C++, and even I don't know how to compile TFS 0.3.6 on Visual Studios.

Do you know how?
The problem is that there are different symbols than on the older version e.t.c 8.6.
So I should rewrite these both files according to older symbols
Or compile in Visual Studios(I don't know how :()
 
Hm I'm working on Dev-C++, and even I don't know how to compile TFS 0.3.6 on Visual Studios.

Do you know how?
The problem is that there are different symbols than on the older version e.t.c 8.6.
So I should rewrite these both files according to older symbols
Or compile in Visual Studios(I don't know how :()

You would need to create a project for it on VS, there should be some tutorials on how to do that or google how to port from dev cpp to visual studio.
What do you mean with symbols?
 
Symbols... for example old in 8.6 "cout" and the new "clog" in 9.81 e.t.c
I haven't found the rest yet.
 
OKEY. Hm I really don't know what this is:
In member function `bool Mount::isTamed(Player*) const':
no matching function for call to `Player::getStorage(const std::string&, std::string&)'
candidates are: virtual bool Creature::getStorage(uint32_t, std::string&) const

Code:
bool Mount::isTamed(Player* player) const
{
   if(!player)
       return false;

   if(player->hasCustomFlag(PlayerCustomFlag_CanUseAllMounts))
       return true;

   if(premium && !player->isPremium())
       return false;

   uint8_t tmpId = id - 1;
   std::string value;

   int32_t key = PSTRG_MOUNTS_RANGE_START + (tmpId / 31);
   if(player->getStorage(key, value))
   {
       int32_t tmp = (int32_t)std::pow(2., tmpId % 31);
       return (tmp & atoi(value.c_str())) == tmp;
   }

   if(storageId.empty())
       return false;

   player->getStorage(storageId, value);
   if(value == storageValue)
       return true;

   int32_t intValue = atoi(value.c_str());
   if(!intValue && value != "0")
       return false;

   int32_t tmp = atoi(storageValue.c_str());
   if(!tmp && storageValue != "0")
       return false;

   return intValue >= tmp;
}

The line:
player->getStorage(storageId, value);
 
Is it line 25 that the error is at?
In that case type is storageId? Is it std::string?

This part is the bugged one:
C++:
   if(storageId.empty())
       return false;

   player->getStorage(storageId, value);
   if(value == storageValue)
       return true;

   int32_t intValue = atoi(value.c_str());
   if(!intValue && value != "0")
       return false;

   int32_t tmp = atoi(storageValue.c_str());
   if(!tmp && storageValue != "0")
       return false;

storageId is not in the function itself
player->getStorage(storageId, value) is called but the return is not handeld
value is compared to storageValue that dosn't exist in the scope either.

Did you do the changes yourself? In that case what are you trying to do?
 
No, it's the original file. I only changed "clog" to "cout" everywhere.

And this :
if(player->getStorage(key, value))

should be:
if(player->getStorage(asString(key), value))

but asString is in the newer version.
Before I've removed "asString", it compiles without problems, but the engine is shutdowned
When I remove it, I get the error.
 
Last edited:
No, it's the original file. I only changed "clog" to "cout" everywhere.

And this :
if(player->getStorage(key, value))

should be:
if(player->getStorage(asString(key), value))

but asString is in the newer version.
Before I've removed "asString", it compiles without problems, but the engine is shutdowned
When I remove it, I get the error.

So if you use asString you get an error? Or the other way around?
Tbh just revert the storage changes and default it, there is no reason to change it.
 
OKey my friend, fuck up this shit. I may go to 10+ version.

But tell how to create a character in this shit. I compiled, everything is ok, database e.t.c, but there is no account manager.....
I'm doing it in the database, but nothing

Version 10.41
 
OKey my friend, fuck up this shit. I may go to 10+ version.

But tell how to create a character in this shit. I compiled, everything is ok, database e.t.c, but there is no account manager.....
I'm doing it in the database, but nothing

Version 10.41

Correct 1.x does not have an account manager.
You need to manually insert a character into the database or use an account manager (AAC, ex Gesior 2012 or Znote).
Set the id (if you got 0 characters in the database, set it to 1 so the amount you got + 1)
Set the name and account id (you can find the account id in the account table, note not the account name)
Set the positions to 0 if they arn't already, then set the town id to the town you want the player to spawn in

I think thats all I normally do, in some cases you might have to check the cap, health and mana but that should be enough.
You will get an error regarding conditions, just ignore it the server will fix it the first time you login.
 
I created the account(in the table accounts) then player(in the table players) and I get the fucking error "Account name or password is not correct". I'm using OTC to log in.
 
I created the account(in the table accounts) then player(in the table players) and I get the fucking error "Account name or password is not correct". I'm using OTC to log in.

Did you encrypt the password? If not use this website; SHA1 online
If you use the password "password" the sha1 sum would be; 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
 
Back
Top