Пример #1
0
        public static ERequestResult HandleRequest(CGameStateController gs, CPlayer player)
        {
            if (gs.PlayerState[player] != EPlayerState.UNITIALIZED)
            {
                return(ERequestResult.PLAYER_INCONSISTENT_STATE);
            }

            MAccountLoginPacket packet = MyMarshal.GetStructure <MAccountLoginPacket>(player.RecvPacket);

            MAccountFile?nAccFile;

            AccountCRUD.EErrorMsg accErr = AccountCRUD.TryRead(packet.AccName, out nAccFile);

            if (accErr == AccountCRUD.EErrorMsg.NO_ERROR)
            {
                MLoginSuccessfulPacket answer =
                    PacketHelper.GetEmptyValid <MLoginSuccessfulPacket>(MLoginSuccessfulPacket.Opcode);

                MAccountFile accFile = nAccFile.Value;

                answer.AccName   = accFile.Info.LoginInfo.AccName;
                answer.Cargo     = accFile.Cargo;
                answer.CargoCoin = accFile.CargoCoin;

                for (int i = 0; i < GameBasics.MAXL_ACC_MOB; i++)
                {
                    unsafe
                    {
                        answer.SelChar.Coin[i]  = accFile.MobCore[i].Coin;
                        answer.SelChar.Equip[i] = accFile.MobCore[i].Equip;
                        answer.SelChar.Exp[i]   = accFile.MobCore[i].Exp;
                        answer.SelChar.Guild[i] = accFile.MobCore[i].Guild;
                        answer.SelChar.Name[i]  = accFile.MobCore[i].Name;
                        answer.SelChar.Score[i] = accFile.MobCore[i].BaseScore;
                        answer.SelChar.SPosX[i] = accFile.MobCore[i].StellarGemPosition.X;
                        answer.SelChar.SPosY[i] = accFile.MobCore[i].StellarGemPosition.Y;
                    }
                }

                player.SendPacket(MyMarshal.GetBytes(answer));
            }
            else if (accErr == AccountCRUD.EErrorMsg.ACC_NOT_FOUND)
            {
                MTextMessagePacket answer =
                    PacketHelper.GetEmptyValid <MTextMessagePacket>(MTextMessagePacket.Opcode);

                answer.Message = "Esta conta não foi encontrada.";

                player.SendPacket(MyMarshal.GetBytes(answer));
            }
            else
            {
                return(ERequestResult.UNKNOWN);
            }

            return(ERequestResult.NO_ERROR);
        }
Пример #2
0
        private EPlayerRequestResult CGameStateController_OnProcessPacket(CGameStateController gs, CPlayer player)
        {
            switch (player.RecvPacket.ReadNextUShort(4))
            {
            case MAccountLoginPacket.Opcode:
            {
                if (player.State != EPlayerState.WAITING_TO_LOGIN)
                {
                    return(EPlayerRequestResult.PLAYER_INCONSISTENT_STATE);
                }

                MAccountLoginPacket packet = W2Marshal.GetStructure <MAccountLoginPacket>(player.RecvPacket);

                MAccountFile?       nAccFile;
                AccountCRUD.EResult accErr = AccountCRUD.TryRead(packet.AccName, out nAccFile);

                if (accErr != AccountCRUD.EResult.NO_ERROR)
                {
                    // if account doesn't exist...
                    if (accErr == AccountCRUD.EResult.ACC_NOT_FOUND)
                    {
                        // create a new account file
                        MAccountFile newAccFile = W2Marshal.CreateEmpty <MAccountFile>();
                        // set the username & password
                        newAccFile.Info.LoginInfo.AccName  = packet.AccName;
                        newAccFile.Info.LoginInfo.Password = packet.Password;

                        AccountCRUD.EResult createAccErr = AccountCRUD.TrySaveAccount(ref newAccFile);

                        if (createAccErr == AccountCRUD.EResult.NO_ERROR)
                        {
                            accErr = AccountCRUD.TryRead(packet.AccName, out nAccFile);

                            if (accErr != AccountCRUD.EResult.NO_ERROR)
                            {
                                return(EPlayerRequestResult.UNKNOWN);
                            }
                        }
                        else if (createAccErr == AccountCRUD.EResult.ACC_NOT_SAVED)
                        {
                            MTextMessagePacket createFailedAnswer =
                                W2Marshal.GetEmptyValid <MTextMessagePacket>(MTextMessagePacket.Opcode);

                            createFailedAnswer.Message = "Não foi possível criar a conta.";

                            player.SendPacket(createFailedAnswer);

                            return(EPlayerRequestResult.NO_ERROR);
                        }
                        else if (createAccErr == AccountCRUD.EResult.UNKNOWN)
                        {
                            return(EPlayerRequestResult.UNKNOWN);
                        }
                    }
                    else
                    {
                        return(EPlayerRequestResult.UNKNOWN);
                    }
                }

                MLoginSuccessfulPacket answer =
                    W2Marshal.GetEmptyValid <MLoginSuccessfulPacket>(MLoginSuccessfulPacket.Opcode);

                MAccountFile accFile = nAccFile.Value;

                answer.AccName   = accFile.Info.LoginInfo.AccName;
                answer.Cargo     = accFile.Cargo;
                answer.CargoCoin = accFile.CargoCoin;

                for (int i = 0; i < GameBasics.MAXL_ACC_MOB; i++)
                {
                    unsafe
                    {
                        answer.SelChar.Coin[i]  = accFile.MobCore[i].Coin;
                        answer.SelChar.Equip[i] = accFile.MobCore[i].Equip;
                        answer.SelChar.Exp[i]   = accFile.MobCore[i].Exp;
                        answer.SelChar.Guild[i] = accFile.MobCore[i].Guild;
                        answer.SelChar.Name[i]  = accFile.MobCore[i].Name;
                        answer.SelChar.Score[i] = accFile.MobCore[i].BaseScore;
                        answer.SelChar.SPosX[i] = accFile.MobCore[i].StellarGemPosition.X;
                        answer.SelChar.SPosY[i] = accFile.MobCore[i].StellarGemPosition.Y;
                    }
                }

                player.SendPacket(answer);

                player.State = EPlayerState.SEL_CHAR;


                return(EPlayerRequestResult.NO_ERROR);
            }

            default: return(EPlayerRequestResult.PACKET_NOT_HANDLED);
            }
        }
Пример #3
0
        private EPlayerRequestResult CGameStateController_OnProcessPacket(CGameStateController gs, CPlayer player)
        {
            switch (player.RecvPacket.ReadNextUShort(4))
            {
            case MAccountLoginPacket.Opcode:
            {
                if (player.State != EPlayerState.WAITING_TO_LOGIN)
                {
                    return(EPlayerRequestResult.PLAYER_INCONSISTENT_STATE);
                }

                MAccountLoginPacket packet = W2Marshal.GetStructure <MAccountLoginPacket>(player.RecvPacket);

                MAccountFile?       nAccFile;
                AccountCRUD.EResult accErr = AccountCRUD.TryRead(packet.AccName, out nAccFile);

                if (accErr == AccountCRUD.EResult.NO_ERROR)
                {
                    MLoginSuccessfulPacket answer =
                        W2Marshal.GetEmptyValid <MLoginSuccessfulPacket>(MLoginSuccessfulPacket.Opcode);

                    MAccountFile accFile = nAccFile.Value;

                    answer.AccName   = accFile.Info.LoginInfo.AccName;
                    answer.Cargo     = accFile.Cargo;
                    answer.CargoCoin = accFile.CargoCoin;

                    for (int i = 0; i < GameBasics.MAXL_ACC_MOB; i++)
                    {
                        unsafe
                        {
                            answer.SelChar.Coin[i]  = accFile.MobCore[i].Coin;
                            answer.SelChar.Equip[i] = accFile.MobCore[i].Equip;
                            answer.SelChar.Exp[i]   = accFile.MobCore[i].Exp;
                            answer.SelChar.Guild[i] = accFile.MobCore[i].Guild;
                            answer.SelChar.Name[i]  = accFile.MobCore[i].Name;
                            answer.SelChar.Score[i] = accFile.MobCore[i].BaseScore;
                            answer.SelChar.SPosX[i] = accFile.MobCore[i].StellarGemPosition.X;
                            answer.SelChar.SPosY[i] = accFile.MobCore[i].StellarGemPosition.Y;
                        }
                    }

                    player.SendPacket(answer);

                    player.State = EPlayerState.SEL_CHAR;
                }
                else if (accErr == AccountCRUD.EResult.ACC_NOT_FOUND)
                {
                    MTextMessagePacket answer =
                        W2Marshal.GetEmptyValid <MTextMessagePacket>(MTextMessagePacket.Opcode);

                    answer.Message = "Esta conta não foi encontrada.";

                    player.SendPacket(answer);
                }
                else
                {
                    return(EPlayerRequestResult.UNKNOWN);
                }

                return(EPlayerRequestResult.NO_ERROR);
            }

            default: return(EPlayerRequestResult.PACKET_NOT_HANDLED);
            }
        }