Exemplo n.º 1
0
bool PUdpSubskillInc::DoAction()
{
    PClient* nClient = mDecodeData->mClient;
    PChar* nChar = nClient->GetChar();

    // Function tries to increase given subskill. If it fails, returnvalue is -1.
    // If success, returnvalue is amount of skillpoints left
    int tRemainingSkillPoints = 0;
    tRemainingSkillPoints = nChar->Skill->IncreaseSubSkill(SubskillID);

    if ( tRemainingSkillPoints > -1 )
    {
        PMessage* tmpMsg = MsgBuilder->BuildSubskillIncMsg(nClient, SubskillID, tRemainingSkillPoints); // last is remaining skillpoints
        nClient->SendUDPMessage(tmpMsg);
    }
    else
    {
        // Send NACK, or just ignore..
    }
    /*if(nChar->Skill->IncSubSkillPossible(SubskillID) == true)
    {
        int tRemainingSkillPoints = 0;
        nChar->Skill->IncreaseSubSkill(SubskillID); // SubskillID
        PMessage* tmpMsg = MsgBuilder->BuildSubskillIncMsg(nClient, SubskillID, tRemainingSkillPoints); // last is remaining skillpoints
        nClient->SendUDPMessage(tmpMsg);
    }*/

    mDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
    return true;
}
Exemplo n.º 2
0
bool PUdpHeldItemAimedAction::DoAction()
{
  u16 maxBroadcastDistance = 0; // parameter.
  PClient* nClient = mDecodeData->mClient;
  //PChar* tChar = nClient->GetChar();
//  PCharCoordinates& nCharCoords = nClient->GetChar()->Coords;
  PMessage* tmpMsg;

  // IF APU SPELL
  //10: 03:be:00:1f:[02:00]:25:1a:[68:11:96:43]:[78:de:12:00:] = ????
  //tmpMsg = MsgBuilder->BuildHeldItemUse3Msg( nClient, 0x1168, 0x4369, 0xde78, 0x0012 ); // unknwon use, unknown data (spells duration/delays ?)
  //nClient->SendUDPMessage(tmpMsg);

  //tmpMsg = MsgBuilder->BuildHeldItemUse2Msg( nClient->GetLocalID(), mTargetRawItemID ); // start spell invocation
  //ClientManager->UDPBroadcast( tmpMsg, nClient, maxBroadcastDistance );

  // END IF APU SPELL

  tmpMsg = MsgBuilder->BuildHeldItemUseMsg( nClient->GetLocalID(), mWeaponId, mTargetRawItemID, mAiming, mTargetedHeight, 0 ); // 'score' is not broadcasted, but set to 0
  ClientManager->UDPBroadcast( tmpMsg, nClient, maxBroadcastDistance, true );

  // IF APU SPELL
  // After spell invocation delay
  // 03:8b:00:1f:[02:00]:2c:01:?[ae:bf]?:?[f5:45]?:[00:20:01:00]:[0e]:
  tmpMsg = MsgBuilder->BuildHeldItemUse4Msg( nClient->GetLocalID(), mTargetRawItemID, 0xaebf, 0x45f5, mTargetedHeight );
  ClientManager->UDPBroadcast( tmpMsg, nClient, maxBroadcastDistance );
  // END IF APUI SPELL

  //if ( gDevDebug )
  Console->Print( "%s Handled item action toward target %d (0x%08x) weaponId=%d aiming=%d 'height'=%d 'score'=%d", Console->ColorText( CYAN, BLACK, "[DEBUG]" ), mTargetRawItemID, mTargetRawItemID, mWeaponId, mAiming, mTargetedHeight, mScore );
  //mDecodeData->mMessage->Dump();

  mDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
  return true;
}
Exemplo n.º 3
0
void PGameServer::Update()
{
  if ( ServerSock->newConnection() )
  {
    int clid = Server->NewClient();
    if ( clid != -1 )
    {
      Console->Print( GREEN, BLACK, "[Info] Gameserver: client [%i] connected", clid );
      PClient *Client = Server->GetClient( clid );
      if ( Client->getTCPConn() ) Console->Print( RED, BLACK, "WARNING: Client %d : TCP Socket NOT NULL before allocation.", Client->GetID() );
      ConnectionTCP* tcpConn = ServerSock->getTCPConnection();
      Client->setTCPConnection( tcpConn );

      //ConnectionUDP* udpConn = ServerSock->getUDPConnection();
      //Client->setUDPConnection(udpConn);

      Console->Print( "Client address: %s", Client->GetAddress() );
      ++mNumClients;

      PGameState *state = new PGameState();
      ClientStates.insert( std::make_pair( Client, state ) );
      state->TCP.mState = PGameState::TCP::GS_CONNECTED;

      // add the new connected client to the global clientmanager for further use in chat, etc...
      ClientManager->addClientToList( Client );
    }
    else
    {
      Console->Print( YELLOW, BLACK, "[Notice] Gameserver: Client connection refused (server full?)" );
    }
  }

  /*** temp check ***/
  for ( PClientMap::iterator it = ClientManager->getClientListBegin(); it != ClientManager->getClientListEnd(); it++ )
  {
    if ( !it->second )
    {
      Console->Print( RED, BLACK, "PANIC: NULL Client found in ClientManager Clients Map." );
    }
  }
  /*** end temp check ***/

  for ( GameStateMap::iterator i = ClientStates.begin(); i != ClientStates.end(); )
  {
    PClient *Client = i->first;
    PGameState *State = i->second;
    // node gets erased in FinalizeClient, increment iterator now
    ++i;
    if ( !ProcessClient( Client, State ) )
      FinalizeClient( Client, State );
  }
}
Exemplo n.º 4
0
bool PUdpHeldItemLaunchingAction::DoAction()
{
  PClient* nClient = mDecodeData->mClient;
  PChar* tChar = nClient->GetChar();
  PWorld* CurrentWorld = Worlds->GetWorld( tChar->GetLocation() );
  const PFurnitureItemTemplate* tFurnitureTemplate = NULL;
  const PDefWorldModel* tFurnitureModel = NULL;

  u32 mRawItemID = mDecodeData->mMessage->U32Data( mDecodeData->Sub0x13Start + 24 );
  //if(gDevDebug) Console->Print("Client %d wants to hack itemID %d ***not managed yet***", mDecodeData->mClient->GetID(), mRawItemID);

  // First try to find out if we're hacking an dynamic actor
  if ( WorldActors->IsDynamicActor( mRawItemID ) == true )
  {
    // Now get the get the function value: (What kind of hackable object)
    int tFunctionVal = WorldActors->GetWorldActorFunctionID( mRawItemID );

    // Then get the FUNCTION VALUE as furniture model so we can access its subvalues etc. Here: Hack difficult
    tFurnitureModel = GameDefs->WorldModels()->GetDef( tFunctionVal );
  }
  else
  {
    // Dat files have smaller IDs
    u32 ItemID = mRawItemID / 1024 - 1;

    // Now grab the template from .dat file
    tFurnitureTemplate = CurrentWorld->GetFurnitureItemTemplate( ItemID );

    // Then get the FUNCTION VALUE as furniture model so we can access its subvalues etc
    tFurnitureModel = CurrentWorld->GetFurnitureItemModel( ItemID );
  }

  if ( tFurnitureModel ) // We have an valid worldobject? Fine. Then start the hackgame
  {
    u8 tHackDifficult = tFurnitureModel->GetHackDifficulty();
    u8 tHackPenalty = tFurnitureModel->GetHackPenalty();

    // Print it!
    if(tHackDifficult)
    {
      //if (gDevDebug)
      Console->Print( "%s Client trying to hack itemID %d. Hack difficult: %d Hack penalty %d", Console->ColorText( CYAN, BLACK, "[DEBUG]" ), mRawItemID, tHackDifficult, tHackPenalty );

      PMessage* tmpMsg = MsgBuilder->BuildStartHackGameMsg( nClient, mRawItemID, tHackDifficult );
      nClient->SendUDPMessage( tmpMsg );
      tmpMsg = NULL;
    }
  }

  mDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
  return true;
}
Exemplo n.º 5
0
void PUdpSync0::GetToSync1( PMsgDecodeData* nDecodeData )
{
  PClient* nClient = nDecodeData->mClient;
  nClient->SetZoning();

  u32 loc = nClient->GetChar()->GetLocation();
//Console->Print("inside HandleGame : Location: %d", loc);
  SendZone( nClient, loc );

  // "aliverep" ?
  PMessage* tmpMsg = MsgBuilder->BuildAliveRepMsg( nClient );
  nClient->SendUDPMessage( tmpMsg );

  nDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
  //State->UDP.mSynced=true;
  nDecodeData->mClientState->UDP.mState = PGameState::UDP::GUS_SYNC1;// To change later
//Console->Print("Initialize: UDP_ID");
  nClient->SetUDP_ID( 0 );
}
Exemplo n.º 6
0
void PPatchServer::Update()
{
    //ServerSock->update();

	if(ServerSock->newConnection())
	{
		int clid = Server->NewClient();
		if(clid!=-1)
		{
			Console->Print(GREEN, BLACK, "Patchserver: client [%i] connected", clid);
			PClient *Client = Server->GetClient(clid);

			ConnectionTCP* tcpConn = ServerSock->getTCPConnection();
			Client->setTCPConnection(tcpConn);

			Console->Print("Client address: %s", Client->GetAddress());
			//++mNumClients;

			PPatchState *state = new PPatchState();
			ClientStates.insert(std::make_pair(Client, state));
			state->mState = PPatchState::PS_CONNECTED;
		} else
		{
			Console->Print("Patchserver: Client connection refused (server full?)");
		}
	}

	for(PatchStateMap::iterator i=ClientStates.begin(); i!=ClientStates.end();)
	{
		PClient *Client = i->first;
		PPatchState *State = i->second;
		// node gets erased in FinalizeClient, increment iterator now
		++i;
		if(!ProcessClient(Client, State))
		{
			FinalizeClient(Client, State);
		}
	}
}
Exemplo n.º 7
0
bool PUdpSync2::DoAction()
{
  if (( mDecodeData->mState & DECODE_ACTION_READY ) && ( mDecodeData->mClientState->UDP.mState == PGameState::UDP::GUS_SYNC2 ) )
  {
    PClient* nClient = mDecodeData->mClient;

    // Baseline message chunking & sending
    PMessage* BaselineMsg = MsgBuilder->BuildBaselineMsg( nClient );
    nClient->FragmentAndSendUDPMessage( BaselineMsg, 0x19 );

    // Sending "CharInfo3/Zoning2Msg" message
    // Removed because same as Zoning2Msg
    PMessage* Zoning2Msg = MsgBuilder->BuildZoning2Msg( nClient, mClientTime );
    nClient->SendUDPMessage( Zoning2Msg );

    mDecodeData->mClientState->UDP.mState = PGameState::UDP::GUS_SYNC3;
    nClient->SetZoning( false );

    // If char is sitting (vhz zoning), send it now to client
    u32 nSeatableObjectId;
    u8 nSeatId;
    if( nClient->GetChar()->GetSeatInUse(&nSeatableObjectId, &nSeatId) )
    {
      if( gDevDebug )
        Console->Print( YELLOW, BLACK, "[DEBUG] PUdpSync2::DoAction : Char %d sitting on vhc id %d, seat %d", nClient->GetLocalID(), nSeatableObjectId, nSeatId  );
      PMessage* SittingMsg = MsgBuilder->BuildCharUseSeatMsg( nClient, nSeatableObjectId, nSeatId );
      nClient->FillInUDP_ID(SittingMsg);
      nClient->SendUDPMessage( SittingMsg );
    }

    //Temp: send Subway to client if in subway
    if ( nClient->GetChar()->GetLocation() == PWorlds::mNcSubwayWorldId )
    {
      PMessage* SubwayMsg = MsgBuilder->BuildSubwaySpawnMsg( nClient, false );
      nClient->SendUDPMessage( SubwayMsg );
      SubwayMsg = MsgBuilder->BuildSubwaySpawnMsg( nClient, true );
      nClient->SendUDPMessage( SubwayMsg );
    }

    // Send spawned vehicles
    PWorld* CurrentWorld = Worlds->GetWorld( nClient->GetChar()->GetLocation() );
    if ( CurrentWorld )
    {
      PSpawnedVhcList* VhcList = CurrentWorld->GetSpawnedVehicules()->GetSpawnedVehicles();
      PSpawnedVehicle* VhcEntry;
      PMessage* VhcMsg;

      while ( ! VhcList->empty() )
      {
        VhcEntry = VhcList->front();
        VhcList->pop();
        if( gDevDebug )
          Console->Print( YELLOW, BLACK, "[DEBUG] PUdpSync2::DoAction : Send info for vhc id %d", VhcEntry->GetLocalId() );
        VhcMsg = MsgBuilder->BuildVhcPosUpdateMsg( VhcEntry );
        nClient->FillInUDP_ID( VhcMsg );
        nClient->SendUDPMessage( VhcMsg );
        VhcMsg = MsgBuilder->BuildVhcInfoMsg( nClient, VhcEntry );
        nClient->SendUDPMessage( VhcMsg );
      }
    }

    // Dispatching info to & from other chars in zone
    int nbSent;
    nbSent = ClientManager->SendUDPZoneWelcomeToClient( nClient );
//Console->Print(GREEN, BLACK, " %d Welcome message were sent to client %d", nbSent, Client->GetIndex());

    PMessage* HelloMsg = MsgBuilder->BuildCharHelloMsg( nClient );
    nbSent = ClientManager->UDPBroadcast( HelloMsg, nClient );
//Console->Print(GREEN, BLACK, "Client %d: Hello message sent to %d chars", Client->GetIndex(), nbSent);

    // Send worldactors to client
    WorldActors->InitWorld( nClient );

    // Send NPC information to client
    NPCManager->InitPlayer( nClient );

    //Console->Print("OP Data inc");
    Outposts->SendOPAreaData( nClient );

    mDecodeData->mState = DECODE_ACTION_DONE | DECODE_FINISHED;
    return true;
  }
  else
    return false;
}