Exemplo n.º 1
0
        public override async Task <bool> OnMessageReceived(WZClient wzsession, object message)
        {
            List <Predicate <TSession> > predicates;

            _filter.TryGetValue(message.GetType(), out predicates);

            TSession session = (TSession)wzsession;

            if (predicates != null && predicates.Any(predicate => !predicate(session)))
            {
                Logger.Debug("Dropping message {messageName} from client {remoteAddress}", message.GetType().Name, session.ID);
                return(false);
            }

            var handled = false;

            foreach (var messageHandler in _messageHandlers)
            {
                var result = await messageHandler.OnMessageReceived(wzsession, message);

                if (result)
                {
                    handled = true;
                }
            }

            return(handled);
        }
Exemplo n.º 2
0
        public override void OnDisconnect(WZClient session)
        {
            base.OnDisconnect(session);

            var Session = session as CSSession;

            ServerManager.Instance.Unregister(Session);
        }
Exemplo n.º 3
0
        protected override void OnConnect(WZClient session)
        {
            var Session = session as GSSession;

            Session.Player = new Player(Session);

            Session.SendAsync(new SJoinResult(1, Session.ID, ClientVersion));
        }
Exemplo n.º 4
0
        protected override void OnConnect(WZClient session)
        {
            var Session = session as GSSession;

            Session.Player = new Player(Session);

            Session.SendAsync(new SJoinResult(1, Session.ID, ClientVersion)).Wait();

            Connect?.Invoke(this, new WZServerEventArgs {
                session = Session
            });
        }
Exemplo n.º 5
0
        protected override void OnConnect(WZClient session)
        {
            var Session = session as GSSession;

            Session.Player = new Player(Session);

            var msg = VersionSelector.CreateMessage <SJoinResult>((byte)1, Session.ID, ClientVersion);

            _ = Session.SendAsync(msg);

            Connect?.Invoke(this, new WZServerEventArgs {
                session = Session
            });
        }
Exemplo n.º 6
0
        public override void OnDisconnect(WZClient session)
        {
            var Session = session as GSSession;

            using (var db = new GameContext())
            {
                if (Session.Player != null)
                {
                    if (Session.Player.Status == LoginStatus.Playing && Session.Player.Character != null)
                    {
                        var @char = Session.Player.Character;
                        var mobVp = @char.MonstersVP.Select(x => MonstersMng.Instance.GetMonster(x)).ToList();
                        //mobVp.ForEach(x => x.ViewPort.Remove(Session.Player));
                        Program.client.SendAsync(new SCRem {
                            Server = (byte)Program.ServerCode, List = new CliRemDto[] { new CliRemDto {
                                                                                            btName = @char.Name.GetBytes()
                                                                                        } }
                        });
                        @char.Map.DelPlayer(Session.Player.Character);
                        @char.Party?.Remove(Session.Player);
                        @char.Duel?.Leave(@char.Player);
                        @char.Party = null;
                        Game.GameServices.CCloseWindow(Session);
                        foreach (var m in mobVp.Where(x => x.Target == Session.Player))
                        {
                            m.Target = null;
                        }
                    }

                    Session.Player.Status = LoginStatus.NotLogged;
                    Logger.ForAccount(Session).Information("Saving...");
                    Session.Player.Save(db).Wait();
                    Logger.ForAccount(Session).Information("Saved!");
                }
                if (Session.Player.Account != null)
                {
                    var acc = (from a in db.Accounts
                               where a.AccountId == Session.Player.Account.ID
                               select a).First();

                    acc.IsConnected = false;

                    db.Accounts.Update(acc);
                    Logger.ForAccount(Session).Information("Disconnecting...");
                }
                db.SaveChanges();
            }
            base.OnDisconnect(session);
        }
Exemplo n.º 7
0
        public override void OnDisconnect(WZClient session)
        {
            var Session = session as GSSession;

            if (Session.Player != null)
            {
                if (Session.Player.Character != null)
                {
                    Program.client
                    .SendAsync(new SCRem
                    {
                        Server = (byte)Program.ServerCode,
                        List   = new CliRemDto[] {
                            new CliRemDto {
                                btName = Session.Player.Character.Name.GetBytes()
                            }
                        }
                    });

                    PartyManager.CancelMatching(Session.Player);
                }
                Session.Player.Status = LoginStatus.NotLogged;

                using (var db = new GameContext())
                {
                    if (Session.Player.Account != null)
                    {
                        var acc = (from a in db.Accounts
                                   where a.AccountId == Session.Player.Account.ID
                                   select a).First();

                        acc.IsConnected = false;

                        db.Accounts.Update(acc);
                        db.SaveChanges();
                        Logger.ForAccount(Session).Information("Disconnecting...");
                    }
                }
                Session.Player.Account = null;
            }
            //db.SaveChanges();

            Session.Player = null;
            base.OnDisconnect(session);
            Disconnect?.Invoke(this, new WZServerEventArgs {
                session = Session
            });
        }
Exemplo n.º 8
0
        public virtual async Task <bool> OnMessageReceived(WZClient session, object message)
        {
            foreach (var m in GetType().GetMethods())
            {
                foreach (var a in m.GetCustomAttributes(false))
                {
                    if (a.GetType() == typeof(MessageHandlerAttribute))
                    {
                        var mh = a as MessageHandlerAttribute;
                        if (mh._type == message.GetType())
                        {
                            var isAsync = m.GetCustomAttributes().Where(x => x.GetType() == typeof(AsyncStateMachineAttribute)).Count() > 0;
                            var lArgs   = new List <object>
                            {
                                session,
                                message
                            };
                            var args = lArgs.Take(m.GetParameters().Length).ToArray();
                            try
                            {
                                if (isAsync)
                                {
                                    await(Task) m.Invoke(this, args);
                                }
                                else
                                {
                                    m.Invoke(this, args);
                                }
                            }catch (Exception e)
                            {
                                Log.ForContext(Constants.SourceContextPropertyName, nameof(MessageHandler))
                                .Error(e, "Is Async:" + isAsync.ToString());
                                return(false);
                            }
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 9
0
        public override void OnDisconnect(WZClient session)
        {
            var Session = session as GSSession;

            using (var db = new GameContext())
            {
                if (Session.Player != null)
                {
                    if (Session.Player.Status == LoginStatus.Playing && Session.Player.Character != null)
                    {
                        var @char = Session.Player.Character;
                        @char.Map.DelPlayer(Session.Player.Character);
                        @char.Party?.Remove(Session.Player);
                        @char.Party = null;
                    }

                    Session.Player.Status = LoginStatus.NotLogged;
                    Logger.ForAccount(Session).Information("Saving...");
                    Session.Player.Save(db);
                    Logger.ForAccount(Session).Information("Saved!");
                }
                if (Session.Player.Account != null)
                {
                    var acc = (from a in db.Accounts
                               where a.AccountId == Session.Player.Account.ID
                               select a).First();

                    acc.IsConnected = false;

                    db.Accounts.Update(acc);
                    db.SaveChanges();
                    Logger.ForAccount(Session).Information("Disconnecting...");
                }
            }
            base.OnDisconnect(session);
        }
Exemplo n.º 10
0
        protected override void OnConnect(WZClient session)
        {
            var Session = session as CSSession;

            Session.SendAsync(new SConnectResult(1));
        }
Exemplo n.º 11
0
        /*protected override void OnConnect(WZClient session)
         * {
         *  var Session = session as CSSession;
         *
         *  Session.SendAsync(new SConnectResult(1));
         * }*/

        public override void OnDisconnect(WZClient session)
        {
            base.OnDisconnect(session);

            var Session = session as CSSession;
        }