Esempio n. 1
0
// This cleans up our clients mess :P
void CWorldServer::OnClientDisconnect( CClientSocket* thisclient )
{
    if(thisclient->player==NULL) return;
	CPlayer* player = (CPlayer*)thisclient->player;
	if(!player->Session->isLoggedIn) return;
    if(!player->Saved)
    {
    	player->savedata();
        player->Session->isLoggedIn = false;
        //send packet to change messenger status (offline)
    	BEGINPACKET( pak, 0x7e1 );
    	ADDBYTE    ( pak, 0xfa );
    	ADDWORD    ( pak, player->CharInfo->charid );
    	ADDBYTE    ( pak, 0x00 );
    	cryptPacket( (char*)&pak, NULL );
    	send( csock, (char*)&pak, pak.Size, 0 );
    }
    if ( player->Fairy )
    {
        FairyList.at(player->FairyListIndex)->assigned = false;
        FairyList.at(player->FairyListIndex)->LastTime = clock();
        FairyList.at(player->FairyListIndex)->ListIndex = 0;
        FairyList.at(player->FairyListIndex)->WaitTime = Config.FairyWait * (rand()% GetFairyRange(1)+ GetFairyRange(0));
        player->Fairy = false;
        player->FairyListIndex = 0;
        DoFairyStuff(player, 0);
        // recalculate FairyMax
        Config.FairyMax = (int)ceil((float)ClientList.size() / 50.0); //(1 fairy more every 50 player)
    }
    if(player->Party->party!=NULL)
    {
        CParty* party = player->Party->party;
        BEGINPACKET( pak, 0x7d2 );
        ADDWORD    ( pak, 0xff00 );
        ADDDWORD   ( pak, player->CharInfo->charid );
        bool pflag = false;
        party->RemovePlayer( player );
        if(party->Members.size()>1)
        {
            for(UINT i=0;i<party->Members.size();i++)
            {
                CPlayer* othermember = party->Members.at(i);
                if(!pflag)
                {
                    ADDDWORD( pak, othermember->CharInfo->charid );
                    if(player->Party->IsMaster)
                        othermember->Party->IsMaster = true;
                    pflag = true;
                }
                othermember->client->SendPacket( &pak );
            }
        }
        else
        {
            for(UINT i=0;i<party->Members.size();i++)
            {
                CPlayer* othermember = party->Members.at(i);
                BEGINPACKET( pak, 0x7d1 );
                ADDBYTE    ( pak, 0x05 );
                ADDWORD    ( pak, 0x0000 );
                ADDWORD    ( pak, 0x0000 );
                othermember->client->SendPacket( &pak );
                othermember->Party->party = NULL;
                othermember->Party->IsMaster = true;
            }
            RemoveParty( party );
            delete party;
            party = NULL;
        }
    }
    DB->QExecute("UPDATE accounts SET online=false where id=%u", player->Session->userid );
}
Esempio n. 2
0
// Party Actions [invite/leave/kick]
bool CWorldServer::pakPartyActions( CPlayer* thisclient, CPacket* P )
{
    unsigned int action = GETBYTE((*P),0);
    CMap* map = MapList.Index[thisclient->Position->Map];
    switch(action)
    {
        case 0x00://Invita a new party
        case 0x01://invite a existent party
        {
            UINT clientid = GETWORD((*P),1);
            if(thisclient->Party->party!=NULL)
            {
                //LMA: Refreshing Capacity if needed
                thisclient->Party->party->RefreshMax();
                if(thisclient->Party->party->Members.size()>=thisclient->Party->party->Capacity)
                {
                    SendSysMsg( thisclient, "Party is full" );
                    return true;
                }
            }
            CPlayer* otherclient = map->GetPlayerInMap( clientid );// have to be in same map
            if(otherclient==NULL)
            {
                BEGINPACKET( pak, 0x7d1 );
                ADDBYTE    ( pak, 0x00 );//No encontro el ID
                ADDWORD    ( pak, clientid );
                ADDBYTE    ( pak, 0x00 );
                thisclient->client->SendPacket( &pak );
                return true;
            }
            if(otherclient->Party->party!=NULL)
            {
                BEGINPACKET( pak, 0x7d1 );
                ADDBYTE    ( pak, 0x01 );//No puede ser solicitado (ya tiene party)
                ADDWORD    ( pak, clientid );
                ADDBYTE    ( pak, 0x00 );
                thisclient->client->SendPacket( &pak );
                return true;
            }
            if(abs(otherclient->Stats->Level-thisclient->Stats->Level)>(Config.Partygap+1))
            {
                BEGINPACKET( pak, 0x7d1 );
                ADDBYTE    ( pak, 0x07 );//Level inapropiado
                ADDWORD    ( pak, clientid );
                ADDBYTE    ( pak, 0x00 );
                thisclient->client->SendPacket( &pak );
                return true;
            }
            BEGINPACKET( pak, 0x7d0 );
            ADDBYTE    ( pak, action );
            ADDWORD    ( pak, thisclient->clientid );
            ADDBYTE    ( pak, 0x00 );
            otherclient->client->SendPacket( &pak );
        }
        break;
        case 0x02://Leave Party
        {
            if(thisclient->Party->party==NULL)
                return true;
            CParty* party = thisclient->Party->party;
            BEGINPACKET( pak, 0x7d2 );
            ADDWORD    ( pak, 0xff00 );
            ADDDWORD   ( pak, thisclient->CharInfo->charid );
            bool pflag = false;
            if(!party->RemovePlayer( thisclient )) //if this player is not in this party
                return true;
            if(party->Members.size()>1)
            {
                for(UINT i=0;i<party->Members.size();i++)
                {
                    CPlayer* thismember = party->Members.at(i);
                    if(!pflag)
                    {
                        ADDDWORD( pak, thismember->CharInfo->charid );
                        if(thisclient->Party->IsMaster)
                            thismember->Party->IsMaster = true;
                        pflag = true;
                    }
                    thismember->client->SendPacket( &pak );
                }
            }
            else
            {
                for(UINT i=0;i<party->Members.size();i++)
                {
                    CPlayer* thismember = party->Members.at(i);
                    BEGINPACKET( pak, 0x7d1 );
                    ADDBYTE    ( pak, 0x05 );
                    ADDWORD    ( pak, 0x0000 );
                    ADDWORD    ( pak, 0x0000 );
                    thismember->client->SendPacket( &pak );
                    thismember->Party->party = NULL;
                    thismember->Party->IsMaster = true;
                }
                RemoveParty( party );
                delete party;
            }
        }
        break;
        case 0x03: //Tomiz: Give leader New Way
        {
            if(thisclient->Party->party==NULL)
                return true;

            unsigned int clientid = GETWORD((*P),1);

            if ( !thisclient->Party->IsMaster || clientid == thisclient->clientid )
               return true;

            CPlayer* otherclient = GetClientByID( clientid );
            if(otherclient==NULL)
                return true;

            BEGINPACKET(pak, 0x7d1);
            ADDBYTE(pak, 8);
            ADDWORD(pak, otherclient->clientid);
            ADDWORD(pak, 0);
            otherclient->Party->IsMaster = true;
            thisclient->Party->IsMaster = false;
            thisclient->Party->party->SendToMembers( &pak );
        }
        break;
        case 0x81: //Kick from party
        {
            unsigned int charid = GETDWORD((*P),1);
            if(thisclient->Party->party==NULL)
                return true;
            if(!thisclient->Party->IsMaster || thisclient->CharInfo->charid==charid)
                return true;
            CParty* party = thisclient->Party->party;
            CPlayer* thismember = party->GetMemberByCharID( charid );
            if(thismember==NULL)
                return true;

            BEGINPACKET( pak, 0x7d1 ); // Kicked from party message
            ADDBYTE    ( pak, 0x80 );
            ADDDWORD   ( pak, thismember->CharInfo->charid );
            thismember->client->SendPacket( &pak );
            RESETPACKET( pak, 0x7d2 );
            ADDWORD    ( pak, 0xff00 );
            ADDDWORD   ( pak, thismember->CharInfo->charid );
            bool pflag = false;
            if(!party->RemovePlayer( thismember )) //if this player is not in this party
                return true;
            if(party->Members.size()>1)
            {
                for(UINT i=0;i<party->Members.size();i++)
                {
                    CPlayer* othermember = party->Members.at(i);
                    if(!pflag)
                    {
                        ADDDWORD( pak, othermember->CharInfo->charid );
                        if(thismember->Party->IsMaster)
                            othermember->Party->IsMaster = true;
                        pflag = true;
                    }
                    othermember->client->SendPacket( &pak );
                }
            }
            else
            {
                for(UINT i=0;i<party->Members.size();i++)
                {
                    CPlayer* othermember = party->Members.at(i);
                    BEGINPACKET( pak, 0x7d1 );
                    ADDBYTE    ( pak, 0x05 );
                    ADDWORD    ( pak, 0x0000 );
                    ADDWORD    ( pak, 0x0000 );
                    othermember->client->SendPacket( &pak );
                    othermember->Party->party = NULL;
                    othermember->Party->IsMaster = true;
                }
                RemoveParty( party );
                delete party;
            }
        }
        break;
        default:
            Log(MSG_WARNING,"Party unknown action: %i", action);
    }
    return true;
}