示例#1
0
    /// <summary>
    /// 유저 정보 응답 처리
    /// </summary>
    /// <param name="errorCode"></param>
    /// <param name="userInfo"></param>
    /// <param name="arrayUserDeck"></param>
    /// <param name="arrayUserDice"></param>
    /// <param name="arrayUserBox"></param>
    /// <param name="questInfo"></param>
    /// <param name="seasonInfo"></param>
    /// <returns></returns>
    public bool OnReceiveUserInfoAck(ERandomwarsUserErrorCode errorCode, MsgUserInfo userInfo, UserDeck[] arrayUserDeck, UserDice[] arrayUserDice, UserItemInfo userItemInfo, QuestInfo questInfo, UserSeasonInfo seasonInfo)
    {
        if (errorCode != ERandomwarsUserErrorCode.Success)
        {
            UserInfoManager.Get().ResetUserId();

            return(true);
        }

        UserInfoManager.Get().SetUserInfo(userInfo, seasonInfo);
        UserInfoManager.Get().SetDeck(arrayUserDeck);
        UserInfoManager.Get().SetDice(arrayUserDice);
        UserInfoManager.Get().SetItem(userItemInfo);
        UI_Popup_Quest.QuestUpdate(questInfo);

        GameStateManager.Get().UserAuthOK();
        //UnityUtil.Print("RECV AUTH => msg", Newtonsoft.Json.JsonConvert.SerializeObject(msg), "green");

        return(true);
    }
        /// <summary>
        /// This function is called once the client has been authenticated. If the character for the client
        /// does not exist in the database, then this function will open the character creation screen; else,
        /// it will load character data and send the client information needed to log into the world. It will
        /// also connect the player to the map server.
        /// </summary>
        /// <param name="pClient">The client being processed.</param>
        /// <param name="pPacket">The authentication packet to be sent to the map server.</param>
        private static void InitializeCharacter(Client pClient, MsgConnect pPacket, bool bCreate = false)
        {
            // check if the server is full
            if (ServerKernel.Players.Count >= ServerKernel.MaxOnlinePlayer)
            {
                pClient.Send(ServerMessages.Login.ServerFull);
                pClient.Disconnect();
                return;
            }

            DbAccount pAccount = new AccountRepository().SearchByIdentity(pClient.AccountIdentity);
            DbUser    pUser    = new CharacterRepository().SearchByAccount(pClient.AccountIdentity);

            if (pAccount != null && pUser != null)
            {
                if (pUser.Life <= 0)
                {
                    pUser.Life = 1;
                }

                pClient.VipLevel        = pAccount.Vip;
                pClient.Identity        = pUser.Identity;
                pClient.AccountIdentity = pAccount.Identity;

                if (CheckGamePool(pClient, pClient.Identity) &&
                    ServerKernel.Players.TryAdd(pClient.Identity, pClient))
                {
                    // The client is ready and authorized for login. Prepare the client for the game world: load
                    // spawn information and send it to the map server, and initialize game structures necessary
                    // to log into the server.
                    if (!bCreate)
                    {
                        pClient.Send(ServerMessages.Login.AnswerOk);
                    }

                    pClient.Send(new MsgUserIpInfo());
                    pClient.Send(new MsgServerInfo()
                    {
                        ClassicMode = 0, PotencyMode = 0
                    });

                    if (pUser.Lookface < 10000)
                    {
                        ushort body     = (ushort)(pUser.Lookface % 10000);
                        uint   lookface = 0;
                        if (body == (ushort)BodyType.THIN_MALE || body == (ushort)BodyType.HEAVY_MALE)
                        {
                            if ((pUser.Profession / 10) == 5)
                            {
                                lookface = (uint)(new Random().Next(103, 107));
                            }
                            else if ((pUser.Profession / 10) == 6)
                            {
                                lookface = (uint)(new Random().Next(109, 113));
                            }
                            else
                            {
                                lookface = (uint)(new Random().Next(1, 102));
                            }
                        }
                        else
                        {
                            if ((pUser.Profession / 10) == 5)
                            {
                                lookface = (uint)(new Random().Next(291, 295));
                            }
                            else if ((pUser.Profession / 10) == 6)
                            {
                                lookface = (uint)(new Random().Next(300, 304));
                            }
                            else
                            {
                                lookface = (uint)(new Random().Next(201, 290));
                            }
                        }
                        pUser.Lookface = lookface * 10000 + pUser.Lookface;
                    }

                    var pInfo = new MsgUserInfo(pUser.Name, string.Empty, pUser.Mate)
                    {
                        Agility            = pUser.Agility,
                        AncestorProfession = (byte)pUser.FirstProfession,
                        Attributes         = pUser.AdditionalPoints,
                        BoundEmoney        = pUser.BoundEmoney,
                        ConquerPoints      = pUser.Emoney,
                        Enlighten          = pUser.EnlightPoints,
                        EnlightenExp       = 0,
                        Experience         = pUser.Experience,
                        Hairstyle          = pUser.Hair,
                        Health             = pUser.Life,
                        Mana               = pUser.Mana,
                        Identity           = pUser.Identity,
                        Level              = pUser.Level,
                        Mesh               = pUser.Lookface,
                        Vitality           = pUser.Vitality,
                        Spirit             = pUser.Spirit,
                        Metempsychosis     = pUser.Metempsychosis,
                        Strength           = pUser.Strength,
                        QuizPoints         = pUser.StudentPoints,
                        Silver             = pUser.Money,
                        PreviousProfession = (byte)pUser.LastProfession,
                        Profession         = (byte)pUser.Profession,
                        PlayerTitle        = pUser.SelectedTitle,
                        PkPoints           = pUser.PkPoints
                    };

                    pClient.Character = new Character(pInfo, pUser, pClient);

                    pClient.Send(pInfo);
                    pClient.Send(new MsgData());
                    pClient.Screen = new Screen(pClient.Character);

                    if (ServerKernel.Players.Count > ServerKernel.OnlineRecord)
                    {
                        ServerKernel.OnlineRecord = (ushort)ServerKernel.Players.Count;
                    }

                    ServerKernel.Log.SaveLog(string.Format("User [{0}] has logged in.", pClient.Character.Name), true, LogType.MESSAGE);
                    ServerKernel.LoginServer.Send(new MsgLoginSvPlayerAmount((ushort)ServerKernel.Players.Count, LoginPlayerAmountRequest.REPLY_ONLINE_AMOUNT));

                    pUser.LastLogin = (uint)UnixTimestamp.Timestamp();
                    Database.Characters.SaveOrUpdate(pUser);
                }
            }
            else if (pAccount != null &&
                     CheckGamePool(pClient, 0) &&
                     ServerKernel.CharacterCreation.TryAdd(pClient.AccountIdentity, pClient))
            {
                pClient.Send(ServerMessages.Login.NewRole);
            }
            else
            {
                pClient.Send(ServerMessages.Login.TransferFailed);
                pClient.Disconnect();
            }
        }