realtimenetprots/sipfw/SampleApp/gameengine/Src/SIPExStateRemote.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 
       
     2 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include    "SIPExStateRemote.h"
       
    21 #include    "SIPExGameEngine.h"
       
    22 #include    "SIPExSIPEngine.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // TSIPExStateRegistering::SocketData
       
    26 // Resolves the move or message from remote player.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 void TSIPExStateRemote::SocketData( CSIPExEngine* aContext, TDesC8& aData )
       
    30     {
       
    31     // The length is fixed to 4. Format is "x, y".
       
    32 	if ( aData.Length() == 4 ) 
       
    33         {
       
    34         TBuf<1> buffer;
       
    35         buffer.Copy( aData.Mid( 0, 1 ) );
       
    36         TLex lex( buffer );
       
    37 		TInt x( 0 );
       
    38 		TInt y( 0 );
       
    39         lex.Val( x );
       
    40         buffer.Copy( aData.Mid( 3, 1 ) );
       
    41         lex.Assign( buffer );
       
    42         lex.Val( y );
       
    43 
       
    44 		aContext->SetRemote( x, y );
       
    45         aContext->IncreaseMovesBy( 1 );
       
    46 
       
    47         TInt ret = aContext->IsWin(x,y);
       
    48 		aContext->SetCursor( x );
       
    49 		if (ret > 0) 
       
    50             {
       
    51             ChangeState( aContext, aContext->iStateRegistered );
       
    52             StatusInfo( aContext, KYouLose() );
       
    53 		    } 
       
    54         else  if ( aContext->Moves() == KMaxMoves) 
       
    55             {
       
    56             ChangeState( aContext, aContext->iStateRegistered );
       
    57 			StatusInfo( aContext, KGameTie() );
       
    58 		    } 
       
    59         else 
       
    60             {
       
    61             ChangeState( aContext, aContext->iStateLocal );
       
    62 			StatusInfo( aContext, KYourMove() );
       
    63 		    }
       
    64 	    } 
       
    65     else 
       
    66         {
       
    67         HBufC* buf = HBufC::NewLC( aData.Length() );
       
    68         buf->Des().Copy( aData );
       
    69         aContext->InfoL( *buf );
       
    70         CleanupStack::PopAndDestroy( buf );
       
    71         }
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // TSIPExStateRegistering::SendInstantMsgL
       
    76 // Calls base classes function to send the instant message.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void TSIPExStateRemote::SendInstantMsgL( CSIPExEngine* aContext, 
       
    80             const TDesC& aAddress, const TDesC& aMsg )
       
    81     {
       
    82     HBufC8* addr = HBufC8::NewLC( aAddress.Length() );
       
    83     addr->Des().Copy( aAddress );
       
    84 
       
    85     HBufC8* msg = HBufC8::NewLC( aMsg.Length() );
       
    86     msg->Des().Copy( aMsg );
       
    87 
       
    88     aContext->SIPEngine()->CreateIML( *msg, *addr );
       
    89 
       
    90     CleanupStack::PopAndDestroy( msg );
       
    91     CleanupStack::PopAndDestroy( addr );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // TSIPExStateRegistering::DisableProfile
       
    96 // Notifies the UI.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void TSIPExStateRemote::DisableProfileL( CSIPExEngine* aContext )
       
   100     {
       
   101     aContext->InfoL( KGameAlreadyRunning() );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // TSIPExStateRegistering::EndGameL
       
   106 // Notifies the UI and changes the active state to the Registered.
       
   107 // The socket engine will be deleted and the SIP session ended.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void TSIPExStateRemote::EndGameL( CSIPExEngine* aContext )
       
   111     {
       
   112     aContext->SIPEngine()->EndSessionL();
       
   113     }
       
   114 
       
   115 // End of file