|
You last visited: Today at 05:05
Advertisement
[C++] Pet Name Change
Discussion on [C++] Pet Name Change within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.
11/29/2015, 12:21
|
#1
|
elite*gold: 0
Join Date: Apr 2010
Posts: 66
Received Thanks: 103
|
[C++] Pet Name Change
Hi.
Note: For all codes:
open petsystem.cpp
find:
add
find:
Code:
void CPetActor::SetName(const char* name)
change code block:
Code:
void CPetActor::SetName(const char* name)
{
std::string petName = m_pkOwner->GetName();
if (0 != m_pkOwner &&
0 == name &&
0 != m_pkOwner->GetName())
{
petName += "'s Pet";
}
else
petName += name;
char sorgu[512];
snprintf(sorgu, sizeof(sorgu), "SELECT name FROM pet_name WHERE id = %u", m_pkOwner->GetPlayerID());
std::auto_ptr<SQLMsg> cekgelsin( DBManager::instance().DirectQuery(sorgu) );
if (cekgelsin->Get()->uiNumRows != 0)
{
MYSQL_ROW row = mysql_fetch_row(cekgelsin->Get()->pSQLResult);
char petad[CHARACTER_NAME_MAX_LEN + 1];
strlcpy(petad, row[0], sizeof(petad));
petName = petad;
}
if (true == IsSummoned())
m_pkChar->SetName(petName);
m_name = petName;
}
open questlua_pet.cpp
find:
Code:
#include "PetSystem.h"
add
find
Code:
int pet_spawn_effect(lua_State* L)
add code block
Code:
int pet_namever(lua_State* L)
{
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr() ;
if ( lua_isstring(L, 1) != true )
{
lua_pushnumber(L, 1);
return 1;
}
const char * szName = lua_tostring(L, 1);
char sorgu[512];
snprintf(sorgu, sizeof(sorgu), "REPLACE INTO pet_name VALUES(%u, '%s')", ch->GetPlayerID(), szName);
std::auto_ptr<SQLMsg> yolla( DBManager::instance().DirectQuery(sorgu) );
if (yolla->Get()->uiAffectedRows != 0)
{
lua_pushnumber(L, 3);
return 3;
}
return 4;
}
find
Code:
{ "spawn_effect", pet_spawn_effect },
add
Code:
{ "adver", pet_namever },
Navicat mysql query :
Open Navicat > Click to "Query":
Code:
DROP TABLE IF EXISTS `pet_name`;
CREATE TABLE `pet_name` (
`id` int(11) NOT NULL DEFAULT '0',
`name` varchar(24) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL DEFAULT 'NONAME',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;
add to in Quest_functions
Quest:
Code:
quest ademin begin
state start begin
when 71115.use begin
say_title("yeni isim ver")
local str = input()
if str == "" or str == nill then
say_title("Kutuyu bos birakma")
return
end
if string.len(str) <= 0 or string.len(str) > 12 then
say_title("isim en fazla 12 karakter olabilir")
return
end
local tt = "%'"
local ct = "%:"
local nk = "%."
local vg = "%,"
if string.find(str, tt) or string.find(str, ct) or string.find(str, nk) or string.find(str, vg) then
say_title("ozel isaret kullanamazsin")
return
end
local t = pet.adver(str)
say_title("pet adi degistirildi. peti gonder")
if t == 1 then
say_title("kutuyu bos bırakma")
return
elseif t == 2 then
say_title("12 karakteri gecme")
return
elseif t == 3 then
say_title("isim degisti")
end
end
end
end
Code:
local tt = "%'"
local ct = "%:"
local nk = "%."
local vg = "%,"
Yukarıda :
tt > '
ct > :
nk > .
vg > ,
Pet name given apply to all pets.
Note: Pet name > max 24 characters
|
|
|
11/29/2015, 13:06
|
#2
|
elite*gold: 222
Join Date: Oct 2012
Posts: 2,361
Received Thanks: 3,388
|
Thank you yavsak
Very useful
|
|
|
11/29/2015, 13:16
|
#3
|
elite*gold: 150
Join Date: Feb 2009
Posts: 643
Received Thanks: 613
|
Thank you!
|
|
|
11/29/2015, 22:58
|
#4
|
elite*gold: 0
Join Date: Dec 2011
Posts: 50
Received Thanks: 99
|
Quote:
Originally Posted by Mr. 'Avenue™
Thank you yavsak
Very useful
|
lol
|
|
|
11/29/2015, 23:51
|
#5
|
elite*gold: 0
Join Date: May 2015
Posts: 16
Received Thanks: 8
|
Hmm, useful. Thanks, I'll take this.
|
|
|
11/30/2015, 00:33
|
#6
|
elite*gold: 0
Join Date: Aug 2015
Posts: 10
Received Thanks: 45
|
At first, your method is totally wrong. I want to explain what does mean REPLACE INTO to you.
It means, If the query is not exist, insert it. Otherwise replace it with new one. Your vulnerability starts here.
If I've more pet in the game, the system is only call first column. So that means, my pet's name is Julia but it returns Adam because of this.
Also, if you're not using pet_name.sql to store the pet names, you don't need to create extra codes to set pet name. You can insert a new column in player.sql and you can call it easily too.
Code:
strlcpy(petad, row[0], sizeof(petad));
Everything will be good with item id.
Here are new codes.
Don't forget to add those things in your questlua_pet.cpp
Code:
#include "db.h"
#include "item.h"
Code:
int pet_set_name(lua_State * L)
{
if (!lua_isstring(L, 1))
{
lua_pushnumber(L, 1);
return 1;
}
LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
LPITEM pItem = CQuestManager::instance().GetCurrentItem();
if (!ch || !pItem) return 1;
const char * c_pszPetName = lua_tostring(L, 1);
char szPetName[CHARACTER_NAME_MAX_LEN + 1];
DBManager::Instance().EscapeString(szPetName, sizeof(szPetName), c_pszPetName, strlen(c_pszPetName));
if (strlen(szPetName) == 0)
{
lua_pushnumber(L, 2);
return 2;
}
std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("REPLACE INTO %spet_name VALUES(%u, '%s')", get_table_postfix(), pItem->GetID(), szPetName));
if (pMsg->Get()->uiAffectedRows != 0)
lua_pushnumber(L, 3);
return 0;
}
Code:
void CPetActor::SetName(const char * name)
{
if (!IsSummoned()) return;
if (m_dwSummonItemVID == 0)
{
std::string petName = m_pkOwner->GetName();
petName += m_pkOwner != 0 && name == 0 && m_pkOwner->GetName() != 0 ? "'s Pet" : name;
m_pkChar->SetName(petName);
m_name = petName;
}
else
{
LPITEM pSummonItem = ITEM_MANAGER::instance().FindByVID(m_dwSummonItemVID);
if (!pSummonItem)
{
std::string petName = m_pkOwner->GetName();
petName += m_pkOwner != 0 && name == 0 && m_pkOwner->GetName() != 0 ? "'s Pet" : name;
m_pkChar->SetName(petName);
m_name = petName;
}
else
{
std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT name FROM %spet_name WHERE id = %u", get_table_postfix(), pSummonItem->GetID()));
if (pMsg->Get()->uiNumRows == 0)
{
std::string petName = m_pkOwner->GetName();
petName += m_pkOwner != 0 && name == 0 && m_pkOwner->GetName() != 0 ? "'s Pet" : name;
m_pkChar->SetName(petName);
m_name = petName;
}
else
{
MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
char szPetName[CHARACTER_NAME_MAX_LEN + 1];
strlcpy(szPetName, row[0], sizeof(szPetName));
m_pkChar->SetName(szPetName);
m_name = szPetName;
}
}
}
}
Code:
local t = pet.adver(str)
say_title("pet adi degistirildi. peti gonder")
if t == 1 then
say_title("kutuyu bos bırakma")
return
elseif t == 2 then
say_title("12 karakteri gecme")
return
elseif t == 3 then
say_title("isim degisti")
end
that variable will never return 2 with your function and that condition is useless too.
Code:
quest pet_name_change begin
state start begin
when 71115.use begin
say_title("Pet name change:")
say("")
---"1234567890"
local petName = input()
if (petName == "" or tostring(petName) == nil) then
say("Enter a pet name!")
return
elseif (string.len(petName) <= 0 or string.len(petName) > 12) then
say("Your pet name is very long.")
return
end
local ret = pet.set_name(petName)
if (ret == 3) then
say("You changed your pet name.")
say("You just need to recall him!")
elseif (ret == 2) then
say("Your pet name is very short.")
else
say("Error code 0x100")
say("Please contact the administrator!")
end
end
end
end
Change CPetActor::Summon with that
Code:
DWORD CPetActor::Summon(const char* petName, LPITEM pSummonItem, bool bSpawnFar)
{
long x = m_pkOwner->GetX();
long y = m_pkOwner->GetY();
long z = m_pkOwner->GetZ();
if (true == bSpawnFar)
{
x += (number(0, 1) * 2 - 1) * number(2000, 2500);
y += (number(0, 1) * 2 - 1) * number(2000, 2500);
}
else
{
x += number(-100, 100);
y += number(-100, 100);
}
if (0 != m_pkChar)
{
m_pkChar->Show (m_pkOwner->GetMapIndex(), x, y);
m_dwVID = m_pkChar->GetVID();
return m_dwVID;
}
m_pkChar = CHARACTER_MANAGER::instance().SpawnMob(
m_dwVnum,
m_pkOwner->GetMapIndex(),
x, y, z,
false, (int)(m_pkOwner->GetRotation()+180), false);
if (0 == m_pkChar)
{
sys_err("[CPetSystem::Summon] Failed to summon the pet. (vnum: %d)", m_dwVnum);
return 0;
}
m_pkChar->SetPet();
// m_pkOwner->DetailLog();
// m_pkChar->DetailLog();
//ÆêÀÇ ±¹°¡¸¦ ÁÖÀÎÀÇ ±¹°¡·Î ¼³Á¤ÇÔ.
m_pkChar->SetEmpire(m_pkOwner->GetEmpire());
m_dwVID = m_pkChar->GetVID();
this->SetSummonItem(pSummonItem);
this->SetName(petName);
// SetSummonItem(pSummonItem)¸¦ ºÎ¸¥ ÈÄ¿¡ ComputePoints¸¦ ºÎ¸£¸é ¹öÇÁ Àû¿ëµÊ.
m_pkOwner->ComputePoints();
m_pkChar->Show(m_pkOwner->GetMapIndex(), x, y, z);
return m_dwVID;
}
Kind Regards ~ Ken
|
|
|
11/30/2015, 07:28
|
#7
|
elite*gold: 83
Join Date: Nov 2013
Posts: 2,891
Received Thanks: 2,764
|
I would search for "%W", which matches all non-alphanumeric characters. Matching only a few blacklisted characters doesnt seem good for me.
Use like below:
Code:
if string.find(petName, "%W") then
--Error msg
return
end
|
|
|
11/30/2015, 11:09
|
#8
|
elite*gold: 0
Join Date: Aug 2015
Posts: 10
Received Thanks: 45
|
Quote:
Originally Posted by Seחsi
I would search for "%W", which matches all non-alphanumeric characters. Matching only a few blacklisted characters doesnt seem good for me.
Use like below:
Code:
if string.find(petName, "%W") then
--Error msg
return
end
|
Yeah, it's an option for Lua but I'd prefer to use c++ for this job.
Code:
const char * c_pszPetName = lua_tostring(L, 1);
char szPetName[CHARACTER_NAME_MAX_LEN + 1];
DBManager::Instance().EscapeString(szPetName, sizeof(szPetName), c_pszPetName, strlen(c_pszPetName));
if (strlen(szPetName) == 0)
{
// Return value
}
or we can use this
Code:
char szPetName[24+1];
_snprintf(szPetName, sizeof(szPetName), "Kralco:cuk");
std::string stPetName = szPetName;
stPetName.erase(std::remove_if(stPetName.begin(), stPetName.end(), std::not1(std::ptr_fun(std::isalnum))), stPetName.end());
std::cout << stPetName << std::endl; // Return value would be "Kralcocuk"
|
|
|
12/08/2015, 00:17
|
#9
|
elite*gold: 0
Join Date: May 2013
Posts: 391
Received Thanks: 92
|
Quote:
Originally Posted by kralcocuk
Hi.
Note: Pet name > max 24 characters
|
That's the only part i don't really like.
Other than that, thanks.
|
|
|
12/08/2015, 02:32
|
#10
|
elite*gold: 0
Join Date: Apr 2010
Posts: 66
Received Thanks: 103
|
Quote:
Originally Posted by naosou
That's the only part i don't really like.
Other than that, thanks.
|
Short ?
Quote:
DROP TABLE IF EXISTS `pet_name`;
CREATE TABLE `pet_name` (
`id` int(11) NOT NULL DEFAULT '0',
`name` varchar(24) CHARACTER SET utf8 COLLATE utf8_turkish_ci NOT NULL DEFAULT 'NONAME',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;
|
varchar(24) <= Change
|
|
|
12/08/2015, 03:35
|
#11
|
elite*gold: 0
Join Date: May 2013
Posts: 391
Received Thanks: 92
|
Quote:
Originally Posted by kralcocuk
Short ?
varchar(24) <= Change
|
Sorry my bad, I meant this part.
Quote:
Originally Posted by kralcocuk
Pet name given apply to all pets.
|
|
|
|
12/10/2015, 00:18
|
#12
|
elite*gold: 0
Join Date: May 2010
Posts: 294
Received Thanks: 157
|
doesn't even matter because his quest dose not allow u to enter a name with more then 12 Charakters
PHP Code:
if string.len(str) <= 0 or string.len(str) > 12 then say_title("isim en fazla 12 karakter olabilir") return end
|
|
|
|
Similar Threads
|
[Selling] Secured Minecraft Accounts| Name Change Avaible| Non-MIgrated| Change Password|
11/21/2015 - Minecraft Trading - 17 Replies
I am selling secured minecraft accounts. All account information can be changed to your liking. Name changes are available for each account.
You can change, email, password, name character. All information
Non-migrated, secured minecraft accounts, Name change available.
Price: 5€
Stock: +1000
|
Great darkorbit account change per kbot license change!!
03/08/2013 - DarkOrbit Trading - 2 Replies
This is my account, i sell it for ''offer me'' or change for a kbot change license.
--Server:: es3(spain 3, good for bot)
-- Lv 14
-- Lot of ammo
-- 1 lf4, 22 lf3, 1 lf4( lv 2)
-- 5 iris, rest flax (all vants lv 6)
-- 23 bo2, rest 15 2.500 uri shields
-- All extras
-- Skylab lv 13 all
-- Goliath
|
[Change]Change Operation7 account for 3 days of Kbot/Ibot gg
01/30/2013 - Browsergames Trading - 2 Replies
the title talk for me, 3 days for 1 acc for the FPS Operation 7: lvl 12 4 guns + cash
|
All times are GMT +2. The time now is 05:05.
|
|