Example #1
0
        public static void HandlePlayerLogin(ref PacketReader packet, ref WorldSession session)
        {
            var mask  = new byte[] { 5, 7, 6, 1, 2, 3, 4, 0 };
            var bytes = new byte[] { 6, 4, 3, 5, 0, 2, 7, 1 };
            var guid  = packet.GetGuid(mask, bytes);

            Player pChar = new Player(ref session);

            session.SetPlayer(pChar);

            if (!pChar.LoadCharacter(guid))
            {
                session.SetPlayer(null);
                session.KickPlayer();                                       // disconnect client, player no set to session and it will not deleted or saved at kick
                //m_playerLoading = false;
                return;
            }

            //pCurrChar->GetMotionMaster()->Initialize();
            //pCurrChar->SendDungeonDifficulty(false);

            PacketWriter world = new PacketWriter(Opcodes.SMSG_NewWorld);

            world.WriteUInt32(pChar.GetMapId());
            world.WriteFloat(pChar.Position.Y);
            world.WriteFloat(pChar.Position.Orientation);
            world.WriteFloat(pChar.Position.X);
            world.WriteFloat(pChar.Position.Z);
            session.Send(world);

            //LoadAccountData(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA), PER_CHARACTER_CACHE_MASK);
            //SendAccountDataTimes(PER_CHARACTER_CACHE_MASK);
            session.SendAccountDataTimes(AccountDataMasks.PerCharacterCacheMask);

            PacketWriter feature = new PacketWriter(Opcodes.SMSG_FeatureSystemStatus);

            feature.WriteUInt8(2);   // SystemStatus
            feature.WriteUInt32(1);  // Unknown, Mostly 1
            feature.WriteUInt32(1);  // Unknown, Mostly 1
            feature.WriteUInt32(2);  // Unknown, Mostly same as SystemStatus, but seen other values
            feature.WriteUInt32(0);  // Unknown, Hmm???

            feature.WriteBit(true);  // Unknown
            feature.WriteBit(true);  // Unknown
            feature.WriteBit(false); // Unknown
            feature.WriteBit(true);  // Unknown
            feature.WriteBit(false); // EnableVoiceChat, not sure
            feature.WriteBit(false); // Unknown
            feature.BitFlush();

            feature.WriteUInt32(1);    // Only seen 1
            feature.WriteUInt32(0);    // Unknown, like random values
            feature.WriteUInt32(0xA);  // Only seen 10
            feature.WriteUInt32(0x3C); // Only seen 60

            //session.Send(feature);

            MiscHandler.SendMOTD(ref session);

            //if (pChar.GuildGuid != 0)
            {
                //Guild guild = GuildMgr.GetGuildByGuid(pChar.GuildGuid);
                //if (guild != null)
                {
                    //var member = guild.GetMember(pChar.Guid);
                    //pChar.SetInGuild(pChar.GuildGuid);
                    //pChar.SetGuildRank(member.RankId);
                    //pChar.SetGuildLevel(guild.GetLevel());
                    //guild.HandleMemberLogin(pChar);
                }
                //else
                {
                    //pChar.SetInGuild(0);
                    //pChar.SetGuildRank(0);
                    //pChar.SetGuildLevel(0);
                }
            }

            PacketWriter data = new PacketWriter(Opcodes.SMSG_LearnedDanceMoves);

            data.WriteUInt64(0);
            //session.Send(data);

            //hotfix

            pChar.SendInitialPacketsBeforeAddToMap();

            /*
             * //Show cinematic at the first time that player login
             * if (!pCurrChar->getCinematic())
             * {
             *  pCurrChar->setCinematic(1);
             *
             *  if (ChrClassesEntry cEntry = sChrClassesStore.LookupEntry(pCurrChar->getClass()))
             *  {
             *      if (cEntry->CinematicSequence)
             *          pCurrChar->SendCinematicStart(cEntry->CinematicSequence);
             *      else if (ChrRacesEntry rEntry = sChrRacesStore.LookupEntry(pCurrChar->getRace()))
             *      pCurrChar->SendCinematicStart(rEntry->CinematicSequence);
             *
             *      // send new char string if not empty
             *      if (!sWorld->GetNewCharString().empty())
             *          chH.PSendSysMessage("%s", sWorld->GetNewCharString().c_str());
             *  }
             * }
             * if (Group* group = pCurrChar->GetGroup())
             * {
             *  if (group->isLFGGroup())
             *  {
             *      LfgDungeonSet Dungeons;
             *      Dungeons.insert(sLFGMgr->GetDungeon(group->GetGUID()));
             *      sLFGMgr->SetSelectedDungeons(pCurrChar->GetGUID(), Dungeons);
             *      sLFGMgr->SetState(pCurrChar->GetGUID(), sLFGMgr->GetState(group->GetGUID()));
             *  }
             * }
             */
            if (!pChar.GetMap().AddPlayer(pChar))//|| !pCurrChar.CheckInstanceLoginValid())
            {
                //AreaTrigger at = sObjectMgr->GetGoBackTrigger(pCurrChar->GetMapId());
                //if (at)
                //pCurrChar->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, pCurrChar->GetOrientation());
                //else
                //pCurrChar->TeleportTo(pCurrChar->m_homebindMapId, pCurrChar->m_homebindX, pCurrChar->m_homebindY, pCurrChar->m_homebindZ, pCurrChar->GetOrientation());
            }
            ObjMgr.AddObject(pChar);

            pChar.SendInitialPacketsAfterAddToMap();

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.CHAR_UPD_CHAR_ONLINE);

            stmt.AddValue(0, pChar.GetGUIDLow());
            DB.Characters.Execute(stmt);

            stmt = DB.Auth.GetPreparedStatement(LoginStatements.Upd_AccountOnline);
            stmt.AddValue(0, session.GetAccountId());
            DB.Auth.Execute(stmt);

            //pCurrChar->SetInGameTime(getMSTime());

            // announce group about member online (must be after add to player list to receive announce to self)
            //if (Group* group = pCurrChar->GetGroup())
            {
                //pCurrChar->groupInfo.group->SendInit(this); // useless
                //group->SendUpdate();
                //group->ResetMaxEnchantingLevel();
            }

            // friend status
            //sSocialMgr->SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), true);

            // Place character in world (and load zone) before some object loading
            //pCurrChar->LoadCorpse();

            // setting Ghost+speed if dead
            //if (pCurrChar->m_deathState != ALIVE)
            {
                // not blizz like, we must correctly save and load player instead...
                //if (pCurrChar->getRace() == RACE_NIGHTELF)
                //pCurrChar->CastSpell(pCurrChar, 20584, true, 0);// auras SPELL_AURA_INCREASE_SPEED(+speed in wisp form), SPELL_AURA_INCREASE_SWIM_SPEED(+swim speed in wisp form), SPELL_AURA_TRANSFORM (to wisp form)
                //pCurrChar->CastSpell(pCurrChar, 8326, true, 0);     // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)

                //pCurrChar->SendMovementSetWaterWalking(true);
            }

            //pCurrChar->ContinueTaxiFlight();

            // reset for all pets before pet loading
            //if (pChar.HasAtLoginFlag(AtLoginFlags.ResetPetTalents))
            //resetTalentsForAllPetsOf(pCurrChar);

            // Load pet if any (if player not alive and in taxi flight or another then pet will remember as temporary unsummoned)
            //pCurrChar->LoadPet();

            // Set FFA PvP for non GM in non-rest mode
            //if (sWorld->IsFFAPvPRealm() && !pCurrChar->isGameMaster() && !pCurrChar->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))
            //pCurrChar->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);

            //if (pChar.HasFlag(PlayerFields.PlayerFlags, PlayerFlags.ContestedPVP))
            //pChar->SetContestedPvP();

            // Apply at_login requests
            if (pChar.HasAtLoginFlag(AtLoginFlags.ResetSpells))
            {
                //pChar.resetSpells();
                pChar.SendNotification(CypherStrings.ResetSpells);
            }

            if (pChar.HasAtLoginFlag(AtLoginFlags.ResetTalents))
            {
                //pChar.ResetTalents(true);
                //pChar.SendTalentsInfoData(false);              // original talents send already in to SendInitialPacketsBeforeAddToMap, resend reset state
                pChar.SendNotification(CypherStrings.ResetTalents);
            }

            if (pChar.HasAtLoginFlag(AtLoginFlags.LoginFirst))
            {
                pChar.RemoveAtLoginFlag(AtLoginFlags.LoginFirst);
            }

            // show time before shutdown if shutdown planned.
            //if (sWorld->IsShuttingDown())
            //sWorld->ShutdownMsg(true, pChar);

            //if (sWorld->getBoolConfig(CONFIG_ALL_TAXI_PATHS))
            //pChar->SetTaxiCheater(true);

            if (pChar.isGameMaster())
            {
                pChar.SendNotification(CypherStrings.GmOn);
            }

            //string IP_str = GetRemoteAddress();
            Log.outDebug("Account: {0} (IP: {1}) Login Character:[{2}] (GUID: {3}) Level: {4}",
                         session.GetAccountId(), 0, pChar.GetName(), pChar.GetGUIDLow(), pChar.getLevel());

            //if (!pChar->IsStandState() && !pChar->HasUnitState(UNIT_STATE_STUNNED))
            //pChar->SetStandState(UNIT_STAND_STATE_STAND);

            //m_playerLoading = false;

            //sScriptMgr->OnPlayerLogin(pCurrChar);
        }