예제 #1
0
void* NetworkManager::threadConnexion(void* arguments)
{
	NetworkManager * networkManager = static_cast<NetworkManager *>(arguments) ;

	while ((enet_host_service (networkManager->client,&networkManager->eventClient, 10) >= 0 ) && (networkManager->endThread == false )  )
	{
		switch (networkManager->eventClient.type)
		{
		case ENET_EVENT_TYPE_CONNECT:
			networkManager->callback((XSILIUM_ALL * 1000) + ID_CONNEXION);
			break;
		case ENET_EVENT_TYPE_RECEIVE:
		{
			MessagePacket * message = new MessagePacket();

			std::istringstream archive_stream(std::string((char*)networkManager->eventClient.packet->data));
			boost::archive::text_iarchive archive(archive_stream);
			archive >> message;

			networkManager->callback(message->getOpcode(),message);
			break;
		}

		case ENET_EVENT_TYPE_DISCONNECT:
			networkManager->callback((XSILIUM_ALL * 1000 ) + ID_DECONEXION);
			networkManager->endThread = true;
			break;
		default:
			break;
		}
        enet_packet_destroy (networkManager->eventClient.packet);
	}
	return NULL;
}
예제 #2
0
ChannelMessage::ChannelMessage(MessagePacket packet)
  : Message(packet->id(), QByteArray(), LS("channel"), LS("addChannelMessage"))
  , m_packet(packet)
{
  setDate(m_packet->date());
  setAuthor(m_packet->sender());
  m_tab = detectTab(m_packet->sender(), m_packet->dest());

  if (!m_packet->internalId().isEmpty())
    m_data.insert(kInternalId, ChatId(m_packet->internalId()).toString());

  m_data.insert(kCommand,   packet->command());
  m_data.insert(kDirection, m_packet->sender() == ChatClient::id() ? kOutgoing : kIncoming);

  /// Если это собственное сообщение, то для него при необходимости устанавливается
  /// статус "offline" или "rejected".
  const int status = packet->status();
  if (isOffline(status))
    m_data.insert(kStatus, kOffline);
  else if (status != Notice::OK && status != Notice::Found && status < Notice::UserStatus)
    m_data.insert(kStatus, kRejected);

  if (status == MessageNotice::Removed) {
    m_data.insert(kStatus, kRemoved);
    m_data.insert(kText, QString(LS("<span class='message-removed' data-tr='message-removed'>%1</span> <i class='message-trash'></i>")).arg(WebBridge::i()->translate("message-removed")));
  }
  else
    m_data.insert(kText, TokenFilter::filter(LS("channel"), packet->text(), 0, packet->id()));

  if (!packet->oid.isNull()) {
    m_data.insert(kOID, QString(ChatId::toBase32(packet->oid.byteArray())));
    m_data.insert(kMDate, packet->mdate);
  }
}
예제 #3
0
int SendFileMessages::read(MessagePacket packet)
{
  if (packet->command() != LS("file"))
    return 0;

  if (SimpleID::typeOf(packet->id()) != SimpleID::MessageId)
    return 0;

  m_plugin->read(packet);
  return 1;
}
예제 #4
0
int ShareMessages::read(MessagePacket packet)
{
  if (packet->command() != LS("image") || Hooks::MessagesImpl::isIgnored(packet))
    return 0;

  if (ChatId(packet->id()).type() != ChatId::MessageId)
    return 0;

  m_share->read(packet);
  return 1;
}
예제 #5
0
string  ArscImpl::test(string stringTest){	
MessagePacket tk = MessagePacket(stringTest);
try{
	tk=arsmStub->selfTest(tk);
}catch(SelfTestException e)
{
	cerr << e.getMessage() << endl;
	throw SelfTestException();
}
	
return tk.getStream() ;	
  	
  }
예제 #6
0
void Stollmann::comTransport(HANDLE h, int eventNo, bool a3, void *buffer, uint32 size)
{
	if(eventNo != 3)
		return;

	MessagePacket *packet = (MessagePacket*)new uint8[size+sizeof(MessagePacket)];

	DbgPrint("Com read, handle: %08X", h);
	memcpy(packet->getData(), buffer, size);
	packet->length = size;
	packet->description[0] = '\0';
	packet->type = RECV;

	sendMessagePacket(packet);

	delete []packet;
}
예제 #7
0
// Stollmann hooks
int Stollmann::comWrite(HANDLE h, void* buffer, int size)
{
	MessagePacket *packet = (MessagePacket*)new uint8[size+sizeof(MessagePacket)];
	
	if(comHandle == NULL)
		comHandle = h;

	DbgPrint("Com write, handle: %08X", h);
	memcpy(packet->getData(), buffer, size);
	packet->length = size;
	packet->description[0] = '\0';
	packet->type = SEND;

	sendMessagePacket(packet);

	delete []packet;
	return pComWrite(h, buffer, size);
}
예제 #8
0
void Stollmann::pythonComWrite(void* buffer, int size)
{
	// Guard
	if(comHandle == NULL)
		return;

	MessagePacket *packet = (MessagePacket*)new uint8[size+sizeof(MessagePacket)];

	DbgPrint("Python com write, handle: %08X", comHandle);
	packet->reset();
	memcpy(packet->getData(), buffer, size);
	packet->length = size;
	packet->type = INJECT_SEND;

	sendMessagePacket(packet);

	delete []packet;
	pComWrite(comHandle, buffer, size);
}
예제 #9
0
   MessagePacket::MessagePacket(const MessagePacket& messagePacket)
      : GNE::Packet(MessagePacket::ID)
   {
      mMessageId = messagePacket.mMessageId;
      mDestination = messagePacket.mDestination;
      mSource = messagePacket.mSource;

      mSendingActor = messagePacket.mSendingActor;
      mAboutActor = messagePacket.mAboutActor;

      mMessageParameters = messagePacket.GetMessageParameters();
   }
예제 #10
0
string ArscImpl::checkSignature(string messageStream)
{
	MessagePacket signedMessagePacket = MessagePacket(messageStream);
	
	gss_qop_t qopState;
	gss_buffer_desc *in_buf, *out_buf;
	int state=wrap;
	OM_uint32 minorStatus,majorStatus;
	in_buf=(gss_buffer_t) malloc(sizeof(gss_buffer_desc));
	in_buf->value = (void*) signedMessagePacket.getMsg().c_str();
	in_buf->length = signedMessagePacket.getMsg().length();
	out_buf=(gss_buffer_desc*) malloc(sizeof(gss_buffer_desc));
	majorStatus = gss_unwrap(&minorStatus,
							 context,
							 in_buf,
							 out_buf,
							 &state,
							 (gss_qop_t *) NULL);

	// TODO release buffer
   // gss_release_buffer(minorStatus,&messageBuffer);
	//gss_release_buffer(minorStatus,&signToken);
							
	if(majorStatus != GSS_S_COMPLETE)
	{
		cerr<<"Data Verify error."<<endl;
		throw SignatureCheckingException();	
	}else	
		{
			if (! state) { 
			cerr<<"Warning! Message not encrypted.\n"<<endl; 
			}	
		cout << "Data Verify sucessfull. : \n" <<endl;	
		return string((char *)out_buf->value,out_buf->length);
		}
		 return MessagePacket().getStream();
   
}
예제 #11
0
파일: main.cpp 프로젝트: carriercomm/xztech
int main ( int argc, char * const argv[] ) 
{
    Crypto  *crypto         = new Crypto();
    bool    loggedIn        = false;
    time_t  last_ping       = time( NULL );
    
    Socket  a_socket( crypto );
    Socket  g_socket( crypto );
    
    GameMap     *gameMap        = new GameMap( &g_socket );
    Dialogue    *dialogue       = new Dialogue();
    MapFile     *mapFile        = new MapFile();
    User        *user           = new User( &g_socket, gameMap, dialogue, mapFile );
    
    AccountInfo                     acct_info;
    std::vector< PET_PACKET >       PetList;
    
    char path[255];
    strcpy( path, GAMEFILESPATH );
    strcat( path, "ini/map.ini" );
    
    mapFile->process( path );
    
    initTime();
    srand( time( NULL ) );
    
    if ( argc != 2 )
        acct_info = account_info( "Whitey" );
    else
        acct_info = account_info( argv[1] );
    
    if ( !strcmp( acct_info.username, "NOTFOUND" ) || 
        !strcmp( acct_info.username, "" ) || 
        !strcmp( acct_info.password, "" ) ||
        !strcmp( acct_info.serverip, "" ) ||
        !strcmp( acct_info.servername, "" ) )
    {
        std::cout   << "Error: .account_info.conf must include a username and password, "
                    << "and optionally a server and protection code." << std::endl;
    }
    
    if ( !a_socket.connect( acct_info.serverip, ACCOUNTPORT ) )
        return 0;
    
    g_socket = login( a_socket, crypto, acct_info );
	
    while ( true )
    {
        g_socket.select();
		
        if ( g_socket.is_readable() )
        {
            CPacket packet;
			
            packet = g_socket.read_packet();
			
            if ( packet.header.size == 0 && packet.header.id == 0 )
            {
                std::cout << "Error while reading packet... time: " << timeGetTime() << std::endl;
                return 0;
            }
            
            if ( difftime( last_ping, time( NULL ) ) >  300 )
                return 0;
            
            switch ( packet.header.id )
            {
                case 1002:
                {
                    memset( ( void * )( packet.data + 0x04 ), 0, packet.header.size - sizeof( CPacketHeader ) );
                    packet.data[8] = 0xC5;
					
                    g_socket.send_packet( packet );
				}
                    
                    break;
					
                case 1004:
                {
                    MessagePacket *msg = new MessagePacket( packet );
                    
                    if ( msg->m_channel == CH_SYSTEM )
                        printf( "[%s]%s\n", msg->m_channelName, msg->m_message );
                    else if ( msg->m_channel == CH_VENDOR )
                        printf( "[%s](%s): %s\n", msg->m_channelName, 
                               msg->m_sender, msg->m_message );
                    else
                        printf( "[%s]%s %s speaks to %s: %s\n", msg->m_channelName, msg->m_sender, msg->m_emotion, 
                               msg->m_target, msg->m_message );
                    
                    if ( strcmp( msg->m_sender, OWNER ) && msg->m_channel == CH_PRIVATE )
                    {                        
                        MessagePacket *fffffu = new MessagePacket( user->m_name, msg->m_sender, "F**k you, stop PMing me.", CH_PRIVATE );
                        
                        g_socket.send_packet( fffffu->pack() );
                        
                        delete fffffu;
                    }
                    
                    if ( !strcmp( msg->m_sender, OWNER ) && msg->m_channel == CH_PRIVATE )
                    {
                        if ( !strcmp( msg->m_message, "@givemoney" ) )
                        {
                            PlayerList playerlist = gameMap->list_players();
                            PlayerList::iterator it;
                            
                            for ( it = playerlist.begin(); it != playerlist.end(); it++ )
                                user->give_money( it->first, 1 );
                        }
                    }
                    
                    delete msg;
                }
					
                    break;
					
                case 1005:
                {
                    WalkPacket  *walk   = new WalkPacket( packet );
                    Player      *player = gameMap->find_player( walk->m_playerID );
                    
                    if ( player->m_id == -1 )
                    {
                        delete player;
                        break;
                    }
                    
                    player->m_x = walk->m_destX;
                    player->m_y = walk->m_destY;

                    //printf( "%s has moved to [%d, %d]\n", PlayerList[id].m_name, x, y );
                    
                    delete walk;
                }
                    break;
				
                case 1006:
                {
                    ActionPacket    *action = new ActionPacket( packet );
                    Player          *player = gameMap->find_player( action->m_playerID );
                    
                    if ( player->m_id == -1 )
                    {
                        delete player;
                        break;
                    }
                    
                    break;
                    
                    switch ( action->m_actionID )
                    {
                        case 4:
                            printf( "* %s faints.\n", player->m_name );
                            break;
							
                        case 6:
                            printf( "* %s waves.\n", player->m_name );
                            break;
							
                        case 7:
                            printf( "* %s kneels.\n", player->m_name );
                            break;
							
                        case 8:
                            printf( "* %s is crying.\n", player->m_name );
                            break;
							
                        case 9:
                            printf( "* %s is angry.\n", player->m_name );
                            break;
							
                        case 10:
                            printf( "* %s sits.\n", player->m_name );
                            break;
							
                        case 12:
                            printf( "* %s is happy.\n", player->m_name );
                            break;
							
                        case 13:
                            printf( "* %s bows.\n", player->m_name );
                            break;
						
                        case 15:
                            printf( "* %s throws.\n", player->m_name );
                            break;
							
                        default:
                            printf( "* Unknown action preformed by %s [%d]\n", player->m_name, action->m_actionID );
                            break;
                    }
                    
                    delete action;
                }
					
                    break;
					
                case 1007:
                {
                    JumpPacket  *jump   = new JumpPacket( packet );
                    Player      *player = gameMap->find_player( jump->m_playerID );
                    
                    if ( player->m_id == -1 )
                    {
                        delete player;
                        break;
                    }
                    
                    if ( jump->m_mode == 2 )
                    {
                        player->m_x = jump->m_x;
                        player->m_y = jump->m_y;
                        
                        //printf( "%s has moved to [%d, %d]\n", PlayerList[id].m_name, x, y );
                    }
                    else if ( jump->m_direction == 8 )
                    {
                        //printf( "%s has left the map.\n", PlayerList[id].m_name );
                        
                        printf( "%s has left the map.\n", player->m_name );
                        
                        char msg[55];
                        strcpy( msg, "Cya later, " );
                        strcat( msg, player->m_name );
                        
                        MessagePacket *bai = new MessagePacket( user->m_name, player->m_name, msg, CH_PRIVATE );
                        
                        g_socket.send_packet( bai->pack() );
                        
                        delete bai;
						
                        gameMap->del_player( jump->m_playerID );
                    }
                    
                    delete jump;
                }
					
                    break;
					
                case 1008:
                {
                    CharInfoPacket *info = new CharInfoPacket( packet );
                    
                    user->process( info );
                    user->m_accountID = account_id;
                    
                    delete info;
                }
                    
                    break;
					
                case 1020:
                {
                    int response = timeGetTime() ^ ( ( user->m_characterID * user->m_characterID ) + 0x2537 );
					
                    memcpy( ( void * )( packet.data + 0x04 ), ( void * )&response, sizeof( response ) );
					
                    g_socket.send_packet( packet );
                }
					
                    break;
                
                case 1031:
                {
                    MapInfoPacket *info = new MapInfoPacket( packet );
                    gameMap->process( info );
                    
                    dialogue->m_open = false;
                    
                    user->m_x = info->m_x;
                    user->m_y = info->m_y;
                    
                    printf( "Entered: %s\n", gameMap->m_name );
					
                    if ( !loggedIn )
                    {
                        user->jump( 0, 0, 19, 0 );
                        
                        if ( strcmp( acct_info.pcode, "" ) )
                        {
                            char unlock[255];
                            
                            strcpy( unlock, "/unlock " );
                            strcat( unlock, acct_info.pcode );
                            
                            MessagePacket *umsg = new MessagePacket( user->m_name, user->m_name, unlock, CH_PRIVATE );
                            g_socket.send_packet( umsg->pack() );
                            delete umsg;
                        }
                        
                        MessagePacket *pokeman = new MessagePacket( user->m_name, "All", "A wild BlakeKing appears!", CH_NORMAL );
                        
                        g_socket.send_packet( pokeman->pack() );
                        
                        delete pokeman;
                    }
                    
                    delete info;
                }
					
                    break;
					
                case 1032:
                {
                    Player *player = new Player( packet );
                    
                    gameMap->add_player( player );
                    
                    //printf( "%s has entered the map (%d, %d)\n", player.m_name, player.m_x, player.m_y );
                    
                    if ( loggedIn )
                    {
                        char msg[55];
                        strcpy( msg, "Welcome to Water City, " );
                        strcat( msg, player->m_name );
                        
                        MessagePacket *hai = new MessagePacket( user->m_name, player->m_name, msg, CH_PRIVATE );
                        
                        g_socket.send_packet( hai->pack() );
                        
                        delete hai;
                    }
                    
                    delete player;
                }
					
                    break;
                    
                case 1033:
                {
                    /*int pet_id = *( int * )packet.data;
                    std::vector< PET_PACKET >::iterator it;
                    
                    for ( it = PetList.begin(); it != PetList.end(); it++ )
                        if ( it->id == pet_id ) 
                            printf( "Marching Pet: %s\n\n", it->name );*/
                }

                    break;
                    
                case 1034:
                {
                    PET_PACKET pp;
                
                    memcpy( ( void * )&pp, ( void * )packet.data, ( packet.header.size - sizeof( CPacketHeader ) ) );

                    PetList.push_back( pp );
                }
                    
                    break;
                    
                case 1038:
                {
                    last_ping = time( 0 );
                    
                    if ( !loggedIn )
                        loggedIn = true;
                }
                    
                    break;
                    
                case 1043: 
                {
                    // Has more data that needs to be reversed
                    /* Don't want to write a class for this quite yet, because
                     * I want to see if this packet is used when a player changes
                     * their actual body in the reborn room, or if it's just
                     * for disguising as a pet.
                     */
                    int     id      = *( int * )packet.data;
                    Player  *player = gameMap->find_player( id );
                    
                    if ( player->m_id == -1 )
                    {
                        delete player;
                        break;
                    }
                    
                    //printf( "* %s has disguised as a pet.\n", player->m_name );
                }
                    break;
					
                case 1050:
                    /* Why don't i have anything for this packet? It's the first
                     * Received packet from the game server...
                     */
                    break;
                    
                case 2030:
                {
                    NpcInfoPacket   *info   = new NpcInfoPacket( packet );
                    Npc             *npc    = new Npc( info );
                    
                    gameMap->add_npc( npc );
                    
                    //printf( "* Added NPC: %s (id=%d)(type=%d)\n", npc->m_name, npc->m_id, npc->m_type );
                    
                    delete info;
                    delete npc;
                }
                    
                    break;
                    
                case 2031:
                {
                    NpcUpdatePacket *update = new NpcUpdatePacket( packet );
                    
                    if ( update->m_action == 3 )
                        gameMap->del_npc( update->m_npcID );
                    
                    delete update;
                }
                    
                    break;
                    
                case 2033:
                {
                    NpcDialoguePacket *dialog = new NpcDialoguePacket( packet );
                    dialogue->process( dialog );
                    
                    delete dialog;
                }
                    
                    break;
					
                default:
                    /*printf( "ID: %d Length: %d Data:\n", packet.header.id, packet.header.size );
                    hexdump( ( void * )packet.data, ( packet.header.size - sizeof( CPacketHeader ) ) );
                    printf( "\n");*/
                    break;
            }
        }
    }
    
    return 1;
}
예제 #12
0
 int  ArscImpl::initContext(){
if(auth())
 	{
		gss_buffer_desc send_token;
		gss_buffer_desc *token_ptr;
		gss_name_t target_name;
		MessagePacket msgIn , msgOut;
		OM_uint32 min_stat,maj_stat,init_sec_min_stat;
		OM_uint32 *ret_flags=(OM_uint32*)malloc(sizeof(OM_uint32));
		string serviceName(SERVICENAME);
		send_token.value = (void *) serviceName.c_str();
		send_token.length = serviceName.length();
		maj_stat = gss_import_name(&min_stat,&send_token,(gss_OID)  gss_nt_user_name ,&target_name);
		if(maj_stat != GSS_S_COMPLETE)
		{
			display_status("inicializing context",maj_stat,min_stat);
			(void) gss_release_name(&min_stat, &target_name);
			return 0;
		}
				
		 token_ptr = GSS_C_NO_BUFFER;
		 context = GSS_C_NO_CONTEXT;
		 
		do {
			maj_stat = gss_init_sec_context(&init_sec_min_stat,
					     GSS_C_NO_CREDENTIAL,
					    &context,
					     target_name,
					     GSS_C_NULL_OID,
					     GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG,
					     0,
					     NULL, // no chanel bindings
					     token_ptr,
					     NULL, // ignore mech type
					     &send_token,
					     ret_flags,
					     NULL); // ignore time_rec
				

		if(send_token.length != 0){
			msgOut = MessagePacket(std::string(id),
			std::string((char*)send_token.value,send_token.length));
			try{
				msgIn = (*arsmStub).initiateContext(msgOut);
			}catch(ContextInitiationException &e)
			{
				cerr << e.getMessage() << endl;
				return 0;
			}
		}
		(void) gss_release_buffer(&min_stat,&send_token);
		if(maj_stat!=GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED){
			display_status("initializing context",maj_stat,init_sec_min_stat);
			(void) gss_release_name(&min_stat,&target_name);
			if(context != GSS_C_NO_CONTEXT){
			//	(void) gss_delete_sec_context(&min_stat,context, GSS_C_NO_BUFFER);
			}
			return 0;
		}
		
		if(maj_stat == GSS_S_CONTINUE_NEEDED){
			 free(token_ptr);
			 token_ptr=(gss_buffer_desc*) malloc(sizeof(gss_buffer_desc));
			 token_ptr->value = (void *) msgIn.getMsg().c_str();
			 token_ptr->length = (int) msgIn.getMsg().length();
		}	
		} while( maj_stat == GSS_S_CONTINUE_NEEDED);
		(void) gss_release_name(&min_stat,&target_name);
		printf("Context created. %s\n",id.c_str());
			return 1;
	 	} else
	 	{
			exit(2);
	 	}
 }