Beispiel #1
0
        private void UpdateDatabase()
        {
            // TODO: rethrow exs using System.Runtime.ExceptionServices.ExceptionDispatchInfo
            using (var db = new BNetDb(this.Context.DbConnectionString))
            {
                db.HookSaveChanges(this.LogSql);
                int serverId = this.Context.Server.ServerId;
                using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    // db.dayz_clear_online(serverId);
                    // TODO: DateTimeOffset.UtcNow;
                    var now = DateTime.UtcNow;
                    var areOnlineGuids = this.Result.Select(r => r.Guid).ToList();
                    var whereOnline = from o in db.dayz_online
                                      where o.dayz_server_id == serverId && o.online == 1
                                      select o;

                    foreach (var wasOnlinePlayer in whereOnline)
                    {
                        if (areOnlineGuids.Contains(wasOnlinePlayer.guid))
                        {
                            // he's still online
                            wasOnlinePlayer.last_seen = now;
                            areOnlineGuids.Remove(wasOnlinePlayer.guid);
                        }
                        else
                        {
                            // he's gone
                            wasOnlinePlayer.online = 0;
                        }
                    }

                    var newOnline = this.Result.Where(r => areOnlineGuids.Contains(r.Guid));
                    foreach (var p in newOnline)
                    {
                        db.dayz_online.Add(
                            new dayz_online
                                {
                                    dayz_server_id = this.Context.Server.ServerId,
                                    guid = p.Guid,
                                    ip_address = p.IpAddress,
                                    lobby = (byte)(p.InLobby ? 1 : 0),
                                    name = p.Name,
                                    ping = p.Ping,
                                    slot = (byte)p.Id,
                                    verified = (sbyte)(p.Verified ? 1 : 0),
                                    first_seen = now,
                                    last_seen = now,
                                    online = 1
                                });
                    }

                    db.SaveChanges();
                    scope.Complete();
                }

                // ~trans()
            }

            // ~db()
        }
Beispiel #2
0
        public IEnumerable<ServerInfo> GetDbServers()
        {
            IEnumerable<ServerInfo> servers;
            using (var db = new BNetDb(this.DbConnectionString))
            {
                db.Configuration.ProxyCreationEnabled = false;

                var dayzServers = db.dayz_server.Where(s => s.server_id == 1).ToArray();
                servers =
                    dayzServers.Select(
                        s => new ServerInfo
                            {
                                ServerId = (int)s.id,
                                ServerName = s.short_name,
                                LoginCredentials =
                                    new BattlEyeLoginCredentials(
                                    s.rcon_host, s.rcon_port, s.rcon_pwd)
                            });
            }

            return servers;
        }