kill command [1.5]

Status
Not open for further replies.
Joined
Jul 11, 2012
Messages
785
Reaction score
191
Hello again, imma make this really fast, since i've been asked 3 times in pm about this command, and some more command.
So just a NOTE: all other commands such as /freeze <player> or /respawn <player> as some guys wanted, it's the same as this one, so just do the same things, i'm not gonna do them all, too lazy XD !!!
Usage: /kill <player>
Gunz/ZChat_Cmds.cpp
Code:
void ChatCmd_Kill(const char* line, const int argc, char **const argv);
Code:
_CC_AC("kill", &ChatCmd_Kill, CCF_ADMIN|CCF_GAME, ARGVNoMin, 1, true, "/kill <charname>", "");
Code:
void ChatCmd_Kill(const char* line, const int argc, char **const argv)
{
	if(argc < 2)
	{
		ZChatOutput("Usage: /kill <charname>", ZChat::CMT_SYSTEM);
		return;
	}
	ZPOSTCMD2(MC_KILL_THIS_PLAYER, MCmdParamStr(""), MCmdParamStr(argv[1]));
}
Gunz/ZGameClient_OnCommand.cpp
Code:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[256] = "";
	char TargetName[256] = "";
	char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade())
		break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
	pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
        ZCharacterManager *pZCharacterManager = ZGetCharacterManager();
        if (pZCharacterManager != NULL) 
        {
             for (ZCharacterManager::iterator itor = pZCharacterManager->begin(); itor != pZCharacterManager->end(); ++itor) 
             {
                  ZCharacter* pCharacter = (*itor).second;
                  if (strcmp(pCharacter->GetProperty()->GetName(), TargetName) == 0)
				pCharacter->SetHP(0);
             }
        }
	sprintf(szMsg, "^2%s has slained %s", AdminName, TargetName);
	ZChatOutput(szMsg);
}
break;
CSCommon/MMatchServer_OnCommand.cpp
Code:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[256] = "";
	char TargetName[256] = "";
	char szMsg[256];

	if(!pCommand->GetParameter(AdminName, 0, MPT_STR))
		break;
	MMatchObject* pChar = GetObjectA(pCommand->GetSenderUID());
	pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
				
	if(pChar == NULL)
		break;
	if(!IsAdminGrade(pChar))
		break;

	MCommand* pCmd = CreateCommand(MC_KILL_THIS_PLAYER, MUID(0,0));
	pCmd->AddParameter(new MCmdParamStr(pChar->GetName()));
	pCmd->AddParameter(new MCmdParamStr(TargetName));
	RouteToStage(pChar->GetStageUID(), pCmd);
	sprintf(szMsg, "^2You have slained %s", TargetName);
	Announce(pChar->GetUID(), szMsg);
}
break;
CSCommon/MSharedCommandTable.cpp
Code:
C(MC_KILL_THIS_PLAYER, "Admin.KillPlayer", "", MCDT_MACHINE2MACHINE)
        P(MPT_STR, "AdminName")
	P(MPT_STR, "TargetName")
CSCommon/MSharedCommandTable.h
Code:
#define MC_KILL_THIS_PLAYER        XXXXXX // Here put a new ID (not found in the file)
Forgive me if it could have been done shorter, but I did it real quick in my way, without looking twice on code, just for those who pm'd me, and ofc for who need this :):
PEACE MATES :thumbup:
 
Last edited:
Took a quick glance through it.

Code:
        if(ZGetMyInfo()->IsAdminGrade())
              break;
Within the client's OnCommand handler, what.

Also, any peer can still send the packet directly to every peer on the stage and automatically kill everyone. Hell, the admin name parameter could be spoofed.
Why not have the MatchServer route the packet directly to the target client, or simply keep it entirely P2P and simply validate the UGrade?
 
Last edited:
Hahaha LOL, thanks for the note didn't think of that :):
Anyways they can still do what you've said, a code can be done in many ways, and i did it real quick, didn't have much time cuz of freaking HWs XD
Thanks again for the note mate.
Appreciated :):
 
You should have a request and response packet, it would make more sense that way.

And could help you clean the code. There is no need to iterate through the whole ZCharacterManager just because someone got slapped.
Easier yet, your response packet could have the victim's UID in it.
Edit: If you sent back both UID's you could do something like

ZPostDie(AdminUID);

Even without any of that you could've done this simply:

Code:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[32] = "";
	char TargetName[32] = ""; //Make sure not to allocate more than you need 32/64  should be the maximum for a character name anyway. 
	char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade()) //This could be easily spoofed by any hacker who can spoof their ugrade.
		break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
	pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
if(strcmp(TargetName, m_pmycharacter->szName) ==0) m_pmycharacter->SetHP(0);    //Something like this im doing it off the top of my head     

	sprintf(szMsg, "^2%s has killed %s", AdminName, TargetName); //Not necessary but ok
	ZChatOutput(szMsg);
}
break;
 
You should have a request and response packet, it would make more sense that way.

And could help you clean the code. There is no need to iterate through the whole ZCharacterManager just because someone got slapped.
Easier yet, your response packet could have the victim's UID in it.
Edit: If you sent back both UID's you could do something like



Even without any of that you could've done this simply:

Code:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[32] = "";
	char TargetName[32] = ""; //Make sure not to allocate more than you need 32/64  should be the maximum for a character name anyway. 
	char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade()) //This could be easily spoofed by any hacker who can spoof their ugrade.
		break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
	pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
if(strcmp(TargetName, m_pmycharacter->szName) ==0) m_pmycharacter->SetHP(0);    //Something like this im doing it off the top of my head     

	sprintf(szMsg, "^2%s has killed %s", AdminName, TargetName); //Not necessary but ok
	ZChatOutput(szMsg);
}
break;
Hmm, yeah about the array size you are right, i'm blowing up the memory like this hahaha XD
So, could u explain what did you mean by this part:
ZPostDie(AdminUID);
and yeah, about this:
if(ZGetMyInfo()->IsAdminGrade())
the player can't use the command anyways cuz of CCF_ADMIN, unless you mean bypassing this by ASM (ollydbg or so) ??!
And thanks for the notes you guys help me alot, I am still in the learning progress I like to know what mistakes I do so I will learn and improve my self..
Thank you guys <3
 
You should have a request and response packet, it would make more sense that way.

And could help you clean the code. There is no need to iterate through the whole ZCharacterManager just because someone got slapped.
Easier yet, your response packet could have the victim's UID in it.
Edit: If you sent back both UID's you could do something like



Even without any of that you could've done this simply:

Code:
case MC_KILL_THIS_PLAYER:
{
    char AdminName[32] = "";
    char TargetName[32] = ""; //Make sure not to allocate more than you need 32/64  should be the maximum for a character name anyway. 
    char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade()) //This could be easily spoofed by any hacker who can spoof their ugrade.
        break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
    pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
if(strcmp(TargetName, m_pmycharacter->szName) ==0) m_pmycharacter->SetHP(0);    //Something like this im doing it off the top of my head     

    sprintf(szMsg, "^2%s has killed %s", AdminName, TargetName); //Not necessary but ok
    ZChatOutput(szMsg);
}
break;

Code:
        if(ZGetMyInfo()->IsAdminGrade()) //This could be easily spoofed by any hacker who can spoof their ugrade.
        break;
Your comment is right, but that chunk of code shouldn't even be there.
 
Code:
        if(ZGetMyInfo()->IsAdminGrade()) //This could be easily spoofed by any hacker who can spoof their ugrade.
        break;
Your comment is right, but that chunk of code shouldn't even be there.

Yeah that's right it should be deleted.. wasn't needed xD
 
Yeah that's right it should be deleted.. wasn't needed xD

After a quick re-read, I can see why it's there. Still, the entire thing could be changed to just:
Check current character name (although using the target's MUID would be far more optimal) against the TargetName -> If it matches, suicide.
If not -> Simply print the message
There's no need to iterate through every single character in the room for that.
 
Well, correcting some useless things..

Client
PHP:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[256] = "";
	char TargetName[256] = "";
	char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade())
		break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
		pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
		ZGetGame()->m_pMyCharacter->SetHP(0);
		sprintf(szMsg, "^2%s has slained %s", AdminName, TargetName);
		ZChatOutput(szMsg);
}
break;

MatchServer
PHP:
case MC_KILL_THIS_PLAYER:
{
	char AdminName[256] = "";
	char TargetName[256] = "";
	char szMsg[256];

	if(!pCommand->GetParameter(AdminName, 0, MPT_STR))
		break;
	MMatchObject* pChar = GetObjectA(pCommand->GetSenderUID());
	pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
	
	
	MMatchObject* pTarget = GetPlayerByName(TargetName);
	
	if(pChar == NULL)
		break;
	if(!IsAdminGrade(pChar))
		break;

	MCommand* pCmd = CreateCommand(MC_KILL_THIS_PLAYER, MUID(0,0));
	pCmd->AddParameter(new MCmdParamStr(pChar->GetName()));
	pCmd->AddParameter(new MCmdParamStr(""));
	RouteToListener(pTarget, pCmd);
	sprintf(szMsg, "^2You have slained %s", TargetName);
	Announce(pChar->GetUID(), szMsg);
}
break;

Sended by a mobile
 
Well, correcting some useless things..

Client
PHP:
case MC_KILL_THIS_PLAYER:
{
    char AdminName[256] = "";
    char TargetName[256] = "";
    char szMsg[256];

        if(ZGetMyInfo()->IsAdminGrade())
        break;

        pCommand->GetParameter(AdminName, 0, MPT_STR, sizeof(AdminName));
        pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
        ZGetGame()->m_pMyCharacter->SetHP(0);
        sprintf(szMsg, "^2%s has slained %s", AdminName, TargetName);
        ZChatOutput(szMsg);
}
break;

MatchServer
PHP:
case MC_KILL_THIS_PLAYER:
{
    char AdminName[256] = "";
    char TargetName[256] = "";
    char szMsg[256];

    if(!pCommand->GetParameter(AdminName, 0, MPT_STR))
        break;
    MMatchObject* pChar = GetObjectA(pCommand->GetSenderUID());
    pCommand->GetParameter(TargetName, 1, MPT_STR, sizeof(TargetName));
    
    
    MMatchObject* pTarget = GetPlayerByName(TargetName);
    
    if(pChar == NULL)
        break;
    if(!IsAdminGrade(pChar))
        break;

    MCommand* pCmd = CreateCommand(MC_KILL_THIS_PLAYER, MUID(0,0));
    pCmd->AddParameter(new MCmdParamStr(pChar->GetName()));
    pCmd->AddParameter(new MCmdParamStr(""));
    RouteToListener(pTarget, pCmd);
    sprintf(szMsg, "^2You have slained %s", TargetName);
    Announce(pChar->GetUID(), szMsg);
}
break;

@Sended by a mobile
Still doesn't fix the vulnerability. You should add the packet ID to the UDP blacklist.
 
Last edited:
After a quick re-read, I can see why it's there. Still, the entire thing could be changed to just:
Check current character name (although using the target's MUID would be far more optimal) against the TargetName -> If it matches, suicide.
If not -> Simply print the message
There's no need to iterate through every single character in the room for that.

By the way, if you mean like call the suicide function it would be much easier, but then I have to send the time to be the less to make it die fast, anyways you're right there is still vulnerability, hmm but I no longer care about gunz, i just posted this for those people who wanted it :):
Thanks for the notes guys :D
 
By the way, if you mean like call the suicide function it would be much easier, but then I have to send the time to be the less to make it die fast, anyways you're right there is still vulnerability, hmm but I no longer care about gunz, i just posted this for those people who wanted it :):
Thanks for the notes guys :D
Just set m_pMyCharacter's HP to 0 on the targetted client.
 
Hey bro, Add this but it happens when I use the command (I modify a /admin_kill) It happens that when I use the command /admin_kill <username> This disconnect me from the server
Why?
 
Hey bro, Add this but it happens when I use the command (I modify a /admin_kill) It happens that when I use the command /admin_kill <username> This disconnect me from the server
Why?
There is an admin command because this not well defined as admin_kill why you should be disconnected
 
Status
Not open for further replies.
Back