Example #1
0
        public static async Task InvokeHandler <T>(Packet reader, NodeSession session)
        {
            var message = reader.Header.Message;

            Tuple <MethodInfo, Type, SessionState> data;

            if (MessageHandlers.TryGetValue(message, out data))
            {
                if ((session.State & data.Item3) == SessionState.None)
                {
                    var clientInfo = session.GetClientInfo();

                    Log.Debug($"Client '{clientInfo}': Received not allowed packet for state '{session.State}'.");
                    Log.Debug($"Disconnecting '{clientInfo}'.");

                    session.Dispose();

                    return;
                }

                var handlerObj = Activator.CreateInstance(data.Item2) as ClientPacket;

                handlerObj.Packet = reader;

                await Task.Run(() => handlerObj.Read());

                if (handlerObj.IsReadComplete)
                {
                    data.Item1.Invoke(null, new object[] { handlerObj, session });
                }
                else
                {
                    Log.Error($"Packet read for '{data.Item2.Name}' failed.");
                }
            }
            else
            {
                var msgName = Enum.GetName(typeof(ClientMessage), message) ?? Enum.GetName(typeof(GlobalClientMessage), message);

                if (msgName == null)
                {
                    Log.Error($"Received unknown opcode '0x{message:X}, Length: {reader.Data.Length}'.");
                }
                else
                {
                    Log.Error($"Packet handler for '{msgName} (0x{message:X}), Length: {reader.Data.Length}' not implemented.");
                }
            }
        }
Example #2
0
        public IActionResult Index()
        {
            var nodeSession = new NodeSession
            {
                Private = new PrivateSession
                {
                    Cookie = string.Join(", ", Request.Cookies.Select(x => $"{x.Key}={x.Value};"))
                },
                Public = new PublicSession
                {
                    ServiceUser = ServiceUser
                }
            };

            return(View(nodeSession));
        }
Example #3
0
        public IActionResult Index()
        {
            var user = HttpContext.Session.GetObjectFromJson <UserModel>("_user");

            if (user == null)
            {
                user = new UserModel();
            }
            var nodeSession = new NodeSession
            {
                Private = new PrivateSession
                {
                    Cookie = string.Join(", ", Request.Cookies.Select(x => $"{x.Key}={x.Value};"))
                },

                Public = new PublicSession
                {
                    User = user
                }
            };

            return(View(nodeSession));
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var tokens = Antiforgery.GetAndStoreTokens(context.HttpContext);

            ViewBag.AntiForgeryRequestToken = tokens.RequestToken;

            if (!string.IsNullOrWhiteSpace(tokens.RequestToken))
            {
                var cookieOptions = new CookieOptions
                {
                    HttpOnly = false,
                    Secure   = this.Request.IsHttps
                };
                this.Response.Cookies.Append("XSRF-TOKEN", tokens.RequestToken, cookieOptions);
            }
            var consentFeature = context.HttpContext.Features.Get <ITrackingConsentFeature>();
            var nodeSession    = new NodeSession
            {
                Private = new PrivateSession
                {
                    Cookie = string.Join(", ", Request.Cookies.Select(x => $"{x.Key}={x.Value};"))
                },
                Public = new PublicSession
                {
                    ConsentCookie = new ConsentCookie {
                        CookieName = consentFeature?.CreateConsentCookie(),
                        CanTrack   = consentFeature?.CanTrack ?? false
                    },
                    ServiceUser = null,
                    XsrfToken   = tokens.RequestToken
                }
            };

            ViewBag.NodeSession = nodeSession;

            base.OnActionExecuting(context);
        }
Example #5
0
 public bool Add(long id, NodeSession session)
 {
     return(Sessions.TryAdd(id, session));
 }
Example #6
0
        public static async void HandleAuthContinuedSession(AuthContinuedSession authContinuedSession, NodeSession session)
        {
            var accountInfo = Manager.Redirect.GetAccountInfo(authContinuedSession.Key);

            // Delete redirect key
            Manager.Redirect.DeleteCharacterRedirect(authContinuedSession.Key);

            if (accountInfo != null)
            {
                var sha1 = new SHA1Managed();

                var emailBytes      = Encoding.UTF8.GetBytes(accountInfo.Item1.AccountId + "#" + accountInfo.Item1.Index);
                var sessionKeyBytes = accountInfo.Item1.SessionKey.ToByteArray();
                var challengeBytes  = BitConverter.GetBytes(session.Challenge);

                sha1.TransformBlock(emailBytes, 0, emailBytes.Length, emailBytes, 0);
                sha1.TransformBlock(sessionKeyBytes, 0, 40, sessionKeyBytes, 0);
                sha1.TransformFinalBlock(challengeBytes, 0, 4);

                if (sha1.Hash.Compare(authContinuedSession.Digest))
                {
                    session.State = SessionState.Authenticated;

                    session.Account     = DB.Auth.Single <Account>(a => a.Id == accountInfo.Item1.AccountId);
                    session.GameAccount = accountInfo.Item1;

                    session.Crypt = new Framework.Cryptography.WoW.WoWCrypt();
                    session.Crypt.Initialize(accountInfo.Item1.SessionKey.ToByteArray(), session.ClientSeed, session.ServerSeed);

                    // Resume on the new connection
                    await session.Send(new ResumeComms());

                    return;
                }
            }

            session.Dispose();
        }
Example #7
0
 public static void HandlerQueuedMessagesEnd(QueuedMessagesEnd queuedMessagedEnd, NodeSession session)
 {
     //not implemented
 }
Example #8
0
 public static async void HandlerLogoutRequest(LogoutRequest logoutRequest, NodeSession session)
 {
     await session.Send(new LogoutResponse { Reason = 0, Instant = true });
 }
Example #9
0
 public static void HandlerRequestCemeteryList(RequestCemeteryList requestCemeteryList, NodeSession session)
 {
     // not implemented
     //await session.Send(new RequestCemeteryListResponse { IsGossipTriggered = false, Count = 0 } );
 }
Example #10
0
 public static void HandlerViolenceLevel(ViolenceLevel violenceLevel, NodeSession session)
 {
     // not implemented
 }