public static void HandleHelloAuth(AuthSession session, ClientHelloAuth helloAuth) { session.EnqueueEvent(new TaskGenericEvent <Account>(AuthDatabase.GetAccountAsync(helloAuth.Email, helloAuth.GameToken.Guid), account => { if (account == null) { // TODO: send error return; } session.EnqueueMessageEncrypted(new ServerAuthAccepted()); session.EnqueueMessageEncrypted(new ServerRealmMessages { MessageGroup = { new ServerRealmMessages.Message { Index = 0, Messages = { "Welcome to this NexusForever server!\nVisit: https://github.com/Rawaho/NexusForever" } } } }); byte[] sessionKey = RandomProvider.GetBytes(16u); session.EnqueueEvent(new TaskEvent(AuthDatabase.UpdateAccountSessionKey(account, sessionKey), () => { ServerManager.ServerInfo server = ServerManager.Servers.First(); session.EnqueueMessageEncrypted(new ServerRealmInfo { AccountId = account.Id, SessionKey = sessionKey, Realm = server.Model.Name, Host = server.Address, Port = server.Model.Port, Type = server.Model.Type }); })); })); }
public static void HandleHelloAuth(AuthSession session, ClientHelloAuth helloAuth) { session.EnqueueEvent(new TaskGenericEvent<Account>(AuthDatabase.GetAccountAsync(helloAuth.Email, helloAuth.GameToken.Guid), account => { if (account == null) { // TODO: send error return; } session.EnqueueMessageEncrypted(new ServerAuthAccepted()); session.EnqueueMessageEncrypted(new ServerRealmMessages { Messages = ServerManager.ServerMessages .Select(m => new ServerRealmMessages.Message { Index = m.Index, Messages = m.Messages }) .ToList() }); byte[] sessionKey = RandomProvider.GetBytes(16u); session.EnqueueEvent(new TaskEvent(AuthDatabase.UpdateAccountSessionKey(account, sessionKey), () => { ServerInfo server = ServerManager.Servers.First(); session.EnqueueMessageEncrypted(new ServerRealmInfo { AccountId = account.Id, SessionKey = sessionKey, Realm = server.Model.Name, Host = server.Address, Port = server.Model.Port, Type = server.Model.Type }); })); })); }
public static void HandleHelloAuth(AuthSession session, ClientHelloAuth helloAuth) { void SendServerAuthDenied(NpLoginResult result) { session.EnqueueMessageEncrypted(new ServerAuthDenied { LoginResult = result }); } if (helloAuth.Build != 16042) { SendServerAuthDenied(NpLoginResult.ClientServerVersionMismatch); return; } session.EnqueueEvent(new TaskGenericEvent <Account>(AuthDatabase.GetAccountAsync(helloAuth.Email, helloAuth.GameToken.Guid), account => { if (account == null) { SendServerAuthDenied(NpLoginResult.ErrorInvalidToken); return; } // TODO: might want to make this smarter in the future, eg: select a server the user has characters on ServerInfo server = ServerManager.Instance.Servers.FirstOrDefault(); if (server == null) { SendServerAuthDenied(NpLoginResult.NoRealmsAvailableAtThisTime); return; } session.EnqueueMessageEncrypted(new ServerAuthAccepted()); session.EnqueueMessageEncrypted(new ServerRealmMessages { Messages = ServerManager.Instance.ServerMessages .Select(m => new NetworkMessage { Index = m.Index, Messages = m.Messages }) .ToList() }); byte[] sessionKey = RandomProvider.GetBytes(16u); session.EnqueueEvent(new TaskEvent(AuthDatabase.UpdateAccountSessionKey(account, sessionKey), () => { session.EnqueueMessageEncrypted(new ServerRealmInfo { AccountId = account.Id, SessionKey = sessionKey, Realm = server.Model.Name, Address = server.Address, Port = server.Model.Port, Type = server.Model.Type }); })); })); }