private void CGameStateController_OnProcessSecTimer(CGameStateController gs)
        {
            if (DateTime.Now - m_LastGlobalAccSave >= m_GlobalAccSaveDueTime)
            {
                for (int i = 0; i < gs.Players.Length; i++)
                {
                    if (gs.Players[i]?.State == EPlayerState.AT_WORLD)
                    {
                        var account = gs.Players[i].AccountData.Value;

                        if (AccountCRUD.TrySaveAccount(ref account) != AccountCRUD.EResult.NO_ERROR)
                        {
                            // TODO: the account could not be saved for some reason.
                            // Do something...
                            throw new Exception($"The account {gs.Players[i].AccountData.Value.Info.LoginInfo.AccName} couldn't be saved.");
                        }
                        else
                        {
                            W2Log.Write($"The account {gs.Players[i].AccountData.Value.Info.LoginInfo.AccName} was saved successfuly.", ELogType.GAME_EVENT);
                        }
                    }
                }

                m_LastGlobalAccSave = gs.SinceInit;
            }
        }
        public static ERequestResult TryProcessPacket(CGameStateController gs, CPlayer player)
        {
            ERequestResult result = ERequestResult.NO_ERROR;

            try
            {
                // Switch for the packet opcode.
                switch (player.RecvPacket.ReadNextUShort(4))
                {
                case MAccountLoginPacket.Opcode:
                    result = MAccountLoginPacket.HandleRequest(gs, player);
                    break;

                case MPingPacket.Opcode:
                    result = MPingPacket.HandleRequest(gs, player);
                    break;

                default:
                    result = ERequestResult.PACKET_NOT_HANDLED;
                    break;
                }
            }
            catch (Exception)
            {
                result = ERequestResult.UNKNOWN;
            }

            return(result);
        }
        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);
        }
Exemple #4
0
        public MainForm()
        {
            InitializeComponent();

            gameController = new CGameStateController();

            MyLog.DidLog += CLog_DidLog;

            StartServer_Channel1();
        }
        public MainForm()
        {
            InitializeComponent();

            PluginController.InstallPlugins();

            W2Log.DidLog += CLog_DidLog;

            gameController = new CGameStateController(this);

            StartServer_Channel1();
        }
Exemple #6
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);
            }
        }
Exemple #7
0
 private void CGameStateController_OnProcessSecTimer(CGameStateController gs)
 {
     W2Log.Write("wat", ELogType.GAME_EVENT);
 }
Exemple #8
0
 public static ERequestResult HandleRequest(CGameStateController gs, CPlayer player)
 {
     throw new NotImplementedException();
 }
Exemple #9
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);
            }
        }