Is possible get Account ID from other client in client side?
#1

I am doing a simple ban system, and I wanted to know if it is possible to obtain the id of another user's account from the client side, or must I do it on the server side?

#2

I don't think you can get that info through the client, I recommend doing it on the server side 

#3


1 hour ago, Desarija said:




I don't think you can get that info through the client, I recommend doing it on the server side 




There's no list in client which detain the ids

#4

Doing some research I found GetTargetDBIdx, but at least for chars, it does not return anything, I suppose that for security reasons this data is not available to clients, I suppose that I will have to obtain the id on the server side using the name of the character...

#5


9 hours ago, nicolasg said:




Doing some research I found GetTargetDBIdx, but at least for chars, it does not return anything, I suppose that for security reasons this data is not available to clients, I suppose that I will have to obtain the id on the server side using the name of the character...




Yea, that's for security reason, plus there is no point to store data in client side about player near you. The server already do it.

 

That was my function to ban people (you already have the code):

void do_ban_account(CPC* ch, const char* arg, std::vector<std:Confusedtring>& vec)
{
int cid,
uid,
scura_bantime,
bantime;

if (arg == NULL)
return;

char nick[MAX_MESSAGE_SIZE] = { 0, };
*nick = '\0'; // argument for arg

char bantimeSTR[11] = { 0, };
*bantimeSTR = '\0'; // argument for arg

arg = AnyOneArg(arg, bantimeSTR);
arg = AnyOneArg(arg, nick);

bantime = atoi(bantimeSTR);

LOG_WARN("Ban Time: %d", bantime);

// GM/GS switch, in this case they can not ban more than 7 days
if (ch->m_admin < 10)
{
if (bantime > 7)
bantime = 7;
}

// Can not ban yourself
if (nick == ch->GetName())
{
CNetMsg::SP rmsg(new CNetMsg);
SayMsg(rmsg, MSG_CHAT_NOTICE, 0, "", "", "can't ban myself");
SEND_Q(rmsg, ch->m_desc);
return;
}

// //Announce ban function
CLCString message(1024);
message.Format("User %s has been banned from staff member: %s", nick, ch->m_nick);
CNetMsg::SP clientMsg(new CNetMsg);
MsgrNoticeMsg(clientMsg, -1, gserver->m_serverno, gserver->m_subno, -1, message);
SEND_Q(clientMsg, gserver->m_messenger);

//Make Kick User
CNetMsg::SP rmsg2(new CNetMsg);
ServerToServerPacket::makeKickUser(rmsg2, ch->m_index, nick);
SEND_Q(rmsg2, gserver->m_helper);

/* Char db declaration*/
mysqldb::connectInfo dbChar_Info;
dbChar_Info.host_ = gserver->m_config.Find("Char DB", "IP");
dbChar_Info.port_ = 0;
dbChar_Info.user_ = gserver->m_config.Find("Char DB", "User");
dbChar_Info.pw_ = gserver->m_config.Find("Char DB", "Password");
dbChar_Info.dbname_ = gserver->m_config.Find("Char DB", "DBName");
dbChar_Info.charsetname_ = "";
mysqldb dbChar_Info_;
dbChar_Info_.connect(dbChar_Info);
/*end char db declaration*/

/*start user db declaration*/
mysqldb::connectInfo dbUser_Info;
dbUser_Info.host_ = gserver->m_config.Find("Auth DB", "IP");
dbUser_Info.port_ = 0;
dbUser_Info.user_ = gserver->m_config.Find("Auth DB", "User");
dbUser_Info.pw_ = gserver->m_config.Find("Auth DB", "Password");
dbUser_Info.dbname_ = gserver->m_config.Find("Auth DB", "DBName");
dbUser_Info.charsetname_ = "";
mysqldb dbUser_Info_;
dbUser_Info_.connect(dbUser_Info);
/*end user db declaration*/

CDBCmd dbChar;
dbChar.Init(&gserver->m_dbchar);
char query[MAX_MESSAGE_SIZE] = "";
sprintf(query, "SELECT `a_index`, `a_user_index` FROM `t_characters` WHERE `a_nick` = '%s'", nick);
dbChar.SetQuery(query);

if (dbChar.Open() == false)
{
CNetMsg::SP rmsg3(new CNetMsg);
SayMsg(rmsg3, MSG_CHAT_NOTICE, 0, "", "", "Error while ban account! dbChar [connection closed!]");
SEND_Q(rmsg3, ch->m_desc);
LOG_ERROR("Error when trying ban [%s] [%s] dbChar [connection closed!]", nick, mysql_error(&gserver->m_dbdata));
return;
}
while (dbChar.MoveNext() == true)
{
dbChar.GetRec("a_index", cid);
dbChar.GetRec("a_user_index", uid);
}
dbChar.Close(); //end connection with the db

CLCString sql(1024);
CDBCmd dbAuth;
dbAuth.Init(&gserver->m_dbauth);

sql.Format("UPDATE bg_user SET activated = 3, unban_date = NOW() + INTERVAL %d DAY, banreason = '%s' WHERE user_code = %d", bantime, arg, uid);
dbAuth.SetQuery(sql);
if (!dbAuth.Update())
{
LOG_ERROR("Error while updating dbAuth!");
dbAuth.Close(); //end connection with the db
return;
}
dbAuth.Close(); //end connection with the db
LOG_WARN("Account: %s has been banned from: %s staff member!", nick, ch->m_nick);
}

 

About retrive the userid by char, i can suggest to retreive the user index by using the function:

CPC* PCManager::getPlayerByCharIndex(int charIndex)
{
map_t::index<Key_Char_Index>::type& p = playerMap_.get<Key_Char_Index>();
map_t::index<Key_Char_Index>::type::iterator it = p.find(charIndex);
if (it == p.end())
return NULL;

if (it->pPlayer->m_bPlaying == false)
return NULL;

return (*it).pPlayer;
}

 

#6


9 hours ago, Scura said:




Yea, that's for security reason, plus there is no point to store data in client side about player near you. The server already do it.



 



That was my function to ban people (you already have the code):


void do_ban_account(CPC* ch, const char* arg, std::vector<std:Confusedtring>& vec)
{
int cid,
uid,
scura_bantime,
bantime;

if (arg == NULL)
return;

char nick[MAX_MESSAGE_SIZE] = { 0, };
*nick = '\0'; // argument for arg

char bantimeSTR[11] = { 0, };
*bantimeSTR = '\0'; // argument for arg

arg = AnyOneArg(arg, bantimeSTR);
arg = AnyOneArg(arg, nick);

bantime = atoi(bantimeSTR);

LOG_WARN("Ban Time: %d", bantime);

// GM/GS switch, in this case they can not ban more than 7 days
if (ch->m_admin < 10)
{
if (bantime > 7)
bantime = 7;
}

// Can not ban yourself
if (nick == ch->GetName())
{
CNetMsg::SP rmsg(new CNetMsg);
SayMsg(rmsg, MSG_CHAT_NOTICE, 0, "", "", "can't ban myself");
SEND_Q(rmsg, ch->m_desc);
return;
}

// //Announce ban function
CLCString message(1024);
message.Format("User %s has been banned from staff member: %s", nick, ch->m_nick);
CNetMsg::SP clientMsg(new CNetMsg);
MsgrNoticeMsg(clientMsg, -1, gserver->m_serverno, gserver->m_subno, -1, message);
SEND_Q(clientMsg, gserver->m_messenger);

//Make Kick User
CNetMsg::SP rmsg2(new CNetMsg);
ServerToServerPacket::makeKickUser(rmsg2, ch->m_index, nick);
SEND_Q(rmsg2, gserver->m_helper);

/* Char db declaration*/
mysqldb::connectInfo dbChar_Info;
dbChar_Info.host_ = gserver->m_config.Find("Char DB", "IP");
dbChar_Info.port_ = 0;
dbChar_Info.user_ = gserver->m_config.Find("Char DB", "User");
dbChar_Info.pw_ = gserver->m_config.Find("Char DB", "Password");
dbChar_Info.dbname_ = gserver->m_config.Find("Char DB", "DBName");
dbChar_Info.charsetname_ = "";
mysqldb dbChar_Info_;
dbChar_Info_.connect(dbChar_Info);
/*end char db declaration*/

/*start user db declaration*/
mysqldb::connectInfo dbUser_Info;
dbUser_Info.host_ = gserver->m_config.Find("Auth DB", "IP");
dbUser_Info.port_ = 0;
dbUser_Info.user_ = gserver->m_config.Find("Auth DB", "User");
dbUser_Info.pw_ = gserver->m_config.Find("Auth DB", "Password");
dbUser_Info.dbname_ = gserver->m_config.Find("Auth DB", "DBName");
dbUser_Info.charsetname_ = "";
mysqldb dbUser_Info_;
dbUser_Info_.connect(dbUser_Info);
/*end user db declaration*/

CDBCmd dbChar;
dbChar.Init(&gserver->m_dbchar);
char query[MAX_MESSAGE_SIZE] = "";
sprintf(query, "SELECT `a_index`, `a_user_index` FROM `t_characters` WHERE `a_nick` = '%s'", nick);
dbChar.SetQuery(query);

if (dbChar.Open() == false)
{
CNetMsg::SP rmsg3(new CNetMsg);
SayMsg(rmsg3, MSG_CHAT_NOTICE, 0, "", "", "Error while ban account! dbChar [connection closed!]");
SEND_Q(rmsg3, ch->m_desc);
LOG_ERROR("Error when trying ban [%s] [%s] dbChar [connection closed!]", nick, mysql_error(&gserver->m_dbdata));
return;
}
while (dbChar.MoveNext() == true)
{
dbChar.GetRec("a_index", cid);
dbChar.GetRec("a_user_index", uid);
}
dbChar.Close(); //end connection with the db

CLCString sql(1024);
CDBCmd dbAuth;
dbAuth.Init(&gserver->m_dbauth);

sql.Format("UPDATE bg_user SET activated = 3, unban_date = NOW() + INTERVAL %d DAY, banreason = '%s' WHERE user_code = %d", bantime, arg, uid);
dbAuth.SetQuery(sql);
if (!dbAuth.Update())
{
LOG_ERROR("Error while updating dbAuth!");
dbAuth.Close(); //end connection with the db
return;
}
dbAuth.Close(); //end connection with the db
LOG_WARN("Account: %s has been banned from: %s staff member!", nick, ch->m_nick);
}


 



About retrive the userid by char, i can suggest to retreive the user index by using the function:


CPC* PCManager::getPlayerByCharIndex(int charIndex)
{
map_t::index<Key_Char_Index>::type& p = playerMap_.get<Key_Char_Index>();
map_t::index<Key_Char_Index>::type::iterator it = p.find(charIndex);
if (it == p.end())
return NULL;

if (it->pPlayer->m_bPlaying == false)
return NULL;

return (*it).pPlayer;
}


 




i want to create it from scratch, using ServerToServerPacket::makeKickUser is the easy way, i made something like that

void AC_BanUser(CPC* ch, CNetMsg::SP& msg) {
if (ch->m_admin < 8)
return;

unsigned char subtype;
CLCString CHARNAME;
CLCString BANTIME;
CLCString BANREASON;

RefMsg(msg) >> subtype
>> CHARNAME
>> BANTIME
>> BANREASON;
/*{ TOO DIRTY 4 ME
CNetMsg::SP rmsg(new CNetMsg);
ServerToServerPacket::makeKickUser(rmsg, ch->m_index, CHARNAME);
SEND_Q(rmsg, gserver->m_helper);
}*/

CPC* pInfo = PCManager::instance()->getPlayerByName(CHARNAME, true);
pInfo->m_desc->Close("CHEATER");

GAMELOG << init("ANTICHEAT")
<< "USER BANNED" << delim << CHARNAME << delim
<< "REASON" << delim << BANREASON << delim
<< "BAN TIME" << delim << BANTIME << delim
<< "BANNED BY" << delim << ch->m_desc->m_pChar->m_name << end;
}


Forum Jump:


Users browsing this thread: 1 Guest(s)