Пример #1
0
        public void CreateSession(long userId, string key)
        {
            using var ctx = new UchuContext();

            ctx.SessionCaches.Add(new SessionCache
            {
                Key    = key,
                UserId = userId
            });

            ctx.SaveChanges();
        }
Пример #2
0
        public void SetZone(IPEndPoint endpoint, ZoneId zone)
        {
            using var ctx = new UchuContext();

            var key = _keys[endpoint.ToString()];

            var session = ctx.SessionCaches.First(s => s.Key == key);

            session.ZoneId = (int)zone;

            ctx.SaveChanges();
        }
Пример #3
0
        public void SetCharacter(IPEndPoint endpoint, long characterId)
        {
            using var ctx = new UchuContext();

            var key = _keys[endpoint.ToString()];

            var session = ctx.SessionCaches.First(s => s.Key == key);

            session.CharacterId = characterId;

            ctx.SaveChanges();
        }
Пример #4
0
        public void DeleteSession(IPEndPoint endpoint)
        {
            using var ctx = new UchuContext();

            var key = _keys[endpoint.ToString()];

            var session = ctx.SessionCaches.First(s => s.Key == key);

            ctx.SessionCaches.Remove(session);

            ctx.SaveChanges();
        }
Пример #5
0
        public void SetZone(IPEndPoint endpoint, ZoneId zone)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint),
                                                ResourceStrings.DatabaseCache_SetZone_NullEndpointException);
            }

            using var ctx = new UchuContext();
            var key     = _keys[endpoint.ToString()];
            var session = ctx.SessionCaches.First(s => s.Key == key);

            session.ZoneId = zone;

            ctx.SaveChanges();
        }
Пример #6
0
        public string CreateSession(long userId)
        {
            using var ctx = new UchuContext();

            var key = GenerateKey();

            ctx.SessionCaches.Add(new SessionCache
            {
                Key    = key,
                UserId = userId
            });

            ctx.SaveChanges();

            return(key);
        }
Пример #7
0
        public void DeleteSession(IPEndPoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint),
                                                ResourceStrings.DatabaseCache_DeleteSession_NullEndpointException);
            }

            using var ctx = new UchuContext();

            var key     = _keys[endpoint.ToString()];
            var session = ctx.SessionCaches.First(s => s.Key == key);

            ctx.SessionCaches.Remove(session);

            ctx.SaveChanges();
        }
Пример #8
0
        public async Task StartAsync(Assembly assembly, bool acceptConsoleCommands = false)
        {
            Logger.Information("Registering assemblies...");

            RegisterAssembly(typeof(Server).Assembly);
            RegisterAssembly(assembly);

            RakNetServer.MessageReceived += HandlePacketAsync;

            Running = true;

            if (acceptConsoleCommands)
            {
                var _ = Task.Run(async() =>
                {
                    Logger.Information($"Ready to accept console command...");

                    while (Running)
                    {
                        var command = Console.ReadLine();

                        if (string.IsNullOrWhiteSpace(command))
                        {
                            continue;
                        }

                        Console.WriteLine(await HandleCommandAsync(command, null, GameMasterLevel.Console).ConfigureAwait(false));
                    }
                });
            }

            try
            {
                Logger.Information("Looking for requests...");

                await using (var ctx = new UchuContext())
                {
                    var request = ctx.WorldServerRequests.FirstOrDefault(w => w.SpecificationId == Id);

                    if (request == default)
                    {
                        Logger.Information($"Starting server...");

                        await RakNetServer.RunAsync().ConfigureAwait(false);

                        return;
                    }

                    Logger.Information($"Request found for {Id}");

                    request.State = WorldServerRequestState.Complete;

                    ctx.SaveChanges();
                }

                Logger.Information($"Starting server...");

                await RakNetServer.RunAsync().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }