⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clan.cpp.svn-base

📁 ROSE的源代码。了解的自己研究,编译通过
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/*
    Rose Online Server Emulator
    Copyright (C) 2006,2007 OSRose Team http://osroseon.to.md
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    depeloped with Main erose/hrose source server + some change from the original eich source        
*/
#include "CharServer.h"

// Send Clan information
bool CCharServer::SendClanInfo (CCharClient* thisclient)
{
    if( thisclient->clanid > 0 )
    {
        CClans *thisclan = GetClanByID(thisclient->clanid);
        if(thisclan!=NULL)
        {
            BEGINPACKET( pak, 0x7e0);
            ADDBYTE    ( pak, 0x33);//0x33 you have invited to clan
            ADDWORD    ( pak, thisclan->id);// clan id
            ADDBYTE    ( pak, 0x00);//
            ADDBYTE    ( pak, 0x00);
            ADDWORD    ( pak, thisclan->back);//Clan Background
            ADDWORD    ( pak, thisclan->logo);//Clan logo
            ADDBYTE    ( pak, thisclan->grade);//Clan grade
            ADDBYTE    ( pak, thisclient->clan_rank);// Clan rank (0 = red rokie / 6 = master)
            ADDWORD    ( pak, 0x0000 ); // eu adicinei depois do update
            ADDWORD    ( pak, 0x0000 ); // eu adicinei depois do update
            ADDWORD    ( pak, thisclan->cp);//Clan Points
            ADDDWORD   ( pak, 0x00000000);
            ADDDWORD   ( pak, 0x00000000); //Clan found
            ADDBYTE    ( pak, 0x00);
            ADDDWORD   ( pak, 0x00000000);
            ADDWORD    ( pak, 0x0000);
            for(int i=34;i<156;i++)
                ADDBYTE ( pak, 0x00);
            ADDWORD    ( pak, 0x0000);
            ADDBYTE    ( pak, 0x00);
//            ADDDWORD   ( pak, 0x00000000 );
//            ADDBYTE    ( pak, 0x00 );
//            ADDBYTE    ( pak, 0x00);
            ADDSTRING  ( pak, thisclan->name);//Clan Name            
            ADDBYTE    ( pak, 0x00);            
            ADDSTRING  ( pak, thisclan->slogan);//Clan slogan
            ADDBYTE    ( pak, 0x00);
            ADDSTRING  ( pak, thisclan->news);//Clan news
            ADDBYTE    ( pak, 0x00);
            thisclient->SendPacket(&pak);	
            
            //Put the player online in clan
            for(UINT i=0;i<thisclan->ClanMembers.size();i++)
        	{		
                CClanMembers*	ClanMember = thisclan->ClanMembers.at( i );;
                CCharClient* otherclient = GetClientByID( ClanMember->id );
                if(otherclient!=NULL)
                    ChangeClanStatus (thisclient, otherclient, thisclient->channel);//send channel here
        	}                      
        }
    }     
    return true;
}

// Change player status in clan ((channel) = online/ 0xff = offline)
bool CCharServer::ChangeClanStatus (CCharClient* thisclient, CCharClient* otherclient, int channel)
{
        BEGINPACKET( pak, 0x7e0 );
        ADDBYTE    ( pak, 0x73 );//Change player status
        ADDBYTE    ( pak, 0x00 );
        ADDBYTE    ( pak, channel );//CANAL
        ADDWORD    ( pak, 0x0000 );
        ADDWORD    ( pak, 0x0000 );
        ADDWORD    ( pak, thisclient->level );
        ADDWORD    ( pak, thisclient->job );
        ADDSTRING  ( pak, thisclient->charname );
        ADDBYTE    ( pak, 0x00 );
        otherclient->SendPacket(&pak); 
        return true;
}

// Clan chat
bool CCharServer::pakClanChat ( CCharClient* thisclient, CPacket* P )
{
    if(!thisclient->isLoggedIn)
        return false;
    char* tmp;
	if (P->Buffer[0]=='/') 
    {
        char* command = strtok( (char*)&(*P).Buffer[1] , " ");
        if(command==NULL)
            return true;
        if(strcmp(command, "pak")==0)//read cpacket.txt and send it (for test packets)
        {
            int comando = 0;
            if ((tmp = strtok(NULL, " "))==NULL)
                return true;
            comando=atoi(tmp);     
            char buffer;                              
            FILE *packet1 = fopen("cpacket.txt","r");                 
            BEGINPACKET(pak,comando);               
            if(packet1==NULL)
            {
                printf("Error opening packet1.txt for 716!\n");
                return true;
            }
            while((fscanf(packet1,"%c",&buffer))!=EOF)
                    ADDBYTE(pak,buffer);
            fclose(packet1);
    		thisclient->SendPacket( &pak );            
    		return true;
        }
    }    
    char* text = new (nothrow) char[P->Size-6];
    if(text==NULL)
    {
        Log(MSG_ERROR, "Error allocing memory" );
        return false;
    }
    memcpy( text, &P->Buffer, P->Size-6 );
    CClans* thisclan = (CClans*) GetClanByID ( thisclient->clanid );
    if(thisclan!=NULL)
    {
            BEGINPACKET( pak, 0x787 );
            ADDSTRING  ( pak, thisclient->charname );
            ADDBYTE    ( pak, 0x00 );
            ADDSTRING  ( pak, text );
            ADDBYTE    ( pak, 0x00 );
            SendToClanMembers(thisclan->id,&pak);
    }
    delete []text;
    return true;
}

// Clan manager for all the clan functions
bool CCharServer::pakClanManager ( CCharClient* thisclient, CPacket* P )
{    
    if(!thisclient->isLoggedIn) return false;
    MYSQL_RES *result;
	MYSQL_ROW row;
    BYTE action = GETBYTE ((*P),0);
    switch (action)
    {
        case 0x01:
        break;
        case 0x02://invite clan
        {
            char* nick = new (nothrow) char[P->Size-7];
            if(nick==NULL)
            {
                Log(MSG_ERROR, "Error allocing memory" );
                return false;
            }
            memcpy( nick, &P->Buffer[1], P->Size-7 );
            if(strcmp(nick,thisclient->charname)==0)
                return true;                 
            CCharClient* otherclient = (CCharClient*) GetClientByName( nick );
            if(otherclient!=NULL)
            {
                BEGINPACKET( pak, 0x7e0 );
                ADDBYTE    ( pak, 0x0b );//invite action
                ADDSTRING  ( pak, thisclient->charname );
                ADDBYTE    ( pak, 0x0 );
                otherclient->SendPacket( &pak );
            }
            delete []nick;
        }
        break;
        case 0x03://Kick from clan
        {
            char* nick = new (nothrow) char[P->Size-7];
            if(nick==NULL)
            {
                Log(MSG_ERROR, "Error allocing memory" );
                return false;
            }
            memcpy( nick, &P->Buffer[1], P->Size-7 );                  
           CClans* thisclan = GetClanByID(thisclient->clanid);     
           if(thisclan==NULL)
           {
                delete []nick;
                return true;                
            }
            BEGINPACKET( pak, 0x7e0 );
	        ADDBYTE    ( pak, 0x81 );//xxx have kicket to yyyy
	        ADDSTRING  ( pak, thisclient->charname );
	        ADDBYTE    ( pak, 0x00);
	        ADDSTRING  ( pak, nick );
	        ADDBYTE    ( pak, 0x00);
            SendToClanMembers(thisclient->clanid,&pak); 
            for(UINT i=0;i<thisclan->ClanMembers.size( );i++)
            {
                CClanMembers* ClanMember =  thisclan->ClanMembers.at( i );
                if(strcmp(ClanMember->name,nick)==0)
                {
                    thisclan->ClanMembers.erase( thisclan->ClanMembers.begin() + i );
                    break;              
               }   
            }   
                                     
           CCharClient* otherclient = (CCharClient*) GetClientByName( nick ); 
           if( otherclient!=NULL )                                              
           {
               otherclient->clanid = 0;
               otherclient->clan_rank=1;                     
	           RESETPACKET( pak, 0x7e1 );//Update world clan information
	           ADDBYTE    ( pak, 0xfb );//action (kick)
	           ADDSTRING  ( pak, nick ); 
	           ADDBYTE    ( pak, 0x00 );
 	           cryptPacket( (char*)&pak, NULL );
 	           CChanels* thischannel = GetChannelByID( otherclient->channel );
 	           if(thischannel!=NULL)
 	           {
        	       send( thischannel->sock, (char*)&pak, pak.Size, 0 );    
               }
               pakClanMembers( otherclient );            
            }           
            if(!DB->QExecute("UPDATE characters SET clanid=0 AND clan_rank=1 WHERE char_name='%s'",nick))
            {
                delete []nick;
                return false;            
            }
            delete []nick;
        }  
        break;        
        case 0x04://up rank
        {
            char* nick = new (nothrow) char[P->Size-7];
            if(nick==NULL)
            {
                Log(MSG_ERROR, "Error allocing memory" );
                return false;
            }
            memcpy( nick, &P->Buffer[1], P->Size-7 );
            int clan_rank=0;
            int level=0;
            int job=0;
            int channel=0xff;            
            if(strcmp(nick,thisclient->charname)==0)
            {
                delete []nick;
                return true;
            }
            CCharClient* otherclient = GetClientByName ( nick );
            if(otherclient!=NULL)
            {
                clan_rank = otherclient->clan_rank;                   
                if(otherclient->clan_rank<5)
                {                    
                    otherclient->clan_rank++;
                }                           
                else
                {
                    delete []nick;
                    return true;
                }      
                job = otherclient->job;
                level = otherclient->level;                
                channel=otherclient->channel;
	            BEGINPACKET( pak, 0x7e0 );
	            ADDBYTE    ( pak, 0x83 );
	            ADDSTRING  ( pak, nick ); 
	            ADDBYTE    ( pak, 0x00 );	           
	            ADDBYTE    ( pak, otherclient->clan_rank );
                otherclient->SendPacket(&pak);                
            }
            else
            {                   
                result = DB->QStore("SELECT clan_rank,classid,level FROM characters WHERE char_name='%s'",nick);
                if(result==NULL)
                {
                    delete []nick;
                    return false;
                }
                if(mysql_num_rows(result)!=1)
                {
                    Log(MSG_WARNING, "Invalid charname: %s" , nick );
                    delete []nick;
                    return false;
                }
	            row = mysql_fetch_row( result );		            
                clan_rank=atoi(row[0]);                       
                job = atoi(row[1]);
                level = atoi(row[2]);
                DB->QFree( );       
            }            
            if(clan_rank<5)
            {
                clan_rank++;
            }
            if(!DB->QExecute("UPDATE characters SET clan_rank=%i WHERE char_name='%s'",clan_rank,nick))
            {
                delete []nick;
                return false;
            }
            BEGINPACKET( pak, 0x7e0 );
            ADDBYTE    ( pak, 0x75 );//
            ADDBYTE    ( pak, clan_rank );
            ADDBYTE    ( pak, channel );//channel 
            ADDWORD    ( pak, 0x0000 );
            ADDWORD    ( pak, 0x0000 );
            ADDWORD    ( pak, level ); // level
            ADDWORD    ( pak, job ); // job
            ADDSTRING  ( pak, nick ); // Nick
            ADDBYTE    ( pak, 0x00 );
            SendToClanMembers(thisclient->clanid,&pak);
                                   
	        RESETPACKET( pak, 0x7e1 );//update world information
	        ADDBYTE    ( pak, 0xfc );
	        ADDBYTE    ( pak, clan_rank );
	        ADDSTRING  ( pak, nick ); 
	        ADDBYTE    ( pak, 0x00 );
	        cryptPacket( (char*)&pak, NULL );
 	        CChanels* thischannel = GetChannelByID( channel );
 	        if(thischannel!=NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -